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

svn_qgis at osgeo.org svn_qgis at osgeo.org
Wed Aug 27 03:44:06 EDT 2008


Author: jef
Date: 2008-08-27 03:44:03 -0400 (Wed, 27 Aug 2008)
New Revision: 9182

Modified:
   trunk/qgis/python/core/qgsvectorlayer.sip
   trunk/qgis/src/app/qgsattributedialog.cpp
   trunk/qgis/src/app/qgsvectorlayerproperties.cpp
   trunk/qgis/src/core/qgsvectorlayer.cpp
   trunk/qgis/src/core/qgsvectorlayer.h
Log:
vector layer updates
- fix: retrieve only existing attributes from provider when editing and set
  added attributes to null
- introduce slider widget for attribute dialog
- include added attributes when editing from identify



Modified: trunk/qgis/python/core/qgsvectorlayer.sip
===================================================================
--- trunk/qgis/python/core/qgsvectorlayer.sip	2008-08-27 07:32:27 UTC (rev 9181)
+++ trunk/qgis/python/core/qgsvectorlayer.sip	2008-08-27 07:44:03 UTC (rev 9182)
@@ -11,7 +11,8 @@
     UniqueValuesEditable,
     ValueMap,
     Classification,
-    Range,
+    EditRange,
+    SliderRange
   };
    
   struct RangeData {

Modified: trunk/qgis/src/app/qgsattributedialog.cpp
===================================================================
--- trunk/qgis/src/app/qgsattributedialog.cpp	2008-08-27 07:32:27 UTC (rev 9181)
+++ trunk/qgis/src/app/qgsattributedialog.cpp	2008-08-27 07:44:03 UTC (rev 9182)
@@ -32,6 +32,7 @@
 #include <QFrame>
 #include <QScrollArea>
 #include <QCompleter>
+#include <QSlider>
 #include <QSpinBox>
 #include <QDoubleSpinBox>
 
@@ -45,7 +46,7 @@
   if ( mpFeature == NULL || vl->dataProvider() == NULL )
     return;
 
-  const QgsFieldMap &theFieldMap = vl->dataProvider()->fields();
+  const QgsFieldMap &theFieldMap = vl->pendingFields();
 
   if ( theFieldMap.isEmpty() ) return;
 
@@ -161,7 +162,8 @@
       }
       break;
 
-      case QgsVectorLayer::Range:
+      case QgsVectorLayer::SliderRange:
+      case QgsVectorLayer::EditRange:
       {
         if ( myFieldType == QVariant::Int )
         {
@@ -169,13 +171,26 @@
           int max = vl->range( it.key() ).mMax.toInt();
           int step = vl->range( it.key() ).mStep.toInt();
 
-          QSpinBox *sb = new QSpinBox();
-          sb->setMinimum( min );
-          sb->setMaximum( max );
-          sb->setSingleStep( step );
-          sb->setValue( it.value().toInt() );
+          if ( editType == QgsVectorLayer::EditRange )
+          {
+            QSpinBox *sb = new QSpinBox();
 
-          myWidget = sb;
+            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 )
@@ -185,16 +200,13 @@
           double step = vl->range( it.key() ).mStep.toDouble();
           QDoubleSpinBox *dsb = new QDoubleSpinBox();
 
-          dsb->setMinimum( min );
-          dsb->setMaximum( max );
+          dsb->setRange( min, max );
           dsb->setSingleStep( step );
           dsb->setValue( it.value().toDouble() );
 
           myWidget = dsb;
-
           break;
         }
-
       }
 
       // fall-through
@@ -292,13 +304,18 @@
       }
     }
 
-
     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 )
     {

Modified: trunk/qgis/src/app/qgsvectorlayerproperties.cpp
===================================================================
--- trunk/qgis/src/app/qgsvectorlayerproperties.cpp	2008-08-27 07:32:27 UTC (rev 9181)
+++ trunk/qgis/src/app/qgsvectorlayerproperties.cpp	2008-08-27 07:44:03 UTC (rev 9182)
@@ -166,7 +166,8 @@
   cb->addItem( tr( "unique values (editable)" ), QgsVectorLayer::UniqueValuesEditable );
   cb->addItem( tr( "value map" ), QgsVectorLayer::ValueMap );
   cb->addItem( tr( "classification" ), QgsVectorLayer::Classification );
-  cb->addItem( tr( "range" ), QgsVectorLayer::Range );
+  cb->addItem( tr( "range (editable)" ), QgsVectorLayer::EditRange );
+  cb->addItem( tr( "range (slider)" ), QgsVectorLayer::SliderRange );
   cb->setSizeAdjustPolicy( QComboBox::AdjustToContentsOnFirstShow );
   cb->setCurrentIndex( layer->editType( idx ) );
 
@@ -188,7 +189,8 @@
 
     tblAttributes->setItem( row, 7, new QTableWidgetItem( mapList.join( ";" ) ) );
   }
-  else if ( layer->editType( idx ) == QgsVectorLayer::Range )
+  else if ( layer->editType( idx ) == QgsVectorLayer::EditRange ||
+            layer->editType( idx ) == QgsVectorLayer::SliderRange )
   {
     tblAttributes->setItem(
       row, 7,
@@ -538,7 +540,8 @@
         }
       }
     }
