Skip to content

Commit

Permalink
Nicer initialization of diagram property map
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Jan 23, 2017
1 parent 746034b commit 1e0c62b
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 32 deletions.
44 changes: 16 additions & 28 deletions src/core/qgsdiagramrenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,21 @@
#include <QDomElement>
#include <QPainter>

QMap< int, QString > QgsDiagramLayerSettings::sPropertyNameMap;

QgsDiagramLayerSettings::QgsDiagramLayerSettings()
{
init();
}
const QMap< int, QString > QgsDiagramLayerSettings::sPropertyNameMap
{
{ QgsDiagramLayerSettings::BackgroundColor, "backgroundColor" },
{ QgsDiagramLayerSettings::OutlineColor, "outlineColor" },
{ QgsDiagramLayerSettings::OutlineWidth, "outlineWidth" },
{ QgsDiagramLayerSettings::PositionX, "positionX" },
{ QgsDiagramLayerSettings::PositionY, "positionY" },
{ QgsDiagramLayerSettings::Distance, "distance" },
{ QgsDiagramLayerSettings::Priority, "priority" },
{ QgsDiagramLayerSettings::ZIndex, "zIndex" },
{ QgsDiagramLayerSettings::IsObstacle, "isObstacle" },
{ QgsDiagramLayerSettings::Show, "show" },
{ QgsDiagramLayerSettings::AlwaysShow, "alwaysShow" },
{ QgsDiagramLayerSettings::StartAngle, "startAngle" }
};

QgsDiagramLayerSettings::QgsDiagramLayerSettings( const QgsDiagramLayerSettings& rh )
: mCt( rh.mCt )
Expand All @@ -43,9 +52,7 @@ QgsDiagramLayerSettings::QgsDiagramLayerSettings( const QgsDiagramLayerSettings&
, mRenderer( rh.mRenderer ? rh.mRenderer->clone() : nullptr )
, mShowAll( rh.mShowAll )
, mProperties( rh.mProperties )
{
init();
}
{}

QgsDiagramLayerSettings&QgsDiagramLayerSettings::operator=( const QgsDiagramLayerSettings & rh )
{
Expand Down Expand Up @@ -148,25 +155,6 @@ bool QgsDiagramLayerSettings::prepare( const QgsExpressionContext& context ) con
return mProperties.prepare( context );
}

void QgsDiagramLayerSettings::init()
{
if ( sPropertyNameMap.isEmpty() )
{
sPropertyNameMap.insert( BackgroundColor, "backgroundColor" );
sPropertyNameMap.insert( OutlineColor, "outlineColor" );
sPropertyNameMap.insert( OutlineWidth, "outlineWidth" );
sPropertyNameMap.insert( PositionX, "positionX" );
sPropertyNameMap.insert( PositionY, "positionY" );
sPropertyNameMap.insert( Distance, "distance" );
sPropertyNameMap.insert( Priority, "priority" );
sPropertyNameMap.insert( ZIndex, "zIndex" );
sPropertyNameMap.insert( IsObstacle, "isObstacle" );
sPropertyNameMap.insert( Show, "show" );
sPropertyNameMap.insert( AlwaysShow, "alwaysShow" );
sPropertyNameMap.insert( StartAngle, "startAngle" );
}
}

QSet<QString> QgsDiagramLayerSettings::referencedFields( const QgsExpressionContext &context ) const
{
QSet< QString > referenced;
Expand Down
6 changes: 2 additions & 4 deletions src/core/qgsdiagramrenderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ class CORE_EXPORT QgsDiagramLayerSettings
StartAngle, //! Angle offset for pie diagram
};

QgsDiagramLayerSettings();
QgsDiagramLayerSettings() = default;

//! Copy constructor
QgsDiagramLayerSettings( const QgsDiagramLayerSettings& rh );
Expand Down Expand Up @@ -308,9 +308,7 @@ class CORE_EXPORT QgsDiagramLayerSettings
//! Property collection for data defined diagram settings
QgsPropertyCollection mProperties;

static QMap< int, QString > sPropertyNameMap;

void init();
static const QMap< int, QString > sPropertyNameMap;
};

/** \ingroup core
Expand Down

0 comments on commit 1e0c62b

Please sign in to comment.