QGIS API Documentation  3.6.0-Noosa (5873452)
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"
20 #include "qgsproperty_p.h"
21 #include "qgsexpression.h"
22 #include "qgsexpressioncontext.h"
23 #include "qgscolorramp.h"
24 
25 #include <QVariant>
26 #include <QHash>
27 #include <QString>
28 #include <QStringList>
29 #include <QDomElement>
30 #include <QDomDocument>
31 #include <QColor>
32 
34 
46 class CORE_EXPORT QgsPropertyDefinition
47 {
48  public:
49 
52  {
53  Boolean = 0,
69  Size,
79  Custom = 3000,
80  };
81 
83  enum DataType
84  {
85 
91  DataTypeString = 0,
92 
99 
106  };
107 
111  QgsPropertyDefinition() = default;
112 
121  QgsPropertyDefinition( const QString &name, const QString &description, StandardPropertyTemplate type, const QString &origin = QString(), const QString &comment = QString() );
122 
133  QgsPropertyDefinition( const QString &name, DataType dataType, const QString &description, const QString &helpText, const QString &origin = QString(), const QString &comment = QString() );
134 
138  QString name() const { return mName; }
139 
143  void setName( const QString &name ) { mName = name; }
144 
150  QString origin() const { return mOrigin; }
151 
157  void setOrigin( const QString &origin ) { mOrigin = origin; }
158 
162  QString description() const { return mDescription; }
163 
167  QString comment() const { return mComment; }
168 
172  void setComment( const QString &comment ) { mComment = comment; }
173 
177  QString helpText() const { return mHelpText; }
178 
182  void setDataType( DataType type ) { mTypes = type; }
183 
187  DataType dataType() const { return mTypes; }
188 
193  StandardPropertyTemplate standardTemplate() const { return mStandardType; }
194 
199  bool supportsAssistant() const;
200 
201  private:
202 
203  QString mName;
204  QString mDescription;
205  DataType mTypes = DataTypeString;
206  QString mHelpText;
207  StandardPropertyTemplate mStandardType = Custom;
208  QString mOrigin;
209  QString mComment;
210 
211  static QString trString();
212 };
213 
214 
229 class CORE_EXPORT QgsProperty
230 {
231  public:
232 
234  enum Type
235  {
240  };
241 
245  QgsProperty();
246 
247  virtual ~QgsProperty() = default;
248 
252  static QgsProperty fromExpression( const QString &expression, bool isActive = true );
253 
257  static QgsProperty fromField( const QString &fieldName, bool isActive = true );
258 
262  static QgsProperty fromValue( const QVariant &value, bool isActive = true );
263 
265  QgsProperty( const QgsProperty &other );
266 
267  QgsProperty &operator=( const QgsProperty &other );
268 
272  operator bool() const;
273 
274  bool operator==( const QgsProperty &other ) const;
275  bool operator!=( const QgsProperty &other ) const;
276 
280  Type propertyType() const;
281 
286  bool isActive() const;
287 
292  void setActive( bool active );
293 
299  void setStaticValue( const QVariant &value );
300 
306  QVariant staticValue() const;
307 
313  void setField( const QString &field );
314 
320  QString field() const;
321 
327  void setExpressionString( const QString &expression );
328 
334  QString expressionString() const;
335 
340  QString asExpression() const;
341 
347  bool prepare( const QgsExpressionContext &context = QgsExpressionContext() ) const;
348 
353  QSet< QString > referencedFields( const QgsExpressionContext &context = QgsExpressionContext() ) const;
354 
360  bool isProjectColor() const;
361 
376  QVariant value( const QgsExpressionContext &context, const QVariant &defaultValue = QVariant(), bool *ok SIP_OUT = nullptr ) const;
377 
390  QString valueAsString( const QgsExpressionContext &context, const QString &defaultString = QString(), bool *ok SIP_OUT = nullptr ) const;
391 
404  QColor valueAsColor( const QgsExpressionContext &context, const QColor &defaultColor = QColor(), bool *ok SIP_OUT = nullptr ) const;
405 
418  double valueAsDouble( const QgsExpressionContext &context, double defaultValue = 0.0, bool *ok SIP_OUT = nullptr ) const;
419 
432  int valueAsInt( const QgsExpressionContext &context, int defaultValue = 0, bool *ok SIP_OUT = nullptr ) const;
433 
446  bool valueAsBool( const QgsExpressionContext &context, bool defaultValue = false, bool *ok SIP_OUT = nullptr ) const;
447 
454  QVariant toVariant() const;
455 
462  bool loadVariant( const QVariant &property );
463 
470  void setTransformer( QgsPropertyTransformer *transformer SIP_TRANSFER );
471 
476  const QgsPropertyTransformer *transformer() const;
477 
484  bool convertToTransformer();
485 
487  operator QVariant() const
488  {
489  return QVariant::fromValue( *this );
490  }
491 
492  private:
493 
494  mutable QExplicitlySharedDataPointer<QgsPropertyPrivate> d;
495 
500  QVariant propertyValue( const QgsExpressionContext &context, const QVariant &defaultValue = QVariant(), bool *ok = nullptr ) const;
501 
502 };
503 
505 
506 #endif // QGSPROPERTY_H
Render units (eg mm/pixels/map units)
Definition: qgsproperty.h:63
Field based property (QgsFieldBasedProperty)
Definition: qgsproperty.h:238
Positive integer values (including 0)
Definition: qgsproperty.h:55
1D size (eg marker radius, or square marker height/width)
Definition: qgsproperty.h:69
Expression based property (QgsExpressionBasedProperty)
Definition: qgsproperty.h:239
bool operator==(const QgsFeatureIterator &fi1, const QgsFeatureIterator &fi2)
bool operator!=(const QgsFeatureIterator &fi1, const QgsFeatureIterator &fi2)
Abstract base class for objects which transform the calculated value of a property.
Non-zero positive integer values.
Definition: qgsproperty.h:56
Color with alpha channel.
Definition: qgsproperty.h:64
Positive double value (including 0)
Definition: qgsproperty.h:58
void setName(const QString &name)
Sets the name of the property.
Definition: qgsproperty.h:143
Q_DECLARE_METATYPE(QModelIndex)
Rotation (value between 0-360 degrees)
Definition: qgsproperty.h:60
Any string value.
Definition: qgsproperty.h:61
Type
Property types.
Definition: qgsproperty.h:234
DataType dataType() const
Returns the allowable field/value data type for the property.
Definition: qgsproperty.h:187
Integer value (including negative values)
Definition: qgsproperty.h:54
Property requires a boolean value.
Definition: qgsproperty.h:105
QString description() const
Descriptive name of the property.
Definition: qgsproperty.h:162
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
#define SIP_TRANSFER
Definition: qgis_sip.h:36
Property requires a numeric value.
Definition: qgsproperty.h:98
A store for object properties.
Definition: qgsproperty.h:229
Fill style (eg solid, lines)
Definition: qgsproperty.h:73
Double value (including negative values)
Definition: qgsproperty.h:57
void setDataType(DataType type)
Sets the data type.
Definition: qgsproperty.h:182
Definition for a property.
Definition: qgsproperty.h:46
QString helpText() const
Helper text for using the property, including a description of the valid values for the property...
Definition: qgsproperty.h:177
DataType
Valid data types required by property.
Definition: qgsproperty.h:83
QString comment() const
Returns the comment of the property.
Definition: qgsproperty.h:167
void setOrigin(const QString &origin)
Sets the origin of the property.
Definition: qgsproperty.h:157
#define SIP_OUT
Definition: qgis_sip.h:51
Line style (eg solid/dashed)
Definition: qgsproperty.h:71
void setComment(const QString &comment)
Sets comment of the property.
Definition: qgsproperty.h:172
Horizontal anchor point.
Definition: qgsproperty.h:75
StandardPropertyTemplate
Predefined standard property templates.
Definition: qgsproperty.h:51
Path to an SVG file.
Definition: qgsproperty.h:77
Line cap style (eg round)
Definition: qgsproperty.h:74
QString name() const
Returns the name of the property.
Definition: qgsproperty.h:138
Invalid (not set) property.
Definition: qgsproperty.h:237
QString origin() const
Returns the origin of the property.
Definition: qgsproperty.h:150
StandardPropertyTemplate standardTemplate() const
Returns the property&#39;s standard template, if applicable.
Definition: qgsproperty.h:193
2D size (width/height different)
Definition: qgsproperty.h:70
Color with no alpha channel.
Definition: qgsproperty.h:65
Double value between 0-1 (inclusive)
Definition: qgsproperty.h:59