Skip to content

Commit ea1aaea

Browse files
committedMay 2, 2013
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
1 parent d4542fe commit ea1aaea

9 files changed

+199
-171
lines changed
 

‎python/core/qgsvectordataprovider.sip

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,12 @@ class QgsVectorDataProvider : QgsDataProvider
269269
QStringList errors();
270270

271271

272+
/**
273+
* It returns false by default.
274+
* Must be implemented by providers that support saving and loading styles to db returning true
275+
*/
276+
virtual bool isSaveAndLoadStyleToDBSupported();
277+
272278
protected:
273279
QVariant convertValue( QVariant::Type type, QString value );
274280

‎python/core/qgsvectorlayer.sip

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,37 @@ class QgsVectorLayer : QgsMapLayer
304304
*/
305305
virtual bool writeXml( QDomNode & layer_node, QDomDocument & doc );
306306

307+
/**
308+
* Save named and sld style of the layer to the style table in the db.
309+
* @param name
310+
* @param description
311+
* @param useAsDefault
312+
* @param uiFileContent
313+
* @param msgError
314+
*/
315+
virtual void saveStyleToDatabase( QString name, QString description,
316+
bool useAsDefault, QString uiFileContent,
317+
QString &msgError );
318+
319+
/**
320+
* Lists all the style in db split into related to the layer and not related to
321+
* @param ids the QVector in which will be stored the style db ids
322+
* @param names the QVector in which will be stored the style names
323+
* @param descriptions the QVector in which will be stored the style descriptions
324+
* @param msgError
325+
* @return the number of styles related to current layer
326+
*/
327+
virtual int listStylesInDatabase( QStringList &ids, QStringList &names,
328+
QStringList &descriptions, QString &msgError );
329+
330+
/**
331+
* Will return the named style corresponding to style id provided
332+
*/
333+
virtual QString getStyleFromDatabase( QString styleId, QString &msgError );
334+
335+
virtual QString loadNamedStyle( const QString theURI, bool &theResultFlag, bool loadFromLocalDb = false );
336+
virtual bool applyNamedStyle( QString namedStyle , QString errorMsg );
337+
307338
/** convert a saved attribute editor element into a AttributeEditor structure as it's used internally.
308339
* @param elem the DOM element
309340
* @param parent the QObject which will own this object

‎src/app/qgsloadstylefromdbdialog.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,7 @@ QgsLoadStyleFromDBDialog::QgsLoadStyleFromDBDialog( QWidget *parent )
4646

4747
}
4848

49-
void QgsLoadStyleFromDBDialog::initializeLists( QVector<QString> ids, QVector<QString> names,
50-
QVector<QString> descriptions, int sectionLimit )
49+
void QgsLoadStyleFromDBDialog::initializeLists( QStringList ids, QStringList names, QStringList descriptions, int sectionLimit )
5150
{
5251
mIds = ids;
5352
mNames = names;

‎src/app/qgsloadstylefromdbdialog.h

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,23 +10,21 @@
1010
#ifndef QGSLOADFILEFROMDBDIALOG_H
1111
#define QGSLOADFILEFROMDBDIALOG_H
1212

13-
#include <QVector>
14-
1513
#include "ui_qgsloadstylefromdbdialog.h"
1614
#include "qgisgui.h"
1715
#include "qgsfield.h"
1816

19-
class QgsLoadStyleFromDBDialog: public QDialog, private Ui::QgsLoadStyleFromDBDialogLayout
17+
class QgsLoadStyleFromDBDialog : public QDialog, private Ui::QgsLoadStyleFromDBDialogLayout
2018
{
2119
QString mSelectedStyleId;
2220
int mSectionLimit;
23-
QVector<QString> mIds, mNames, mDescriptions;
21+
QStringList mIds, mNames, mDescriptions;
2422
QString qmlStyle;
2523
Q_OBJECT
2624
public:
2725
explicit QgsLoadStyleFromDBDialog( QWidget *parent = 0 );
2826

29-
void initializeLists( QVector<QString> ids, QVector<QString> names, QVector<QString> descriptions, int sectionLimit );
27+
void initializeLists( QStringList ids, QStringList names, QStringList descriptions, int sectionLimit );
3028
QString getSelectedStyleId();
3129

3230
public slots:

‎src/app/qgsvectorlayerproperties.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ QgsVectorLayerProperties::QgsVectorLayerProperties(
146146
if ( layer->dataProvider()->isSaveAndLoadStyleToDBSupported() )
147147
{
148148
//for loading
149-
mLoadStyleMenu = new QMenu();
149+
mLoadStyleMenu = new QMenu();
150150
mLoadStyleMenu->addAction( tr( "Load from file" ) );
151151
mLoadStyleMenu->addAction( tr( "Load from database" ) );
152152
pbnLoadStyle->setContextMenuPolicy( Qt::PreventContextMenu );
@@ -297,7 +297,7 @@ void QgsVectorLayerProperties::insertExpression()
297297
dlg.setWindowTitle( tr( "Insert expression" ) );
298298
if ( dlg.exec() == QDialog::Accepted )
299299
{
300-
QString expression = dlg.expressionBuilder()->expressionText();
300+
QString expression = dlg.expressionBuilder()->expressionText();
301301
//Only add the expression if the user has entered some text.
302302
if ( !expression.isEmpty() )
303303
{
@@ -754,7 +754,7 @@ void QgsVectorLayerProperties::saveStyleAs( StyleType styleType )
754754
}
755755
else
756756
{
757-
format = tr( "QGIS Layer Style File" ) + " (*.qml)";
757+
format = tr( "QGIS Layer Style File" ) + " (*.qml)";
758758
extension = ".qml";
759759
}
760760

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

831831
//get the list of styles in the db
832832
int sectionLimit = layer->listStylesInDatabase( ids, names, descriptions, errorMsg );

‎src/core/qgsvectordataprovider.h

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -335,14 +335,6 @@ class CORE_EXPORT QgsVectorDataProvider : public QgsDataProvider
335335
*/
336336
virtual bool isSaveAndLoadStyleToDBSupported() { return false; }
337337

