[QGIS Commit] r11154 - in trunk/qgis/src/app: . attributetable

svn_qgis at osgeo.org svn_qgis at osgeo.org
Thu Jul 23 07:11:41 EDT 2009


Author: jef
Date: 2009-07-23 07:11:41 -0400 (Thu, 23 Jul 2009)
New Revision: 11154

Added:
   trunk/qgis/src/app/qgsattributeeditor.cpp
   trunk/qgis/src/app/qgsattributeeditor.h
Modified:
   trunk/qgis/src/app/CMakeLists.txt
   trunk/qgis/src/app/attributetable/qgsattributetabledelegate.cpp
   trunk/qgis/src/app/attributetable/qgsattributetabledelegate.h
   trunk/qgis/src/app/attributetable/qgsattributetablefiltermodel.h
   trunk/qgis/src/app/attributetable/qgsattributetableidcolumnpair.cpp
   trunk/qgis/src/app/attributetable/qgsattributetableidcolumnpair.h
   trunk/qgis/src/app/attributetable/qgsattributetablemodel.cpp
   trunk/qgis/src/app/qgsattributedialog.cpp
   trunk/qgis/src/app/qgsattributedialog.h
   trunk/qgis/src/app/qgsvectorlayerproperties.cpp
Log:
refactor widget creation for attribute dialog and table into a factory class.



Modified: trunk/qgis/src/app/CMakeLists.txt
===================================================================
--- trunk/qgis/src/app/CMakeLists.txt	2009-07-23 11:07:34 UTC (rev 11153)
+++ trunk/qgis/src/app/CMakeLists.txt	2009-07-23 11:11:41 UTC (rev 11154)
@@ -6,6 +6,7 @@
   qgsaddattrdialog.cpp
   qgsattributeactiondialog.cpp
   qgsattributedialog.cpp
+  qgsattributeeditor.cpp
   qgsattributetypedialog.cpp
   qgsattributetypeloaddialog.cpp
   qgsbookmarkitem.cpp
@@ -110,6 +111,7 @@
   qgsaddattrdialog.h
   qgsattributeactiondialog.h
   qgsattributedialog.h
+  qgsattributeeditor.h
   qgsattributetypedialog.h
   qgsattributetypeloaddialog.h
   qgsbookmarks.h

Modified: trunk/qgis/src/app/attributetable/qgsattributetabledelegate.cpp
===================================================================
--- trunk/qgis/src/app/attributetable/qgsattributetabledelegate.cpp	2009-07-23 11:07:34 UTC (rev 11153)
+++ trunk/qgis/src/app/attributetable/qgsattributetabledelegate.cpp	2009-07-23 11:11:41 UTC (rev 11154)
@@ -17,185 +17,60 @@
 #include <QLineEdit>
 #include <QComboBox>
 #include <QPainter>
-#include <QCompleter>
-#include <QSpinBox>
-#include <QDoubleSpinBox>
 
 #include "qgsattributetableview.h"
 #include "qgsattributetablemodel.h"
 #include "qgsattributetablefiltermodel.h"
 #include "qgsattributetabledelegate.h"
 #include "qgsvectordataprovider.h"
-#include "qgsvectorlayer.h"
-#include "qgsuniquevaluerenderer.h"
-#include "qgssymbol.h"
+#include "qgsattributeeditor.h"
+#include "qgslogger.h"
 
