QGIS API Documentation 3.41.0-Master (af5edcb665c)
Loading...
Searching...
No Matches
qgsproperty.h
Go to the documentation of this file.
1/***************************************************************************
2 qgsproperty.h
3 -------------
4 Date : January 2017
5 Copyright : (C) 2017 by Nyall Dawson
6 Email : nyall dot dawson 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 QGSPROPERTY_H
16#define QGSPROPERTY_H
17
18#include "qgis_core.h"
19#include "qgis_sip.h"
21
22#include <QVariant>
23#include <QHash>
24#include <QString>
25#include <QStringList>
26#include <QDomElement>
27#include <QDomDocument>
28#include <QColor>
29#include <QDateTime>
30
32class QgsPropertyPrivate;
33
44class CORE_EXPORT QgsPropertyDefinition
45{
46 public:
47
80
83 {
84
90 DataTypeString = 0,
91
98
105 };
106
111
120 QgsPropertyDefinition( const QString &name, const QString &description, StandardPropertyTemplate type, const QString &origin = QString(), const QString &comment = QString() );
121
132 QgsPropertyDefinition( const QString &name, DataType dataType, const QString &description, const QString &helpText, const QString &origin = QString(), const QString &comment = QString() );
133
137 QString name() const { return mName; }
138
142 void setName( const QString &name ) { mName = name; }
143
149 QString origin() const { return mOrigin; }
150
156 void setOrigin( const QString &origin ) { mOrigin = origin; }
157
161 QString description() const { return mDescription; }
162
166 QString comment() const { return mComment; }
167
171 void setComment( const QString &comment ) { mComment = comment; }
172
176 QString helpText() const { return mHelpText; }
177
181 void setDataType( DataType type ) { mTypes = type; }
182
186 DataType dataType() const { return mTypes; }
187
192 StandardPropertyTemplate standardTemplate() const { return mStandardType; }
193
198 bool supportsAssistant() const;
199
200 private:
201
202 QString mName;
203 QString mDescription;
204 DataType mTypes = DataTypeString;
205 QString mHelpText;
206 StandardPropertyTemplate mStandardType = Custom;
207 QString mOrigin;
208 QString mComment;
209
210 static QString trString();
211};
212
213
227class CORE_EXPORT QgsProperty
228{
229 public:
230
236 static QVariantMap propertyMapToVariantMap( const QMap<QString, QgsProperty> &propertyMap );
237
244 static QMap<QString, QgsProperty> variantMapToPropertyMap( const QVariantMap &variantMap );
245
249 QgsProperty();
250
252
256 static QgsProperty fromExpression( const QString &expression, bool isActive = true );
257
261 static QgsProperty fromField( const QString &fieldName, bool isActive = true );
262
266 static QgsProperty fromValue( const QVariant &value, bool isActive = true );
267
268 QgsProperty( const QgsProperty &other );
269 QgsProperty &operator=( const QgsProperty &other );
270
274 explicit operator bool() const SIP_SKIP;
275
276 bool operator==( const QgsProperty &other ) const;
277 bool operator!=( const QgsProperty &other ) const;
278
282 Qgis::PropertyType propertyType() const;
283
288 bool isActive() const;
289
304 bool isStaticValueInContext( const QgsExpressionContext &context, QVariant &staticValue SIP_OUT ) const;
305
310 void setActive( bool active );
311
317 void setStaticValue( const QVariant &value );
318
324 QVariant staticValue() const;
325
331 void setField( const QString &field );
332
338 QString field() const;
339
345 void setExpressionString( const QString &expression );
346
352 QString expressionString() const;
353
358 QString asExpression() const;
359
365 bool prepare( const QgsExpressionContext &context = QgsExpressionContext() ) const;
366
374 QSet< QString > referencedFields( const QgsExpressionContext &context = QgsExpressionContext(), bool ignoreContext = false ) const;
375
381 bool isProjectColor() const;
382
397 QVariant value( const QgsExpressionContext &context, const QVariant &defaultValue = QVariant(), bool *ok SIP_OUT = nullptr ) const;
398
413 QDateTime valueAsDateTime( const QgsExpressionContext &context, const QDateTime &defaultDateTime = QDateTime(), bool *ok SIP_OUT = nullptr ) const;
414
428 QString valueAsString( const QgsExpressionContext &context, const QString &defaultString = QString(), bool *ok SIP_OUT = nullptr ) const;
429
443 QColor valueAsColor( const QgsExpressionContext &context, const QColor &defaultColor = QColor(), bool *ok SIP_OUT = nullptr ) const;
444
458 double valueAsDouble( const QgsExpressionContext &context, double defaultValue = 0.0, bool *ok SIP_OUT = nullptr ) const;
459
473 int valueAsInt( const QgsExpressionContext &context, int defaultValue = 0, bool *ok SIP_OUT = nullptr ) const;
474
488 bool valueAsBool( const QgsExpressionContext &context, bool defaultValue = false, bool *ok SIP_OUT = nullptr ) const;
489
496 QVariant toVariant() const;
497
504 bool loadVariant( const QVariant &property );
505
512 void setTransformer( QgsPropertyTransformer *transformer SIP_TRANSFER );
513
518 const QgsPropertyTransformer *transformer() const;
519
526 bool convertToTransformer();
527
529 operator QVariant() const
530 {
531 return QVariant::fromValue( *this );
532 }
533
534
535#ifdef SIP_RUN
536 SIP_PYOBJECT __repr__();
537 % MethodCode
538 QString typeString;
539 QString definitionString;
540 switch ( sipCpp->propertyType() )
541 {
543 typeString = QStringLiteral( "static" );
544 definitionString = sipCpp->staticValue().toString();
545 break;
546
548 typeString = QStringLiteral( "field" );
549 definitionString = sipCpp->field();
550 break;
551
553 typeString = QStringLiteral( "expression" );
554 definitionString = sipCpp->expressionString();
555 break;
556
558 typeString = QStringLiteral( "invalid" );
559 break;
560 }
561
562 QString str = QStringLiteral( "<QgsProperty: %1%2%3>" ).arg( !sipCpp->isActive() && sipCpp->propertyType() != Qgis::PropertyType::Invalid ? QStringLiteral( "INACTIVE " ) : QString(),
563 typeString,
564 definitionString.isEmpty() ? QString() : QStringLiteral( " (%1)" ).arg( definitionString ) );
565 sipRes = PyUnicode_FromString( str.toUtf8().constData() );
566 % End
567#endif
568
569 private:
570
571 mutable QExplicitlySharedDataPointer<QgsPropertyPrivate> d;
572
577 QVariant propertyValue( const QgsExpressionContext &context, const QVariant &defaultValue = QVariant(), bool *ok = nullptr ) const;
578
579};
580
582
583#endif // QGSPROPERTY_H
The Qgis class provides global constants for use throughout the application.
Definition qgis.h:54
@ Invalid
Invalid (not set) property.
@ Field
Field based property.
@ Static
Static property.
@ Expression
Expression based property.
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
Definition for a property.
Definition qgsproperty.h:45
StandardPropertyTemplate standardTemplate() const
Returns the property's standard template, if applicable.
QString helpText() const
Helper text for using the property, including a description of the valid values for the property.
QString comment() const
Returns the comment of the property.
DataType dataType() const
Returns the allowable field/value data type for the property.
void setOrigin(const QString &origin)
Sets the origin of the property.
QString description() const
Descriptive name of the property.
StandardPropertyTemplate
Predefined standard property templates.
Definition qgsproperty.h:50
@ HorizontalAnchor
Horizontal anchor point.
Definition qgsproperty.h:73
@ Double
Double value (including negative values)
Definition qgsproperty.h:55
@ VerticalAnchor
Vertical anchor point.
Definition qgsproperty.h:74
@ Double0To1
Double value between 0-1 (inclusive)
Definition qgsproperty.h:57
@ FillStyle
Fill style (eg solid, lines)
Definition qgsproperty.h:71
@ StrokeWidth
Line stroke width.
Definition qgsproperty.h:70
@ LineStyle
Line style (eg solid/dashed)
Definition qgsproperty.h:69
@ Integer
Integer value (including negative values)
Definition qgsproperty.h:52
@ String
Any string value.
Definition qgsproperty.h:59
@ DateTime
DateTime value.
Definition qgsproperty.h:77
@ BlendMode
Blend mode.
Definition qgsproperty.h:65
@ RenderUnits
Render units (eg mm/pixels/map units)
Definition qgsproperty.h:61
@ PenJoinStyle
Pen join style.
Definition qgsproperty.h:64
@ SvgPath
Path to an SVG file.
Definition qgsproperty.h:75
@ IntegerPositiveGreaterZero
Non-zero positive integer values.
Definition qgsproperty.h:54
@ IntegerPositive
Positive integer values (including 0)
Definition qgsproperty.h:53
@ Opacity
Opacity (0-100)
Definition qgsproperty.h:60
@ CapStyle
Line cap style (eg round)
Definition qgsproperty.h:72
@ ColorNoAlpha
Color with no alpha channel.
Definition qgsproperty.h:63
@ Rotation
Rotation (value between 0-360 degrees)
Definition qgsproperty.h:58
@ Size
1D size (eg marker radius, or square marker height/width)
Definition qgsproperty.h:67
@ ColorWithAlpha
Color with alpha channel.
Definition qgsproperty.h:62
@ DoublePositive
Positive double value (including 0)
Definition qgsproperty.h:56
@ Size2D
2D size (width/height different)
Definition qgsproperty.h:68
QString name() const
Returns the name of the property.
QgsPropertyDefinition()=default
Constructs an empty property.
void setDataType(DataType type)
Sets the data type.
void setName(const QString &name)
Sets the name of the property.
QString origin() const
Returns the origin of the property.
void setComment(const QString &comment)
Sets comment of the property.
DataType
Valid data types required by property.
Definition qgsproperty.h:83
@ DataTypeBoolean
Property requires a boolean value.
@ DataTypeNumeric
Property requires a numeric value.
Definition qgsproperty.h:97
Abstract base class for objects which transform the calculated value of a property.
A store for object properties.
#define SIP_SKIP
Definition qgis_sip.h:126
#define SIP_TRANSFER
Definition qgis_sip.h:36
#define SIP_OUT
Definition qgis_sip.h:58
Q_DECLARE_METATYPE(QgsDatabaseQueryLogEntry)