[QGIS Commit] r11706 - trunk/qgis/src/app
svn_qgis at osgeo.org
svn_qgis at osgeo.org
Thu Sep 24 07:20:31 EDT 2009
Author: jef
Date: 2009-09-24 07:20:29 -0400 (Thu, 24 Sep 2009)
New Revision: 11706
Modified:
trunk/qgis/src/app/qgsvectorlayerproperties.cpp
trunk/qgis/src/app/qgsvectorlayerproperties.h
Log:
fix alias editing in vector layer properties
Modified: trunk/qgis/src/app/qgsvectorlayerproperties.cpp
===================================================================
--- trunk/qgis/src/app/qgsvectorlayerproperties.cpp 2009-09-24 09:28:17 UTC (rev 11705)
+++ trunk/qgis/src/app/qgsvectorlayerproperties.cpp 2009-09-24 11:20:29 UTC (rev 11706)
@@ -150,16 +150,16 @@
tblAttributes->clear();
- tblAttributes->setColumnCount( 8 );
+ tblAttributes->setColumnCount( attrColCount );
tblAttributes->setRowCount( fields.size() );
- tblAttributes->setHorizontalHeaderItem( 0, new QTableWidgetItem( tr( "id" ) ) );
- tblAttributes->setHorizontalHeaderItem( 1, new QTableWidgetItem( tr( "name" ) ) );
- tblAttributes->setHorizontalHeaderItem( 2, new QTableWidgetItem( tr( "type" ) ) );
- tblAttributes->setHorizontalHeaderItem( 3, new QTableWidgetItem( tr( "length" ) ) );
- tblAttributes->setHorizontalHeaderItem( 4, new QTableWidgetItem( tr( "precision" ) ) );
- tblAttributes->setHorizontalHeaderItem( 5, new QTableWidgetItem( tr( "comment" ) ) );
- tblAttributes->setHorizontalHeaderItem( 6, new QTableWidgetItem( tr( "edit widget" ) ) );
- tblAttributes->setHorizontalHeaderItem( 7, new QTableWidgetItem( tr( "alias" ) ) );
+ tblAttributes->setHorizontalHeaderItem( attrIdCol, new QTableWidgetItem( tr( "id" ) ) );
+ tblAttributes->setHorizontalHeaderItem( attrNameCol, new QTableWidgetItem( tr( "name" ) ) );
+ tblAttributes->setHorizontalHeaderItem( attrTypeCol, new QTableWidgetItem( tr( "type" ) ) );
+ tblAttributes->setHorizontalHeaderItem( attrLengthCol, new QTableWidgetItem( tr( "length" ) ) );
+ tblAttributes->setHorizontalHeaderItem( attrPrecCol, new QTableWidgetItem( tr( "precision" ) ) );
+ tblAttributes->setHorizontalHeaderItem( attrCommentCol, new QTableWidgetItem( tr( "comment" ) ) );
+ tblAttributes->setHorizontalHeaderItem( attrEditTypeCol, new QTableWidgetItem( tr( "edit widget" ) ) );
+ tblAttributes->setHorizontalHeaderItem( attrAliasCol, new QTableWidgetItem( tr( "alias" ) ) );
tblAttributes->setSelectionBehavior( QAbstractItemView::SelectRows );
tblAttributes->setSelectionMode( QAbstractItemView::MultiSelection );
@@ -173,23 +173,23 @@
void QgsVectorLayerProperties::setRow( int row, int idx, const QgsField &field )
{
- tblAttributes->setItem( row, 0, new QTableWidgetItem( QString::number( idx ) ) );
- tblAttributes->setItem( row, 1, new QTableWidgetItem( field.name() ) );
- tblAttributes->setItem( row, 2, new QTableWidgetItem( field.typeName() ) );
- tblAttributes->setItem( row, 3, new QTableWidgetItem( QString::number( field.length() ) ) );
- tblAttributes->setItem( row, 4, new QTableWidgetItem( QString::number( field.precision() ) ) );
- tblAttributes->setItem( row, 5, new QTableWidgetItem( field.comment() ) );
+ tblAttributes->setItem( row, attrIdCol, new QTableWidgetItem( QString::number( idx ) ) );
+ tblAttributes->setItem( row, attrNameCol, new QTableWidgetItem( field.name() ) );
+ tblAttributes->setItem( row, attrTypeCol, new QTableWidgetItem( field.typeName() ) );
+ tblAttributes->setItem( row, attrLengthCol, new QTableWidgetItem( QString::number( field.length() ) ) );
+ tblAttributes->setItem( row, attrPrecCol, new QTableWidgetItem( QString::number( field.precision() ) ) );
+ tblAttributes->setItem( row, attrCommentCol, new QTableWidgetItem( field.comment() ) );
- for ( int i = 0; i < 6; i++ )
+ for ( int i = 0; i < attrEditTypeCol; i++ )
tblAttributes->item( row, i )->setFlags( tblAttributes->item( row, i )->flags() & ~Qt::ItemIsEditable );
QPushButton *pb = new QPushButton( editTypeButtonText( layer->editType( idx ) ) );
- tblAttributes->setCellWidget( row, 6, pb );
+ tblAttributes->setCellWidget( row, attrEditTypeCol, pb );
connect( pb, SIGNAL( pressed() ), this, SLOT( attributeTypeDialog( ) ) );
mButtonMap.insert( idx, pb );
//set the alias for the attribute
- tblAttributes->setItem( row, 7, new QTableWidgetItem( layer->attributeAlias( idx ) ) );
+ tblAttributes->setItem( row, attrAliasCol, new QTableWidgetItem( layer->attributeAlias( idx ) ) );
}
@@ -605,9 +605,9 @@
for ( int i = 0; i < tblAttributes->rowCount(); i++ )
{
- int idx = tblAttributes->item( i, 0 )->text().toInt();
+ int idx = tblAttributes->item( i, attrIdCol )->text().toInt();
- QPushButton *pb = dynamic_cast<QPushButton*>( tblAttributes->cellWidget( i, 6 ) );
+ QPushButton *pb = dynamic_cast<QPushButton*>( tblAttributes->cellWidget( i, attrEditTypeCol ) );
if ( !pb )
continue;
@@ -1097,21 +1097,21 @@
void QgsVectorLayerProperties::on_tblAttributes_cellChanged( int row, int column )
{
- if ( column == 8 && layer ) //only consider attribute aliases in this function
+ if ( column == attrAliasCol && layer ) //only consider attribute aliases in this function
{
+ int idx = tblAttributes->item( row, attrIdCol )->text().toInt();
+
const QgsFieldMap &fields = layer->pendingFields();
- if ( row >= fields.size() )
+
+ if ( !fields.contains( idx ) )
{
- return; //index must be wrong
+ return; // index must be wrong
}
- QgsFieldMap::const_iterator f_it = fields.constBegin();
- f_it += row;
- int index = f_it.key();
- QTableWidgetItem* aliasItem = tblAttributes->item( row, column );
+ QTableWidgetItem *aliasItem = tblAttributes->item( row, column );
if ( aliasItem )
{
- layer->addAttributeAlias( index, aliasItem->text() );
+ layer->addAttributeAlias( idx, aliasItem->text() );
}
}
}
Modified: trunk/qgis/src/app/qgsvectorlayerproperties.h
===================================================================
--- trunk/qgis/src/app/qgsvectorlayerproperties.h 2009-09-24 09:28:17 UTC (rev 11705)
+++ trunk/qgis/src/app/qgsvectorlayerproperties.h 2009-09-24 11:20:29 UTC (rev 11706)
@@ -116,6 +116,19 @@
void toggleEditing( QgsMapLayer * );
protected:
+ enum attrColumns
+ {
+ attrIdCol = 0,
+ attrNameCol,
+ attrTypeCol,
+ attrLengthCol,
+ attrPrecCol,
+ attrCommentCol,
+ attrEditTypeCol,
+ attrAliasCol,
+ attrColCount,
+ };
+
QgsVectorLayer *layer;
/**Renderer dialog which is shown*/
QDialog* mRendererDialog;
More information about the QGIS-commit
mailing list