+QgsVectorLayer *QgsAttributeTableDelegate::layer( const QAbstractItemModel *model ) const
+{
+  const QgsAttributeTableModel *tm = dynamic_cast<const QgsAttributeTableModel*>( model );
+  if ( tm )
+    return tm->layer();
 
-QWidget * QgsAttributeTableDelegate::createEditor(
+  const QgsAttributeTableFilterModel *fm = dynamic_cast<const QgsAttributeTableFilterModel*>( model );
+  if ( fm )
+    return fm->layer();
+
+  return NULL;
+}
+
+QWidget *QgsAttributeTableDelegate::createEditor(
   QWidget *parent,
   const QStyleOptionViewItem &option,
   const QModelIndex &index ) const
 {
-  QWidget *editor;
+  QgsVectorLayer *vl = layer( index.model() );
+  if ( vl == NULL )
+    return NULL;
 
-  const QgsAttributeTableFilterModel* fm = dynamic_cast<const QgsAttributeTableFilterModel*>( index.model() );
-  if ( !fm )
-  {
-      return editor;
-  }
-  const QgsAttributeTableModel* m = dynamic_cast<const QgsAttributeTableModel*>( fm->sourceModel() );
-  if ( !m )
-  {
-      return editor;
-  }
+  QWidget *widget = QgsAttributeEditor::createAttributeEditor( parent, vl, index.column(), index.model()->data( index ) );
+  widget->adjustSize();
 
-  int col = index.column();
-  QVariant::Type type = m->layer()->dataProvider()->fields()[col].type();
-  QgsVectorLayer::EditType editType = m->layer()->editType(col);
+  QgsAttributeTableView *tv = dynamic_cast<QgsAttributeTableView *>( parent->parentWidget() );
+  tv->setRowHeight( index.row(), widget->height() );
+  tv->setColumnWidth( index.column(), widget->width() );
 
-  //need to created correct edit widget according to edit type of value
-  //and fill with data from correct source
-  if (editType == QgsVectorLayer::LineEdit ||
-      editType == QgsVectorLayer::UniqueValuesEditable ||
-      editType == QgsVectorLayer::FileName ||
-      editType == QgsVectorLayer::Immutable)
-  { //these are all siple edits
-    editor = new QLineEdit(parent);
-    QLineEdit* le = dynamic_cast<QLineEdit*> ( editor );
-    le-> setReadOnly ( false );
+  return widget;
+}
 
-    if ( editType == QgsVectorLayer::UniqueValuesEditable )
-    { //just this value has completer
-      QList<QVariant> values;
-      m->layer()->dataProvider()->uniqueValues( col, values );
+void QgsAttributeTableDelegate::setModelData( QWidget *editor, QAbstractItemModel *model, const QModelIndex &index ) const
+{
+  QgsVectorLayer *vl = layer( index.model() );
+  if ( vl == NULL )
+    return;
 
-      QStringList svalues;
-      for ( QList<QVariant>::const_iterator it = values.begin(); it != values.end(); it++ )
-        svalues << it->toString();
+  QVariant value;
+  if ( !QgsAttributeEditor::retrieveValue( editor, vl, index.column(), value ) )
+    return;
 
-      QCompleter *c = new QCompleter( svalues );
-      c->setCompletionMode( QCompleter::PopupCompletion );
-      le->setCompleter( c );
-    }
-    if (editType == QgsVectorLayer::Immutable)
-    {
-      le->setReadOnly(true);
-    }
-    //validators if value needs it
-    if ( type == QVariant::Int )
-    {
-      le->setValidator( new QIntValidator( le ) );
-    }
-    else if ( type == QVariant::Double )
-    {
-      le->setValidator( new QDoubleValidator( le ) );
-    }
-  }
-  else if (editType == QgsVectorLayer::ValueMap)
-  { //simple combobox from data from vector layer
-    editor = new QComboBox(parent);
-    QComboBox* cb = dynamic_cast<QComboBox*>( editor );
-    QMap<QString, QVariant> &map = m->layer()->valueMap(col);
-    QMap<QString, QVariant>::iterator it = map.begin();
-    for ( ; it != map.end(); it ++)
-    {
-      cb->addItem( it.key() ,it.value());
-    }
-  }
-  else if (editType == QgsVectorLayer::SliderRange)
-  { //horizontal slider
-    editor = new QSlider(Qt::Horizontal, parent);
-    QSlider* s = dynamic_cast<QSlider*>(editor );
-    QgsVectorLayer::RangeData &range = m->layer()->range(col);
-    s->setMinimum( range.mMin.toInt() );
-    s->setMaximum( range.mMax.toInt() );
-    s->setPageStep( range.mStep.toInt() );
-  }
-  else if (editType == QgsVectorLayer::Classification)
-  {
-    // should be prepared probably to not change it always
-    int classificationField = -1;
-    QMap<QString, QString> classes;
-    const QgsUniqueValueRenderer *uvr = dynamic_cast<const QgsUniqueValueRenderer *>( m->layer()->renderer() );
-    if ( uvr )
-    {
-      classificationField = uvr->classificationField();
-      const QList<QgsSymbol *> symbols = uvr->symbols();
-
-      for ( int i = 0; i < symbols.size(); i++ )
-      {
-        QString label = symbols[i]->label();
-        QString name = symbols[i]->lowerValue();
-        if ( label == "" )
-          label = name;
-        classes.insert( name, label );
-      }
-    }
-    editor = new QComboBox(parent);
-    QComboBox* cb = dynamic_cast<QComboBox*>( editor );
-    for ( QMap<QString, QString>::const_iterator it = classes.begin(); it != classes.end(); it++ )
-    {
-      cb->addItem( it.value(), it.key() );
-    }
-  }
-  else if (editType == QgsVectorLayer::UniqueValues)
-  {
-    QList<QVariant> values;
-    m->layer()->dataProvider()->uniqueValues( col, values );
-
-    editor = new QComboBox(parent);
-    QComboBox* cb = dynamic_cast<QComboBox*>( editor );
-    cb->setEditable( true );
-
-    for ( QList<QVariant>::iterator it = values.begin(); it != values.end(); it++ )
-      cb->addItem( it->toString() );
-
-  }
-  else if (editType == QgsVectorLayer::Enumeration)
-  {
-    QStringList enumValues;
-    m->layer()->dataProvider()->enumValues( col, enumValues );
-
-    editor = new QComboBox(parent);
-    QComboBox* cb = dynamic_cast<QComboBox*>( editor );
-    QStringList::const_iterator s_it = enumValues.constBegin();
-    for ( ; s_it != enumValues.constEnd(); ++s_it )
-    {
-      cb->addItem( *s_it );
-    }
-  }
-  else if (editType == QgsVectorLayer::EditRange)
-  {
-    if ( type == QVariant::Int )
-    {
-      int min = m->layer()->range( col ).mMin.toInt();
-      int max = m->layer()->range( col ).mMax.toInt();
-      int step = m->layer()->range( col ).mStep.toInt();
-      editor = new QSpinBox(parent);
-      QSpinBox* sb = dynamic_cast<QSpinBox*>( editor );
-
-      sb->setRange( min, max );
-      sb->setSingleStep( step );
-
-    }
-    else if ( type == QVariant::Double )
-    {
-      double min = m->layer()->range( col ).mMin.toDouble();
-      double max = m->layer()->range( col ).mMax.toDouble();
-      double step = m->layer()->range( col ).mStep.toDouble();
-      editor = new QDoubleSpinBox(parent);
-      QDoubleSpinBox* dsb = dynamic_cast<QDoubleSpinBox*>( editor );
-
-      dsb->setRange( min, max );
-      dsb->setSingleStep( step );
-    }
-  }
-
-
-  return editor;
+  model->setData( index, value );
 }
 
-
 void QgsAttributeTableDelegate::paint( QPainter * painter,
                                        const QStyleOptionViewItem & option,
                                        const QModelIndex & index ) const
@@ -212,130 +87,3 @@
     painter->restore();
   }
 }
-
-
-void QgsAttributeTableDelegate::setEditorData(QWidget *editor, const QModelIndex &index) const
-{
-
-
-  const QgsAttributeTableFilterModel* fm = dynamic_cast<const QgsAttributeTableFilterModel*>( index.model() );
-  if ( !fm )
-  {
-      return;
-  }
-  const QgsAttributeTableModel* m = dynamic_cast<const QgsAttributeTableModel*>( fm->sourceModel() );
-  if ( !m )
-  {
-      return;
-  }
-  int col = index.column();
-  QVariant::Type type = m->layer()->dataProvider()->fields()[col].type();
-  QgsVectorLayer::EditType editType = m->layer()->editType(col);
-  if (editType == QgsVectorLayer::LineEdit ||
-      editType == QgsVectorLayer::UniqueValuesEditable ||
-      editType == QgsVectorLayer::FileName ||
-      editType == QgsVectorLayer::Immutable)
-  {
-    QString qs = index.model()->data(index, Qt::DisplayRole).toString();
-    
-    QLineEdit* le = dynamic_cast<QLineEdit*> ( editor );
-    le->setText( qs );
-  }
-  else if (editType == QgsVectorLayer::ValueMap ||
-           editType == QgsVectorLayer::Classification ||
-           editType == QgsVectorLayer::UniqueValues ||
-           editType == QgsVectorLayer::Enumeration)
-  {
-    QComboBox* cb = dynamic_cast<QComboBox*>( editor );
-    QVariant qs = index.model()->data(index, Qt::EditRole);
-    int cbIndex = cb->findData(qs);
-    if (cbIndex > -1)
-    {
-      cb->setCurrentIndex(cbIndex);
-    }
-  }
-  else if (editType == QgsVectorLayer::SliderRange)
-  {
-     int value = index.model()->data(index, Qt::EditRole).toInt();
-     QSlider* s = dynamic_cast<QSlider*>( editor );
-     s->setValue( value );
-  }
-  else if (editType == QgsVectorLayer::EditRange)
-  {
-    if ( type == QVariant::Int )
-    {
-      QSpinBox* sb = dynamic_cast<QSpinBox*>( editor );
-      int value = index.model()->data(index, Qt::EditRole).toInt();
-      sb->setValue( value );
-    }
-    else if ( type == QVariant::Double )
-    {
-      QDoubleSpinBox* sb = dynamic_cast<QDoubleSpinBox*>( editor );
-      double value = index.model()->data(index, Qt::EditRole).toDouble();
-      sb->setValue( value );
-    }
-  }
-}
-
-
-
-void QgsAttributeTableDelegate::setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const
-{
-  const QgsAttributeTableFilterModel* fm = dynamic_cast<const QgsAttributeTableFilterModel*>( index.model() );
-  if ( !fm )
-  {
-      return;
-  }
-  const QgsAttributeTableModel* m = dynamic_cast<const QgsAttributeTableModel*>( fm->sourceModel() );
-  if ( !m )
-  {
-      return;
-  }
-
-  int col = index.column();
-  QVariant::Type type = m->layer()->dataProvider()->fields()[col].type();
-  QgsVectorLayer::EditType editType = m->layer()->editType(col);
-  if (editType == QgsVectorLayer::LineEdit ||
-      editType == QgsVectorLayer::UniqueValuesEditable ||
-      editType == QgsVectorLayer::FileName ||
-      editType == QgsVectorLayer::Immutable)
-  {
-    QLineEdit* le = dynamic_cast<QLineEdit*> ( editor );
-    QString text = le->text();
-    QVariant value = QVariant (text);
-    model->setData( index, value );
-  }
-  else if (editType == QgsVectorLayer::ValueMap ||
-           editType == QgsVectorLayer::Classification ||
-           editType == QgsVectorLayer::UniqueValues ||
-           editType == QgsVectorLayer::Enumeration)
-  {
-    QComboBox* cb = dynamic_cast<QComboBox*>( editor );
-    model->setData(index, cb->itemData(cb->currentIndex()));
-  }
-  else if (editType == QgsVectorLayer::SliderRange)
-  {
-    QSlider* s = dynamic_cast<QSlider*>( editor );
-    model->setData( index, s->value() );
-  }
-  else if (editType == QgsVectorLayer::EditRange)
-  {
-    if ( type == QVariant::Int )
-    {
-      QSpinBox* sb = dynamic_cast<QSpinBox*>( editor );
-      model->setData( index, sb->value() );
-    }
-    else if ( type == QVariant::Double )
-    {
-      QDoubleSpinBox* sb = dynamic_cast<QDoubleSpinBox*>( editor );
-      model->setData( index, sb->value() );
-    }
-  }
-}
-
-
-
-
-
-
-