338-
signals:
339-
/** Is emitted, when editing has started */
340-
void editingStarted();
341-
342-
/** Is emitted, when editing stopped */
343-
void editingStopped();
344-
345-
346338
protected:
347339
QVariant convertValue( QVariant::Type type, QString value );
348340

‎src/core/qgsvectorlayer.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -96,9 +96,9 @@ typedef QString loadStyle_t(
9696

9797
typedef int listStyles_t(
9898
const QString& uri,
99-
QVector<QString> &ids,
100-
QVector<QString> &names,
101-
QVector<QString> &descriptions,
99+
QStringList &ids,
100+
QStringList &names,
101+
QStringList &descriptions,
102102
QString& errCause
103103
);
104104

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

3733-
int QgsVectorLayer::listStylesInDatabase( QVector<QString> &ids, QVector<QString> &names, QVector<QString> &descriptions, QString &msgError )
3733+
int QgsVectorLayer::listStylesInDatabase( QStringList &ids, QStringList &names, QStringList &descriptions, QString &msgError )
37343734
{
37353735
QgsProviderRegistry * pReg = QgsProviderRegistry::instance();
37363736
QLibrary *myLib = pReg->providerLibrary( mProviderKey );

‎src/core/qgsvectorlayer.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
#include <QSet>
2323
#include <QList>
2424
#include <QStringList>
25-
#include <QVector>
2625

2726
#include "qgis.h"
2827
#include "qgsmaplayer.h"
@@ -713,8 +712,8 @@ class CORE_EXPORT QgsVectorLayer : public QgsMapLayer
713712
* @param msgError
714713
* @return the number of styles related to current layer
715714
*/
716-
virtual int listStylesInDatabase( QVector<QString> &ids, QVector<QString> &names,
717-
QVector<QString> &descriptions, QString &msgError );
715+
virtual int listStylesInDatabase( QStringList &ids, QStringList &names,
716+
QStringList &descriptions, QString &msgError );
718717

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

‎src/providers/postgres/qgspostgresprovider.cpp

Lines changed: 148 additions & 145 deletions
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)
Please sign in to comment.