Skip to content
Permalink
Browse files

[pal] Nicer use of enums, LineArrangementFlags

  • Loading branch information
nyalldawson committed Jul 15, 2015
1 parent fea58eb commit ea41b92be1118a2680970c9eb810b38cb2024510
Showing with 27 additions and 28 deletions.
  1. +1 −1 src/core/pal/feature.cpp
  2. +3 −3 src/core/pal/layer.h
  3. +8 −9 src/core/pal/pal.h
  4. +13 −13 src/core/qgsdiagramrendererv2.h
  5. +2 −2 src/core/qgspallabeling.cpp
@@ -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

@@ -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.
@@ -267,7 +267,7 @@ namespace pal

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

@@ -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 */
@@ -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)*/
@@ -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.
@@ -389,5 +384,9 @@ namespace pal
*/
int getMaxIt();
};

} // end namespace pal

Q_DECLARE_OPERATORS_FOR_FLAGS( pal::LineArrangementFlags )

#endif
@@ -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)
@@ -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:
@@ -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;
@@ -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:
@@ -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; }
@@ -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 );
@@ -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

0 comments on commit ea41b92

Please sign in to comment.
You can’t perform that action at this time.