QGIS API Documentation 3.99.0-Master (26c88405ac0)
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
45class CORE_EXPORT QgsDefaultValue
46{
47 Q_GADGET SIP_SKIP
48
49 Q_PROPERTY( QString expression READ expression WRITE setExpression )
50 Q_PROPERTY( bool applyOnUpdate READ applyOnUpdate WRITE setApplyOnUpdate )
51
52 public:
53
58 explicit QgsDefaultValue( const QString &expression = QString(), bool applyOnUpdate = false );
59
60 // TODO c++20 - replace with = default
61 bool operator==( const QgsDefaultValue &other ) const;
62
63#ifdef SIP_RUN
64 SIP_PYOBJECT __repr__();
65 % MethodCode
66 const QString str = sipCpp->isValid() ? QStringLiteral( "<QgsDefaultValue: %1>" ).arg(
67 sipCpp->expression().length() > 1000 ? sipCpp->expression().left( 1000 ) + QStringLiteral( "..." )
68 : sipCpp->expression() )
69 : QStringLiteral( "<QgsDefaultValue: invalid>" );
70 sipRes = PyUnicode_FromString( str.toUtf8().constData() );
71 % End
72#endif
73
78 QString expression() const;
79
84 void setExpression( const QString &expression );
85
90 bool applyOnUpdate() const;
91
97
102 bool isValid() const;
103
108 explicit operator bool() const SIP_PYTHON_SPECIAL_BOOL( isValid );
109
110 private:
111 QString mExpression;
112 bool mApplyOnUpdate = false;
113};
114
116
117#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:255
#define SIP_SKIP
Definition qgis_sip.h:134
Q_DECLARE_METATYPE(QgsDatabaseQueryLogEntry)