Skip to content

Commit

Permalink
In QgsVectorLayer::loadNamedStyle changed how to check if the usi ref…
Browse files Browse the repository at this point in the history
…ers to db or not
  • Loading branch information
Emilio Loi committed Apr 16, 2013
1 parent ef2d532 commit 8645094
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 10 deletions.
5 changes: 3 additions & 2 deletions src/app/qgsvectorlayerproperties.cpp
Expand Up @@ -130,7 +130,7 @@ QgsVectorLayerProperties::QgsVectorLayerProperties(
mSaveAsMenu->addAction( tr( "SLD File" ) );

//Only if the provider support loading & saving style to db add new choices
if( layer->dataProvider()->isSavingStyleToDBSupported() )
if( layer->dataProvider()->isSaveAndLoadStyleToDBSupported() )
{
//for loading
mLoadStyleMenu = new QMenu();
Expand Down Expand Up @@ -642,7 +642,7 @@ void QgsVectorLayerProperties::saveStyleAs( StyleType styleType )
QString msgError;

QgsSaveStyleToDbDialog askToUser;

//Ask the user for a name and a description about the style
if( askToUser.exec() == QDialog::Accepted )
{
QString styleName = askToUser.getName();
Expand Down Expand Up @@ -752,6 +752,7 @@ void QgsVectorLayerProperties::showListOfStylesFromDatabase()
QString errorMsg;
QVector<QString> ids, names, descriptions;

//get the list of styles in the db
int sectionLimit = layer->listStylesInDatabase(ids, names, descriptions, errorMsg);
if( !errorMsg.isNull() )
{
Expand Down
2 changes: 1 addition & 1 deletion src/app/qgsvectorlayerproperties.h
Expand Up @@ -142,7 +142,7 @@ class QgsVectorLayerProperties : public QDialog, private Ui::QgsVectorLayerPrope

void saveStyleAs( StyleType styleType );

/** when provider supports, it will list all the styles relative the layer */
/** when provider supports, it will list all the styles relative the layer in a dialog */
void showListOfStylesFromDatabase();

void updateSymbologyPage();
Expand Down
4 changes: 2 additions & 2 deletions src/core/qgsvectordataprovider.h
Expand Up @@ -330,9 +330,9 @@ class CORE_EXPORT QgsVectorDataProvider : public QgsDataProvider

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


protected:
Expand Down
9 changes: 5 additions & 4 deletions src/core/qgsvectorlayer.cpp
Expand Up @@ -40,6 +40,7 @@
#include "qgis.h" //for globals
#include "qgsapplication.h"
#include "qgscoordinatetransform.h"
#include "qgsdatasourceuri.h"
#include "qgsfeature.h"
#include "qgsfeaturerequest.h"
#include "qgsfield.h"
Expand Down Expand Up @@ -3077,7 +3078,6 @@ void QgsVectorLayer::destroyEditCommand()
undoStack()->undo();
}


void QgsVectorLayer::setCheckedState( int idx, QString checked, QString unchecked )
{
const QgsFields &fields = pendingFields();
Expand Down Expand Up @@ -3818,8 +3818,9 @@ void QgsVectorLayer::saveStyleToDatabase(QString name, QString description,

QString QgsVectorLayer::loadNamedStyle( const QString theURI, bool &theResultFlag )
{
//TODO find a better way to check if uri is pointing to db
if ( theURI.contains( tr( "dbname=" ) ) )
QgsDataSourceURI dsUri( theURI );

if ( !dsUri.database().isEmpty() )
{
QgsProviderRegistry * pReg = QgsProviderRegistry::instance();
QLibrary *myLib = pReg->providerLibrary( mProviderKey );
Expand All @@ -3832,7 +3833,7 @@ QString QgsVectorLayer::loadNamedStyle( const QString theURI, bool &theResultFla
qml = loadStyleExternalMethod( mDataSource, errorMsg );
if( qml.compare( tr( "" ) ) )
{
theResultFlag = this->applyNamedStyle( qml, errorMsg);
theResultFlag = this->applyNamedStyle( qml, errorMsg );
}
}
}
Expand Down
19 changes: 19 additions & 0 deletions src/core/qgsvectorlayer.h
Expand Up @@ -382,13 +382,32 @@ class CORE_EXPORT QgsVectorLayer : public QgsMapLayer
*/
virtual bool writeXml( QDomNode & layer_node, QDomDocument & doc );

/**
* Save named and sld style of the layer to the style table in the db.
* @param name
* @param description
* @param useAsDefault
* @param uiFileContent
* @param msgError
*/
virtual void saveStyleToDatabase( QString name, QString description,
bool useAsDefault, QString uiFileContent,
QString &msgError );

/**
* Lists all the style in db split into related to the layer and not related to
* @param ids the QVector in which will be stored the style db ids
* @param names the QVector in which will be stored the style names
* @param descriptions the QVector in which will be stored the style descriptions
* @param msgError
* @return the number of styles related to current layer
*/
virtual int listStylesInDatabase( QVector<QString> &ids, QVector<QString> &names,
QVector<QString> &descriptions, QString &msgError );

/**
* Will return the named style corresponding to style id provided
*/
virtual QString getStyleFromDatabase( QString styleId, QString &msgError );

virtual QString loadNamedStyle( const QString theURI, bool &theResultFlag );
Expand Down
2 changes: 1 addition & 1 deletion src/providers/postgres/qgspostgresprovider.h
Expand Up @@ -167,7 +167,7 @@ class QgsPostgresProvider : public QgsVectorDataProvider
/**
* It returns true. Saving style to db is supported by this provider
*/
virtual bool isSavingStyleToDBSupported(){ return true; }
virtual bool isSaveAndLoadStyleToDBSupported(){ return true; }

QgsAttributeList attributeIndexes();

Expand Down

0 comments on commit 8645094

Please sign in to comment.