diff --git a/python/core/qgsauxiliarystorage.sip b/python/core/qgsauxiliarystorage.sip index c926fd84fab..90c29907361 100644 --- a/python/core/qgsauxiliarystorage.sip +++ b/python/core/qgsauxiliarystorage.sip @@ -179,6 +179,15 @@ class QgsAuxiliaryLayer : QgsVectorLayer :rtype: bool %End + bool isHiddenProperty( int index ) const; +%Docstring + Returns true if the underlying field have to be hidden from editing + tools like attribute table, false otherwise. + + \param index The index of the field for which visibility is checked + :rtype: bool +%End + static int createProperty( QgsPalLayerSettings::Property property, const QString &providerId, QgsVectorLayer *vlayer ); %Docstring Create if necessary a new auxiliary field for a PAL property and diff --git a/python/core/qgsvectorlayer.sip b/python/core/qgsvectorlayer.sip index 0447733bd84..ff727c09bfa 100644 --- a/python/core/qgsvectorlayer.sip +++ b/python/core/qgsvectorlayer.sip @@ -1125,7 +1125,7 @@ Returns true if the provider has been modified since the last commit :rtype: bool %End - bool isAuxiliaryField( int index ) const; + bool isAuxiliaryField( int index, int &srcIndex ) const; %Docstring Returns true if the field comes from the auxiliary layer, false otherwise. diff --git a/src/core/qgsauxiliarystorage.cpp b/src/core/qgsauxiliarystorage.cpp index af7e7542719..ea376706800 100644 --- a/src/core/qgsauxiliarystorage.cpp +++ b/src/core/qgsauxiliarystorage.cpp @@ -30,6 +30,31 @@ const QString AS_JOINFIELD = "ASPK"; const QString AS_EXTENSION = "qgd"; const QString AS_JOINPREFIX = "auxiliary_storage_"; +const QVector palHiddenProperties +{ + QgsPalLayerSettings::PositionX, + QgsPalLayerSettings::PositionY, + QgsPalLayerSettings::Show, + QgsPalLayerSettings::LabelRotation, + QgsPalLayerSettings::Family, + QgsPalLayerSettings::FontStyle, + QgsPalLayerSettings::Size, + QgsPalLayerSettings::Bold, + QgsPalLayerSettings::Italic, + QgsPalLayerSettings::Underline, + QgsPalLayerSettings::Color, + QgsPalLayerSettings::Strikeout, + QgsPalLayerSettings::BufferSize, + QgsPalLayerSettings::BufferColor, + QgsPalLayerSettings::LabelDistance, + QgsPalLayerSettings::Hali, + QgsPalLayerSettings::Vali, + QgsPalLayerSettings::ScaleVisibility, + QgsPalLayerSettings::MinScale, + QgsPalLayerSettings::MaxScale, + QgsPalLayerSettings::AlwaysShow +}; + QgsAuxiliaryField::QgsAuxiliaryField( const QgsPropertyDefinition &def ) : QgsField() , mPropertyDefinition( def ) @@ -310,6 +335,29 @@ int QgsAuxiliaryLayer::createProperty( QgsDiagramLayerSettings::Property propert return index; } +bool QgsAuxiliaryLayer::isHiddenProperty( int index ) const +{ + bool hidden = false; + + QgsAuxiliaryField aField( fields().field( index ) ); + QgsPropertyDefinition def = aField.propertyDefinition(); + + if ( def.origin().compare( "labeling" ) == 0 ) + { + Q_FOREACH ( const QgsPalLayerSettings::Property &p, palHiddenProperties ) + { + const QString propName = QgsPalLayerSettings::propertyDefinitions()[ p ].name(); + if ( propName.compare( def.name() ) == 0 ) + { + hidden = true; + break; + } + } + } + + return hidden; +} + // // QgsAuxiliaryStorage // diff --git a/src/core/qgsauxiliarystorage.h b/src/core/qgsauxiliarystorage.h index 25b4bc1cd7f..41cff49380e 100644 --- a/src/core/qgsauxiliarystorage.h +++ b/src/core/qgsauxiliarystorage.h @@ -199,6 +199,14 @@ class CORE_EXPORT QgsAuxiliaryLayer : public QgsVectorLayer */ virtual bool deleteAttribute( int attr ) override; + /** + * Returns true if the underlying field have to be hidden from editing + * tools like attribute table, false otherwise. + * + * \param index The index of the field for which visibility is checked + */ + bool isHiddenProperty( int index ) const; + /** * Create if necessary a new auxiliary field for a PAL property and * activate this property in settings. diff --git a/src/core/qgsvectorlayer.cpp b/src/core/qgsvectorlayer.cpp index 7f0a7c674be..2d443e15fb2 100644 --- a/src/core/qgsvectorlayer.cpp +++ b/src/core/qgsvectorlayer.cpp @@ -2834,17 +2834,17 @@ bool QgsVectorLayer::isModified() const } -bool QgsVectorLayer::isAuxiliaryField( int index ) const +bool QgsVectorLayer::isAuxiliaryField( int index, int &srcIndex ) const { bool auxiliaryField = false; + srcIndex = -1; if ( !auxiliaryLayer() ) return auxiliaryField; if ( index >= 0 && fields().fieldOrigin( index ) == QgsFields::OriginJoin ) { - int srcFieldIndex; - const QgsVectorLayerJoinInfo *info = mJoinBuffer->joinForFieldIndex( index, fields(), srcFieldIndex ); + const QgsVectorLayerJoinInfo *info = mJoinBuffer->joinForFieldIndex( index, fields(), srcIndex ); if ( info && info->joinLayerId() == auxiliaryLayer()->id() ) auxiliaryField = true; @@ -3073,6 +3073,31 @@ void QgsVectorLayer::updateFields() mFields[index].setEditorWidgetSetup( fieldWidgetIterator.value() ); } + // update attribute table config + mAttributeTableConfig.update( fields() ); + + if ( auxiliaryLayer() ) + { + QVector columns = mAttributeTableConfig.columns(); + + QVector::iterator it; + for ( it = columns.begin(); it != columns.end(); ++it ) + { + int idx = fields().lookupField( it->name ); + if ( idx >= 0 ) + { + int srcIdx = -1; + if ( !isAuxiliaryField( idx, srcIdx ) ) + continue; + + if ( auxiliaryLayer()->isHiddenProperty( srcIdx ) ) + it->hidden = true; + } + } + + mAttributeTableConfig.setColumns( columns ); + } + if ( oldFields != mFields ) { emit updatedFields(); diff --git a/src/core/qgsvectorlayer.h b/src/core/qgsvectorlayer.h index 89d38a99eca..9eb8af2ce07 100644 --- a/src/core/qgsvectorlayer.h +++ b/src/core/qgsvectorlayer.h @@ -1166,7 +1166,7 @@ class CORE_EXPORT QgsVectorLayer : public QgsMapLayer, public QgsExpressionConte * * \since QGIS 3.0 */ - bool isAuxiliaryField( int index ) const; + bool isAuxiliaryField( int index, int &srcIndex ) const; //! Synchronises with changes in the datasource virtual void reload() override;