Skip to content
Permalink
Browse files

cleanup style to db:

- add sip bindings to new methods
- table name, sql queries and constants should not be translated
- replace QVector<QString> with QStringList
  • Loading branch information
jef-n committed May 2, 2013
1 parent d4542fe commit ea1aaeae012aaa25f2aecf149752a08b1db3fd98
@@ -269,6 +269,12 @@ class QgsVectorDataProvider : QgsDataProvider
QStringList errors();


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

protected:
QVariant convertValue( QVariant::Type type, QString value );

@@ -304,6 +304,37 @@ class QgsVectorLayer : 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( QStringList &ids, QStringList &names,
QStringList &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, bool loadFromLocalDb = false );
virtual bool applyNamedStyle( QString namedStyle , QString errorMsg );

/** convert a saved attribute editor element into a AttributeEditor structure as it's used internally.
* @param elem the DOM element
* @param parent the QObject which will own this object
@@ -46,8 +46,7 @@ QgsLoadStyleFromDBDialog::QgsLoadStyleFromDBDialog( QWidget *parent )

}

void QgsLoadStyleFromDBDialog::initializeLists( QVector<QString> ids, QVector<QString> names,
QVector<QString> descriptions, int sectionLimit )
void QgsLoadStyleFromDBDialog::initializeLists( QStringList ids, QStringList names, QStringList descriptions, int sectionLimit )
{
mIds = ids;
mNames = names;
@@ -10,23 +10,21 @@
#ifndef QGSLOADFILEFROMDBDIALOG_H
#define QGSLOADFILEFROMDBDIALOG_H

#include <QVector>

#include "ui_qgsloadstylefromdbdialog.h"
#include "qgisgui.h"
#include "qgsfield.h"

class QgsLoadStyleFromDBDialog: public QDialog, private Ui::QgsLoadStyleFromDBDialogLayout
class QgsLoadStyleFromDBDialog : public QDialog, private Ui::QgsLoadStyleFromDBDialogLayout
{
QString mSelectedStyleId;
int mSectionLimit;
QVector<QString> mIds, mNames, mDescriptions;
QStringList mIds, mNames, mDescriptions;
QString qmlStyle;
Q_OBJECT
public:
explicit QgsLoadStyleFromDBDialog( QWidget *parent = 0 );

void initializeLists( QVector<QString> ids, QVector<QString> names, QVector<QString> descriptions, int sectionLimit );
void initializeLists( QStringList ids, QStringList names, QStringList descriptions, int sectionLimit );
QString getSelectedStyleId();

public slots:
@@ -146,7 +146,7 @@ QgsVectorLayerProperties::QgsVectorLayerProperties(
if ( layer->dataProvider()->isSaveAndLoadStyleToDBSupported() )
{
//for loading
mLoadStyleMenu = new QMenu();
mLoadStyleMenu = new QMenu();
mLoadStyleMenu->addAction( tr( "Load from file" ) );
mLoadStyleMenu->addAction( tr( "Load from database" ) );
pbnLoadStyle->setContextMenuPolicy( Qt::PreventContextMenu );
@@ -297,7 +297,7 @@ void QgsVectorLayerProperties::insertExpression()
dlg.setWindowTitle( tr( "Insert expression" ) );
if ( dlg.exec() == QDialog::Accepted )
{
QString expression = dlg.expressionBuilder()->expressionText();
QString expression = dlg.expressionBuilder()->expressionText();
//Only add the expression if the user has entered some text.
if ( !expression.isEmpty() )
{
@@ -754,7 +754,7 @@ void QgsVectorLayerProperties::saveStyleAs( StyleType styleType )
}
else
{
format = tr( "QGIS Layer Style File" ) + " (*.qml)";
format = tr( "QGIS Layer Style File" ) + " (*.qml)";
extension = ".qml";
}

@@ -826,7 +826,7 @@ void QgsVectorLayerProperties::loadStyleMenuTriggered( QAction *action )
void QgsVectorLayerProperties::showListOfStylesFromDatabase()
{
QString errorMsg;
QVector<QString> ids, names, descriptions;
QStringList ids, names, descriptions;

//get the list of styles in the db
int sectionLimit = layer->listStylesInDatabase( ids, names, descriptions, errorMsg );
@@ -335,14 +335,6 @@ class CORE_EXPORT QgsVectorDataProvider : public QgsDataProvider
*/
virtual bool isSaveAndLoadStyleToDBSupported() { return false; }

signals:
/** Is emitted, when editing has started */
void editingStarted();

/** Is emitted, when editing stopped */
void editingStopped();


protected:
QVariant convertValue( QVariant::Type type, QString value );

@@ -96,9 +96,9 @@ typedef QString loadStyle_t(

typedef int listStyles_t(
const QString& uri,
QVector<QString> &ids,
QVector<QString> &names,
QVector<QString> &descriptions,
QStringList &ids,
QStringList &names,
QStringList &descriptions,
QString& errCause
);

@@ -3730,7 +3730,7 @@ QDomElement QgsAttributeEditorField::toDomElement( QDomDocument& doc ) const
return elem;
}

int QgsVectorLayer::listStylesInDatabase( QVector<QString> &ids, QVector<QString> &names, QVector<QString> &descriptions, QString &msgError )
int QgsVectorLayer::listStylesInDatabase( QStringList &ids, QStringList &names, QStringList &descriptions, QString &msgError )
{
QgsProviderRegistry * pReg = QgsProviderRegistry::instance();
QLibrary *myLib = pReg->providerLibrary( mProviderKey );
@@ -22,7 +22,6 @@
#include <QSet>
#include <QList>
#include <QStringList>
#include <QVector>

#include "qgis.h"
#include "qgsmaplayer.h"
@@ -713,8 +712,8 @@ class CORE_EXPORT QgsVectorLayer : public QgsMapLayer
* @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 );
virtual int listStylesInDatabase( QStringList &ids, QStringList &names,
QStringList &descriptions, QString &msgError );

/**
* Will return the named style corresponding to style id provided

0 comments on commit ea1aaea

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