Skip to content

Commit

Permalink
Minor provider cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Jul 31, 2021
1 parent 7e66281 commit 37ffa4c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 19 deletions.
28 changes: 13 additions & 15 deletions src/providers/gpx/qgsgpxprovider.cpp
Expand Up @@ -45,23 +45,21 @@
#include "qgsgpxprovider.h"
#include "gpsdata.h"

const char *QgsGPXProvider::ATTR[] = { "name", "elevation", "symbol", "number",
"comment", "description", "source",
"url", "url name"
};
QVariant::Type QgsGPXProvider::attrType[] = { QVariant::String, QVariant::Double, QVariant::String, QVariant::Int,
QVariant::String, QVariant::String, QVariant::String,
QVariant::String, QVariant::String
};
QgsGPXProvider::DataType QgsGPXProvider::attrUsed[] =
const QStringList QgsGPXProvider::sAttributeNames = { "name", "elevation", "symbol", "number",
"comment", "description", "source",
"url", "url name"
};
const QList< QVariant::Type > QgsGPXProvider::sAttributeTypes = { QVariant::String, QVariant::Double, QVariant::String, QVariant::Int,
QVariant::String, QVariant::String, QVariant::String,
QVariant::String, QVariant::String
};
const QList< QgsGPXProvider::DataType > QgsGPXProvider::sAttributedUsedForLayerType =
{
QgsGPXProvider::AllType, QgsGPXProvider::WaypointType, QgsGPXProvider::TrkRteType, QgsGPXProvider::TrkRteType,
QgsGPXProvider::AllType, QgsGPXProvider::AllType, QgsGPXProvider::AllType, QgsGPXProvider::AllType,
QgsGPXProvider::AllType, QgsGPXProvider::AllType
};

const int QgsGPXProvider::ATTR_COUNT = sizeof( QgsGPXProvider::ATTR ) / sizeof( const char * );

const QString GPX_KEY = QStringLiteral( "gpx" );

const QString GPX_DESCRIPTION = QObject::tr( "GPS eXchange format provider" );
Expand Down Expand Up @@ -90,12 +88,12 @@ QgsGPXProvider::QgsGPXProvider( const QString &uri, const ProviderOptions &optio
mFileName = uriParts.value( QStringLiteral( "path" ) ).toString();

// set up the attributes and the geometry type depending on the feature type
for ( int i = 0; i < ATTR_COUNT; ++i )
for ( int i = 0; i < sAttributeNames.size(); ++i )
{
if ( attrUsed[i] & mFeatureType )
if ( sAttributedUsedForLayerType[i] & mFeatureType )
{
QString attrTypeName = ( attrType[i] == QVariant::Int ? "int" : ( attrType[i] == QVariant::Double ? "double" : "text" ) );
mAttributeFields.append( QgsField( ATTR[i], attrType[i], attrTypeName ) );
QString attrTypeName = ( sAttributeTypes[i] == QVariant::Int ? "int" : ( sAttributeTypes[i] == QVariant::Double ? "double" : "text" ) );
mAttributeFields.append( QgsField( sAttributeNames[i], sAttributeTypes[i], attrTypeName ) );
mIndexToAttr.append( i );
}
}
Expand Down
7 changes: 3 additions & 4 deletions src/providers/gpx/qgsgpxprovider.h
Expand Up @@ -108,10 +108,9 @@ class QgsGPXProvider final: public QgsVectorDataProvider

DataType mFeatureType = WaypointType;

static const char *ATTR[];
static QVariant::Type attrType[];
static DataType attrUsed[];
static const int ATTR_COUNT;
static const QStringList sAttributeNames;
static const QList< QVariant::Type > sAttributeTypes;
static const QList< DataType > sAttributedUsedForLayerType;

bool mValid = false;

Expand Down

0 comments on commit 37ffa4c

Please sign in to comment.