Skip to content

Commit 54089ff

Browse files
committed
Follow up 4a3871, fix broken data defined properties
(definitions are often accessed before a QgsSymboLayer/etc is constructed)
1 parent fa8189a commit 54089ff

23 files changed

+128
-59
lines changed

python/core/composer/qgscomposerobject.sip

+5-1
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,11 @@ class QgsComposerObject : QObject, QgsExpressionContextGenerator
6060
ScalebarLineWidth, //!< Scalebar line width
6161
};
6262

63-
static const QgsPropertiesDefinition PROPERTY_DEFINITIONS;
63+
/**
64+
* Returns the composer object property definitions.
65+
* @note added in QGIS 3.0
66+
*/
67+
static const QgsPropertiesDefinition& propertyDefinitions();
6468

6569
/** Specifies whether the value returned by a function should be the original, user
6670
* set value, or the current evaluated value for the property. This may differ if

python/core/qgsdiagramrenderer.sip

+6-1
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,12 @@ class QgsDiagramLayerSettings
5353
StartAngle, /*! Angle offset for pie diagram */
5454
};
5555

56+
/**
57+
* Returns the diagram property definitions.
58+
* @note added in QGIS 3.0
59+
*/
60+
static const QgsPropertiesDefinition& propertyDefinitions();
61+
5662
QgsDiagramLayerSettings();
5763

5864
//! Copy constructor
@@ -209,7 +215,6 @@ class QgsDiagramLayerSettings
209215

210216
void setDataDefinedProperties( const QgsPropertyCollection& collection );
211217

212-
static const QgsPropertiesDefinition PROPERTY_DEFINITIONS;
213218

214219
};
215220

python/core/qgspallabeling.sip

+6-2
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,12 @@ class QgsPalLayerSettings
270270
AlwaysShow
271271
};
272272

273+
/**
274+
* Returns the labeling property definitions.
275+
* @note added in QGIS 3.0
276+
*/
277+
static const QgsPropertiesDefinition& propertyDefinitions();
278+
273279
// whether to label this layer
274280
bool enabled;
275281

@@ -460,8 +466,6 @@ class QgsPalLayerSettings
460466
int mFeatsSendingToPal; // total features tested for sending into PAL (relative to maxNumLabels)
461467
int mFeatsRegPal; // number of features registered in PAL, when using limitNumLabels
462468

463-
static const QgsPropertiesDefinition PROPERTY_DEFINITIONS;
464-
465469
};
466470

467471
class QgsLabelCandidate

python/core/symbology-ng/qgssymbollayer.sip

+5-1
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,11 @@ class QgsSymbolLayer
122122
PropertyArrowType, //!< Arrow type
123123
};
124124

125-
static const QgsPropertiesDefinition PROPERTY_DEFINITIONS;
125+
/**
126+
* Returns the symbol layer property definitions.
127+
* @note added in QGIS 3.0
128+
*/
129+
static const QgsPropertiesDefinition& propertyDefinitions();
126130

127131
virtual ~QgsSymbolLayer();
128132

src/app/composer/qgscomposeritemwidget.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ void QgsComposerConfigObject::updateDataDefinedButtons()
7777
void QgsComposerConfigObject::initializeDataDefinedButton( QgsPropertyOverrideButton* button, QgsComposerObject::DataDefinedProperty key )
7878
{
7979
button->blockSignals( true );
80-
button->init( key, mComposerObject->dataDefinedProperties(), QgsComposerObject::PROPERTY_DEFINITIONS, atlasCoverageLayer() );
80+
button->init( key, mComposerObject->dataDefinedProperties(), QgsComposerObject::propertyDefinitions(), atlasCoverageLayer() );
8181
connect( button, &QgsPropertyOverrideButton::changed, this, &QgsComposerConfigObject::updateDataDefinedProperty );
8282
button->registerExpressionContextGenerator( mComposerObject );
8383
button->blockSignals( false );

src/app/composer/qgscompositionwidget.cpp

+5-5
Original file line numberDiff line numberDiff line change
@@ -156,11 +156,11 @@ void QgsCompositionWidget::populateDataDefinedButtons()
156156
connect( button, &QgsPropertyOverrideButton::changed, this, &QgsCompositionWidget::updateDataDefinedProperty );
157157
}
158158

