2222#include " qgsmapcanvas.h"
2323#include " qgsrubberband.h"
2424#include " qgsvectorlayer.h"
25+ #include " qgsattributeeditor.h"
2526#include < limits>
2627#include < QComboBox>
2728
@@ -74,12 +75,13 @@ void QgsMergeAttributesDialog::createTableWidgetContents()
7475 QgsFieldMap::const_iterator fieldIt = fieldMap.constBegin ();
7576
7677 // insert attribute names
77- QStringList horizontalHeaderLabels ;
78+ int col = 0 ;
7879 for ( ; fieldIt != fieldMap.constEnd (); ++fieldIt )
7980 {
80- horizontalHeaderLabels << fieldIt.value ().name ();
81+ QTableWidgetItem *item = new QTableWidgetItem ( fieldIt.value ().name () );
82+ item->setData ( Qt::UserRole, fieldIt.key () );
83+ mTableWidget ->setHorizontalHeaderItem ( col++, item );
8184 }
82- mTableWidget ->setHorizontalHeaderLabels ( horizontalHeaderLabels );
8385
8486 // insert the attribute values
8587 int currentRow = 1 ;
@@ -97,7 +99,7 @@ void QgsMergeAttributesDialog::createTableWidgetContents()
9799 QTableWidgetItem* attributeValItem = new QTableWidgetItem ( currentMapIt.value ().toString () );
98100 attributeValItem->setFlags ( Qt::ItemIsEnabled | Qt::ItemIsSelectable );
99101 mTableWidget ->setItem ( currentRow, col, attributeValItem );
100- ++col ;
102+ mTableWidget -> setCellWidget ( currentRow, col++, QgsAttributeEditor::createAttributeEditor ( mTableWidget , NULL , mVectorLayer , currentMapIt. key (), currentMapIt. value () ) ) ;
101103 }
102104 ++currentRow;
103105 }
@@ -106,7 +108,6 @@ void QgsMergeAttributesDialog::createTableWidgetContents()
106108 verticalHeaderLabels << tr ( " Merge" );
107109 mTableWidget ->setVerticalHeaderLabels ( verticalHeaderLabels );
108110
109-
110111 // insert currently merged values
111112 for ( int i = 0 ; i < fieldMap.size (); ++i )
112113 {
@@ -254,21 +255,22 @@ void QgsMergeAttributesDialog::refreshMergedValue( int col )
254255
255256QString QgsMergeAttributesDialog::featureAttributeString ( int featureId, int col )
256257{
257- QString resultText;
258- for ( int i = 0 ; i < mFeatureList .size (); ++i )
258+ int idx = mTableWidget ->horizontalHeaderItem ( col )->data ( Qt::UserRole ).toInt ();
259+
260+ int i;
261+ for ( i = 0 ; i < mFeatureList .size () && mFeatureList [i].id () != featureId; i++ )
262+ ;
263+
264+ QVariant value;
265+ if ( i < mFeatureList .size () &&
266+ QgsAttributeEditor::retrieveValue ( mTableWidget ->cellWidget ( i + 1 , col ), mVectorLayer , idx, value ) )
259267 {
260- int currentFid = mFeatureList [i].id ();
261- if ( currentFid == featureId )
262- {
263- QTableWidgetItem* currentItem = mTableWidget ->item ( i + 1 , col );
264- if ( !currentItem )
265- {
266- continue ;
267- }
268- resultText = currentItem->text ();
269- }
268+ return value.toString ();
269+ }
270+ else
271+ {
272+ return " " ;
270273 }
271- return resultText;
272274}
273275
274276QString QgsMergeAttributesDialog::minimumAttributeString ( int col )
0 commit comments