Skip to content

Commit

Permalink
[ux] don't enable OK button in new connection dialogs if required fields
Browse files Browse the repository at this point in the history
are empty (fix #26038)
  • Loading branch information
alexbruy committed Apr 23, 2020
1 parent 2239b30 commit e2f106b
Show file tree
Hide file tree
Showing 15 changed files with 108 additions and 3 deletions.
13 changes: 13 additions & 0 deletions src/gui/ogr/qgsnewogrconnection.cpp
Expand Up @@ -41,6 +41,12 @@ QgsNewOgrConnection::QgsNewOgrConnection( QWidget *parent, const QString &connTy
connect( buttonBox, &QDialogButtonBox::helpRequested, this, &QgsNewOgrConnection::showHelp );
Q_NOWARN_DEPRECATED_POP

buttonBox->button( QDialogButtonBox::Ok )->setDisabled( true );
connect( txtName, &QLineEdit::textChanged, this, &QgsNewOgrConnection::updateOkButtonState );
connect( txtHost, &QLineEdit::textChanged, this, &QgsNewOgrConnection::updateOkButtonState );
connect( txtDatabase, &QLineEdit::textChanged, this, &QgsNewOgrConnection::updateOkButtonState );
connect( txtPort, &QLineEdit::textChanged, this, &QgsNewOgrConnection::updateOkButtonState );

QgsSettings settings;

//add database drivers
Expand Down Expand Up @@ -115,6 +121,13 @@ void QgsNewOgrConnection::showHelp()
QgsHelp::openHelp( QStringLiteral( "managing_data_source/opening_data.html#creating-a-stored-connection" ) );
}

void QgsNewOgrConnection::updateOkButtonState()
{
bool enabled = !txtName->text().isEmpty() && !txtHost->text().isEmpty() && !txtDatabase->text().isEmpty() && !txtPort->text().isEmpty();
buttonBox->button( QDialogButtonBox::Ok )->setEnabled( enabled );
}


//! Autoconnected SLOTS *
void QgsNewOgrConnection::accept()
{
Expand Down
1 change: 1 addition & 0 deletions src/gui/ogr/qgsnewogrconnection.h
Expand Up @@ -52,6 +52,7 @@ class GUI_EXPORT QgsNewOgrConnection : public QDialog, private Ui::QgsNewOgrConn

public slots:
void accept() override;
void updateOkButtonState();

private slots:
void btnConnect_clicked();
Expand Down
12 changes: 12 additions & 0 deletions src/gui/vectortile/qgsvectortileconnectiondialog.cpp
Expand Up @@ -16,7 +16,9 @@
#include "qgsvectortileconnectiondialog.h"
#include "qgsvectortileconnection.h"
#include "qgsgui.h"

#include <QMessageBox>
#include <QPushButton>

///@cond PRIVATE

Expand All @@ -29,6 +31,10 @@ QgsVectorTileConnectionDialog::QgsVectorTileConnectionDialog( QWidget *parent )
// Behavior for min and max zoom checkbox
connect( mCheckBoxZMin, &QCheckBox::toggled, mSpinZMin, &QSpinBox::setEnabled );
connect( mCheckBoxZMax, &QCheckBox::toggled, mSpinZMax, &QSpinBox::setEnabled );

buttonBox->button( QDialogButtonBox::Ok )->setDisabled( true );
connect( mEditName, &QLineEdit::textChanged, this, &QgsVectorTileConnectionDialog::updateOkButtonState );
connect( mEditUrl, &QLineEdit::textChanged, this, &QgsVectorTileConnectionDialog::updateOkButtonState );
}

void QgsVectorTileConnectionDialog::setConnection( const QString &name, const QString &uri )
Expand Down Expand Up @@ -59,6 +65,12 @@ QString QgsVectorTileConnectionDialog::connectionName() const
return mEditName->text();
}

void QgsVectorTileConnectionDialog::updateOkButtonState()
{
bool enabled = !mEditName->text().isEmpty() && !mEditUrl->text().isEmpty();
buttonBox->button( QDialogButtonBox::Ok )->setEnabled( enabled );
}

