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