Skip to content

Commit

Permalink
Hide auxiliary columns which can be edited by "change label propertie…
Browse files Browse the repository at this point in the history
…s" map tool
  • Loading branch information
pblottiere committed Oct 9, 2017
1 parent ce2436d commit 821aadc
Show file tree
Hide file tree
Showing 6 changed files with 95 additions and 5 deletions.
9 changes: 9 additions & 0 deletions python/core/qgsauxiliarystorage.sip
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion python/core/qgsvectorlayer.sip
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
48 changes: 48 additions & 0 deletions src/core/qgsauxiliarystorage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 )
Expand Down Expand Up @@ -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
//
Expand Down
8 changes: 8 additions & 0 deletions src/core/qgsauxiliarystorage.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
31 changes: 28 additions & 3 deletions src/core/qgsvectorlayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion src/core/qgsvectorlayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 821aadc

Please sign in to comment.