Skip to content
Permalink
Browse files

In QgsVectorLayer::loadNamedStyle changed how to check if the usi ref…

…ers to db or not
  • Loading branch information
Emilio Loi
Emilio Loi committed Apr 16, 2013
1 parent ef2d532 commit 8645094c2ea717e62371bde5afacb7664f1f3490
@@ -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();
@@ -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();
@@ -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() )
{
@@ -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();
@@ -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:
@@ -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"
@@ -3077,7 +3078,6 @@ void QgsVectorLayer::destroyEditCommand()
undoStack()->undo();
}


void QgsVectorLayer::setCheckedState( int idx, QString checked, QString unchecked )
{
const QgsFields &fields = pendingFields();
@@ -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 );
@@ -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 );
}
}
}
@@ -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 );
@@ -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();

0 comments on commit 8645094

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