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