Skip to content
Permalink
Browse files

Apply some @m-kuhn comments (#3736)

* Use QgsStringMap

* Better description

* Use new translated metadata methods
  • Loading branch information
sbrunner authored and m-kuhn committed Nov 8, 2016
1 parent 63e3fd3 commit 6cf47bef1ef8e0d273f0ed3179ec15f0cbb3f36f
@@ -401,7 +401,22 @@ class QgsVectorDataProvider : QgsDataProvider
* Get some metadata that will be display in the metadata tab of the layer properties.
* @return The provider metadata
*/
virtual QMap<QString, QString> metadata() const;
virtual QVariantMap metadata() const;

/**
* Get the translated metadata key.
* @param mdKey The metadata key
* @return The translated metadata value
*/
virtual QString translateMetadataKey( const QString& mdKey ) const;

/**
* Get the translated metadata value.
* @param mdKey The metadata key
* @param value The metadata value
* @return The translated metadata value
*/
virtual QString translateMetadataValue( const QString& mdKey, const QVariant& value ) const;

signals:
/**
@@ -460,10 +460,25 @@ class CORE_EXPORT QgsVectorDataProvider : public QgsDataProvider
virtual QList<QgsRelation> discoverRelations( const QgsVectorLayer* self, const QList<QgsVectorLayer*>& layers ) const;

/**
* Get some metadata that will be display in the metadata tab of the layer properties.
* Get metadata, dependent on the provider type, that will be display in the metadata tab of the layer properties.
* @return The provider metadata
*/
virtual QMap<QString, QString> metadata() const { return QMap<QString, QString>(); };
virtual QVariantMap metadata() const { return QVariantMap(); };

/**
* Get the translated metadata key.
* @param mdKey The metadata key
* @return The translated metadata value
*/
virtual QString translateMetadataKey( const QString& mdKey ) const { return mdKey; };

/**
* Get the translated metadata value.
* @param mdKey The metadata key
* @param value The metadata value
* @return The translated metadata value
*/
virtual QString translateMetadataValue( const QString& mdKey, const QVariant& value ) const { Q_UNUSED( mdKey ); return value.toString(); };

signals:

@@ -3890,16 +3890,19 @@ QString QgsVectorLayer::metadata() const
myMetadata += dataProvider()->description().replace( '\n', QLatin1String( "<br>" ) );
myMetadata += QLatin1String( "</p>\n" );

QMap<QString, QString> dataProviderMetadata = mDataProvider->metadata();
QVariantMap dataProviderMetadata = mDataProvider->metadata();
if ( !dataProviderMetadata.isEmpty() )
{
myMetadata += "<p class=\"glossy\">" + tr( "Provider Metadata" ) + "</p>\n";
myMetadata += "<p><table><tr><th>" + tr( "Metadata name" ) + "</th><th>" + tr( "Metadata value" ) + "</th></tr>\n";
QMapIterator<QString, QString> i( dataProviderMetadata );
QMapIterator<QString, QVariant> i( dataProviderMetadata );
while ( i.hasNext() )
{
i.next();
myMetadata += "<tr><td>" + i.key() + ":</td><td>" + i.value() + "</td></tr>\n";
myMetadata += "<tr>";
myMetadata += "<td>" + mDataProvider->translateMetadataKey( i.key() ) + ":</td>";
myMetadata += "<td>" + mDataProvider->translateMetadataValue( i.key(), i.value() ) + "</td>";
myMetadata += "</tr>\n";
}
myMetadata += QLatin1String( "</table></p>\n" );
}
@@ -1100,16 +1100,51 @@ bool QgsWFSProvider::changeAttributeValues( const QgsChangedAttributesMap &attr_
}
}


QMap<QString, QString> QgsWFSProvider::metadata()
QVariantMap QgsWFSProvider::metadata() const
{
QMap<QString, QString> result;
result[tr( "Max Features" )] = mShared->mCaps.maxFeatures == 0 ? tr( "not provided" ) : QString( mShared->mCaps.maxFeatures );
result[tr( "Supports Paging" )] = mShared->mCaps.supportsPaging ? tr( "supported" ) : tr( "unsupported" );
result[tr( "Supports Joins" )] = mShared->mCaps.supportsJoins ? tr( "supported" ) : tr( "unsupported" );
QVariantMap result;
result["MaxFeatures"] = mShared->mCaps.maxFeatures;
result["SupportsPaging"] = mShared->mCaps.supportsPaging;
result["SupportsJoins"] = mShared->mCaps.supportsJoins;
return result;
}

QString QgsWFSProvider::translateMetadataKey( const QString& mdKey ) const
{
if ( mdKey == "MaxFeatures" )
{
return tr( "Max Features" );
}
else if ( mdKey == "SupportsPaging" )
{
return tr( "Supports Paging" );
}
else if ( mdKey == "SupportsJoins" )
{
return tr( "Supports Joins" );
}
else
{
return mdKey;
}
};

QString QgsWFSProvider::translateMetadataValue( const QString& mdKey, const QVariant& value ) const
{
if ( mdKey == "MaxFeatures" )
{
return value.toInt() == 0 ? tr( "not provided" ) : value.toString();
}
else if ( mdKey == "SupportsPaging" || mdKey == "SupportsJoins" )
{
return value.toBool() ? tr( "supported" ) : tr( "unsupported" );
}
else
{
return value.toString();
}
};

bool QgsWFSProvider::describeFeatureType( QString& geometryAttribute, QgsFields& fields, QgsWkbTypes::Type& geomType )
{
fields.clear();
@@ -137,7 +137,22 @@ class QgsWFSProvider : public QgsVectorDataProvider
* Get some metadata description of the provider.
* @return The provider metadata
*/
virtual QMap<QString, QString> metadata();
virtual QVariantMap metadata() const override;

/**
* Get the translated metadata key.
* @param mdKey The metadata key
* @return The translated metadata value
*/
virtual QString translateMetadataKey( const QString& mdKey ) const override;

/**
* Get the translated metadata value.
* @param mdKey The metadata key
* @param value The metadata value
* @return The translated metadata value
*/
virtual QString translateMetadataValue( const QString& mdKey, const QVariant& value ) const override;

public slots:

0 comments on commit 6cf47be

Please sign in to comment.
You can’t perform that action at this time.