QGIS API Documentation 3.99.0-Master (d270888f95f)
Loading...
Searching...
No Matches
qgsattributesforminitcode.cpp
Go to the documentation of this file.
1/***************************************************************************
2 qgsattributesforminitcode.cpp
3 ---------------------
4 begin : October 2017
5 copyright : (C) 2017 by David Signer
6 email : david 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 "ui_qgsattributesforminitcode.h"
18
19#include "qgsgui.h"
20#include "qgshelp.h"
21#include "qgssettings.h"
22
23#include <QFileDialog>
24#include <QString>
25
26#include "moc_qgsattributesforminitcode.cpp"
27
28using namespace Qt::StringLiterals;
29
31{
32 setupUi( this );
34
35 // Init function stuff
36 mInitCodeSourceComboBox->addItem( QString(), QVariant::fromValue( Qgis::AttributeFormPythonInitCodeSource::NoSource ) );
37 mInitCodeSourceComboBox->addItem( tr( "Load from External File" ), QVariant::fromValue( Qgis::AttributeFormPythonInitCodeSource::File ) );
38 mInitCodeSourceComboBox->addItem( tr( "Provide Code in this Dialog" ), QVariant::fromValue( Qgis::AttributeFormPythonInitCodeSource::Dialog ) );
39 mInitCodeSourceComboBox->addItem( tr( "Load from the Environment" ), QVariant::fromValue( Qgis::AttributeFormPythonInitCodeSource::Environment ) );
40
41 const QgsSettings settings;
42 mInitFileWidget->setDefaultRoot( settings.value( u"style/lastInitFilePathDir"_s, "." ).toString() );
43 mInitFileWidget->setDialogTitle( tr( "Select Python File" ) );
44 mInitFileWidget->setFilter( tr( "Python files (*.py *.PY)" ) );
45
46 connect( mInitCodeSourceComboBox, static_cast<void ( QComboBox::* )( int )>( &QComboBox::currentIndexChanged ), this, &QgsAttributesFormInitCode::mInitCodeSourceComboBox_currentIndexChanged );
47 connect( buttonBox, &QDialogButtonBox::helpRequested, this, &QgsAttributesFormInitCode::showHelp );
48}
49
51{
52 mInitCodeSourceComboBox->setCurrentIndex( mInitCodeSourceComboBox->findData( QVariant::fromValue( initCodeSource ) ) );
53 mInitCodeSourceComboBox_currentIndexChanged( mInitCodeSourceComboBox->currentIndex() );
54}
56{
57 mInitFunctionLineEdit->setText( initFunction );
58}
60{
61 mInitFileWidget->setFilePath( initFilePath );
62}
64{
65 mInitCodeEditorPython->setText( initCode );
66}
67
72
74{
75 return mInitFunctionLineEdit->text();
76}
78{
79 return mInitFileWidget->filePath();
80}
82{
83 return mInitCodeEditorPython->text();
84}
85
86void QgsAttributesFormInitCode::mInitCodeSourceComboBox_currentIndexChanged( int )
87{
89 mInitFunctionContainer->setVisible( codeSource != Qgis::AttributeFormPythonInitCodeSource::NoSource );
90 mInitFilePathLabel->setVisible( codeSource == Qgis::AttributeFormPythonInitCodeSource::File );
91 mInitFileWidget->setVisible( codeSource == Qgis::AttributeFormPythonInitCodeSource::File );
92 mInitCodeEditorPython->setVisible( codeSource == Qgis::AttributeFormPythonInitCodeSource::Dialog );
93}
94
95void QgsAttributesFormInitCode::showHelp()
96{
97 QgsHelp::openHelp( u"working_with_vector/vector_properties.html#enhance-your-form-with-custom-functions"_s );
98}
AttributeFormPythonInitCodeSource
The Python init code source for attribute forms.
Definition qgis.h:5781
@ File
Load the Python code from an external file.
Definition qgis.h:5783
@ Environment
Use the Python code available in the Python environment.
Definition qgis.h:5785
@ NoSource
Do not use Python code at all.
Definition qgis.h:5782
@ Dialog
Use the Python code provided in the dialog.
Definition qgis.h:5784
QString initFilePath() const
Returns the file path for the file containing the init code.
void setCodeSource(Qgis::AttributeFormPythonInitCodeSource source)
Sets the Python init code source.
void setInitFilePath(const QString &initFilePath)
Sets the file path for the file containing the init code.
void setInitFunction(const QString &initFunction)
Sets the name of the init function.
QString initFunction() const
Returns the name of the init function.
void setInitCode(const QString &initCode)
Sets the init code contents.
Qgis::AttributeFormPythonInitCodeSource codeSource() const
Returns the Python init code source.
QString initCode() const
Returns the init code contents.
static void enableAutoGeometryRestore(QWidget *widget, const QString &key=QString())
Register the widget to allow its position to be automatically saved and restored when open and closed...
Definition qgsgui.cpp:224
static void openHelp(const QString &key)
Opens help topic for the given help key using default system web browser.
Definition qgshelp.cpp:41
Stores settings for use within QGIS.
Definition qgssettings.h:68
QVariant value(const QString &key, const QVariant &defaultValue=QVariant(), Section section=NoSection) const
Returns the value for setting key.