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

svn_qgis at osgeo.org svn_qgis at osgeo.org
Wed May 12 18:53:03 EDT 2010


Author: jef
Date: 2010-05-12 18:53:01 -0400 (Wed, 12 May 2010)
New Revision: 13472

Modified:
   trunk/qgis/src/app/qgsmergeattributesdialog.cpp
Log:
implement #2696

Modified: trunk/qgis/src/app/qgsmergeattributesdialog.cpp
===================================================================
--- trunk/qgis/src/app/qgsmergeattributesdialog.cpp	2010-05-12 22:49:13 UTC (rev 13471)
+++ trunk/qgis/src/app/qgsmergeattributesdialog.cpp	2010-05-12 22:53:01 UTC (rev 13472)
@@ -22,6 +22,7 @@
 #include "qgsmapcanvas.h"
 #include "qgsrubberband.h"
 #include "qgsvectorlayer.h"
+#include "qgsattributeeditor.h"
 #include <limits>
 #include <QComboBox>
 
@@ -74,12 +75,13 @@
   QgsFieldMap::const_iterator fieldIt = fieldMap.constBegin();
 
   //insert attribute names
-  QStringList horizontalHeaderLabels;
+  int col = 0;
   for ( ; fieldIt != fieldMap.constEnd(); ++fieldIt )
   {
-    horizontalHeaderLabels << fieldIt.value().name();
+    QTableWidgetItem *item = new QTableWidgetItem( fieldIt.value().name() );
+    item->setData( Qt::UserRole, fieldIt.key() );
+    mTableWidget->setHorizontalHeaderItem( col++, item );
   }
-  mTableWidget->setHorizontalHeaderLabels( horizontalHeaderLabels );
 
   //insert the attribute values
   int currentRow = 1;
@@ -97,7 +99,7 @@
       QTableWidgetItem* attributeValItem = new QTableWidgetItem( currentMapIt.value().toString() );
       attributeValItem->setFlags( Qt::ItemIsEnabled | Qt::ItemIsSelectable );
       mTableWidget->setItem( currentRow, col, attributeValItem );
-      ++col;
+      mTableWidget->setCellWidget( currentRow, col++, QgsAttributeEditor::createAttributeEditor( mTableWidget, NULL, mVectorLayer, currentMapIt.key(), currentMapIt.value() ) );
     }
     ++currentRow;
   }
@@ -106,7 +108,6 @@
   verticalHeaderLabels << tr( "Merge" );
   mTableWidget->setVerticalHeaderLabels( verticalHeaderLabels );
 
-
   //insert currently merged values
   for ( int i = 0; i < fieldMap.size(); ++i )
   {
@@ -254,21 +255,22 @@
 
 QString QgsMergeAttributesDialog::featureAttributeString( int featureId, int col )
 {
-  QString resultText;
-  for ( int i = 0; i < mFeatureList.size(); ++i )
+  int idx = mTableWidget->horizontalHeaderItem( col )->data( Qt::UserRole ).toInt();
+
+  int i;
+  for ( i = 0; i < mFeatureList.size() && mFeatureList[i].id() != featureId; i++ )
+    ;
+
+  QVariant value;
+  if ( i < mFeatureList.size() &&
+       QgsAttributeEditor::retrieveValue( mTableWidget->cellWidget( i + 1, col ), mVectorLayer, idx, value ) )
   {
-    int currentFid = mFeatureList[i].id();
-    if ( currentFid == featureId )
-    {
-      QTableWidgetItem* currentItem = mTableWidget->item( i + 1, col );
-      if ( !currentItem )
-      {
-        continue;
-      }
-      resultText = currentItem->text();
-    }
+    return value.toString();
   }
-  return resultText;
+  else
+  {
+    return "";
+  }
 }
 
 QString QgsMergeAttributesDialog::minimumAttributeString( int col )



More information about the QGIS-commit mailing list