Skip to content

Commit

Permalink
reapply some cleanup to 'styles_to_db'
Browse files Browse the repository at this point in the history
  • Loading branch information
jef-n committed May 9, 2013
1 parent a905b55 commit 576102b
Show file tree
Hide file tree
Showing 8 changed files with 560 additions and 509 deletions.
42 changes: 21 additions & 21 deletions doc/TRANSLATORS

Large diffs are not rendered by default.

306 changes: 177 additions & 129 deletions i18n/qgis_de.ts

Large diffs are not rendered by default.

379 changes: 190 additions & 189 deletions src/app/qgsvectorlayerproperties.cpp

Large diffs are not rendered by default.

259 changes: 130 additions & 129 deletions src/core/qgsvectorlayer.cpp
Expand Up @@ -32,7 +32,6 @@
#include <QString>
#include <QDomNode>
#include <QVector>
#include <QMessageBox>

#include "qgsvectorlayer.h"

Expand Down Expand Up @@ -74,39 +73,40 @@
#include "qgsdiagramrendererv2.h"
#include "qgsstylev2.h"
#include "qgssymbologyv2conversion.h"
#include "qgspallabeling.h"

#ifdef TESTPROVIDERLIB
#include <dlfcn.h>
#endif

typedef bool saveStyle_t(
const QString& uri,
const QString& qmlStyle,
const QString& sldStyle,
const QString& styleName,
const QString& styleDescription,
const QString& uiFileContent,
bool useAsDefault,
QString& errCause
const QString& uri,
const QString& qmlStyle,
const QString& sldStyle,
const QString& styleName,
const QString& styleDescription,
const QString& uiFileContent,
bool useAsDefault,
QString& errCause
);

typedef QString loadStyle_t(
const QString& uri,
QString& errCause
const QString& uri,
QString& errCause
);

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

typedef QString getStyleById_t(
const QString& uri,
QString styleID,
QString& errCause
const QString& uri,
QString styleID,
QString& errCause
);


Expand Down Expand Up @@ -3731,151 +3731,152 @@ 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 );
if ( !myLib )
{
msgError = QObject::tr( "Unable to load %1 provider" ).arg( mProviderKey );
return -1;
}
listStyles_t* listStylesExternalMethod = ( listStyles_t * ) cast_to_fptr(myLib->resolve("listStyles"));
QgsProviderRegistry * pReg = QgsProviderRegistry::instance();
QLibrary *myLib = pReg->providerLibrary( mProviderKey );
if ( !myLib )
{
msgError = QObject::tr( "Unable to load %1 provider" ).arg( mProviderKey );
return -1;
}
listStyles_t* listStylesExternalMethod = ( listStyles_t * ) cast_to_fptr( myLib->resolve( "listStyles" ) );

if ( !listStylesExternalMethod )
{
delete myLib;
msgError = QObject::tr( "Provider %1 has no listStyles method" ).arg( mProviderKey );
return -1;
}
if ( !listStylesExternalMethod )
{
delete myLib;
msgError = QObject::tr( "Provider %1 has no %2 method" ).arg( mProviderKey ).arg( "listStyles" );
return -1;
}

return listStylesExternalMethod(mDataSource, ids, names, descriptions, msgError);
return listStylesExternalMethod( mDataSource, ids, names, descriptions, msgError );
}

QString QgsVectorLayer::getStyleFromDatabase(QString styleId, QString &msgError)
QString QgsVectorLayer::getStyleFromDatabase( QString styleId, QString &msgError )
{
QgsProviderRegistry * pReg = QgsProviderRegistry::instance();
QLibrary *myLib = pReg->providerLibrary( mProviderKey );
if ( !myLib )
{
msgError = QObject::tr( "Unable to load %1 provider" ).arg( mProviderKey );
return QObject::tr( "" );
}
getStyleById_t* getStyleByIdMethod = ( getStyleById_t * ) cast_to_fptr(myLib->resolve("getStyleById"));
QgsProviderRegistry * pReg = QgsProviderRegistry::instance();
QLibrary *myLib = pReg->providerLibrary( mProviderKey );
if ( !myLib )
{
msgError = QObject::tr( "Unable to load %1 provider" ).arg( mProviderKey );
return QObject::tr( "" );
}
getStyleById_t* getStyleByIdMethod = ( getStyleById_t * ) cast_to_fptr( myLib->resolve( "getStyleById" ) );

if ( !getStyleByIdMethod )
{
delete myLib;
msgError = QObject::tr( "Provider %1 has no getStyleById method" ).arg( mProviderKey );
return QObject::tr( "" );
}
if ( !getStyleByIdMethod )
{
delete myLib;
msgError = QObject::tr( "Provider %1 has no %2 method" ).arg( mProviderKey ).arg( "getStyleById" );
return QObject::tr( "" );
}

return getStyleByIdMethod( mDataSource, styleId, msgError );
return getStyleByIdMethod( mDataSource, styleId, msgError );
}


