[QGIS Commit] r15691 - in trunk/qgis/src: app core

svn_qgis at osgeo.org svn_qgis at osgeo.org
Sat Apr 9 20:56:17 EDT 2011


Author: jef
Date: 2011-04-09 17:56:17 -0700 (Sat, 09 Apr 2011)
New Revision: 15691

Modified:
   trunk/qgis/src/app/qgsattributetypedialog.cpp
   trunk/qgis/src/app/qgsattributetypedialog.h
   trunk/qgis/src/app/qgsattributetypeloaddialog.cpp
   trunk/qgis/src/app/qgsvectorlayerproperties.cpp
   trunk/qgis/src/core/qgsvectorlayer.cpp
Log:
cleanup and fix attribute widget configuration

Modified: trunk/qgis/src/app/qgsattributetypedialog.cpp
===================================================================
--- trunk/qgis/src/app/qgsattributetypedialog.cpp	2011-04-09 22:28:21 UTC (rev 15690)
+++ trunk/qgis/src/app/qgsattributetypedialog.cpp	2011-04-10 00:56:17 UTC (rev 15691)
@@ -17,10 +17,9 @@
 /* $Id$ */
 
 #include "qgsattributetypedialog.h"
-
 #include "qgsattributetypeloaddialog.h"
-
 #include "qgsvectordataprovider.h"
+
 #include "qgslogger.h"
 
 #include <QTableWidgetItem>
@@ -33,19 +32,18 @@
 #include <cfloat>
 
 QgsAttributeTypeDialog::QgsAttributeTypeDialog( QgsVectorLayer *vl )
-    : QDialog(),
-    mLayer( vl )
+    : QDialog()
+    , mLayer( vl )
 {
   setupUi( this );
   tableWidget->insertRow( 0 );
   connect( selectionComboBox, SIGNAL( currentIndexChanged( int ) ), this, SLOT( setStackPage( int ) ) );
-  connect( removeSelectedButton, SIGNAL( pressed( ) ), this, SLOT( removeSelectedButtonPushed( ) ) );
-  connect( loadFromLayerButton, SIGNAL( pressed( ) ), this, SLOT( loadFromLayerButtonPushed( ) ) );
-  connect( loadFromCSVButton, SIGNAL( pressed( ) ), this, SLOT( loadFromCSVButtonPushed( ) ) );
-  connect( tableWidget,  SIGNAL( cellChanged( int, int ) ), this, SLOT( vCellChanged( int, int ) ) );
+  connect( removeSelectedButton, SIGNAL( clicked() ), this, SLOT( removeSelectedButtonPushed() ) );
+  connect( loadFromLayerButton, SIGNAL( clicked() ), this, SLOT( loadFromLayerButtonPushed() ) );
+  connect( loadFromCSVButton, SIGNAL( clicked() ), this, SLOT( loadFromCSVButtonPushed() ) );
+  connect( tableWidget, SIGNAL( cellChanged( int, int ) ), this, SLOT( vCellChanged( int, int ) ) );
 }
 
