Skip to content

Commit a29f2ba

Browse files
committedJun 4, 2013
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
1 parent 5d68c30 commit a29f2ba

File tree

2 files changed

+52
-49
lines changed

2 files changed

+52
-49
lines changed
 

‎src/gui/qgsdatadefinedbutton.cpp

Lines changed: 50 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,51 @@ QgsDataDefinedButton::QgsDataDefinedButton( QWidget* parent,
4242
QString description )
4343
: QToolButton( parent )
4444
{
45+
// set up static icons
46+
if ( mIconDataDefine.isNull() )
47+
{
48+
mIconDataDefine = QgsApplication::getThemeIcon( "/mIconDataDefine.svg" );
49+
mIconDataDefineOn = QgsApplication::getThemeIcon( "/mIconDataDefineOn.svg" );
50+
mIconDataDefineError = QgsApplication::getThemeIcon( "/mIconDataDefineError.svg" );
51+
mIconDataDefineExpression = QgsApplication::getThemeIcon( "/mIconDataDefineExpression.svg" );
52+
mIconDataDefineExpressionOn = QgsApplication::getThemeIcon( "/mIconDataDefineExpressionOn.svg" );
53+
mIconDataDefineExpressionError = QgsApplication::getThemeIcon( "/mIconDataDefineExpressionError.svg" );
54+
}
55+
56+
// set default tool button icon properties
57+
setFixedSize( 28, 24 );
58+
setStyleSheet( QString( "QToolButton{ background: none; border: none;}" ) );
59+
setIconSize( QSize( 24, 24 ) );
60+
setPopupMode( QToolButton::InstantPopup );
61+
62+
mDefineMenu = new QMenu( this );
63+
connect( mDefineMenu, SIGNAL( aboutToShow() ), this, SLOT( aboutToShowMenu() ) );
64+
connect( mDefineMenu, SIGNAL( triggered( QAction* ) ), this, SLOT( menuActionTriggered( QAction* ) ) );
65+
setMenu( mDefineMenu );
66+
67+
mFieldsMenu = new QMenu( this );
68+
69+
mActionDataTypes = new QAction( this );
70+
// list fields and types in submenu, since there may be many
71+
mActionDataTypes->setMenu( mFieldsMenu );
72+
73+
mActionActive = new QAction( this );
74+
QFont f = mActionActive->font();
75+
f.setBold( true );
76+
mActionActive->setFont( f );
77+
78+
mActionDescription = new QAction( tr( "Description..." ), this );
79+
80+
mActionExpDialog = new QAction( tr( "Edit..." ), this );
81+
mActionExpression = 0;
82+
mActionPasteExpr = new QAction( tr( "Paste" ), this );
83+
mActionCopyExpr = new QAction( tr( "Copy" ), this );
84+
mActionClearExpr = new QAction( tr( "Clear" ), this );
85+
86+
// set up sibling widget connections
87+
connect( this, SIGNAL( dataDefinedActivated( bool ) ), this, SLOT( disableEnabledWidgets( bool ) ) );
88+
connect( this, SIGNAL( dataDefinedActivated( bool ) ), this, SLOT( checkCheckedWidgets( bool ) ) );
89+
4590
init( vl, datadefined, datatypes, description );
4691
}
4792

@@ -74,49 +119,15 @@ void QgsDataDefinedButton::init( const QgsVectorLayer* vl,
74119
}
75120

76121
mDataTypes = datatypes;
122+
mFieldNameList.clear();
123+
mFieldTypeList.clear();
124+
77125
mInputDescription = description;
78126
mFullDescription = QString( "" );
79127
mUsageInfo = QString( "" );
80128
mCurrentDefinition = QString( "" );
81129

