QGIS API Documentation 3.99.0-Master (26c88405ac0)
Loading...
Searching...
No Matches
qgsexpressionaddfunctionfiledialog.cpp
Go to the documentation of this file.
1/***************************************************************************
2 qgsexpressionaddfunctionfiledialog.cpp
3 ---------------------
4 begin : May 2024
5 copyright : (C) 2024 by Germán Carrillo
6 email : german 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
18#include "qgshelp.h"
19
20#include <QPushButton>
21#include <QStandardItemModel>
22
23#include "moc_qgsexpressionaddfunctionfiledialog.cpp"
24
26 : QDialog( parent )
27{
28 setupUi( this );
29 cboFileOptions->addItem( tr( "Function file" ) );
30 cboFileOptions->addItem( tr( "Project functions" ), QStringLiteral( "project" ) );
31
32 // Disable project functions (they should be created only once)
33 if ( !enableProjectFunctions )
34 {
35 QStandardItem *item = qobject_cast<QStandardItemModel *>( cboFileOptions->model() )->item( 1 );
36 item->setFlags( item->flags() & ~Qt::ItemIsEnabled );
37 }
38
39 connect( cboFileOptions, qOverload<int>( &QComboBox::currentIndexChanged ), this, &QgsExpressionAddFunctionFileDialog::cboFileOptions_currentIndexChanged );
40 connect( txtNewFileName, &QLineEdit::textChanged, this, [this]( const QString & ) { updateOkButtonStatus(); } );
41 connect( buttonBox, &QDialogButtonBox::helpRequested, this, [] {
42 QgsHelp::openHelp( QStringLiteral( "expressions/expression.html#function-editor" ) );
43 } );
44
45 updateOkButtonStatus();
46}
47
48void QgsExpressionAddFunctionFileDialog::cboFileOptions_currentIndexChanged( int )
49{
50 bool projectSelected = cboFileOptions->currentData() == QLatin1String( "project" );
51 lblNewFileName->setVisible( !projectSelected );
52 txtNewFileName->setVisible( !projectSelected );
53 updateOkButtonStatus();
54}
55
56void QgsExpressionAddFunctionFileDialog::updateOkButtonStatus()
57{
58 QPushButton *okBtn = buttonBox->button( QDialogButtonBox::StandardButton::Ok );
59 okBtn->setEnabled( true );
60
61 if ( cboFileOptions->currentData() != QLatin1String( "project" ) )
62 {
63 okBtn->setEnabled( !txtNewFileName->text().trimmed().isEmpty() );
64 }
65}
66
68{
69 return cboFileOptions->currentData() == QLatin1String( "project" );
70}
71
73{
74 return txtNewFileName->text().trimmed();
75}
QgsExpressionAddFunctionFileDialog(bool enableProjectFunctions, QWidget *parent)
Creates a QgsExpressionAddFunctionFileDialog to create function files or to set the current project a...
bool createProjectFunctions() const
Returns whether user has selected to create project functions.
static void openHelp(const QString &key)
Opens help topic for the given help key using default system web browser.
Definition qgshelp.cpp:38