@@ -87,6 +87,7 @@ QgsVectorLayerProperties::QgsVectorLayerProperties(
8787 , mAuxiliaryLayerActionClear( nullptr )
8888 , mAuxiliaryLayerActionDelete( nullptr )
8989 , mAuxiliaryLayerActionExport( nullptr )
90+ , mAuxiliaryLayerActionDeleteField( nullptr )
9091{
9192 setupUi ( this );
9293 connect ( mLayerOrigNameLineEdit , &QLineEdit::textEdited, this , &QgsVectorLayerProperties::mLayerOrigNameLineEdit_textEdited );
@@ -378,6 +379,8 @@ QgsVectorLayerProperties::QgsVectorLayerProperties(
378379
379380 mAuxiliaryStorageActions ->setMenu ( menu );
380381
382+ connect ( mAuxiliaryStorageFieldsDeleteBtn , &QPushButton::clicked, this , &QgsVectorLayerProperties::onAuxiliaryLayerDeleteField );
383+
381384 updateAuxiliaryStoragePage ();
382385}
383386
@@ -1631,3 +1634,48 @@ void QgsVectorLayerProperties::onAuxiliaryLayerExport()
16311634
16321635 QgisApp::instance ()->saveAsFile ( clone.get () );
16331636}
1637+
1638+ void QgsVectorLayerProperties::onAuxiliaryLayerDeleteField ()
1639+ {
1640+ QgsAuxiliaryLayer *alayer = mLayer ->auxiliaryLayer ();
1641+ if ( !alayer )
1642+ return ;
1643+
1644+ QList<QTreeWidgetItem *> items = mAuxiliaryStorageFieldsTree ->selectedItems ();
1645+ if ( items.count () < 1 )
1646+ return ;
1647+
1648+ // get auxiliary field name and index from item
1649+ const QTreeWidgetItem *item = items[0 ];
1650+ QgsPropertyDefinition def;
1651+
1652+ if ( item->text ( 0 ).compare ( " pal" , Qt::CaseInsensitive ) == 0 )
1653+ def.setOrigin ( QgsPropertyDefinition::Pal );
1654+ else
1655+ def.setOrigin ( QgsPropertyDefinition::Diagram );
1656+
1657+ def.setName ( item->text ( 1 ) );
1658+
1659+ const QString fieldName = QgsAuxiliaryField::name ( def );
1660+
1661+ const int index = mLayer ->auxiliaryLayer ()->fields ().indexOf ( fieldName );
1662+ if ( index < 0 )
1663+ return ;
1664+
1665+ // should be only 1 field
1666+ const QString msg = tr ( " Are you sure you want to delete auxiliary field %1 for %2" ).arg ( item->text ( 1 ), item->text ( 0 ) );
1667+
1668+ QMessageBox::StandardButton reply;
1669+ reply = QMessageBox::question ( this , " Delete auxiliary field" , msg, QMessageBox::Yes | QMessageBox::No );
1670+
1671+ if ( reply == QMessageBox::Yes )
1672+ {
1673+ QApplication::setOverrideCursor ( Qt::WaitCursor );
1674+ mLayer ->auxiliaryLayer ()->deleteAttribute ( index );
1675+ QApplication::restoreOverrideCursor ();
1676+ mLayer ->updateFields ();
1677+ updateAuxiliaryStoragePage ( true );
1678+ mFieldsPropertiesDialog ->init ();
1679+ mLayer ->triggerRepaint ();
1680+ }
1681+ }
0 commit comments