Skip to content

Commit cbc830b

Browse files
committed
Use QgsFieldCombo for map tip field combo boxes
1 parent b6c2529 commit cbc830b

File tree

2 files changed

+35
-40
lines changed

2 files changed

+35
-40
lines changed

src/app/qgsvectorlayerproperties.cpp

+9-20
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,8 @@ QgsVectorLayerProperties::QgsVectorLayerProperties(
111111

112112
connect( mOptionsStackedWidget, SIGNAL( currentChanged( int ) ), this, SLOT( mOptionsStackedWidget_CurrentChanged( int ) ) );
113113

114+
fieldComboBox->setLayer( lyr );
115+
displayFieldComboBox->setLayer( lyr );
114116
connect( insertFieldButton, SIGNAL( clicked() ), this, SLOT( insertField() ) );
115117
connect( insertExpressionButton, SIGNAL( clicked() ), this, SLOT( insertExpression() ) );
116118

@@ -332,14 +334,10 @@ void QgsVectorLayerProperties::insertField()
332334
{
333335
// Convert the selected field to an expression and
334336
// insert it into the action at the cursor position
335-
336-
if ( !fieldComboBox->currentText().isNull() )
337-
{
338-
QString field = "[% \"";
339-
field += fieldComboBox->currentText();
340-
field += "\" %]";
341-
htmlMapTip->insertPlainText( field );
342-
}
337+
QString field = "[% \"";
338+
field += fieldComboBox->currentField();
339+
field += "\" %]";
340+
htmlMapTip->insertPlainText( field );
343341
}
344342

345343
void QgsVectorLayerProperties::insertExpression()
@@ -373,16 +371,15 @@ void QgsVectorLayerProperties::insertExpression()
373371

374372
void QgsVectorLayerProperties::setDisplayField( const QString& name )
375373
{
376-
int idx = displayFieldComboBox->findText( name );
377-
if ( idx == -1 )
374+
if ( layer->fields().fieldNameIndex( name ) == -1 )
378375
{
379376
htmlRadio->setChecked( true );
380377
htmlMapTip->setPlainText( name );
381378
}
382379
else
383380
{
384381
fieldComboRadio->setChecked( true );
385-
displayFieldComboBox->setCurrentIndex( idx );
382+
displayFieldComboBox->setField( name );
386383
}
387384
}
388385

@@ -415,14 +412,6 @@ void QgsVectorLayerProperties::syncToLayer( void )
415412
pbnQueryBuilder->setToolTip( tr( "Stop editing mode to enable this." ) );
416413
}
417414

418-
//get field list for display field combo
419-
const QgsFields& myFields = layer->fields();
420-
for ( int idx = 0; idx < myFields.count(); ++idx )
421-
{
422-
displayFieldComboBox->addItem( myFields[idx].name() );
423-
fieldComboBox->addItem( myFields[idx].name() );
424-
}
425-
426415
setDisplayField( layer->displayField() );
427416

428417
// set up the scale based layer visibility stuff....
@@ -573,7 +562,7 @@ void QgsVectorLayerProperties::apply()
573562

574563
if ( fieldComboRadio->isChecked() )
575564
{
576-
layer->setDisplayField( displayFieldComboBox->currentText() );
565+
layer->setDisplayField( displayFieldComboBox->currentField() );
577566
}
578567

579568
actionDialog->apply();

src/ui/qgsvectorlayerpropertiesbase.ui

