QGIS API Documentation 3.99.0-Master (8e76e220402)
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.h"
20#include "qgis_core.h"
21#include "qgis_sip.h"
22
23#include <QString>
24
25using namespace Qt::StringLiterals;
26
37class CORE_EXPORT QgsFieldDomain
38{
39
40#ifdef SIP_RUN
42 if ( sipCpp->type() == Qgis::FieldDomainType::Coded )
43 {
44 sipType = sipType_QgsCodedFieldDomain;
45 }
46 else if ( sipCpp->type() == Qgis::FieldDomainType::Range )
47 {
48 sipType = sipType_QgsRangeFieldDomain;
49 }
50 else if ( sipCpp->type() == Qgis::FieldDomainType::Glob )
51 {
52 sipType = sipType_QgsGlobFieldDomain;
53 }
54 else
55 {
56 sipType = 0;
57 }
59#endif
60
61 public:
62
66 QgsFieldDomain( const QString &name,
67 const QString &description,
68 QMetaType::Type fieldType );
69
74 Q_DECL_DEPRECATED QgsFieldDomain( const QString &name,
75 const QString &description,
76 QVariant::Type fieldType ) SIP_DEPRECATED;
77
78 virtual ~QgsFieldDomain();
79
83 virtual QgsFieldDomain *clone() const = 0 SIP_FACTORY;
84
88 virtual Qgis::FieldDomainType type() const = 0;
89
93 virtual QString typeName() const = 0;
94
100 QString name() const { return mName; }
101
107 void setName( const QString &name ) { mName = name; }
108
114 QString description() const { return mDescription; }
115
122
128 QMetaType::Type fieldType() const { return mFieldType; }
129
135 void setFieldType( QMetaType::Type type ) { mFieldType = type; }
136
143 Q_DECL_DEPRECATED void setFieldType( QVariant::Type type ) SIP_DEPRECATED;
144
151
158
165
172
173 protected:
174
175 QString mName;
177
178 QMetaType::Type mFieldType = QMetaType::Type::QString;
181
182};
183
190class CORE_EXPORT QgsCodedValue
191{
192 public:
193
200 QgsCodedValue( const QVariant &code, const QString &value )
201 : mCode( code )
202 , mValue( value )
203 {}
204
209 QVariant code() const { return mCode; }
210
215 QString value() const { return mValue; }
216
217#ifdef SIP_RUN
218 SIP_PYOBJECT __repr__();
219 % MethodCode
220 QString str = u"<QgsCodedValue: %1 (%2)>"_s.arg( sipCpp->code().toString(), sipCpp->value() );
221 sipRes = PyUnicode_FromString( str.toUtf8().constData() );
222 % End
223#endif
224
225 bool operator==( const QgsCodedValue &other ) const;
226 bool operator!=( const QgsCodedValue &other ) const;
227
228 private:
229
230 QVariant mCode;
231 QString mValue;
232};
233
234
245class CORE_EXPORT QgsCodedFieldDomain : public QgsFieldDomain
246{
247
248 public:
249
256 QgsCodedFieldDomain( const QString &name,
257 const QString &description,
258 QMetaType::Type fieldType,
259 const QList<QgsCodedValue> &values );
260
268 Q_DECL_DEPRECATED QgsCodedFieldDomain( const QString &name,
269 const QString &description,
270 QVariant::Type fieldType,
271 const QList<QgsCodedValue> &values ) SIP_DEPRECATED;
272
273#ifndef SIP_RUN
277 QgsCodedFieldDomain &operator= ( const QgsCodedFieldDomain & ) = delete;
278#endif
279
280 Qgis::FieldDomainType type() const override;
281 QString typeName() const override;
282 QgsCodedFieldDomain *clone() const override SIP_FACTORY;
283
289 QList< QgsCodedValue> values() const { return mValues; }
290
296 void setValues( const QList< QgsCodedValue> &values ) { mValues = values; }
297
298#ifdef SIP_RUN
299 SIP_PYOBJECT __repr__();
300 % MethodCode
301 QString str = u"<QgsCodedFieldDomain: %1>"_s.arg( sipCpp->name() );
302 sipRes = PyUnicode_FromString( str.toUtf8().constData() );
303 % End
304#endif
305
306 private:
307 QList< QgsCodedValue> mValues;
308
309#ifdef SIP_RUN
311#endif
312};
313
314
321class CORE_EXPORT QgsRangeFieldDomain : public QgsFieldDomain
322{
323
324 public:
325
331 QgsRangeFieldDomain( const QString &name,
332 const QString &description,
333 QMetaType::Type fieldType,
334 const QVariant &minimum,
336 const QVariant &maximum,
337 bool maximumIsInclusive );
338
345 Q_DECL_DEPRECATED QgsRangeFieldDomain( const QString &name,
346 const QString &description,
347 QVariant::Type fieldType,
348 const QVariant &minimum,
350 const QVariant &maximum,
352
353
354#ifndef SIP_RUN
358 QgsRangeFieldDomain &operator= ( const QgsRangeFieldDomain & ) = delete;
359#endif
360
361 Qgis::FieldDomainType type() const override;
362 QString typeName() const override;
363 QgsRangeFieldDomain *clone() const override SIP_FACTORY;
364
373 QVariant minimum() const { return mMin; }
374
383 void setMinimum( const QVariant &minimum ) { mMin = minimum; }
384
391 bool minimumIsInclusive() const { return mMinIsInclusive; }
392
399 void setMinimumIsInclusive( bool inclusive ) { mMinIsInclusive = inclusive; }
400
409 QVariant maximum() const { return mMax; }
410
419 void setMaximum( const QVariant &maximum ) { mMax = maximum; }
420
427 bool maximumIsInclusive() const { return mMaxIsInclusive; }
428
435 void setMaximumIsInclusive( bool inclusive ) { mMaxIsInclusive = inclusive; }
436
437#ifdef SIP_RUN
438 SIP_PYOBJECT __repr__();
439 % MethodCode
440 QString str = u"<QgsRangeFieldDomain: %1 %2%3, %4%5>"_s.arg( sipCpp->name(),
441 sipCpp->minimumIsInclusive() ? u"["_s : u"("_s,
442 sipCpp->minimum().toString(),
443 sipCpp->maximum().toString(),
444 sipCpp->maximumIsInclusive() ? u"]"_s : u")"_s );
445 sipRes = PyUnicode_FromString( str.toUtf8().constData() );
446 % End
447#endif
448
449 private:
450 QVariant mMin;
451 QVariant mMax;
452 bool mMinIsInclusive = false;
453 bool mMaxIsInclusive = false;
454
455#ifdef SIP_RUN
457#endif
458};
459
460
469class CORE_EXPORT QgsGlobFieldDomain : public QgsFieldDomain
470{
471
472 public:
473
479 QgsGlobFieldDomain( const QString &name,
480 const QString &description,
481 QMetaType::Type fieldType,
482 const QString &glob );
483
490 Q_DECL_DEPRECATED QgsGlobFieldDomain( const QString &name,
491 const QString &description,
492 QVariant::Type fieldType,
493 const QString &glob ) SIP_DEPRECATED;
494
495
496#ifndef SIP_RUN
500 QgsGlobFieldDomain &operator= ( const QgsGlobFieldDomain & ) = delete;
501#endif
502
503 Qgis::FieldDomainType type() const override;
504 QString typeName() const override;
505 QgsGlobFieldDomain *clone() const override SIP_FACTORY;
506
514 QString glob() const { return mGlob; }
515
523 void setGlob( const QString &glob ) { mGlob = glob; }
524
525#ifdef SIP_RUN
526 SIP_PYOBJECT __repr__();
527 % MethodCode
528 QString str = u"<QgsGlobFieldDomain: %1 '%2'>"_s.arg( sipCpp->name(), sipCpp->glob() );
529 sipRes = PyUnicode_FromString( str.toUtf8().constData() );
530 % End
531#endif
532
533 private:
534 QString mGlob;
535
536#ifdef SIP_RUN
538#endif
539
540};
541
542#endif // QGSFIELDDOMAIN_H
FieldDomainMergePolicy
Merge policy for field domains.
Definition qgis.h:3994
@ DefaultValue
Use default field value.
Definition qgis.h:3995
FieldDomainSplitPolicy
Split policy for field domains.
Definition qgis.h:3977
@ DefaultValue
Use default field value.
Definition qgis.h:3978
FieldDomainType
Types of field domain.
Definition qgis.h:4027
@ Coded
Coded field domain.
Definition qgis.h:4028
@ Range
Numeric range field domain (min/max).
Definition qgis.h:4029
@ Glob
Glob string pattern field domain.
Definition qgis.h:4030
Definition of a coded / enumerated field domain.
QgsCodedFieldDomain * clone() const override
Clones the field domain.
void setValues(const QList< QgsCodedValue > &values)
Sets the enumeration as QgsCodedValue values.
QList< QgsCodedValue > values() const
Returns the enumeration as QgsCodedValue values.
QgsCodedFieldDomain(const QString &name, const QString &description, QMetaType::Type fieldType, const QList< QgsCodedValue > &values)
Constructor for QgsCodedFieldDomain, with the associated name, description and fieldType.
Qgis::FieldDomainType type() const override
Returns the type of field domain.
QgsCodedFieldDomain(const QgsCodedFieldDomain &)=delete
QgsCodedFieldDomain cannot be copied - use clone() instead.
QString typeName() const override
Returns a translated name of the field domain type.
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.
Qgis::FieldDomainMergePolicy mergePolicy() const
Returns the merge policy.
Qgis::FieldDomainSplitPolicy mSplitPolicy
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.
Qgis::FieldDomainMergePolicy mMergePolicy
virtual Qgis::FieldDomainType type() const =0
Returns the type of field domain.
QMetaType::Type mFieldType
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.
QgsFieldDomain(const QString &name, const QString &description, QMetaType::Type fieldType)
Constructor for QgsFieldDomain, with the specified name, description and fieldType.
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.
QgsGlobFieldDomain(const QString &name, const QString &description, QMetaType::Type fieldType, const QString &glob)
Constructor for QgsGlobFieldDomain, with the specified name, description and fieldType.
QString typeName() const override
Returns a translated name of the field domain type.
QString glob() const
Returns the glob expression.
QgsGlobFieldDomain * clone() const override
Clones the field domain.
void setGlob(const QString &glob)
Sets the glob expression.
Qgis::FieldDomainType type() const override
Returns the type of field domain.
Definition of a numeric field domain with a range of validity for values.
void setMaximumIsInclusive(bool inclusive)
Sets whether the maximum value is inclusive.
Qgis::FieldDomainType type() const override
Returns the type of field domain.
QVariant minimum() const
Returns the minimum value.
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.
QgsRangeFieldDomain(const QString &name, const QString &description, QMetaType::Type fieldType, const QVariant &minimum, bool minimumIsInclusive, const QVariant &maximum, bool maximumIsInclusive)
Constructor for QgsRangeFieldDomain, with the specified name, description and fieldType.
void setMinimum(const QVariant &minimum)
Sets the minimum allowed value.
QgsRangeFieldDomain * clone() const override
Clones the field domain.
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.
QString typeName() const override
Returns a translated name of the field domain type.
#define SIP_CONVERT_TO_SUBCLASS_CODE(code)
Definition qgis_sip.h:199
#define SIP_DEPRECATED
Definition qgis_sip.h:114
#define SIP_FACTORY
Definition qgis_sip.h:84
#define SIP_END
Definition qgis_sip.h:216
bool operator==(const QgsFeatureIterator &fi1, const QgsFeatureIterator &fi2)
bool operator!=(const QgsFeatureIterator &fi1, const QgsFeatureIterator &fi2)