Modified: trunk/qgis/src/app/attributetable/qgsattributetabledelegate.h
===================================================================
--- trunk/qgis/src/app/attributetable/qgsattributetabledelegate.h	2009-07-23 11:07:34 UTC (rev 11153)
+++ trunk/qgis/src/app/attributetable/qgsattributetabledelegate.h	2009-07-23 11:11:41 UTC (rev 11154)
@@ -19,6 +19,8 @@
 #include <QItemDelegate>
 #include "qgsvectorlayer.h"
 class QPainter;
+class QgsVectorLayer;
+
 /** \ingroup app
  * A delegate item class for QgsAttributeTable (see Qt documentation for
  * QItemDelegate).
@@ -27,6 +29,9 @@
 class QgsAttributeTableDelegate : public QItemDelegate
 {
     Q_OBJECT;
+
+    QgsVectorLayer *layer( const QAbstractItemModel *model ) const;
+
   public:
     /** Constructor
      * @param parent parent object
@@ -39,6 +44,7 @@
       QWidget *parent,
       const QStyleOptionViewItem &option,
       const QModelIndex &index ) const;
+
     /** Overloads the paint method form the QItemDelegate bas class */
     void paint(
       QPainter * painter,
@@ -46,19 +52,12 @@
       const QModelIndex & index ) const;
 
     /**
-     * Sets data to editor widget. Overloads default metod
-     * @param editor editor which was created by create editor function in this class
-     * @param index index of field which is to be modified
-     */
-    void setEditorData(QWidget *editor, const QModelIndex &index) const;
-
-    /**
      * Sets data from editor backk to model. Overloads default metod
      * @param editor editor which was created by create editor function in this class
      * @param model model where data should be updated
      * @param index index of field which is to be modified
      */
-    void setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const;
+    void setModelData( QWidget *editor, QAbstractItemModel *model, const QModelIndex &index ) const;
 
 };
 

Modified: trunk/qgis/src/app/attributetable/qgsattributetablefiltermodel.h
===================================================================
--- trunk/qgis/src/app/attributetable/qgsattributetablefiltermodel.h	2009-07-23 11:07:34 UTC (rev 11153)
+++ trunk/qgis/src/app/attributetable/qgsattributetablefiltermodel.h	2009-07-23 11:11:41 UTC (rev 11154)
@@ -40,6 +40,9 @@
     virtual void sort( int column, Qt::SortOrder order = Qt::AscendingOrder );
     //QModelIndex mapToSource ( const QModelIndex & filterIndex ) const;
     //QModelIndex mapFromSource ( const QModelIndex & sourceIndex ) const;
+
+    QgsVectorLayer *layer() const { return mLayer; }
+
   protected:
     /**
      * Returns true if the source row will be accepted

Modified: trunk/qgis/src/app/attributetable/qgsattributetableidcolumnpair.cpp
===================================================================
--- trunk/qgis/src/app/attributetable/qgsattributetableidcolumnpair.cpp	2009-07-23 11:07:34 UTC (rev 11153)
+++ trunk/qgis/src/app/attributetable/qgsattributetableidcolumnpair.cpp	2009-07-23 11:11:41 UTC (rev 11154)
@@ -22,14 +22,20 @@
 bool QgsAttributeTableIdColumnPair::operator<( const QgsAttributeTableIdColumnPair &b ) const
 {
   //QVariant thinks gid is a string!
-  QVariant::Type columnType = columnItem.type();
+  QVariant::Type columnType = mItem.type();
 
-  if ( columnType == QVariant::Int || columnType == QVariant::UInt || columnType == QVariant::LongLong || columnType == QVariant::ULongLong )
-    return columnItem.toLongLong() < b.columnItem.toLongLong();
+  switch ( columnType )
+  {
+    case QVariant::Int:
+    case QVariant::UInt:
+    case QVariant::LongLong:
+    case QVariant::ULongLong:
+      return mItem.toLongLong() < b.mItem.toLongLong();
 
-  if ( columnType == QVariant::Double )
-    return columnItem.toDouble() < b.columnItem.toDouble();
+    case QVariant::Double:
+      return mItem.toDouble() < b.mItem.toDouble();
 
-  return columnItem.toString() < b.columnItem.toString();
+    default:
+      return mItem.toString() < b.mItem.toString();
+  }
 }
-

Modified: trunk/qgis/src/app/attributetable/qgsattributetableidcolumnpair.h
===================================================================
--- trunk/qgis/src/app/attributetable/qgsattributetableidcolumnpair.h	2009-07-23 11:07:34 UTC (rev 11153)
+++ trunk/qgis/src/app/attributetable/qgsattributetableidcolumnpair.h	2009-07-23 11:11:41 UTC (rev 11154)
@@ -21,15 +21,17 @@
 
 class QgsAttributeTableIdColumnPair
 {
+    int mId;
+    QVariant mItem;
+
   public:
-    int id;
-    QVariant columnItem;
-
+    QgsAttributeTableIdColumnPair( int anId, QVariant anItem ) : mId( anId ), mItem( anItem ) {}
     /**
      * Returns true if this id-column pair is less the the tested one
      * @param b the tested id-column pair
      */
     bool operator<( const QgsAttributeTableIdColumnPair &b ) const;
+    int id() { return mId; }
 };
 
 #endif

Modified: trunk/qgis/src/app/attributetable/qgsattributetablemodel.cpp
===================================================================
--- trunk/qgis/src/app/attributetable/qgsattributetablemodel.cpp	2009-07-23 11:07:34 UTC (rev 11153)
+++ trunk/qgis/src/app/attributetable/qgsattributetablemodel.cpp	2009-07-23 11:11:41 UTC (rev 11154)
@@ -144,7 +144,7 @@
 
   loadLayer();
   emit modelChanged();
