From a29f2ba5a1c1567d3b61af4ef7ab3d5e52247f5c Mon Sep 17 00:00:00 2001 From: Larry Shaffer Date: Tue, 4 Jun 2013 15:57:37 -0600 Subject: [PATCH] Fix for #7993 again, fields are listed twice in labeling data defined menu - Reverts 0192e37 - Move code from init() to ctor for fix and to ensure connections are not duplicated - New code also fixes previously unknown issue when loading .qml style --- src/gui/qgsdatadefinedbutton.cpp | 98 ++++++++++++++++---------------- src/gui/qgsdatadefinedbutton.h | 3 +- 2 files changed, 52 insertions(+), 49 deletions(-) diff --git a/src/gui/qgsdatadefinedbutton.cpp b/src/gui/qgsdatadefinedbutton.cpp index 3957c950a9d..ac923e06843 100644 --- a/src/gui/qgsdatadefinedbutton.cpp +++ b/src/gui/qgsdatadefinedbutton.cpp @@ -42,6 +42,51 @@ QgsDataDefinedButton::QgsDataDefinedButton( QWidget* parent, QString description ) : QToolButton( parent ) { + // set up static icons + if ( mIconDataDefine.isNull() ) + { + mIconDataDefine = QgsApplication::getThemeIcon( "/mIconDataDefine.svg" ); + mIconDataDefineOn = QgsApplication::getThemeIcon( "/mIconDataDefineOn.svg" ); + mIconDataDefineError = QgsApplication::getThemeIcon( "/mIconDataDefineError.svg" ); + mIconDataDefineExpression = QgsApplication::getThemeIcon( "/mIconDataDefineExpression.svg" ); + mIconDataDefineExpressionOn = QgsApplication::getThemeIcon( "/mIconDataDefineExpressionOn.svg" ); + mIconDataDefineExpressionError = QgsApplication::getThemeIcon( "/mIconDataDefineExpressionError.svg" ); + } + + // set default tool button icon properties + setFixedSize( 28, 24 ); + setStyleSheet( QString( "QToolButton{ background: none; border: none;}" ) ); + setIconSize( QSize( 24, 24 ) ); + setPopupMode( QToolButton::InstantPopup ); + + mDefineMenu = new QMenu( this ); + connect( mDefineMenu, SIGNAL( aboutToShow() ), this, SLOT( aboutToShowMenu() ) ); + connect( mDefineMenu, SIGNAL( triggered( QAction* ) ), this, SLOT( menuActionTriggered( QAction* ) ) ); + setMenu( mDefineMenu ); + + mFieldsMenu = new QMenu( this ); + + mActionDataTypes = new QAction( this ); + // list fields and types in submenu, since there may be many + mActionDataTypes->setMenu( mFieldsMenu ); + + mActionActive = new QAction( this ); + QFont f = mActionActive->font(); + f.setBold( true ); + mActionActive->setFont( f ); + + mActionDescription = new QAction( tr( "Description..." ), this ); + + mActionExpDialog = new QAction( tr( "Edit..." ), this ); + mActionExpression = 0; + mActionPasteExpr = new QAction( tr( "Paste" ), this ); + mActionCopyExpr = new QAction( tr( "Copy" ), this ); + mActionClearExpr = new QAction( tr( "Clear" ), this ); + + // set up sibling widget connections + connect( this, SIGNAL( dataDefinedActivated( bool ) ), this, SLOT( disableEnabledWidgets( bool ) ) ); + connect( this, SIGNAL( dataDefinedActivated( bool ) ), this, SLOT( checkCheckedWidgets( bool ) ) ); + init( vl, datadefined, datatypes, description ); } @@ -74,49 +119,15 @@ void QgsDataDefinedButton::init( const QgsVectorLayer* vl, } mDataTypes = datatypes; + mFieldNameList.clear(); + mFieldTypeList.clear(); + mInputDescription = description; mFullDescription = QString( "" ); mUsageInfo = QString( "" ); mCurrentDefinition = QString( "" ); - mActionExpression = 0; - - if ( mIconDataDefine.isNull() ) - { - mIconDataDefine = QgsApplication::getThemeIcon( "/mIconDataDefine.svg" ); - mIconDataDefineOn = QgsApplication::getThemeIcon( "/mIconDataDefineOn.svg" ); - mIconDataDefineError = QgsApplication::getThemeIcon( "/mIconDataDefineError.svg" ); - mIconDataDefineExpression = QgsApplication::getThemeIcon( "/mIconDataDefineExpression.svg" ); - mIconDataDefineExpressionOn = QgsApplication::getThemeIcon( "/mIconDataDefineExpressionOn.svg" ); - mIconDataDefineExpressionError = QgsApplication::getThemeIcon( "/mIconDataDefineExpressionError.svg" ); - } - - // set default icon properties - setFixedSize( 28, 24 ); - setStyleSheet( QString( "QToolButton{ background: none; border: none;}" ) ); - setIconSize( QSize( 24, 24 ) ); - setPopupMode( QToolButton::InstantPopup ); - - mDefineMenu = new QMenu( this ); - connect( mDefineMenu, SIGNAL( aboutToShow() ), this, SLOT( aboutToShowMenu() ) ); - connect( mDefineMenu, SIGNAL( triggered( QAction* ) ), this, SLOT( menuActionTriggered( QAction* ) ) ); - - mFieldsMenu = new QMenu( this ); - - mActionActive = new QAction( this ); - QFont f = mActionActive->font(); - f.setBold( true ); - mActionActive->setFont( f ); - - mActionDescription = new QAction( tr( "Description..." ), this ); - - mActionExpDialog = new QAction( tr( "Edit..." ), this ); - mActionPasteExpr = new QAction( tr( "Paste" ), this ); - mActionCopyExpr = new QAction( tr( "Copy" ), this ); - mActionClearExpr = new QAction( tr( "Clear" ), this ); - // set up data types string - mActionDataTypes = 0; mDataTypesString = QString( "" ); QStringList ts; @@ -136,7 +147,7 @@ void QgsDataDefinedButton::init( const QgsVectorLayer* vl, if ( !ts.isEmpty() ) { mDataTypesString = ts.join( ", " ); - mActionDataTypes = new QAction( tr( "Field type: " ) + mDataTypesString, this ); + mActionDataTypes->setText( tr( "Field type: " ) + mDataTypesString ); } if ( mVectorLayer ) @@ -176,12 +187,6 @@ void QgsDataDefinedButton::init( const QgsVectorLayer* vl, } } - setMenu( mDefineMenu ); - - // set up sibling widget connections - connect( this, SIGNAL( dataDefinedActivated( bool ) ), this, SLOT( disableEnabledWidgets( bool ) ) ); - connect( this, SIGNAL( dataDefinedActivated( bool ) ), this, SLOT( checkCheckedWidgets( bool ) ) ); - updateGui(); } @@ -243,7 +248,7 @@ void QgsDataDefinedButton::aboutToShowMenu() mDefineMenu->addSeparator(); - if ( mActionDataTypes ) + if ( !mDataTypesString.isEmpty() ) { QAction* fieldTitleAct = mDefineMenu->addAction( tr( "Attribute field" ) ); fieldTitleAct->setFont( titlefont ); @@ -274,9 +279,6 @@ void QgsDataDefinedButton::aboutToShowMenu() act->setEnabled( false ); } - // list fields and types in submenu, since there may be many - mActionDataTypes->setMenu( mFieldsMenu ); - mDefineMenu->addSeparator(); } diff --git a/src/gui/qgsdatadefinedbutton.h b/src/gui/qgsdatadefinedbutton.h index a9c93d4805f..421596958c2 100644 --- a/src/gui/qgsdatadefinedbutton.h +++ b/src/gui/qgsdatadefinedbutton.h @@ -250,7 +250,9 @@ class GUI_EXPORT QgsDataDefinedButton: public QToolButton QMap< QString, QString > mProperty; QList< QPointer > mEnabledWidgets; QList< QPointer > mCheckedWidgets; + QMenu* mDefineMenu; + QAction* mActionDataTypes; QMenu* mFieldsMenu; QAction* mActionActive; @@ -260,7 +262,6 @@ class GUI_EXPORT QgsDataDefinedButton: public QToolButton QAction* mActionPasteExpr; QAction* mActionCopyExpr; QAction* mActionClearExpr; - QAction* mActionDataTypes; DataTypes mDataTypes; QString mDataTypesString;