[QGIS Commit] r8776 - trunk/qgis/src/app
svn_qgis at osgeo.org
svn_qgis at osgeo.org
Mon Jul 14 16:23:14 EDT 2008
Author: jef
Date: 2008-07-14 16:23:14 -0400 (Mon, 14 Jul 2008)
New Revision: 8776
Modified:
trunk/qgis/src/app/qgsattributedialog.cpp
trunk/qgis/src/app/qgsattributedialog.h
trunk/qgis/src/app/qgsmaptooladdfeature.cpp
Log:
select value for classification in attribute dialog from unique value renderer classes
Modified: trunk/qgis/src/app/qgsattributedialog.cpp
===================================================================
--- trunk/qgis/src/app/qgsattributedialog.cpp 2008-07-14 20:21:57 UTC (rev 8775)
+++ trunk/qgis/src/app/qgsattributedialog.cpp 2008-07-14 20:23:14 UTC (rev 8776)
@@ -19,26 +19,33 @@
#include "qgsfield.h"
#include "qgslogger.h"
+#include "qgsvectorlayer.h"
+#include "qgsvectordataprovider.h"
+#include "qgsuniquevaluerenderer.h"
+#include "qgssymbol.h"
+
#include <QTableWidgetItem>
#include <QSettings>
#include <QLineEdit>
-#include <QSpinBox>
+#include <QComboBox>
#include <QLabel>
-#include <QDoubleSpinBox>
#include <QFrame>
#include <QScrollArea>
-QgsAttributeDialog::QgsAttributeDialog(
- QgsFieldMap theFieldMap, QgsFeature * thepFeature)
+QgsAttributeDialog::QgsAttributeDialog(QgsVectorLayer *vl, QgsFeature * thepFeature)
: QDialog(),
mSettingsPath("/Windows/AttributeDialog/"),
- mFieldMap(theFieldMap),
- mpFeature(thepFeature)
+ mpFeature(thepFeature),
+ mLayer(vl)
{
+ setupUi(this);
+ if (mpFeature==NULL || vl->getDataProvider()==NULL )
+ return;
- setupUi(this);
- if (mpFeature==NULL) return;
- if (mFieldMap.isEmpty()) return;
+ const QgsFieldMap &theFieldMap = vl->getDataProvider()->fields();
+
+ if (theFieldMap.isEmpty()) return;
+
QgsAttributeMap myAttributes = mpFeature->attributeMap();
//
//Set up dynamic inside a scroll box
@@ -58,26 +65,79 @@
mypScrollArea->setWidgetResizable( true );
QGridLayout * mypInnerLayout = new QGridLayout(mypInnerFrame);
+
+ int classificationField = -1;
+ QStringList values;
+
+ const QgsUniqueValueRenderer *uvr = dynamic_cast<const QgsUniqueValueRenderer *>( mLayer->renderer() );
+ if( uvr )
+ {
+ classificationField = uvr->classificationField();
+
+ const QList<QgsSymbol *> symbols = uvr->symbols();
+
+ for(int i=0; i<symbols.size(); i++)
+ {
+ values.append( symbols[i]->lowerValue() );
+ }
+ }
+
int index=0;
for (QgsAttributeMap::const_iterator it = myAttributes.begin();
it != myAttributes.end();
++it)
{
- QString myFieldName = mFieldMap[it.key()].name();
+ QString myFieldName = theFieldMap[it.key()].name();
+ int myFieldType = theFieldMap[it.key()].type();
QLabel * mypLabel = new QLabel();
mypInnerLayout->addWidget(mypLabel,index,0);
QVariant myFieldValue = it.value();
- QLineEdit * mypLineEdit = new QLineEdit();
- //the provider may have provided a default value so use it
- mypLineEdit->setText(myFieldValue.toString());
- if( mFieldMap[it.key()].type()==QVariant::Int )
+
+ QWidget *myWidget;
+ if(classificationField!=it.key())
{
- mypLineEdit->setValidator( new QIntValidator(mypLineEdit) );
+ QLineEdit *le = new QLineEdit();
+
+ //the provider may have provided a default value so use it
+ le->setText(myFieldValue.toString());
+
+ if( myFieldType==QVariant::Int )
+ {
+ le->setValidator( new QIntValidator(le) );
+ }
+ else if( myFieldType==QVariant::Double )
+ {
+ le->setValidator( new QIntValidator(le) );
+ }
+
+ myWidget = le;
+ }
+ else
+ {
+ QComboBox *cb = new QComboBox();
+ cb->addItems(values);
+ cb->setEditable(true);
+
+ //the provider may have provided a default value so use it
+ cb->setEditText(myFieldValue.toString());
+
+ if( myFieldType==QVariant::Int ) {
+ cb->setValidator( new QIntValidator(cb) );
+ }
+ else if( myFieldType==QVariant::Double )
+ {
+ cb->setValidator( new QIntValidator(cb) );
+ }
+
+ myWidget = cb;
+ }
+
+ if( myFieldType==QVariant::Int )
+ {
mypLabel->setText(myFieldName + tr(" (int)"));
}
- else if( mFieldMap[it.key()].type()==QVariant::Double )
+ else if( myFieldType==QVariant::Double )
{
- mypLineEdit->setValidator( new QDoubleValidator(mypLineEdit) );
mypLabel->setText(myFieldName + tr(" (dbl)"));
}
else //string
@@ -85,8 +145,9 @@
//any special behaviour for string goes here
mypLabel->setText(myFieldName + tr(" (txt)"));
}
- mypInnerLayout->addWidget(mypLineEdit,index,1);
- mpWidgets << mypLineEdit;
+
+ mypInnerLayout->addWidget(myWidget, index, 1);
+ mpWidgets << myWidget;
++index;
}
restoreGeometry();
@@ -107,13 +168,27 @@
it != myAttributes.end();
++it)
{
+ const QgsFieldMap &theFieldMap = mLayer->getDataProvider()->fields();
+
//Q_ASSERT(myIndex <= mpWidgets.size());
- QString myFieldName = mFieldMap[it.key()].name();
+ QString myFieldName = theFieldMap[it.key()].name();
bool myFlag=false;
- QString myFieldValue =
- dynamic_cast<QLineEdit *>(mpWidgets.value(myIndex))->text();
- switch( mFieldMap[it.key()].type() )
+ QString myFieldValue;
+
+ QLineEdit *le = dynamic_cast<QLineEdit *>(mpWidgets.value(myIndex));
+ if(le)
{
+ myFieldValue = le->text();
+ }
+
+ QComboBox *cb = dynamic_cast<QComboBox *>(mpWidgets.value(myIndex));
+ if(cb)
+ {
+ myFieldValue = cb->currentText();
+ }
+
+ switch( theFieldMap[it.key()].type() )
+ {
case QVariant::Int:
{
int myIntValue = myFieldValue.toInt(&myFlag);
Modified: trunk/qgis/src/app/qgsattributedialog.h
===================================================================
--- trunk/qgis/src/app/qgsattributedialog.h 2008-07-14 20:21:57 UTC (rev 8775)
+++ trunk/qgis/src/app/qgsattributedialog.h 2008-07-14 20:23:14 UTC (rev 8776)
@@ -27,14 +27,14 @@
class QgsFeature;
class QLayout;
class QgsField;
-typedef QMap<int, QgsField> QgsFieldMap;
+class QgsVectorLayer;
class QgsAttributeDialog: public QDialog, private Ui::QgsAttributeDialogBase
{
Q_OBJECT;
public:
- QgsAttributeDialog(const QgsFieldMap thepFieldMap, QgsFeature * thepFeature);
+ QgsAttributeDialog(QgsVectorLayer *vl, QgsFeature * thepFeature);
~QgsAttributeDialog();
/** Overloaded accept method which will write the feature field
@@ -53,7 +53,7 @@
private:
QString mSettingsPath;
QList<QWidget *> mpWidgets;
- QgsFieldMap mFieldMap;
+ QgsVectorLayer *mLayer;
QgsFeature * mpFeature;
};
Modified: trunk/qgis/src/app/qgsmaptooladdfeature.cpp
===================================================================
--- trunk/qgis/src/app/qgsmaptooladdfeature.cpp 2008-07-14 20:21:57 UTC (rev 8775)
+++ trunk/qgis/src/app/qgsmaptooladdfeature.cpp 2008-07-14 20:23:14 UTC (rev 8776)
@@ -175,7 +175,7 @@
}
// show the dialog to enter attribute values
- QgsAttributeDialog * mypDialog = new QgsAttributeDialog(fields,f );
+ QgsAttributeDialog * mypDialog = new QgsAttributeDialog( vlayer, f );
if (mypDialog->exec())
{
qDebug("Adding feature to layer");
@@ -436,7 +436,7 @@
f->addAttribute(it.key(), provider->getDefaultValue(it.key()));
}
- QgsAttributeDialog * mypDialog = new QgsAttributeDialog(fields,f );
+ QgsAttributeDialog * mypDialog = new QgsAttributeDialog( vlayer, f );
if (mypDialog->exec())
{
if(vlayer->addFeature(*f))
More information about the QGIS-commit
mailing list