-  emit headerDataChanged ( Qt::Horizontal, 0, columnCount() - 1);
+  emit headerDataChanged( Qt::Horizontal, 0, columnCount() - 1 );
 }
 
 void QgsAttributeTableModel::loadLayer()
@@ -158,7 +158,7 @@
   mIdRowMap.clear();
 
   int pendingFeatureCount = mLayer->pendingFeatureCount();
-  if ( mFeatureCount < pendingFeatureCount)
+  if ( mFeatureCount < pendingFeatureCount )
   {
     QgsDebugMsg( "ins" );
     ins = true;
@@ -176,8 +176,8 @@
   mLayer->select( QgsAttributeList(), QgsRectangle(), false );
 
   // preallocate data before inserting
-  mRowIdMap.reserve(pendingFeatureCount + 50);
-  mIdRowMap.reserve(pendingFeatureCount + 50);
+  mRowIdMap.reserve( pendingFeatureCount + 50 );
+  mIdRowMap.reserve( pendingFeatureCount + 50 );
 
   for ( int i = 0; mLayer->nextFeature( f ); ++i )
   {
@@ -294,7 +294,6 @@
 void QgsAttributeTableModel::sort( int column, Qt::SortOrder order )
 {
   QgsAttributeMap row;
-  QgsAttributeTableIdColumnPair pair;
   QgsAttributeList attrs;
   QgsFeature f;
 
@@ -308,11 +307,7 @@
   while ( mLayer->nextFeature( f ) )
   {
     row = f.attributeMap();
-
-    pair.id = f.id();
-    pair.columnItem = row[ mAttributes[column] ];
-
-    mSortList.append( pair );
+    mSortList.append( QgsAttributeTableIdColumnPair( f.id(), row[ mAttributes[column] ] ) );
   }
 
   if ( order == Qt::AscendingOrder )
@@ -328,8 +323,8 @@
   QList<QgsAttributeTableIdColumnPair>::Iterator it;
   for ( it = mSortList.begin(); it != mSortList.end(); ++it, ++i )
   {
-    mRowIdMap.insert( i, it->id );
-    mIdRowMap.insert( it->id, i );
+    mRowIdMap.insert( i, it->id() );
+    mIdRowMap.insert( it->id(), i );
   }
 
   // restore selection

Modified: trunk/qgis/src/app/qgsattributedialog.cpp
===================================================================
--- trunk/qgis/src/app/qgsattributedialog.cpp	2009-07-23 11:07:34 UTC (rev 11153)
+++ trunk/qgis/src/app/qgsattributedialog.cpp	2009-07-23 11:11:41 UTC (rev 11154)
@@ -23,21 +23,13 @@
 #include "qgsvectordataprovider.h"
 #include "qgsuniquevaluerenderer.h"
 #include "qgssymbol.h"
+#include "qgsattributeeditor.h"
 
 #include <QTableWidgetItem>
 #include <QSettings>
-#include <QLineEdit>
-#include <QComboBox>
 #include <QLabel>
 #include <QFrame>
 #include <QScrollArea>
-#include <QCompleter>
-#include <QSlider>
-#include <QSpinBox>
-#include <QDoubleSpinBox>
-#include <QPushButton>
-#include <QHBoxLayout>
-#include <QFileDialog>
 
 QgsAttributeDialog::QgsAttributeDialog( QgsVectorLayer *vl, QgsFeature *thepFeature )
     : QDialog(),
@@ -73,28 +65,7 @@
   QGridLayout * mypInnerLayout = new QGridLayout( mypInnerFrame );
 
 
-  int classificationField = -1;
-  QMap<QString, QString> classes;
 
-  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++ )
-    {
-      QString label = symbols[i]->label();
-      QString name = symbols[i]->lowerValue();
-
-      if ( label == "" )
-        label = name;
-
-      classes.insert( name, label );
-    }
-  }
-
   int index = 0;
   for ( QgsAttributeMap::const_iterator it = myAttributes.begin();
         it != myAttributes.end();
@@ -105,194 +76,9 @@
     //show attribute alias if available
     QString myFieldName = vl->attributeDisplayName( it.key() );
     int myFieldType = field.type();
+
     QLabel * mypLabel = new QLabel();
     mypInnerLayout->addWidget( mypLabel, index, 0 );
-    QVariant myFieldValue = it.value();
-
-    QWidget *myWidget;
-
-    QgsVectorLayer::EditType editType = vl->editType( it.key() );
-
-    switch ( editType )
-    {
-      case QgsVectorLayer::UniqueValues:
-      {
-        QList<QVariant> values;
-        mLayer->dataProvider()->uniqueValues( it.key(), values );
-
-        QComboBox *cb = new QComboBox();
-        cb->setEditable( true );
-
-        for ( QList<QVariant>::iterator it = values.begin(); it != values.end(); it++ )
-          cb->addItem( it->toString() );
-
-        int idx = cb->findText( myFieldValue.toString() );
-        if ( idx >= 0 )
-          cb->setCurrentIndex( idx );
-
-        myWidget = cb;
-      }
-      break;
-
-      case QgsVectorLayer::Enumeration:
-      {
-        QStringList enumValues;
-        mLayer->dataProvider()->enumValues( it.key(), enumValues );
-
-        QComboBox *cb = new QComboBox();
-        QStringList::const_iterator s_it = enumValues.constBegin();
-        for ( ; s_it != enumValues.constEnd(); ++s_it )
-        {
-          cb->addItem( *s_it );
-        }
-        int idx = cb->findText( myFieldValue.toString() );
-        if ( idx >= 0 )
-        {
-          cb->setCurrentIndex( idx );
-        }
-        myWidget = cb;
-      }
-      break;
-
-      case QgsVectorLayer::ValueMap:
-      {
-        const QMap<QString, QVariant> &map = vl->valueMap( it.key() );
-
-        QComboBox *cb = new QComboBox();
-
-        for ( QMap<QString, QVariant>::const_iterator it = map.begin(); it != map.end(); it++ )
-        {
-          cb->addItem( it.key(), it.value() );
-        }
-
-        int idx = cb->findData( myFieldValue );
-        if ( idx >= 0 )
-          cb->setCurrentIndex( idx );
-
-        myWidget = cb;
-      }
-      break;
-
-      case QgsVectorLayer::Classification:
-      {
-        QComboBox *cb = new QComboBox();
-        for ( QMap<QString, QString>::const_iterator it = classes.begin(); it != classes.end(); it++ )
-        {
-          cb->addItem( it.value(), it.key() );
-        }
-
-        int idx = cb->findData( myFieldValue );
-        if ( idx >= 0 )
-          cb->setCurrentIndex( idx );
-
-        myWidget = cb;
-      }
-      break;
-
-      case QgsVectorLayer::SliderRange:
-      case QgsVectorLayer::EditRange:
-      {
-        if ( myFieldType == QVariant::Int )
-        {
-          int min = vl->range( it.key() ).mMin.toInt();
-          int max = vl->range( it.key() ).mMax.toInt();
-          int step = vl->range( it.key() ).mStep.toInt();
-
-          if ( editType == QgsVectorLayer::EditRange )
-          {
-            QSpinBox *sb = new QSpinBox();
-
-            sb->setRange( min, max );
-            sb->setSingleStep( step );
-            sb->setValue( it.value().toInt() );
-
-            myWidget = sb;
-          }
-          else
-          {
-            QSlider *sl = new QSlider( Qt::Horizontal );
-
-            sl->setRange( min, max );
-            sl->setSingleStep( step );
-            sl->setValue( it.value().toInt() );
-
-            myWidget = sl;
-          }
-          break;
-        }
-        else if ( myFieldType == QVariant::Double )
-        {
-          double min = vl->range( it.key() ).mMin.toDouble();
-          double max = vl->range( it.key() ).mMax.toDouble();
-          double step = vl->range( it.key() ).mStep.toDouble();
-          QDoubleSpinBox *dsb = new QDoubleSpinBox();
-
-          dsb->setRange( min, max );
-          dsb->setSingleStep( step );
-          dsb->setValue( it.value().toDouble() );
-
-          myWidget = dsb;
-          break;
-        }
-      }
-
-      // fall-through
-
-      case QgsVectorLayer::LineEdit:
-      case QgsVectorLayer::UniqueValuesEditable:
-      case QgsVectorLayer::Immutable:
-      default:
-      {
-        QLineEdit *le = new QLineEdit( myFieldValue.toString() );
-
-        if ( editType == QgsVectorLayer::Immutable )
-        {
-          le->setEnabled( false );
-        }
-        if ( editType == QgsVectorLayer::UniqueValuesEditable )
-        {
-          QList<QVariant> values;
-          mLayer->dataProvider()->uniqueValues( it.key(), values );
-
-          QStringList svalues;
-          for ( QList<QVariant>::const_iterator it = values.begin(); it != values.end(); it++ )
-            svalues << it->toString();
-
-          QCompleter *c = new QCompleter( svalues );
-          c->setCompletionMode( QCompleter::PopupCompletion );
-          le->setCompleter( c );
-        }
-
-        if ( myFieldType == QVariant::Int )
-        {
-          le->setValidator( new QIntValidator( le ) );
-        }
-        else if ( myFieldType == QVariant::Double )
-        {
-          le->setValidator( new QDoubleValidator( le ) );
-        }
-
-        myWidget = le;
-      }
-      break;
-
-      case QgsVectorLayer::FileName:
-      {
-        QLineEdit *le = new QLineEdit( myFieldValue.toString() );
-
-        QPushButton *pb = new QPushButton( tr( "..." ) );
-        connect( pb, SIGNAL( clicked() ), this, SLOT( selectFileName() ) );
-
-        QHBoxLayout *hbl = new QHBoxLayout();
-        hbl->addWidget( le );
-        hbl->addWidget( pb );
-
-        myWidget = new QWidget;
-        myWidget->setLayout( hbl );
-      }
-      break;
-    }
-
     if ( myFieldType == QVariant::Int )
     {
       mypLabel->setText( myFieldName + tr( " (int)" ) );
@@ -307,6 +93,8 @@
       mypLabel->setText( myFieldName + tr( " (txt)" ) );
     }
 
+    QWidget *myWidget = QgsAttributeEditor::createAttributeEditor( 0, vl, it.key(), it.value() );
+
     mypInnerLayout->addWidget( myWidget, index, 1 );
     mpWidgets << myWidget;
     ++index;
@@ -325,27 +113,6 @@
   saveGeometry();
 }
 
-void QgsAttributeDialog::selectFileName()
-{
-  QPushButton *pb = dynamic_cast<QPushButton *>( sender() );
-  if ( !pb )
-    return;
-
-  QWidget *hbox = dynamic_cast<QWidget *>( pb->parent() );
-  if ( !hbox )
-    return;
-
-  QLineEdit *le = hbox->findChild<QLineEdit *>();
-  if ( !le )
-    return;
-
-  QString fileName = QFileDialog::getOpenFileName( 0 , tr( "Select a file" ) );
-  if ( fileName.isNull() )
-    return;
-
-  le->setText( fileName );
-}
-
 void QgsAttributeDialog::accept()
 {
   //write the new values back to the feature
@@ -355,99 +122,11 @@
         it != myAttributes.end();
         ++it )
   {
-    const QgsField &theField = mLayer->pendingFields()[it.key()];
-    QgsVectorLayer::EditType editType = mLayer->editType( it.key() );
-    QString myFieldName = theField.name();
-    bool myFlag = false;
-    QString myFieldValue;
-    bool modified = true;
+    QVariant value;
 
-    QLineEdit *le = dynamic_cast<QLineEdit *>( mpWidgets.value( myIndex ) );
-    if ( le )
-    {
-      myFieldValue = le->text();
-      modified = le->isModified();
-    }
+    if ( QgsAttributeEditor::retrieveValue( mpWidgets.value( myIndex ), mLayer, it.key(), value ) )
+      mpFeature->changeAttribute( it.key(), value );
 
-    QComboBox *cb = dynamic_cast<QComboBox *>( mpWidgets.value( myIndex ) );
-    if ( cb )
-    {
-      if ( editType == QgsVectorLayer::UniqueValues ||
-           editType == QgsVectorLayer::ValueMap ||
-           editType == QgsVectorLayer::Classification )
-      {
-        myFieldValue = cb->itemData( cb->currentIndex() ).toString();
-      }
-      else
-      {
-        myFieldValue = cb->currentText();
-      }
-    }
-
-    QSpinBox *sb = dynamic_cast<QSpinBox *>( mpWidgets.value( myIndex ) );
-    if ( sb )
-    {
-      myFieldValue = QString::number( sb->value() );
-    }
-
-    QSlider *slider = dynamic_cast<QSlider *>( mpWidgets.value( myIndex ) );
-    if ( slider )
-    {
-      myFieldValue = QString::number( slider->value() );
-    }
-
-    QDoubleSpinBox *dsb = dynamic_cast<QDoubleSpinBox *>( mpWidgets.value( myIndex ) );
-    if ( dsb )
-    {
-      myFieldValue = QString::number( dsb->value() );
-    }
-
-    le = mpWidgets.value( myIndex )->findChild<QLineEdit *>();
-    if ( le )
-    {
-      myFieldValue = le->text();
-    }
-
-    switch ( theField.type() )
-    {
-      case QVariant::Int:
-      {
-        int myIntValue = myFieldValue.toInt( &myFlag );
-        if ( myFlag && ! myFieldValue.isEmpty() )
-        {
-          mpFeature->changeAttribute( it.key(), QVariant( myIntValue ) );
-        }
-        else if ( modified )
-        {
-          mpFeature->changeAttribute( it.key(), QVariant( QString::null ) );
-        }
-        else
-        {
-          mpFeature->changeAttribute( it.key(), myFieldValue );
-        }
-      }
-      break;
-      case QVariant::Double:
-      {
-        double myDblValue = myFieldValue.toDouble( &myFlag );
-        if ( myFlag && ! myFieldValue.isEmpty() )
-        {
-          mpFeature->changeAttribute( it.key(), QVariant( myDblValue ) );
-        }
-        else if ( modified )
-        {
-          mpFeature->changeAttribute( it.key(), QVariant( QString::null ) );
-        }
-        else
-        {
-          mpFeature->changeAttribute( it.key(), myFieldValue );
-        }
-      }
-      break;
-      default: //string
-        mpFeature->changeAttribute( it.key(), QVariant( myFieldValue ) );
-        break;
-    }
     ++myIndex;
   }
   QDialog::accept();

Modified: trunk/qgis/src/app/qgsattributedialog.h
===================================================================
--- trunk/qgis/src/app/qgsattributedialog.h	2009-07-23 11:07:34 UTC (rev 11153)
+++ trunk/qgis/src/app/qgsattributedialog.h	2009-07-23 11:11:41 UTC (rev 11154)
@@ -50,14 +50,14 @@
      */
     void restoreGeometry();
 
-  public slots:
-    void selectFileName();
+    static QWidget *createEditor( QgsVectorLayer *vl, int idx, const QVariant &value );
 
   private:
     QString mSettingsPath;
     QList<QWidget *> mpWidgets;
     QgsVectorLayer *mLayer;
     QgsFeature *  mpFeature;
+
 };
 
 #endif