+26-20
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@
273273
</sizepolicy>
274274
</property>
275275
<property name="currentIndex">
276-
<number>0</number>
276+
<number>6</number>
277277
</property>
278278
<widget class="QWidget" name="mOptsPage_General">
279279
<layout class="QVBoxLayout" name="verticalLayout_14">
@@ -302,8 +302,8 @@
302302
<rect>
303303
<x>0</x>
304304
<y>0</y>
305-
<width>730</width>
306-
<height>537</height>
305+
<width>331</width>
306+
<height>431</height>
307307
</rect>
308308
</property>
309309
<layout class="QVBoxLayout" name="verticalLayout_13">
@@ -600,8 +600,8 @@
600600
<rect>
601601
<x>0</x>
602602
<y>0</y>
603-
<width>730</width>
604-
<height>537</height>
603+
<width>100</width>
604+
<height>30</height>
605605
</rect>
606606
</property>
607607
<layout class="QVBoxLayout" name="verticalLayout_18">
@@ -701,8 +701,8 @@
701701
<rect>
702702
<x>0</x>
703703
<y>0</y>
704-
<width>730</width>
705-
<height>537</height>
704+
<width>123</width>
705+
<height>38</height>
706706
</rect>
707707
</property>
708708
<layout class="QVBoxLayout" name="verticalLayout_28">
@@ -783,8 +783,8 @@
783783
<rect>
784784
<x>0</x>
785785
<y>0</y>
786-
<width>730</width>
787-
<height>537</height>
786+
<width>100</width>
787+
<height>30</height>
788788
</rect>
789789
</property>
790790
<layout class="QVBoxLayout" name="verticalLayout_20">
@@ -843,8 +843,8 @@
843843
<rect>
844844
<x>0</x>
845845
<y>0</y>
846-
<width>730</width>
847-
<height>537</height>
846+
<width>721</width>
847+
<height>199</height>
848848
</rect>
849849
</property>
850850
<layout class="QVBoxLayout" name="verticalLayout_32">
@@ -1022,7 +1022,7 @@
10221022
<item>
10231023
<widget class="QGroupBox" name="groupBox_2">
10241024
<property name="title">
1025-
<string>Map Tip display text</string>
1025+
<string>Map tip display text</string>
10261026
</property>
10271027
<property name="syncGroup" stdset="0">
10281028
<string notr="true">vectordisplay</string>
@@ -1066,7 +1066,7 @@
10661066
</spacer>
10671067
</item>
10681068
<item>
1069-
<widget class="QComboBox" name="fieldComboBox">
1069+
<widget class="QgsFieldComboBox" name="fieldComboBox">
10701070
<property name="enabled">
10711071
<bool>false</bool>
10721072
</property>
@@ -1139,7 +1139,7 @@
11391139
</layout>
11401140
</item>
11411141
<item row="1" column="2">
1142-
<widget class="QComboBox" name="displayFieldComboBox">
1142+
<widget class="QgsFieldComboBox" name="displayFieldComboBox">
11431143
<property name="enabled">
11441144
<bool>false</bool>
11451145
</property>
@@ -1181,8 +1181,8 @@
11811181
<rect>
11821182
<x>0</x>
11831183
<y>0</y>
1184-
<width>730</width>
1185-
<height>537</height>
1184+
<width>100</width>
1185+
<height>30</height>
11861186
</rect>
11871187
</property>
11881188
<layout class="QVBoxLayout" name="verticalLayout_21">
@@ -1247,8 +1247,8 @@
12471247
<rect>
12481248
<x>0</x>
12491249
<y>0</y>
1250-
<width>730</width>
1251-
<height>537</height>
1250+
<width>134</width>
1251+
<height>113</height>
12521252
</rect>
12531253
</property>
12541254
<layout class="QVBoxLayout" name="verticalLayout_23">
@@ -1415,8 +1415,8 @@
14151415
<property name="geometry">
14161416
<rect>
14171417
<x>0</x>
1418-
<y>-104</y>
1419-
<width>714</width>
1418+
<y>0</y>
1419+
<width>393</width>
14201420
<height>641</height>
14211421
</rect>
14221422
</property>
@@ -1916,6 +1916,12 @@
19161916
<header location="global">qgsvariableeditorwidget.h</header>
19171917
<container>1</container>
19181918
</customwidget>
1919+
<customwidget>
1920+
<class>QgsFieldComboBox</class>
1921+
<extends>QComboBox</extends>
1922+
<header>qgsfieldcombobox.h</header>
1923+
<container>1</container>
1924+
</customwidget>
19191925
</customwidgets>
19201926
<tabstops>
19211927
<tabstop>mOptionsListWidget</tabstop>

0 commit comments

Comments
 (0)