QGIS API Documentation 3.27.0-Master (f261cc1f8b)
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#include <QHash>
25#include <memory>
26
30class QgsSymbol;
31
32typedef QList<QgsConditionalStyle> QgsConditionalStyles;
33
34
40class CORE_EXPORT QgsConditionalLayerStyles : public QObject
41{
42 Q_OBJECT
43
44 public:
45
49 QgsConditionalLayerStyles( QObject *parent = nullptr );
50
56 QgsConditionalStyles rowStyles() const;
57
65 void setRowStyles( const QgsConditionalStyles &styles );
66
72 void setFieldStyles( const QString &fieldName, const QList<QgsConditionalStyle> &styles );
73
79 QList<QgsConditionalStyle> fieldStyles( const QString &fieldName ) const;
80
86 bool readXml( const QDomNode &node, const QgsReadWriteContext &context );
87
93 bool writeXml( QDomNode &node, QDomDocument &doc, const QgsReadWriteContext &context ) const;
94
95 signals:
96
102 void changed();
103
104 private:
105 QHash<QString, QgsConditionalStyles> mFieldStyles;
106 QgsConditionalStyles mRowStyles;
107};
108
114class CORE_EXPORT QgsConditionalStyle
115{
116 public:
119 QgsConditionalStyle( const QString &rule );
121
122 QgsConditionalStyle &operator=( const QgsConditionalStyle &other );
123
130 bool matches( const QVariant &value, QgsExpressionContext &context ) const;
131
139 QPixmap renderPreview( const QSize &size = QSize() ) const;
140
145 void setName( const QString &value ) { mName = value; mValid = true; }
146
152 void setRule( const QString &value ) { mRule = value; mValid = true; }
153
158 void setBackgroundColor( const QColor &value ) { mBackColor = value; mValid = true; }
159
164 void setTextColor( const QColor &value ) { mTextColor = value; mValid = true; }
165
170 void setFont( const QFont &value ) { mFont = value; mValid = true; }
171
176 void setSymbol( QgsSymbol *value );
177
182 QString displayText() const;
183
188 QString name() const { return mName; }
189
194 QPixmap icon() const { return mIcon; }
195
200 QgsSymbol *symbol() const { return mSymbol.get(); }
201
206 QColor textColor() const { return mTextColor; }
207
213 bool validTextColor() const;
214
219 QColor backgroundColor() const { return mBackColor; }
220
226 bool validBackgroundColor() const;
227
232 QFont font() const { return mFont; }
233
239 QString rule() const { return mRule; }
240
246 bool isValid() const { return mValid; }
247
255 static QList<QgsConditionalStyle> matchingConditionalStyles( const QList<QgsConditionalStyle> &styles, const QVariant &value, QgsExpressionContext &context );
256
264 static QgsConditionalStyle matchingConditionalStyle( const QList<QgsConditionalStyle> &styles, const QVariant &value, QgsExpressionContext &context );
265
272 static QgsConditionalStyle compressStyles( const QList<QgsConditionalStyle> &styles );
273
277 bool readXml( const QDomNode &node, const QgsReadWriteContext &context );
278
282 bool writeXml( QDomNode &node, QDomDocument &doc, const QgsReadWriteContext &context ) const;
283
284 bool operator==( const QgsConditionalStyle &other ) const;
285 bool operator!=( const QgsConditionalStyle &other ) const;
286
287#ifdef SIP_RUN
288 SIP_PYOBJECT __repr__();
289 % MethodCode
290 QString str;
291 if ( !sipCpp->name().isEmpty() )
292 str = QStringLiteral( "<QgsConditionalStyle: '%1' (%2)>" ).arg( sipCpp->name(), sipCpp->rule() );
293 else
294 str = QStringLiteral( "<QgsConditionalStyle: %2>" ).arg( sipCpp->rule() );
295 sipRes = PyUnicode_FromString( str.toUtf8().constData() );
296 % End
297#endif
298
299 private:
300
301 bool mValid = false;
302 QString mName;
303 QString mRule;
304 std::unique_ptr<QgsSymbol> mSymbol;
305 QFont mFont;
306 QColor mBackColor;
307 QColor mTextColor;
308 QPixmap mIcon;
309};
310
311#endif // QGSCONDITIONALSTYLE_H
The QgsConditionalLayerStyles class holds conditional style information for a layer.
void changed()
Emitted when the conditional styles are changed.
Conditional styling for a rule.
QString name() const
The name of the style.
void setName(const QString &value)
Set the name of the style.
void setTextColor(const QColor &value)
Set the text color for the style.
void setRule(const QString &value)
Set the rule for the style.
void setBackgroundColor(const QColor &value)
Set the background color for the style.
void setFont(const QFont &value)
Set the font for the style.
QColor backgroundColor() const
The background color for style.
QColor textColor() const
The text color set for style.
QString rule() const
The condition rule set for the style.
QFont font() const
The font for the style.
QgsSymbol * symbol() const
The symbol used to generate the icon for the style.
bool isValid() const
isValid Check if this rule is valid.
QPixmap icon() const
The icon set for style generated from the set symbol.
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
The class is used as a container of context for various read/write operations on other objects.
Abstract base class for all rendered symbols.
Definition: qgssymbol.h:93
#define str(x)
Definition: qgis.cpp:37
QList< QgsConditionalStyle > QgsConditionalStyles
bool operator==(const QgsFeatureIterator &fi1, const QgsFeatureIterator &fi2)
bool operator!=(const QgsFeatureIterator &fi1, const QgsFeatureIterator &fi2)