@@ -95,6 +95,10 @@ QgsVectorLayerProperties::QgsVectorLayerProperties(
95
95
connect ( layer, SIGNAL ( attributeAdded ( int ) ), this , SLOT ( attributeAdded ( int ) ) );
96
96
connect ( layer, SIGNAL ( attributeDeleted ( int ) ), this , SLOT ( attributeDeleted ( int ) ) );
97
97
98
+ connect ( insertFieldButton, SIGNAL ( clicked () ), this , SLOT ( insertField () ) );
99
+ connect ( insertExpressionButton, SIGNAL ( clicked () ), this , SLOT ( insertExpression () ) );
100
+
101
+
98
102
mAddAttributeButton ->setIcon ( QgsApplication::getThemeIcon ( " /mActionNewAttribute.png" ) );
99
103
mDeleteAttributeButton ->setIcon ( QgsApplication::getThemeIcon ( " /mActionDeleteAttribute.png" ) );
100
104
mToggleEditingButton ->setIcon ( QgsApplication::getThemeIcon ( " /mActionToggleEditing.png" ) );
@@ -481,9 +485,55 @@ void QgsVectorLayerProperties::setLegendType( QString type )
481
485
legendtypecombobox->setItemText ( legendtypecombobox->currentIndex (), type );
482
486
}
483
487
488
+ void QgsVectorLayerProperties::insertField ()
489
+ {
490
+ // Convert the selected field to an expression and
491
+ // insert it into the action at the cursor position
492
+
493
+ if ( !fieldComboBox->currentText ().isNull () )
494
+ {
495
+ QString field = " [% \" " ;
496
+ field += fieldComboBox->currentText ();
497
+ field += " \" %]" ;
498
+ htmlMapTip->insertPlainText ( field );
499
+ }
500
+ }
501
+
502
+ void QgsVectorLayerProperties::insertExpression ()
503
+ {
504
+ QString selText = htmlMapTip->textCursor ().selectedText ();
505
+
506
+ // edit the selected expression if there's one
507
+ if ( selText.startsWith ( " [%" ) && selText.endsWith ( " %]" ) )
508
+ selText = selText.mid ( 2 , selText.size () - 4 );
509
+
510
+ // display the expression builder
511
+ QgsExpressionBuilderDialog dlg ( layer , selText, this );
512
+ dlg.setWindowTitle ( tr ( " Insert expression" ) );
513
+ if ( dlg.exec () == QDialog::Accepted )
514
+ {
515
+ QString expression = dlg.expressionBuilder ()->expressionText ();
516
+ // Only add the expression if the user has entered some text.
517
+ if ( !expression.isEmpty () )
518
+ {
519
+ htmlMapTip->insertPlainText ( " [%" + expression + " %]" );
520
+ }
521
+ }
522
+ }
523
+
484
524
void QgsVectorLayerProperties::setDisplayField ( QString name )
485
525
{
486
- displayFieldComboBox->setItemText ( displayFieldComboBox->currentIndex (), name );
526
+ int idx = displayFieldComboBox->findText ( name );
527
+ if ( idx == -1 )
528
+ {
529
+ htmlRadio->setChecked ( true );
530
+ htmlMapTip->setPlainText ( name );
531
+ }
532
+ else
533
+ {
534
+ fieldComboRadio->setChecked ( true );
535
+ displayFieldComboBox->setCurrentIndex ( idx );
536
+ }
487
537
}
488
538
489
539
// ! @note in raster props, this method is called sync()
@@ -520,9 +570,10 @@ void QgsVectorLayerProperties::reset( void )
520
570
for ( QgsFieldMap::const_iterator it = myFields.begin (); it != myFields.end (); ++it )
521
571
{
522
572
displayFieldComboBox->addItem ( it->name () );
573
+ fieldComboBox->addItem ( it->name () );
523
574
}
524
- displayFieldComboBox-> setCurrentIndex ( displayFieldComboBox-> findText (
525
- layer->displayField () ) );
575
+
576
+ setDisplayField ( layer-> displayField () );
526
577
527
578
// set up the scale based layer visibility stuff....
528
579
chkUseScaleDependentRendering->setChecked ( layer->hasScaleBasedVisibility () );
@@ -633,7 +684,15 @@ void QgsVectorLayerProperties::apply()
633
684
}
634
685
635
686
// update the display field
636
- layer->setDisplayField ( displayFieldComboBox->currentText () );
687
+ if ( htmlRadio->isChecked () )
688
+ {
689
+ layer->setDisplayField ( htmlMapTip->toPlainText () );
690
+ }
691
+
692
+ if ( fieldComboRadio->isChecked () )
693
+ {
694
+ layer->setDisplayField ( displayFieldComboBox->currentText () );
695
+ }
637
696
638
697
layer->setEditForm ( leEditForm->text () );
639
698
layer->setEditFormInit ( leEditFormInit->text () );
0 commit comments