@@ -42,6 +42,51 @@ QgsDataDefinedButton::QgsDataDefinedButton( QWidget* parent,
42
42
QString description )
43
43
: QToolButton( parent )
44
44
{
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
+
45
90
init ( vl, datadefined, datatypes, description );
46
91
}
47
92
@@ -74,49 +119,15 @@ void QgsDataDefinedButton::init( const QgsVectorLayer* vl,
74
119
}
75
120
76
121
mDataTypes = datatypes;
122
+ mFieldNameList .clear ();
123
+ mFieldTypeList .clear ();
124
+
77
125
mInputDescription = description;
78
126
mFullDescription = QString ( " " );
79
127
mUsageInfo = QString ( " " );
80
128
mCurrentDefinition = QString ( " " );
81
129
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
-
118
130
// set up data types string
119
- mActionDataTypes = 0 ;
120
131
mDataTypesString = QString ( " " );
121
132
122
133
QStringList ts;
@@ -136,7 +147,7 @@ void QgsDataDefinedButton::init( const QgsVectorLayer* vl,
136
147
if ( !ts.isEmpty () )
137
148
{
138
149
mDataTypesString = ts.join ( " , " );
139
- mActionDataTypes = new QAction ( tr ( " Field type: " ) + mDataTypesString , this );
150
+ mActionDataTypes -> setText ( tr ( " Field type: " ) + mDataTypesString );
140
151
}
141
152
142
153
if ( mVectorLayer )
@@ -176,12 +187,6 @@ void QgsDataDefinedButton::init( const QgsVectorLayer* vl,
176
187
}
177
188
}
178
189
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
-
185
190
updateGui ();
186
191
}
187
192
@@ -243,7 +248,7 @@ void QgsDataDefinedButton::aboutToShowMenu()
243
248
244
249
mDefineMenu ->addSeparator ();
245
250
246
- if ( mActionDataTypes )
251
+ if ( ! mDataTypesString . isEmpty () )
247
252
{
248
253
QAction* fieldTitleAct = mDefineMenu ->addAction ( tr ( " Attribute field" ) );
249
254
fieldTitleAct->setFont ( titlefont );
@@ -274,9 +279,6 @@ void QgsDataDefinedButton::aboutToShowMenu()
274
279
act->setEnabled ( false );
275
280
}
276
281
277
- // list fields and types in submenu, since there may be many
278
- mActionDataTypes ->setMenu ( mFieldsMenu );
279
-
280
282
mDefineMenu ->addSeparator ();
281
283
}
282
284
0 commit comments