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