QGIS API Documentation  3.26.3-Buenos Aires (65e4edfdad)
qgsfielddomain.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgsfielddomain.h
3  ------------------
4  Date : January 2022
5  Copyright : (C) 2022 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 
16 #ifndef QGSFIELDDOMAIN_H
17 #define QGSFIELDDOMAIN_H
18 
19 #include "qgis_core.h"
20 #include "qgis_sip.h"
21 #include "qgis.h"
22 
33 class CORE_EXPORT QgsFieldDomain
34 {
35 
36 #ifdef SIP_RUN
38  if ( sipCpp->type() == Qgis::FieldDomainType::Coded )
39  {
40  sipType = sipType_QgsCodedFieldDomain;
41  }
42  else if ( sipCpp->type() == Qgis::FieldDomainType::Range )
43  {
44  sipType = sipType_QgsRangeFieldDomain;
45  }
46  else if ( sipCpp->type() == Qgis::FieldDomainType::Glob )
47  {
48  sipType = sipType_QgsGlobFieldDomain;
49  }
50  else
51  {
52  sipType = 0;
53  }
54  SIP_END
55 #endif
56 
57  public:
58 
62  QgsFieldDomain( const QString &name,
63  const QString &description,
64  QVariant::Type fieldType );
65 
66  virtual ~QgsFieldDomain();
67 
71  virtual QgsFieldDomain *clone() const = 0 SIP_FACTORY;
72 
76  virtual Qgis::FieldDomainType type() const = 0;
77 
81  virtual QString typeName() const = 0;
82 
88  QString name() const { return mName; }
89 
95  void setName( const QString &name ) { mName = name; }
96 
102  QString description() const { return mDescription; }
103 
109  void setDescription( const QString &description ) { mDescription = description; }
110 
116  QVariant::Type fieldType() const { return mFieldType; }
117 
123  void setFieldType( QVariant::Type type ) { mFieldType = type; }
124 
130  Qgis::FieldDomainSplitPolicy splitPolicy() const { return mSplitPolicy; }
131 
137  void setSplitPolicy( Qgis::FieldDomainSplitPolicy policy ) { mSplitPolicy = policy; }
138 
144  Qgis::FieldDomainMergePolicy mergePolicy() const { return mMergePolicy; }
145 
151  void setMergePolicy( Qgis::FieldDomainMergePolicy policy ) { mMergePolicy = policy; }
152 
153  protected:
154 
155  QString mName;
156  QString mDescription;
157 
158  QVariant::Type mFieldType = QVariant::Type::String;
161 
162 };
163 
170 class CORE_EXPORT QgsCodedValue
171 {
172  public:
173 
180  QgsCodedValue( const QVariant &code, const QString &value )
181  : mCode( code )
182  , mValue( value )
183  {}
184 
189  QVariant code() const { return mCode; }
190 
195  QString value() const { return mValue; }
196 
197 #ifdef SIP_RUN
198  SIP_PYOBJECT __repr__();
199  % MethodCode
200  QString str = QStringLiteral( "<QgsCodedValue: %1 (%2)>" ).arg( sipCpp->code().toString(), sipCpp->value() );
201  sipRes = PyUnicode_FromString( str.toUtf8().constData() );
202  % End
203 #endif
204 
205  bool operator==( const QgsCodedValue &other ) const;
206  bool operator!=( const QgsCodedValue &other ) const;
207 
208  private:
209 
210  QVariant mCode;
211  QString mValue;
212 };
213 
214 
225 class CORE_EXPORT QgsCodedFieldDomain : public QgsFieldDomain
226 {
227 
228  public:
229 
236  QgsCodedFieldDomain( const QString &name,
237  const QString &description,
238  QVariant::Type fieldType,
239  const QList<QgsCodedValue> &values );
240 
241 #ifndef SIP_RUN
242  QgsCodedFieldDomain( const QgsCodedFieldDomain & ) = delete;
245  QgsCodedFieldDomain &operator= ( const QgsCodedFieldDomain & ) = delete;
246 #endif
247 
248  Qgis::FieldDomainType type() const override;
249  QString typeName() const override;
250  QgsCodedFieldDomain *clone() const override SIP_FACTORY;
251 
257  QList< QgsCodedValue> values() const { return mValues; }
258 
264  void setValues( const QList< QgsCodedValue> &values ) { mValues = values; }
265 
266 #ifdef SIP_RUN
267  SIP_PYOBJECT __repr__();
268  % MethodCode
269  QString str = QStringLiteral( "<QgsCodedFieldDomain: %1>" ).arg( sipCpp->name() );
270  sipRes = PyUnicode_FromString( str.toUtf8().constData() );
271  % End
272 #endif
273 
274  private:
275  QList< QgsCodedValue> mValues;
276 
277 #ifdef SIP_RUN
279 #endif
280 };
281 
282 
289 class CORE_EXPORT QgsRangeFieldDomain : public QgsFieldDomain
290 {
291 
292  public:
293 
299  QgsRangeFieldDomain( const QString &name,
300  const QString &description,
301  QVariant::Type fieldType,
302  const QVariant &minimum,
303  bool minimumIsInclusive,
304  const QVariant &maximum,
305  bool maximumIsInclusive );
306 
307 #ifndef SIP_RUN
308  QgsRangeFieldDomain( const QgsRangeFieldDomain & ) = delete;
311  QgsRangeFieldDomain &operator= ( const QgsRangeFieldDomain & ) = delete;
312 #endif
313 
314  Qgis::FieldDomainType type() const override;
315  QString typeName() const override;
316  QgsRangeFieldDomain *clone() const override SIP_FACTORY;
317 
326  QVariant minimum() const { return mMin; }
327 
336  void setMinimum( const QVariant &minimum ) { mMin = minimum; }
337 
344  bool minimumIsInclusive() const { return mMinIsInclusive; }
345 
352  void setMinimumIsInclusive( bool inclusive ) { mMinIsInclusive = inclusive; }
353 
362  QVariant maximum() const { return mMax; }
363 
372  void setMaximum( const QVariant &maximum ) { mMax = maximum; }
373 
380  bool maximumIsInclusive() const { return mMaxIsInclusive; }
381 
388  void setMaximumIsInclusive( bool inclusive ) { mMaxIsInclusive = inclusive; }
389 
390 #ifdef SIP_RUN
391  SIP_PYOBJECT __repr__();
392  % MethodCode
393  QString str = QStringLiteral( "<QgsRangeFieldDomain: %1 %2%3, %4%5>" ).arg( sipCpp->name(),
394  sipCpp->minimumIsInclusive() ? QStringLiteral( "[" ) : QStringLiteral( "(" ),
395  sipCpp->minimum().toString(),
396  sipCpp->maximum().toString(),
397  sipCpp->maximumIsInclusive() ? QStringLiteral( "]" ) : QStringLiteral( ")" ) );
398  sipRes = PyUnicode_FromString( str.toUtf8().constData() );
399  % End
400 #endif
401 
402  private:
403  QVariant mMin;
404  QVariant mMax;
405  bool mMinIsInclusive = false;
406  bool mMaxIsInclusive = false;
407 
408 #ifdef SIP_RUN
410 #endif
411 };
412 
413 
422 class CORE_EXPORT QgsGlobFieldDomain : public QgsFieldDomain
423 {
424 
425  public:
426 
432  QgsGlobFieldDomain( const QString &name,
433  const QString &description,
434  QVariant::Type fieldType,
435  const QString &glob );
436 
437 #ifndef SIP_RUN
438  QgsGlobFieldDomain( const QgsGlobFieldDomain & ) = delete;
441  QgsGlobFieldDomain &operator= ( const QgsGlobFieldDomain & ) = delete;
442 #endif
443 
444  Qgis::FieldDomainType type() const override;
445  QString typeName() const override;
446  QgsGlobFieldDomain *clone() const override SIP_FACTORY;
447 
455  QString glob() const { return mGlob; }
456 
464  void setGlob( const QString &glob ) { mGlob = glob; }
465 
466 #ifdef SIP_RUN
467  SIP_PYOBJECT __repr__();
468  % MethodCode
469  QString str = QStringLiteral( "<QgsGlobFieldDomain: %1 '%2'>" ).arg( sipCpp->name(), sipCpp->glob() );
470  sipRes = PyUnicode_FromString( str.toUtf8().constData() );
471  % End
472 #endif
473 
474  private:
475  QString mGlob;
476 
477 #ifdef SIP_RUN
479 #endif
480 
481 };
482 
483 #endif // QGSFIELDDOMAIN_H
QgsFieldDomain::setName
void setName(const QString &name)
Sets the name of the field domain.
Definition: qgsfielddomain.h:95
operator==
bool operator==(const QgsFeatureIterator &fi1, const QgsFeatureIterator &fi2)
Definition: qgsfeatureiterator.h:425
Qgis::FieldDomainType::Glob
@ Glob
Glob string pattern field domain.
QgsFieldDomain::name
QString name() const
Returns the name of the field domain.
Definition: qgsfielddomain.h:88
QgsRangeFieldDomain::setMaximumIsInclusive
void setMaximumIsInclusive(bool inclusive)
Sets whether the maximum value is inclusive.
Definition: qgsfielddomain.h:388
QgsCodedValue::QgsCodedValue
QgsCodedValue(const QVariant &code, const QString &value)
Constructor for QgsCodedValue, with the associated code and value.
Definition: qgsfielddomain.h:180
QgsFieldDomain::setDescription
void setDescription(const QString &description)
Sets the description of the field domain.
Definition: qgsfielddomain.h:109
qgis.h
QgsFieldDomain::typeName
virtual QString typeName() const =0
Returns a translated name of the field domain type.
QgsGlobFieldDomain::setGlob
void setGlob(const QString &glob)
Sets the glob expression.
Definition: qgsfielddomain.h:464
Qgis::FieldDomainType
FieldDomainType
Types of field domain.
Definition: qgis.h:1731
QgsRangeFieldDomain::maximumIsInclusive
bool maximumIsInclusive() const
Returns true if the maximum value is inclusive.
Definition: qgsfielddomain.h:380
QgsCodedFieldDomain::setValues
void setValues(const QList< QgsCodedValue > &values)
Sets the enumeration as QgsCodedValue values.
Definition: qgsfielddomain.h:264
QgsRangeFieldDomain::setMinimumIsInclusive
void setMinimumIsInclusive(bool inclusive)
Sets whether the minimum value is inclusive.
Definition: qgsfielddomain.h:352
operator!=
bool operator!=(const QgsFeatureIterator &fi1, const QgsFeatureIterator &fi2)
Definition: qgsfeatureiterator.h:430
QgsCodedFieldDomain
Definition of a coded / enumerated field domain.
Definition: qgsfielddomain.h:225
SIP_FACTORY
#define SIP_FACTORY
Definition: qgis_sip.h:76
QgsFieldDomain::setFieldType
void setFieldType(QVariant::Type type)
Sets the associated field type.
Definition: qgsfielddomain.h:123
SIP_CONVERT_TO_SUBCLASS_CODE
#define SIP_CONVERT_TO_SUBCLASS_CODE(code)
Definition: qgis_sip.h:186
QgsFieldDomain::setMergePolicy
void setMergePolicy(Qgis::FieldDomainMergePolicy policy)
Sets the merge policy.
Definition: qgsfielddomain.h:151
QgsFieldDomain::fieldType
QVariant::Type fieldType() const
Returns the associated field type.
Definition: qgsfielddomain.h:116
Qgis::FieldDomainSplitPolicy
FieldDomainSplitPolicy
Split policy for field domains.
Definition: qgis.h:1702
QgsGlobFieldDomain
Definition of a field domain for field content validated by a glob.
Definition: qgsfielddomain.h:422
QgsGlobFieldDomain::glob
QString glob() const
Returns the glob expression.
Definition: qgsfielddomain.h:455
QgsRangeFieldDomain::setMinimum
void setMinimum(const QVariant &minimum)
Sets the minimum allowed value.
Definition: qgsfielddomain.h:336
qgis_sip.h
Qgis::FieldDomainMergePolicy::DefaultValue
@ DefaultValue
Use default field value.
typeName
const QString & typeName
Definition: qgswfsgetfeature.cpp:109
Qgis::FieldDomainMergePolicy
FieldDomainMergePolicy
Merge policy for field domains.
Definition: qgis.h:1718
QgsFieldDomain::clone
virtual QgsFieldDomain * clone() const =0
Clones the field domain.
QgsFieldDomain::mergePolicy
Qgis::FieldDomainMergePolicy mergePolicy() const
Returns the merge policy.
Definition: qgsfielddomain.h:144
QgsRangeFieldDomain::minimumIsInclusive
bool minimumIsInclusive() const
Returns true if the minimum value is inclusive.
Definition: qgsfielddomain.h:344
QgsFieldDomain::type
virtual Qgis::FieldDomainType type() const =0
Returns the type of field domain.
Qgis::FieldDomainType::Range
@ Range
Numeric range field domain (min/max)
QgsCodedFieldDomain::values
QList< QgsCodedValue > values() const
Returns the enumeration as QgsCodedValue values.
Definition: qgsfielddomain.h:257
QgsRangeFieldDomain
Definition of a numeric field domain with a range of validity for values.
Definition: qgsfielddomain.h:289
Qgis::FieldDomainSplitPolicy::DefaultValue
@ DefaultValue
Use default field value.
str
#define str(x)
Definition: qgis.cpp:37
QgsFieldDomain::splitPolicy
Qgis::FieldDomainSplitPolicy splitPolicy() const
Returns the split policy.
Definition: qgsfielddomain.h:130
QgsRangeFieldDomain::setMaximum
void setMaximum(const QVariant &maximum)
Sets the maximum allowed value.
Definition: qgsfielddomain.h:372
QgsFieldDomain::description
QString description() const
Returns the description of the field domain.
Definition: qgsfielddomain.h:102
QgsRangeFieldDomain::minimum
QVariant minimum() const
Returns the minimum value.
Definition: qgsfielddomain.h:326
QgsFieldDomain
Base class for field domains.
Definition: qgsfielddomain.h:33
QgsRangeFieldDomain::maximum
QVariant maximum() const
Returns the maximum value.
Definition: qgsfielddomain.h:362
SIP_END
#define SIP_END
Definition: qgis_sip.h:203
QgsFieldDomain::mName
QString mName
Definition: qgsfielddomain.h:155
QgsCodedValue::value
QString value() const
Returns the associated value, which is the user-friendly string representation.
Definition: qgsfielddomain.h:195
QgsFieldDomain::mDescription
QString mDescription
Definition: qgsfielddomain.h:156
Qgis::FieldDomainType::Coded
@ Coded
Coded field domain.
QgsFieldDomain::setSplitPolicy
void setSplitPolicy(Qgis::FieldDomainSplitPolicy policy)
Sets the split policy.
Definition: qgsfielddomain.h:137
QgsCodedValue
Associates a code and a value.
Definition: qgsfielddomain.h:170
QgsCodedValue::code
QVariant code() const
Returns the associated code, which is the underlying value stored in fields.
Definition: qgsfielddomain.h:189