@@ -146,7 +146,7 @@ void QgsVectorLayerProperties::loadRows()
146146
147147 tblAttributes->clear ();
148148
149- tblAttributes->setColumnCount ( 8 );
149+ tblAttributes->setColumnCount ( 9 );
150150 tblAttributes->setRowCount ( fields.size () );
151151 tblAttributes->setHorizontalHeaderItem ( 0 , new QTableWidgetItem ( tr ( " id" ) ) );
152152 tblAttributes->setHorizontalHeaderItem ( 1 , new QTableWidgetItem ( tr ( " name" ) ) );
@@ -156,6 +156,7 @@ void QgsVectorLayerProperties::loadRows()
156156 tblAttributes->setHorizontalHeaderItem ( 5 , new QTableWidgetItem ( tr ( " comment" ) ) );
157157 tblAttributes->setHorizontalHeaderItem ( 6 , new QTableWidgetItem ( tr ( " edit widget" ) ) );
158158 tblAttributes->setHorizontalHeaderItem ( 7 , new QTableWidgetItem ( tr ( " values" ) ) );
159+ tblAttributes->setHorizontalHeaderItem ( 8 , new QTableWidgetItem ( tr ( " alias" ) ) );
159160
160161 tblAttributes->setSelectionBehavior ( QAbstractItemView::SelectRows );
161162 tblAttributes->setSelectionMode ( QAbstractItemView::MultiSelection );
@@ -174,7 +175,7 @@ void QgsVectorLayerProperties::setRow( int row, int idx, const QgsField &field )
174175 tblAttributes->setItem ( row, 2 , new QTableWidgetItem ( field.typeName () ) );
175176 tblAttributes->setItem ( row, 3 , new QTableWidgetItem ( QString::number ( field.length () ) ) );
176177 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 () ) );
178179
179180 for ( int i = 0 ; i < 6 ; i++ )
180181 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 )
223224 )
224225 );
225226 }
227+
228+ // set the alias for the attribute
229+ tblAttributes->setItem ( row, 8 , new QTableWidgetItem (layer->attributeAlias (idx)));
226230}
227231
228232
@@ -381,6 +385,8 @@ void QgsVectorLayerProperties::setDisplayField( QString name )
381385// ! @note in raster props, this method is called sync()
382386void QgsVectorLayerProperties::reset ( void )
383387{
388+ QObject::disconnect (tblAttributes, SIGNAL (cellChanged (int , int )), this , SLOT (on_tblAttributes_cellChanged (int ,int )));
389+
384390 // populate the general information
385391 txtDisplayName->setText ( layer->name () );
386392 pbnQueryBuilder->setWhatsThis ( tr ( " This button opens the PostgreSQL query "
@@ -487,6 +493,7 @@ void QgsVectorLayerProperties::reset( void )
487493 sliderTransparency_valueChanged ( 255 - layer->getTransparency () );
488494
489495 loadRows ();
496+ QObject::connect (tblAttributes, SIGNAL (cellChanged (int , int )), this , SLOT (on_tblAttributes_cellChanged (int ,int )));
490497} // reset()
491498
492499
@@ -1066,6 +1073,27 @@ void QgsVectorLayerProperties::on_pbnSaveStyleAs_clicked()
10661073 }
10671074}
10681075
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+
10691097QList<QgsVectorOverlayPlugin*> QgsVectorLayerProperties::overlayPlugins () const
10701098{
10711099 QList<QgsVectorOverlayPlugin*> pluginList;
0 commit comments