-
 QgsAttributeTypeDialog::~QgsAttributeTypeDialog()
 {
 
@@ -211,6 +209,10 @@
 {
   switch ( editType )
   {
+    case QgsVectorLayer::LineEdit:
+      setPage( 0 );
+      break;
+
     case QgsVectorLayer::Classification:
       setPage( 1 );
       break;
@@ -252,21 +254,14 @@
 
     case QgsVectorLayer::TextEdit:
       setPage( 10 );
+      break;
 
     case QgsVectorLayer::Calendar:
       setPage( 11 );
-
-    case QgsVectorLayer::LineEdit:
-      setPage( 0 );
       break;
   }
 }
 
-void QgsAttributeTypeDialog::setPageForIndex( int index )
-{
-  setPageForEditType( mLayer->editType( index ) );
-}
-
 void QgsAttributeTypeDialog::setValueMap( QMap<QString, QVariant> valueMap )
 {
   mValueMap = valueMap;
@@ -277,19 +272,10 @@
   mRangeData = range;
 }
 
-void QgsAttributeTypeDialog::setIndex( int index, int editTypeInt )
+void QgsAttributeTypeDialog::setIndex( int index, QgsVectorLayer::EditType editType )
 {
   mIndex = index;
   //need to set index for combobox
-  QgsVectorLayer::EditType editType;
-  if ( editTypeInt > -1 )
-  {
-    editType = QgsVectorLayer::EditType( editTypeInt );
-  }
-  else
-  {
-    editType = mLayer->editType( index );
-  }
 
   setWindowTitle( defaultWindowTitle() + " \"" + mLayer->pendingFields()[index].name() + "\"" );
   QgsAttributeList attributeList = QgsAttributeList();
@@ -346,33 +332,20 @@
   }
   valuesLabel->setText( text );
 
-  //setPageForIndex( index );
   setPageForEditType( editType );
 
   switch ( editType )
   {
     case QgsVectorLayer::ValueMap:
     {
-
       tableWidget->clearContents();
       for ( int i = tableWidget->rowCount() - 1; i > 0; i-- )
       {
         tableWidget->removeRow( i );
       }
 
-      // if some value map already present use it
-      QMap<QString, QVariant> map;
-      if ( !mValueMap.empty() )
-      {
-        map = mValueMap;
-      }
-      else
-      {
-        map = mLayer->valueMap( index );
-      }
-
       int row = 0;
-      for ( QMap<QString, QVariant>::iterator mit = map.begin(); mit != map.end(); mit++, row++ )
+      for ( QMap<QString, QVariant>::iterator mit = mValueMap.begin(); mit != mValueMap.end(); mit++, row++ )
       {
         tableWidget->insertRow( row );
         if ( mit.value().isNull() )
@@ -395,15 +368,15 @@
     {
       if ( mLayer->pendingFields()[mIndex].type() != QVariant::Int )
       {
-        minimumSpinBox->setValue( mLayer->range( index ).mMin.toInt() );
-        maximumSpinBox->setValue( mLayer->range( index ).mMax.toInt() );
-        stepSpinBox->setValue( mLayer->range( index ).mStep.toInt() );
+        minimumSpinBox->setValue( mRangeData.mMin.toInt() );
+        maximumSpinBox->setValue( mRangeData.mMax.toInt() );
+        stepSpinBox->setValue( mRangeData.mStep.toInt() );
       }
       else if ( mLayer->pendingFields()[mIndex].type() == QVariant::Double )
       {
-        minimumDoubleSpinBox->setValue( mLayer->range( index ).mMin.toDouble() );
-        maximumDoubleSpinBox->setValue( mLayer->range( index ).mMax.toDouble() );
-        stepDoubleSpinBox->setValue( mLayer->range( index ).mStep.toDouble() );
+        minimumDoubleSpinBox->setValue( mRangeData.mMin.toDouble() );
+        maximumDoubleSpinBox->setValue( mRangeData.mMax.toDouble() );
+        stepDoubleSpinBox->setValue( mRangeData.mStep.toDouble() );
       }
       if ( editType == QgsVectorLayer::EditRange )
       {
@@ -424,7 +397,16 @@
       editableUniqueValues->setChecked( editType == QgsVectorLayer::UniqueValuesEditable );
       break;
 
-    default:
+    case QgsVectorLayer::LineEdit:
+    case QgsVectorLayer::UniqueValues:
+    case QgsVectorLayer::Classification:
+    case QgsVectorLayer::CheckBox:
+    case QgsVectorLayer::FileName:
+    case QgsVectorLayer::Enumeration:
+    case QgsVectorLayer::Immutable:
+    case QgsVectorLayer::Hidden:
+    case QgsVectorLayer::TextEdit:
+    case QgsVectorLayer::Calendar:
       break;
   }
 }

Modified: trunk/qgis/src/app/qgsattributetypedialog.h
===================================================================
--- trunk/qgis/src/app/qgsattributetypedialog.h	2011-04-09 22:28:21 UTC (rev 15690)
+++ trunk/qgis/src/app/qgsattributetypedialog.h	2011-04-10 00:56:17 UTC (rev 15691)
@@ -45,7 +45,7 @@
      * @param index of page to be selected
      * @param editTypeInt type of edit type which was selected before save
      */
-    void setIndex( int index, int editTypeInt = -1 );
+    void setIndex( int index, QgsVectorLayer::EditType editType );
 
     /**
      * Setting page which is to be selected
@@ -129,12 +129,6 @@
     QString defaultWindowTitle();
 
     /**
-     * Function to set page index
-     * @param index index of page to be changed
-     */
-    void setPageForIndex( int index );
-
-    /**
      * Function to set page according to edit type
      * @param editType edit type to set page
      */

Modified: trunk/qgis/src/app/qgsattributetypeloaddialog.cpp
===================================================================
--- trunk/qgis/src/app/qgsattributetypeloaddialog.cpp	2011-04-09 22:28:21 UTC (rev 15690)
+++ trunk/qgis/src/app/qgsattributetypeloaddialog.cpp	2011-04-10 00:56:17 UTC (rev 15691)
@@ -71,10 +71,11 @@
 void QgsAttributeTypeLoadDialog::fillLayerList()
 {
   layerComboBox->clear();
-  QMap<QString, QgsMapLayer*>::iterator layer_it = QgsMapLayerRegistry::instance()->mapLayers().begin();
-  for ( ; layer_it != QgsMapLayerRegistry::instance()->mapLayers().end(); layer_it++ )
+  foreach( QgsMapLayer *l, QgsMapLayerRegistry::instance()->mapLayers() )
   {
-    layerComboBox->addItem( layer_it.value()->name(), layer_it.key() );
+    QgsVectorLayer *vl = qobject_cast< QgsVectorLayer * >( l );
+    if ( vl )
+      layerComboBox->addItem( vl->name(), vl->id() );
   }
 }
 

Modified: trunk/qgis/src/app/qgsvectorlayerproperties.cpp
===================================================================
--- trunk/qgis/src/app/qgsvectorlayerproperties.cpp	2011-04-09 22:28:21 UTC (rev 15690)
+++ trunk/qgis/src/app/qgsvectorlayerproperties.cpp	2011-04-10 00:56:17 UTC (rev 15691)
@@ -215,7 +215,7 @@
 
   QPushButton *pb = new QPushButton( editTypeButtonText( layer->editType( idx ) ) );
   tblAttributes->setCellWidget( row, attrEditTypeCol, pb );
-  connect( pb, SIGNAL( pressed() ), this, SLOT( attributeTypeDialog( ) ) );
+  connect( pb, SIGNAL( clicked() ), this, SLOT( attributeTypeDialog() ) );
   mButtonMap.insert( idx, pb );
 
   //set the alias for the attribute
@@ -231,7 +231,7 @@
   settings.setValue( "/Windows/VectorLayerProperties/row", tabWidget->currentIndex() );
 }
 
-void QgsVectorLayerProperties::attributeTypeDialog( )
+void QgsVectorLayerProperties::attributeTypeDialog()
 {
   QPushButton *pb = qobject_cast<QPushButton *>( sender() );
   if ( !pb )
@@ -243,38 +243,14 @@
 
   QgsAttributeTypeDialog attributeTypeDialog( layer );
 
-  if ( mValueMaps.contains( index ) )
-  {
-    attributeTypeDialog.setValueMap( mValueMaps[index] );
-  }
-  else
-  {
-    attributeTypeDialog.setValueMap( QMap<QString, QVariant>() );
-  }
+  attributeTypeDialog.setValueMap( mValueMaps.value( index, layer->valueMap( index ) ) );
+  attributeTypeDialog.setRange( mRanges.value( index, layer->range( index ) ) );
 
-  if ( mRanges.contains( index ) )
-  {
-    attributeTypeDialog.setRange( mRanges[index] );
-  }
-  else
-  {
-    attributeTypeDialog.setRange( QgsVectorLayer::RangeData( 0, 5, 1 ) );
-  }
+  QPair<QString, QString> checkStates = mCheckedStates.value( index, layer->checkedState( index ) );
+  attributeTypeDialog.setCheckedState( checkStates.first, checkStates.second );
 
-  if ( mEditTypeMap.contains( index ) )
-  {
-    attributeTypeDialog.setIndex( index, mEditTypeMap[index] );
-  }
-  else
-  {
-    attributeTypeDialog.setIndex( index );
-  }
+  attributeTypeDialog.setIndex( index, mEditTypeMap.value( index, layer->editType( index ) ) );
 
-  if ( mCheckedStates.contains( index ) )
-  {
-    attributeTypeDialog.setCheckedState( mCheckedStates[index].first, mCheckedStates[index].second );
-  }
-
   if ( !attributeTypeDialog.exec() )
     return;
 
@@ -295,8 +271,18 @@
       break;
     case QgsVectorLayer::CheckBox:
       mCheckedStates.insert( index, attributeTypeDialog.checkedState() );
-    default:
       break;
+    case QgsVectorLayer::LineEdit:
+    case QgsVectorLayer::TextEdit:
+    case QgsVectorLayer::UniqueValues:
+    case QgsVectorLayer::UniqueValuesEditable:
+    case QgsVectorLayer::Classification:
+    case QgsVectorLayer::FileName:
+    case QgsVectorLayer::Enumeration:
+    case QgsVectorLayer::Immutable:
+    case QgsVectorLayer::Hidden:
+    case QgsVectorLayer::Calendar:
+      break;
   }
 
   pb->setText( editTypeButtonText( editType ) );
@@ -622,31 +608,45 @@
     QgsVectorLayer::EditType editType = editTypeFromButtonText( pb->text() );
     layer->setEditType( idx, editType );
 
-    if ( editType == QgsVectorLayer::ValueMap )
+    switch ( editType )
     {
-      if ( mValueMaps.contains( idx ) )
-      {
-        QMap<QString, QVariant> &map = layer->valueMap( idx );
-        map.clear();
-        map = mValueMaps[idx];
-      }
+      case QgsVectorLayer::ValueMap:
+        if ( mValueMaps.contains( idx ) )
+        {
+          QMap<QString, QVariant> &map = layer->valueMap( idx );
+          map.clear();
+          map = mValueMaps[idx];
+        }
+        break;
+
+      case QgsVectorLayer::EditRange:
+      case QgsVectorLayer::SliderRange:
+      case QgsVectorLayer::DialRange:
+        if ( mRanges.contains( idx ) )
+        {
+          layer->range( idx ) = mRanges[idx];
+        }
+        break;
+
+      case QgsVectorLayer::CheckBox:
+        if ( mCheckedStates.contains( idx ) )
+        {
+          layer->setCheckedState( idx, mCheckedStates[idx].first, mCheckedStates[idx].second );
+        }
+        break;
+
+      case QgsVectorLayer::LineEdit:
+      case QgsVectorLayer::UniqueValues:
+      case QgsVectorLayer::UniqueValuesEditable:
+      case QgsVectorLayer::Classification:
+      case QgsVectorLayer::FileName:
+      case QgsVectorLayer::Enumeration:
+      case QgsVectorLayer::Immutable:
+      case QgsVectorLayer::Hidden:
+      case QgsVectorLayer::TextEdit:
+      case QgsVectorLayer::Calendar:
+        break;
     }
-    else if ( editType == QgsVectorLayer::EditRange ||
-              editType == QgsVectorLayer::SliderRange ||
-              editType == QgsVectorLayer::DialRange )
-    {
-      if ( mRanges.contains( idx ) )
-      {
-        layer->range( idx ) = mRanges[idx];
-      }
-    }
-    else if ( editType == QgsVectorLayer::CheckBox )
-    {
-      if ( mCheckedStates.contains( idx ) )
-      {
-        layer->setCheckedState( idx, mCheckedStates[idx].first, mCheckedStates[idx].second );
-      }
-    }
   }
 
   if ( layer->isUsingRendererV2() )

Modified: trunk/qgis/src/core/qgsvectorlayer.cpp
===================================================================
--- trunk/qgis/src/core/qgsvectorlayer.cpp	2011-04-09 22:28:21 UTC (rev 15690)
+++ trunk/qgis/src/core/qgsvectorlayer.cpp	2011-04-10 00:56:17 UTC (rev 15691)
@@ -2984,6 +2984,8 @@
       QDomElement editTypeElement = editTypeNode.toElement();
 
       QString name = editTypeElement.attribute( "name" );
+      if ( fieldNameIndex( name ) < -1 )
+        continue;
 
       EditType editType = ( EditType ) editTypeElement.attribute( "type" ).toInt();
       mEditTypes.insert( name, editType );
@@ -3170,38 +3172,54 @@
       editTypeElement.setAttribute( "name", it.key() );
       editTypeElement.setAttribute( "type", it.value() );
 
-      if ( it.value() == ValueMap )
+      switch (( EditType ) it.value() )
       {
-        if ( mValueMaps.contains( it.key() ) )
-        {
-          const QMap<QString, QVariant> &map = mValueMaps[ it.key()];
+        case ValueMap:
+          if ( mValueMaps.contains( it.key() ) )
+          {
+            const QMap<QString, QVariant> &map = mValueMaps[ it.key()];
 
-          for ( QMap<QString, QVariant>::const_iterator vmit = map.begin(); vmit != map.end(); vmit++ )
+            for ( QMap<QString, QVariant>::const_iterator vmit = map.begin(); vmit != map.end(); vmit++ )
+            {
+              QDomElement value = doc.createElement( "valuepair" );
+              value.setAttribute( "key", vmit.key() );
+              value.setAttribute( "value", vmit.value().toString() );
+              editTypeElement.appendChild( value );
+            }
+          }
+          break;
+
+        case EditRange:
+        case SliderRange:
+        case DialRange:
+          if ( mRanges.contains( it.key() ) )
           {
-            QDomElement value = doc.createElement( "valuepair" );
-            value.setAttribute( "key", vmit.key() );
-            value.setAttribute( "value", vmit.value().toString() );
-            editTypeElement.appendChild( value );
+            editTypeElement.setAttribute( "min", mRanges[ it.key()].mMin.toString() );
+            editTypeElement.setAttribute( "max", mRanges[ it.key()].mMax.toString() );
+            editTypeElement.setAttribute( "step", mRanges[ it.key()].mStep.toString() );
           }
-        }
+          break;
+
+        case CheckBox:
+          if ( mCheckedStates.contains( it.key() ) )
+          {
+            editTypeElement.setAttribute( "checked", mCheckedStates[ it.key()].first );
+            editTypeElement.setAttribute( "unchecked", mCheckedStates[ it.key()].second );
+          }
+          break;
+
+        case LineEdit:
+        case UniqueValues:
+        case UniqueValuesEditable:
+        case Classification:
+        case FileName:
+        case Hidden:
+        case TextEdit:
+        case Calendar:
+        case Enumeration:
+        case Immutable:
+          break;
       }
-      else if ( it.value() == EditRange || it.value() == SliderRange )
-      {
-        if ( mRanges.contains( it.key() ) )
-        {
-          editTypeElement.setAttribute( "min", mRanges[ it.key()].mMin.toString() );
-          editTypeElement.setAttribute( "max", mRanges[ it.key()].mMax.toString() );
-          editTypeElement.setAttribute( "step", mRanges[ it.key()].mStep.toString() );
-        }
-      }
-      else if ( it.value() == CheckBox )
-      {
-        if ( mCheckedStates.contains( it.key() ) )
-        {
-          editTypeElement.setAttribute( "checked", mCheckedStates[ it.key()].first );
-          editTypeElement.setAttribute( "unchecked", mCheckedStates[ it.key()].second );
-        }
-      }
 
       editTypesElement.appendChild( editTypeElement );
     }
@@ -3232,8 +3250,8 @@
     for ( ; a_it != mAttributeAliasMap.constEnd(); ++a_it )
     {
       int idx = fieldNameIndex( a_it.key() );
-      if( idx < 0 )
-	continue;
+      if ( idx < 0 )
+        continue;
 
       QDomElement aliasEntryElem = doc.createElement( "alias" );
       aliasEntryElem.setAttribute( "field", a_it.key() );



More information about the QGIS-commit mailing list