void QgsVectorLayer::saveStyleToDatabase(QString name, QString description,
bool useAsDefault, QString uiFileContent, QString &msgError){
void QgsVectorLayer::saveStyleToDatabase( QString name, QString description,
bool useAsDefault, QString uiFileContent, QString &msgError )
{

QString sldStyle, qmlStyle;
QgsProviderRegistry * pReg = QgsProviderRegistry::instance();
QLibrary *myLib = pReg->providerLibrary( mProviderKey );
if ( !myLib )
{
msgError = QObject::tr( "Unable to load %1 provider" ).arg( mProviderKey );
return;
}
saveStyle_t* saveStyleExternalMethod = ( saveStyle_t * ) cast_to_fptr(myLib->resolve("saveStyle"));
QString sldStyle, qmlStyle;
QgsProviderRegistry * pReg = QgsProviderRegistry::instance();
QLibrary *myLib = pReg->providerLibrary( mProviderKey );
if ( !myLib )
{
msgError = QObject::tr( "Unable to load %1 provider" ).arg( mProviderKey );
return;
}
saveStyle_t* saveStyleExternalMethod = ( saveStyle_t * ) cast_to_fptr( myLib->resolve( "saveStyle" ) );

if ( !saveStyleExternalMethod )
{
delete myLib;
msgError = QObject::tr( "Provider %1 has no saveStyle method" ).arg( mProviderKey );
return;
}
if ( !saveStyleExternalMethod )
{
delete myLib;
msgError = QObject::tr( "Provider %1 has no %2 method" ).arg( mProviderKey ).arg( "saveStyle" );
return;
}

QDomDocument qmlDocument, sldDocument;
this->exportNamedStyle(qmlDocument, msgError);
if( !msgError.isNull() )
{
return;
}
qmlStyle = qmlDocument.toString();
QDomDocument qmlDocument, sldDocument;
this->exportNamedStyle( qmlDocument, msgError );
if ( !msgError.isNull() )
{
return;
}
qmlStyle = qmlDocument.toString();

this->exportSldStyle(sldDocument, msgError);
if( !msgError.isNull() )
{
return;
}
sldStyle = sldDocument.toString();
this->exportSldStyle( sldDocument, msgError );
if ( !msgError.isNull() )
{
return;
}
sldStyle = sldDocument.toString();

saveStyleExternalMethod( mDataSource, qmlStyle, sldStyle, name,
description, uiFileContent, useAsDefault, msgError );
saveStyleExternalMethod( mDataSource, qmlStyle, sldStyle, name,
description, uiFileContent, useAsDefault, msgError );
}



QString QgsVectorLayer::loadNamedStyle( const QString theURI, bool &theResultFlag )
{
return loadNamedStyle( theURI, theResultFlag, false );
return loadNamedStyle( theURI, theResultFlag, false );
}

QString QgsVectorLayer::loadNamedStyle( const QString theURI, bool &theResultFlag , bool loadFromLocalDB )
{
QgsDataSourceURI dsUri( theURI );
if ( !loadFromLocalDB && !dsUri.database().isEmpty() )
QgsDataSourceURI dsUri( theURI );
if ( !loadFromLocalDB && !dsUri.database().isEmpty() )
{
QgsProviderRegistry * pReg = QgsProviderRegistry::instance();
QLibrary *myLib = pReg->providerLibrary( mProviderKey );
if ( myLib )
{
QgsProviderRegistry * pReg = QgsProviderRegistry::instance();
QLibrary *myLib = pReg->providerLibrary( mProviderKey );
if ( myLib )
loadStyle_t* loadStyleExternalMethod = ( loadStyle_t * ) cast_to_fptr( myLib->resolve( "loadStyle" ) );
if ( loadStyleExternalMethod )
{
QString qml, errorMsg;
qml = loadStyleExternalMethod( mDataSource, errorMsg );
if ( !qml.isEmpty() )
{
loadStyle_t* loadStyleExternalMethod = ( loadStyle_t * ) cast_to_fptr( myLib->resolve( "loadStyle" ) );
if ( loadStyleExternalMethod )
{
QString qml, errorMsg;
qml = loadStyleExternalMethod( mDataSource, errorMsg );
if( !qml.isEmpty() )
{
theResultFlag = this->applyNamedStyle( qml, errorMsg );
}
}
theResultFlag = this->applyNamedStyle( qml, errorMsg );
}

}
if( !theResultFlag )
{
return QgsMapLayer::loadNamedStyle( theURI, theResultFlag );
}
}
return QObject::tr( "Loaded from Provider" );

}
if ( !theResultFlag )
{
return QgsMapLayer::loadNamedStyle( theURI, theResultFlag );
}
return QObject::tr( "Loaded from Provider" );
}

bool QgsVectorLayer::applyNamedStyle(QString namedStyle, QString errorMsg )
bool QgsVectorLayer::applyNamedStyle( QString namedStyle, QString errorMsg )
{
QDomDocument myDocument( "qgis" );
myDocument.setContent( namedStyle );
QDomDocument myDocument( "qgis" );
myDocument.setContent( namedStyle );

QDomElement myRoot = myDocument.firstChildElement( "qgis" );
QDomElement myRoot = myDocument.firstChildElement( "qgis" );

if( myRoot.isNull() )
{
errorMsg = tr( "Error: qgis element could not be found" );
return false;
}
toggleScaleBasedVisibility( myRoot.attribute( "hasScaleBasedVisibilityFlag" ).toInt() == 1 );
setMinimumScale( myRoot.attribute( "minimumScale" ).toFloat() );
setMaximumScale( myRoot.attribute( "maximumScale" ).toFloat() );
if ( myRoot.isNull() )
{
errorMsg = tr( "Error: qgis element could not be found" );
return false;
}
toggleScaleBasedVisibility( myRoot.attribute( "hasScaleBasedVisibilityFlag" ).toInt() == 1 );
setMinimumScale( myRoot.attribute( "minimumScale" ).toFloat() );
setMaximumScale( myRoot.attribute( "maximumScale" ).toFloat() );

#if 0
//read transparency level
QDomNode transparencyNode = myRoot.namedItem( "transparencyLevelInt" );
if ( ! transparencyNode.isNull() )
{
// set transparency level only if it's in project
// (otherwise it sets the layer transparent)
QDomElement myElement = transparencyNode.toElement();
setTransparency( myElement.text().toInt() );
}
#endif
#if 0
//read transparency level
QDomNode transparencyNode = myRoot.namedItem( "transparencyLevelInt" );
if ( ! transparencyNode.isNull() )
{
// set transparency level only if it's in project
// (otherwise it sets the layer transparent)
QDomElement myElement = transparencyNode.toElement();
setTransparency( myElement.text().toInt() );
}
#endif

return readSymbology( myRoot, errorMsg );
return readSymbology( myRoot, errorMsg );
}
19 changes: 9 additions & 10 deletions src/core/qgsvectorlayer.h
Expand Up @@ -22,7 +22,6 @@
#include <QSet>
#include <QList>
#include <QStringList>
#include <QVector>

#include "qgis.h"
#include "qgsmaplayer.h"
Expand Down Expand Up @@ -707,14 +706,14 @@ class CORE_EXPORT QgsVectorLayer : public QgsMapLayer

/**
* 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 ids the list in which will be stored the style db ids
* @param names the list in which will be stored the style names
* @param descriptions the list 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 );
virtual int listStylesInDatabase( QStringList &ids, QStringList &names,
QStringList &descriptions, QString &msgError );

/**
* Will return the named style corresponding to style id provided
Expand All @@ -735,7 +734,7 @@ class CORE_EXPORT QgsVectorLayer : public QgsMapLayer
*/
virtual QString loadNamedStyle( const QString theURI, bool &theResultFlag );

virtual bool applyNamedStyle(QString namedStyle , QString errorMsg);
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
Expand Down Expand Up @@ -1281,15 +1280,15 @@ class CORE_EXPORT QgsVectorLayer : public QgsMapLayer
signals:

/**
* This signal is emited when selection was changed
* This signal is emitted when selection was changed
*
* @param selected Newly selected feature ids
* @param deselected Ids of all features which have previously been selected but are not any more
* @param clearAndSelect In case this is set to true, the old selection was dismissed and the new selection corresponds to selected
*/
void selectionChanged( const QgsFeatureIds selected, const QgsFeatureIds deselected, const bool clearAndSelect );

/** This signal is emited when selection was changed */
/** This signal is emitted when selection was changed */
void selectionChanged();

/** This signal is emitted when modifications has been done on layer */
Expand All @@ -1298,7 +1297,7 @@ class CORE_EXPORT QgsVectorLayer : public QgsMapLayer
/** Is emitted, when editing on this layer has started*/
void editingStarted();

/** Is emitted, when edited changes succesfully have been written to the data provider */
/** Is emitted, when edited changes successfully have been written to the data provider */
void editingStopped();

/** Is emitted, before changes are commited to the data provider */
Expand Down

0 comments on commit 576102b

Please sign in to comment.