[QGIS Commit] r10708 - trunk/qgis/src/app

svn_qgis at osgeo.org svn_qgis at osgeo.org
Sat May 2 18:57:48 EDT 2009


Author: jef
Date: 2009-05-02 18:57:48 -0400 (Sat, 02 May 2009)
New Revision: 10708

Modified:
   trunk/qgis/src/app/qgscontinuouscolordialog.cpp
   trunk/qgis/src/app/qgscontinuouscolordialog.h
Log:
fix #1666

Modified: trunk/qgis/src/app/qgscontinuouscolordialog.cpp
===================================================================
--- trunk/qgis/src/app/qgscontinuouscolordialog.cpp	2009-05-02 22:03:19 UTC (rev 10707)
+++ trunk/qgis/src/app/qgscontinuouscolordialog.cpp	2009-05-02 22:57:48 UTC (rev 10708)
@@ -39,31 +39,16 @@
   QObject::connect( btnMaxValue, SIGNAL( clicked() ), this, SLOT( selectMaximumColor() ) );
 
   //find out the numerical fields of mVectorLayer
-  QgsVectorDataProvider *provider = mVectorLayer->dataProvider();
-  if ( provider )
-  {
-    const QgsFieldMap & fields = provider->fields();
-    int fieldNumber( 0 ), comboNumber( 0 );
-    QString str;
+  const QgsFieldMap & fields = mVectorLayer->pendingFields();
 
-    for ( QgsFieldMap::const_iterator it = fields.begin(); it != fields.end(); ++it )
+  for ( QgsFieldMap::const_iterator it = fields.begin(); it != fields.end(); ++it )
+  {
+    QVariant::Type type = it->type();
+    if ( type == QVariant::Int || type == QVariant::Double )
     {
-      QVariant::Type type = ( *it ).type();
-      if ( type == QVariant::Int || type == QVariant::Double )
-      {
-        str = ( *it ).name();
-        classificationComboBox->addItem( str );
-        mFieldMap.insert( std::make_pair( comboNumber, fieldNumber ) );
-        comboNumber++;
-      }
-      fieldNumber++;
+      classificationComboBox->addItem( it->name(), it.key() );
     }
   }
-  else
-  {
-    QgsDebugMsg( "data provider is null" );
-    return;
-  }
 
   //restore the correct colors for minimum and maximum values
 
@@ -71,22 +56,8 @@
 
   if ( renderer )
   {
-    // Awkard - here we want to search through mFieldMap for a
-    // particular value, while elsewhere in this code we need to search
-    // for a particular key, so one or the other loses out, which is here.
+    classificationComboBox->setCurrentIndex( classificationComboBox->findData( renderer->classificationField() ) );
 
-    std::map<int, int>::const_iterator iter = mFieldMap.begin();
-    while ( iter != mFieldMap.end() )
-    {
-      if ( iter->second == renderer->classificationField() )
-        break;
-      iter++;
-    }
-    if ( iter != mFieldMap.end() )
-      classificationComboBox->setCurrentIndex( iter->first );
-    else
-      classificationComboBox->setCurrentIndex( -1 );
-
     const QgsSymbol* minsymbol = renderer->minimumSymbol();
     const QgsSymbol* maxsymbol = renderer->maximumSymbol();
 
@@ -147,17 +118,8 @@
 
 void QgsContinuousColorDialog::apply()
 {
-  int comboIndex = classificationComboBox->currentIndex();
-  if ( comboIndex == -1 )  //don't do anything, if there is no classification field
-  {
-    return;
-  }
-  std::map < int, int >::iterator iter = mFieldMap.find( comboIndex );
-  // Should never happen...
-  assert( iter != mFieldMap.end() );
+  int classfield = classificationComboBox->itemData( classificationComboBox->currentIndex() ).toInt();
 
-  int classfield = iter->second;
-
   //find the minimum and maximum for the classification variable
   double minimum, maximum;
   QgsVectorDataProvider *provider = dynamic_cast<QgsVectorDataProvider*>( mVectorLayer->dataProvider() );

Modified: trunk/qgis/src/app/qgscontinuouscolordialog.h
===================================================================
--- trunk/qgis/src/app/qgscontinuouscolordialog.h	2009-05-02 22:03:19 UTC (rev 10707)
+++ trunk/qgis/src/app/qgscontinuouscolordialog.h	2009-05-02 22:57:48 UTC (rev 10708)
@@ -44,9 +44,6 @@
 
   protected:
     QgsVectorLayer* mVectorLayer;
-    /**Stores the relationship between provider field indices and field selection
-       combobox indices. First is the combobox index, second is the provider field index */
-    std::map<int, int> mFieldMap;
 
   private:
     /** Default constructor is private, do not use this */



More information about the QGIS-commit mailing list