QGIS API Documentation  3.0.2-Girona (307d082)
qgsconditionalstyle.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgsconditionalstyle.h
3  ---------------------
4  begin : August 2015
5  copyright : (C) 2015 by Nathan Woodrow
6  email : woodrow dot nathan at gmail dot com
7  ***************************************************************************
8  * *
9  * This program is free software; you can redistribute it and/or modify *
10  * it under the terms of the GNU General Public License as published by *
11  * the Free Software Foundation; either version 2 of the License, or *
12  * (at your option) any later version. *
13  * *
14  ***************************************************************************/
15 #ifndef QGSCONDITIONALSTYLE_H
16 #define QGSCONDITIONALSTYLE_H
17 
18 #include "qgis_core.h"
19 #include <QFont>
20 #include <QColor>
21 #include <QPixmap>
22 #include <QDomNode>
23 #include <QDomDocument>
24 
25 #include "qgssymbol.h"
26 
29 
30 typedef QList<QgsConditionalStyle> QgsConditionalStyles;
31 
32 
38 class CORE_EXPORT QgsConditionalLayerStyles
39 {
40  public:
42 
43  QList<QgsConditionalStyle> rowStyles();
44 
51  void setRowStyles( const QList<QgsConditionalStyle> &styles );
52 
58  void setFieldStyles( const QString &fieldName, const QList<QgsConditionalStyle> &styles );
59 
64  QList<QgsConditionalStyle> fieldStyles( const QString &fieldName );
65 
69  bool readXml( const QDomNode &node, const QgsReadWriteContext &context );
70 
74  bool writeXml( QDomNode &node, QDomDocument &doc, const QgsReadWriteContext &context ) const;
75 
76  private:
77  QHash<QString, QgsConditionalStyles> mFieldStyles;
78  QList<QgsConditionalStyle> mRowStyles;
79 };
80 
86 class CORE_EXPORT QgsConditionalStyle
87 {
88  public:
91  QgsConditionalStyle( const QString &rule );
92 
93  QgsConditionalStyle &operator=( const QgsConditionalStyle &other );
94 
101  bool matches( const QVariant &value, QgsExpressionContext &context ) const;
102 
107  QPixmap renderPreview() const;
108 
113  void setName( const QString &value ) { mName = value; mValid = true; }
114 
120  void setRule( const QString &value ) { mRule = value; mValid = true; }
121 
126  void setBackgroundColor( const QColor &value ) { mBackColor = value; mValid = true; }
127 
132  void setTextColor( const QColor &value ) { mTextColor = value; mValid = true; }
133 
138  void setFont( const QFont &value ) { mFont = value; mValid = true; }
139 
144  void setSymbol( QgsSymbol *value );
145 
150  QString displayText() const;
151 
156  QString name() const { return mName; }
157 
162  QPixmap icon() const { return mIcon; }
163 
168  QgsSymbol *symbol() const { return mSymbol.get(); }
169 
174  QColor textColor() const { return mTextColor; }
175 
181  bool validTextColor() const;
182 
187  QColor backgroundColor() const { return mBackColor; }
188 
194  bool validBackgroundColor() const;
195 
200  QFont font() const { return mFont; }
201 
207  QString rule() const { return mRule; }
208 
214  bool isValid() const { return mValid; }
215 
223  static QList<QgsConditionalStyle> matchingConditionalStyles( const QList<QgsConditionalStyle> &styles, const QVariant &value, QgsExpressionContext &context );
224 
232  static QgsConditionalStyle matchingConditionalStyle( const QList<QgsConditionalStyle> &styles, const QVariant &value, QgsExpressionContext &context );
233 
240  static QgsConditionalStyle compressStyles( const QList<QgsConditionalStyle> &styles );
241 
245  bool readXml( const QDomNode &node, const QgsReadWriteContext &context );
246 
250  bool writeXml( QDomNode &node, QDomDocument &doc, const QgsReadWriteContext &context ) const;
251 
252 
253  private:
254 
255  bool mValid = false;
256  QString mName;
257  QString mRule;
258  std::unique_ptr<QgsSymbol> mSymbol;
259  QFont mFont;
260  QColor mBackColor;
261  QColor mTextColor;
262  QPixmap mIcon;
263 };
264 
265 #endif // QGSCONDITIONALSTYLE_H
The class is used as a container of context for various read/write operations on other objects...
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.
QgsSymbol * 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.