Skip to content
Permalink
Browse files
select value for classification in attribute dialog from unique value…
… renderer classes

git-svn-id: http://svn.osgeo.org/qgis/trunk@8776 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
jef committed Jul 14, 2008
1 parent b5948bd commit bf2370003289640b36a6304a48e9a8de94d5768e
Showing with 103 additions and 28 deletions.
  1. +98 −23 src/app/qgsattributedialog.cpp
  2. +3 −3 src/app/qgsattributedialog.h
  3. +2 −2 src/app/qgsmaptooladdfeature.cpp
@@ -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) return;
if (mFieldMap.isEmpty()) return;
if (mpFeature==NULL || vl->getDataProvider()==NULL )
return;

const QgsFieldMap &theFieldMap = vl->getDataProvider()->fields();

if (theFieldMap.isEmpty()) return;

QgsAttributeMap myAttributes = mpFeature->attributeMap();
//
//Set up dynamic inside a scroll box
@@ -58,35 +65,89 @@ QgsAttributeDialog::QgsAttributeDialog(
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())
{
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 )
{
mypLineEdit->setValidator( new QIntValidator(mypLineEdit) );
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
{
//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,12 +168,26 @@ void QgsAttributeDialog::accept()
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:
{
@@ -27,14 +27,14 @@ class QDialog;
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 @@ class QgsAttributeDialog: public QDialog, private Ui::QgsAttributeDialogBase
private:
QString mSettingsPath;
QList<QWidget *> mpWidgets;
QgsFieldMap mFieldMap;
QgsVectorLayer *mLayer;
QgsFeature * mpFeature;
};

@@ -175,7 +175,7 @@ void QgsMapToolAddFeature::canvasReleaseEvent(QMouseEvent * e)
}

// 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 @@ void QgsMapToolAddFeature::canvasReleaseEvent(QMouseEvent * e)
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))

0 comments on commit bf23700

Please sign in to comment.