QGIS API Documentation 3.99.0-Master (d270888f95f)
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#include <QString>
23
24#include "moc_qgsexpressionaddfunctionfiledialog.cpp"
25
26using namespace Qt::StringLiterals;
27
29 : QDialog( parent )
30{
31 setupUi( this );
32 cboFileOptions->addItem( tr( "Function file" ) );
33 cboFileOptions->addItem( tr( "Project functions" ), u"project"_s );
34
35 // Disable project functions (they should be created only once)
36 if ( !enableProjectFunctions )
37 {
38 QStandardItem *item = qobject_cast<QStandardItemModel *>( cboFileOptions->model() )->item( 1 );
39 item->setFlags( item->flags() & ~Qt::ItemIsEnabled );
40 }
41
42 connect( cboFileOptions, qOverload<int>( &QComboBox::currentIndexChanged ), this, &QgsExpressionAddFunctionFileDialog::cboFileOptions_currentIndexChanged );
43 connect( txtNewFileName, &QLineEdit::textChanged, this, [this]( const QString & ) { updateOkButtonStatus(); } );
44 connect( buttonBox, &QDialogButtonBox::helpRequested, this, [] {
45 QgsHelp::openHelp( u"expressions/expression.html#function-editor"_s );
46 } );
47
48 updateOkButtonStatus();
49}
50
51void QgsExpressionAddFunctionFileDialog::cboFileOptions_currentIndexChanged( int )
52{
53 bool projectSelected = cboFileOptions->currentData() == "project"_L1;
54 lblNewFileName->setVisible( !projectSelected );
55 txtNewFileName->setVisible( !projectSelected );
56 updateOkButtonStatus();
57}
58
59void QgsExpressionAddFunctionFileDialog::updateOkButtonStatus()
60{
61 QPushButton *okBtn = buttonBox->button( QDialogButtonBox::StandardButton::Ok );
62 okBtn->setEnabled( true );
63
64 if ( cboFileOptions->currentData() != "project"_L1 )
65 {
66 okBtn->setEnabled( !txtNewFileName->text().trimmed().isEmpty() );
67 }
68}
69
71{
72 return cboFileOptions->currentData() == "project"_L1;
73}
74
76{
77 return txtNewFileName->text().trimmed();
78}
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:41