QGIS API Documentation 3.41.0-Master (3440c17df1d)
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
50}
51void QgsAttributesFormInitCode::setInitFunction( const QString &initFunction )
52{
53 mInitFunctionLineEdit->setText( initFunction );
54}
55void QgsAttributesFormInitCode::setInitFilePath( const QString &initFilePath )
56{
57 mInitFileWidget->setFilePath( initFilePath );
58}
59void QgsAttributesFormInitCode::setInitCode( const QString &initCode )
60{
61 mInitCodeEditorPython->setText( initCode );
62}
63
65{
66 return mInitCodeSourceComboBox->currentData().value< Qgis::AttributeFormPythonInitCodeSource >();
67}
68
70{
71 return mInitFunctionLineEdit->text();
72}
74{
75 return mInitFileWidget->filePath();
76}
78{
79 return mInitCodeEditorPython->text();
80}
81
82void QgsAttributesFormInitCode::mInitCodeSourceComboBox_currentIndexChanged( int )
83{
84 Qgis::AttributeFormPythonInitCodeSource codeSource = mInitCodeSourceComboBox->currentData().value< Qgis::AttributeFormPythonInitCodeSource >();
85 mInitFunctionContainer->setVisible( codeSource != Qgis::AttributeFormPythonInitCodeSource::NoSource );
86 mInitFilePathLabel->setVisible( codeSource == Qgis::AttributeFormPythonInitCodeSource::File );
87 mInitFileWidget->setVisible( codeSource == Qgis::AttributeFormPythonInitCodeSource::File );
88 mInitCodeEditorPython->setVisible( codeSource == Qgis::AttributeFormPythonInitCodeSource::Dialog );
89}
90
91void QgsAttributesFormInitCode::showHelp()
92{
93 QgsHelp::openHelp( QStringLiteral( "working_with_vector/vector_properties.html#enhance-your-form-with-custom-functions" ) );
94}
AttributeFormPythonInitCodeSource
The Python init code source for attribute forms.
Definition qgis.h:5126
@ 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:209
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.