Implement delete field action

This commit is contained in:
Blottiere Paul 2017-08-29 09:45:01 +01:00
parent dcec98dfda
commit 4a8fce2b00
9 changed files with 102 additions and 2 deletions

View File

@ -151,6 +151,17 @@ class QgsAuxiliaryLayer : QgsVectorLayer
:rtype: bool
%End
virtual bool deleteAttribute( int attr );
%Docstring
Remove attribute from the layer and commit changes. The layer remains
editable.
\param attr The index of the attribute to remove
:return: true if the attribute is well deleted, false otherwise
:rtype: bool
%End
};

View File

@ -104,12 +104,22 @@ class QgsPropertyDefinition
:rtype: str
%End
void setName( const QString &name );
%Docstring
Sets the name of the property
%End
Origin origin() const;
%Docstring
Returns the origin of the property
:rtype: Origin
%End
void setOrigin( Origin origin );
%Docstring
Sets origin of the property
%End
QString description() const;
%Docstring
Descriptive name of the property.

View File

@ -1302,7 +1302,7 @@ Returns a map of field name to attribute alias
A set of attributes that are not advertised in WFS requests with QGIS server.
%End
bool deleteAttribute( int attr );
virtual bool deleteAttribute( int attr );
%Docstring
Delete an attribute field (but does not commit it)
:rtype: bool

View File

@ -87,6 +87,7 @@ QgsVectorLayerProperties::QgsVectorLayerProperties(
, mAuxiliaryLayerActionClear( nullptr )
, mAuxiliaryLayerActionDelete( nullptr )
, mAuxiliaryLayerActionExport( nullptr )
, mAuxiliaryLayerActionDeleteField( nullptr )
{
setupUi( this );
connect( mLayerOrigNameLineEdit, &QLineEdit::textEdited, this, &QgsVectorLayerProperties::mLayerOrigNameLineEdit_textEdited );
@ -378,6 +379,8 @@ QgsVectorLayerProperties::QgsVectorLayerProperties(
mAuxiliaryStorageActions->setMenu( menu );
connect( mAuxiliaryStorageFieldsDeleteBtn, &QPushButton::clicked, this, &QgsVectorLayerProperties::onAuxiliaryLayerDeleteField );
updateAuxiliaryStoragePage();
}
@ -1631,3 +1634,48 @@ void QgsVectorLayerProperties::onAuxiliaryLayerExport()
QgisApp::instance()->saveAsFile( clone.get() );
}
void QgsVectorLayerProperties::onAuxiliaryLayerDeleteField()
{
QgsAuxiliaryLayer *alayer = mLayer->auxiliaryLayer();
if ( !alayer )
return;
QList<QTreeWidgetItem *> items = mAuxiliaryStorageFieldsTree->selectedItems();
if ( items.count() < 1 )
return;
// get auxiliary field name and index from item
const QTreeWidgetItem *item = items[0];
QgsPropertyDefinition def;
if ( item->text( 0 ).compare( "pal", Qt::CaseInsensitive ) == 0 )
def.setOrigin( QgsPropertyDefinition::Pal );
else
def.setOrigin( QgsPropertyDefinition::Diagram );
def.setName( item->text( 1 ) );
const QString fieldName = QgsAuxiliaryField::name( def );
const int index = mLayer->auxiliaryLayer()->fields().indexOf( fieldName );
if ( index < 0 )
return;
// should be only 1 field
const QString msg = tr( "Are you sure you want to delete auxiliary field %1 for %2" ).arg( item->text( 1 ), item->text( 0 ) );
QMessageBox::StandardButton reply;
reply = QMessageBox::question( this, "Delete auxiliary field", msg, QMessageBox::Yes | QMessageBox::No );
if ( reply == QMessageBox::Yes )
{
QApplication::setOverrideCursor( Qt::WaitCursor );
mLayer->auxiliaryLayer()->deleteAttribute( index );
QApplication::restoreOverrideCursor();
mLayer->updateFields();
updateAuxiliaryStoragePage( true );
mFieldsPropertiesDialog->init();
mLayer->triggerRepaint();
}
}

View File

@ -162,6 +162,8 @@ class APP_EXPORT QgsVectorLayerProperties : public QgsOptionsDialogBase, private
void onAuxiliaryLayerDelete();
void onAuxiliaryLayerDeleteField();
void onAuxiliaryLayerExport();
private:
@ -231,6 +233,7 @@ class APP_EXPORT QgsVectorLayerProperties : public QgsOptionsDialogBase, private
QAction *mAuxiliaryLayerActionClear;
QAction *mAuxiliaryLayerActionDelete;
QAction *mAuxiliaryLayerActionExport;
QAction *mAuxiliaryLayerActionDeleteField;
private slots:
void openPanel( QgsPanelWidget *panel );

View File

@ -233,6 +233,14 @@ QgsAuxiliaryFields QgsAuxiliaryLayer::auxiliaryFields() const
return afields;
}
bool QgsAuxiliaryLayer::deleteAttribute( int attr )
{
QgsVectorLayer::deleteAttribute( attr );
bool rc = commitChanges();
startEditing();
return rc;
}
bool QgsAuxiliaryLayer::save()
{
bool rc = false;

View File

@ -174,6 +174,16 @@ class CORE_EXPORT QgsAuxiliaryLayer : public QgsVectorLayer
*/
bool save();
/**
* Remove attribute from the layer and commit changes. The layer remains
* editable.
*
* \param attr The index of the attribute to remove
*
* \returns true if the attribute is well deleted, false otherwise
*/
virtual bool deleteAttribute( int attr ) override;
private:
QgsVectorLayerJoinInfo mJoinInfo;
const QgsVectorLayer *mLayer;

View File

@ -141,11 +141,21 @@ class CORE_EXPORT QgsPropertyDefinition
*/
QString name() const { return mName; }
/**
* Sets the name of the property
*/
void setName( const QString &name ) { mName = name; }
/**
* Returns the origin of the property
*/
Origin origin() const { return mOrigin; }
/**
* Sets origin of the property
*/
void setOrigin( Origin origin ) { mOrigin = origin; }
/**
* Descriptive name of the property.
*/

View File

@ -1302,7 +1302,7 @@ class CORE_EXPORT QgsVectorLayer : public QgsMapLayer, public QgsExpressionConte
void setExcludeAttributesWfs( const QSet<QString> &att ) { mExcludeAttributesWFS = att; }
//! Delete an attribute field (but does not commit it)
bool deleteAttribute( int attr );
virtual bool deleteAttribute( int attr );
/**
* Deletes a list of attribute fields (but does not commit it)