Skip to content
Permalink
Browse files
Stronger definitions of properties in collections
Instead of defining the suitable field types and values for
properties when registering them to a data defined button,
now properties are fully defined when the valid
property keys are defined.
  • Loading branch information
nyalldawson committed Jan 23, 2017
1 parent 6c53ba2 commit 90e80c1353e999dc6482b6776dd64f7539688552
Showing with 1,009 additions and 1,099 deletions.
  1. +61 −3 python/core/qgsproperty.sip
  2. +7 −7 python/core/qgspropertycollection.sip
  3. +1 −1 python/gui/symbology-ng/qgsrendererwidget.sip
  4. +1 −2 src/app/composer/qgscomposerhtmlwidget.cpp
  5. +18 −30 src/app/composer/qgscomposeritemwidget.cpp
  6. +4 −10 src/app/composer/qgscomposeritemwidget.h
  7. +2 −4 src/app/composer/qgscomposerlegendwidget.cpp
  8. +9 −18 src/app/composer/qgscomposermapwidget.cpp
  9. +4 −8 src/app/composer/qgscomposerpicturewidget.cpp
  10. +4 −8 src/app/composer/qgscomposerscalebarwidget.cpp
  11. +6 −37 src/app/composer/qgscompositionwidget.cpp
  12. +0 −4 src/app/composer/qgscompositionwidget.h
  13. +16 −27 src/app/qgsdiagramproperties.cpp
  14. +1 −1 src/app/qgsdiagramproperties.h
  15. +98 −230 src/app/qgslabelinggui.cpp
  16. +1 −1 src/app/qgslabelinggui.h
  17. +44 −45 src/core/composer/qgscomposerobject.cpp
  18. +2 −1 src/core/composer/qgscomposerobject.h
  19. +3 −3 src/core/composer/qgscomposerutils.cpp
  20. +2 −2 src/core/composer/qgscomposition.cpp
  21. +17 −17 src/core/qgsdiagramrenderer.cpp
  22. +3 −1 src/core/qgsdiagramrenderer.h
  23. +116 −100 src/core/qgspallabeling.cpp
  24. +3 −2 src/core/qgspallabeling.h
  25. +150 −0 src/core/qgsproperty.cpp
  26. +122 −3 src/core/qgsproperty.h
  27. +18 −8 src/core/qgspropertycollection.cpp
  28. +12 −16 src/core/qgspropertycollection.h
  29. +51 −49 src/core/symbology-ng/qgssymbollayer.cpp
  30. +2 −1 src/core/symbology-ng/qgssymbollayer.h
  31. +2 −2 src/core/symbology-ng/qgssymbollayerutils.cpp
  32. +68 −241 src/gui/qgsdatadefinedbuttonv2.cpp
  33. +27 −73 src/gui/qgsdatadefinedbuttonv2.h
  34. +7 −7 src/gui/symbology-ng/qgsarrowsymbollayerwidget.cpp
  35. +12 −12 src/gui/symbology-ng/qgsellipsesymbollayerwidget.cpp
  36. +4 −6 src/gui/symbology-ng/qgslayerpropertieswidget.cpp
  37. +1 −1 src/gui/symbology-ng/qgslayerpropertieswidget.h
  38. +3 −2 src/gui/symbology-ng/qgsrendererwidget.cpp
  39. +5 −4 src/gui/symbology-ng/qgsrendererwidget.h
  40. +90 −101 src/gui/symbology-ng/qgssymbollayerwidget.cpp
  41. +2 −1 src/gui/symbology-ng/qgssymbollayerwidget.h
  42. +3 −3 src/gui/symbology-ng/qgssymbolslistwidget.cpp
  43. +7 −7 tests/src/core/testqgsproperty.cpp
@@ -1,3 +1,61 @@
class QgsPropertyDefinition
{
%TypeHeaderCode
#include <qgsproperty.h>
%End
public:

enum StandardPropertyTemplate
{
Boolean,
Integer,
IntegerPositive,
IntegerPositiveGreaterZero,
Double,
DoublePositive,
Double0To1,
String,
Transparency,
RenderUnits,
ColorWithAlpha,
ColorNoAlpha,
PenJoinStyle,
BlendMode,
Point,
Size,
LineStyle,
FillStyle,
CapStyle,
HorizontalAnchor,
VerticalAnchor,
SvgPath,
Offset,
Custom,
};

enum DataType
{
DataTypeString,
DataTypeNumeric,
DataTypeBoolean,
};

QgsPropertyDefinition();

QgsPropertyDefinition( const QString& name, const QString& description, StandardPropertyTemplate type );

QgsPropertyDefinition( const QString& name, DataType dataTypes, const QString& description, const QString& helpText );

QString name() const;

QString description() const;

QString helpText() const;

DataType dataType() const;

};

