From 62e2c7cf1ff1f101c050cdbacaed855a3b6a99c4 Mon Sep 17 00:00:00 2001 From: g_j_m Date: Mon, 8 Nov 2004 09:10:32 +0000 Subject: [PATCH] Provide a UI in the vector layer properties dialog box to set the field used as the top level field in the Identify Results dialog box. The value is read from and written to .qgs files git-svn-id: http://svn.osgeo.org/qgis/trunk@2222 c8812cc2-4d05-0410-92ff-de0c093fc19c --- src/qgsdlgvectorlayerproperties.cpp | 28 +- src/qgsdlgvectorlayerproperties.h | 2 + src/qgsdlgvectorlayerpropertiesbase.ui | 945 +++++++++++++------------ src/qgsvectorlayer.cpp | 22 + src/qgsvectorlayer.h | 3 + 5 files changed, 545 insertions(+), 455 deletions(-) diff --git a/src/qgsdlgvectorlayerproperties.cpp b/src/qgsdlgvectorlayerproperties.cpp index 21cd0130d0f..d5f717b76c0 100644 --- a/src/qgsdlgvectorlayerproperties.cpp +++ b/src/qgsdlgvectorlayerproperties.cpp @@ -82,14 +82,20 @@ bufferRenderer(layer-> // QTextOStream (&ur) << extent->xMax() << ", " << extent->yMax(); lblUpperRight->setText(ur.sprintf("%16f, %16f", extent->xMax(), extent->yMax())); std::vector < QgsField > fields = dp->fields(); - // populate the table and the display field drop-down with the field information + // populate the table and the display field drop-down with the field + // information + + displayFieldComboBox->insertItem( "" ); for (int i = 0; i < fields.size(); i++) - { - QgsField fld = fields[i]; - QListViewItem *lvi = new QListViewItem(listViewFields, fld.name(), - fld.type(), QString("%1").arg(fld.length()), - QString("%1").arg(fld.precision())); - } + { + QgsField fld = fields[i]; + QListViewItem *lvi = new QListViewItem(listViewFields, fld.name(), + fld.type(), QString("%1").arg(fld.length()), + QString("%1").arg(fld.precision())); + displayFieldComboBox->insertItem( fld.name() ); + } + displayFieldComboBox->setCurrentItem(0); // the blank one + // set up the scale based layer visibility stuff.... chkUseScaleDependentRendering->setChecked(lyr->scaleBasedVisibility()); spinMinimumScale->setValue(lyr->minScale()); @@ -213,6 +219,9 @@ void QgsDlgVectorLayerProperties::apply() layer->setScaleBasedVisibility(chkUseScaleDependentRendering->isChecked()); layer->setMinScale(spinMinimumScale->value()); layer->setMaxScale(spinMaximumScale->value()); + + // update the display field + layer->setDisplayField(displayFieldComboBox->currentText()); if (rendererDirty) { @@ -306,6 +315,11 @@ void QgsDlgVectorLayerProperties::setLegendType(QString type) legendtypecombobox->setCurrentText(tr(type)); } +void QgsDlgVectorLayerProperties::setDisplayField(QString name) +{ + displayFieldComboBox->setCurrentText(name); +} + void QgsDlgVectorLayerProperties::reset( void ) { actionDialog->init(); diff --git a/src/qgsdlgvectorlayerproperties.h b/src/qgsdlgvectorlayerproperties.h index 96931027499..4a61577d3b6 100644 --- a/src/qgsdlgvectorlayerproperties.h +++ b/src/qgsdlgvectorlayerproperties.h @@ -40,6 +40,8 @@ class QgsDlgVectorLayerProperties : public QgsDlgVectorLayerPropertiesBase{ void setLegendType(QString type); /**Returns the display name entered in the dialog*/ QString displayName(); + /**Sets the attribute that is used in the Identify Results dialog box*/ + void setDisplayField(QString name); /**Sets the rendererDirty flag*/ void setRendererDirty(bool enabled=true); /**Returns a pointer to the bufferDialog*/ diff --git a/src/qgsdlgvectorlayerpropertiesbase.ui b/src/qgsdlgvectorlayerpropertiesbase.ui index 615b6cfe5dc..216f776c96a 100644 --- a/src/qgsdlgvectorlayerpropertiesbase.ui +++ b/src/qgsdlgvectorlayerpropertiesbase.ui @@ -1,4 +1,4 @@ - + QgsDlgVectorLayerPropertiesBase @@ -9,535 +9,584 @@ 0 0 689 - 588 + 592 Layer Properties - + unnamed - + - layout3 + layout9 - + unnamed - + - spacer2_2 - - - Horizontal - - - Expanding - - - - 185 - 29 - - - - - - btnApply - - - Apply + layout3 + + + unnamed + + + + spacer2_2 + + + Horizontal + + + Expanding + + + + 185 + 29 + + + + + + btnApply + + + Apply + + + + + btnClose + + + Close + + + + + spacer2 + + + Horizontal + + + Expanding + + + + 179 + 29 + + + + - + - btnClose + tabWidget2 - - Close + + Rounded - - - - spacer2 - - - Horizontal - - - Expanding - - - - 179 - 29 - - - - - - - - tabWidget2 - - - Rounded - - - - tab - - - Legend - - - - unnamed - - + - legendtypelabel - - - - 32767 - 22 - - - - Legend type: - - - - - widgetStackRenderers - - - - 7 - 7 - 0 - 0 - - - - - qt_dead_widget_singlesympage - - - 0 - - - - unnamed - - - - - - qt_dead_widget_continuoussympage - - - 1 - - - - unnamed - - - - - - qt_dead_widget_WStackPage - - - 2 - - - - - - legendtypecombobox - - - - 270 - 24 - - - - - 32767 - 22 - - - - - - - - tab - - - General - - - - unnamed - - - - groupBox1 - - - Fields + tab + + Legend + unnamed - - - - Field - - - true - - - true - - - - - Type - - - true - - - true - - - - - Length - - - true - - - true - - - - - Precision - - - true - - - true - - + - listViewFields + legendtypelabel - - Manual - - - AllColumns - - - - - - - groupBox2 - - - - 7 - 0 - 0 - 0 - - - - Features - - - - unnamed - - - - textLabel6_2 - - - Count - - - - - lblFeatureCount - - - count - - - - - textLabel6 - - - Geometry type - - - - - lblGeometryType - - + - 120 - 0 + 32767 + 22 - geom + Legend type: - + - textLabel7_6 + widgetStackRenderers - - Upper right + + + 7 + 7 + 0 + 0 + + + + qt_dead_widget_singlesympage + + + 0 + + + + unnamed + + + + + + qt_dead_widget_continuoussympage + + + 1 + + + + unnamed + + + + + + qt_dead_widget_WStackPage + + + 2 + + - + - lblUpperRight + legendtypecombobox - - ur + + + 270 + 24 + - - - - lblLowerLeft - - - ll - - - - - textLabel7_5 - - - Lower left + + + 32767 + 22 + - + - groupBox3 - - - Visibility + tab + + General + unnamed - + - chkUseScaleDependentRendering + textLabel3_2 + + + + 32767 + 22 + - Use scale dependent rendering + Layer source - + - textLabel1_2_2 + groupBox3 + + + Visibility + + + + unnamed + + + + chkUseScaleDependentRendering + + + Use scale dependent rendering + + + + + textLabel1_2_2 + + + Maximum 1: + + + + + spinMaximumScale + + + 100000000 + + + 1 + + + Maximum scale at which this layer will be displayed. + + + + + textLabel1 + + + Minimum 1: + + + + + spinMinimumScale + + + 100000000 + + + 1 + + + Minimum scale at which this layer will be displayed. + + + + + + + groupBox1 + + + Fields + + + + unnamed + + + + + Field + + + true + + + true + + + + + Type + + + true + + + true + + + + + Length + + + true + + + true + + + + + Precision + + + true + + + true + + + + listViewFields + + + Manual + + + AllColumns + + + + + + + textLabel2 - Maximum 1: - - - - - spinMaximumScale - - - 100000000 - - - 1 + Display field - Maximum scale at which this layer will be displayed. + Display field for the Identify Results dialog box + + This sets the display field for the Identify Results dialog box + + + + + groupBox2 + + + + 7 + 0 + 0 + 0 + + + + Features + + + + unnamed + + + + textLabel6_2 + + + Count + + + + + lblFeatureCount + + + count + + + + + textLabel6 + + + Geometry type + + + + + lblGeometryType + + + + 120 + 0 + + + + geom + + + + + textLabel7_6 + + + Upper right + + + + + lblUpperRight + + + ur + + + + + lblLowerLeft + + + ll + + + + + textLabel7_5 + + + Lower left + + + - textLabel1 + textLabel3 - Minimum 1: + Display name - + - spinMinimumScale + displayFieldComboBox - - 100000000 - - - 1 - - - Minimum scale at which this layer will be displayed. + + Use this control to set which field is placed at the top level of the Identify Results dialog box. + + + txtDisplayName + + + + + lblSource + + + + 32767 + 22 + + + + StyledPanel + + + Sunken + + + TextLabel2 + + + + + spacer3 + + + Horizontal + + + Expanding + + + + 436 + 21 + + + - + - txtDisplayName + tab + + Labels + + + + unnamed + + + + labelCheckBox + + + + 7 + 0 + 0 + 0 + + + + Display labels + + + + + labelOptionsFrame + + + + 7 + 7 + 0 + 0 + + + + NoFrame + + + Plain + + + - + - textLabel3 - - - Display name + TabPage + + Actions + + + + actionOptionsFrame + + + + 0 + 0 + 651 + 491 + + + + NoFrame + + + Raised + + - - - textLabel3_2 - - - - 32767 - 22 - - - - Layer source - - - - - lblSource - - - - 32767 - 22 - - - - StyledPanel - - - Sunken - - - TextLabel2 - - - - - - - tab - - - Labels - - - - unnamed - - - - labelCheckBox - - - - 7 - 0 - 0 - 0 - - - - Display labels - - - - - labelOptionsFrame - - - - 7 - 7 - 0 - 0 - - - - NoFrame - - - Plain - - - - - - - TabPage - - - Actions - - - - actionOptionsFrame - - - - 0 - 0 - 651 - 491 - - - - NoFrame - - - Raised - - + - + diff --git a/src/qgsvectorlayer.cpp b/src/qgsvectorlayer.cpp index 08309c47c56..bfaea275247 100644 --- a/src/qgsvectorlayer.cpp +++ b/src/qgsvectorlayer.cpp @@ -824,6 +824,9 @@ void QgsVectorLayer::select(int number) if (! m_propertiesDialog) { m_propertiesDialog = new QgsDlgVectorLayerProperties(this); + // Make sure that the UI starts out with the correct display + // field value + m_propertiesDialog->setDisplayField(displayField()); } m_propertiesDialog->reset(); @@ -1140,7 +1143,11 @@ void QgsVectorLayer::select(int number) { delete m_propertiesDialog; } + m_propertiesDialog = properties; + // Make sure that the UI gets the correct display + // field value + m_propertiesDialog->setDisplayField(displayField()); } @@ -1409,6 +1416,14 @@ bool QgsVectorLayer::readXML_( QDomNode & layer_node ) setDataProvider( providerKey ); + // get and set the display field if it exists. + QDomNode displayFieldNode = layer_node.namedItem("displayfield"); + if (!displayFieldNode.isNull()) + { + QDomElement e = displayFieldNode.toElement(); + setDisplayField(e.text()); + } + // create and bind a renderer to this layer QDomNode singlenode = layer_node.namedItem("singlesymbol"); @@ -1643,6 +1658,13 @@ QgsVectorLayer:: setDataProvider( QString const & provider ) layer_node.appendChild( provider ); + // add the display field + + QDomElement dField = document.createElement( "displayfield" ); + QDomText dFieldText = document.createTextNode( displayField() ); + dField.appendChild( dFieldText ); + layer_node.appendChild( dField ); + // add label node QDomElement label = document.createElement( "label" ); diff --git a/src/qgsvectorlayer.h b/src/qgsvectorlayer.h index 962d10f42b2..f41f932f11d 100644 --- a/src/qgsvectorlayer.h +++ b/src/qgsvectorlayer.h @@ -70,6 +70,9 @@ class QgsVectorLayer : public QgsMapLayer //! Set the primary display field to be used in the identify results dialog void setDisplayField(QString fldName=0); + //! Returns the primary display field name used in the identify results dialog + const QString displayField() const { return fieldIndex; } + //! Initialize the context menu void initContextMenu(QgisApp * app);