22
22
#include " qgsmapcanvas.h"
23
23
#include " qgsrubberband.h"
24
24
#include " qgsvectorlayer.h"
25
+ #include " qgsattributeeditor.h"
25
26
#include < limits>
26
27
#include < QComboBox>
27
28
@@ -74,12 +75,13 @@ void QgsMergeAttributesDialog::createTableWidgetContents()
74
75
QgsFieldMap::const_iterator fieldIt = fieldMap.constBegin ();
75
76
76
77
// insert attribute names
77
- QStringList horizontalHeaderLabels ;
78
+ int col = 0 ;
78
79
for ( ; fieldIt != fieldMap.constEnd (); ++fieldIt )
79
80
{
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 );
81
84
}
82
- mTableWidget ->setHorizontalHeaderLabels ( horizontalHeaderLabels );
83
85
84
86
// insert the attribute values
85
87
int currentRow = 1 ;
@@ -97,7 +99,7 @@ void QgsMergeAttributesDialog::createTableWidgetContents()
97
99
QTableWidgetItem* attributeValItem = new QTableWidgetItem ( currentMapIt.value ().toString () );
98
100
attributeValItem->setFlags ( Qt::ItemIsEnabled | Qt::ItemIsSelectable );
99
101
mTableWidget ->setItem ( currentRow, col, attributeValItem );
100
- ++col ;
102
+ mTableWidget -> setCellWidget ( currentRow, col++, QgsAttributeEditor::createAttributeEditor ( mTableWidget , NULL , mVectorLayer , currentMapIt. key (), currentMapIt. value () ) ) ;
101
103
}
102
104
++currentRow;
103
105
}
@@ -106,7 +108,6 @@ void QgsMergeAttributesDialog::createTableWidgetContents()
106
108
verticalHeaderLabels << tr ( " Merge" );
107
109
mTableWidget ->setVerticalHeaderLabels ( verticalHeaderLabels );
108
110
109
-
110
111
// insert currently merged values
111
112
for ( int i = 0 ; i < fieldMap.size (); ++i )
112
113
{
@@ -254,21 +255,22 @@ void QgsMergeAttributesDialog::refreshMergedValue( int col )
254
255
255
256
QString QgsMergeAttributesDialog::featureAttributeString ( int featureId, int col )
256
257
{
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 ) )
259
267
{
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 " " ;
270
273
}
271
- return resultText;
272
274
}
273
275
274
276
QString QgsMergeAttributesDialog::minimumAttributeString ( int col )
0 commit comments