mirror of
https://github.com/fralx/LimeReport.git
synced 2025-09-30 19:19:56 +03:00
defaultConnection support has been added to LimeReport designer
This commit is contained in:
@@ -41,7 +41,7 @@ namespace LimeReport{
|
||||
|
||||
ConnectionDialog::ConnectionDialog(LimeReport::IConnectionController *conControl, LimeReport::ConnectionDesc* connectionDesc, QWidget *parent) :
|
||||
QDialog(parent),
|
||||
ui(new Ui::ConnectionDialog),m_connection(connectionDesc),m_controller(conControl)
|
||||
ui(new Ui::ConnectionDialog), m_connection(connectionDesc), m_controller(conControl), m_savedConnectionName("")
|
||||
{
|
||||
ui->setupUi(this);
|
||||
setAttribute(Qt::WA_DeleteOnClose,true);
|
||||
@@ -56,6 +56,7 @@ ConnectionDialog::~ConnectionDialog()
|
||||
void ConnectionDialog::init()
|
||||
{
|
||||
ui->cbbDrivers->addItems(QSqlDatabase::drivers());
|
||||
ui->cbbUseDefaultConnection->setEnabled(!m_controller->containsDefaultConnection());
|
||||
}
|
||||
|
||||
void ConnectionDialog::showEvent(QShowEvent *)
|
||||
@@ -101,27 +102,20 @@ void ConnectionDialog::checkFieldsFill()
|
||||
bool ConnectionDialog::checkConnection()
|
||||
{
|
||||
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());
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
LimeReport::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(ui->leConnectionName->text());
|
||||
result ->setName(ConnectionDesc::connectionNameForReport(ui->leConnectionName->text()));
|
||||
result ->setHost(ui->leServerName->text());
|
||||
result ->setDriver(ui->cbbDrivers->currentText());
|
||||
result ->setUserName(ui->leUserName->text());
|
||||
@@ -135,7 +129,8 @@ void ConnectionDialog::connectionToUI()
|
||||
{
|
||||
init();
|
||||
if (!m_connection) return;
|
||||
ui->leConnectionName->setText(m_connection->name());
|
||||
ui->leConnectionName->setText(ConnectionDesc::connectionNameForUser(m_connection->name()));
|
||||
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());
|
||||
@@ -144,10 +139,26 @@ void ConnectionDialog::connectionToUI()
|
||||
ui->cbAutoConnect->setChecked(m_connection->autoconnect());
|
||||
}
|
||||
|
||||
|
||||
void ConnectionDialog::on_toolButton_clicked()
|
||||
{
|
||||
ui->leDataBase->setText(QFileDialog::getOpenFileName());
|
||||
}
|
||||
|
||||
void ConnectionDialog::on_cbbUseDefaultConnection_toggled(bool checked)
|
||||
{
|
||||
if (checked){
|
||||
m_savedConnectionName = ui->leConnectionName->text();
|
||||
ui->leConnectionName->setText(tr("defaultConnection"));
|
||||
ui->leConnectionName->setEnabled(false);
|
||||
} else {
|
||||
ui->leConnectionName->setText(m_savedConnectionName);
|
||||
ui->leConnectionName->setEnabled(true);
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace LimeReport
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user