Skip to content
Permalink
Browse files

Add metadata for WFS provider in layer metadata informations

  • Loading branch information
sbrunner committed Nov 7, 2016
1 parent e7333f6 commit bc1ad2ce82196402ffa83118b7fd3c2f195a4414
@@ -379,6 +379,12 @@ class QgsVectorDataProvider : 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.
* @return The provider metadata
*/
virtual QMap<QString, QString> metadata() const;

signals:
/**
* Signals an error in this provider
@@ -383,7 +383,7 @@ class CORE_EXPORT QgsVectorDataProvider : public QgsDataProvider
* Returns true if the provider is strict about the type of inserted features
* (e.g. no multipolygon in a polygon layer)
*/
virtual bool doesStrictFeatureTypeCheck() const { return true;}
virtual bool doesStrictFeatureTypeCheck() const { return true; }

//! Returns a list of available encodings
static QStringList availableEncodings();
@@ -439,6 +439,12 @@ 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.

This comment has been minimized.

Copy link
@m-kuhn

m-kuhn Nov 7, 2016

Member

Can you expand the word "some" to some description ;)

* @return The provider metadata
*/
virtual QMap<QString, QString> metadata() const { return QMap<QString, QString>(); };

This comment has been minimized.

Copy link
@m-kuhn

m-kuhn Nov 7, 2016

Member

Should that be a QgsStringMap? Or even a QVariantMap?


signals:
/**
* Signals an error in this provider
@@ -3770,6 +3770,20 @@ QString QgsVectorLayer::metadata() const
myMetadata += QLatin1String( "<p>" );
myMetadata += dataProvider()->description().replace( '\n', QLatin1String( "<br>" ) );
myMetadata += QLatin1String( "</p>\n" );

QMap<QString, QString> 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 );
while ( i.hasNext() )
{
i.next();
myMetadata += "<tr><td>" + i.key() + ":</td><td>" + i.value() + "</td></tr>\n";
}
myMetadata += QLatin1String( "</table></p>\n" );
}
}

// data source
@@ -1100,6 +1100,16 @@ bool QgsWFSProvider::changeAttributeValues( const QgsChangedAttributesMap &attr_
}
}


QMap<QString, QString> QgsWFSProvider::metadata()
{
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" );
return result;

This comment has been minimized.

Copy link
@m-kuhn

m-kuhn Nov 7, 2016

Member

Returning all translated strings here makes this method quite hard to use for code. I think translation should go to some presentation layer while we're deep in the data/model layer here in the provider.

This comment has been minimized.

Copy link
@sbrunner

sbrunner Nov 8, 2016

Author Contributor

If I remove the tr from here and add the somewhere else, the string collecting will no more working ...

makes this method quite hard to use for code

Its not the goal to get e.g. the MaxFeature with this method...

This comment has been minimized.

Copy link
@m-kuhn

m-kuhn Nov 8, 2016

Member

Is it not possible to return a QVariantMap here and move the code from here to QgsVectorLayer?

{
 "MaxFeatures": 0
 "Paging": True
 "Joins": False
}

This would look much more flexible and future-proof to me.

This comment has been minimized.

Copy link
@sbrunner

sbrunner Nov 8, 2016

Author Contributor

This is a "json" representation not metadata that can be display in a UI...

This comment has been minimized.

Copy link
@m-kuhn

m-kuhn Nov 8, 2016

Member

This is a json representation of a QVariantMap. This is what a data-level object (like a dataprovider) should return so something on the presentation-layer (like the vectorlayer) can display it to the user.

This comment has been minimized.

Copy link
@sbrunner

sbrunner Nov 8, 2016

Author Contributor

Then I don't know what to do in the presentation with that...

This comment has been minimized.

Copy link
@m-kuhn

m-kuhn Nov 8, 2016

Member

Hmmm... What about something like this?

foreach( m in metadata )
{
   if ( m.key() == "MaxFeatures" )
      myString.append( QString("<th>%1</th><td>%2</td>").arg( tr( "Maximum numer of features per request" ) ).arg( m.value() ? m.value() : tr( "Not available" ) ) )
   else if ( m.key() == "Paging" )
     ...
}

This comment has been minimized.

Copy link
@sbrunner

sbrunner Nov 8, 2016

Author Contributor

The presentation should know what's in all the metadata of all the provider...
The goal it especially to don't do that, If we do that I don't need a metadata method and I directly access to the provider properties...
I what that the presentation layer don't know the provider and you purpose the opposed...

This comment has been minimized.

Copy link
@m-kuhn

m-kuhn Nov 8, 2016

Member

If I want to make a plugin that offers me this very cool UI to build joins but only enables this GUI for WFS layers that support it, who do I do that? (contrieved example but you get the point).

This comment has been minimized.

Copy link
@rouault

rouault Nov 8, 2016

Contributor

Jumping into this discussion. A QString QgsDataProvider::translateMetadata(const QString& val) method called by the presentation layer could perhaps solve the issue ?

This comment has been minimized.

Copy link
@sbrunner

sbrunner Nov 8, 2016

Author Contributor

@m-kuhn returning en empty map?

contrieved example but you get the point

not sure :-(

This comment has been minimized.

Copy link
@sbrunner

sbrunner Nov 8, 2016

Author Contributor

@rouault why not...

}

bool QgsWFSProvider::describeFeatureType( QString& geometryAttribute, QgsFields& fields, QgsWkbTypes::Type& geomType )
{
fields.clear();
@@ -132,6 +132,12 @@ class QgsWFSProvider : public QgsVectorDataProvider
*/
virtual bool changeAttributeValues( const QgsChangedAttributesMap &attr_map ) override;

/**
* Get some metadata description of the provider.
* @return The provider metadata
*/
virtual QMap<QString, QString> metadata();

public slots:
/** Reloads the data from the source. Needs to be implemented by providers with data caches to
synchronize with changes in the data source*/

0 comments on commit bc1ad2c

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