mirror of
https://github.com/qgis/QGIS.git
synced 2025-04-18 00:03:05 -04:00
Properly update layer settings when an auxiliary field is deleted
This commit is contained in:
parent
b6752df628
commit
4fa3400981
@ -211,6 +211,19 @@ class QgsAuxiliaryLayer : QgsVectorLayer
|
|||||||
:rtype: int
|
:rtype: int
|
||||||
%End
|
%End
|
||||||
|
|
||||||
|
int propertyFromField( int index ) const;
|
||||||
|
%Docstring
|
||||||
|
Returns the underlying property key for the field index. The key may be
|
||||||
|
a PAL, diagram or symbology property according to the underlying
|
||||||
|
property definition of the field. The key -1 is returned if an error
|
||||||
|
happened.
|
||||||
|
|
||||||
|
\param index The index of the field
|
||||||
|
|
||||||
|
.. versionadded:: 3.0
|
||||||
|
:rtype: int
|
||||||
|
%End
|
||||||
|
|
||||||
static int createProperty( QgsPalLayerSettings::Property property, const QString &providerId, QgsVectorLayer *vlayer );
|
static int createProperty( QgsPalLayerSettings::Property property, const QString &providerId, QgsVectorLayer *vlayer );
|
||||||
%Docstring
|
%Docstring
|
||||||
Create if necessary a new auxiliary field for a PAL property and
|
Create if necessary a new auxiliary field for a PAL property and
|
||||||
|
@ -180,13 +180,6 @@ class QgsPropertyOverrideButton: QToolButton
|
|||||||
%Docstring
|
%Docstring
|
||||||
Updates list of fields.
|
Updates list of fields.
|
||||||
|
|
||||||
.. versionadded:: 3.0
|
|
||||||
%End
|
|
||||||
|
|
||||||
void updateGui();
|
|
||||||
%Docstring
|
|
||||||
Updates data defined button icon.
|
|
||||||
|
|
||||||
.. versionadded:: 3.0
|
.. versionadded:: 3.0
|
||||||
%End
|
%End
|
||||||
|
|
||||||
|
@ -50,6 +50,8 @@ void QgsLabelingGui::registerDataDefinedButton( QgsPropertyOverrideButton *butto
|
|||||||
connect( button, &QgsPropertyOverrideButton::changed, this, &QgsLabelingGui::updateProperty );
|
connect( button, &QgsPropertyOverrideButton::changed, this, &QgsLabelingGui::updateProperty );
|
||||||
connect( button, &QgsPropertyOverrideButton::createAuxiliaryField, this, &QgsLabelingGui::createAuxiliaryField );
|
connect( button, &QgsPropertyOverrideButton::createAuxiliaryField, this, &QgsLabelingGui::createAuxiliaryField );
|
||||||
button->registerExpressionContextGenerator( this );
|
button->registerExpressionContextGenerator( this );
|
||||||
|
|
||||||
|
mButtons[key] = button;
|
||||||
}
|
}
|
||||||
|
|
||||||
void QgsLabelingGui::updateProperty()
|
void QgsLabelingGui::updateProperty()
|
||||||
@ -611,15 +613,6 @@ void QgsLabelingGui::updateUi()
|
|||||||
{
|
{
|
||||||
chkMergeLines->setToolTip( QString() );
|
chkMergeLines->setToolTip( QString() );
|
||||||
}
|
}
|
||||||
|
|
||||||
mCoordXDDBtn->updateFieldLists();
|
|
||||||
mCoordXDDBtn->updateGui();
|
|
||||||
|
|
||||||
mCoordYDDBtn->updateFieldLists();
|
|
||||||
mCoordYDDBtn->updateGui();
|
|
||||||
|
|
||||||
mCoordRotationDDBtn->updateFieldLists();
|
|
||||||
mCoordRotationDDBtn->updateGui();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void QgsLabelingGui::createAuxiliaryField()
|
void QgsLabelingGui::createAuxiliaryField()
|
||||||
@ -653,3 +646,17 @@ void QgsLabelingGui::createAuxiliaryField()
|
|||||||
|
|
||||||
emit auxiliaryFieldCreated();
|
emit auxiliaryFieldCreated();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void QgsLabelingGui::deactivateField( QgsPalLayerSettings::Property key )
|
||||||
|
{
|
||||||
|
if ( mButtons.contains( key ) )
|
||||||
|
{
|
||||||
|
QgsPropertyOverrideButton *button = mButtons[ key ];
|
||||||
|
QgsProperty p = button->toProperty();
|
||||||
|
p.setField( QString() );
|
||||||
|
p.setActive( false );
|
||||||
|
button->updateFieldLists();
|
||||||
|
button->setToProperty( p );
|
||||||
|
mDataDefinedProperties.setProperty( key, p );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -43,6 +43,16 @@ class APP_EXPORT QgsLabelingGui : public QgsTextFormatWidget, private QgsExpress
|
|||||||
|
|
||||||
void setLayer( QgsMapLayer *layer );
|
void setLayer( QgsMapLayer *layer );
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Deactivate a field from data defined properties and update the
|
||||||
|
* corresponding button.
|
||||||
|
*
|
||||||
|
* \param key The property key to deactivate
|
||||||
|
*
|
||||||
|
* \since QGIS 3.0
|
||||||
|
*/
|
||||||
|
void deactivateField( QgsPalLayerSettings::Property key );
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
|
|
||||||
void auxiliaryFieldCreated();
|
void auxiliaryFieldCreated();
|
||||||
@ -68,6 +78,8 @@ class APP_EXPORT QgsLabelingGui : public QgsTextFormatWidget, private QgsExpress
|
|||||||
void populateDataDefinedButtons();
|
void populateDataDefinedButtons();
|
||||||
void registerDataDefinedButton( QgsPropertyOverrideButton *button, QgsPalLayerSettings::Property key );
|
void registerDataDefinedButton( QgsPropertyOverrideButton *button, QgsPalLayerSettings::Property key );
|
||||||
|
|
||||||
|
QMap<QgsPalLayerSettings::Property, QgsPropertyOverrideButton *> mButtons;
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
|
|
||||||
void updateProperty();
|
void updateProperty();
|
||||||
|
@ -40,6 +40,11 @@ QgsLabelingWidget::QgsLabelingWidget( QgsVectorLayer *layer, QgsMapCanvas *canva
|
|||||||
setLayer( layer );
|
setLayer( layer );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QgsLabelingGui *QgsLabelingWidget::labelingGui()
|
||||||
|
{
|
||||||
|
return qobject_cast<QgsLabelingGui *>( mWidget );
|
||||||
|
}
|
||||||
|
|
||||||
void QgsLabelingWidget::resetSettings()
|
void QgsLabelingWidget::resetSettings()
|
||||||
{
|
{
|
||||||
if ( mOldSettings )
|
if ( mOldSettings )
|
||||||
|
@ -38,6 +38,13 @@ class QgsLabelingWidget : public QgsMapLayerConfigWidget, private Ui::QgsLabelin
|
|||||||
public:
|
public:
|
||||||
QgsLabelingWidget( QgsVectorLayer *layer, QgsMapCanvas *canvas, QWidget *parent = nullptr );
|
QgsLabelingWidget( QgsVectorLayer *layer, QgsMapCanvas *canvas, QWidget *parent = nullptr );
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the labeling gui widget or a nullptr if none.
|
||||||
|
*
|
||||||
|
* \since QGIS 3.0
|
||||||
|
*/
|
||||||
|
QgsLabelingGui *labelingGui();
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void setLayer( QgsMapLayer *layer );
|
void setLayer( QgsMapLayer *layer );
|
||||||
//! save config to layer
|
//! save config to layer
|
||||||
|
@ -57,6 +57,7 @@
|
|||||||
#include "qgsstyle.h"
|
#include "qgsstyle.h"
|
||||||
#include "qgsauxiliarystorage.h"
|
#include "qgsauxiliarystorage.h"
|
||||||
#include "qgsnewauxiliarylayerdialog.h"
|
#include "qgsnewauxiliarylayerdialog.h"
|
||||||
|
#include "qgslabelinggui.h"
|
||||||
|
|
||||||
#include "layertree/qgslayertreelayer.h"
|
#include "layertree/qgslayertreelayer.h"
|
||||||
#include "qgslayertree.h"
|
#include "qgslayertree.h"
|
||||||
@ -1555,7 +1556,7 @@ void QgsVectorLayerProperties::updateAuxiliaryStoragePage( bool reset )
|
|||||||
|
|
||||||
if ( reset && labelingDialog )
|
if ( reset && labelingDialog )
|
||||||
{
|
{
|
||||||
labelingDialog->resetSettings(); // update data defined buttons
|
labelingDialog->setLayer( mLayer );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1608,6 +1609,15 @@ void QgsVectorLayerProperties::onAuxiliaryLayerDelete()
|
|||||||
{
|
{
|
||||||
QApplication::setOverrideCursor( Qt::WaitCursor );
|
QApplication::setOverrideCursor( Qt::WaitCursor );
|
||||||
QgsDataSourceUri uri( alayer->source() );
|
QgsDataSourceUri uri( alayer->source() );
|
||||||
|
|
||||||
|
// delete each attribute to correctly update layer settings and data
|
||||||
|
// defined buttons
|
||||||
|
while ( alayer->auxiliaryFields().size() > 0 )
|
||||||
|
{
|
||||||
|
QgsAuxiliaryField aField = alayer->auxiliaryFields()[0];
|
||||||
|
deleteAuxiliaryField( alayer->fields().indexOf( aField.name() ) );
|
||||||
|
}
|
||||||
|
|
||||||
mLayer->setAuxiliaryLayer(); // remove auxiliary layer
|
mLayer->setAuxiliaryLayer(); // remove auxiliary layer
|
||||||
QgsAuxiliaryStorage::deleteTable( uri );
|
QgsAuxiliaryStorage::deleteTable( uri );
|
||||||
QApplication::restoreOverrideCursor();
|
QApplication::restoreOverrideCursor();
|
||||||
@ -1659,11 +1669,27 @@ void QgsVectorLayerProperties::onAuxiliaryLayerDeleteField()
|
|||||||
if ( reply == QMessageBox::Yes )
|
if ( reply == QMessageBox::Yes )
|
||||||
{
|
{
|
||||||
QApplication::setOverrideCursor( Qt::WaitCursor );
|
QApplication::setOverrideCursor( Qt::WaitCursor );
|
||||||
mLayer->auxiliaryLayer()->deleteAttribute( index );
|
deleteAuxiliaryField( index );
|
||||||
QApplication::restoreOverrideCursor();
|
|
||||||
mLayer->updateFields();
|
|
||||||
updateAuxiliaryStoragePage( true );
|
|
||||||
mFieldsPropertiesDialog->init();
|
|
||||||
mLayer->triggerRepaint();
|
mLayer->triggerRepaint();
|
||||||
|
QApplication::restoreOverrideCursor();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void QgsVectorLayerProperties::deleteAuxiliaryField( int index )
|
||||||
|
{
|
||||||
|
if ( !mLayer->auxiliaryLayer() )
|
||||||
|
return;
|
||||||
|
|
||||||
|
int key = mLayer->auxiliaryLayer()->propertyFromField( index );
|
||||||
|
if ( mLayer->auxiliaryLayer()->deleteAttribute( index ) )
|
||||||
|
{
|
||||||
|
mLayer->updateFields();
|
||||||
|
|
||||||
|
// immediately deactivate data defined button
|
||||||
|
if ( labelingDialog && labelingDialog->labelingGui() )
|
||||||
|
labelingDialog->labelingGui()->deactivateField( ( QgsPalLayerSettings::Property ) key );
|
||||||
|
|
||||||
|
updateAuxiliaryStoragePage( true );
|
||||||
|
mFieldsPropertiesDialog->init();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -217,6 +217,7 @@ class APP_EXPORT QgsVectorLayerProperties : public QgsOptionsDialogBase, private
|
|||||||
void addJoinToTreeWidget( const QgsVectorLayerJoinInfo &join, const int insertIndex = -1 );
|
void addJoinToTreeWidget( const QgsVectorLayerJoinInfo &join, const int insertIndex = -1 );
|
||||||
|
|
||||||
void updateAuxiliaryStoragePage( bool reset = false );
|
void updateAuxiliaryStoragePage( bool reset = false );
|
||||||
|
void deleteAuxiliaryField( int index );
|
||||||
|
|
||||||
QgsExpressionContext mContext;
|
QgsExpressionContext mContext;
|
||||||
|
|
||||||
|
@ -405,6 +405,29 @@ bool QgsAuxiliaryLayer::isHiddenProperty( int index ) const
|
|||||||
return hidden;
|
return hidden;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int QgsAuxiliaryLayer::propertyFromField( int index ) const
|
||||||
|
{
|
||||||
|
int p = -1;
|
||||||
|
QgsAuxiliaryField aField( fields().field( index ) );
|
||||||
|
QgsPropertyDefinition aDef = aField.propertyDefinition();
|
||||||
|
|
||||||
|
if ( aDef.origin().compare( "labeling" ) == 0 )
|
||||||
|
{
|
||||||
|
const QgsPropertiesDefinition defs = QgsPalLayerSettings::propertyDefinitions();
|
||||||
|
QgsPropertiesDefinition::const_iterator it = defs.constBegin();
|
||||||
|
for ( ; it != defs.constEnd(); ++it )
|
||||||
|
{
|
||||||
|
if ( it->name().compare( aDef.name(), Qt::CaseInsensitive ) == 0 )
|
||||||
|
{
|
||||||
|
p = it.key();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return p;
|
||||||
|
}
|
||||||
|
|
||||||
int QgsAuxiliaryLayer::indexOfProperty( const QgsPropertyDefinition &def ) const
|
int QgsAuxiliaryLayer::indexOfProperty( const QgsPropertyDefinition &def ) const
|
||||||
{
|
{
|
||||||
return fields().indexOf( QgsAuxiliaryField::nameFromProperty( def ) );
|
return fields().indexOf( QgsAuxiliaryField::nameFromProperty( def ) );
|
||||||
|
@ -228,6 +228,18 @@ class CORE_EXPORT QgsAuxiliaryLayer : public QgsVectorLayer
|
|||||||
*/
|
*/
|
||||||
int indexOfProperty( const QgsPropertyDefinition &definition ) const;
|
int indexOfProperty( const QgsPropertyDefinition &definition ) const;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the underlying property key for the field index. The key may be
|
||||||
|
* a PAL, diagram or symbology property according to the underlying
|
||||||
|
* property definition of the field. The key -1 is returned if an error
|
||||||
|
* happened.
|
||||||
|
*
|
||||||
|
* \param index The index of the field
|
||||||
|
*
|
||||||
|
* \since QGIS 3.0
|
||||||
|
*/
|
||||||
|
int propertyFromField( int index ) const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create if necessary a new auxiliary field for a PAL property and
|
* Create if necessary a new auxiliary field for a PAL property and
|
||||||
* activate this property in settings.
|
* activate this property in settings.
|
||||||
|
@ -192,13 +192,6 @@ class GUI_EXPORT QgsPropertyOverrideButton: public QToolButton
|
|||||||
*/
|
*/
|
||||||
void updateFieldLists();
|
void updateFieldLists();
|
||||||
|
|
||||||
/**
|
|
||||||
* Updates data defined button icon.
|
|
||||||
*
|
|
||||||
* \since QGIS 3.0
|
|
||||||
*/
|
|
||||||
void updateGui();
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets a symbol which can be used for previews inside the widget or in any dialog created
|
* Sets a symbol which can be used for previews inside the widget or in any dialog created
|
||||||
* by the widget. If not specified, a default created symbol will be used instead.
|
* by the widget. If not specified, a default created symbol will be used instead.
|
||||||
@ -232,6 +225,7 @@ class GUI_EXPORT QgsPropertyOverrideButton: public QToolButton
|
|||||||
void showDescriptionDialog();
|
void showDescriptionDialog();
|
||||||
void showExpressionDialog();
|
void showExpressionDialog();
|
||||||
void showAssistant();
|
void showAssistant();
|
||||||
|
void updateGui();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the active status, emitting the activated signal where necessary (but never emitting the changed signal!).
|
* Sets the active status, emitting the activated signal where necessary (but never emitting the changed signal!).
|
||||||
|
Loading…
x
Reference in New Issue
Block a user