Hide auxiliary columns which can be edited by "change label properties" map tool

This commit is contained in:
Blottiere Paul 2017-09-02 06:15:52 +01:00
parent ce2436dc4a
commit 821aadc400
6 changed files with 95 additions and 5 deletions

View File

@ -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

View File

@ -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.

View File

@ -30,6 +30,31 @@ const QString AS_JOINFIELD = "ASPK";
const QString AS_EXTENSION = "qgd";
const QString AS_JOINPREFIX = "auxiliary_storage_";
const QVector<QgsPalLayerSettings::Property> 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
//

View File

@ -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.

View File

@ -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<QgsAttributeTableConfig::ColumnConfig> columns = mAttributeTableConfig.columns();
QVector<QgsAttributeTableConfig::ColumnConfig>::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();

View File

@ -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;