QGIS API Documentation  3.24.2-Tisler (13c1a02865)
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 }
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 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:174
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.