QGIS API Documentation
4.3.0-Master (16eddb2670e)
Toggle main menu visibility
Loading...
Searching...
No Matches
src
gui
qgsattributeformlegacyinterface.cpp
Go to the documentation of this file.
1
/***************************************************************************
2
qgsattributeformlegacyinterface.cpp
3
--------------------------------------
4
Date : 13.5.2014
5
Copyright : (C) 2014 Matthias Kuhn
6
Email : matthias at opengis dot ch
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
#include "
qgsattributeformlegacyinterface.h
"
17
18
#include "
qgsattributeform.h
"
19
#include "
qgspythonrunner.h
"
20
21
#include <QDateTime>
22
#include <QRegularExpression>
23
#include <QString>
24
25
using namespace
Qt::StringLiterals;
26
27
QgsAttributeFormLegacyInterface::QgsAttributeFormLegacyInterface
(
const
QString &function,
const
QString &pyFormName,
QgsAttributeForm
*
form
)
28
:
QgsAttributeFormInterface
(
form
)
29
, mPyFunctionName( function )
30
, mPyFormVarName( pyFormName )
31
{
32
static
int
sLayerCounter = 0;
33
mPyLayerVarName = u
"_qgis_layer_%1_%2"
_s.arg(
form
->layer()->id() ).arg( sLayerCounter++ );
34
const
thread_local
QRegularExpression reClean( QRegularExpression(
"[^a-zA-Z0-9_]"
) );
35
mPyLayerVarName.replace( reClean, u
"_"
_s );
// clean identifier
36
37
const
QString initLayer = u
"%1 = sip.wrapinstance( %2, qgis.core.QgsVectorLayer )"
_s.arg( mPyLayerVarName ).arg( ( quint64 )
form
->layer() );
38
39
QgsPythonRunner::run
( initLayer );
40
}
41
42
QgsAttributeFormLegacyInterface::~QgsAttributeFormLegacyInterface
()
43
{
44
const
QString delLayer = u
"del %1"
_s.arg( mPyLayerVarName );
45
QgsPythonRunner::run
( delLayer );
46
}
47
48
void
QgsAttributeFormLegacyInterface::featureChanged
()
49
{
50
QDialogButtonBox *buttonBox =
form
()->findChild<QDialogButtonBox *>();
51
if
( buttonBox )
52
{
53
// If the init function did not call disconnect, we do it here before reconnecting
54
// If it did call disconnect, then the call will just do nothing
55
QObject::disconnect( buttonBox, &QDialogButtonBox::accepted,
form
(), &
QgsAttributeForm::save
);
56
QObject::connect( buttonBox, &QDialogButtonBox::accepted,
form
(), &
QgsAttributeForm::save
);
57
}
58
59
// Generate the unique ID of this feature. We used to use feature ID but some providers
60
// return a ID that is an invalid python variable when we have new unsaved features.
61
const
QDateTime dt = QDateTime::currentDateTime();
62
const
QString pyFeatureVarName = u
"_qgis_feature_%1"
_s.arg( dt.toString( u
"yyyyMMddhhmmsszzz"
_s ) );
63
const
QString initFeature = u
"%1 = sip.wrapinstance( %2, qgis.core.QgsFeature )"
_s.arg( pyFeatureVarName ).arg( ( quint64 ) &
form
()->
feature
() );
64
65
QgsPythonRunner::run
( initFeature );
66
67
const
QString expr = u
"%1( %2, %3, %4)"
_s.arg( mPyFunctionName, mPyFormVarName, mPyLayerVarName, pyFeatureVarName );
68
69
QgsPythonRunner::run
( expr );
70
71
const
QString delFeature = u
"del %1"
_s.arg( pyFeatureVarName );
72
QgsPythonRunner::run
( delFeature );
73
}
QgsAttributeFormInterface::form
QgsAttributeForm * form() const
Returns the attribute form.
Definition
qgsattributeforminterface.cpp:37
QgsAttributeFormInterface::QgsAttributeFormInterface
QgsAttributeFormInterface(QgsAttributeForm *form)
Definition
qgsattributeforminterface.cpp:21
QgsAttributeFormInterface::feature
const QgsFeature & feature() const
Returns the current feature for the attribute form.
Definition
qgsattributeforminterface.cpp:42
QgsAttributeFormLegacyInterface::QgsAttributeFormLegacyInterface
QgsAttributeFormLegacyInterface(const QString &function, const QString &pyFormName, QgsAttributeForm *form)
Definition
qgsattributeformlegacyinterface.cpp:27
QgsAttributeFormLegacyInterface::featureChanged
void featureChanged() override
Definition
qgsattributeformlegacyinterface.cpp:48
QgsAttributeFormLegacyInterface::~QgsAttributeFormLegacyInterface
~QgsAttributeFormLegacyInterface() override
Definition
qgsattributeformlegacyinterface.cpp:42
QgsAttributeForm
The attribute form widget for vector layer features.
Definition
qgsattributeform.h:48
QgsAttributeForm::save
bool save()
Save all the values from the editors to the layer.
Definition
qgsattributeform.cpp:917
QgsPythonRunner::run
static bool run(const QString &command, const QString &messageOnError=QString())
Execute a Python statement.
Definition
qgspythonrunner.cpp:33
qgsattributeform.h
qgsattributeformlegacyinterface.h
qgspythonrunner.h
Generated on
for QGIS API Documentation by
1.17.0