Skip to content

Commit

Permalink
Use QgsFieldCombo for map tip field combo boxes
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Feb 17, 2016
1 parent b6c2529 commit cbc830b
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 40 deletions.
29 changes: 9 additions & 20 deletions src/app/qgsvectorlayerproperties.cpp
Expand Up @@ -111,6 +111,8 @@ QgsVectorLayerProperties::QgsVectorLayerProperties(

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

fieldComboBox->setLayer( lyr );
displayFieldComboBox->setLayer( lyr );
connect( insertFieldButton, SIGNAL( clicked() ), this, SLOT( insertField() ) );
connect( insertExpressionButton, SIGNAL( clicked() ), this, SLOT( insertExpression() ) );

Expand Down Expand Up @@ -332,14 +334,10 @@ void QgsVectorLayerProperties::insertField()
{
// Convert the selected field to an expression and
// insert it into the action at the cursor position

if ( !fieldComboBox->currentText().isNull() )
{
QString field = "[% \"";
field += fieldComboBox->currentText();
field += "\" %]";
htmlMapTip->insertPlainText( field );
}
QString field = "[% \"";
field += fieldComboBox->currentField();
field += "\" %]";
htmlMapTip->insertPlainText( field );
}

void QgsVectorLayerProperties::insertExpression()
Expand Down Expand Up @@ -373,16 +371,15 @@ void QgsVectorLayerProperties::insertExpression()

void QgsVectorLayerProperties::setDisplayField( const QString& name )
{
int idx = displayFieldComboBox->findText( name );
if ( idx == -1 )
if ( layer->fields().fieldNameIndex( name ) == -1 )
{
htmlRadio->setChecked( true );
htmlMapTip->setPlainText( name );
}
else
{
fieldComboRadio->setChecked( true );
displayFieldComboBox->setCurrentIndex( idx );
displayFieldComboBox->setField( name );
}
}

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

//get field list for display field combo
const QgsFields& myFields = layer->fields();
for ( int idx = 0; idx < myFields.count(); ++idx )
{
displayFieldComboBox->addItem( myFields[idx].name() );
fieldComboBox->addItem( myFields[idx].name() );
}

setDisplayField( layer->displayField() );

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

if ( fieldComboRadio->isChecked() )
{
layer->setDisplayField( displayFieldComboBox->currentText() );
layer->setDisplayField( displayFieldComboBox->currentField() );
}

actionDialog->apply();
Expand Down
46 changes: 26 additions & 20 deletions src/ui/qgsvectorlayerpropertiesbase.ui
Expand Up @@ -273,7 +273,7 @@
</sizepolicy>
</property>
<property name="currentIndex">
<number>0</number>
<number>6</number>
</property>
<widget class="QWidget" name="mOptsPage_General">
<layout class="QVBoxLayout" name="verticalLayout_14">
Expand Down Expand Up @@ -302,8 +302,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>730</width>
<height>537</height>
<width>331</width>
<height>431</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_13">
Expand Down Expand Up @@ -600,8 +600,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>730</width>
<height>537</height>
<width>100</width>
<height>30</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_18">
Expand Down Expand Up @@ -701,8 +701,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>730</width>
<height>537</height>
<width>123</width>
<height>38</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_28">
Expand Down Expand Up @@ -783,8 +783,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>730</width>
<height>537</height>
<width>100</width>
<height>30</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_20">
Expand Down Expand Up @@ -843,8 +843,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>730</width>
<height>537</height>
<width>721</width>
<height>199</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_32">
Expand Down Expand Up @@ -1022,7 +1022,7 @@
<item>
<widget class="QGroupBox" name="groupBox_2">
<property name="title">
<string>Map Tip display text</string>
<string>Map tip display text</string>
</property>
<property name="syncGroup" stdset="0">
<string notr="true">vectordisplay</string>
Expand Down Expand Up @@ -1066,7 +1066,7 @@
</spacer>
</item>
<item>
<widget class="QComboBox" name="fieldComboBox">
<widget class="QgsFieldComboBox" name="fieldComboBox">
<property name="enabled">
<bool>false</bool>
</property>
Expand Down Expand Up @@ -1139,7 +1139,7 @@
</layout>
</item>
<item row="1" column="2">
<widget class="QComboBox" name="displayFieldComboBox">
<widget class="QgsFieldComboBox" name="displayFieldComboBox">
<property name="enabled">
<bool>false</bool>
</property>
Expand Down Expand Up @@ -1181,8 +1181,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>730</width>
<height>537</height>
<width>100</width>
<height>30</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_21">
Expand Down Expand Up @@ -1247,8 +1247,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>730</width>
<height>537</height>
<width>134</width>
<height>113</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_23">
Expand Down Expand Up @@ -1415,8 +1415,8 @@
<property name="geometry">
<rect>
<x>0</x>
<y>-104</y>
<width>714</width>
<y>0</y>
<width>393</width>
<height>641</height>
</rect>
</property>
Expand Down Expand Up @@ -1916,6 +1916,12 @@
<header location="global">qgsvariableeditorwidget.h</header>
<container>1</container>
</customwidget>
<customwidget>
<class>QgsFieldComboBox</class>
<extends>QComboBox</extends>
<header>qgsfieldcombobox.h</header>
<container>1</container>
</customwidget>
</customwidgets>
<tabstops>
<tabstop>mOptionsListWidget</tabstop>
Expand Down

0 comments on commit cbc830b

Please sign in to comment.