Added: trunk/qgis/src/app/qgsattributeeditor.cpp
===================================================================
--- trunk/qgis/src/app/qgsattributeeditor.cpp	                        (rev 0)
+++ trunk/qgis/src/app/qgsattributeeditor.cpp	2009-07-23 11:11:41 UTC (rev 11154)
@@ -0,0 +1,361 @@
+/***************************************************************************
+                         qgsattributeeditor.cpp  -  description
+                             -------------------
+    begin                : July 2009
+    copyright            : (C) 2009 by Jürgen E. Fischer
+    email                : jef at norbit.de
+ ***************************************************************************/
+
+/***************************************************************************
+ *                                                                         *
+ *   This program is free software; you can redistribute it and/or modify  *
+ *   it under the terms of the GNU General Public License as published by  *
+ *   the Free Software Foundation; either version 2 of the License, or     *
+ *   (at your option) any later version.                                   *
+ *                                                                         *
+ ***************************************************************************/
+/* $Id$ */
+
+#include "qgsattributeeditor.h"
+#include <qgsvectorlayer.h>
+#include <qgsvectordataprovider.h>
+#include <qgsuniquevaluerenderer.h>
+#include <qgssymbol.h>
+
+#include <QPushButton>
+#include <QLineEdit>
+#include <QFileDialog>
+#include <QComboBox>
+#include <QSpinBox>
+#include <QCompleter>
+#include <QHBoxLayout>
+
+void QgsAttributeEditor::selectFileName( void )
+{
+  QPushButton *pb = dynamic_cast<QPushButton *>( sender() );
+  if ( !pb )
+    return;
+
+  QWidget *hbox = dynamic_cast<QWidget *>( pb->parent() );
+  if ( !hbox )
+    return;
+
+  QLineEdit *le = hbox->findChild<QLineEdit *>();
+  if ( !le )
+    return;
+
+  QString fileName = QFileDialog::getOpenFileName( 0 , tr( "Select a file" ) );
+  if ( fileName.isNull() )
+    return;
+
+  le->setText( fileName );
+}
+
+QWidget *QgsAttributeEditor::createAttributeEditor( QWidget *parent, QgsVectorLayer *vl, int idx, const QVariant &value )
+{
+  if ( !vl )
+    return NULL;
+
+  QWidget *myWidget;
+  QgsVectorLayer::EditType editType = vl->editType( idx );
+  const QgsField &field = vl->pendingFields()[idx];
+  QVariant::Type myFieldType = field.type();
+
+  switch ( editType )
+  {
+    case QgsVectorLayer::UniqueValues:
+    {
+      QList<QVariant> values;
+      vl->dataProvider()->uniqueValues( idx, values );
+
+      QComboBox *cb = new QComboBox( parent );
+      cb->setEditable( true );
+
+      for ( QList<QVariant>::iterator it = values.begin(); it != values.end(); it++ )
+        cb->addItem( it->toString() );
+
+      int idx = cb->findText( value.toString() );
+      if ( idx >= 0 )
+        cb->setCurrentIndex( idx );
+
+      myWidget = cb;
+    }
+    break;
+
+    case QgsVectorLayer::Enumeration:
+    {
+      QStringList enumValues;
+      vl->dataProvider()->enumValues( idx, enumValues );
+
+      QComboBox *cb = new QComboBox( parent );
+      QStringList::const_iterator s_it = enumValues.constBegin();
+      for ( ; s_it != enumValues.constEnd(); ++s_it )
+      {
+        cb->addItem( *s_it );
+      }
+      int idx = cb->findText( value.toString() );
+      if ( idx >= 0 )
+      {
+        cb->setCurrentIndex( idx );
+      }
+      myWidget = cb;
+    }
+    break;
+
+    case QgsVectorLayer::ValueMap:
+    {
+      const QMap<QString, QVariant> &map = vl->valueMap( idx );
+
+      QComboBox *cb = new QComboBox( parent );
+
+      for ( QMap<QString, QVariant>::const_iterator it = map.begin(); it != map.end(); it++ )
+      {
+        cb->addItem( it.key(), it.value() );
+      }
+
+      int idx = cb->findData( value );
+      if ( idx >= 0 )
+        cb->setCurrentIndex( idx );
+
+      myWidget = cb;
+    }
+    break;
+
+    case QgsVectorLayer::Classification:
+    {
+      int classificationField = -1;
+      QMap<QString, QString> classes;
+
+      const QgsUniqueValueRenderer *uvr = dynamic_cast<const QgsUniqueValueRenderer *>( vl->renderer() );
+      if ( uvr )
+      {
+        classificationField = uvr->classificationField();
+
+        const QList<QgsSymbol *> symbols = uvr->symbols();
+
+        for ( int i = 0; i < symbols.size(); i++ )
+        {
+          QString label = symbols[i]->label();
+          QString name = symbols[i]->lowerValue();
+
+          if ( label == "" )
+            label = name;
+
+          classes.insert( name, label );
+        }
+      }
+
+      QComboBox *cb = new QComboBox( parent );
+      for ( QMap<QString, QString>::const_iterator it = classes.begin(); it != classes.end(); it++ )
+      {
+        cb->addItem( it.value(), it.key() );
+      }
+
+      int idx = cb->findData( value );
+      if ( idx >= 0 )
+        cb->setCurrentIndex( idx );
+
+      myWidget = cb;
+    }
+    break;
+
+    case QgsVectorLayer::SliderRange:
+    case QgsVectorLayer::EditRange:
+    {
+      if ( myFieldType == QVariant::Int )
+      {
+        int min = vl->range( idx ).mMin.toInt();
+        int max = vl->range( idx ).mMax.toInt();
+        int step = vl->range( idx ).mStep.toInt();
+
+        if ( editType == QgsVectorLayer::EditRange )
+        {
+          QSpinBox *sb = new QSpinBox( parent );
+
+          sb->setRange( min, max );
+          sb->setSingleStep( step );
+          sb->setValue( value.toInt() );
+
+          myWidget = sb;
+        }
+        else
+        {
+          QSlider *sl = new QSlider( Qt::Horizontal, parent );
+
+          sl->setRange( min, max );
+          sl->setSingleStep( step );
+          sl->setValue( value.toInt() );
+
+          myWidget = sl;
+        }
+        break;
+      }
+      else if ( myFieldType == QVariant::Double )
+      {
+        double min = vl->range( idx ).mMin.toDouble();
+        double max = vl->range( idx ).mMax.toDouble();
+        double step = vl->range( idx ).mStep.toDouble();
+        QDoubleSpinBox *dsb = new QDoubleSpinBox( parent );
+
+        dsb->setRange( min, max );
+        dsb->setSingleStep( step );
+        dsb->setValue( value.toDouble() );
+
+        myWidget = dsb;
+        break;
+      }
+    }
+
+    // fall-through
+
+    case QgsVectorLayer::LineEdit:
+    case QgsVectorLayer::UniqueValuesEditable:
+    case QgsVectorLayer::Immutable:
+    default:
+    {
+      QLineEdit *le = new QLineEdit( value.toString(), parent );
+
+      if ( editType == QgsVectorLayer::Immutable )
+      {
+        le->setEnabled( false );
+      }
+
+      if ( editType == QgsVectorLayer::UniqueValuesEditable )
+      {
+        QList<QVariant> values;
+        vl->dataProvider()->uniqueValues( idx, values );
+
+        QStringList svalues;
+        for ( QList<QVariant>::const_iterator it = values.begin(); it != values.end(); it++ )
+          svalues << it->toString();
+
+        QCompleter *c = new QCompleter( svalues );
+        c->setCompletionMode( QCompleter::PopupCompletion );
+        le->setCompleter( c );
+      }
+
+      if ( myFieldType == QVariant::Int )
+      {
+        le->setValidator( new QIntValidator( le ) );
+      }
+      else if ( myFieldType == QVariant::Double )
+      {
+        le->setValidator( new QDoubleValidator( le ) );
+      }
+
+      myWidget = le;
+    }
+    break;
+
+    case QgsVectorLayer::FileName:
+    {
+      QLineEdit *le = new QLineEdit( value.toString() );
+
+      QPushButton *pb = new QPushButton( tr( "..." ) );
+      connect( pb, SIGNAL( clicked() ), new QgsAttributeEditor( pb ), SLOT( selectFileName() ) );
+
+      QHBoxLayout *hbl = new QHBoxLayout();
+      hbl->addWidget( le );
+      hbl->addWidget( pb );
+
+      myWidget = new QWidget( parent );
+      myWidget->setLayout( hbl );
+    }
+    break;
+  }
+
+  return myWidget;
+}
+
+bool QgsAttributeEditor::retrieveValue( QWidget *widget, QgsVectorLayer *vl, int idx, QVariant &value )
+{
+  const QgsField &theField = vl->pendingFields()[idx];
+  QgsVectorLayer::EditType editType = vl->editType( idx );
+  bool modified = false;
+  QString text;
+
+  QLineEdit *le = dynamic_cast<QLineEdit *>( widget );
+  if ( le )
+  {
+    text = le->text();
+    modified = le->isModified();
+  }
+
+  QComboBox *cb = dynamic_cast<QComboBox *>( widget );
+  if ( cb )
+  {
+    if ( editType == QgsVectorLayer::UniqueValues ||
+         editType == QgsVectorLayer::ValueMap ||
+         editType == QgsVectorLayer::Classification )
+    {
+      text = cb->itemData( cb->currentIndex() ).toString();
+    }
+    else
+    {
+      text = cb->currentText();
+    }
+  }
+
+  QSpinBox *sb = dynamic_cast<QSpinBox *>( widget );
+  if ( sb )
+  {
+    text = QString::number( sb->value() );
+  }
+
+  QSlider *slider = dynamic_cast<QSlider *>( widget );
+  if ( slider )
+  {
+    text = QString::number( slider->value() );
+  }
+  QDoubleSpinBox *dsb = dynamic_cast<QDoubleSpinBox *>( widget );
+  if ( dsb )
+  {
+    text = QString::number( dsb->value() );
+  }
+
+  le = widget->findChild<QLineEdit *>();
+  if ( le )
+  {
+    text = le->text();
+  }
+
+  switch ( theField.type() )
+  {
+    case QVariant::Int:
+    {
+      bool ok;
+      int myIntValue = text.toInt( &ok );
+      if ( ok && !text.isEmpty() )
+      {
+        value = QVariant( myIntValue );
+        modified = true;
+      }
+      else if ( modified )
+      {
+        value = QVariant( QString::null );
+      }
+    }
+    break;
+    case QVariant::Double:
+    {
+      bool ok;
+      double myDblValue = text.toDouble( &ok );
+      if ( ok && !text.isEmpty() )
+      {
+        value = QVariant( myDblValue );
+        modified = true;
+      }
+      else if ( modified )
+      {
+        value = QVariant( QString::null );
+      }
+    }
+    break;
+    default: //string
+      modified = true;
+      value = QVariant( text );
+      break;
+  }
+
+  return modified;
+}