82-
mActionExpression = 0;
83-
84-
if ( mIconDataDefine.isNull() )
85-
{
86-
mIconDataDefine = QgsApplication::getThemeIcon( "/mIconDataDefine.svg" );
87-
mIconDataDefineOn = QgsApplication::getThemeIcon( "/mIconDataDefineOn.svg" );
88-
mIconDataDefineError = QgsApplication::getThemeIcon( "/mIconDataDefineError.svg" );
89-
mIconDataDefineExpression = QgsApplication::getThemeIcon( "/mIconDataDefineExpression.svg" );
90-
mIconDataDefineExpressionOn = QgsApplication::getThemeIcon( "/mIconDataDefineExpressionOn.svg" );
91-
mIconDataDefineExpressionError = QgsApplication::getThemeIcon( "/mIconDataDefineExpressionError.svg" );
92-
}
93-
94-
// set default icon properties
95-
setFixedSize( 28, 24 );
96-
setStyleSheet( QString( "QToolButton{ background: none; border: none;}" ) );
97-
setIconSize( QSize( 24, 24 ) );
98-
setPopupMode( QToolButton::InstantPopup );
99-
100-
mDefineMenu = new QMenu( this );
101-
connect( mDefineMenu, SIGNAL( aboutToShow() ), this, SLOT( aboutToShowMenu() ) );
102-
connect( mDefineMenu, SIGNAL( triggered( QAction* ) ), this, SLOT( menuActionTriggered( QAction* ) ) );
103-
104-
mFieldsMenu = new QMenu( this );
105-
106-
mActionActive = new QAction( this );
107-
QFont f = mActionActive->font();
108-
f.setBold( true );
109-
mActionActive->setFont( f );
110-
111-
mActionDescription = new QAction( tr( "Description..." ), this );
112-
113-
mActionExpDialog = new QAction( tr( "Edit..." ), this );
114-
mActionPasteExpr = new QAction( tr( "Paste" ), this );
115-
mActionCopyExpr = new QAction( tr( "Copy" ), this );
116-
mActionClearExpr = new QAction( tr( "Clear" ), this );
117-
118130
// set up data types string
119-
mActionDataTypes = 0;
120131
mDataTypesString = QString( "" );
121132

122133
QStringList ts;
@@ -136,7 +147,7 @@ void QgsDataDefinedButton::init( const QgsVectorLayer* vl,
136147
if ( !ts.isEmpty() )
137148
{
138149
mDataTypesString = ts.join( ", " );
139-
mActionDataTypes = new QAction( tr( "Field type: " ) + mDataTypesString, this );
150+
mActionDataTypes->setText( tr( "Field type: " ) + mDataTypesString );
140151
}
141152

142153
if ( mVectorLayer )
@@ -176,12 +187,6 @@ void QgsDataDefinedButton::init( const QgsVectorLayer* vl,
176187
}
177188
}
178189

179-
setMenu( mDefineMenu );
180-
181-
// set up sibling widget connections
182-
connect( this, SIGNAL( dataDefinedActivated( bool ) ), this, SLOT( disableEnabledWidgets( bool ) ) );
183-
connect( this, SIGNAL( dataDefinedActivated( bool ) ), this, SLOT( checkCheckedWidgets( bool ) ) );
184-
185190
updateGui();
186191
}
187192

@@ -243,7 +248,7 @@ void QgsDataDefinedButton::aboutToShowMenu()
243248

244249
mDefineMenu->addSeparator();
245250

246-
if ( mActionDataTypes )
251+
if ( !mDataTypesString.isEmpty() )
247252
{
248253
QAction* fieldTitleAct = mDefineMenu->addAction( tr( "Attribute field" ) );
249254
fieldTitleAct->setFont( titlefont );
@@ -274,9 +279,6 @@ void QgsDataDefinedButton::aboutToShowMenu()
274279
act->setEnabled( false );
275280
}
276281

277-
// list fields and types in submenu, since there may be many
278-
mActionDataTypes->setMenu( mFieldsMenu );
279-
280282
mDefineMenu->addSeparator();
281283
}
282284

‎src/gui/qgsdatadefinedbutton.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,9 @@ class GUI_EXPORT QgsDataDefinedButton: public QToolButton
250250
QMap< QString, QString > mProperty;
251251
QList< QPointer<QWidget> > mEnabledWidgets;
252252
QList< QPointer<QWidget> > mCheckedWidgets;
253+
253254
QMenu* mDefineMenu;
255+
QAction* mActionDataTypes;
254256
QMenu* mFieldsMenu;
255257

256258
QAction* mActionActive;
@@ -260,7 +262,6 @@ class GUI_EXPORT QgsDataDefinedButton: public QToolButton
260262
QAction* mActionPasteExpr;
261263
QAction* mActionCopyExpr;
262264
QAction* mActionClearExpr;
263-
QAction* mActionDataTypes;
264265

265266
DataTypes mDataTypes;
266267
QString mDataTypesString;

0 commit comments

Comments
 (0)
Please sign in to comment.