/
qgsconditionalstyle.h
133 lines (111 loc) · 3.86 KB
/
qgsconditionalstyle.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
#ifndef QGSCONDITIONALSTYLE_H
#define QGSCONDITIONALSTYLE_H
#include <QFont>
#include <QColor>
#include <QPixmap>
#include <QDomNode>
#include <QDomDocument>
#include "qgsfeature.h"
#include "qgssymbolv2.h"
/** \class QgsFieldFormat
* Conditional styling for a rule.
*/
class CORE_EXPORT QgsConditionalStyle
{
public:
QgsConditionalStyle();
QgsConditionalStyle( const QgsConditionalStyle& other );
QgsConditionalStyle( QString rule );
~QgsConditionalStyle();
QgsConditionalStyle& operator=( const QgsConditionalStyle& other );
/**
* @brief Check if the rule matches using the given value and feature
* @param value The current value being checked. The "value" variable from the context is replaced with this value.
* @param context Expression context for evaluating rule expression
* @return True of the rule matches against the given feature
*/
bool matches( QVariant value, QgsExpressionContext& context ) const;
/**
* @brief Render a preview icon of the rule.
* @return QPixmap preview of the style
*/
QPixmap renderPreview();
/**
* @brief Set the rule for the style. Rules should be of QgsExpression syntax.
* Special value of \@value is replaced at run time with the check value
* @param value The QgsExpression style rule to use for this style
*/
void setRule( QString value ) { mRule = value; mValid = true; }
/**
* @brief Set the background color for the style
* @param value QColor for background color
*/
void setBackgroundColor( QColor value ) { mBackColor = value; mValid = true; }
/**
* @brief Set the text color for the style
* @param value QColor for text color
*/
void setTextColor( QColor value ) { mTextColor = value; mValid = true; }
/**
* @brief Set the font for the the style
* @param value QFont to be used for text
*/
void setFont( QFont value ) { mFont = value; mValid = true; }
/**
* @brief Set the icon for the style. Icons are generated from symbols
* @param value QgsSymbolV2 to be used when generating the icon
*/
void setSymbol( QgsSymbolV2* value );
/**
* @brief The icon set for style generated from the set symbol
* @return A QPixmap that was set for the icon using the symbol
*/
QPixmap icon() const { return mIcon; }
/**
* @brief The symbol used to generate the icon for the style
* @return The QgsSymbolV2 used for the icon
*/
QgsSymbolV2* symbol() const { return mSymbol.data(); }
/**
* @brief The text color set for style
* @return QColor for text color
*/
QColor textColor() const { return mTextColor; }
/**
* @brief The background color for style
* @return QColor for background color
*/
QColor backgroundColor() const { return mBackColor; }
/**
* @brief The font for the style
* @return QFont for the style
*/
QFont font() const { return mFont; }
/**
* @brief The condition rule set for the style. Rule may contain variable \@value
* to represent the current value
* @return QString of the current set rule
*/
QString rule() const { return mRule; }
/**
* @brief isValid Check if this rule is valid. A valid rule has one or more properties
* set.
* @return True if the rule is valid.
*/
bool isValid() const { return mValid; }
/** Reads vector conditional style specific state from layer Dom node.
*/
virtual bool readXml( const QDomNode& node );
/** Write vector conditional style specific state from layer Dom node.
*/
virtual bool writeXml( QDomNode & node, QDomDocument & doc );
private:
bool mValid;
QString mRule;
QScopedPointer<QgsSymbolV2> mSymbol;
QFont mFont;
QColor mBackColor;
QColor mTextColor;
QPixmap mIcon;
};
#endif // QGSCONDITIONALSTYLE_H