QGIS API Documentation 3.41.0-Master (af5edcb665c)
Loading...
Searching...
No Matches
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
33class 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 }
55#endif
56
57 public:
58
62 QgsFieldDomain( const QString &name,
63 const QString &description,
64 QMetaType::Type fieldType );
65
70 Q_DECL_DEPRECATED QgsFieldDomain( const QString &name,
71 const QString &description,
72 QVariant::Type fieldType ) SIP_DEPRECATED;
73
74 virtual ~QgsFieldDomain();
75
79 virtual QgsFieldDomain *clone() const = 0 SIP_FACTORY;
80
84 virtual Qgis::FieldDomainType type() const = 0;
85
89 virtual QString typeName() const = 0;
90
96 QString name() const { return mName; }
97
103 void setName( const QString &name ) { mName = name; }
104
110 QString description() const { return mDescription; }
111
117 void setDescription( const QString &description ) { mDescription = description; }
118
124 QMetaType::Type fieldType() const { return mFieldType; }
125
131 void setFieldType( QMetaType::Type type ) { mFieldType = type; }
132
139 Q_DECL_DEPRECATED void setFieldType( QVariant::Type type ) SIP_DEPRECATED;
140
146 Qgis::FieldDomainSplitPolicy splitPolicy() const { return mSplitPolicy; }
147
153 void setSplitPolicy( Qgis::FieldDomainSplitPolicy policy ) { mSplitPolicy = policy; }
154
160 Qgis::FieldDomainMergePolicy mergePolicy() const { return mMergePolicy; }
161
167 void setMergePolicy( Qgis::FieldDomainMergePolicy policy ) { mMergePolicy = policy; }
168
169 protected:
170
171 QString mName;
173
174 QMetaType::Type mFieldType = QMetaType::Type::QString;
177
178};
179
186class CORE_EXPORT QgsCodedValue
187{
188 public:
189
196 QgsCodedValue( const QVariant &code, const QString &value )
197 : mCode( code )
198 , mValue( value )
199 {}
200
205 QVariant code() const { return mCode; }
206
211 QString value() const { return mValue; }
212
213#ifdef SIP_RUN
214 SIP_PYOBJECT __repr__();
215 % MethodCode
216 QString str = QStringLiteral( "<QgsCodedValue: %1 (%2)>" ).arg( sipCpp->code().toString(), sipCpp->value() );
217 sipRes = PyUnicode_FromString( str.toUtf8().constData() );
218 % End
219#endif
220
221 bool operator==( const QgsCodedValue &other ) const;
222 bool operator!=( const QgsCodedValue &other ) const;
223
224 private:
225
226 QVariant mCode;
227 QString mValue;
228};
229
230
241class CORE_EXPORT QgsCodedFieldDomain : public QgsFieldDomain
242{
243
244 public:
245
252 QgsCodedFieldDomain( const QString &name,
253 const QString &description,
254 QMetaType::Type fieldType,
255 const QList<QgsCodedValue> &values );
256
264 Q_DECL_DEPRECATED QgsCodedFieldDomain( const QString &name,
265 const QString &description,
266 QVariant::Type fieldType,
267 const QList<QgsCodedValue> &values ) SIP_DEPRECATED;
268
269#ifndef SIP_RUN
273 QgsCodedFieldDomain &operator= ( const QgsCodedFieldDomain & ) = delete;
274#endif
275
276 Qgis::FieldDomainType type() const override;
277 QString typeName() const override;
278 QgsCodedFieldDomain *clone() const override SIP_FACTORY;
279
285 QList< QgsCodedValue> values() const { return mValues; }
286
292 void setValues( const QList< QgsCodedValue> &values ) { mValues = values; }
293
294#ifdef SIP_RUN
295 SIP_PYOBJECT __repr__();
296 % MethodCode
297 QString str = QStringLiteral( "<QgsCodedFieldDomain: %1>" ).arg( sipCpp->name() );
298 sipRes = PyUnicode_FromString( str.toUtf8().constData() );
299 % End
300#endif
301
302 private:
303 QList< QgsCodedValue> mValues;
304
305#ifdef SIP_RUN
307#endif
308};
309
310
317class CORE_EXPORT QgsRangeFieldDomain : public QgsFieldDomain
318{
319
320 public:
321
327 QgsRangeFieldDomain( const QString &name,
328 const QString &description,
329 QMetaType::Type fieldType,
330 const QVariant &minimum,
331 bool minimumIsInclusive,
332 const QVariant &maximum,
333 bool maximumIsInclusive );
334
341 Q_DECL_DEPRECATED QgsRangeFieldDomain( const QString &name,
342 const QString &description,
343 QVariant::Type fieldType,
344 const QVariant &minimum,
345 bool minimumIsInclusive,
346 const QVariant &maximum,
347 bool maximumIsInclusive ) SIP_DEPRECATED;
348
349
350#ifndef SIP_RUN
354 QgsRangeFieldDomain &operator= ( const QgsRangeFieldDomain & ) = delete;
355#endif
356
357 Qgis::FieldDomainType type() const override;
358 QString typeName() const override;
359 QgsRangeFieldDomain *clone() const override SIP_FACTORY;
360
369 QVariant minimum() const { return mMin; }
370
379 void setMinimum( const QVariant &minimum ) { mMin = minimum; }
380
387 bool minimumIsInclusive() const { return mMinIsInclusive; }
388
395 void setMinimumIsInclusive( bool inclusive ) { mMinIsInclusive = inclusive; }
396
405 QVariant maximum() const { return mMax; }
406
415 void setMaximum( const QVariant &maximum ) { mMax = maximum; }
416
423 bool maximumIsInclusive() const { return mMaxIsInclusive; }
424
431 void setMaximumIsInclusive( bool inclusive ) { mMaxIsInclusive = inclusive; }
432
433#ifdef SIP_RUN
434 SIP_PYOBJECT __repr__();
435 % MethodCode
436 QString str = QStringLiteral( "<QgsRangeFieldDomain: %1 %2%3, %4%5>" ).arg( sipCpp->name(),
437 sipCpp->minimumIsInclusive() ? QStringLiteral( "[" ) : QStringLiteral( "(" ),
438 sipCpp->minimum().toString(),
439 sipCpp->maximum().toString(),
440 sipCpp->maximumIsInclusive() ? QStringLiteral( "]" ) : QStringLiteral( ")" ) );
441 sipRes = PyUnicode_FromString( str.toUtf8().constData() );
442 % End
443#endif
444
445 private:
446 QVariant mMin;
447 QVariant mMax;
448 bool mMinIsInclusive = false;
449 bool mMaxIsInclusive = false;
450
451#ifdef SIP_RUN
453#endif
454};
455
456
465class CORE_EXPORT QgsGlobFieldDomain : public QgsFieldDomain
466{
467
468 public:
469
475 QgsGlobFieldDomain( const QString &name,
476 const QString &description,
477 QMetaType::Type fieldType,
478 const QString &glob );
479
486 Q_DECL_DEPRECATED QgsGlobFieldDomain( const QString &name,
487 const QString &description,
488 QVariant::Type fieldType,
489 const QString &glob ) SIP_DEPRECATED;
490
491
492#ifndef SIP_RUN
496 QgsGlobFieldDomain &operator= ( const QgsGlobFieldDomain & ) = delete;
497#endif
498
499 Qgis::FieldDomainType type() const override;
500 QString typeName() const override;
501 QgsGlobFieldDomain *clone() const override SIP_FACTORY;
502
510 QString glob() const { return mGlob; }
511
519 void setGlob( const QString &glob ) { mGlob = glob; }
520
521#ifdef SIP_RUN
522 SIP_PYOBJECT __repr__();
523 % MethodCode
524 QString str = QStringLiteral( "<QgsGlobFieldDomain: %1 '%2'>" ).arg( sipCpp->name(), sipCpp->glob() );
525 sipRes = PyUnicode_FromString( str.toUtf8().constData() );
526 % End
527#endif
528
529 private:
530 QString mGlob;
531
532#ifdef SIP_RUN
534#endif
535
536};
537
538#endif // QGSFIELDDOMAIN_H
FieldDomainMergePolicy
Merge policy for field domains.
Definition qgis.h:3708
@ DefaultValue
Use default field value.
FieldDomainSplitPolicy
Split policy for field domains.
Definition qgis.h:3691
@ DefaultValue
Use default field value.
FieldDomainType
Types of field domain.
Definition qgis.h:3736
@ Coded
Coded field domain.
@ Range
Numeric range field domain (min/max)
@ Glob
Glob string pattern field domain.
Definition of a coded / enumerated field domain.
void setValues(const QList< QgsCodedValue > &values)
Sets the enumeration as QgsCodedValue values.
QgsCodedFieldDomain(const QgsCodedFieldDomain &)=delete
QgsCodedFieldDomain cannot be copied - use clone() instead.
Associates a code and a value.
QVariant code() const
Returns the associated code, which is the underlying value stored in fields.
QgsCodedValue(const QVariant &code, const QString &value)
Constructor for QgsCodedValue, with the associated code and value.
QString value() const
Returns the associated value, which is the user-friendly string representation.
Base class for field domains.
Qgis::FieldDomainMergePolicy mergePolicy() const
Returns the merge policy.
Qgis::FieldDomainSplitPolicy splitPolicy() const
Returns the split policy.
void setFieldType(QMetaType::Type type)
Sets the associated field type.
virtual ~QgsFieldDomain()
void setName(const QString &name)
Sets the name of the field domain.
QMetaType::Type fieldType() const
Returns the associated field type.
virtual Qgis::FieldDomainType type() const =0
Returns the type of field domain.
QString name() const
Returns the name of the field domain.
void setDescription(const QString &description)
Sets the description of the field domain.
void setSplitPolicy(Qgis::FieldDomainSplitPolicy policy)
Sets the split policy.
QString description() const
Returns the description of the field domain.
void setMergePolicy(Qgis::FieldDomainMergePolicy policy)
Sets the merge policy.
virtual QgsFieldDomain * clone() const =0
Clones the field domain.
virtual QString typeName() const =0
Returns a translated name of the field domain type.
Definition of a field domain for field content validated by a glob.
QgsGlobFieldDomain(const QgsGlobFieldDomain &)=delete
QgsGlobFieldDomain cannot be copied - use clone() instead.
void setGlob(const QString &glob)
Sets the glob expression.
Definition of a numeric field domain with a range of validity for values.
void setMaximumIsInclusive(bool inclusive)
Sets whether the maximum value is inclusive.
QgsRangeFieldDomain(const QgsRangeFieldDomain &)=delete
QgsRangeFieldDomain cannot be copied - use clone() instead.
void setMaximum(const QVariant &maximum)
Sets the maximum allowed value.
bool maximumIsInclusive() const
Returns true if the maximum value is inclusive.
void setMinimum(const QVariant &minimum)
Sets the minimum allowed value.
bool minimumIsInclusive() const
Returns true if the minimum value is inclusive.
void setMinimumIsInclusive(bool inclusive)
Sets whether the minimum value is inclusive.
QVariant maximum() const
Returns the maximum value.
#define SIP_CONVERT_TO_SUBCLASS_CODE(code)
Definition qgis_sip.h:191
#define SIP_DEPRECATED
Definition qgis_sip.h:106
#define SIP_FACTORY
Definition qgis_sip.h:76
#define SIP_END
Definition qgis_sip.h:208
bool operator==(const QgsFeatureIterator &fi1, const QgsFeatureIterator &fi2)
bool operator!=(const QgsFeatureIterator &fi1, const QgsFeatureIterator &fi2)
const QString & typeName