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