qtbase/examples/sql/sqlbrowser/qsqlconnectiondialog.cpp
Marc Mutz f2b88b3225 sqlbrowser example: use idiomatic Qt [1/3]: disabling group-box
The old code connected to the wrong signal and therefore had to write
a custom slot to perform the disabling of the group-box.

The new code simply connects the QCheckBox::toggled(bool) signal to
the directly-compatible QWidget::setDisabled(bool) slot, removing the
need for a custom slot.

Also move the connection into the .ui file, so it works already when
checking the form in QtDesigner.

Amends 2690822428deec4f0c08f4d118d69a7c6036369e, which, however, only
inherited the issues from older code.

Pick-to: 6.8
Change-Id: Ia834f92de270bb7b18981273188f6e5b6cd457a2
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
(cherry picked from commit 53826d1cde26f825d1983476c6697f72130e351f)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
2025-01-02 09:57:17 +00:00

81 lines
1.8 KiB
C++

// Copyright (C) 2016 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
#include "qsqlconnectiondialog.h"
#include <ui_qsqlconnectiondialog.h>
#include <QCheckBox>
#include <QMessageBox>
#include <QPushButton>
#include <QSqlDatabase>
QSqlConnectionDialog::QSqlConnectionDialog(QWidget *parent)
: QDialog(parent)
, m_ui(new Ui::QSqlConnectionDialogUi)
{
m_ui->setupUi(this);
QStringList drivers = QSqlDatabase::drivers();
if (!drivers.contains("QSQLITE"))
m_ui->dbCheckBox->setEnabled(false);
m_ui->comboDriver->addItems(drivers);
connect(m_ui->okButton, &QPushButton::clicked,
this, &QSqlConnectionDialog::onOkButton);
connect(m_ui->cancelButton, &QPushButton::clicked,
this, &QSqlConnectionDialog::reject);
}
QSqlConnectionDialog::~QSqlConnectionDialog()
{
delete m_ui;
}
QString QSqlConnectionDialog::driverName() const
{
return m_ui->comboDriver->currentText();
}
QString QSqlConnectionDialog::databaseName() const
{
return m_ui->editDatabase->text();
}
QString QSqlConnectionDialog::userName() const
{
return m_ui->editUsername->text();
}
QString QSqlConnectionDialog::password() const
{
return m_ui->editPassword->text();
}
QString QSqlConnectionDialog::hostName() const
{
return m_ui->editHostname->text();
}
int QSqlConnectionDialog::port() const
{
return m_ui->portSpinBox->value();
}
bool QSqlConnectionDialog::useInMemoryDatabase() const
{
return m_ui->dbCheckBox->isChecked();
}
void QSqlConnectionDialog::onOkButton()
{
if (m_ui->comboDriver->currentText().isEmpty()) {
QMessageBox::information(this, tr("No database driver selected"),
tr("Please select a database driver"));
m_ui->comboDriver->setFocus();
} else {
accept();
}
}