QGIS API Documentation 3.99.0-Master (21b3aa880ba)
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
25#include "moc_qgsattributesforminitcode.cpp"
26
28{
29 setupUi( this );
31
32 // Init function stuff
33 mInitCodeSourceComboBox->addItem( QString(), QVariant::fromValue( Qgis::AttributeFormPythonInitCodeSource::NoSource ) );
34 mInitCodeSourceComboBox->addItem( tr( "Load from External File" ), QVariant::fromValue( Qgis::AttributeFormPythonInitCodeSource::File ) );
35 mInitCodeSourceComboBox->addItem( tr( "Provide Code in this Dialog" ), QVariant::fromValue( Qgis::AttributeFormPythonInitCodeSource::Dialog ) );
36 mInitCodeSourceComboBox->addItem( tr( "Load from the Environment" ), QVariant::fromValue( Qgis::AttributeFormPythonInitCodeSource::Environment ) );
37
38 const QgsSettings settings;
39 mInitFileWidget->setDefaultRoot( settings.value( QStringLiteral( "style/lastInitFilePathDir" ), "." ).toString() );
40 mInitFileWidget->setDialogTitle( tr( "Select Python File" ) );
41 mInitFileWidget->setFilter( tr( "Python files (*.py *.PY)" ) );
42
43 connect( mInitCodeSourceComboBox, static_cast<void ( QComboBox::* )( int )>( &QComboBox::currentIndexChanged ), this, &QgsAttributesFormInitCode::mInitCodeSourceComboBox_currentIndexChanged );
44 connect( buttonBox, &QDialogButtonBox::helpRequested, this, &QgsAttributesFormInitCode::showHelp );
45}
46
48{
49 mInitCodeSourceComboBox->setCurrentIndex( mInitCodeSourceComboBox->findData( QVariant::fromValue( initCodeSource ) ) );
50 mInitCodeSourceComboBox_currentIndexChanged( mInitCodeSourceComboBox->currentIndex() );
51}
53{
54 mInitFunctionLineEdit->setText( initFunction );
55}
57{
58 mInitFileWidget->setFilePath( initFilePath );
59}
61{
62 mInitCodeEditorPython->setText( initCode );
63}
64
69
71{
72 return mInitFunctionLineEdit->text();
73}
75{
76 return mInitFileWidget->filePath();
77}
79{
80 return mInitCodeEditorPython->text();
81}
82
83void QgsAttributesFormInitCode::mInitCodeSourceComboBox_currentIndexChanged( int )
84{
86 mInitFunctionContainer->setVisible( codeSource != Qgis::AttributeFormPythonInitCodeSource::NoSource );
87 mInitFilePathLabel->setVisible( codeSource == Qgis::AttributeFormPythonInitCodeSource::File );
88 mInitFileWidget->setVisible( codeSource == Qgis::AttributeFormPythonInitCodeSource::File );
89 mInitCodeEditorPython->setVisible( codeSource == Qgis::AttributeFormPythonInitCodeSource::Dialog );
90}
91
92void QgsAttributesFormInitCode::showHelp()
93{
94 QgsHelp::openHelp( QStringLiteral( "working_with_vector/vector_properties.html#enhance-your-form-with-custom-functions" ) );
95}
AttributeFormPythonInitCodeSource
The Python init code source for attribute forms.
Definition qgis.h:5515
@ File
Load the Python code from an external file.
Definition qgis.h:5517
@ Environment
Use the Python code available in the Python environment.
Definition qgis.h:5519
@ NoSource
Do not use Python code at all.
Definition qgis.h:5516
@ Dialog
Use the Python code provided in the dialog.
Definition qgis.h:5518
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:221
static void openHelp(const QString &key)
Opens help topic for the given help key using default system web browser.
Definition qgshelp.cpp:38
Stores settings for use within QGIS.
Definition qgssettings.h:65
QVariant value(const QString &key, const QVariant &defaultValue=QVariant(), Section section=NoSection) const
Returns the value for setting key.