Skip to content
Permalink
Browse files
fix alias editing in vector layer properties
git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@11706 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
jef committed Sep 24, 2009
1 parent 97ced4c commit e4441dcd0c8bf528bb8254a8e3fb107efdb69607
Showing with 42 additions and 29 deletions.
  1. +29 −29 src/app/qgsvectorlayerproperties.cpp
  2. +13 −0 src/app/qgsvectorlayerproperties.h
@@ -150,16 +150,16 @@ void QgsVectorLayerProperties::loadRows()

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::loadRows()

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() ) );

for ( int i = 0; i < 6; i++ )
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 < 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 @@ void QgsVectorLayerProperties::apply()

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_pbnSaveStyleAs_clicked()

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() );
}
}
}
@@ -116,6 +116,19 @@ class QgsVectorLayerProperties : public QDialog, private Ui::QgsVectorLayerPrope
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;

0 comments on commit e4441dc

Please sign in to comment.