-    else if ( editType == QgsVectorLayer::Range )
+    else if ( editType == QgsVectorLayer::EditRange ||
+              editType == QgsVectorLayer::SliderRange )
     {
       QStringList values = tblAttributes->item( i, 7 )->text().split( ";" );
 

Modified: trunk/qgis/src/core/qgsvectorlayer.cpp
===================================================================
--- trunk/qgis/src/core/qgsvectorlayer.cpp	2008-08-27 07:32:27 UTC (rev 9181)
+++ trunk/qgis/src/core/qgsvectorlayer.cpp	2008-08-27 07:44:03 UTC (rev 9182)
@@ -1134,6 +1134,9 @@
     for ( QgsAttributeMap::const_iterator it = map.begin(); it != map.end(); it++ )
       f.changeAttribute( it.key(), it.value() );
   }
+
+  for ( QgsAttributeList::const_iterator it = mFetchNullAttributes.begin(); it != mFetchNullAttributes.end(); it++ )
+    f.changeAttribute( *it, QVariant( QString::null ) );
 }
 
 void QgsVectorLayer::updateFeatureGeometry( QgsFeature &f )
@@ -1165,7 +1168,27 @@
   //look in the normal features of the provider
   if ( mFetchAttributes.size() > 0 )
   {
-    mDataProvider->select( mFetchAttributes, rect, fetchGeometries, useIntersect );
+    mFetchNullAttributes.clear();
+
+    if ( mEditable )
+    {
+      // fetch only available field from provider
+      QgsAttributeList provAttributes;
+      for ( QgsAttributeList::iterator it = mFetchAttributes.begin(); it != mFetchAttributes.end(); it++ )
+      {
+        if ( !mUpdatedFields.contains( *it ) )
+          continue;
+
+        if ( !mDeletedAttributeIds.contains( *it ) && !mAddedAttributeIds.contains( *it ) )
+          provAttributes << *it;
+        else
+          mFetchNullAttributes << *it;
+      }
+
+      mDataProvider->select( provAttributes, rect, fetchGeometries, useIntersect );
+    }
+    else
+      mDataProvider->select( mFetchAttributes, rect, fetchGeometries, useIntersect );
   }
   else
   {
@@ -1957,6 +1980,7 @@
   mEditable = true;
 
   mUpdatedFields = mDataProvider->fields();
+
   mMaxUpdatedIndex = -1;
 
   for ( QgsFieldMap::const_iterator it = mUpdatedFields.begin(); it != mUpdatedFields.end(); it++ )
@@ -2049,7 +2073,7 @@
           mValueMaps[ name ].insert( value.attribute( "key" ), value.attribute( "value" ) );
         }
       }
-      else if ( editType == Range )
+      else if ( editType == EditRange || editType == SliderRange )
       {
         QVariant min = editTypeElement.attribute( "min" );
         QVariant max = editTypeElement.attribute( "max" );
@@ -2295,7 +2319,7 @@
           }
         }
       }
-      else if ( it.value() == Range )
+      else if ( it.value() == EditRange || it.value() == SliderRange )
       {
         if ( mRanges.contains( it.key() ) )
         {
@@ -3266,8 +3290,6 @@
         if ( wkbType == QGis::WKBMultiPoint25D ) // ignore Z value
           ptr += sizeof( double );
 
-        QgsDebugMsg( QString( "...WKBMultiPoint (%1, %2)" ).arg( x ).arg( y ) );
-
         transformPoint( x, y, theMapToPixelTransform, ct );
         //QPointF pt(x - (marker->width()/2),  y - (marker->height()/2));
         //QPointF pt(x/markerScaleFactor - (marker->width()/2),  y/markerScaleFactor - (marker->height()/2));

Modified: trunk/qgis/src/core/qgsvectorlayer.h
===================================================================
--- trunk/qgis/src/core/qgsvectorlayer.h	2008-08-27 07:32:27 UTC (rev 9181)
+++ trunk/qgis/src/core/qgsvectorlayer.h	2008-08-27 07:44:03 UTC (rev 9182)
@@ -66,7 +66,8 @@
       UniqueValuesEditable,
       ValueMap,
       Classification,
-      Range
+      EditRange,
+      SliderRange
     };
 
     struct RangeData
@@ -341,7 +342,7 @@
      */
     void drawLabels( QPainter * p, const QgsRect& viewExtent, const QgsMapToPixel* cXf, const QgsCoordinateTransform* ct, double scale );
 
-    /** returns fields list which are not commited */
+    /** returns field list in the to-be-committed state */
     const QgsFieldMap &pendingFields();
 
     /** returns list of attributes */
@@ -608,6 +609,7 @@
     bool mFetching;
     QgsRect mFetchRect;
     QgsAttributeList mFetchAttributes;
+    QgsAttributeList mFetchNullAttributes;
     bool mFetchGeometry;
 
     QSet<int> mFetchConsidered;



More information about the QGIS-commit mailing list