QGIS API Documentation 3.43.0-Master (b60ef06885e)
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
44class CORE_EXPORT QgsConditionalLayerStyles : public QObject
45{
46 Q_OBJECT
47
48 public:
49
53 QgsConditionalLayerStyles( QObject *parent = nullptr );
54
60 QgsConditionalStyles rowStyles() const;
61
68 void setRowStyles( const QgsConditionalStyles &styles );
69
75 QgsConditionalStyle constraintFailureStyles( QgsFieldConstraints::ConstraintStrength strength );
76
85 void setFieldStyles( const QString &fieldName, const QList<QgsConditionalStyle> &styles );
86
92 QList<QgsConditionalStyle> fieldStyles( const QString &fieldName ) const;
93
99 bool readXml( const QDomNode &node, const QgsReadWriteContext &context );
100
106 bool writeXml( QDomNode &node, QDomDocument &doc, const QgsReadWriteContext &context ) const;
107
112 bool rulesNeedGeometry() const;
113
114 signals:
115
121 void changed();
122
123 private:
124 QHash<QString, QgsConditionalStyles> mFieldStyles;
125 QgsConditionalStyles mRowStyles;
126};
127
133class CORE_EXPORT QgsConditionalStyle
134{
135 public:
138 QgsConditionalStyle( const QString &rule );
140
141 QgsConditionalStyle &operator=( const QgsConditionalStyle &other );
142
149 bool matches( const QVariant &value, QgsExpressionContext &context ) const;
150
158 QPixmap renderPreview( const QSize &size = QSize() ) const;
159
164 void setName( const QString &value ) { mName = value; mValid = true; }
165
171 void setRule( const QString &value ) { mRule = value; mValid = true; }
172
177 void setBackgroundColor( const QColor &value ) { mBackColor = value; mValid = true; }
178
183 void setTextColor( const QColor &value ) { mTextColor = value; mValid = true; }
184
189 void setFont( const QFont &value ) { mFont = value; mValid = true; }
190
195 void setSymbol( QgsSymbol *value );
196
201 QString displayText() const;
202
207 QString name() const { return mName; }
208
213 QPixmap icon() const { return mIcon; }
214
219 QgsSymbol *symbol() const { return mSymbol.get(); }
220
225 QColor textColor() const { return mTextColor; }
226
232 bool validTextColor() const;
233
238 QColor backgroundColor() const { return mBackColor; }
239
245 bool validBackgroundColor() const;
246
251 QFont font() const { return mFont; }
252
258 QString rule() const { return mRule; }
259
265 bool isValid() const { return mValid; }
266
274 static QList<QgsConditionalStyle> matchingConditionalStyles( const QList<QgsConditionalStyle> &styles, const QVariant &value, QgsExpressionContext &context );
275
283 static QgsConditionalStyle matchingConditionalStyle( const QList<QgsConditionalStyle> &styles, const QVariant &value, QgsExpressionContext &context );
284
291 static QgsConditionalStyle compressStyles( const QList<QgsConditionalStyle> &styles );
292
296 bool readXml( const QDomNode &node, const QgsReadWriteContext &context );
297
301 bool writeXml( QDomNode &node, QDomDocument &doc, const QgsReadWriteContext &context ) const;
302
303 bool operator==( const QgsConditionalStyle &other ) const;
304 bool operator!=( const QgsConditionalStyle &other ) const;
305
306#ifdef SIP_RUN
307 SIP_PYOBJECT __repr__();
308 % MethodCode
309 QString str;
310 if ( !sipCpp->name().isEmpty() )
311 str = QStringLiteral( "<QgsConditionalStyle: '%1' (%2)>" ).arg( sipCpp->name(), sipCpp->rule() );
312 else
313 str = QStringLiteral( "<QgsConditionalStyle: %2>" ).arg( sipCpp->rule() );
314 sipRes = PyUnicode_FromString( str.toUtf8().constData() );
315 % End
316#endif
317
318 private:
319
320 bool mValid = false;
321 QString mName;
322 QString mRule;
323 std::unique_ptr<QgsSymbol> mSymbol;
324 QFont mFont;
325 QColor mBackColor;
326 QColor mTextColor;
327 QPixmap mIcon;
328};
329
330#endif // QGSCONDITIONALSTYLE_H
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.
A container for the context for various read/write operations on objects.
Abstract base class for all rendered symbols.
Definition qgssymbol.h:231
QList< QgsConditionalStyle > QgsConditionalStyles
bool operator==(const QgsFeatureIterator &fi1, const QgsFeatureIterator &fi2)
bool operator!=(const QgsFeatureIterator &fi1, const QgsFeatureIterator &fi2)