Skip to content
Permalink
Browse files

[FEATURE] Allow renaming fields by double clicking name

in layer properties window

Available for supported data providers only (postgres,
memory layers and OGR layers, dependant on OGR data format
and version)
  • Loading branch information
nyalldawson committed May 31, 2016
1 parent 0e03115 commit 831f4c12b780b965e4bf2bb3286df7ef46ab1b61
Showing with 35 additions and 1 deletion.
  1. +30 −1 src/app/qgsfieldsproperties.cpp
  2. +5 −0 src/app/qgsfieldsproperties.h
@@ -257,6 +257,7 @@ void QgsFieldsProperties::loadRows()

mFieldsList->resizeColumnsToContents();
connect( mFieldsList, SIGNAL( cellChanged( int, int ) ), this, SLOT( attributesListCellChanged( int, int ) ) );
updateFieldRenamingStatus();
}

void QgsFieldsProperties::setRow( int row, int idx, const QgsField& field )
@@ -307,6 +308,12 @@ void QgsFieldsProperties::setRow( int row, int idx, const QgsField& field )
for ( int i = 0; i < attrCommentCol; i++ )
mFieldsList->item( row, i )->setFlags( mFieldsList->item( row, i )->flags() & ~Qt::ItemIsEditable );

bool canRenameFields = mLayer->isEditable() && ( mLayer->dataProvider()->capabilities() & QgsVectorDataProvider::RenameAttributes ) && !mLayer->readOnly();
if ( canRenameFields )
mFieldsList->item( row, attrNameCol )->setFlags( mFieldsList->item( row, attrNameCol )->flags() | Qt::ItemIsEditable );
else
mFieldsList->item( row, attrNameCol )->setFlags( mFieldsList->item( row, attrNameCol )->flags() & ~Qt::ItemIsEditable );

FieldConfig cfg( mLayer, idx );
QPushButton *pb;
pb = new QPushButton( QgsEditorWidgetRegistry::instance()->name( cfg.mEditorWidgetV2Type ) );
@@ -602,6 +609,7 @@ bool QgsFieldsProperties::addAttribute( const QgsField &field )
void QgsFieldsProperties::editingToggled()
{
updateButtons();
updateFieldRenamingStatus();
}

QgsFieldsProperties::FieldConfig QgsFieldsProperties::configForRow( int row )
@@ -715,7 +723,7 @@ void QgsFieldsProperties::updateButtons()

void QgsFieldsProperties::attributesListCellChanged( int row, int column )
{
if ( column == attrAliasCol && mLayer ) //only consider attribute aliases in this function
if ( column == attrAliasCol && mLayer )
{
int idx = mFieldsList->item( row, attrIdCol )->text().toInt();

@@ -739,6 +747,14 @@ void QgsFieldsProperties::attributesListCellChanged( int row, int column )
}
}
}
else if ( column == attrNameCol && mLayer && mLayer->isEditable() )
{
QTableWidgetItem *nameItem = mFieldsList->item( row, column );
if ( nameItem && !nameItem->text().isEmpty() )
{
mLayer->renameAttribute( row, nameItem->text() );
}
}
}

void QgsFieldsProperties::updateExpression()
@@ -814,6 +830,19 @@ QString QgsFieldsProperties::editTypeButtonText( QgsVectorLayer::EditType type )
return editTypeMap[ type ];
}

void QgsFieldsProperties::updateFieldRenamingStatus()
{
bool canRenameFields = mLayer->isEditable() && ( mLayer->dataProvider()->capabilities() & QgsVectorDataProvider::RenameAttributes ) && !mLayer->readOnly();

for ( int row = 0; row < mFieldsList->rowCount(); ++row )
{
if ( canRenameFields )
mFieldsList->item( row, attrNameCol )->setFlags( mFieldsList->item( row, attrNameCol )->flags() | Qt::ItemIsEditable );
else
mFieldsList->item( row, attrNameCol )->setFlags( mFieldsList->item( row, attrNameCol )->flags() & ~Qt::ItemIsEditable );
}
}

QgsAttributeEditorElement* QgsFieldsProperties::createAttributeEditorWidget( QTreeWidgetItem* item, QObject *parent )
{
QgsAttributeEditorElement *widgetDef = nullptr;
@@ -217,6 +217,11 @@ class APP_EXPORT QgsFieldsProperties : public QWidget, private Ui_QgsFieldsPrope
static QMap< QgsVectorLayer::EditType, QString > editTypeMap;
static void setupEditTypes();
static QString editTypeButtonText( QgsVectorLayer::EditType type );

private:

void updateFieldRenamingStatus();

};

QDataStream& operator<< ( QDataStream& stream, const QgsFieldsProperties::DesignerTreeItemData& data );

0 comments on commit 831f4c1

Please sign in to comment.
You can’t perform that action at this time.