Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
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 90e80c1
Show file tree
Hide file tree
Showing 43 changed files with 1,009 additions and 1,099 deletions.
64 changes: 61 additions & 3 deletions python/core/qgsproperty.sip
@@ -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.
Expand Down Expand Up @@ -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 );

Expand Down Expand Up @@ -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 );

Expand Down Expand Up @@ -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 );

Expand Down
14 changes: 7 additions & 7 deletions python/core/qgspropertycollection.sip
@@ -1,4 +1,4 @@
typedef QMap< int, QString > QgsPropertyDefinition;
typedef QMap< int, QgsPropertyDefinition > QgsPropertiesDefinition;

/**
* \ingroup core
Expand Down Expand Up @@ -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.
Expand All @@ -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;

};

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 );
};

2 changes: 1 addition & 1 deletion python/gui/symbology-ng/qgsrendererwidget.sip
Expand Up @@ -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/;
Expand Down
3 changes: 1 addition & 2 deletions src/app/composer/qgscomposerhtmlwidget.cpp
Expand Up @@ -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()
Expand Down
48 changes: 18 additions & 30 deletions src/app/composer/qgscomposeritemwidget.cpp
Expand Up @@ -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 )
{
Expand All @@ -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 );
Expand All @@ -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 ) );
}

Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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 )
Expand Down
14 changes: 4 additions & 10 deletions src/app/composer/qgscomposeritemwidget.h
Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand Down
6 changes: 2 additions & 4 deletions src/app/composer/qgscomposerlegendwidget.cpp
Expand Up @@ -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();

Expand Down
27 changes: 9 additions & 18 deletions src/app/composer/qgscomposermapwidget.cpp
Expand Up @@ -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();
Expand Down
12 changes: 4 additions & 8 deletions src/app/composer/qgscomposerpicturewidget.cpp
Expand Up @@ -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()
Expand Down
12 changes: 4 additions & 8 deletions src/app/composer/qgscomposerscalebarwidget.cpp
Expand Up @@ -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
Expand Down

0 comments on commit 90e80c1

Please sign in to comment.