QGIS API Documentation 3.41.0-Master (cea29feecf2)
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 "moc_qgsattributesforminitcode.cpp"
18#include "ui_qgsattributesforminitcode.h"
19#include "qgssettings.h"
20#include "qgsgui.h"
21#include "qgshelp.h"
22
23#include <QFileDialog>
24
26{
27 setupUi( this );
29
30 // Init function stuff
31 mInitCodeSourceComboBox->addItem( QString(), QVariant::fromValue( Qgis::AttributeFormPythonInitCodeSource::NoSource ) );
32 mInitCodeSourceComboBox->addItem( tr( "Load from External File" ), QVariant::fromValue( Qgis::AttributeFormPythonInitCodeSource::File ) );
33 mInitCodeSourceComboBox->addItem( tr( "Provide Code in this Dialog" ), QVariant::fromValue( Qgis::AttributeFormPythonInitCodeSource::Dialog ) );
34 mInitCodeSourceComboBox->addItem( tr( "Load from the Environment" ), QVariant::fromValue( Qgis::AttributeFormPythonInitCodeSource::Environment ) );
35
36 const QgsSettings settings;
37 mInitFileWidget->setDefaultRoot( settings.value( QStringLiteral( "style/lastInitFilePathDir" ), "." ).toString() );
38 mInitFileWidget->setDialogTitle( tr( "Select Python File" ) );
39 mInitFileWidget->setFilter( tr( "Python files (*.py *.PY)" ) );
40
41 connect( mInitCodeSourceComboBox, static_cast<void ( QComboBox::* )( int )>( &QComboBox::currentIndexChanged ), this, &QgsAttributesFormInitCode::mInitCodeSourceComboBox_currentIndexChanged );
42 connect( buttonBox, &QDialogButtonBox::helpRequested, this, &QgsAttributesFormInitCode::showHelp );
43}
44
46{
47 mInitCodeSourceComboBox->setCurrentIndex( mInitCodeSourceComboBox->findData( QVariant::fromValue( initCodeSource ) ) );
48 mInitCodeSourceComboBox_currentIndexChanged( mInitCodeSourceComboBox->currentIndex() );
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
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{
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:5171
@ 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:210
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.