Skip to content

Commit

Permalink
[pal] Nicer use of enums, LineArrangementFlags
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Jul 15, 2015
1 parent fea58eb commit ea41b92
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 28 deletions.
2 changes: 1 addition & 1 deletion src/core/pal/feature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -563,7 +563,7 @@ namespace pal
double alpha;
double cost;

unsigned long flags = f->layer->arrangementFlags();
LineArrangementFlags flags = f->layer->arrangementFlags();
if ( flags == 0 )
flags = FLAG_ON_LINE; // default flag

Expand Down
6 changes: 3 additions & 3 deletions src/core/pal/layer.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,13 +98,13 @@ namespace pal
/** Returns the layer's arrangement flags.
* @see setArrangementFlags
*/
unsigned long arrangementFlags() const { return mArrangementFlags; }
LineArrangementFlags arrangementFlags() const { return mArrangementFlags; }

/** Sets the layer's arrangement flags.
* @param flags arrangement flags
* @see arrangementFlags
*/
void setArrangementFlags( unsigned long flags ) { mArrangementFlags = flags; }
void setArrangementFlags( LineArrangementFlags flags ) { mArrangementFlags = flags; }

/**
* \brief Sets whether the layer is currently active.
Expand Down Expand Up @@ -267,7 +267,7 @@ namespace pal

/** Optional flags used for some placement methods */
Arrangement mArrangement;
unsigned long mArrangementFlags;
LineArrangementFlags mArrangementFlags;
LabelMode mMode;
bool mMergeLines;

Expand Down
17 changes: 8 additions & 9 deletions src/core/pal/pal.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ namespace pal
class PointSet;

/** Search method to use */
enum _searchMethod
enum SearchMethod
{
CHAIN = 0, /**< is the worst but fastest method */
POPMUSIC_TABU_CHAIN = 1, /**< is the best but slowest */
Expand All @@ -68,14 +68,11 @@ namespace pal
FALP = 4 /** only initial solution */
};

/** Typedef for _Units enumeration */
typedef enum _searchMethod SearchMethod;

/** The way to arrange labels against spatial entities
*
* image html arrangement.png "Arrangement modes" width=7cm
* */
enum _arrangement
enum Arrangement
{
P_POINT = 0, /**< arranges candidates around a point (centroid for polygon)*/
P_POINT_OVER, /** arranges candidates over a point (centroid for polygon)*/
Expand All @@ -85,17 +82,15 @@ namespace pal
P_FREE /**< Only for polygon, arranges candidates with respect of polygon orientation */
};

/** Typedef for _arrangement enumeration */
typedef enum _arrangement Arrangement;

/** Enumeration line arrangement flags. Flags can be combined. */
enum LineArrangementFlags
enum LineArrangementFlag
{
FLAG_ON_LINE = 1,
FLAG_ABOVE_LINE = 2,
FLAG_BELOW_LINE = 4,
FLAG_MAP_ORIENTATION = 8
};
Q_DECLARE_FLAGS( LineArrangementFlags, LineArrangementFlag )

/**
* \brief Pal main class.
Expand Down Expand Up @@ -389,5 +384,9 @@ namespace pal
*/
int getMaxIt();
};

} // end namespace pal

Q_DECLARE_OPERATORS_FOR_FLAGS( pal::LineArrangementFlags )

#endif
26 changes: 13 additions & 13 deletions src/core/qgsdiagramrendererv2.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ class CORE_EXPORT QgsDiagramLayerSettings

//pal placement properties
Placement placement;
unsigned int placementFlags;
unsigned int placementFlags;
int priority; // 0 = low, 10 = high
bool obstacle; // whether it's an obstacle
double dist; // distance from the feature (in mm)
Expand Down Expand Up @@ -172,13 +172,13 @@ class CORE_EXPORT QgsDiagramInterpolationSettings
QSizeF upperSize;
double lowerValue;
double upperValue;
/**Index of the classification attribute*/
/** Index of the classification attribute*/
int classificationAttribute;
QString classificationAttributeExpression;
bool classificationAttributeIsExpression;
};

