QGIS API Documentation 4.1.0-Master (60fea48833c)
Loading...
Searching...
No Matches
qgsdefaultvalue.h
Go to the documentation of this file.
1/***************************************************************************
2 qgsdefaultvalue.h
3
4 ---------------------
5 begin : 19.9.2017
6 copyright : (C) 2017 by Matthias Kuhn
8 ***************************************************************************
9 * *
10 * This program is free software; you can redistribute it and/or modify *
11 * it under the terms of the GNU General Public License as published by *
12 * the Free Software Foundation; either version 2 of the License, or *
13 * (at your option) any later version. *
14 * *
15 ***************************************************************************/
16#ifndef QGSDEFAULTVALUE_H
17#define QGSDEFAULTVALUE_H
18
19#include "qgis_core.h"
20#include "qgis_sip.h"
21
22#include <QObject>
23#include <QString>
24
25using namespace Qt::StringLiterals;
26
47class CORE_EXPORT QgsDefaultValue
48{
49 // clang-format off
50 Q_GADGET SIP_SKIP
51
52 Q_PROPERTY( QString expression READ expression WRITE setExpression )
53 Q_PROPERTY( bool applyOnUpdate READ applyOnUpdate WRITE setApplyOnUpdate )
54
55 public:
56 // clang-format on
57
62 explicit QgsDefaultValue( const QString &expression = QString(), bool applyOnUpdate = false );
63
64 // TODO c++20 - replace with = default
65 bool operator==( const QgsDefaultValue &other ) const;
66
67#ifdef SIP_RUN
68 // clang-format off
69 SIP_PYOBJECT __repr__();
70 % MethodCode
71 const QString str = sipCpp->isValid() ? u"<QgsDefaultValue: %1>"_s.arg(
72 sipCpp->expression().length() > 1000 ? sipCpp->expression().left( 1000 ) + u"..."_s
73 : sipCpp->expression() )
74 : u"<QgsDefaultValue: invalid>"_s;
75 sipRes = PyUnicode_FromString( str.toUtf8().constData() );
76 % End
77// clang-format on
78#endif
79
84 QString expression() const;
85
90 void setExpression( const QString &expression );
91
96 bool applyOnUpdate() const;
97
102 void setApplyOnUpdate( bool applyOnUpdate );
103
108 bool isValid() const;
109
114 explicit operator bool() const SIP_PYTHON_SPECIAL_BOOL( isValid );
115
116 private:
117 QString mExpression;
118 bool mApplyOnUpdate = false;
119};
120
122
123#endif // QGSDEFAULTVALUE_H
QgsDefaultValue(const QString &expression=QString(), bool applyOnUpdate=false)
Create a new default value with the given expression and applyOnUpdate flag.
void setApplyOnUpdate(bool applyOnUpdate)
The applyOnUpdate flag determines if this expression should also be applied when a feature is updated...
bool isValid() const
Returns if this default value should be applied.
void setExpression(const QString &expression)
The expression will be evaluated whenever a default value needs to be calculated for a field.
#define SIP_PYTHON_SPECIAL_BOOL(method_or_code)
Definition qgis_sip.h:254
#define SIP_SKIP
Definition qgis_sip.h:133
Q_DECLARE_METATYPE(QgsDatabaseQueryLogEntry)