|
32 | 32 | #include <QString>
|
33 | 33 | #include <QDomNode>
|
34 | 34 | #include <QVector>
|
35 |
| -#include <QMessageBox> |
36 | 35 |
|
37 | 36 | #include "qgsvectorlayer.h"
|
38 | 37 |
|
|
74 | 73 | #include "qgsdiagramrendererv2.h"
|
75 | 74 | #include "qgsstylev2.h"
|
76 | 75 | #include "qgssymbologyv2conversion.h"
|
| 76 | +#include "qgspallabeling.h" |
77 | 77 |
|
78 | 78 | #ifdef TESTPROVIDERLIB
|
79 | 79 | #include <dlfcn.h>
|
80 | 80 | #endif
|
81 | 81 |
|
82 | 82 | typedef bool saveStyle_t(
|
83 |
| - const QString& uri, |
84 |
| - const QString& qmlStyle, |
85 |
| - const QString& sldStyle, |
86 |
| - const QString& styleName, |
87 |
| - const QString& styleDescription, |
88 |
| - const QString& uiFileContent, |
89 |
| - bool useAsDefault, |
90 |
| - QString& errCause |
| 83 | + const QString& uri, |
| 84 | + const QString& qmlStyle, |
| 85 | + const QString& sldStyle, |
| 86 | + const QString& styleName, |
| 87 | + const QString& styleDescription, |
| 88 | + const QString& uiFileContent, |
| 89 | + bool useAsDefault, |
| 90 | + QString& errCause |
91 | 91 | );
|
92 | 92 |
|
93 | 93 | typedef QString loadStyle_t(
|
94 |
| - const QString& uri, |
95 |
| - QString& errCause |
| 94 | + const QString& uri, |
| 95 | + QString& errCause |
96 | 96 | );
|
97 | 97 |
|
98 | 98 | typedef int listStyles_t(
|
99 |
| - const QString& uri, |
100 |
| - QVector<QString> &ids, |
101 |
| - QVector<QString> &names, |
102 |
| - QVector<QString> &descriptions, |
103 |
| - QString& errCause |
| 99 | + const QString& uri, |
| 100 | + QStringList &ids, |
| 101 | + QStringList &names, |
| 102 | + QStringList &descriptions, |
| 103 | + QString& errCause |
104 | 104 | );
|
105 | 105 |
|
106 | 106 | typedef QString getStyleById_t(
|
107 |
| - const QString& uri, |
108 |
| - QString styleID, |
109 |
| - QString& errCause |
| 107 | + const QString& uri, |
| 108 | + QString styleID, |
| 109 | + QString& errCause |
110 | 110 | );
|
111 | 111 |
|
112 | 112 |
|
@@ -3731,151 +3731,152 @@ QDomElement QgsAttributeEditorField::toDomElement( QDomDocument& doc ) const
|
3731 | 3731 | return elem;
|
3732 | 3732 | }
|
3733 | 3733 |
|
3734 |
| -int QgsVectorLayer::listStylesInDatabase( QVector<QString> &ids, QVector<QString> &names, QVector<QString> &descriptions, QString &msgError ) |
| 3734 | +int QgsVectorLayer::listStylesInDatabase( QStringList &ids, QStringList &names, QStringList &descriptions, QString &msgError ) |
3735 | 3735 | {
|
3736 |
| - QgsProviderRegistry * pReg = QgsProviderRegistry::instance(); |
3737 |
| - QLibrary *myLib = pReg->providerLibrary( mProviderKey ); |
3738 |
| - if ( !myLib ) |
3739 |
| - { |
3740 |
| - msgError = QObject::tr( "Unable to load %1 provider" ).arg( mProviderKey ); |
3741 |
| - return -1; |
3742 |
| - } |
3743 |
| - listStyles_t* listStylesExternalMethod = ( listStyles_t * ) cast_to_fptr(myLib->resolve("listStyles")); |
| 3736 | + QgsProviderRegistry * pReg = QgsProviderRegistry::instance(); |
| 3737 | + QLibrary *myLib = pReg->providerLibrary( mProviderKey ); |
| 3738 | + if ( !myLib ) |
| 3739 | + { |
| 3740 | + msgError = QObject::tr( "Unable to load %1 provider" ).arg( mProviderKey ); |
| 3741 | + return -1; |
| 3742 | + } |
| 3743 | + listStyles_t* listStylesExternalMethod = ( listStyles_t * ) cast_to_fptr( myLib->resolve( "listStyles" ) ); |
3744 | 3744 |
|
3745 |
| - if ( !listStylesExternalMethod ) |
3746 |
| - { |
3747 |
| - delete myLib; |
3748 |
| - msgError = QObject::tr( "Provider %1 has no listStyles method" ).arg( mProviderKey ); |
3749 |
| - return -1; |
3750 |
| - } |
| 3745 | + if ( !listStylesExternalMethod ) |
| 3746 | + { |
| 3747 | + delete myLib; |
| 3748 | + msgError = QObject::tr( "Provider %1 has no %2 method" ).arg( mProviderKey ).arg( "listStyles" ); |
| 3749 | + return -1; |
| 3750 | + } |
3751 | 3751 |
|
3752 |
| - return listStylesExternalMethod(mDataSource, ids, names, descriptions, msgError); |
| 3752 | + return listStylesExternalMethod( mDataSource, ids, names, descriptions, msgError ); |
3753 | 3753 | }
|
3754 | 3754 |
|
3755 |
| -QString QgsVectorLayer::getStyleFromDatabase(QString styleId, QString &msgError) |
| 3755 | +QString QgsVectorLayer::getStyleFromDatabase( QString styleId, QString &msgError ) |
3756 | 3756 | {
|
3757 |
| - QgsProviderRegistry * pReg = QgsProviderRegistry::instance(); |
3758 |
| - QLibrary *myLib = pReg->providerLibrary( mProviderKey ); |
3759 |
| - if ( !myLib ) |
3760 |
| - { |
3761 |
| - msgError = QObject::tr( "Unable to load %1 provider" ).arg( mProviderKey ); |
3762 |
| - return QObject::tr( "" ); |
3763 |
| - } |
3764 |
| - getStyleById_t* getStyleByIdMethod = ( getStyleById_t * ) cast_to_fptr(myLib->resolve("getStyleById")); |
| 3757 | + QgsProviderRegistry * pReg = QgsProviderRegistry::instance(); |
| 3758 | + QLibrary *myLib = pReg->providerLibrary( mProviderKey ); |
| 3759 | + if ( !myLib ) |
| 3760 | + { |
| 3761 | + msgError = QObject::tr( "Unable to load %1 provider" ).arg( mProviderKey ); |
| 3762 | + return QObject::tr( "" ); |
| 3763 | + } |
| 3764 | + getStyleById_t* getStyleByIdMethod = ( getStyleById_t * ) cast_to_fptr( myLib->resolve( "getStyleById" ) ); |
3765 | 3765 |
|
3766 |
| - if ( !getStyleByIdMethod ) |
3767 |
| - { |
3768 |
| - delete myLib; |
3769 |
| - msgError = QObject::tr( "Provider %1 has no getStyleById method" ).arg( mProviderKey ); |
3770 |
| - return QObject::tr( "" ); |
3771 |
| - } |
| 3766 | + if ( !getStyleByIdMethod ) |
| 3767 | + { |
| 3768 | + delete myLib; |
| 3769 | + msgError = QObject::tr( "Provider %1 has no %2 method" ).arg( mProviderKey ).arg( "getStyleById" ); |
| 3770 | + return QObject::tr( "" ); |
| 3771 | + } |
3772 | 3772 |
|
3773 |
| - return getStyleByIdMethod( mDataSource, styleId, msgError ); |
| 3773 | + return getStyleByIdMethod( mDataSource, styleId, msgError ); |
3774 | 3774 | }
|
3775 | 3775 |
|
3776 | 3776 |
|
3777 |
| -void QgsVectorLayer::saveStyleToDatabase(QString name, QString description, |
3778 |
| - bool useAsDefault, QString uiFileContent, QString &msgError){ |
| 3777 | +void QgsVectorLayer::saveStyleToDatabase( QString name, QString description, |
| 3778 | + bool useAsDefault, QString uiFileContent, QString &msgError ) |
| 3779 | +{ |
3779 | 3780 |
|
3780 |
| - QString sldStyle, qmlStyle; |
3781 |
| - QgsProviderRegistry * pReg = QgsProviderRegistry::instance(); |
3782 |
| - QLibrary *myLib = pReg->providerLibrary( mProviderKey ); |
3783 |
| - if ( !myLib ) |
3784 |
| - { |
3785 |
| - msgError = QObject::tr( "Unable to load %1 provider" ).arg( mProviderKey ); |
3786 |
| - return; |
3787 |
| - } |
3788 |
| - saveStyle_t* saveStyleExternalMethod = ( saveStyle_t * ) cast_to_fptr(myLib->resolve("saveStyle")); |
| 3781 | + QString sldStyle, qmlStyle; |
| 3782 | + QgsProviderRegistry * pReg = QgsProviderRegistry::instance(); |
| 3783 | + QLibrary *myLib = pReg->providerLibrary( mProviderKey ); |
| 3784 | + if ( !myLib ) |
| 3785 | + { |
| 3786 | + msgError = QObject::tr( "Unable to load %1 provider" ).arg( mProviderKey ); |
| 3787 | + return; |
| 3788 | + } |
| 3789 | + saveStyle_t* saveStyleExternalMethod = ( saveStyle_t * ) cast_to_fptr( myLib->resolve( "saveStyle" ) ); |
3789 | 3790 |
|
3790 |
| - if ( !saveStyleExternalMethod ) |
3791 |
| - { |
3792 |
| - delete myLib; |
3793 |
| - msgError = QObject::tr( "Provider %1 has no saveStyle method" ).arg( mProviderKey ); |
3794 |
| - return; |
3795 |
| - } |
| 3791 | + if ( !saveStyleExternalMethod ) |
| 3792 | + { |
| 3793 | + delete myLib; |
| 3794 | + msgError = QObject::tr( "Provider %1 has no %2 method" ).arg( mProviderKey ).arg( "saveStyle" ); |
| 3795 | + return; |
| 3796 | + } |
3796 | 3797 |
|
3797 |
| - QDomDocument qmlDocument, sldDocument; |
3798 |
| - this->exportNamedStyle(qmlDocument, msgError); |
3799 |
| - if( !msgError.isNull() ) |
3800 |
| - { |
3801 |
| - return; |
3802 |
| - } |
3803 |
| - qmlStyle = qmlDocument.toString(); |
| 3798 | + QDomDocument qmlDocument, sldDocument; |
| 3799 | + this->exportNamedStyle( qmlDocument, msgError ); |
| 3800 | + if ( !msgError.isNull() ) |
| 3801 | + { |
| 3802 | + return; |
| 3803 | + } |
| 3804 | + qmlStyle = qmlDocument.toString(); |
3804 | 3805 |
|
3805 |
| - this->exportSldStyle(sldDocument, msgError); |
3806 |
| - if( !msgError.isNull() ) |
3807 |
| - { |
3808 |
| - return; |
3809 |
| - } |
3810 |
| - sldStyle = sldDocument.toString(); |
| 3806 | + this->exportSldStyle( sldDocument, msgError ); |
| 3807 | + if ( !msgError.isNull() ) |
| 3808 | + { |
| 3809 | + return; |
| 3810 | + } |
| 3811 | + sldStyle = sldDocument.toString(); |
3811 | 3812 |
|
3812 |
| - saveStyleExternalMethod( mDataSource, qmlStyle, sldStyle, name, |
3813 |
| - description, uiFileContent, useAsDefault, msgError ); |
| 3813 | + saveStyleExternalMethod( mDataSource, qmlStyle, sldStyle, name, |
| 3814 | + description, uiFileContent, useAsDefault, msgError ); |
3814 | 3815 | }
|
3815 | 3816 |
|
3816 | 3817 |
|
3817 | 3818 |
|
3818 | 3819 | QString QgsVectorLayer::loadNamedStyle( const QString theURI, bool &theResultFlag )
|
3819 | 3820 | {
|
3820 |
| - return loadNamedStyle( theURI, theResultFlag, false ); |
| 3821 | + return loadNamedStyle( theURI, theResultFlag, false ); |
3821 | 3822 | }
|
3822 | 3823 |
|
3823 | 3824 | QString QgsVectorLayer::loadNamedStyle( const QString theURI, bool &theResultFlag , bool loadFromLocalDB )
|
3824 | 3825 | {
|
3825 |
| - QgsDataSourceURI dsUri( theURI ); |
3826 |
| - if ( !loadFromLocalDB && !dsUri.database().isEmpty() ) |
| 3826 | + QgsDataSourceURI dsUri( theURI ); |
| 3827 | + if ( !loadFromLocalDB && !dsUri.database().isEmpty() ) |
| 3828 | + { |
| 3829 | + QgsProviderRegistry * pReg = QgsProviderRegistry::instance(); |
| 3830 | + QLibrary *myLib = pReg->providerLibrary( mProviderKey ); |
| 3831 | + if ( myLib ) |
3827 | 3832 | {
|
3828 |
| - QgsProviderRegistry * pReg = QgsProviderRegistry::instance(); |
3829 |
| - QLibrary *myLib = pReg->providerLibrary( mProviderKey ); |
3830 |
| - if ( myLib ) |
| 3833 | + loadStyle_t* loadStyleExternalMethod = ( loadStyle_t * ) cast_to_fptr( myLib->resolve( "loadStyle" ) ); |
| 3834 | + if ( loadStyleExternalMethod ) |
| 3835 | + { |
| 3836 | + QString qml, errorMsg; |
| 3837 | + qml = loadStyleExternalMethod( mDataSource, errorMsg ); |
| 3838 | + if ( !qml.isEmpty() ) |
3831 | 3839 | {
|
3832 |
| - loadStyle_t* loadStyleExternalMethod = ( loadStyle_t * ) cast_to_fptr( myLib->resolve( "loadStyle" ) ); |
3833 |
| - if ( loadStyleExternalMethod ) |
3834 |
| - { |
3835 |
| - QString qml, errorMsg; |
3836 |
| - qml = loadStyleExternalMethod( mDataSource, errorMsg ); |
3837 |
| - if( !qml.isEmpty() ) |
3838 |
| - { |
3839 |
| - theResultFlag = this->applyNamedStyle( qml, errorMsg ); |
3840 |
| - } |
3841 |
| - } |
| 3840 | + theResultFlag = this->applyNamedStyle( qml, errorMsg ); |
3842 | 3841 | }
|
3843 |
| - |
3844 |
| - } |
3845 |
| - if( !theResultFlag ) |
3846 |
| - { |
3847 |
| - return QgsMapLayer::loadNamedStyle( theURI, theResultFlag ); |
| 3842 | + } |
3848 | 3843 | }
|
3849 |
| - return QObject::tr( "Loaded from Provider" ); |
| 3844 | + |
| 3845 | + } |
| 3846 | + if ( !theResultFlag ) |
| 3847 | + { |
| 3848 | + return QgsMapLayer::loadNamedStyle( theURI, theResultFlag ); |
| 3849 | + } |
| 3850 | + return QObject::tr( "Loaded from Provider" ); |
3850 | 3851 | }
|
3851 | 3852 |
|
3852 |
| -bool QgsVectorLayer::applyNamedStyle(QString namedStyle, QString errorMsg ) |
| 3853 | +bool QgsVectorLayer::applyNamedStyle( QString namedStyle, QString errorMsg ) |
3853 | 3854 | {
|
3854 |
| - QDomDocument myDocument( "qgis" ); |
3855 |
| - myDocument.setContent( namedStyle ); |
| 3855 | + QDomDocument myDocument( "qgis" ); |
| 3856 | + myDocument.setContent( namedStyle ); |
3856 | 3857 |
|
3857 |
| - QDomElement myRoot = myDocument.firstChildElement( "qgis" ); |
| 3858 | + QDomElement myRoot = myDocument.firstChildElement( "qgis" ); |
3858 | 3859 |
|
3859 |
| - if( myRoot.isNull() ) |
3860 |
| - { |
3861 |
| - errorMsg = tr( "Error: qgis element could not be found" ); |
3862 |
| - return false; |
3863 |
| - } |
3864 |
| - toggleScaleBasedVisibility( myRoot.attribute( "hasScaleBasedVisibilityFlag" ).toInt() == 1 ); |
3865 |
| - setMinimumScale( myRoot.attribute( "minimumScale" ).toFloat() ); |
3866 |
| - setMaximumScale( myRoot.attribute( "maximumScale" ).toFloat() ); |
| 3860 | + if ( myRoot.isNull() ) |
| 3861 | + { |
| 3862 | + errorMsg = tr( "Error: qgis element could not be found" ); |
| 3863 | + return false; |
| 3864 | + } |
| 3865 | + toggleScaleBasedVisibility( myRoot.attribute( "hasScaleBasedVisibilityFlag" ).toInt() == 1 ); |
| 3866 | + setMinimumScale( myRoot.attribute( "minimumScale" ).toFloat() ); |
| 3867 | + setMaximumScale( myRoot.attribute( "maximumScale" ).toFloat() ); |
3867 | 3868 |
|
3868 |
| - #if 0 |
3869 |
| - //read transparency level |
3870 |
| - QDomNode transparencyNode = myRoot.namedItem( "transparencyLevelInt" ); |
3871 |
| - if ( ! transparencyNode.isNull() ) |
3872 |
| - { |
3873 |
| - // set transparency level only if it's in project |
3874 |
| - // (otherwise it sets the layer transparent) |
3875 |
| - QDomElement myElement = transparencyNode.toElement(); |
3876 |
| - setTransparency( myElement.text().toInt() ); |
3877 |
| - } |
3878 |
| - #endif |
| 3869 | +#if 0 |
| 3870 | + //read transparency level |
| 3871 | + QDomNode transparencyNode = myRoot.namedItem( "transparencyLevelInt" ); |
| 3872 | + if ( ! transparencyNode.isNull() ) |
| 3873 | + { |
| 3874 | + // set transparency level only if it's in project |
| 3875 | + // (otherwise it sets the layer transparent) |
| 3876 | + QDomElement myElement = transparencyNode.toElement(); |
| 3877 | + setTransparency( myElement.text().toInt() ); |
| 3878 | + } |
| 3879 | +#endif |
3879 | 3880 |
|
3880 |
| - return readSymbology( myRoot, errorMsg ); |
| 3881 | + return readSymbology( myRoot, errorMsg ); |
3881 | 3882 | }
|
0 commit comments