2022-05-10 10:06:48 +00:00
|
|
|
// Copyright (C) 2016 The Qt Company Ltd.
|
|
|
|
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
#include "qsqlconnectiondialog.h"
|
2024-01-12 21:25:23 +00:00
|
|
|
#include <ui_qsqlconnectiondialog.h>
|
2011-04-27 10:05:43 +00:00
|
|
|
|
2024-01-12 21:25:23 +00:00
|
|
|
#include <QCheckBox>
|
|
|
|
#include <QMessageBox>
|
|
|
|
#include <QPushButton>
|
2011-04-27 10:05:43 +00:00
|
|
|
#include <QSqlDatabase>
|
|
|
|
|
|
|
|
QSqlConnectionDialog::QSqlConnectionDialog(QWidget *parent)
|
|
|
|
: QDialog(parent)
|
2024-12-31 09:03:41 +00:00
|
|
|
, m_ui{std::make_unique<Ui::QSqlConnectionDialogUi>()}
|
2011-04-27 10:05:43 +00:00
|
|
|
{
|
2024-01-12 21:25:23 +00:00
|
|
|
m_ui->setupUi(this);
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
QStringList drivers = QSqlDatabase::drivers();
|
|
|
|
|
|
|
|
if (!drivers.contains("QSQLITE"))
|
2024-01-12 21:25:23 +00:00
|
|
|
m_ui->dbCheckBox->setEnabled(false);
|
2011-04-27 10:05:43 +00:00
|
|
|
|
2024-01-12 21:25:23 +00:00
|
|
|
m_ui->comboDriver->addItems(drivers);
|
2011-04-27 10:05:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
QSqlConnectionDialog::~QSqlConnectionDialog()
|
2024-12-31 09:03:41 +00:00
|
|
|
= default;
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
QString QSqlConnectionDialog::driverName() const
|
|
|
|
{
|
2024-01-12 21:25:23 +00:00
|
|
|
return m_ui->comboDriver->currentText();
|
2011-04-27 10:05:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
QString QSqlConnectionDialog::databaseName() const
|
|
|
|
{
|
2024-01-12 21:25:23 +00:00
|
|
|
return m_ui->editDatabase->text();
|
2011-04-27 10:05:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
QString QSqlConnectionDialog::userName() const
|
|
|
|
{
|
2024-01-12 21:25:23 +00:00
|
|
|
return m_ui->editUsername->text();
|
2011-04-27 10:05:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
QString QSqlConnectionDialog::password() const
|
|
|
|
{
|
2024-01-12 21:25:23 +00:00
|
|
|
return m_ui->editPassword->text();
|
2011-04-27 10:05:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
QString QSqlConnectionDialog::hostName() const
|
|
|
|
{
|
2024-01-12 21:25:23 +00:00
|
|
|
return m_ui->editHostname->text();
|
2011-04-27 10:05:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int QSqlConnectionDialog::port() const
|
|
|
|
{
|
2024-01-12 21:25:23 +00:00
|
|
|
return m_ui->portSpinBox->value();
|
2011-04-27 10:05:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool QSqlConnectionDialog::useInMemoryDatabase() const
|
|
|
|
{
|
2024-01-12 21:25:23 +00:00
|
|
|
return m_ui->dbCheckBox->isChecked();
|
2011-04-27 10:05:43 +00:00
|
|
|
}
|
|
|
|
|
sqlbrowser example: use idiomatic Qt [2/3]: use button-box / override accept()
- The old code used two QPushButtons in a QHBoxLayout to provide
Ok/Cancel buttons. This hard-codes the positions and text (and
icons) of these buttons, instead of adapting to the platform style.
The new code simply uses QDialogButtonBox, which is designed for
this purpose.
- Also, the old code connected the Ok button's clicked() signal to a
custom slot that then called QDialog::accept(). This means that the
code in the custom slot is not executed when the dialog is accepted
by other means (e.g. return press in one of the line edits
("auto-default"), though I'm not sure here).
The new code uses the idiomatic Qt way of overriding
QDialog::accept() instead, and connects the button-box's accepted()
signal to it. This is done in the .ui file, so it already works in
Designer preview.
- Finally, the old code made a manual connection from the Cancel
button to QDialog::reject().
The new code uses the Qt idiom of connecting in the .ui file
directly, using QDialogButtonBox::rejected() as the signal.
Amends 2690822428deec4f0c08f4d118d69a7c6036369e, which, however,
inherited all of the above from even older code.
Pick-to: 6.9 6.8
Change-Id: I83afd6156a0811e0c0f99f2480625ea6b69ff78b
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
2024-12-31 09:03:41 +00:00
|
|
|
void QSqlConnectionDialog::accept()
|
2011-04-27 10:05:43 +00:00
|
|
|
{
|
2024-01-12 21:25:23 +00:00
|
|
|
if (m_ui->comboDriver->currentText().isEmpty()) {
|
2011-04-27 10:05:43 +00:00
|
|
|
QMessageBox::information(this, tr("No database driver selected"),
|
|
|
|
tr("Please select a database driver"));
|
2024-01-12 21:25:23 +00:00
|
|
|
m_ui->comboDriver->setFocus();
|
2011-04-27 10:05:43 +00:00
|
|
|
} else {
|
sqlbrowser example: use idiomatic Qt [2/3]: use button-box / override accept()
- The old code used two QPushButtons in a QHBoxLayout to provide
Ok/Cancel buttons. This hard-codes the positions and text (and
icons) of these buttons, instead of adapting to the platform style.
The new code simply uses QDialogButtonBox, which is designed for
this purpose.
- Also, the old code connected the Ok button's clicked() signal to a
custom slot that then called QDialog::accept(). This means that the
code in the custom slot is not executed when the dialog is accepted
by other means (e.g. return press in one of the line edits
("auto-default"), though I'm not sure here).
The new code uses the idiomatic Qt way of overriding
QDialog::accept() instead, and connects the button-box's accepted()
signal to it. This is done in the .ui file, so it already works in
Designer preview.
- Finally, the old code made a manual connection from the Cancel
button to QDialog::reject().
The new code uses the Qt idiom of connecting in the .ui file
directly, using QDialogButtonBox::rejected() as the signal.
Amends 2690822428deec4f0c08f4d118d69a7c6036369e, which, however,
inherited all of the above from even older code.
Pick-to: 6.9 6.8
Change-Id: I83afd6156a0811e0c0f99f2480625ea6b69ff78b
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
2024-12-31 09:03:41 +00:00
|
|
|
QDialog::accept();
|
2011-04-27 10:05:43 +00:00
|
|
|
}
|
|
|
|
}
|