LCOV - code coverage report
Current view: top level - analysis/processing - qgsalgorithmshpencodinginfo.cpp (source / functions) Hit Total Coverage
Test: coverage.info.cleaned Lines: 0 42 0.0 %
Date: 2021-03-26 12:19:53 Functions: 0 0 -
Branches: 0 0 -

           Branch data     Line data    Source code
       1                 :            : /***************************************************************************
       2                 :            :                          qgsalgorithmshpencodinginfo.cpp
       3                 :            :                          -----------------------------
       4                 :            :     begin                : February 2020
       5                 :            :     copyright            : (C) 2020 by Nyall Dawson
       6                 :            :     email                : nyall dot dawson at gmail dot com
       7                 :            :  ***************************************************************************/
       8                 :            : 
       9                 :            : /***************************************************************************
      10                 :            :  *                                                                         *
      11                 :            :  *   This program is free software; you can redistribute it and/or modify  *
      12                 :            :  *   it under the terms of the GNU General Public License as published by  *
      13                 :            :  *   the Free Software Foundation; either version 2 of the License, or     *
      14                 :            :  *   (at your option) any later version.                                   *
      15                 :            :  *                                                                         *
      16                 :            :  ***************************************************************************/
      17                 :            : 
      18                 :            : #include "qgsalgorithmshpencodinginfo.h"
      19                 :            : #include "qgsogrutils.h"
      20                 :            : 
      21                 :            : ///@cond PRIVATE
      22                 :            : 
      23                 :          0 : QString QgsShapefileEncodingInfoAlgorithm::name() const
      24                 :            : {
      25                 :          0 :   return QStringLiteral( "shpencodinginfo" );
      26                 :            : }
      27                 :            : 
      28                 :          0 : QString QgsShapefileEncodingInfoAlgorithm::displayName() const
      29                 :            : {
      30                 :          0 :   return QObject::tr( "Extract Shapefile encoding" );
      31                 :            : }
      32                 :            : 
      33                 :          0 : QStringList QgsShapefileEncodingInfoAlgorithm::tags() const
      34                 :            : {
      35                 :          0 :   return QObject::tr( "shp,codepage,cpg,ldid,information,list,show" ).split( ',' );
      36                 :          0 : }
      37                 :            : 
      38                 :          0 : QString QgsShapefileEncodingInfoAlgorithm::group() const
      39                 :            : {
      40                 :          0 :   return QObject::tr( "Vector general" );
      41                 :            : }
      42                 :            : 
      43                 :          0 : QString QgsShapefileEncodingInfoAlgorithm::groupId() const
      44                 :            : {
      45                 :          0 :   return QStringLiteral( "vectorgeneral" );
      46                 :            : }
      47                 :            : 
      48                 :          0 : QString QgsShapefileEncodingInfoAlgorithm::shortHelpString() const
      49                 :            : {
      50                 :          0 :   return QObject::tr( "This algorithm extracts the attribute encoding information embedded in a Shapefile.\n\n"
      51                 :            :                       "Both the encoding specified by an optional .cpg file and any encoding details present in the "
      52                 :            :                       ".dbf LDID header block are considered." );
      53                 :            : }
      54                 :            : 
      55                 :          0 : QString QgsShapefileEncodingInfoAlgorithm::shortDescription() const
      56                 :            : {
      57                 :          0 :   return QObject::tr( "Extracts the attribute encoding information embedded in a Shapefile." );
      58                 :            : }
      59                 :            : 
      60                 :          0 : QgsShapefileEncodingInfoAlgorithm *QgsShapefileEncodingInfoAlgorithm::createInstance() const
      61                 :            : {
      62                 :          0 :   return new QgsShapefileEncodingInfoAlgorithm();
      63                 :            : }
      64                 :            : 
      65                 :          0 : void QgsShapefileEncodingInfoAlgorithm::initAlgorithm( const QVariantMap & )
      66                 :            : {
      67                 :          0 :   addParameter( new QgsProcessingParameterFile( QStringLiteral( "INPUT" ), QObject::tr( "Input layer" ), QgsProcessingParameterFile::File,
      68                 :          0 :                 QString(), QVariant(), false, QObject::tr( "Shapefiles (%1)" ).arg( QLatin1String( "*.shp *.SHP)" ) ) ) );
      69                 :            : 
      70                 :          0 :   addOutput( new QgsProcessingOutputString( QStringLiteral( "ENCODING" ), QObject::tr( "Shapefile Encoding" ) ) );
      71                 :          0 :   addOutput( new QgsProcessingOutputString( QStringLiteral( "CPG_ENCODING" ), QObject::tr( "CPG Encoding" ) ) );
      72                 :          0 :   addOutput( new QgsProcessingOutputString( QStringLiteral( "LDID_ENCODING" ), QObject::tr( "LDID Encoding" ) ) );
      73                 :          0 : }
      74                 :            : 
      75                 :          0 : bool QgsShapefileEncodingInfoAlgorithm::prepareAlgorithm( const QVariantMap &parameters, QgsProcessingContext &context, QgsProcessingFeedback *feedback )
      76                 :            : {
      77                 :          0 :   const QString path = parameterAsFile( parameters, QStringLiteral( "INPUT" ), context );
      78                 :            : 
      79                 :          0 :   mCpgEncoding = QgsOgrUtils::readShapefileEncodingFromCpg( path );
      80                 :          0 :   if ( mCpgEncoding.isEmpty() )
      81                 :          0 :     feedback->pushInfo( QObject::tr( "No encoding information present in CPG file" ) );
      82                 :            :   else
      83                 :          0 :     feedback->pushInfo( QObject::tr( "Detected encoding from CPG file: %1" ).arg( mCpgEncoding ) );
      84                 :            : 
      85                 :          0 :   mLdidEncoding = QgsOgrUtils::readShapefileEncodingFromLdid( path );
      86                 :          0 :   if ( mLdidEncoding.isEmpty() )
      87                 :          0 :     feedback->pushInfo( QObject::tr( "No encoding information present in DBF LDID header" ) );
      88                 :            :   else
      89                 :          0 :     feedback->pushInfo( QObject::tr( "Detected encoding from DBF LDID header: %1" ).arg( mLdidEncoding ) );
      90                 :            : 
      91                 :            :   return true;
      92                 :          0 : }
      93                 :            : 
      94                 :            : 
      95                 :          0 : QVariantMap QgsShapefileEncodingInfoAlgorithm::processAlgorithm( const QVariantMap &, QgsProcessingContext &, QgsProcessingFeedback * )
      96                 :            : {
      97                 :          0 :   QVariantMap outputs;
      98                 :          0 :   outputs.insert( QStringLiteral( "ENCODING" ), mCpgEncoding.isEmpty() ? mLdidEncoding : mCpgEncoding );
      99                 :          0 :   outputs.insert( QStringLiteral( "CPG_ENCODING" ), mCpgEncoding );
     100                 :          0 :   outputs.insert( QStringLiteral( "LDID_ENCODING" ), mLdidEncoding );
     101                 :          0 :   return outputs;
     102                 :          0 : }
     103                 :            : 
     104                 :            : ///@endcond

Generated by: LCOV version 1.14