mirror of
https://github.com/fralx/LimeReport.git
synced 2025-11-25 00:18:06 +03:00
Define code style and format all source file using clang-format-14
except those placed in 3rdparty directories.
This commit is contained in:
@@ -29,111 +29,118 @@
|
||||
****************************************************************************/
|
||||
#include "lrconnectiondialog.h"
|
||||
#include "ui_lrconnectiondialog.h"
|
||||
|
||||
#include "lrglobal.h"
|
||||
|
||||
#include <QDebug>
|
||||
#include <QFileDialog>
|
||||
#include <QMessageBox>
|
||||
#include <QSqlDatabase>
|
||||
#include <QSqlError>
|
||||
#include <QDebug>
|
||||
#include <QMessageBox>
|
||||
|
||||
#include <stdexcept>
|
||||
#include <QFileDialog>
|
||||
|
||||
namespace LimeReport{
|
||||
namespace LimeReport {
|
||||
|
||||
ConnectionDialog::ConnectionDialog(LimeReport::IConnectionController *conControl, LimeReport::ConnectionDesc* connectionDesc, QWidget *parent) :
|
||||
ConnectionDialog::ConnectionDialog(LimeReport::IConnectionController* conControl,
|
||||
LimeReport::ConnectionDesc* connectionDesc, QWidget* parent):
|
||||
QDialog(parent),
|
||||
ui(new Ui::ConnectionDialog), m_connection(connectionDesc), m_controller(conControl), m_savedConnectionName("")
|
||||
ui(new Ui::ConnectionDialog),
|
||||
m_connection(connectionDesc),
|
||||
m_controller(conControl),
|
||||
m_savedConnectionName("")
|
||||
{
|
||||
ui->setupUi(this);
|
||||
setAttribute(Qt::WA_DeleteOnClose,true);
|
||||
m_changeMode=m_connection!=0;
|
||||
setAttribute(Qt::WA_DeleteOnClose, true);
|
||||
m_changeMode = m_connection != 0;
|
||||
}
|
||||
|
||||
ConnectionDialog::~ConnectionDialog()
|
||||
{
|
||||
delete ui;
|
||||
}
|
||||
ConnectionDialog::~ConnectionDialog() { delete ui; }
|
||||
|
||||
void ConnectionDialog::init()
|
||||
{
|
||||
ui->cbbDrivers->addItems(QSqlDatabase::drivers());
|
||||
ui->cbbUseDefaultConnection->setEnabled(!m_controller->containsDefaultConnection());
|
||||
ui->cbbDrivers->addItems(QSqlDatabase::drivers());
|
||||
ui->cbbUseDefaultConnection->setEnabled(!m_controller->containsDefaultConnection());
|
||||
}
|
||||
|
||||
void ConnectionDialog::showEvent(QShowEvent *)
|
||||
{
|
||||
connectionToUI();
|
||||
}
|
||||
void ConnectionDialog::showEvent(QShowEvent*) { connectionToUI(); }
|
||||
|
||||
void ConnectionDialog::slotAccept()
|
||||
{
|
||||
try {
|
||||
checkFieldsFill();
|
||||
if (ui->cbAutoConnect->isChecked()) checkConnection();
|
||||
if (!m_connection){
|
||||
if (ui->cbAutoConnect->isChecked())
|
||||
checkConnection();
|
||||
if (!m_connection) {
|
||||
m_controller->addConnectionDesc(uiToConnection());
|
||||
} else {
|
||||
m_controller->changeConnectionDesc(uiToConnection(m_connection));
|
||||
}
|
||||
close();
|
||||
}
|
||||
catch(LimeReport::ReportError &exception){
|
||||
QMessageBox::critical(this,tr("Error"),exception.what());
|
||||
} catch (LimeReport::ReportError& exception) {
|
||||
QMessageBox::critical(this, tr("Error"), exception.what());
|
||||
}
|
||||
}
|
||||
|
||||
void ConnectionDialog::slotCheckConnection()
|
||||
{
|
||||
try{
|
||||
try {
|
||||
checkConnection();
|
||||
QMessageBox::information(this,tr("Connection"),tr("Connection succsesfully established!"));
|
||||
} catch(LimeReport::ReportError &exception) {
|
||||
QMessageBox::critical(this,tr("Error"),exception.what());
|
||||
QMessageBox::information(this, tr("Connection"),
|
||||
tr("Connection succsesfully established!"));
|
||||
} catch (LimeReport::ReportError& exception) {
|
||||
QMessageBox::critical(this, tr("Error"), exception.what());
|
||||
}
|
||||
}
|
||||
|
||||
void ConnectionDialog::checkFieldsFill()
|
||||
{
|
||||
if (ui->leConnectionName->text().isEmpty()){throw LimeReport::ReportError(tr("Connection Name is empty"));}
|
||||
if (!m_changeMode&&QSqlDatabase::connectionNames().contains(ui->leConnectionName->text())) {
|
||||
throw LimeReport::ReportError(tr("Connection with name ")+ui->leConnectionName->text()+tr(" already exists! "));
|
||||
if (ui->leConnectionName->text().isEmpty()) {
|
||||
throw LimeReport::ReportError(tr("Connection Name is empty"));
|
||||
}
|
||||
if (!m_changeMode && QSqlDatabase::connectionNames().contains(ui->leConnectionName->text())) {
|
||||
throw LimeReport::ReportError(tr("Connection with name ") + ui->leConnectionName->text()
|
||||
+ tr(" already exists! "));
|
||||
}
|
||||
}
|
||||
|
||||
bool ConnectionDialog::checkConnection()
|
||||
{
|
||||
QScopedPointer<LimeReport::ConnectionDesc> con(uiToConnection());
|
||||
if (!m_controller->checkConnectionDesc(con.data())){
|
||||
if (!m_controller->checkConnectionDesc(con.data())) {
|
||||
throw LimeReport::ReportError(m_controller->lastError());
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
ConnectionDesc *ConnectionDialog::uiToConnection(LimeReport::ConnectionDesc* conDesc)
|
||||
ConnectionDesc* ConnectionDialog::uiToConnection(LimeReport::ConnectionDesc* conDesc)
|
||||
{
|
||||
LimeReport::ConnectionDesc* result;
|
||||
if (conDesc)
|
||||
result = conDesc;
|
||||
else
|
||||
result = new LimeReport::ConnectionDesc();
|
||||
result ->setName(ConnectionDesc::connectionNameForReport(ui->leConnectionName->text()));
|
||||
result ->setHost(ui->leServerName->text());
|
||||
result->setName(ConnectionDesc::connectionNameForReport(ui->leConnectionName->text()));
|
||||
result->setHost(ui->leServerName->text());
|
||||
if (!ui->lePort->text().isEmpty())
|
||||
result->setPort(ui->lePort->text());
|
||||
result ->setDriver(ui->cbbDrivers->currentText());
|
||||
result ->setUserName(ui->leUserName->text());
|
||||
result ->setPassword(ui->lePassword->text());
|
||||
result ->setDatabaseName(ui->leDataBase->text());
|
||||
result ->setAutoconnect(ui->cbAutoConnect->isChecked());
|
||||
result->setDriver(ui->cbbDrivers->currentText());
|
||||
result->setUserName(ui->leUserName->text());
|
||||
result->setPassword(ui->lePassword->text());
|
||||
result->setDatabaseName(ui->leDataBase->text());
|
||||
result->setAutoconnect(ui->cbAutoConnect->isChecked());
|
||||
result->setKeepDBCredentials(!ui->cbbKeepCredentials->isChecked());
|
||||
return result ;
|
||||
return result;
|
||||
}
|
||||
|
||||
void ConnectionDialog::connectionToUI()
|
||||
{
|
||||
init();
|
||||
if (!m_connection) return;
|
||||
if (!m_connection)
|
||||
return;
|
||||
ui->leConnectionName->setText(ConnectionDesc::connectionNameForUser(m_connection->name()));
|
||||
ui->cbbUseDefaultConnection->setChecked(m_connection->name().compare(QSqlDatabase::defaultConnection) == 0);
|
||||
ui->cbbUseDefaultConnection->setChecked(
|
||||
m_connection->name().compare(QSqlDatabase::defaultConnection) == 0);
|
||||
ui->leDataBase->setText(m_connection->databaseName());
|
||||
ui->leServerName->setText(m_connection->host());
|
||||
ui->leUserName->setText(m_connection->userName());
|
||||
@@ -151,7 +158,7 @@ void ConnectionDialog::on_toolButton_clicked()
|
||||
|
||||
void ConnectionDialog::on_cbbUseDefaultConnection_toggled(bool checked)
|
||||
{
|
||||
if (checked){
|
||||
if (checked) {
|
||||
m_savedConnectionName = ui->leConnectionName->text();
|
||||
ui->leConnectionName->setText(tr("defaultConnection"));
|
||||
ui->leConnectionName->setEnabled(false);
|
||||
@@ -166,10 +173,3 @@ void ConnectionDialog::on_toolButton_2_toggled(bool checked)
|
||||
}
|
||||
|
||||
} // namespace LimeReport
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user