/** \ingroup core
* \class QgsAbstractProperty
* \brief Abstract base class for properties.
@@ -209,7 +267,7 @@ class QgsStaticProperty : QgsAbstractProperty

/** Constructor for QgsStaticProperty.
* @param value initial static value to use for property
* @param isActive whether the property is intially active
* @param isActive whether the property is initially active
*/
QgsStaticProperty( const QVariant& value = QVariant(), bool isActive = true );

@@ -255,7 +313,7 @@ class QgsFieldBasedProperty : QgsAbstractProperty

/** Constructor for QgsFieldBasedProperty.
* @param field field name
* @param isActive whether the property is intially active
* @param isActive whether the property is initially active
*/
QgsFieldBasedProperty( const QString& field = QString(), bool isActive = true );

@@ -303,7 +361,7 @@ class QgsExpressionBasedProperty : QgsAbstractProperty

/** Constructor for QgsExpressionBasedProperty.
* @param expression expression string
* @param isActive whether the property is intially active
* @param isActive whether the property is initially active
*/
QgsExpressionBasedProperty( const QString& expression = QString(), bool isActive = true );

@@ -1,4 +1,4 @@
typedef QMap< int, QString > QgsPropertyDefinition;
typedef QMap< int, QgsPropertyDefinition > QgsPropertiesDefinition;

/**
* \ingroup core
@@ -198,7 +198,7 @@ class QgsAbstractPropertyCollection
* to avoid writing the raw integer key values to XML, for readability and future-proofness.
* @see readXML()
*/
virtual bool writeXml( QDomElement& collectionElem, QDomDocument& doc, const QgsPropertyDefinition& propertyNameMap ) const = 0;
virtual bool writeXml( QDomElement& collectionElem, QDomDocument& doc, const QgsPropertiesDefinition& definitions ) const = 0;

/**
* Reads property collection state from an XML element.
@@ -208,7 +208,7 @@ class QgsAbstractPropertyCollection
* the propertyNameMap specified when writeXML() was called.
* @see writeXML()
*/
virtual bool readXml( const QDomElement& collectionElem, const QDomDocument& doc, const QgsPropertyDefinition &propertyNameMap ) = 0;
virtual bool readXml( const QDomElement& collectionElem, const QDomDocument& doc, const QgsPropertiesDefinition &definitions ) = 0;

};

@@ -257,8 +257,8 @@ class QgsPropertyCollection : QgsAbstractPropertyCollection
bool isActive( int key ) const;
bool hasActiveProperties() const;
bool hasActiveDynamicProperties() const;
bool writeXml( QDomElement& collectionElem, QDomDocument& doc, const QgsPropertyDefinition& propertyNameMap ) const;
bool readXml( const QDomElement& collectionElem, const QDomDocument& doc, const QgsPropertyDefinition& propertyNameMap );
bool writeXml( QDomElement& collectionElem, QDomDocument& doc, const QgsPropertiesDefinition& definitions ) const;
bool readXml( const QDomElement& collectionElem, const QDomDocument& doc, const QgsPropertiesDefinition& definitions );

/** Adds a property to the collection and takes ownership of it.
* @param key integer key for property. Any existing property with the same key will be deleted
@@ -383,7 +383,7 @@ class QgsPropertyCollectionStack : QgsAbstractPropertyCollection

QSet<int> propertyKeys() const;
bool hasProperty( int key ) const;
bool writeXml( QDomElement& collectionElem, QDomDocument& doc, const QgsPropertyDefinition& propertyNameMap ) const;
bool readXml( const QDomElement& collectionElem, const QDomDocument& doc, const QgsPropertyDefinition &propertyNameMap );
bool writeXml( QDomElement& collectionElem, QDomDocument& doc, const QgsPropertiesDefinition& definitions ) const;
bool readXml( const QDomElement& collectionElem, const QDomDocument& doc, const QgsPropertiesDefinition &definitions );
};

@@ -125,7 +125,7 @@ class QgsDataDefinedValueDialog : QDialog
*
* @note May be missing Python bindings depending on the platform.
*/
void init( const QString& description ); // needed in children ctor to call virtual
void init( int propertyKey ); // needed in children ctor to call virtual

