Skip to content

Commit

Permalink
Changed "save to db" provider capability check
Browse files Browse the repository at this point in the history
  • Loading branch information
Emilio Loi committed Apr 13, 2013
1 parent 4826e28 commit 7aa831d
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/app/qgsvectorlayerproperties.cpp
Expand Up @@ -127,10 +127,10 @@ QgsVectorLayerProperties::QgsVectorLayerProperties(
mSaveAsMenu->addAction( tr( "QGIS Layer Style File" ) );
mSaveAsMenu->addAction( tr( "SLD File" ) );

//Only if the provider is PostgresProvider add action to save the style in the DB
if( layer->providerType().compare( tr( "postgres" ) ) == 0 )
//Only if the provider support saving style to db add new choice
if( layer->dataProvider()->isSavingStyleToDBSupported() )
{
mSaveAsMenu->addAction( tr( "Save in Postgres") );
mSaveAsMenu->addAction( tr( "Save on database (%1)" ).arg( layer->providerType() ) );
}

QObject::connect( mSaveAsMenu, SIGNAL( triggered( QAction * ) ), this, SLOT( saveStyleAsMenuTriggered( QAction * ) ) );
Expand Down Expand Up @@ -624,7 +624,7 @@ void QgsVectorLayerProperties::saveStyleAs( StyleType styleType )

if( styleType == DB )
{
QString infoWindowTitle = QObject::tr( "Save style to Postgres" );
QString infoWindowTitle = QObject::tr( "Save style to DB (%1)" ).arg( layer->providerType() );
QString msgError;

QgsSaveStyleToDbDialog askToUser;
Expand Down
6 changes: 6 additions & 0 deletions src/core/qgsvectordataprovider.h
Expand Up @@ -328,6 +328,12 @@ class CORE_EXPORT QgsVectorDataProvider : public QgsDataProvider
*/
QStringList errors();

/**
* It returns false by default.
* Must be implemented by providers that support saving style to db returning true
*/
virtual bool isSavingStyleToDBSupported() { return false; }


protected:
QVariant convertValue( QVariant::Type type, QString value );
Expand Down
6 changes: 6 additions & 0 deletions src/providers/postgres/qgspostgresprovider.h
Expand Up @@ -163,6 +163,12 @@ class QgsPostgresProvider : public QgsVectorDataProvider
*/
bool isValid();


/**
* It returns true. Saving style to db is supported by this provider
*/
virtual bool isSavingStyleToDBSupported(){ return true; }

QgsAttributeList attributeIndexes();

QgsAttributeList pkAttributeIndexes() { return mPrimaryKeyAttrs; }
Expand Down

0 comments on commit 7aa831d

Please sign in to comment.