QGIS API Documentation  2.18.21-Las Palmas (9fba24a)
qgsconditionalstyle.h
Go to the documentation of this file.
1 #ifndef QGSCONDITIONALSTYLE_H
2 #define QGSCONDITIONALSTYLE_H
3 
4 #include <QFont>
5 #include <QColor>
6 #include <QPixmap>
7 #include <QDomNode>
8 #include <QDomDocument>
9 
10 #include "qgsfeature.h"
11 #include "qgssymbolv2.h"
12 
14 
16 
17 
22 class CORE_EXPORT QgsConditionalLayerStyles
23 {
24  public:
26 
27  QList<QgsConditionalStyle> rowStyles();
28 
35  void setRowStyles( const QList<QgsConditionalStyle>& styles );
36 
42  void setFieldStyles( const QString& fieldName, const QList<QgsConditionalStyle>& styles );
43 
48  QList<QgsConditionalStyle> fieldStyles( const QString& fieldName );
49 
52  bool readXml( const QDomNode& node );
53 
56  bool writeXml( QDomNode & node, QDomDocument & doc ) const;
57 
58  private:
60  QList<QgsConditionalStyle> mRowStyles;
61 };
62 
67 class CORE_EXPORT QgsConditionalStyle
68 {
69  public:
72  QgsConditionalStyle( const QString& rule );
74 
75  QgsConditionalStyle& operator=( const QgsConditionalStyle& other );
76 
83  bool matches( const QVariant& value, QgsExpressionContext& context ) const;
84 
89  QPixmap renderPreview() const;
90 
95  void setName( const QString& value ) { mName = value; mValid = true; }
96 
102  void setRule( const QString& value ) { mRule = value; mValid = true; }
103 
108  void setBackgroundColor( const QColor& value ) { mBackColor = value; mValid = true; }
109 
114  void setTextColor( const QColor& value ) { mTextColor = value; mValid = true; }
115 
120  void setFont( const QFont& value ) { mFont = value; mValid = true; }
121 
126  void setSymbol( QgsSymbolV2* value );
127 
132  QString displayText() const;
133 
138  QString name() const { return mName; }
139 
144  QPixmap icon() const { return mIcon; }
145 
150  QgsSymbolV2* symbol() const { return mSymbol.data(); }
151 
156  QColor textColor() const { return mTextColor; }
157 
163  bool validTextColor() const;
164 
169  QColor backgroundColor() const { return mBackColor; }
170 
176  bool validBackgroundColor() const;
181  QFont font() const { return mFont; }
182 
188  QString rule() const { return mRule; }
189 
195  bool isValid() const { return mValid; }
196 
204  static QList<QgsConditionalStyle> matchingConditionalStyles( const QList<QgsConditionalStyle>& styles, const QVariant& value, QgsExpressionContext& context );
205 
213  static QgsConditionalStyle matchingConditionalStyle( const QList<QgsConditionalStyle>& styles, const QVariant& value, QgsExpressionContext& context );
214 
221  static QgsConditionalStyle compressStyles( const QList<QgsConditionalStyle>& styles );
222 
225  bool readXml( const QDomNode& node );
226 
229  bool writeXml( QDomNode & node, QDomDocument & doc ) const;
230 
231 
232  private:
233 
234  bool mValid;
235  QString mName;
236  QString mRule;
238  QFont mFont;
239  QColor mBackColor;
240  QColor mTextColor;
241  QPixmap mIcon;
242 };
243 
244 #endif // QGSCONDITIONALSTYLE_H
QString name() const
The name of the style.
void setName(const QString &value)
Set the name of the style.
void setRule(const QString &value)
Set the rule for the style.
QPixmap icon() const
The icon set for style generated from the set symbol.
Conditional styling for a rule.
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
bool isValid() const
isValid Check if this rule is valid.
QColor backgroundColor() const
The background color for style.
void setBackgroundColor(const QColor &value)
Set the background color for the style.
void setFont(const QFont &value)
Set the font for the the style.
QColor textColor() const
The text color set for style.
The QgsConditionalLayerStyles class holds conditional style information for a layer.
QgsSymbolV2 * symbol() const
The symbol used to generate the icon for the style.
QFont font() const
The font for the style.
QString rule() const
The condition rule set for the style.
QList< QgsConditionalStyle > QgsConditionalStyles
void setTextColor(const QColor &value)
Set the text color for the style.