The old code used manual memory mangement (raw new/delete) to (de)allocate the Ui struct. This is so 80s. Use an owning smart pointer to manage the memory. Ordinarily, this would have been QScopedPointer, but seeing as that doesn't have a create() method to hide the raw new, use std::unique_ptr and std::make_unique() instead. Amends 2690822428deec4f0c08f4d118d69a7c6036369e. Change-Id: Icabb9154eb38630855e14094b958af0214516f6b Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io> (cherry picked from commit 0da2c2c4ef2219967db87021eece2a60b6e207af) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org> (cherry picked from commit 88600c30964bc1d11ed09e3dddd4cbe4477f02d3)
74 lines
1.6 KiB
C++
74 lines
1.6 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{std::make_unique<Ui::QSqlConnectionDialogUi>()}
|
|
{
|
|
m_ui->setupUi(this);
|
|
|
|
QStringList drivers = QSqlDatabase::drivers();
|
|
|
|
if (!drivers.contains("QSQLITE"))
|
|
m_ui->dbCheckBox->setEnabled(false);
|
|
|
|
m_ui->comboDriver->addItems(drivers);
|
|
}
|
|
|
|
QSqlConnectionDialog::~QSqlConnectionDialog()
|
|
= default;
|
|
|
|
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::accept()
|
|
{
|
|
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 {
|
|
QDialog::accept();
|
|
}
|
|
}
|