Added: trunk/qgis/src/app/qgsattributeeditor.h
===================================================================
--- trunk/qgis/src/app/qgsattributeeditor.h	                        (rev 0)
+++ trunk/qgis/src/app/qgsattributeeditor.h	2009-07-23 11:11:41 UTC (rev 11154)
@@ -0,0 +1,42 @@
+/***************************************************************************
+                         qgsattributeeditor.h  -  description
+                             -------------------
+    begin                : July 2009
+    copyright            : (C) 2009 by Jürgen E. Fischer
+    email                : jef at norbit.de
+ ***************************************************************************/
+
+/***************************************************************************
+ *                                                                         *
+ *   This program is free software; you can redistribute it and/or modify  *
+ *   it under the terms of the GNU General Public License as published by  *
+ *   the Free Software Foundation; either version 2 of the License, or     *
+ *   (at your option) any later version.                                   *
+ *                                                                         *
+ ***************************************************************************/
+/* $Id$ */
+#ifndef QGSATTRIBUTEEDITOR_H
+#define QGSATTRIBUTEEDITOR_H
+
+#include <QVariant>
+
+class QObject;
+class QWidget;
+class QgsVectorLayer;
+
+class QgsAttributeEditor : public QObject
+{
+    Q_OBJECT
+
+  public:
+    QgsAttributeEditor( QObject *parent ) : QObject( parent ) {}
+
+  public slots:
+    void selectFileName( void );
+
+    static QWidget *createAttributeEditor( QWidget *parent, QgsVectorLayer *vl, int idx, const QVariant &value );
+    static bool retrieveValue( QWidget *widget, QgsVectorLayer *vl, int idx, QVariant &value );
+};
+
+
+#endif

