Skip to content

Commit 821aadc

Browse files
committedOct 9, 2017
Hide auxiliary columns which can be edited by "change label properties" map tool
1 parent ce2436d commit 821aadc

File tree

6 files changed

+95
-5
lines changed

6 files changed

+95
-5
lines changed
 

‎python/core/qgsauxiliarystorage.sip

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,15 @@ class QgsAuxiliaryLayer : QgsVectorLayer
179179
:rtype: bool
180180
%End
181181

182+
bool isHiddenProperty( int index ) const;
183+
%Docstring
184+
Returns true if the underlying field have to be hidden from editing
185+
tools like attribute table, false otherwise.
186+
187+
\param index The index of the field for which visibility is checked
188+
:rtype: bool
189+
%End
190+
182191
static int createProperty( QgsPalLayerSettings::Property property, const QString &providerId, QgsVectorLayer *vlayer );
183192
%Docstring
184193
Create if necessary a new auxiliary field for a PAL property and

‎python/core/qgsvectorlayer.sip

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1125,7 +1125,7 @@ Returns true if the provider has been modified since the last commit
11251125
:rtype: bool
11261126
%End
11271127

1128-
bool isAuxiliaryField( int index ) const;
1128+
bool isAuxiliaryField( int index, int &srcIndex ) const;
11291129
%Docstring
11301130
Returns true if the field comes from the auxiliary layer,
11311131
false otherwise.

‎src/core/qgsauxiliarystorage.cpp

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,31 @@ const QString AS_JOINFIELD = "ASPK";
3030
const QString AS_EXTENSION = "qgd";
3131
const QString AS_JOINPREFIX = "auxiliary_storage_";
3232

33+
const QVector<QgsPalLayerSettings::Property> palHiddenProperties
34+
{
35+
QgsPalLayerSettings::PositionX,
36+
QgsPalLayerSettings::PositionY,
37+
QgsPalLayerSettings::Show,
38+
QgsPalLayerSettings::LabelRotation,
39+
QgsPalLayerSettings::Family,
40+
QgsPalLayerSettings::FontStyle,
41+
QgsPalLayerSettings::Size,
42+
QgsPalLayerSettings::Bold,
43+
QgsPalLayerSettings::Italic,
44+
QgsPalLayerSettings::Underline,
45+
QgsPalLayerSettings::Color,
46+
QgsPalLayerSettings::Strikeout,
47+
QgsPalLayerSettings::BufferSize,
48+
QgsPalLayerSettings::BufferColor,
49+
QgsPalLayerSettings::LabelDistance,
50+
QgsPalLayerSettings::Hali,
51+
QgsPalLayerSettings::Vali,
52+
QgsPalLayerSettings::ScaleVisibility,
53+
QgsPalLayerSettings::MinScale,
54+
QgsPalLayerSettings::MaxScale,
55+
QgsPalLayerSettings::AlwaysShow
56+
};
57+
3358
QgsAuxiliaryField::QgsAuxiliaryField( const QgsPropertyDefinition &def )
3459
: QgsField()
3560
, mPropertyDefinition( def )
@@ -310,6 +335,29 @@ int QgsAuxiliaryLayer::createProperty( QgsDiagramLayerSettings::Property propert
310335
return index;
311336
}
312337

338+
bool QgsAuxiliaryLayer::isHiddenProperty( int index ) const
339+
{
340+
bool hidden = false;
341+
342+
QgsAuxiliaryField aField( fields().field( index ) );
343+
QgsPropertyDefinition def = aField.propertyDefinition();
344+
345+
if ( def.origin().compare( "labeling" ) == 0 )
346+
{
347+
Q_FOREACH ( const QgsPalLayerSettings::Property &p, palHiddenProperties )
348+
{
349+
const QString propName = QgsPalLayerSettings::propertyDefinitions()[ p ].name();
350+
if ( propName.compare( def.name() ) == 0 )
351+
{
352+
hidden = true;
353+
break;
354+
}
355+
}
356+
}
357+
358+
return hidden;
359+
}
360+
313361
//
314362
// QgsAuxiliaryStorage
315363
//

‎src/core/qgsauxiliarystorage.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,14 @@ class CORE_EXPORT QgsAuxiliaryLayer : public QgsVectorLayer
199199
*/
200200
virtual bool deleteAttribute( int attr ) override;
201201

202+
/**
203+
* Returns true if the underlying field have to be hidden from editing
204+
* tools like attribute table, false otherwise.
205+
*
206+
* \param index The index of the field for which visibility is checked
207+
*/
208+
bool isHiddenProperty( int index ) const;
209+
202210
/**
203211
* Create if necessary a new auxiliary field for a PAL property and
204212
* activate this property in settings.

‎src/core/qgsvectorlayer.cpp

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2834,17 +2834,17 @@ bool QgsVectorLayer::isModified() const
28342834
}
28352835

28362836

2837-
bool QgsVectorLayer::isAuxiliaryField( int index ) const
2837+
bool QgsVectorLayer::isAuxiliaryField( int index, int &srcIndex ) const
28382838
{
28392839
bool auxiliaryField = false;
2840+
srcIndex = -1;
28402841

28412842
if ( !auxiliaryLayer() )
28422843
return auxiliaryField;
28432844

28442845
if ( index >= 0 && fields().fieldOrigin( index ) == QgsFields::OriginJoin )
28452846
{
2846-
int srcFieldIndex;
2847-
const QgsVectorLayerJoinInfo *info = mJoinBuffer->joinForFieldIndex( index, fields(), srcFieldIndex );
2847+
const QgsVectorLayerJoinInfo *info = mJoinBuffer->joinForFieldIndex( index, fields(), srcIndex );
28482848

28492849
if ( info && info->joinLayerId() == auxiliaryLayer()->id() )
28502850
auxiliaryField = true;
@@ -3073,6 +3073,31 @@ void QgsVectorLayer::updateFields()
30733073
mFields[index].setEditorWidgetSetup( fieldWidgetIterator.value() );
30743074
}
30753075

3076+
// update attribute table config
3077+
mAttributeTableConfig.update( fields() );
3078+
3079+
if ( auxiliaryLayer() )
3080+
{
3081+
QVector<QgsAttributeTableConfig::ColumnConfig> columns = mAttributeTableConfig.columns();
3082+
3083+
QVector<QgsAttributeTableConfig::ColumnConfig>::iterator it;
3084+
for ( it = columns.begin(); it != columns.end(); ++it )
3085+
{
3086+
int idx = fields().lookupField( it->name );
3087+
if ( idx >= 0 )
3088+
{
3089+
int srcIdx = -1;
3090+
if ( !isAuxiliaryField( idx, srcIdx ) )
3091+
continue;
3092+
3093+
if ( auxiliaryLayer()->isHiddenProperty( srcIdx ) )
3094+
it->hidden = true;
3095+
}
3096+
}
3097+
3098+
mAttributeTableConfig.setColumns( columns );
3099+
}
3100+
30763101
if ( oldFields != mFields )
30773102
{
30783103
emit updatedFields();

‎src/core/qgsvectorlayer.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1166,7 +1166,7 @@ class CORE_EXPORT QgsVectorLayer : public QgsMapLayer, public QgsExpressionConte
11661166
*
11671167
* \since QGIS 3.0
11681168
*/
1169-
bool isAuxiliaryField( int index ) const;
1169+
bool isAuxiliaryField( int index, int &srcIndex ) const;
11701170

11711171
//! Synchronises with changes in the datasource
11721172
virtual void reload() override;

0 commit comments

Comments
 (0)
Please sign in to comment.