@@ -146,7 +146,7 @@ void QgsVectorLayerProperties::loadRows()
146
146
147
147
tblAttributes->clear ();
148
148
149
- tblAttributes->setColumnCount ( 8 );
149
+ tblAttributes->setColumnCount ( 9 );
150
150
tblAttributes->setRowCount ( fields.size () );
151
151
tblAttributes->setHorizontalHeaderItem ( 0 , new QTableWidgetItem ( tr ( " id" ) ) );
152
152
tblAttributes->setHorizontalHeaderItem ( 1 , new QTableWidgetItem ( tr ( " name" ) ) );
@@ -156,6 +156,7 @@ void QgsVectorLayerProperties::loadRows()
156
156
tblAttributes->setHorizontalHeaderItem ( 5 , new QTableWidgetItem ( tr ( " comment" ) ) );
157
157
tblAttributes->setHorizontalHeaderItem ( 6 , new QTableWidgetItem ( tr ( " edit widget" ) ) );
158
158
tblAttributes->setHorizontalHeaderItem ( 7 , new QTableWidgetItem ( tr ( " values" ) ) );
159
+ tblAttributes->setHorizontalHeaderItem ( 8 , new QTableWidgetItem ( tr ( " alias" ) ) );
159
160
160
161
tblAttributes->setSelectionBehavior ( QAbstractItemView::SelectRows );
161
162
tblAttributes->setSelectionMode ( QAbstractItemView::MultiSelection );
@@ -174,7 +175,7 @@ void QgsVectorLayerProperties::setRow( int row, int idx, const QgsField &field )
174
175
tblAttributes->setItem ( row, 2 , new QTableWidgetItem ( field.typeName () ) );
175
176
tblAttributes->setItem ( row, 3 , new QTableWidgetItem ( QString::number ( field.length () ) ) );
176
177
tblAttributes->setItem ( row, 4 , new QTableWidgetItem ( QString::number ( field.precision () ) ) );
177
- tblAttributes->setItem ( row, 5 , new QTableWidgetItem ( field.comment () ) );
178
+ tblAttributes->setItem ( row, 5 , new QTableWidgetItem ( field.comment () ) );
178
179
179
180
for ( int i = 0 ; i < 6 ; i++ )
180
181
tblAttributes->item ( row, i )->setFlags ( tblAttributes->item ( row, i )->flags () & ~Qt::ItemIsEditable );
@@ -223,6 +224,9 @@ void QgsVectorLayerProperties::setRow( int row, int idx, const QgsField &field )
223
224
)
224
225
);
225
226
}
227
+
228
+ // set the alias for the attribute
229
+ tblAttributes->setItem ( row, 8 , new QTableWidgetItem (layer->attributeAlias (idx)));
226
230
}
227
231
228
232
@@ -381,6 +385,8 @@ void QgsVectorLayerProperties::setDisplayField( QString name )
381
385
// ! @note in raster props, this method is called sync()
382
386
void QgsVectorLayerProperties::reset ( void )
383
387
{
388
+ QObject::disconnect (tblAttributes, SIGNAL (cellChanged (int , int )), this , SLOT (on_tblAttributes_cellChanged (int ,int )));
389
+
384
390
// populate the general information
385
391
txtDisplayName->setText ( layer->name () );
386
392
pbnQueryBuilder->setWhatsThis ( tr ( " This button opens the PostgreSQL query "
@@ -487,6 +493,7 @@ void QgsVectorLayerProperties::reset( void )
487
493
sliderTransparency_valueChanged ( 255 - layer->getTransparency () );
488
494
489
495
loadRows ();
496
+ QObject::connect (tblAttributes, SIGNAL (cellChanged (int , int )), this , SLOT (on_tblAttributes_cellChanged (int ,int )));
490
497
} // reset()
491
498
492
499
@@ -1066,6 +1073,27 @@ void QgsVectorLayerProperties::on_pbnSaveStyleAs_clicked()
1066
1073
}
1067
1074
}
1068
1075
1076
+ void QgsVectorLayerProperties::on_tblAttributes_cellChanged (int row, int column)
1077
+ {
1078
+ if (column == 8 && layer) // only consider attribute aliases in this function
1079
+ {
1080
+ const QgsFieldMap &fields = layer->pendingFields ();
1081
+ if (row >= fields.size ())
1082
+ {
1083
+ return ; // index must be wrong
1084
+ }
1085
+
1086
+ QgsFieldMap::const_iterator f_it = fields.constBegin ();
1087
+ f_it += row;
1088
+ int index = f_it.key ();
1089
+ QTableWidgetItem* aliasItem = tblAttributes->item (row, column);
1090
+ if (aliasItem)
1091
+ {
1092
+ layer->addAttributeAlias (index , aliasItem->text ());
1093
+ }
1094
+ }
1095
+ }
1096
+
1069
1097
QList<QgsVectorOverlayPlugin*> QgsVectorLayerProperties::overlayPlugins () const
1070
1098
{
1071
1099
QList<QgsVectorOverlayPlugin*> pluginList;
0 commit comments