private:
QgsAbstractProperty* symbolDataDefined() const /Factory/;
@@ -66,8 +66,7 @@ QgsComposerHtmlWidget::QgsComposerHtmlWidget( QgsComposerHtml* html, QgsComposer

//connections for data defined buttons
connect( mUrlDDBtn, &QgsDataDefinedButtonV2::activated, mUrlLineEdit, &QLineEdit::setDisabled );
registerDataDefinedButton( mUrlDDBtn, QgsComposerObject::SourceUrl,
QgsDataDefinedButtonV2::AnyType, tr( "url string" ) );
registerDataDefinedButton( mUrlDDBtn, QgsComposerObject::SourceUrl );
}

QgsComposerHtmlWidget::QgsComposerHtmlWidget()
@@ -53,8 +53,8 @@ void QgsComposerConfigObject::updateDataDefinedProperty()
}
QgsComposerObject::DataDefinedProperty key = QgsComposerObject::NoProperty;

if ( ddButton->property( "propertyKey" ).isValid() )
key = static_cast< QgsComposerObject::DataDefinedProperty >( ddButton->property( "propertyKey" ).toInt() );
if ( ddButton->propertyKey() >= 0 )
key = static_cast< QgsComposerObject::DataDefinedProperty >( ddButton->propertyKey() );

if ( key == QgsComposerObject::NoProperty )
{
@@ -74,12 +74,10 @@ void QgsComposerConfigObject::updateDataDefinedButtons()
}
}

