QGIS API Documentation 3.39.0-Master (be2050b798e)
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
17#include "ui_qgsattributesforminitcode.h"
18#include "qgssettings.h"
19#include "qgsgui.h"
20#include "qgshelp.h"
21
22#include <QFileDialog>
23
25{
26 setupUi( this );
28
29 // Init function stuff
30 mInitCodeSourceComboBox->addItem( QString(), QVariant::fromValue( Qgis::AttributeFormPythonInitCodeSource::NoSource ) );
31 mInitCodeSourceComboBox->addItem( tr( "Load from External File" ), QVariant::fromValue( Qgis::AttributeFormPythonInitCodeSource::File ) );
32 mInitCodeSourceComboBox->addItem( tr( "Provide Code in this Dialog" ), QVariant::fromValue( Qgis::AttributeFormPythonInitCodeSource::Dialog ) );
33 mInitCodeSourceComboBox->addItem( tr( "Load from the Environment" ), QVariant::fromValue( Qgis::AttributeFormPythonInitCodeSource::Environment ) );
34
35 const QgsSettings settings;
36 mInitFileWidget->setDefaultRoot( settings.value( QStringLiteral( "style/lastInitFilePathDir" ), "." ).toString() );
37 mInitFileWidget->setDialogTitle( tr( "Select Python File" ) );
38 mInitFileWidget->setFilter( tr( "Python files (*.py *.PY)" ) );
39
40 connect( mInitCodeSourceComboBox, static_cast<void ( QComboBox::* )( int )>( &QComboBox::currentIndexChanged ), this, &QgsAttributesFormInitCode::mInitCodeSourceComboBox_currentIndexChanged );
41 connect( buttonBox, &QDialogButtonBox::helpRequested, this, &QgsAttributesFormInitCode::showHelp );
42}
43
45{
46 mInitCodeSourceComboBox->setCurrentIndex( mInitCodeSourceComboBox->findData( QVariant::fromValue( initCodeSource ) ) );
47 mInitCodeSourceComboBox_currentIndexChanged( mInitCodeSourceComboBox->currentIndex() );
48
49}
50void QgsAttributesFormInitCode::setInitFunction( const QString &initFunction )
51{
52 mInitFunctionLineEdit->setText( initFunction );
53}
54void QgsAttributesFormInitCode::setInitFilePath( const QString &initFilePath )
55{
56 mInitFileWidget->setFilePath( initFilePath );
57}
58void QgsAttributesFormInitCode::setInitCode( const QString &initCode )
59{
60 mInitCodeEditorPython->setText( initCode );
61}
62
64{
65 return mInitCodeSourceComboBox->currentData().value< Qgis::AttributeFormPythonInitCodeSource >();
66}
67
69{
70 return mInitFunctionLineEdit->text();
71}
73{
74 return mInitFileWidget->filePath();
75}
77{
78 return mInitCodeEditorPython->text();
79}
80
81void QgsAttributesFormInitCode::mInitCodeSourceComboBox_currentIndexChanged( int )
82{
83 Qgis::AttributeFormPythonInitCodeSource codeSource = mInitCodeSourceComboBox->currentData().value< Qgis::AttributeFormPythonInitCodeSource >();
84 mInitFunctionContainer->setVisible( codeSource != Qgis::AttributeFormPythonInitCodeSource::NoSource );
85 mInitFilePathLabel->setVisible( codeSource == Qgis::AttributeFormPythonInitCodeSource::File );
86 mInitFileWidget->setVisible( codeSource == Qgis::AttributeFormPythonInitCodeSource::File );
87 mInitCodeEditorPython->setVisible( codeSource == Qgis::AttributeFormPythonInitCodeSource::Dialog );
88}
89
90void QgsAttributesFormInitCode::showHelp()
91{
92 QgsHelp::openHelp( QStringLiteral( "working_with_vector/vector_properties.html#enhance-your-form-with-custom-functions" ) );
93}
AttributeFormPythonInitCodeSource
The Python init code source for attribute forms.
Definition qgis.h:4859
@ File
Load the Python code from an external file.
@ Environment
Use the Python code available in the Python environment.
@ NoSource
Do not use Python code at all.
@ Dialog
Use the Python code provided in the dialog.
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:200
static void openHelp(const QString &key)
Opens help topic for the given help key using default system web browser.
Definition qgshelp.cpp:39
This class is a composition of two QSettings instances:
Definition qgssettings.h:64
QVariant value(const QString &key, const QVariant &defaultValue=QVariant(), Section section=NoSection) const
Returns the value for setting key.