159-
mPaperSizeDDBtn->init( QgsComposerObject::PresetPaperSize, mComposition->dataDefinedProperties(), QgsComposerObject::PROPERTY_DEFINITIONS, vl );
160-
mPaperWidthDDBtn->init( QgsComposerObject::PaperWidth, mComposition->dataDefinedProperties(), QgsComposerObject::PROPERTY_DEFINITIONS, vl );
161-
mPaperHeightDDBtn->init( QgsComposerObject::PaperHeight, mComposition->dataDefinedProperties(), QgsComposerObject::PROPERTY_DEFINITIONS, vl );
162-
mNumPagesDDBtn->init( QgsComposerObject::NumPages, mComposition->dataDefinedProperties(), QgsComposerObject::PROPERTY_DEFINITIONS, vl );
163-
mPaperOrientationDDBtn->init( QgsComposerObject::PaperOrientation, mComposition->dataDefinedProperties(), QgsComposerObject::PROPERTY_DEFINITIONS, vl );
159+
mPaperSizeDDBtn->init( QgsComposerObject::PresetPaperSize, mComposition->dataDefinedProperties(), QgsComposerObject::propertyDefinitions(), vl );
160+
mPaperWidthDDBtn->init( QgsComposerObject::PaperWidth, mComposition->dataDefinedProperties(), QgsComposerObject::propertyDefinitions(), vl );
161+
mPaperHeightDDBtn->init( QgsComposerObject::PaperHeight, mComposition->dataDefinedProperties(), QgsComposerObject::propertyDefinitions(), vl );
162+
mNumPagesDDBtn->init( QgsComposerObject::NumPages, mComposition->dataDefinedProperties(), QgsComposerObject::propertyDefinitions(), vl );
163+
mPaperOrientationDDBtn->init( QgsComposerObject::PaperOrientation, mComposition->dataDefinedProperties(), QgsComposerObject::propertyDefinitions(), vl );
164164

165165
//initial state of controls - disable related controls when dd buttons are active
166166
mPaperSizeComboBox->setEnabled( !mPaperSizeDDBtn->isActive() );

src/app/qgsdiagramproperties.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -429,7 +429,7 @@ QgsDiagramProperties::~QgsDiagramProperties()
429429

430430
void QgsDiagramProperties::registerDataDefinedButton( QgsPropertyOverrideButton * button, QgsDiagramLayerSettings::Property key )
431431
{
432-
button->init( key, mDataDefinedProperties, QgsDiagramLayerSettings::PROPERTY_DEFINITIONS, mLayer );
432+
button->init( key, mDataDefinedProperties, QgsDiagramLayerSettings::propertyDefinitions(), mLayer );
433433
connect( button, &QgsPropertyOverrideButton::changed, this, &QgsDiagramProperties::updateProperty );
434434
button->registerExpressionContextGenerator( this );
435435
}

src/app/qgslabelinggui.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ QgsExpressionContext QgsLabelingGui::createExpressionContext() const
4444

4545
void QgsLabelingGui::registerDataDefinedButton( QgsPropertyOverrideButton* button, QgsPalLayerSettings::Property key )
4646
{
47-
button->init( key, mDataDefinedProperties, QgsPalLayerSettings::PROPERTY_DEFINITIONS, mLayer );
47+
button->init( key, mDataDefinedProperties, QgsPalLayerSettings::propertyDefinitions(), mLayer );
4848
connect( button, &QgsPropertyOverrideButton::changed, this, &QgsLabelingGui::updateProperty );
4949
button->registerExpressionContextGenerator( this );
5050
}

src/core/composer/qgscomposerobject.cpp

+11-5
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,14 @@
2323
#include "qgsproject.h"
2424
#include "qgsvectorlayer.h"
2525

26-
QgsPropertiesDefinition QgsComposerObject::PROPERTY_DEFINITIONS;
26+
QgsPropertiesDefinition QgsComposerObject::sPropertyDefinitions;
2727

