mirror of
https://github.com/fralx/LimeReport.git
synced 2025-10-07 13:23:59 +03:00
Added ability to use variables in the connection settings
This commit is contained in:
@@ -69,7 +69,7 @@ void ConnectionDialog::slotAccept()
|
||||
if (!m_connection){
|
||||
m_controller->addConnectionDesc(uiToConnection());
|
||||
} else {
|
||||
m_controller->changeConnectionDesc(uiToConnection());
|
||||
m_controller->changeConnectionDesc(uiToConnection(m_connection));
|
||||
}
|
||||
close();
|
||||
}
|
||||
@@ -98,35 +98,35 @@ void ConnectionDialog::checkFieldsFill()
|
||||
|
||||
bool ConnectionDialog::checkConnection()
|
||||
{
|
||||
bool connectionEstablished = false;
|
||||
QString lastError;
|
||||
{
|
||||
QSqlDatabase db = QSqlDatabase::addDatabase(ui->cbbDrivers->currentText(),ui->leConnectionName->text()+"_check");
|
||||
db.setHostName(ui->leServerName->text());
|
||||
db.setUserName(ui->leUserName->text());
|
||||
db.setDatabaseName(ui->leDataBase->text());
|
||||
db.setPassword(ui->lePassword->text());
|
||||
connectionEstablished = db.open();
|
||||
if (!db.open()) {
|
||||
lastError=db.lastError().text();
|
||||
}
|
||||
QScopedPointer<LimeReport::ConnectionDesc> con(uiToConnection());
|
||||
// LimeReport::ConnectionDesc con;
|
||||
// con.setName(ui->leConnectionName->text()+"_check");
|
||||
// con.setHost(ui->leServerName->text());
|
||||
// con.setUserName(ui->leUserName->text());
|
||||
// con.setPassword(ui->lePassword->text());
|
||||
// con.setDatabaseName(ui->leDataBase->text());
|
||||
// con.setDriver(ui->cbbDrivers->currentText());
|
||||
if (!m_controller->checkConnectionDesc(con.data())){
|
||||
throw LimeReport::ReportError(m_controller->lastError());
|
||||
}
|
||||
QSqlDatabase::removeDatabase(ui->leConnectionName->text()+"_check");
|
||||
if (!connectionEstablished) throw LimeReport::ReportError(lastError);
|
||||
return true;
|
||||
}
|
||||
|
||||
LimeReport::ConnectionDesc *ConnectionDialog::uiToConnection()
|
||||
LimeReport::ConnectionDesc *ConnectionDialog::uiToConnection(LimeReport::ConnectionDesc* conDesc)
|
||||
{
|
||||
if (!m_connection) m_connection = new LimeReport::ConnectionDesc();
|
||||
m_connection->setName(ui->leConnectionName->text());
|
||||
m_connection->setHost(ui->leServerName->text());
|
||||
m_connection->setDriver(ui->cbbDrivers->currentText());
|
||||
m_connection->setUserName(ui->leUserName->text());
|
||||
m_connection->setPassword(ui->lePassword->text());
|
||||
m_connection->setDatabaseName(ui->leDataBase->text());
|
||||
m_connection->setAutoconnect(ui->cbAutoConnect->isChecked());
|
||||
return m_connection;
|
||||
LimeReport::ConnectionDesc* result;
|
||||
if (conDesc)
|
||||
result = conDesc;
|
||||
else
|
||||
result = new LimeReport::ConnectionDesc();
|
||||
result ->setName(ui->leConnectionName->text());
|
||||
result ->setHost(ui->leServerName->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());
|
||||
return result ;
|
||||
}
|
||||
|
||||
void ConnectionDialog::connectionToUI()
|
||||
|
@@ -48,7 +48,7 @@ protected:
|
||||
void init();
|
||||
void checkFieldsFill();
|
||||
bool checkConnection();
|
||||
LimeReport::ConnectionDesc* uiToConnection();
|
||||
LimeReport::ConnectionDesc* uiToConnection(LimeReport::ConnectionDesc *conDesc = 0);
|
||||
void connectionToUI();
|
||||
signals:
|
||||
void conectionRegistred(LimeReport::ConnectionDesc* connectionDesc);
|
||||
@@ -56,7 +56,6 @@ private slots:
|
||||
void slotAccept();
|
||||
void slotCheckConnection();
|
||||
void on_toolButton_clicked();
|
||||
|
||||
private:
|
||||
Ui::ConnectionDialog *ui;
|
||||
LimeReport::ConnectionDesc* m_connection;
|
||||
|
@@ -595,11 +595,27 @@ void DataBrowser::addConnectionDesc(ConnectionDesc *connection)
|
||||
|
||||
void DataBrowser::changeConnectionDesc(ConnectionDesc *connection)
|
||||
{
|
||||
Q_UNUSED(connection)
|
||||
if (connection->autoconnect()) m_report->dataManager()->connectConnection(connection->name());
|
||||
updateDataTree();
|
||||
}
|
||||
|
||||
bool DataBrowser::checkConnectionDesc(ConnectionDesc *connection)
|
||||
{
|
||||
bool result = m_report->dataManager()->checkConnectionDesc(connection);
|
||||
if (!result) setLastError(m_report->dataManager()->lastError());
|
||||
return result;
|
||||
}
|
||||
|
||||
QString DataBrowser::lastError() const
|
||||
{
|
||||
return m_lastError;
|
||||
}
|
||||
|
||||
void DataBrowser::setLastError(const QString &lastError)
|
||||
{
|
||||
m_lastError = lastError;
|
||||
}
|
||||
|
||||
void DataBrowser::on_dataTree_currentItemChanged(QTreeWidgetItem *current, QTreeWidgetItem *previous)
|
||||
{
|
||||
Q_UNUSED(previous)
|
||||
|
@@ -59,6 +59,9 @@ public:
|
||||
void closeAllDataWindows();
|
||||
void setSettings(QSettings* value, bool owned = false);
|
||||
QSettings* settings();
|
||||
QString lastError() const;
|
||||
void setLastError(const QString &lastError);
|
||||
|
||||
private slots:
|
||||
void slotDatasourcesChanged();
|
||||
void slotAddConnection();
|
||||
@@ -100,6 +103,7 @@ private:
|
||||
|
||||
void addConnectionDesc(ConnectionDesc *connection);
|
||||
void changeConnectionDesc(ConnectionDesc *connection);
|
||||
bool checkConnectionDesc(ConnectionDesc *connection);
|
||||
|
||||
private:
|
||||
Ui::DataBrowser* ui;
|
||||
@@ -109,6 +113,7 @@ private:
|
||||
bool m_closingWindows;
|
||||
QSettings* m_settings;
|
||||
bool m_ownedSettings;
|
||||
QString m_lastError;
|
||||
};
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user