QGIS API Documentation 3.29.0-Master (8c80f25a4f)
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 <QObject>
20#include <QFont>
21#include <QColor>
22#include <QPixmap>
23#include <QDomNode>
24#include <QDomDocument>
25#include <QHash>
26#include <memory>
27
31class QgsSymbol;
32
33typedef QList<QgsConditionalStyle> QgsConditionalStyles;
34
35
41class CORE_EXPORT QgsConditionalLayerStyles : public QObject
42{
43 Q_OBJECT
44
45 public:
46
50 QgsConditionalLayerStyles( QObject *parent = nullptr );
51
57 QgsConditionalStyles rowStyles() const;
58
66 void setRowStyles( const QgsConditionalStyles &styles );
67
73 void setFieldStyles( const QString &fieldName, const QList<QgsConditionalStyle> &styles );
74
80 QList<QgsConditionalStyle> fieldStyles( const QString &fieldName ) const;
81
87 bool readXml( const QDomNode &node, const QgsReadWriteContext &context );
88
94 bool writeXml( QDomNode &node, QDomDocument &doc, const QgsReadWriteContext &context ) const;
95
100 bool rulesNeedGeometry() const;
101
102 signals:
103
109 void changed();
110
111 private:
112 QHash<QString, QgsConditionalStyles> mFieldStyles;
113 QgsConditionalStyles mRowStyles;
114};
115
121class CORE_EXPORT QgsConditionalStyle
122{
123 public:
126 QgsConditionalStyle( const QString &rule );
128
129 QgsConditionalStyle &operator=( const QgsConditionalStyle &other );
130
137 bool matches( const QVariant &value, QgsExpressionContext &context ) const;
138
146 QPixmap renderPreview( const QSize &size = QSize() ) const;
147
152 void setName( const QString &value ) { mName = value; mValid = true; }
153
159 void setRule( const QString &value ) { mRule = value; mValid = true; }
160
165 void setBackgroundColor( const QColor &value ) { mBackColor = value; mValid = true; }
166
171 void setTextColor( const QColor &value ) { mTextColor = value; mValid = true; }
172
177 void setFont( const QFont &value ) { mFont = value; mValid = true; }
178
183 void setSymbol( QgsSymbol *value );
184
189 QString displayText() const;
190
195 QString name() const { return mName; }
196
201 QPixmap icon() const { return mIcon; }
202
207 QgsSymbol *symbol() const { return mSymbol.get(); }
208
213 QColor textColor() const { return mTextColor; }
214
220 bool validTextColor() const;
221
226 QColor backgroundColor() const { return mBackColor; }
227
233 bool validBackgroundColor() const;
234
239 QFont font() const { return mFont; }
240
246 QString rule() const { return mRule; }
247
253 bool isValid() const { return mValid; }
254
262 static QList<QgsConditionalStyle> matchingConditionalStyles( const QList<QgsConditionalStyle> &styles, const QVariant &value, QgsExpressionContext &context );
263
271 static QgsConditionalStyle matchingConditionalStyle( const QList<QgsConditionalStyle> &styles, const QVariant &value, QgsExpressionContext &context );
272
279 static QgsConditionalStyle compressStyles( const QList<QgsConditionalStyle> &styles );
280
284 bool readXml( const QDomNode &node, const QgsReadWriteContext &context );
285
289 bool writeXml( QDomNode &node, QDomDocument &doc, const QgsReadWriteContext &context ) const;
290
291 bool operator==( const QgsConditionalStyle &other ) const;
292 bool operator!=( const QgsConditionalStyle &other ) const;
293
294#ifdef SIP_RUN
295 SIP_PYOBJECT __repr__();
296 % MethodCode
297 QString str;
298 if ( !sipCpp->name().isEmpty() )
299 str = QStringLiteral( "<QgsConditionalStyle: '%1' (%2)>" ).arg( sipCpp->name(), sipCpp->rule() );
300 else
301 str = QStringLiteral( "<QgsConditionalStyle: %2>" ).arg( sipCpp->rule() );
302 sipRes = PyUnicode_FromString( str.toUtf8().constData() );
303 % End
304#endif
305
306 private:
307
308 bool mValid = false;
309 QString mName;
310 QString mRule;
311 std::unique_ptr<QgsSymbol> mSymbol;
312 QFont mFont;
313 QColor mBackColor;
314 QColor mTextColor;
315 QPixmap mIcon;
316};
317
318#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)