/**Returns diagram settings for a feature*/
/** Returns diagram settings for a feature*/
class CORE_EXPORT QgsDiagramRendererV2
{
public:
Expand All @@ -190,20 +190,20 @@ class CORE_EXPORT QgsDiagramRendererV2
* @note added in 2.4 */
virtual QgsDiagramRendererV2* clone() const = 0;

/**Returns size of the diagram for a feature in map units. Returns an invalid QSizeF in case of error*/
/** Returns size of the diagram for a feature in map units. Returns an invalid QSizeF in case of error*/
virtual QSizeF sizeMapUnits( const QgsFeature& feature, const QgsRenderContext& c );

virtual QString rendererName() const = 0;

/**Returns attribute indices needed for diagram rendering*/
/** Returns attribute indices needed for diagram rendering*/
virtual QList<QString> diagramAttributes() const = 0;

void renderDiagram( const QgsFeature& feature, QgsRenderContext& c, const QPointF& pos );

void setDiagram( QgsDiagram* d );
QgsDiagram* diagram() const { return mDiagram; }

/**Returns list with all diagram settings in the renderer*/
/** Returns list with all diagram settings in the renderer*/
virtual QList<QgsDiagramSettings> diagramSettings() const = 0;

virtual void readXML( const QDomElement& elem, const QgsVectorLayer* layer ) = 0;
Expand All @@ -218,31 +218,31 @@ class CORE_EXPORT QgsDiagramRendererV2
protected:
QgsDiagramRendererV2( const QgsDiagramRendererV2& other );

/**Returns diagram settings for a feature (or false if the diagram for the feature is not to be rendered). Used internally within renderDiagram()
/** Returns diagram settings for a feature (or false if the diagram for the feature is not to be rendered). Used internally within renderDiagram()
* @param feature the feature
* @param c render context
* @param s out: diagram settings for the feature
*/
virtual bool diagramSettings( const QgsFeature &feature, const QgsRenderContext& c, QgsDiagramSettings& s ) = 0;

/**Returns size of the diagram (in painter units) or an invalid size in case of error*/
/** Returns size of the diagram (in painter units) or an invalid size in case of error*/
virtual QSizeF diagramSize( const QgsFeature& features, const QgsRenderContext& c ) = 0;

/**Converts size from mm to map units*/
/** Converts size from mm to map units*/
void convertSizeToMapUnits( QSizeF& size, const QgsRenderContext& context ) const;

/**Returns the paint device dpi (or -1 in case of error*/
/** Returns the paint device dpi (or -1 in case of error*/
static int dpiPaintDevice( const QPainter* );

//read / write diagram
void _readXML( const QDomElement& elem, const QgsVectorLayer* layer );
void _writeXML( QDomElement& rendererElem, QDomDocument& doc, const QgsVectorLayer* layer ) const;

/**Reference to the object that does the real diagram rendering*/
/** Reference to the object that does the real diagram rendering*/
QgsDiagram* mDiagram;
};

/**Renders the diagrams for all features with the same settings*/
/** Renders the diagrams for all features with the same settings*/
class CORE_EXPORT QgsSingleCategoryDiagramRenderer : public QgsDiagramRendererV2
{
public:
Expand Down Expand Up @@ -281,7 +281,7 @@ class CORE_EXPORT QgsLinearlyInterpolatedDiagramRenderer : public QgsDiagramRend

QgsDiagramRendererV2* clone() const override;

/**Returns list with all diagram settings in the renderer*/
/** Returns list with all diagram settings in the renderer*/
QList<QgsDiagramSettings> diagramSettings() const override;

void setDiagramSettings( const QgsDiagramSettings& s ) { mSettings = s; }
Expand Down
4 changes: 2 additions & 2 deletions src/core/qgspallabeling.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3237,7 +3237,7 @@ int QgsPalLabeling::prepareLayer( QgsVectorLayer* layer, QStringList& attrNames,
lyr.displayAll );

if ( lyr.placementFlags )
l->setArrangementFlags( lyr.placementFlags );
l->setArrangementFlags(( LineArrangementFlags )lyr.placementFlags );

// set label mode (label per feature is the default)
l->setLabelMode( lyr.labelPerPart ? Layer::LabelPerFeaturePart : Layer::LabelPerFeature );
Expand Down Expand Up @@ -3324,7 +3324,7 @@ int QgsPalLabeling::addDiagramLayer( QgsVectorLayer* layer, const QgsDiagramLaye
{
double priority = 1 - s->priority / 10.0; // convert 0..10 --> 1..0
Layer* l = mPal->addLayer( layer->id().append( "d" ).toUtf8().data(), pal::Arrangement( s->placement ), priority, s->obstacle, true, true );
l->setArrangementFlags( s->placementFlags );
l->setArrangementFlags(( LineArrangementFlags )s->placementFlags );

mActiveDiagramLayers.insert( layer->id(), *s );
// initialize the local copy
Expand Down

0 comments on commit ea41b92

Please sign in to comment.