QGIS API Documentation 3.41.0-Master (3440c17df1d)
Loading...
Searching...
No Matches
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
66 void setRowStyles( const QgsConditionalStyles &styles );
67
73 QgsConditionalStyle constraintFailureStyles( QgsFieldConstraints::ConstraintStrength strength );
74
83 void setFieldStyles( const QString &fieldName, const QList<QgsConditionalStyle> &styles );
84
90 QList<QgsConditionalStyle> fieldStyles( const QString &fieldName ) const;
91
97 bool readXml( const QDomNode &node, const QgsReadWriteContext &context );
98
104 bool writeXml( QDomNode &node, QDomDocument &doc, const QgsReadWriteContext &context ) const;
105
110 bool rulesNeedGeometry() const;
111
112 signals:
113
119 void changed();
120
121 private:
122 QHash<QString, QgsConditionalStyles> mFieldStyles;
123 QgsConditionalStyles mRowStyles;
124};
125
131class CORE_EXPORT QgsConditionalStyle
132{
133 public:
136 QgsConditionalStyle( const QString &rule );
138
139 QgsConditionalStyle &operator=( const QgsConditionalStyle &other );
140
147 bool matches( const QVariant &value, QgsExpressionContext &context ) const;
148
156 QPixmap renderPreview( const QSize &size = QSize() ) const;
157
162 void setName( const QString &value ) { mName = value; mValid = true; }
163
169 void setRule( const QString &value ) { mRule = value; mValid = true; }
170
175 void setBackgroundColor( const QColor &value ) { mBackColor = value; mValid = true; }
176
181 void setTextColor( const QColor &value ) { mTextColor = value; mValid = true; }
182
187 void setFont( const QFont &value ) { mFont = value; mValid = true; }
188
193 void setSymbol( QgsSymbol *value );
194
199 QString displayText() const;
200
205 QString name() const { return mName; }
206
211 QPixmap icon() const { return mIcon; }
212
217 QgsSymbol *symbol() const { return mSymbol.get(); }
218
223 QColor textColor() const { return mTextColor; }
224
230 bool validTextColor() const;
231
236 QColor backgroundColor() const { return mBackColor; }
237
243 bool validBackgroundColor() const;
244
249 QFont font() const { return mFont; }
250
256 QString rule() const { return mRule; }
257
263 bool isValid() const { return mValid; }
264
272 static QList<QgsConditionalStyle> matchingConditionalStyles( const QList<QgsConditionalStyle> &styles, const QVariant &value, QgsExpressionContext &context );
273
281 static QgsConditionalStyle matchingConditionalStyle( const QList<QgsConditionalStyle> &styles, const QVariant &value, QgsExpressionContext &context );
282
289 static QgsConditionalStyle compressStyles( const QList<QgsConditionalStyle> &styles );
290
294 bool readXml( const QDomNode &node, const QgsReadWriteContext &context );
295
299 bool writeXml( QDomNode &node, QDomDocument &doc, const QgsReadWriteContext &context ) const;
300
301 bool operator==( const QgsConditionalStyle &other ) const;
302 bool operator!=( const QgsConditionalStyle &other ) const;
303
304#ifdef SIP_RUN
305 SIP_PYOBJECT __repr__();
306 % MethodCode
307 QString str;
308 if ( !sipCpp->name().isEmpty() )
309 str = QStringLiteral( "<QgsConditionalStyle: '%1' (%2)>" ).arg( sipCpp->name(), sipCpp->rule() );
310 else
311 str = QStringLiteral( "<QgsConditionalStyle: %2>" ).arg( sipCpp->rule() );
312 sipRes = PyUnicode_FromString( str.toUtf8().constData() );
313 % End
314#endif
315
316 private:
317
318 bool mValid = false;
319 QString mName;
320 QString mRule;
321 std::unique_ptr<QgsSymbol> mSymbol;
322 QFont mFont;
323 QColor mBackColor;
324 QColor mTextColor;
325 QPixmap mIcon;
326};
327
328#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:231
#define str(x)
Definition qgis.cpp:39
QList< QgsConditionalStyle > QgsConditionalStyles
bool operator==(const QgsFeatureIterator &fi1, const QgsFeatureIterator &fi2)
bool operator!=(const QgsFeatureIterator &fi1, const QgsFeatureIterator &fi2)