Modified: trunk/qgis/src/app/qgsvectorlayerproperties.cpp
===================================================================
--- trunk/qgis/src/app/qgsvectorlayerproperties.cpp	2009-07-23 11:07:34 UTC (rev 11153)
+++ trunk/qgis/src/app/qgsvectorlayerproperties.cpp	2009-07-23 11:11:41 UTC (rev 11154)
@@ -65,7 +65,7 @@
   QgsVectorLayer *lyr,
   QWidget * parent,
   Qt::WFlags fl
-  )
+)
     : QDialog( parent, fl ),
     layer( lyr ),
     mRendererDialog( 0 )
@@ -182,7 +182,7 @@
     tblAttributes->item( row, i )->setFlags( tblAttributes->item( row, i )->flags() & ~Qt::ItemIsEditable );
 
   QString buttonText;
-  switch (layer->editType( idx ))
+  switch ( layer->editType( idx ) )
   {
     case QgsVectorLayer::LineEdit:
       buttonText = "Line Edit";
@@ -215,13 +215,13 @@
       buttonText =  tr( "Immutable" );
       break;
   }
-  QPushButton * pb = new QPushButton(buttonText);
+  QPushButton * pb = new QPushButton( buttonText );
   tblAttributes->setCellWidget( row, 6, pb );
   connect( pb, SIGNAL( pressed() ), this, SLOT( attributeTypeDialog( ) ) );
   mButtonMap.insert( idx, pb );
 
   //set the alias for the attribute