2828
void QgsComposerObject::initPropertyDefinitions()
2929
{
30-
if ( !PROPERTY_DEFINITIONS.isEmpty() )
30+
if ( !sPropertyDefinitions.isEmpty() )
3131
return;
3232

33-
PROPERTY_DEFINITIONS = QgsPropertiesDefinition
33+
sPropertyDefinitions = QgsPropertiesDefinition
3434
{
3535
{ QgsComposerObject::TestProperty, QgsPropertyDefinition( "dataDefinedProperty" , QgsPropertyDefinition::DataTypeString, "invalid property", QString() ) },
3636
{ QgsComposerObject::PresetPaperSize, QgsPropertyDefinition( "dataDefinedPaperSize" , QgsPropertyDefinition::DataTypeString, QObject::tr( "Paper size" ), QObject::tr( "string " ) + QLatin1String( "[<b>A5</b>|<b>A4</b>|<b>A3</b>|<b>A2</b>|<b>A1</b>|<b>A0</b>"
@@ -76,6 +76,12 @@ void QgsComposerObject::initPropertyDefinitions()
7676
};
7777
}
7878

79+
const QgsPropertiesDefinition& QgsComposerObject::propertyDefinitions()
80+
{
81+
QgsComposerObject::initPropertyDefinitions();
82+
return sPropertyDefinitions;
83+
}
84+
7985
QgsComposerObject::QgsComposerObject( QgsComposition* composition )
8086
: QObject( nullptr )
8187
, mComposition( composition )
@@ -109,7 +115,7 @@ bool QgsComposerObject::writeXml( QDomElement &elem, QDomDocument &doc ) const
109115
}
110116

111117
QDomElement ddPropsElement = doc.createElement( QStringLiteral( "dataDefinedProperties" ) );
112-
mDataDefinedProperties.writeXml( ddPropsElement, doc, PROPERTY_DEFINITIONS );
118+
mDataDefinedProperties.writeXml( ddPropsElement, doc, sPropertyDefinitions );
113119
elem.appendChild( ddPropsElement );
114120

115121
//custom properties
@@ -132,7 +138,7 @@ bool QgsComposerObject::readXml( const QDomElement &itemElem, const QDomDocument
132138
QDomNode propsNode = itemElem.namedItem( QStringLiteral( "dataDefinedProperties" ) );
133139
if ( !propsNode.isNull() )
134140
{
135-
mDataDefinedProperties.readXml( propsNode.toElement(), doc, PROPERTY_DEFINITIONS );
141+
mDataDefinedProperties.readXml( propsNode.toElement(), doc, sPropertyDefinitions );
136142
}
137143

138144
//custom properties

src/core/composer/qgscomposerobject.h

+9-3
Original file line numberDiff line numberDiff line change
@@ -88,9 +88,6 @@ class CORE_EXPORT QgsComposerObject: public QObject, public QgsExpressionContext
8888
ScalebarLineWidth, //!< Scalebar line width
8989
};
9090

91-
//! Property definitions
92-
static QgsPropertiesDefinition PROPERTY_DEFINITIONS;
93-
9491
/** Specifies whether the value returned by a function should be the original, user
9592
* set value, or the current evaluated value for the property. This may differ if
9693
* a property has a data defined expression active.
@@ -101,6 +98,12 @@ class CORE_EXPORT QgsComposerObject: public QObject, public QgsExpressionContext
10198
OriginalValue //!< Return the original, user set value
10299
};
103100

101+
/**
102+
* Returns the composer object property definitions.
103+
* @note added in QGIS 3.0
104+
*/
105+
static const QgsPropertiesDefinition& propertyDefinitions();
106+
104107
/** Constructor
105108
* @param composition parent composition
106109
*/
@@ -229,6 +232,9 @@ class CORE_EXPORT QgsComposerObject: public QObject, public QgsExpressionContext
229232
void prepareProperties() const;
230233

231234
private:
235+
//! Property definitions
236+
static QgsPropertiesDefinition sPropertyDefinitions;
237+
232238
static void initPropertyDefinitions();
233239

234240
friend class TestQgsComposerObject;

src/core/composer/qgscomposerutils.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -322,8 +322,8 @@ bool QgsComposerUtils::decodePresetPaperSize( const QString& presetString, doubl
322322

323323
void QgsComposerUtils::readOldDataDefinedPropertyMap( const QDomElement &itemElem, QgsPropertyCollection& dataDefinedProperties )
324324
{
325-
QgsPropertiesDefinition::const_iterator i = QgsComposerObject::PROPERTY_DEFINITIONS.constBegin();
326-
for ( ; i != QgsComposerObject::PROPERTY_DEFINITIONS.constEnd(); ++i )
325+
QgsPropertiesDefinition::const_iterator i = QgsComposerObject::propertyDefinitions().constBegin();
326+
for ( ; i != QgsComposerObject::propertyDefinitions().constEnd(); ++i )
327327
{
328328
QString elemName = i.value().name();
329329
QDomNodeList ddNodeList = itemElem.elementsByTagName( elemName );

src/core/composer/qgscomposition.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -902,7 +902,7 @@ bool QgsComposition::writeXml( QDomElement& composerElem, QDomDocument& doc )
902902

903903
//data defined properties
904904
QDomElement ddPropsElement = doc.createElement( QStringLiteral( "dataDefinedProperties" ) );
905-
mDataDefinedProperties.writeXml( ddPropsElement, doc, QgsComposerObject::PROPERTY_DEFINITIONS );
905+
mDataDefinedProperties.writeXml( ddPropsElement, doc, QgsComposerObject::propertyDefinitions() );
906906
compositionElem.appendChild( ddPropsElement );
907907

908908
composerElem.appendChild( compositionElem );
@@ -989,7 +989,7 @@ bool QgsComposition::readXml( const QDomElement& compositionElem, const QDomDocu
989989
QDomNode propsNode = compositionElem.namedItem( QStringLiteral( "dataDefinedProperties" ) );
990990
if ( !propsNode.isNull() )
991991
{
992-
mDataDefinedProperties.readXml( propsNode.toElement(), doc, QgsComposerObject::PROPERTY_DEFINITIONS );
992+
mDataDefinedProperties.readXml( propsNode.toElement(), doc, QgsComposerObject::propertyDefinitions() );
993993
}
994994

995995
//custom properties

src/core/qgsdiagramrenderer.cpp

+11-5
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,14 @@
2525
#include <QDomElement>
2626
#include <QPainter>
2727

28-
QgsPropertiesDefinition QgsDiagramLayerSettings::PROPERTY_DEFINITIONS;
28+
QgsPropertiesDefinition QgsDiagramLayerSettings::sPropertyDefinitions;
2929

3030
void QgsDiagramLayerSettings::initPropertyDefinitions()
3131
{
32-
if ( !PROPERTY_DEFINITIONS.isEmpty() )
32+
if ( !sPropertyDefinitions.isEmpty() )
3333
return;
3434

35-
PROPERTY_DEFINITIONS = QgsPropertiesDefinition
35+
sPropertyDefinitions = QgsPropertiesDefinition
3636
{
3737
{ QgsDiagramLayerSettings::BackgroundColor, QgsPropertyDefinition( "backgroundColor", QObject::tr( "Background color" ), QgsPropertyDefinition::ColorWithAlpha ) },
3838
{ QgsDiagramLayerSettings::OutlineColor, QgsPropertyDefinition( "outlineColor", QObject::tr( "Outline color" ), QgsPropertyDefinition::ColorWithAlpha ) },
@@ -49,6 +49,12 @@ void QgsDiagramLayerSettings::initPropertyDefinitions()
4949
};
5050
}
5151

52+
const QgsPropertiesDefinition& QgsDiagramLayerSettings::propertyDefinitions()
53+
{
54+
initPropertyDefinitions();
55+
return sPropertyDefinitions;
56+
}
57+
5258
QgsDiagramLayerSettings::QgsDiagramLayerSettings( const QgsDiagramLayerSettings& rh )
5359
: mCt( rh.mCt )
5460
, mPlacement( rh.mPlacement )
@@ -105,7 +111,7 @@ void QgsDiagramLayerSettings::readXml( const QDomElement& elem, const QgsVectorL
105111
QDomNodeList propertyElems = elem.elementsByTagName( "properties" );
106112
if ( !propertyElems.isEmpty() )
107113
{
108-
( void )mDataDefinedProperties.readXml( propertyElems.at( 0 ).toElement(), elem.ownerDocument(), PROPERTY_DEFINITIONS );
114+
( void )mDataDefinedProperties.readXml( propertyElems.at( 0 ).toElement(), elem.ownerDocument(), sPropertyDefinitions );
109115
}
110116
else
111117
{
@@ -148,7 +154,7 @@ void QgsDiagramLayerSettings::writeXml( QDomElement& layerElem, QDomDocument& do
148154

149155
QDomElement diagramLayerElem = doc.createElement( QStringLiteral( "DiagramLayerSettings" ) );
150156
QDomElement propertiesElem = doc.createElement( "properties" );
151-
( void )mDataDefinedProperties.writeXml( propertiesElem, doc, PROPERTY_DEFINITIONS );
157+
( void )mDataDefinedProperties.writeXml( propertiesElem, doc, sPropertyDefinitions );
152158
diagramLayerElem.appendChild( propertiesElem );
153159
diagramLayerElem.setAttribute( QStringLiteral( "placement" ), mPlacement );
154160
diagramLayerElem.setAttribute( QStringLiteral( "linePlacementFlags" ), mPlacementFlags );

src/core/qgsdiagramrenderer.h

+10-3
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,12 @@ class CORE_EXPORT QgsDiagramLayerSettings
9595
StartAngle, //! Angle offset for pie diagram
9696
};
9797

98+
/**
99+
* Returns the diagram property definitions.
100+
* @note added in QGIS 3.0
101+
*/
102+
static const QgsPropertiesDefinition& propertyDefinitions();
103+
98104
/**
99105
* Constructor for QgsDiagramLayerSettings.
100106
*/
@@ -286,9 +292,6 @@ class CORE_EXPORT QgsDiagramLayerSettings
286292
*/
287293
void setDataDefinedProperties( const QgsPropertyCollection& collection ) { mDataDefinedProperties = collection; }
288294

289-
//! Property definitions
290-
static QgsPropertiesDefinition PROPERTY_DEFINITIONS;
291-
292295
private:
293296

294297
//! Associated coordinate transform, or invalid transform for no transformation
@@ -324,6 +327,10 @@ class CORE_EXPORT QgsDiagramLayerSettings
324327
QgsPropertyCollection mDataDefinedProperties;
325328

326329
static void initPropertyDefinitions();
330+
331+
//! Property definitions
332+
static QgsPropertiesDefinition sPropertyDefinitions;
333+
327334
};
328335

329336
/** \ingroup core

src/core/qgspallabeling.cpp

+15-10
Original file line numberDiff line numberDiff line change
@@ -90,14 +90,14 @@ const QVector< QgsPalLayerSettings::PredefinedPointPosition > QgsPalLayerSetting
9090
<< QgsPalLayerSettings::TopMiddle
9191
<< QgsPalLayerSettings::BottomMiddle;*/
9292

93-
QgsPropertiesDefinition QgsPalLayerSettings::PROPERTY_DEFINITIONS;
93+
QgsPropertiesDefinition QgsPalLayerSettings::sPropertyDefinitions;
9494

9595
void QgsPalLayerSettings::initPropertyDefinitions()
9696
{
97-
if ( !PROPERTY_DEFINITIONS.isEmpty() )
97+
if ( !sPropertyDefinitions.isEmpty() )
9898
return;
9999

100-
PROPERTY_DEFINITIONS = QgsPropertiesDefinition
100+
sPropertyDefinitions = QgsPropertiesDefinition
101101
{
102102
{ QgsPalLayerSettings::Size, QgsPropertyDefinition( "Size" , QObject::tr( "Font size" ), QgsPropertyDefinition::DoublePositive ) },
103103
{ QgsPalLayerSettings::Bold, QgsPropertyDefinition( "Bold", QObject::tr( "Bold style" ), QgsPropertyDefinition::Boolean ) },
@@ -392,6 +392,11 @@ QgsPalLayerSettings QgsPalLayerSettings::fromLayer( QgsVectorLayer* layer )
392392
return settings;
393393
}
394394

395+
const QgsPropertiesDefinition& QgsPalLayerSettings::propertyDefinitions()
396+
{
397+
initPropertyDefinitions();
398+
return sPropertyDefinitions;
399+
}
395400

396401
QgsExpression* QgsPalLayerSettings::getLabelExpression()
397402
{
@@ -438,7 +443,7 @@ QString updateDataDefinedString( const QString& value )
438443

439444
void QgsPalLayerSettings::readOldDataDefinedProperty( QgsVectorLayer* layer, QgsPalLayerSettings::Property p )
440445
{
441-
QString newPropertyName = "labeling/dataDefined/" + PROPERTY_DEFINITIONS.value( p ).name();
446+
QString newPropertyName = "labeling/dataDefined/" + sPropertyDefinitions.value( p ).name();
442447
QVariant newPropertyField = layer->customProperty( newPropertyName, QVariant() );
443448

444449
if ( !newPropertyField.isValid() )
@@ -476,8 +481,8 @@ void QgsPalLayerSettings::readOldDataDefinedPropertyMap( QgsVectorLayer* layer,
476481
return;
477482
}
478483

479-
QgsPropertiesDefinition::const_iterator i = PROPERTY_DEFINITIONS.constBegin();
480-
for ( ; i != PROPERTY_DEFINITIONS.constEnd(); ++i )
484+
QgsPropertiesDefinition::const_iterator i = sPropertyDefinitions.constBegin();
485+
for ( ; i != sPropertyDefinitions.constEnd(); ++i )
481486
{
482487
if ( layer )
483488
{
@@ -650,7 +655,7 @@ void QgsPalLayerSettings::readFromLayer( QgsVectorLayer* layer )
650655
QDomDocument doc( QStringLiteral( "dd" ) );
651656
doc.setContent( layer->customProperty( QStringLiteral( "labeling/ddProperties" ) ).toString() );
652657
QDomElement elem = doc.firstChildElement( QStringLiteral( "properties" ) );
653-
mDataDefinedProperties.readXml( elem, doc, PROPERTY_DEFINITIONS );
658+
mDataDefinedProperties.readXml( elem, doc, sPropertyDefinitions );
654659
}
655660
else
656661
{
@@ -741,7 +746,7 @@ void QgsPalLayerSettings::writeToLayer( QgsVectorLayer* layer )
741746

742747
doc = QDomDocument( QStringLiteral( "dd" ) );
743748
QDomElement ddElem = doc.createElement( QStringLiteral( "properties" ) );
744-
mDataDefinedProperties.writeXml( ddElem, doc, PROPERTY_DEFINITIONS );
749+
mDataDefinedProperties.writeXml( ddElem, doc, sPropertyDefinitions );
745750
QString ddProps;
746751
QTextStream streamProps( &ddProps );
747752
ddElem.save( streamProps, -1 );
@@ -857,7 +862,7 @@ void QgsPalLayerSettings::readXml( QDomElement& elem )
857862
QDomElement ddElem = elem.firstChildElement( QStringLiteral( "dd_properties" ) );
858863
if ( !ddElem.isNull() )
859864
{
860-
mDataDefinedProperties.readXml( ddElem, ddElem.ownerDocument(), PROPERTY_DEFINITIONS );
865+
mDataDefinedProperties.readXml( ddElem, ddElem.ownerDocument(), sPropertyDefinitions );
861866
}
862867
else
863868
{
@@ -946,7 +951,7 @@ QDomElement QgsPalLayerSettings::writeXml( QDomDocument& doc )
946951
renderingElem.setAttribute( QStringLiteral( "zIndex" ), zIndex );
947952

948953
QDomElement ddElem = doc.createElement( QStringLiteral( "dd_properties" ) );
949-
mDataDefinedProperties.writeXml( ddElem, doc, PROPERTY_DEFINITIONS );
954+
mDataDefinedProperties.writeXml( ddElem, doc, sPropertyDefinitions );
950955

951956
QDomElement elem = doc.createElement( QStringLiteral( "settings" ) );
952957
elem.appendChild( textStyleElem );

0 commit comments

Comments
 (0)