void QgsVectorTileConnectionDialog::accept()
{
if ( mCheckBoxZMin->isChecked() && mCheckBoxZMax->isChecked() && mSpinZMax->value() < mSpinZMin->value() )
Expand Down
4 changes: 3 additions & 1 deletion src/gui/vectortile/qgsvectortileconnectiondialog.h
Expand Up @@ -37,8 +37,10 @@ class QgsVectorTileConnectionDialog : public QDialog, public Ui::QgsVectorTileCo

void accept() override;

private:
private slots:
void updateOkButtonState();

private:
QString mBaseKey;
QString mCredentialsBaseKey;
};
Expand Down
16 changes: 16 additions & 0 deletions src/providers/db2/qgsdb2newconnection.cpp
Expand Up @@ -38,6 +38,14 @@ QgsDb2NewConnection::QgsDb2NewConnection( QWidget *parent, const QString &connNa
connect( btnConnect, &QPushButton::clicked, this, &QgsDb2NewConnection::btnConnect_clicked );
connect( buttonBox, &QDialogButtonBox::helpRequested, this, &QgsDb2NewConnection::showHelp );

buttonBox->button( QDialogButtonBox::Ok )->setDisabled( true );
connect( txtName, &QLineEdit::textChanged, this, &QgsDb2NewConnection::updateOkButtonState );
connect( txtService, &QLineEdit::textChanged, this, &QgsDb2NewConnection::updateOkButtonState );
connect( txtDriver, &QLineEdit::textChanged, this, &QgsDb2NewConnection::updateOkButtonState );
connect( txtHost, &QLineEdit::textChanged, this, &QgsDb2NewConnection::updateOkButtonState );
connect( txtPort, &QLineEdit::textChanged, this, &QgsDb2NewConnection::updateOkButtonState );
connect( txtDatabase, &QLineEdit::textChanged, this, &QgsDb2NewConnection::updateOkButtonState );

mAuthSettings->setDataprovider( QStringLiteral( "db2" ) );
mAuthSettings->showStoreCheckboxes( true );

Expand Down Expand Up @@ -200,3 +208,11 @@ void QgsDb2NewConnection::showHelp()
{
QgsHelp::openHelp( QStringLiteral( "managing_data_source/opening_data.html#connecting-to-db2-spatial" ) );
}

void QgsDb2NewConnection::updateOkButtonState()
{
bool enabled = !txtName->text().isEmpty() && (
( !txtService->text().isEmpty() && !txtDatabase->text().isEmpty() ) ||
( !txtDriver->text().isEmpty() && !txtHost->text().isEmpty() && !txtPort->text().isEmpty() && !txtDatabase->text().isEmpty() ) );
buttonBox->button( QDialogButtonBox::Ok )->setEnabled( enabled );
}
2 changes: 2 additions & 0 deletions src/providers/db2/qgsdb2newconnection.h
Expand Up @@ -45,6 +45,8 @@ class QgsDb2NewConnection : public QDialog, private Ui::QgsDb2NewConnectionBase
void btnListDatabase_clicked();
void btnConnect_clicked();
void on_cb_trustedConnection_clicked();
private slots:
void updateOkButtonState();
private:
QString mOriginalConnName; //store initial name to delete entry in case of rename
void showHelp();
Expand Down
13 changes: 13 additions & 0 deletions src/providers/mssql/qgsmssqlnewconnection.cpp
Expand Up @@ -39,6 +39,12 @@ QgsMssqlNewConnection::QgsMssqlNewConnection( QWidget *parent, const QString &co
connect( cb_trustedConnection, &QCheckBox::clicked, this, &QgsMssqlNewConnection::cb_trustedConnection_clicked );
connect( buttonBox, &QDialogButtonBox::helpRequested, this, &QgsMssqlNewConnection::showHelp );

buttonBox->button( QDialogButtonBox::Ok )->setDisabled( true );
connect( txtName, &QLineEdit::textChanged, this, &QgsMssqlNewConnection::updateOkButtonState );
connect( txtService, &QLineEdit::textChanged, this, &QgsMssqlNewConnection::updateOkButtonState );
connect( txtHost, &QLineEdit::textChanged, this, &QgsMssqlNewConnection::updateOkButtonState );
connect( listDatabase, &QListWidget::currentItemChanged, this, &QgsMssqlNewConnection::updateOkButtonState );

lblWarning->hide();

if ( !connName.isEmpty() )
Expand Down Expand Up @@ -243,3 +249,10 @@ void QgsMssqlNewConnection::showHelp()
{
QgsHelp::openHelp( QStringLiteral( "managing_data_source/opening_data.html#connecting-to-mssql-spatial" ) );
}

void QgsMssqlNewConnection::updateOkButtonState()
{
QListWidgetItem *item = listDatabase->currentItem();
bool enabled = !txtName->text().isEmpty() && !txtService->text().isEmpty() && !txtHost->text().isEmpty() && item;
buttonBox->button( QDialogButtonBox::Ok )->setEnabled( enabled );
}
3 changes: 3 additions & 0 deletions src/providers/mssql/qgsmssqlnewconnection.h
Expand Up @@ -45,6 +45,9 @@ class QgsMssqlNewConnection : public QDialog, private Ui::QgsMssqlNewConnectionB
void btnListDatabase_clicked();
void btnConnect_clicked();
void cb_trustedConnection_clicked();

private slots:
void updateOkButtonState();
private:
QString mOriginalConnName; //store initial name to delete entry in case of rename
void showHelp();
Expand Down
12 changes: 12 additions & 0 deletions src/providers/oracle/qgsoraclenewconnection.cpp
Expand Up @@ -36,6 +36,12 @@ QgsOracleNewConnection::QgsOracleNewConnection( QWidget *parent, const QString &
connect( buttonBox, &QDialogButtonBox::helpRequested, this, &QgsOracleNewConnection::showHelp );
connect( btnConnect, &QPushButton::clicked, this, &QgsOracleNewConnection::testConnection );

buttonBox->button( QDialogButtonBox::Ok )->setDisabled( true );
connect( txtName, &QLineEdit::textChanged, this, &QgsOracleNewConnection::updateOkButtonState );
connect( txtDatabase, &QLineEdit::textChanged, this, &QgsOracleNewConnection::updateOkButtonState );
connect( txtHost, &QLineEdit::textChanged, this, &QgsOracleNewConnection::updateOkButtonState );
connect( txtPort, &QLineEdit::textChanged, this, &QgsOracleNewConnection::updateOkButtonState );

mAuthSettings->setDataprovider( QStringLiteral( "oracle" ) );
mAuthSettings->showStoreCheckboxes( true );

Expand Down Expand Up @@ -186,3 +192,9 @@ void QgsOracleNewConnection::showHelp()
{
QgsHelp::openHelp( QStringLiteral( "managing_data_source/opening_data.html#connecting-to-oracle-spatial" ) );
}

void QgsOracleNewConnection::updateOkButtonState()
{
bool enabled = !txtName->text().isEmpty() && !txtHost->text().isEmpty() && !txtPort->text().isEmpty() && !txtDatabase->text().isEmpty();
buttonBox->button( QDialogButtonBox::Ok )->setEnabled( enabled );
}
1 change: 1 addition & 0 deletions src/providers/oracle/qgsoraclenewconnection.h
Expand Up @@ -40,6 +40,7 @@ class QgsOracleNewConnection : public QDialog, private Ui::QgsOracleNewConnectio

private slots:
void testConnection();
void updateOkButtonState();

private:
QString mOriginalConnName; //store initial name to delete entry in case of rename
Expand Down
15 changes: 15 additions & 0 deletions src/providers/postgres/qgspgnewconnection.cpp
Expand Up @@ -38,6 +38,13 @@ QgsPgNewConnection::QgsPgNewConnection( QWidget *parent, const QString &connName
connect( cb_geometryColumnsOnly, &QCheckBox::clicked, this, &QgsPgNewConnection::cb_geometryColumnsOnly_clicked );
connect( buttonBox, &QDialogButtonBox::helpRequested, this, &QgsPgNewConnection::showHelp );

buttonBox->button( QDialogButtonBox::Ok )->setDisabled( true );
connect( txtName, &QLineEdit::textChanged, this, &QgsPgNewConnection::updateOkButtonState );
connect( txtService, &QLineEdit::textChanged, this, &QgsPgNewConnection::updateOkButtonState );
connect( txtHost, &QLineEdit::textChanged, this, &QgsPgNewConnection::updateOkButtonState );
connect( txtPort, &QLineEdit::textChanged, this, &QgsPgNewConnection::updateOkButtonState );
connect( txtDatabase, &QLineEdit::textChanged, this, &QgsPgNewConnection::updateOkButtonState );

cbxSSLmode->addItem( tr( "disable" ), QgsDataSourceUri::SslDisable );
cbxSSLmode->addItem( tr( "allow" ), QgsDataSourceUri::SslAllow );
cbxSSLmode->addItem( tr( "prefer" ), QgsDataSourceUri::SslPrefer );
Expand Down Expand Up @@ -238,3 +245,11 @@ void QgsPgNewConnection::showHelp()
{
QgsHelp::openHelp( QStringLiteral( "managing_data_source/opening_data.html#creating-a-stored-connection" ) );
}

void QgsPgNewConnection::updateOkButtonState()
{
bool enabled = !txtName->text().isEmpty() && (
( !txtService->text().isEmpty() && !txtDatabase->text().isEmpty() ) ||
( !txtHost->text().isEmpty() && !txtPort->text().isEmpty() && !txtDatabase->text().isEmpty() ) );
buttonBox->button( QDialogButtonBox::Ok )->setEnabled( enabled );
}
2 changes: 2 additions & 0 deletions src/providers/postgres/qgspgnewconnection.h
Expand Up @@ -38,6 +38,8 @@ class QgsPgNewConnection : public QDialog, private Ui::QgsPgNewConnectionBase
void accept() override;
void btnConnect_clicked();
void cb_geometryColumnsOnly_clicked();
private slots:
void updateOkButtonState();
private:
QString mOriginalConnName; //store initial name to delete entry in case of rename
void showHelp();
Expand Down
11 changes: 11 additions & 0 deletions src/providers/wms/qgsxyzconnectiondialog.cpp
Expand Up @@ -16,6 +16,7 @@
#include "qgsxyzconnectiondialog.h"
#include "qgsxyzconnection.h"
#include "qgsgui.h"

#include <QMessageBox>

QgsXyzConnectionDialog::QgsXyzConnectionDialog( QWidget *parent )
Expand All @@ -27,6 +28,10 @@ QgsXyzConnectionDialog::QgsXyzConnectionDialog( QWidget *parent )
// Behavior for min and max zoom checkbox
connect( mCheckBoxZMin, &QCheckBox::toggled, mSpinZMin, &QSpinBox::setEnabled );
connect( mCheckBoxZMax, &QCheckBox::toggled, mSpinZMax, &QSpinBox::setEnabled );

buttonBox->button( QDialogButtonBox::Ok )->setDisabled( true );
connect( mEditName, &QLineEdit::textChanged, this, &QgsXyzConnectionDialog::updateOkButtonState );
connect( mEditUrl, &QLineEdit::textChanged, this, &QgsXyzConnectionDialog::updateOkButtonState );
}

void QgsXyzConnectionDialog::setConnection( const QgsXyzConnection &conn )
Expand Down Expand Up @@ -71,6 +76,12 @@ QgsXyzConnection QgsXyzConnectionDialog::connection() const
return conn;
}

void QgsXyzConnectionDialog::updateOkButtonState()
{
bool enabled = !mEditName->text().isEmpty() && !mEditUrl->text().isEmpty();
buttonBox->button( QDialogButtonBox::Ok )->setEnabled( enabled );
}

void QgsXyzConnectionDialog::accept()
{
if ( mCheckBoxZMin->isChecked() && mCheckBoxZMax->isChecked() && mSpinZMax->value() < mSpinZMin->value() )
Expand Down
4 changes: 3 additions & 1 deletion src/providers/wms/qgsxyzconnectiondialog.h
Expand Up @@ -36,8 +36,10 @@ class QgsXyzConnectionDialog : public QDialog, public Ui::QgsXyzConnectionDialog

void accept() override;

private:
private slots:
void updateOkButtonState();

private:
QString mBaseKey;
QString mCredentialsBaseKey;
};
Expand Down
2 changes: 1 addition & 1 deletion src/ui/qgsxyzconnectiondialog.ui
Expand Up @@ -7,7 +7,7 @@
<x>0</x>
<y>0</y>
<width>636</width>
<height>624</height>
<height>331</height>
</rect>
</property>
<property name="windowTitle">
Expand Down

3 comments on commit e2f106b

@jgrocha
Copy link
Member

@jgrocha jgrocha commented on e2f106b May 1, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@alexbruy With this condition on updateOkButtonState() function, we are not able to create or edit Postgresql connections based on libpq. With libpq services, we don't have to enter a database name. The connection and service name are enough, since you can specify the database on the service file, like:

[recart11]
host=localhost
port=5433
dbname=recart11
user=geobox
password=geobox

I've just filled issue #36127 related to this.

What do you think @alexbruy?

@jgrocha
Copy link
Member

@jgrocha jgrocha commented on e2f106b May 1, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As far as I can see, it seems more adequate to impose that, if a service is specified, no database name should be entered, like:

bool enabled = !txtName->text().isEmpty() && (
                   ( !txtService->text().isEmpty() && txtDatabase->text().isEmpty() ) ||
                   ( !txtHost->text().isEmpty() && !txtPort->text().isEmpty() && !txtDatabase->text().isEmpty() ) );

Is this ok for @alexbruy?

@jgrocha
Copy link
Member

@jgrocha jgrocha commented on e2f106b May 1, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've submit a new PR#36129

I would be grateful if you can review it @alexbruy

Please sign in to comment.