QGIS API Documentation 3.30.0-'s-Hertogenbosch (f186b8efe0)
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 "qgsfield.h"
20
21#include <QObject>
22#include <QFont>
23#include <QColor>
24#include <QPixmap>
25#include <QDomNode>
26#include <QDomDocument>
27#include <QHash>
28#include <memory>
29
33class QgsSymbol;
34
35typedef QList<QgsConditionalStyle> QgsConditionalStyles;
36
42class CORE_EXPORT QgsConditionalLayerStyles : public QObject
43{
44 Q_OBJECT
45
46 public:
47
51 QgsConditionalLayerStyles( QObject *parent = nullptr );
52
58 QgsConditionalStyles rowStyles() const;
59
67 void setRowStyles( const QgsConditionalStyles &styles );
68
74 QgsConditionalStyle constraintFailureStyles( QgsFieldConstraints::ConstraintStrength strength );
75
84 void setFieldStyles( const QString &fieldName, const QList<QgsConditionalStyle> &styles );
85
91 QList<QgsConditionalStyle> fieldStyles( const QString &fieldName ) const;
92
98 bool readXml( const QDomNode &node, const QgsReadWriteContext &context );
99
105 bool writeXml( QDomNode &node, QDomDocument &doc, const QgsReadWriteContext &context ) const;
106
111 bool rulesNeedGeometry() const;
112
113 signals:
114
120 void changed();
121
122 private:
123 QHash<QString, QgsConditionalStyles> mFieldStyles;
124 QgsConditionalStyles mRowStyles;
125};
126
132class CORE_EXPORT QgsConditionalStyle
133{
134 public:
137 QgsConditionalStyle( const QString &rule );
139
140 QgsConditionalStyle &operator=( const QgsConditionalStyle &other );
141
148 bool matches( const QVariant &value, QgsExpressionContext &context ) const;
149
157 QPixmap renderPreview( const QSize &size = QSize() ) const;
158
163 void setName( const QString &value ) { mName = value; mValid = true; }
164
170 void setRule( const QString &value ) { mRule = value; mValid = true; }
171
176 void setBackgroundColor( const QColor &value ) { mBackColor = value; mValid = true; }
177
182 void setTextColor( const QColor &value ) { mTextColor = value; mValid = true; }
183
188 void setFont( const QFont &value ) { mFont = value; mValid = true; }
189
194 void setSymbol( QgsSymbol *value );
195
200 QString displayText() const;
201
206 QString name() const { return mName; }
207
212 QPixmap icon() const { return mIcon; }
213
218 QgsSymbol *symbol() const { return mSymbol.get(); }
219
224 QColor textColor() const { return mTextColor; }
225
231 bool validTextColor() const;
232
237 QColor backgroundColor() const { return mBackColor; }
238
244 bool validBackgroundColor() const;
245
250 QFont font() const { return mFont; }
251
257 QString rule() const { return mRule; }
258
264 bool isValid() const { return mValid; }
265
273 static QList<QgsConditionalStyle> matchingConditionalStyles( const QList<QgsConditionalStyle> &styles, const QVariant &value, QgsExpressionContext &context );
274
282 static QgsConditionalStyle matchingConditionalStyle( const QList<QgsConditionalStyle> &styles, const QVariant &value, QgsExpressionContext &context );
283
290 static QgsConditionalStyle compressStyles( const QList<QgsConditionalStyle> &styles );
291
295 bool readXml( const QDomNode &node, const QgsReadWriteContext &context );
296
300 bool writeXml( QDomNode &node, QDomDocument &doc, const QgsReadWriteContext &context ) const;
301
302 bool operator==( const QgsConditionalStyle &other ) const;
303 bool operator!=( const QgsConditionalStyle &other ) const;
304
305#ifdef SIP_RUN
306 SIP_PYOBJECT __repr__();
307 % MethodCode
308 QString str;
309 if ( !sipCpp->name().isEmpty() )
310 str = QStringLiteral( "<QgsConditionalStyle: '%1' (%2)>" ).arg( sipCpp->name(), sipCpp->rule() );
311 else
312 str = QStringLiteral( "<QgsConditionalStyle: %2>" ).arg( sipCpp->rule() );
313 sipRes = PyUnicode_FromString( str.toUtf8().constData() );
314 % End
315#endif
316
317 private:
318
319 bool mValid = false;
320 QString mName;
321 QString mRule;
322 std::unique_ptr<QgsSymbol> mSymbol;
323 QFont mFont;
324 QColor mBackColor;
325 QColor mTextColor;
326 QPixmap mIcon;
327};
328
329#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...
ConstraintStrength
Strength of constraints.
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)