-  tblAttributes->setItem( row, 7, new QTableWidgetItem(layer->attributeAlias(idx)));
+  tblAttributes->setItem( row, 7, new QTableWidgetItem( layer->attributeAlias( idx ) ) );
 
 }
 
@@ -234,35 +234,35 @@
 {
   int index = -1;
   QMap<int, QPushButton*>::iterator it = mButtonMap.begin();
-  for (; it != mButtonMap.end() ;it++)
+  for ( ; it != mButtonMap.end() ;it++ )
   {
-     if (it.value()->isDown())
-     {
-       index = it.key();
-     }
+    if ( it.value()->isDown() )
+    {
+      index = it.key();
+    }
   }
 
   QgsAttributeTypeDialog attributeTypeDialog( layer );
 
-  if (mValueMaps.contains(index))
+  if ( mValueMaps.contains( index ) )
   {
-    attributeTypeDialog.setValueMap(mValueMaps[index]);
+    attributeTypeDialog.setValueMap( mValueMaps[index] );
   }
   else
   {
     attributeTypeDialog.setValueMap( QMap<QString, QVariant>() );
   }
 
-  if (mRanges.contains(index))
+  if ( mRanges.contains( index ) )
   {
     attributeTypeDialog.setRange( mRanges[index] );
   }
   else
   {
-    attributeTypeDialog.setRange( QgsVectorLayer::RangeData(0, 5, 1));
+    attributeTypeDialog.setRange( QgsVectorLayer::RangeData( 0, 5, 1 ) );
   }
 
-  if (mEditTypeMap.contains(index))
+  if ( mEditTypeMap.contains( index ) )
   {
     attributeTypeDialog.setIndex( index, mEditTypeMap[index] );
   }
@@ -271,11 +271,11 @@
     attributeTypeDialog.setIndex( index );
   }
 
-  if (!attributeTypeDialog.exec())
+  if ( !attributeTypeDialog.exec() )
     return;
 
   QgsVectorLayer::EditType editType = attributeTypeDialog.editType();
-  mEditTypeMap.insert(index, editType);
+  mEditTypeMap.insert( index, editType );
   QString buttonText;
   switch ( editType )
   {
@@ -293,15 +293,15 @@
       break;
     case QgsVectorLayer::ValueMap:
       buttonText = "Value Map";
-      mValueMaps.insert(index, attributeTypeDialog.valueMap() );
+      mValueMaps.insert( index, attributeTypeDialog.valueMap() );
       break;
     case QgsVectorLayer::EditRange:
       buttonText = "Edit Range";
-      mRanges.insert(index, attributeTypeDialog.rangeData());
+      mRanges.insert( index, attributeTypeDialog.rangeData() );
       break;
     case QgsVectorLayer::SliderRange:
       buttonText = "Slider Range";
-      mRanges.insert(index, attributeTypeDialog.rangeData());
+      mRanges.insert( index, attributeTypeDialog.rangeData() );
       break;
     case QgsVectorLayer::FileName:
       buttonText = "File Name";
@@ -351,7 +351,7 @@
   QgsAddAttrDialog dialog( layer->dataProvider(), this );
   if ( dialog.exec() == QDialog::Accepted )
   {
-    layer->beginEditCommand("Attribute added");
+    layer->beginEditCommand( "Attribute added" );
     if ( !addAttribute( dialog.field() ) )
     {
       layer->destroyEditCommand();
@@ -596,45 +596,45 @@
 }
 
 
-QgsVectorLayer::EditType QgsVectorLayerProperties::getEditType(QString text)
+QgsVectorLayer::EditType QgsVectorLayerProperties::getEditType( QString text )
 {
-  if (text == "Line Edit")
+  if ( text == "Line Edit" )
   {
     return QgsVectorLayer::LineEdit;
   }
-  else if (text == "Unique Values")
+  else if ( text == "Unique Values" )
   {
     return QgsVectorLayer::UniqueValues;
   }
-  else if (text == "Unique Values Editable")
+  else if ( text == "Unique Values Editable" )
   {
     return QgsVectorLayer::UniqueValuesEditable;
   }
-  else if (text == "Classification")
+  else if ( text == "Classification" )
   {
     return QgsVectorLayer::Classification;
   }
-  else if (text == "Value Map")
+  else if ( text == "Value Map" )
   {
     return QgsVectorLayer::ValueMap;
   }
-  else if (text == "Edit Range")
+  else if ( text == "Edit Range" )
   {
     return QgsVectorLayer::EditRange;
   }
-  else if (text == "Slider Range")
+  else if ( text == "Slider Range" )
   {
     return QgsVectorLayer::SliderRange;
   }
-  else if (text == "File Name")
+  else if ( text == "File Name" )
   {
     return QgsVectorLayer::FileName;
   }
-  else if (text == "Enumeration")
+  else if ( text == "Enumeration" )
   {
     return QgsVectorLayer::Enumeration;
   }
-  else if (text == "Immutable")
+  else if ( text == "Immutable" )
   {
     return QgsVectorLayer::Immutable;
   }
@@ -680,18 +680,17 @@
   for ( int i = 0; i < tblAttributes->rowCount(); i++ )
   {
     int idx = tblAttributes->item( i, 0 )->text().toInt();
-    const QgsField &field = layer->pendingFields()[idx];
 
     QPushButton *pb = dynamic_cast<QPushButton*>( tblAttributes->cellWidget( i, 6 ) );
     if ( !pb )
       continue;
 
-    QgsVectorLayer::EditType editType = getEditType( pb->text());
+    QgsVectorLayer::EditType editType = getEditType( pb->text() );
     layer->setEditType( idx, editType );
 
     if ( editType == QgsVectorLayer::ValueMap )
     {
-      if (mValueMaps.contains( idx ))
+      if ( mValueMaps.contains( idx ) )
       {
         QMap<QString, QVariant> &map = layer->valueMap( idx );
         map.clear();
@@ -701,7 +700,7 @@
     else if ( editType == QgsVectorLayer::EditRange ||
               editType == QgsVectorLayer::SliderRange )
     {
-      if (mRanges.contains( idx ) )
+      if ( mRanges.contains( idx ) )
       {
         layer->range( idx ) = mRanges[idx];
       }



More information about the QGIS-commit mailing list