@@ -76,6 +76,7 @@ void QgsDataDefinedButton::init( const QgsVectorLayer* vl,
76
76
mDataTypes = datatypes;
77
77
mInputDescription = description;
78
78
mFullDescription = QString ( " " );
79
+ mUsageInfo = QString ( " " );
79
80
mCurrentDefinition = QString ( " " );
80
81
81
82
mActionExpression = 0 ;
@@ -109,9 +110,10 @@ void QgsDataDefinedButton::init( const QgsVectorLayer* vl,
109
110
110
111
mActionDescription = new QAction ( tr ( " Description..." ), this );
111
112
112
- mActionExpDialog = new QAction ( tr ( " Edit expression..." ), this );
113
-
114
- mActionCopyExpr = new QAction ( tr ( " Copy expression" ), this );
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 );
115
117
116
118
// set up data types string
117
119
mActionDataTypes = 0 ;
@@ -120,21 +122,21 @@ void QgsDataDefinedButton::init( const QgsVectorLayer* vl,
120
122
QStringList ts;
121
123
if ( mDataTypes .testFlag ( AnyType ) || mDataTypes .testFlag ( String ) )
122
124
{
123
- ts << tr ( " String " );
125
+ ts << tr ( " string " );
124
126
}
125
127
if ( mDataTypes .testFlag ( AnyType ) || mDataTypes .testFlag ( Int ) )
126
128
{
127
- ts << tr ( " Int " );
129
+ ts << tr ( " int " );
128
130
}
129
131
if ( mDataTypes .testFlag ( AnyType ) || mDataTypes .testFlag ( Double ) )
130
132
{
131
- ts << tr ( " Double " );
133
+ ts << tr ( " double " );
132
134
}
133
135
134
136
if ( !ts.isEmpty () )
135
137
{
136
138
mDataTypesString = ts.join ( " , " );
137
- mActionDataTypes = new QAction ( tr ( " Field types : " ) + mDataTypesString , this );
139
+ mActionDataTypes = new QAction ( tr ( " Field type : " ) + mDataTypesString , this );
138
140
139
141
// list fields and types in submenu, since there may be many
140
142
mActionDataTypes ->setMenu ( mFieldsMenu );
@@ -208,6 +210,13 @@ void QgsDataDefinedButton::aboutToShowMenu()
208
210
209
211
bool hasExp = !getExpression ().isEmpty ();
210
212
bool hasField = !getField ().isEmpty ();
213
+ QString ddTitle = tr ( " Data defined override" );
214
+
215
+ QAction* ddTitleAct = mDefineMenu ->addAction ( ddTitle );
216
+ QFont titlefont = ddTitleAct->font ();
217
+ titlefont.setItalic ( true );
218
+ ddTitleAct->setFont ( titlefont );
219
+ ddTitleAct->setEnabled ( false );
211
220
212
221
bool addActiveAction = false ;
213
222
if ( useExpression () && hasExp )
@@ -222,36 +231,70 @@ void QgsDataDefinedButton::aboutToShowMenu()
222
231
addActiveAction = mFieldNameList .contains ( getField () );
223
232
}
224
233
225
- bool addTopSep = false ;
226
234
if ( addActiveAction )
227
235
{
236
+ ddTitleAct->setText ( ddTitle + " (" + ( useExpression () ? tr ( " expression" ) : tr ( " field" ) ) + " )" );
228
237
mDefineMenu ->addAction ( mActionActive );
229
238
mActionActive ->setText ( isActive () ? tr ( " Deactivate" ) : tr ( " Activate" ) );
230
239
mActionActive ->setData ( QVariant ( isActive () ? false : true ) );
231
- addTopSep = true ;
232
240
}
233
241
234
242
if ( !mFullDescription .isEmpty () )
235
243
{
236
244
mDefineMenu ->addAction ( mActionDescription );
237
- addTopSep = true ;
238
245
}
239
246
240
- if ( addTopSep )
247
+ mDefineMenu ->addSeparator ();
248
+
249
+ if ( mActionDataTypes )
241
250
{
251
+ QAction* fieldTitleAct = mDefineMenu ->addAction ( tr ( " Attribute field" ) );
252
+ fieldTitleAct->setFont ( titlefont );
253
+ fieldTitleAct->setEnabled ( false );
254
+
255
+ mDefineMenu ->addAction ( mActionDataTypes );
256
+
257
+ mFieldsMenu ->clear ();
258
+
259
+ if ( mFieldNameList .size () > 0 )
260
+ {
261
+
262
+ for ( int j = 0 ; j < mFieldNameList .count (); ++j )
263
+ {
264
+ QString fldname = mFieldNameList .at ( j );
265
+ QAction* act = mFieldsMenu ->addAction ( fldname + " (" + mFieldTypeList .at ( j ) + " )" );
266
+ act->setData ( QVariant ( fldname ) );
267
+ if ( getField () == fldname )
268
+ {
269
+ act->setCheckable ( true );
270
+ act->setChecked ( !useExpression () );
271
+ }
272
+ }
273
+ }
274
+ else
275
+ {
276
+ QAction* act = mFieldsMenu ->addAction ( tr ( " No matching field types found" ) );
277
+ act->setEnabled ( false );
278
+ }
279
+
242
280
mDefineMenu ->addSeparator ();
243
281
}
244
282
245
- mDefineMenu ->addAction ( mActionExpDialog );
283
+ QAction* exprTitleAct = mDefineMenu ->addAction ( tr ( " Expression" ) );
284
+ exprTitleAct->setFont ( titlefont );
285
+ exprTitleAct->setEnabled ( false );
246
286
247
287
if ( hasExp )
248
288
{
249
289
QString expString = getExpression ();
250
- if ( expString.length () > 100 )
290
+ if ( expString.length () > 35 )
251
291
{
252
- expString.truncate ( 100 );
292
+ expString.truncate ( 35 );
253
293
expString.append ( " ..." );
254
294
}
295
+
296
+ expString.prepend ( tr ( " Current: " ) );
297
+
255
298
if ( !mActionExpression )
256
299
{
257
300
mActionExpression = new QAction ( expString, this );
@@ -261,34 +304,18 @@ void QgsDataDefinedButton::aboutToShowMenu()
261
304
{
262
305
mActionExpression ->setText ( expString );
263
306
}
264
-
265
- mDefineMenu ->addAction ( mActionCopyExpr );
266
307
mDefineMenu ->addAction ( mActionExpression );
267
308
mActionExpression ->setChecked ( useExpression () );
268
- }
269
309
270
- if ( mFieldNameList .size () > 0 )
310
+ mDefineMenu ->addAction ( mActionExpDialog );
311
+ mDefineMenu ->addAction ( mActionCopyExpr );
312
+ mDefineMenu ->addAction ( mActionPasteExpr );
313
+ mDefineMenu ->addAction ( mActionClearExpr );
314
+ }
315
+ else
271
316
{
272
- mDefineMenu ->addSeparator ();
273
-
274
- if ( mActionDataTypes )
275
- {
276
- mDefineMenu ->addAction ( mActionDataTypes );
277
- }
278
-
279
- mFieldsMenu ->clear ();
280
-
281
- for ( int j = 0 ; j < mFieldNameList .count (); ++j )
282
- {
283
- QString fldname = mFieldNameList .at ( j );
284
- QAction* act = mFieldsMenu ->addAction ( fldname + " (" + mFieldTypeList .at ( j ) + " )" );
285
- act->setData ( QVariant ( fldname ) );
286
- if ( getField () == fldname )
287
- {
288
- act->setCheckable ( true );
289
- act->setChecked ( !useExpression () );
290
- }
291
- }
317
+ mDefineMenu ->addAction ( mActionExpDialog );
318
+ mDefineMenu ->addAction ( mActionPasteExpr );
292
319
}
293
320
294
321
}
@@ -318,16 +345,41 @@ void QgsDataDefinedButton::menuActionTriggered( QAction* action )
318
345
{
319
346
QApplication::clipboard ()->setText ( getExpression () );
320
347
}
321
- else // a field name clicked
348
+ else if ( action == mActionPasteExpr )
322
349
{
323
- if ( getField () != action->text () )
350
+ QString exprString = QApplication::clipboard ()->text ();
351
+ if ( !exprString.isEmpty () )
324
352
{
325
- setField ( action->data ().toString () );
353
+ setExpression ( exprString );
354
+ setUseExpression ( true );
355
+ setActive ( true );
356
+ updateGui ();
326
357
}
327
- setUseExpression ( false );
328
- setActive ( true );
358
+ }
359
+ else if ( action == mActionClearExpr )
360
+ {
361
+ // only deactivate if defined expression is being used
362
+ if ( isActive () && useExpression () )
363
+ {
364
+ setUseExpression ( false );
365
+ setActive ( false );
366
+ }
367
+ setExpression ( QString ( " " ) );
329
368
updateGui ();
330
369
}
370
+ else if ( mFieldsMenu ->actions ().contains ( action ) ) // a field name clicked
371
+ {
372
+ if ( action->isEnabled () )
373
+ {
374
+ if ( getField () != action->text () )
375
+ {
376
+ setField ( action->data ().toString () );
377
+ }
378
+ setUseExpression ( false );
379
+ setActive ( true );
380
+ updateGui ();
381
+ }
382
+ }
331
383
}
332
384
333
385
void QgsDataDefinedButton::showDescriptionDialog ()
@@ -383,7 +435,7 @@ void QgsDataDefinedButton::updateGui()
383
435
{
384
436
setActive ( false );
385
437
icon = mIconDataDefineExpressionError ;
386
- deftip = tr ( " Expression parse error: %1" ).arg ( exp.parserErrorString () );
438
+ deftip = tr ( " Parse error: %1" ).arg ( exp.parserErrorString () );
387
439
newDef = " " ;
388
440
}
389
441
}
@@ -411,10 +463,15 @@ void QgsDataDefinedButton::updateGui()
411
463
}
412
464
413
465
// build full description for tool tip and popup dialog
414
- mFullDescription = QString ( " " );
466
+ mFullDescription = tr ( " <b><u>Data defined override</u></b><br> " );
415
467
416
468
mFullDescription += tr ( " <b>Active: </b>%1 <i>(ctrl|right-click toggles)</i><br>" ).arg ( isActive () ? tr ( " yes" ) : tr ( " no" ) );
417
469
470
+ if ( !mUsageInfo .isEmpty () )
471
+ {
472
+ mFullDescription += tr ( " <b>Usage:</b><br>%1<br>" ).arg ( mUsageInfo );
473
+ }
474
+
418
475
if ( !mInputDescription .isEmpty () )
419
476
{
420
477
mFullDescription += tr ( " <b>Expected input:</b><br>%1<br>" ).arg ( mInputDescription );
@@ -431,6 +488,13 @@ void QgsDataDefinedButton::updateGui()
431
488
deftype = QString ( " (%1)" ).arg ( useExpression () ? tr ( " expression" ) : tr ( " field" ) );
432
489
}
433
490
491
+ // truncate long expressions, or tool tip may be too wide for screen
492
+ if ( deftip.length () > 75 )
493
+ {
494
+ deftip.truncate ( 75 );
495
+ deftip.append ( " ..." );
496
+ }
497
+
434
498
mFullDescription += tr ( " <b>Current definition%1:</b><br>%2" ).arg ( deftype ).arg ( deftip );
435
499
436
500
setToolTip ( mFullDescription );
0 commit comments