QGIS API Documentation 3.99.0-Master (2fe06baccd8)
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 <memory>
19
20#include "qgis_core.h"
21#include "qgsfield.h"
22
23#include <QColor>
24#include <QDomDocument>
25#include <QDomNode>
26#include <QFont>
27#include <QHash>
28#include <QObject>
29#include <QPixmap>
30
34class QgsSymbol;
35
36typedef QList<QgsConditionalStyle> QgsConditionalStyles;
37
45class CORE_EXPORT QgsConditionalLayerStyles : public QObject
46{
47 Q_OBJECT
48
49 public:
50
54 QgsConditionalLayerStyles( QObject *parent = nullptr );
55
62
69 void setRowStyles( const QgsConditionalStyles &styles );
70
77
86 void setFieldStyles( const QString &fieldName, const QList<QgsConditionalStyle> &styles );
87
93 QList<QgsConditionalStyle> fieldStyles( const QString &fieldName ) const;
94
100 bool readXml( const QDomNode &node, const QgsReadWriteContext &context );
101
107 bool writeXml( QDomNode &node, QDomDocument &doc, const QgsReadWriteContext &context ) const;
108
113 bool rulesNeedGeometry() const;
114
115 signals:
116
122 void changed();
123
124 private:
125 QHash<QString, QgsConditionalStyles> mFieldStyles;
126 QgsConditionalStyles mRowStyles;
127};
128
134class CORE_EXPORT QgsConditionalStyle
135{
136 public:
140 QgsConditionalStyle( const QString &rule );
142
145
152 bool matches( const QVariant &value, QgsExpressionContext &context ) const;
153
161 QPixmap renderPreview( const QSize &size = QSize() ) const;
162
167 void setName( const QString &value ) { mName = value; mValid = true; }
168
174 void setRule( const QString &value ) { mRule = value; mValid = true; }
175
180 void setBackgroundColor( const QColor &value ) { mBackColor = value; mValid = true; }
181
186 void setTextColor( const QColor &value ) { mTextColor = value; mValid = true; }
187
192 void setFont( const QFont &value ) { mFont = value; mValid = true; }
193
198 void setSymbol( QgsSymbol *value );
199
204 QString displayText() const;
205
210 QString name() const { return mName; }
211
216 QPixmap icon() const { return mIcon; }
217
222 QgsSymbol *symbol() const { return mSymbol.get(); }
223
228 QColor textColor() const { return mTextColor; }
229
235 bool validTextColor() const;
236
241 QColor backgroundColor() const { return mBackColor; }
242
248 bool validBackgroundColor() const;
249
254 QFont font() const { return mFont; }
255
261 QString rule() const { return mRule; }
262
268 bool isValid() const { return mValid; }
269
277 static QList<QgsConditionalStyle> matchingConditionalStyles( const QList<QgsConditionalStyle> &styles, const QVariant &value, QgsExpressionContext &context );
278
286 static QgsConditionalStyle matchingConditionalStyle( const QList<QgsConditionalStyle> &styles, const QVariant &value, QgsExpressionContext &context );
287
294 static QgsConditionalStyle compressStyles( const QList<QgsConditionalStyle> &styles );
295
299 bool readXml( const QDomNode &node, const QgsReadWriteContext &context );
300
304 bool writeXml( QDomNode &node, QDomDocument &doc, const QgsReadWriteContext &context ) const;
305
306 bool operator==( const QgsConditionalStyle &other ) const;
307 bool operator!=( const QgsConditionalStyle &other ) const;
308
309#ifdef SIP_RUN
310 SIP_PYOBJECT __repr__();
311 % MethodCode
312 QString str;
313 if ( !sipCpp->name().isEmpty() )
314 str = QStringLiteral( "<QgsConditionalStyle: '%1' (%2)>" ).arg( sipCpp->name(), sipCpp->rule() );
315 else
316 str = QStringLiteral( "<QgsConditionalStyle: %2>" ).arg( sipCpp->rule() );
317 sipRes = PyUnicode_FromString( str.toUtf8().constData() );
318 % End
319#endif
320
321 private:
322
323 bool mValid = false;
324 QString mName;
325 QString mRule;
326 std::unique_ptr<QgsSymbol> mSymbol;
327 QFont mFont;
328 QColor mBackColor;
329 QColor mTextColor;
330 QPixmap mIcon;
331};
332
333#endif // QGSCONDITIONALSTYLE_H
void changed()
Emitted when the conditional styles are changed.
bool readXml(const QDomNode &node, const QgsReadWriteContext &context)
Reads the condition styles state from a DOM node.
QgsConditionalStyles rowStyles() const
Returns a list of row styles associated with the layer.
QgsConditionalLayerStyles(QObject *parent=nullptr)
Constructor for QgsConditionalLayerStyles, with the specified parent object.
QgsConditionalStyle constraintFailureStyles(QgsFieldConstraints::ConstraintStrength strength)
Returns a style associated to a constraint failure.
bool writeXml(QDomNode &node, QDomDocument &doc, const QgsReadWriteContext &context) const
Writes the condition styles state to a DOM node.
QList< QgsConditionalStyle > fieldStyles(const QString &fieldName) const
Returns the conditional styles set for the field with matching fieldName.
bool rulesNeedGeometry() const
Returns true if at least one rule needs geometry.
void setFieldStyles(const QString &fieldName, const QList< QgsConditionalStyle > &styles)
Set the conditional styles for a field, with the specified fieldName.
void setRowStyles(const QgsConditionalStyles &styles)
Sets the conditional styles that apply to full rows of data in the attribute table.
Conditional styling for a rule.
QString name() const
The name of the style.
void setName(const QString &value)
Set the name of the style.
QPixmap renderPreview(const QSize &size=QSize()) const
Render a preview icon of the rule, at the specified size.
bool matches(const QVariant &value, QgsExpressionContext &context) const
Check if the rule matches using the given value and feature.
QgsConditionalStyle & operator=(const QgsConditionalStyle &other)
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
#define SIP_SKIP
Definition qgis_sip.h:134
QList< QgsConditionalStyle > QgsConditionalStyles
bool operator==(const QgsFeatureIterator &fi1, const QgsFeatureIterator &fi2)
bool operator!=(const QgsFeatureIterator &fi1, const QgsFeatureIterator &fi2)