void QgsComposerConfigObject::initializeDataDefinedButton( QgsDataDefinedButtonV2* button, QgsComposerObject::DataDefinedProperty key,
QgsDataDefinedButtonV2::DataType type, const QString& description )
void QgsComposerConfigObject::initializeDataDefinedButton( QgsDataDefinedButtonV2* button, QgsComposerObject::DataDefinedProperty key )
{
button->blockSignals( true );
button->init( atlasCoverageLayer(), mComposerObject->dataDefinedProperties().property( key ), type, description );
button->setProperty( "propertyKey", key );
button->init( key, mComposerObject->dataDefinedProperties(), QgsComposerObject::PROPERTY_DEFINITIONS, atlasCoverageLayer() );
connect( button, &QgsDataDefinedButtonV2::changed, this, &QgsComposerConfigObject::updateDataDefinedProperty );
button->registerExpressionContextGenerator( mComposerObject );
button->blockSignals( false );
@@ -90,10 +88,10 @@ void QgsComposerConfigObject::updateDataDefinedButton( QgsDataDefinedButtonV2* b
if ( !button )
return;

if ( !button->property( "propertyKey" ).isValid() )
if ( button->propertyKey() < 0 )
return;

QgsComposerObject::DataDefinedProperty key = static_cast< QgsComposerObject::DataDefinedProperty >( button->property( "propertyKey" ).toInt() );
QgsComposerObject::DataDefinedProperty key = static_cast< QgsComposerObject::DataDefinedProperty >( button->propertyKey() );
whileBlocking( button )->setToProperty( mComposerObject->dataDefinedProperties().property( key ) );
}

@@ -539,26 +537,16 @@ void QgsComposerItemWidget::setValuesForGuiNonPositionElements()

void QgsComposerItemWidget::initializeDataDefinedButtons()
{
mConfigObject->initializeDataDefinedButton( mXPositionDDBtn, QgsComposerObject::PositionX,
QgsDataDefinedButtonV2::AnyType, QgsDataDefinedButtonV2::doubleDesc() );
mConfigObject->initializeDataDefinedButton( mYPositionDDBtn, QgsComposerObject::PositionY,
QgsDataDefinedButtonV2::AnyType, QgsDataDefinedButtonV2::doubleDesc() );
mConfigObject->initializeDataDefinedButton( mWidthDDBtn, QgsComposerObject::ItemWidth,
QgsDataDefinedButtonV2::AnyType, QgsDataDefinedButtonV2::doubleDesc() );
mConfigObject->initializeDataDefinedButton( mHeightDDBtn, QgsComposerObject::ItemHeight,
QgsDataDefinedButtonV2::AnyType, QgsDataDefinedButtonV2::doubleDesc() );
mConfigObject->initializeDataDefinedButton( mItemRotationDDBtn, QgsComposerObject::ItemRotation,
QgsDataDefinedButtonV2::AnyType, QgsDataDefinedButtonV2::double180RotDesc() );
mConfigObject->initializeDataDefinedButton( mTransparencyDDBtn, QgsComposerObject::Transparency,
QgsDataDefinedButtonV2::AnyType, QgsDataDefinedButtonV2::intTranspDesc() );
mConfigObject->initializeDataDefinedButton( mBlendModeDDBtn, QgsComposerObject::BlendMode,
QgsDataDefinedButtonV2::String, QgsDataDefinedButtonV2::blendModesDesc() );
mConfigObject->initializeDataDefinedButton( mExcludePrintsDDBtn, QgsComposerObject::ExcludeFromExports,
QgsDataDefinedButtonV2::String, QgsDataDefinedButtonV2::boolDesc() );
mConfigObject->initializeDataDefinedButton( mItemFrameColorDDBtn, QgsComposerObject::FrameColor,
QgsDataDefinedButtonV2::String, QgsDataDefinedButtonV2::colorAlphaDesc() );
mConfigObject->initializeDataDefinedButton( mItemBackgroundColorDDBtn, QgsComposerObject::BackgroundColor,
QgsDataDefinedButtonV2::String, QgsDataDefinedButtonV2::colorAlphaDesc() );
mConfigObject->initializeDataDefinedButton( mXPositionDDBtn, QgsComposerObject::PositionX );
mConfigObject->initializeDataDefinedButton( mYPositionDDBtn, QgsComposerObject::PositionY );
mConfigObject->initializeDataDefinedButton( mWidthDDBtn, QgsComposerObject::ItemWidth );
mConfigObject->initializeDataDefinedButton( mHeightDDBtn, QgsComposerObject::ItemHeight );
mConfigObject->initializeDataDefinedButton( mItemRotationDDBtn, QgsComposerObject::ItemRotation );
mConfigObject->initializeDataDefinedButton( mTransparencyDDBtn, QgsComposerObject::Transparency );
mConfigObject->initializeDataDefinedButton( mBlendModeDDBtn, QgsComposerObject::BlendMode );
mConfigObject->initializeDataDefinedButton( mExcludePrintsDDBtn, QgsComposerObject::ExcludeFromExports );
mConfigObject->initializeDataDefinedButton( mItemFrameColorDDBtn, QgsComposerObject::FrameColor );
mConfigObject->initializeDataDefinedButton( mItemBackgroundColorDDBtn, QgsComposerObject::BackgroundColor );
}

void QgsComposerItemWidget::populateDataDefinedButtons()
@@ -793,9 +781,9 @@ QgsComposerItemBaseWidget::QgsComposerItemBaseWidget( QWidget* parent, QgsCompos

}

void QgsComposerItemBaseWidget::registerDataDefinedButton( QgsDataDefinedButtonV2* button, QgsComposerObject::DataDefinedProperty property, QgsDataDefinedButtonV2::DataType type, const QString& description )
void QgsComposerItemBaseWidget::registerDataDefinedButton( QgsDataDefinedButtonV2* button, QgsComposerObject::DataDefinedProperty property )
{
mConfigObject->initializeDataDefinedButton( button, property, type, description );
mConfigObject->initializeDataDefinedButton( button, property );
}

void QgsComposerItemBaseWidget::updateDataDefinedButton( QgsDataDefinedButtonV2* button )
@@ -58,12 +58,9 @@ class QgsComposerConfigObject: public QObject

/** Registers a data defined button, setting up its initial value, connections and description.
* @param button button to register
* @param property corresponding data defined property
* @param type valid data types for button
* @param description user visible description for data defined property
* @param key corresponding data defined property key
*/
void initializeDataDefinedButton( QgsDataDefinedButtonV2* button, QgsComposerObject::DataDefinedProperty key,
QgsDataDefinedButtonV2::DataType type, const QString& description );
void initializeDataDefinedButton( QgsDataDefinedButtonV2* button, QgsComposerObject::DataDefinedProperty key );

/**
* Updates a data defined button to reflect the item's current properties.
@@ -103,12 +100,9 @@ class QgsComposerItemBaseWidget: public QgsPanelWidget

/** Registers a data defined button, setting up its initial value, connections and description.
* @param button button to register
* @param property corresponding data defined property
* @param type valid data types for button
* @param description user visible description for data defined property
* @param property corresponding data defined property key
*/
void registerDataDefinedButton( QgsDataDefinedButtonV2* button, QgsComposerObject::DataDefinedProperty property,
QgsDataDefinedButtonV2::DataType type, const QString& description );
void registerDataDefinedButton( QgsDataDefinedButtonV2* button, QgsComposerObject::DataDefinedProperty property );

/**
* Updates a previously registered data defined button to reflect the item's current properties.
@@ -100,10 +100,8 @@ QgsComposerLegendWidget::QgsComposerLegendWidget( QgsComposerLegend* legend )
connect( &legend->composition()->atlasComposition(), SIGNAL( coverageLayerChanged( QgsVectorLayer* ) ), this, SLOT( updateFilterLegendByAtlasButton() ) );
}

registerDataDefinedButton( mLegendTitleDDBtn, QgsComposerObject::LegendTitle,
QgsDataDefinedButtonV2::AnyType, QgsDataDefinedButtonV2::anyStringDesc() );
registerDataDefinedButton( mColumnsDDBtn, QgsComposerObject::LegendColumnCount,
QgsDataDefinedButtonV2::AnyType, QgsDataDefinedButtonV2::intPosOneDesc() );
registerDataDefinedButton( mLegendTitleDDBtn, QgsComposerObject::LegendTitle );
registerDataDefinedButton( mColumnsDDBtn, QgsComposerObject::LegendColumnCount );

setGuiElements();

@@ -105,24 +105,15 @@ QgsComposerMapWidget::QgsComposerMapWidget( QgsComposerMap* composerMap )

connect( mCrsSelector, &QgsProjectionSelectionWidget::crsChanged, this, &QgsComposerMapWidget::mapCrsChanged );

registerDataDefinedButton( mScaleDDBtn, QgsComposerObject::MapScale,
QgsDataDefinedButtonV2::AnyType, QgsDataDefinedButtonV2::doubleDesc() );
registerDataDefinedButton( mMapRotationDDBtn, QgsComposerObject::MapRotation,
QgsDataDefinedButtonV2::AnyType, QgsDataDefinedButtonV2::doubleDesc() );
registerDataDefinedButton( mXMinDDBtn, QgsComposerObject::MapXMin,
QgsDataDefinedButtonV2::AnyType, QgsDataDefinedButtonV2::doubleDesc() );
registerDataDefinedButton( mYMinDDBtn, QgsComposerObject::MapYMin,
QgsDataDefinedButtonV2::AnyType, QgsDataDefinedButtonV2::doubleDesc() );
registerDataDefinedButton( mXMaxDDBtn, QgsComposerObject::MapXMax,
QgsDataDefinedButtonV2::AnyType, QgsDataDefinedButtonV2::doubleDesc() );
registerDataDefinedButton( mYMaxDDBtn, QgsComposerObject::MapYMax,
QgsDataDefinedButtonV2::AnyType, QgsDataDefinedButtonV2::doubleDesc() );
registerDataDefinedButton( mAtlasMarginDDBtn, QgsComposerObject::MapAtlasMargin,
QgsDataDefinedButtonV2::AnyType, QgsDataDefinedButtonV2::doubleDesc() );
registerDataDefinedButton( mStylePresetsDDBtn, QgsComposerObject::MapStylePreset,
QgsDataDefinedButtonV2::String, tr( "string matching a style preset name" ) );
registerDataDefinedButton( mLayersDDBtn, QgsComposerObject::MapLayers,
QgsDataDefinedButtonV2::String, tr( "list of map layer names separated by | characters" ) );
registerDataDefinedButton( mScaleDDBtn, QgsComposerObject::MapScale );
registerDataDefinedButton( mMapRotationDDBtn, QgsComposerObject::MapRotation );
registerDataDefinedButton( mXMinDDBtn, QgsComposerObject::MapXMin );
registerDataDefinedButton( mYMinDDBtn, QgsComposerObject::MapYMin );
registerDataDefinedButton( mXMaxDDBtn, QgsComposerObject::MapXMax );
registerDataDefinedButton( mYMaxDDBtn, QgsComposerObject::MapYMax );
registerDataDefinedButton( mAtlasMarginDDBtn, QgsComposerObject::MapAtlasMargin );
registerDataDefinedButton( mStylePresetsDDBtn, QgsComposerObject::MapStylePreset );
registerDataDefinedButton( mLayersDDBtn, QgsComposerObject::MapLayers );

updateGuiElements();
loadGridEntries();
@@ -78,14 +78,10 @@ QgsComposerPictureWidget::QgsComposerPictureWidget( QgsComposerPicture* picture

//connections for data defined buttons
connect( mSourceDDBtn, &QgsDataDefinedButtonV2::activated, mPictureLineEdit, &QLineEdit::setDisabled );
registerDataDefinedButton( mSourceDDBtn, QgsComposerObject::PictureSource,
QgsDataDefinedButtonV2::AnyType, QgsDataDefinedButtonV2::anyStringDesc() );
registerDataDefinedButton( mFillColorDDBtn, QgsComposerObject::PictureSvgBackgroundColor,
QgsDataDefinedButtonV2::AnyType, QgsDataDefinedButtonV2::colorAlphaDesc() );
registerDataDefinedButton( mOutlineColorDDBtn, QgsComposerObject::PictureSvgOutlineColor,
QgsDataDefinedButtonV2::AnyType, QgsDataDefinedButtonV2::colorAlphaDesc() );
registerDataDefinedButton( mOutlineWidthDDBtn, QgsComposerObject::PictureSvgOutlineWidth,
QgsDataDefinedButtonV2::AnyType, QgsDataDefinedButtonV2::doublePosDesc() );
registerDataDefinedButton( mSourceDDBtn, QgsComposerObject::PictureSource );
registerDataDefinedButton( mFillColorDDBtn, QgsComposerObject::PictureSvgBackgroundColor );
registerDataDefinedButton( mOutlineColorDDBtn, QgsComposerObject::PictureSvgOutlineColor );
registerDataDefinedButton( mOutlineWidthDDBtn, QgsComposerObject::PictureSvgOutlineWidth );
}

QgsComposerPictureWidget::~QgsComposerPictureWidget()
@@ -91,14 +91,10 @@ QgsComposerScaleBarWidget::QgsComposerScaleBarWidget( QgsComposerScaleBar* scale

connect( mMapItemComboBox, SIGNAL( itemChanged( QgsComposerItem* ) ), this, SLOT( composerMapChanged( QgsComposerItem* ) ) );

registerDataDefinedButton( mFillColorDDBtn, QgsComposerObject::ScalebarFillColor,
QgsDataDefinedButtonV2::AnyType, QgsDataDefinedButtonV2::colorAlphaDesc() );
registerDataDefinedButton( mFillColor2DDBtn, QgsComposerObject::ScalebarFillColor2,
QgsDataDefinedButtonV2::AnyType, QgsDataDefinedButtonV2::colorAlphaDesc() );
registerDataDefinedButton( mLineColorDDBtn, QgsComposerObject::ScalebarLineColor,
QgsDataDefinedButtonV2::AnyType, QgsDataDefinedButtonV2::colorAlphaDesc() );
registerDataDefinedButton( mLineWidthDDBtn, QgsComposerObject::ScalebarLineWidth,
QgsDataDefinedButtonV2::AnyType, QgsDataDefinedButtonV2::doublePosDesc() );
registerDataDefinedButton( mFillColorDDBtn, QgsComposerObject::ScalebarFillColor );
registerDataDefinedButton( mFillColor2DDBtn, QgsComposerObject::ScalebarFillColor2 );
registerDataDefinedButton( mLineColorDDBtn, QgsComposerObject::ScalebarLineColor );
registerDataDefinedButton( mLineWidthDDBtn, QgsComposerObject::ScalebarLineWidth );

blockMemberSignals( false );
setGuiElements(); //set the GUI elements to the state of scaleBar

0 comments on commit 90e80c1

Please sign in to comment.