Change to subforder project model.

This commit is contained in:
newsages
2016-03-21 02:12:30 +01:00
parent 9797b30d0a
commit 598d4f10ed
531 changed files with 167 additions and 2522 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 387 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 698 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 726 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 936 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 884 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 890 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1000 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 508 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 761 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 294 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 692 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 717 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 411 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 904 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 635 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 537 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 725 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 497 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 713 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 489 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 577 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 909 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 814 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 767 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 775 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 929 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 901 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 912 B

View File

@@ -0,0 +1,153 @@
/***************************************************************************
* This file is part of the Lime Report project *
* Copyright (C) 2015 by Alexander Arin *
* arin_a@bk.ru *
* *
** GNU General Public License Usage **
* *
* This library is free software: you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation, either version 3 of the License, or *
* (at your option) any later version. *
* You should have received a copy of the GNU General Public License *
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
* *
** GNU Lesser General Public License **
* *
* This library is free software: you can redistribute it and/or modify *
* it under the terms of the GNU Lesser General Public License as *
* published by the Free Software Foundation, either version 3 of the *
* License, or (at your option) any later version. *
* You should have received a copy of the GNU Lesser General Public *
* License along with this library. *
* If not, see <http://www.gnu.org/licenses/>. *
* *
* This library is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
****************************************************************************/
#include "lrconnectiondialog.h"
#include "ui_lrconnectiondialog.h"
#include "lrglobal.h"
#include <QSqlDatabase>
#include <QSqlError>
#include <QDebug>
#include <QMessageBox>
#include <stdexcept>
#include <QFileDialog>
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->setupUi(this);
setAttribute(Qt::WA_DeleteOnClose,true);
m_changeMode=m_connection!=0;
}
ConnectionDialog::~ConnectionDialog()
{
delete ui;
}
void ConnectionDialog::init()
{
ui->cbbDrivers->addItems(QSqlDatabase::drivers());
}
void ConnectionDialog::showEvent(QShowEvent *)
{
connectionToUI();
}
void ConnectionDialog::slotAccept()
{
try {
checkFieldsFill();
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());
}
}
void ConnectionDialog::slotCheckConnection()
{
try{
checkConnection();
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 "));
}
}
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)
{
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()
{
init();
if (!m_connection) return;
ui->leConnectionName->setText(m_connection->name());
ui->leDataBase->setText(m_connection->databaseName());
ui->leServerName->setText(m_connection->host());
ui->leUserName->setText(m_connection->userName());
ui->lePassword->setText(m_connection->password());
ui->cbbDrivers->setCurrentIndex(ui->cbbDrivers->findText(m_connection->driver()));
ui->cbAutoConnect->setChecked(m_connection->autoconnect());
}
void ConnectionDialog::on_toolButton_clicked()
{
ui->leDataBase->setText(QFileDialog::getOpenFileName());
}
} // namespace LimeReport

View File

@@ -0,0 +1,70 @@
/***************************************************************************
* This file is part of the Lime Report project *
* Copyright (C) 2015 by Alexander Arin *
* arin_a@bk.ru *
* *
** GNU General Public License Usage **
* *
* This library is free software: you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation, either version 3 of the License, or *
* (at your option) any later version. *
* You should have received a copy of the GNU General Public License *
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
* *
** GNU Lesser General Public License **
* *
* This library is free software: you can redistribute it and/or modify *
* it under the terms of the GNU Lesser General Public License as *
* published by the Free Software Foundation, either version 3 of the *
* License, or (at your option) any later version. *
* You should have received a copy of the GNU Lesser General Public *
* License along with this library. *
* If not, see <http://www.gnu.org/licenses/>. *
* *
* This library is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
****************************************************************************/
#ifndef LRCONNECTIONDIALOG_H
#define LRCONNECTIONDIALOG_H
#include <QDialog>
#include "lrdatadesignintf.h"
namespace LimeReport{
namespace Ui {
class ConnectionDialog;
}
class ConnectionDialog : public QDialog
{
Q_OBJECT
public:
explicit ConnectionDialog(LimeReport::IConnectionController* conControl, LimeReport::ConnectionDesc* connectionDesc=0, QWidget *parent = 0);
~ConnectionDialog();
protected:
void showEvent(QShowEvent *);
void init();
void checkFieldsFill();
bool checkConnection();
LimeReport::ConnectionDesc* uiToConnection(LimeReport::ConnectionDesc *conDesc = 0);
void connectionToUI();
signals:
void conectionRegistred(LimeReport::ConnectionDesc* connectionDesc);
private slots:
void slotAccept();
void slotCheckConnection();
void on_toolButton_clicked();
private:
Ui::ConnectionDialog *ui;
LimeReport::ConnectionDesc* m_connection;
bool m_changeMode;
LimeReport::IConnectionController* m_controller;
};
} // namespace LimeReport
#endif // LRCONNECTIONDIALOG_H

View File

@@ -0,0 +1,249 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>LimeReport::ConnectionDialog</class>
<widget class="QDialog" name="LimeReport::ConnectionDialog">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>420</width>
<height>294</height>
</rect>
</property>
<property name="windowTitle">
<string>Connection</string>
</property>
<property name="windowIcon">
<iconset resource="lrdatabrowser.qrc">
<normaloff>:/databrowser/images/database_disconnected</normaloff>:/databrowser/images/database_disconnected</iconset>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QLabel" name="lbConnection">
<property name="text">
<string>Connection Name</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="leConnectionName">
<property name="text">
<string/>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QFormLayout" name="formLayout">
<item row="0" column="0">
<widget class="QLabel" name="lbDriver">
<property name="text">
<string>Driver</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QComboBox" name="cbbDrivers"/>
</item>
<item row="1" column="0">
<widget class="QLabel" name="lbServer">
<property name="text">
<string>Server </string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QLineEdit" name="leServerName">
<property name="text">
<string/>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="lbUser">
<property name="text">
<string>User</string>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QLineEdit" name="leUserName">
<property name="text">
<string/>
</property>
</widget>
</item>
<item row="3" column="0">
<widget class="QLabel" name="lbPassword">
<property name="text">
<string>Password</string>
</property>
</widget>
</item>
<item row="3" column="1">
<widget class="QLineEdit" name="lePassword">
<property name="text">
<string/>
</property>
<property name="echoMode">
<enum>QLineEdit::Password</enum>
</property>
</widget>
</item>
<item row="4" column="0">
<widget class="QLabel" name="lbDatabase">
<property name="text">
<string>Database</string>
</property>
</widget>
</item>
<item row="4" column="1">
<layout class="QHBoxLayout" name="horizontalLayout_3">
<property name="spacing">
<number>2</number>
</property>
<item>
<widget class="QLineEdit" name="leDataBase">
<property name="text">
<string/>
</property>
</widget>
</item>
<item>
<widget class="QToolButton" name="toolButton">
<property name="text">
<string>...</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</item>
<item>
<widget class="QCheckBox" name="cbAutoConnect">
<property name="text">
<string>Auto connect</string>
</property>
</widget>
</item>
<item>
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>0</height>
</size>
</property>
</spacer>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<widget class="QPushButton" name="pbCheckConnection">
<property name="text">
<string>Check connection</string>
</property>
<property name="autoDefault">
<bool>false</bool>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QPushButton" name="pbCancel">
<property name="text">
<string>Cancel</string>
</property>
<property name="autoDefault">
<bool>false</bool>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="pbOk">
<property name="text">
<string>Ok</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
<resources>
<include location="lrdatabrowser.qrc"/>
</resources>
<connections>
<connection>
<sender>pbOk</sender>
<signal>clicked()</signal>
<receiver>LimeReport::ConnectionDialog</receiver>
<slot>slotAccept()</slot>
<hints>
<hint type="sourcelabel">
<x>388</x>
<y>266</y>
</hint>
<hint type="destinationlabel">
<x>376</x>
<y>215</y>
</hint>
</hints>
</connection>
<connection>
<sender>pbCancel</sender>
<signal>clicked()</signal>
<receiver>LimeReport::ConnectionDialog</receiver>
<slot>reject()</slot>
<hints>
<hint type="sourcelabel">
<x>268</x>
<y>263</y>
</hint>
<hint type="destinationlabel">
<x>255</x>
<y>225</y>
</hint>
</hints>
</connection>
<connection>
<sender>pbCheckConnection</sender>
<signal>clicked()</signal>
<receiver>LimeReport::ConnectionDialog</receiver>
<slot>slotCheckConnection()</slot>
<hints>
<hint type="sourcelabel">
<x>28</x>
<y>271</y>
</hint>
<hint type="destinationlabel">
<x>36</x>
<y>224</y>
</hint>
</hints>
</connection>
</connections>
<slots>
<slot>slotAccept()</slot>
<slot>slotCheckConnection()</slot>
</slots>
</ui>

View File

@@ -0,0 +1,724 @@
/***************************************************************************
* This file is part of the Lime Report project *
* Copyright (C) 2015 by Alexander Arin *
* arin_a@bk.ru *
* *
** GNU General Public License Usage **
* *
* This library is free software: you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation, either version 3 of the License, or *
* (at your option) any later version. *
* You should have received a copy of the GNU General Public License *
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
* *
** GNU Lesser General Public License **
* *
* This library is free software: you can redistribute it and/or modify *
* it under the terms of the GNU Lesser General Public License as *
* published by the Free Software Foundation, either version 3 of the *
* License, or (at your option) any later version. *
* You should have received a copy of the GNU Lesser General Public *
* License along with this library. *
* If not, see <http://www.gnu.org/licenses/>. *
* *
* This library is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
****************************************************************************/
#include <QVBoxLayout>
#include <QHBoxLayout>
#include <QDebug>
#include <QMessageBox>
#include <QtSql/QSqlDatabase>
#include <QtSql/QSqlQuery>
#include <QtSql/QSqlQueryModel>
#include <QtSql/QSqlError>
#include <QFileInfo>
#include <QTableView>
#include <QDockWidget>
#include <QMainWindow>
#include "ui_lrdatabrowser.h"
#include "lrdatabrowser.h"
#include "lrsqleditdialog.h"
#include "lrconnectiondialog.h"
#include "lrreportengine_p.h"
#include "lrvariabledialog.h"
#include "lrdatabrowsertree.h"
namespace LimeReport{
DataBrowser::DataBrowser(QWidget *parent) :
QWidget(parent),
ui(new Ui::DataBrowser), m_report(0), m_closingWindows(false), m_settings(0), m_ownedSettings(false)
{
ui->setupUi(this);
connect(ui->addConnection,SIGNAL(clicked()),this,SLOT(slotAddConnection()));
connect(ui->deleteConection,SIGNAL(clicked()),this,SLOT(slotDeleteConnection()));
connect(ui->addDataSource,SIGNAL(clicked()),this,SLOT(slotAddDataSource()));
connect(ui->viewDataSource,SIGNAL(clicked()),this,SLOT(slotViewDatasource()));
connect(ui->editDataSource,SIGNAL(clicked()),this,SLOT(slotEditDatasource()));
connect(ui->deleteDataSource,SIGNAL(clicked()),this,SLOT(slotDeleteDatasource()));
connect(ui->changeConnection,SIGNAL(clicked()),this,SLOT(slotChangeConnection()));
connect(ui->pbConnect,SIGNAL(clicked()),this,SLOT(slotChangeConnectionState()));
ui->dataTree->setHeaderLabel(tr("Datasources"));
ui->pbConnect->setEnabled(false);
}
DataBrowser::~DataBrowser()
{
delete ui;
if (m_settings && m_ownedSettings)
delete m_settings;
}
QSize DataBrowser::sizeHint() const
{
return QSize(100,200);
}
void DataBrowser::slotAddConnection()
{
ConnectionDialog *connectionEdit = new ConnectionDialog(this,0,this);
connectionEdit->setAttribute(Qt::WA_DeleteOnClose,true);
#ifdef Q_OS_MAC
connectionEdit->setWindowModality(Qt::WindowModal);
#else
connectionEdit->setWindowModality(Qt::ApplicationModal);
#endif
//connect(connectionEdit,SIGNAL(finished(int)),this,SLOT(slotConnectionEditFinished(int)));
//connect(connectionEdit,SIGNAL(conectionRegistred(QString)),this,SLOT(slotConnectionRegistred(QString)));
connectionEdit->exec();
}
void DataBrowser::slotSQLEditingFinished(SQLEditResult result)
{
if (result.dialogMode==SQLEditDialog::AddMode) {
switch (result.resultMode) {
case SQLEditResult::Query:
addQuery(result);
break;
case SQLEditResult::SubQuery:
addSubQuery(result);
break;
case SQLEditResult::SubProxy:
addProxy(result);
default:
break;
}
} else {
switch(result.resultMode){
case SQLEditResult::Query:
changeQuery(result);
break;
case SQLEditResult::SubQuery:
changeSubQuery(result);
break;
case SQLEditResult::SubProxy:
changeProxy(result);
}
}
updateDataTree();
}
void DataBrowser::slotDeleteConnection()
{
if (!getConnectionName().isEmpty()){
if (
QMessageBox::critical(
this,
tr("Attention"),
tr("Do you really want to delete \"%1\" connection ?").arg(getConnectionName()),
QMessageBox::Ok|QMessageBox::No,
QMessageBox::No
)==QMessageBox::Ok
){
m_report->dataManager()->removeConnection(getConnectionName());
updateDataTree();
}
}
}
void DataBrowser::slotAddDataSource()
{
SQLEditDialog *sqlEdit = new SQLEditDialog(this,m_report->dataManager(),SQLEditDialog::AddMode);
sqlEdit->setAttribute(Qt::WA_DeleteOnClose,true);
#ifdef Q_OS_MAC
sqlEdit->setWindowModality(Qt::WindowModal);
#else
sqlEdit->setWindowModality(Qt::ApplicationModal);
#endif
sqlEdit->setSettings(settings());
sqlEdit->setDataSources(m_report->dataManager());
sqlEdit->setDefaultConnection(getConnectionName());
connect(sqlEdit,SIGNAL(signalSqlEditingFinished(SQLEditResult)),this,SLOT(slotSQLEditingFinished(SQLEditResult)));
sqlEdit->exec();
}
void DataBrowser::updateDataTree()
{
QString selectedText = "";
int selectedType = 0;
if (ui->dataTree->selectedItems().count()==1){
selectedType = ui->dataTree->selectedItems().at(0)->type();
selectedText = ui->dataTree->selectedItems().at(0)->text(0);
}
initConnections();
foreach(QString dataSourceName, m_report->datasourcesNames()){
QTreeWidgetItem *item=new QTreeWidgetItem(QStringList(dataSourceName),DataBrowserTree::Table);
QTreeWidgetItem *parentItem = findByNameAndType(m_report->dataManager()->connectionName(dataSourceName),DataBrowserTree::Connection);
if (parentItem){
parentItem->addChild(item);
if (!parentItem->isExpanded()) ui->dataTree->expandItem(parentItem);
} else {
ui->dataTree->addTopLevelItem(item);
}
try{
IDataSource* datasource = m_report->dataManager()->dataSource(dataSourceName);
if (datasource){
fillFields(item,datasource);
if (!datasource->isInvalid())
item->setIcon(0,QIcon(":/databrowser/images/table_good"));
else
item->setIcon(0,QIcon(":/databrowser/images/table_error"));
} else item->setIcon(0,QIcon(":/databrowser/images/table_error"));
} catch(ReportError& /*exception*/) {
item->setIcon(0,QIcon(":/databrowser/images/table_error"));
//qDebug()<<exception.what();
}
}
QTreeWidgetItem* selectedItem = findByNameAndType(selectedText,selectedType);
if (selectedItem){
selectedItem->setSelected(true);
ui->dataTree->setCurrentItem(selectedItem);
}
}
void DataBrowser::updateVariablesTree()
{
ui->variablesTree->clear();
QTreeWidgetItem *userVariables =new QTreeWidgetItem(QStringList(tr("User variables")),DataBrowserTree::Category);
userVariables->setIcon(0,QIcon(":/report/images/folder"));
QTreeWidgetItem *systemVariables =new QTreeWidgetItem(QStringList(tr("System variables")),DataBrowserTree::Category);
systemVariables->setIcon(0,QIcon(":/report/images/folder"));
ui->variablesTree->addTopLevelItem(userVariables);
ui->variablesTree->addTopLevelItem(systemVariables);
foreach(QString variableName,m_report->dataManager()->variableNames()){
QStringList values;
values<<variableName+((m_report->dataManager()->variableIsSystem(variableName))?
"":
" ["+m_report->dataManager()->variable(variableName).toString()+"]"
)
<<variableName;
QTreeWidgetItem *item=new QTreeWidgetItem(values,DataBrowserTree::Variable);
item->setIcon(0,QIcon(":/databrowser/images/value"));
if (m_report->dataManager()->variableIsSystem(variableName)){
systemVariables->addChild(item);
} else {
userVariables->addChild(item);
}
}
ui->variablesTree->expandItem(userVariables);
ui->variablesTree->expandItem(systemVariables);
}
void DataBrowser::closeAllDataWindows()
{
m_closingWindows = true;
QMap<QString,QDockWidget*>::iterator it = m_dataWindows.begin();
for(;it!=m_dataWindows.end();){
(*it)->close();
delete (*it);
it = m_dataWindows.erase(it);
}
m_closingWindows = false;
}
void DataBrowser::setSettings(QSettings *value, bool owned)
{
if (m_settings && m_ownedSettings) delete m_settings;
m_settings=value;
m_ownedSettings = owned;
}
QSettings *DataBrowser::settings()
{
if (m_settings){
return m_settings;
} else {
m_settings = new QSettings("LimeReport",QApplication::applicationName());
m_ownedSettings = true;
return m_settings;
}
}
void DataBrowser::slotDatasourcesChanged()
{
updateDataTree();
}
void DataBrowser::fillFields(QTreeWidgetItem *parentItem, LimeReport::IDataSource *dataSource)
{
if (!dataSource) return;
for (int i=0;i<dataSource->columnCount();i++){
QTreeWidgetItem *item = new QTreeWidgetItem(QStringList(dataSource->columnNameByIndex(i)),DataBrowserTree::Row);
item->setIcon(0,QIcon(":/databrowser/images/field"));
parentItem->addChild(item);
}
parentItem->sortChildren(0,Qt::AscendingOrder);
}
QTreeWidgetItem * DataBrowser::findByNameAndType(QString name, int itemType)
{
if (name.isEmpty()) return 0;
QList<QTreeWidgetItem *>items = ui->dataTree->findItems(name,Qt::MatchContains | Qt::MatchRecursive);
if (!items.isEmpty()){
for (int i=0;i<items.count();i++){
if ( (items.at(i)->type()==itemType)/* && (items.at(0)->text(0)==name)*/){ return items.at(i);}
}
}
return 0;
}
void DataBrowser::slotViewDatasource()
{
QString datasourceName=getDatasourceName();
if (!datasourceName.isEmpty()){
showDataWindow(datasourceName);
}
}
QString DataBrowser::getDatasourceName()
{
if (ui->dataTree->currentItem()){
if (ui->dataTree->currentItem()->type() == DataBrowserTree::Table) return ui->dataTree->currentItem()->text(0);
if (ui->dataTree->currentItem()->type() == DataBrowserTree::Row) return ui->dataTree->currentItem()->parent()->text(0);
};
return QString();
}
QTreeWidgetItem* findConnectionItem(QTreeWidgetItem* item){
if (item->type() == DataBrowserTree::Connection){
return item;
} else {
if (item->parent())
return findConnectionItem(item->parent());
else
return 0;
}
}
QString DataBrowser::getConnectionName()
{
if (ui->dataTree->currentItem()){
QTreeWidgetItem * ci = findConnectionItem(ui->dataTree->currentItem());
if (ci) return ci->text(0);
else return QString();
};
return QString();
}
QString DataBrowser::getVariable()
{
if(ui->variablesTree->currentItem()&&ui->variablesTree->currentItem()->type() == DataBrowserTree::Variable){
return ui->variablesTree->currentItem()->text(1);
}
return QString();
}
void DataBrowser::slotEditDatasource()
{
if (!getDatasourceName().isEmpty()){
closeDataWindow(getDatasourceName());
SQLEditDialog *sqlEdit = new SQLEditDialog(this,m_report->dataManager(),SQLEditDialog::EditMode);
sqlEdit->setAttribute(Qt::WA_DeleteOnClose);
#ifdef Q_OS_MAC
sqlEdit->setWindowModality(Qt::WindowModal);
#else
sqlEdit->setWindowModality(Qt::ApplicationModal);
#endif
sqlEdit->setSettings(settings());
sqlEdit->setDataSources(m_report->dataManager(),getDatasourceName());
connect(sqlEdit,SIGNAL(signalSqlEditingFinished(SQLEditResult)),this,SLOT(slotSQLEditingFinished(SQLEditResult)));
sqlEdit->exec();
}
}
void DataBrowser::slotDeleteDatasource()
{
QString datasourceName=getDatasourceName();
QTreeWidgetItem *item = findByNameAndType(datasourceName, DataBrowserTree::Table);
if (item){
if (
QMessageBox::critical(
this,
tr("Attention"),
tr("Do you really want to delete \"%1\" datasource ?").arg(datasourceName),
QMessageBox::Ok|QMessageBox::No,
QMessageBox::No
)==QMessageBox::Ok
){
removeDatasource(datasourceName);
}
}
}
void DataBrowser::setReportEditor(LimeReport::ReportDesignWidget *report)
{
m_report=report;
connect(m_report,SIGNAL(cleared()),this,SLOT(slotClear()));
connect(m_report->dataManager(), SIGNAL(datasourcesChanged()), this, SLOT(slotDatasourcesChanged()));
updateDataTree();
updateVariablesTree();
}
void DataBrowser::slotClear()
{
ui->dataTree->clear();
foreach(QDockWidget* window,m_dataWindows.values()) window->close();
updateDataTree();
}
void DataBrowser::initConnections()
{
ui->dataTree->clear();
QList<QTreeWidgetItem *>items;
foreach(QString connectionName,m_report->dataManager()->connectionNames()){
QTreeWidgetItem *item=new QTreeWidgetItem(ui->dataTree,QStringList(connectionName), DataBrowserTree::Connection);
if (m_report->dataManager()->isConnectionConnected(connectionName))
item->setIcon(0,QIcon(":/databrowser/images/database_connected"));
else
item->setIcon(0,QIcon(":/databrowser/images/database_disconnected"));
items.append(item);
}
ui->dataTree->insertTopLevelItems(0,items);
}
QDockWidget *DataBrowser::createDataWindow(QString datasourceName)
{
QDockWidget *window = new QDockWidget("Table: "+datasourceName);
QTableView *tableView = new QTableView(window);
//TODO: exception or message ?
try {
IDataSourceHolder* holder = m_report->dataManager()->dataSourceHolder(datasourceName);
if (holder) holder->update();
IDataSource* datasource = m_report->dataManager()->dataSource(datasourceName);
if (datasource){
tableView->setModel(datasource->model());
}
} catch (ReportError& exception) {
qDebug()<<exception.what();
}
window->setWidget(tableView);
window->setAttribute(Qt::WA_DeleteOnClose);
connect(window,SIGNAL(destroyed()),this,SLOT(slotDataWindowClosed()));
if (!m_dataWindows.isEmpty())
m_mainWindow->tabifyDockWidget(m_dataWindows.values().at(0),window);
else
m_mainWindow->addDockWidget(Qt::BottomDockWidgetArea,window);
m_dataWindows.insert(datasourceName,window);
return window;
}
QDockWidget *DataBrowser::dataWindow(QString datasourceName)
{
if (m_dataWindows.contains(datasourceName)){
return m_dataWindows.value(datasourceName);
} else return createDataWindow(datasourceName);
}
void DataBrowser::setMainWindow(QMainWindow *mainWindow)
{
m_mainWindow=mainWindow;
}
void DataBrowser::slotDataWindowClosed()
{
if (isClosingWindows()) return;
for (int i=0;i<m_dataWindows.count();i++){
if (m_dataWindows.values().at(i)==sender()){
m_dataWindows.remove(m_dataWindows.keys().at(i));
}
}
}
void DataBrowser::slotChangeConnection()
{
if (!getConnectionName().isEmpty()){
ConnectionDialog *connectionEdit = new ConnectionDialog(
this,
m_report->dataManager()->connectionByName(getConnectionName()),
this
);
connectionEdit->setAttribute(Qt::WA_DeleteOnClose,true);
#ifdef Q_OS_MAC
connectionEdit->setWindowModality(Qt::WindowModal);
#else
connectionEdit->setWindowModality(Qt::ApplicationModal);
#endif
//connect(connectionEdit,SIGNAL(finished(int)),this,SLOT(slotConnectionEditFinished(int)));
connectionEdit->exec();
}
}
void DataBrowser::slotChangeConnectionState()
{
QString connectionName = getConnectionName();
if (!connectionName.isEmpty()){
if (!m_report->dataManager()->isConnectionConnected(connectionName)){
setCursor(Qt::WaitCursor);
//try {
if (!m_report->dataManager()->connectConnection(connectionName)){
//} catch(std::runtime_error &exception) {
QMessageBox::critical(this,tr("Attention"),m_report->dataManager()->lastError());
//}
}
updateDataTree();
setCursor(Qt::ArrowCursor);
} else {
m_report->dataManager()->disconnectConnection(connectionName);
updateDataTree();
}
}
}
void DataBrowser::slotVariableEditorAccept(const QString &variable)
{
updateVariablesTree();
QList<QTreeWidgetItem*> items = ui->variablesTree->findItems(variable, Qt::MatchContains | Qt::MatchRecursive);
if (!items.isEmpty()){
ui->variablesTree->setCurrentItem(items.at(0));
}
}
void DataBrowser::showDataWindow(QString datasourceName)
{
QDockWidget *window = dataWindow(datasourceName);
if (window){
window->show();
window->raise();
}
}
void DataBrowser::closeDataWindow(QString datasourceName)
{
if (m_dataWindows.contains(datasourceName))
m_dataWindows.value(datasourceName)->close();
}
void DataBrowser::removeDatasource(QString datasourceName)
{
closeDataWindow(datasourceName);
m_report->dataManager()->removeDatasource(datasourceName);
}
void DataBrowser::addQuery(SQLEditResult result)
{
try {
m_report->dataManager()->addQuery(result.datasourceName, result.sql, result.connectionName);
} catch(ReportError &exception){
qDebug()<<exception.what();
}
}
void DataBrowser::changeQuery(SQLEditResult result)
{
try {
m_report->dataManager()->removeDatasource(result.oldDatasourceName);
m_report->dataManager()->addQuery(result.datasourceName, result.sql, result.connectionName);
}catch(ReportError &exception){
qDebug()<<exception.what();
}
}
void DataBrowser::addSubQuery(SQLEditResult result)
{
try {
m_report->dataManager()->addSubQuery(result.datasourceName, result.sql, result.connectionName, result.masterDatasource);
} catch(ReportError &exception){
qDebug()<<exception.what();
}
}
void DataBrowser::changeSubQuery(SQLEditResult result)
{
try {
m_report->dataManager()->removeDatasource(result.oldDatasourceName);
m_report->dataManager()->addSubQuery(result.datasourceName, result.sql, result.connectionName, result.masterDatasource);
}catch(ReportError &exception){
qDebug()<<exception.what();
}
}
void DataBrowser::addProxy(SQLEditResult result)
{
try {
m_report->dataManager()->addProxy(result.datasourceName,result.masterDatasource,result.childDataSource,result.fieldMap);
} catch(ReportError &exception){
qDebug()<<exception.what();
}
}
void DataBrowser::changeProxy(SQLEditResult result)
{
try {
m_report->dataManager()->removeDatasource(result.oldDatasourceName);
m_report->dataManager()->addProxy(result.datasourceName,result.masterDatasource,result.childDataSource,result.fieldMap);
} catch(ReportError &exception){
qDebug()<<exception.what();
}
}
void DataBrowser::addConnectionDesc(ConnectionDesc *connection)
{
m_report->dataManager()->addConnectionDesc(connection);
updateDataTree();
}
void DataBrowser::changeConnectionDesc(ConnectionDesc *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)
if (current&&(current->type() == DataBrowserTree::Connection)) {
ui->pbConnect->setEnabled(true);
if (m_report->dataManager()->isConnectionConnected(current->text(0))){
ui->pbConnect->setIcon(QIcon(":/databrowser/images/plug-connect.png"));
} else {
ui->pbConnect->setIcon(QIcon(":/databrowser/images/plug-disconnect.png"));
}
ui->editDataSource->setEnabled(false);
ui->deleteDataSource->setEnabled(false);
ui->viewDataSource->setEnabled(false);
ui->changeConnection->setEnabled(true);
ui->deleteConection->setEnabled(true);
ui->errorMessage->setDisabled(true);
} else {
ui->changeConnection->setEnabled(false);
ui->deleteConection->setEnabled(false);
ui->pbConnect->setEnabled(false);
IDataSourceHolder* holder = m_report->dataManager()->dataSourceHolder(getDatasourceName());
if (holder){
ui->viewDataSource->setEnabled(!holder->isInvalid());
ui->editDataSource->setEnabled(holder->isEditable());
ui->deleteDataSource->setEnabled(holder->isRemovable());
if (!holder->lastError().isEmpty()){
ui->errorMessage->setEnabled(true);
} else {ui->errorMessage->setEnabled(false);}
}
}
}
void LimeReport::DataBrowser::on_addVariable_clicked()
{
LRVariableDialog dialog(this);
#ifdef Q_OS_MAC
dialog.setWindowModality(Qt::WindowModal);
#else
dialog.setWindowModality(Qt::ApplicationModal);
#endif
dialog.setVariableContainer(m_report->dataManager());
connect(&dialog,SIGNAL(signalVariableAccepted(QString)),this,SLOT(slotVariableEditorAccept(QString)));
dialog.exec();
}
void DataBrowser::on_editVariable_clicked()
{
if (!getVariable().isEmpty())
{
LRVariableDialog dialog(this);
#ifdef Q_OS_MAC
dialog.setWindowModality(Qt::WindowModal);
#else
dialog.setWindowModality(Qt::ApplicationModal);
#endif
dialog.setVariableContainer(m_report->dataManager());
QString varName = getVariable();
dialog.setVariableName(varName);
connect(&dialog,SIGNAL(signalVariableAccepted(QString)),this,SLOT(slotVariableEditorAccept(QString)));
dialog.exec();
}
}
void DataBrowser::on_deleteVariable_clicked()
{
QString varName = getVariable();
if (!varName.isEmpty()){
if (QMessageBox::critical(this,tr("Attention"),QString(tr("Do you really want to delete variable \"%1\" ?")).arg(varName),
QMessageBox::Ok|QMessageBox::Cancel, QMessageBox::Cancel
)==QMessageBox::Ok){
m_report->dataManager()->deleteVariable(varName);
updateVariablesTree();
}
}
}
void DataBrowser::on_variablesTree_currentItemChanged(QTreeWidgetItem *current, QTreeWidgetItem *previous)
{
Q_UNUSED(previous)
if (current){
if (m_report->dataManager()->containsVariable(current->text(1))&&
!m_report->dataManager()->variableIsSystem(current->text(1))
){
ui->editVariable->setEnabled(true);
ui->deleteVariable->setEnabled(true);
} else {
ui->editVariable->setEnabled(false);
ui->deleteVariable->setEnabled(false);
}
}
}
void DataBrowser::on_errorMessage_clicked()
{
if(!getDatasourceName().isEmpty()&&m_report->dataManager()->dataSourceHolder(getDatasourceName())){
QMessageBox::critical(this,tr("Error"),m_report->dataManager()->dataSourceHolder(getDatasourceName())->lastError());
}
}
} // namespace LimeReport

View File

@@ -0,0 +1,121 @@
/***************************************************************************
* This file is part of the Lime Report project *
* Copyright (C) 2015 by Alexander Arin *
* arin_a@bk.ru *
* *
** GNU General Public License Usage **
* *
* This library is free software: you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation, either version 3 of the License, or *
* (at your option) any later version. *
* You should have received a copy of the GNU General Public License *
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
* *
** GNU Lesser General Public License **
* *
* This library is free software: you can redistribute it and/or modify *
* it under the terms of the GNU Lesser General Public License as *
* published by the Free Software Foundation, either version 3 of the *
* License, or (at your option) any later version. *
* You should have received a copy of the GNU Lesser General Public *
* License along with this library. *
* If not, see <http://www.gnu.org/licenses/>. *
* *
* This library is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
****************************************************************************/
#ifndef LRDATABROWSER_H
#define LRDATABROWSER_H
#include <QWidget>
#include <QTreeWidget>
#include <QToolButton>
#include <QDockWidget>
#include "lrreportdesignwidget.h"
#include "lrsqleditdialog.h"
namespace LimeReport{
namespace Ui {
class DataBrowser;
}
class DataBrowser : public QWidget, public IConnectionController
{
Q_OBJECT
public:
explicit DataBrowser(QWidget *parent = 0);
~DataBrowser();
QSize sizeHint() const;
void setReportEditor(LimeReport::ReportDesignWidget* report);
void setMainWindow(QMainWindow* mainWindow);
void initConnections();
void updateDataTree();
void updateVariablesTree();
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();
void slotDeleteConnection();
void slotAddDataSource();
void slotViewDatasource();
void slotEditDatasource();
void slotDeleteDatasource();
void slotSQLEditingFinished(SQLEditResult result);
void slotClear();
void slotDataWindowClosed();
void slotChangeConnection();
void slotChangeConnectionState();
void slotVariableEditorAccept(const QString &variable);
void on_dataTree_currentItemChanged(QTreeWidgetItem *current, QTreeWidgetItem *previous);
void on_editVariable_clicked();
void on_deleteVariable_clicked();
void on_addVariable_clicked();
void on_variablesTree_currentItemChanged(QTreeWidgetItem *current, QTreeWidgetItem *previous);
void on_errorMessage_clicked();
private:
QString getDatasourceName();
QString getConnectionName();
QString getVariable();
bool isClosingWindows() const {return m_closingWindows;}
QTreeWidgetItem * findByNameAndType(QString name, int itemType);
void fillFields(QTreeWidgetItem *parentItem, LimeReport::IDataSource *dataSource);
QDockWidget* createDataWindow(QString datasourceName);
void closeDataWindow(QString datasourceName);
QDockWidget* dataWindow(QString datasourceName);
void showDataWindow(QString datasourceName);
void removeDatasource(QString datasourceName);
void addQuery(SQLEditResult result);
void changeQuery(SQLEditResult result);
void addSubQuery(SQLEditResult result);
void changeSubQuery(SQLEditResult result);
void addProxy(SQLEditResult result);
void changeProxy(SQLEditResult result);
void addConnectionDesc(ConnectionDesc *connection);
void changeConnectionDesc(ConnectionDesc *connection);
bool checkConnectionDesc(ConnectionDesc *connection);
private:
Ui::DataBrowser* ui;
ReportDesignWidget* m_report;
QMap<QString,QDockWidget*> m_dataWindows;
QMainWindow* m_mainWindow;
bool m_closingWindows;
QSettings* m_settings;
bool m_ownedSettings;
QString m_lastError;
};
}
#endif // LRDATABROWSER_H

View File

@@ -0,0 +1,47 @@
<RCC>
<qresource prefix="/databrowser">
<file>images/data_add.png</file>
<file>images/data_delete.png</file>
<file>images/table.png</file>
<file>images/table_delete.png</file>
<file>images/data.png</file>
<file>images/row.png</file>
<file>images/edit_table.png</file>
<file>images/table_view.png</file>
<file>images/value_add.png</file>
<file>images/value_delete.png</file>
<file>images/value_edit.png</file>
<file>images/value.png</file>
<file>images/data_edit.png</file>
<file>images/add.png</file>
<file>images/remove.png</file>
<file>images/plug-connect.png</file>
<file>images/plug-disconnect.png</file>
<file>images/database_connect.png</file>
<file>images/database_disconnect.png</file>
<file>images/database_connected.png</file>
<file>images/database_connected2.png</file>
<file>images/table_error.png</file>
<file>images/table_good.png</file>
<file>images/error_message.png</file>
<file>images/error_message_2.png</file>
<file alias="/images/database_disconnected">images/data1.png</file>
<file alias="/images/database_connected">images/database_connected3.png</file>
<file alias="/images/field">images/field.png</file>
<file alias="/images/table_error">images/table_error1.png</file>
<file alias="/images/table_good">images/table_good1.png</file>
<file alias="/images/database_add">images/data_add1.png</file>
<file alias="/images/database_delete">images/data_delete1.png</file>
<file alias="/images/database_edit">images/data_edit1.png</file>
<file alias="/images/table_add">images/table_add.png</file>
<file alias="/images/table_delete">images/table_delete1.png</file>
<file alias="/images/table_edit">images/table_edit.png</file>
<file alias="/images/table_view">images/table_view1.png</file>
<file>images/value_add1.png</file>
<file alias="/images/value_delete">images/value_delete1.png</file>
<file>images/value_edit1.png</file>
<file alias="/images/value_add">images/value_add2.png</file>
<file alias="/images/value_edit">images/value_edit2.png</file>
<file alias="/images/value">images/value1.png</file>
</qresource>
</RCC>

View File

@@ -0,0 +1,508 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>LimeReport::DataBrowser</class>
<widget class="QWidget" name="LimeReport::DataBrowser">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>300</height>
</rect>
</property>
<property name="windowTitle">
<string>Datasources</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_2">
<property name="spacing">
<number>1</number>
</property>
<property name="leftMargin">
<number>1</number>
</property>
<property name="topMargin">
<number>1</number>
</property>
<property name="rightMargin">
<number>1</number>
</property>
<property name="bottomMargin">
<number>2</number>
</property>
<item>
<widget class="QTabWidget" name="tabWidget">
<property name="tabPosition">
<enum>QTabWidget::South</enum>
</property>
<property name="currentIndex">
<number>0</number>
</property>
<widget class="QWidget" name="tab">
<attribute name="title">
<string>Datasources</string>
</attribute>
<layout class="QVBoxLayout" name="verticalLayout">
<property name="leftMargin">
<number>2</number>
</property>
<property name="topMargin">
<number>2</number>
</property>
<property name="rightMargin">
<number>2</number>
</property>
<property name="bottomMargin">
<number>2</number>
</property>
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<property name="spacing">
<number>2</number>
</property>
<item>
<widget class="QToolButton" name="addConnection">
<property name="toolTip">
<string>Add database connection</string>
</property>
<property name="text">
<string>...</string>
</property>
<property name="icon">
<iconset resource="lrdatabrowser.qrc">
<normaloff>:/databrowser/images/database_add</normaloff>:/databrowser/images/database_add</iconset>
</property>
<property name="iconSize">
<size>
<width>16</width>
<height>16</height>
</size>
</property>
<property name="autoRaise">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QToolButton" name="changeConnection">
<property name="enabled">
<bool>false</bool>
</property>
<property name="text">
<string>...</string>
</property>
<property name="icon">
<iconset resource="lrdatabrowser.qrc">
<normaloff>:/databrowser/images/database_edit</normaloff>:/databrowser/images/database_edit</iconset>
</property>
<property name="iconSize">
<size>
<width>16</width>
<height>16</height>
</size>
</property>
<property name="autoRaise">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QToolButton" name="deleteConection">
<property name="enabled">
<bool>false</bool>
</property>
<property name="text">
<string>...</string>
</property>
<property name="icon">
<iconset resource="lrdatabrowser.qrc">
<normaloff>:/databrowser/images/database_delete</normaloff>:/databrowser/images/database_delete</iconset>
</property>
<property name="iconSize">
<size>
<width>16</width>
<height>16</height>
</size>
</property>
<property name="autoRaise">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QToolButton" name="pbConnect">
<property name="enabled">
<bool>false</bool>
</property>
<property name="text">
<string>...</string>
</property>
<property name="icon">
<iconset resource="lrdatabrowser.qrc">
<normaloff>:/databrowser/images/plug-connect.png</normaloff>:/databrowser/images/plug-connect.png</iconset>
</property>
<property name="iconSize">
<size>
<width>16</width>
<height>16</height>
</size>
</property>
<property name="autoRaise">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="label">
<property name="frameShape">
<enum>QFrame::VLine</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Sunken</enum>
</property>
<property name="text">
<string/>
</property>
</widget>
</item>
<item>
<widget class="QToolButton" name="addDataSource">
<property name="toolTip">
<string>Add new datasource</string>
</property>
<property name="text">
<string>...</string>
</property>
<property name="icon">
<iconset resource="lrdatabrowser.qrc">
<normaloff>:/databrowser/images/table_add</normaloff>:/databrowser/images/table_add</iconset>
</property>
<property name="iconSize">
<size>
<width>16</width>
<height>16</height>
</size>
</property>
<property name="autoRaise">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QToolButton" name="viewDataSource">
<property name="enabled">
<bool>false</bool>
</property>
<property name="toolTip">
<string>View data</string>
</property>
<property name="text">
<string>...</string>
</property>
<property name="icon">
<iconset resource="lrdatabrowser.qrc">
<normaloff>:/databrowser/images/table_view</normaloff>:/databrowser/images/table_view</iconset>
</property>
<property name="iconSize">
<size>
<width>16</width>
<height>16</height>
</size>
</property>
<property name="autoRaise">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QToolButton" name="editDataSource">
<property name="enabled">
<bool>false</bool>
</property>
<property name="toolTip">
<string>Change datasource</string>
</property>
<property name="text">
<string>...</string>
</property>
<property name="icon">
<iconset resource="lrdatabrowser.qrc">
<normaloff>:/databrowser/images/table_edit</normaloff>:/databrowser/images/table_edit</iconset>
</property>
<property name="iconSize">
<size>
<width>16</width>
<height>16</height>
</size>
</property>
<property name="autoRaise">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QToolButton" name="deleteDataSource">
<property name="enabled">
<bool>false</bool>
</property>
<property name="toolTip">
<string>Delete datasource</string>
</property>
<property name="text">
<string>...</string>
</property>
<property name="icon">
<iconset resource="lrdatabrowser.qrc">
<normaloff>:/databrowser/images/table_delete</normaloff>:/databrowser/images/table_delete</iconset>
</property>
<property name="iconSize">
<size>
<width>16</width>
<height>16</height>
</size>
</property>
<property name="autoRaise">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QToolButton" name="errorMessage">
<property name="enabled">
<bool>false</bool>
</property>
<property name="toolTip">
<string>Show error</string>
</property>
<property name="text">
<string>...</string>
</property>
<property name="icon">
<iconset resource="lrdatabrowser.qrc">
<normaloff>:/databrowser/images/error_message_2.png</normaloff>:/databrowser/images/error_message_2.png</iconset>
</property>
<property name="iconSize">
<size>
<width>16</width>
<height>16</height>
</size>
</property>
<property name="autoRaise">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_2">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item>
<widget class="DataBrowserTree" name="dataTree">
<property name="enabled">
<bool>true</bool>
</property>
<property name="dragEnabled">
<bool>true</bool>
</property>
<property name="dragDropMode">
<enum>QAbstractItemView::DragOnly</enum>
</property>
<attribute name="headerVisible">
<bool>false</bool>
</attribute>
<column>
<property name="text">
<string notr="true">1</string>
</property>
</column>
</widget>
</item>
</layout>
</widget>
<widget class="QWidget" name="tab_2">
<attribute name="title">
<string>Variables</string>
</attribute>
<layout class="QVBoxLayout" name="verticalLayout_3">
<property name="leftMargin">
<number>2</number>
</property>
<property name="topMargin">
<number>2</number>
</property>
<property name="rightMargin">
<number>2</number>
</property>
<property name="bottomMargin">
<number>2</number>
</property>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<property name="spacing">
<number>2</number>
</property>
<item>
<widget class="QToolButton" name="addVariable">
<property name="toolTip">
<string>Add new variable</string>
</property>
<property name="text">
<string>...</string>
</property>
<property name="icon">
<iconset resource="lrdatabrowser.qrc">
<normaloff>:/databrowser/images/value_add</normaloff>:/databrowser/images/value_add</iconset>
</property>
<property name="iconSize">
<size>
<width>16</width>
<height>16</height>
</size>
</property>
<property name="popupMode">
<enum>QToolButton::DelayedPopup</enum>
</property>
<property name="autoRaise">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QToolButton" name="editVariable">
<property name="enabled">
<bool>false</bool>
</property>
<property name="toolTip">
<string>Edit variable</string>
</property>
<property name="text">
<string>...</string>
</property>
<property name="icon">
<iconset resource="lrdatabrowser.qrc">
<normaloff>:/databrowser/images/value_edit</normaloff>:/databrowser/images/value_edit</iconset>
</property>
<property name="iconSize">
<size>
<width>16</width>
<height>16</height>
</size>
</property>
<property name="autoRaise">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QToolButton" name="deleteVariable">
<property name="enabled">
<bool>false</bool>
</property>
<property name="toolTip">
<string>Delete variable</string>
</property>
<property name="text">
<string>...</string>
</property>
<property name="icon">
<iconset resource="lrdatabrowser.qrc">
<normaloff>:/databrowser/images/value_delete</normaloff>:/databrowser/images/value_delete</iconset>
</property>
<property name="iconSize">
<size>
<width>16</width>
<height>16</height>
</size>
</property>
<property name="autoRaise">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_3">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item>
<widget class="DataBrowserTree" name="variablesTree">
<property name="dragEnabled">
<bool>true</bool>
</property>
<property name="dragDropMode">
<enum>QAbstractItemView::DragOnly</enum>
</property>
<property name="rootIsDecorated">
<bool>true</bool>
</property>
<property name="columnCount">
<number>1</number>
</property>
<attribute name="headerVisible">
<bool>false</bool>
</attribute>
<column>
<property name="text">
<string notr="true">1</string>
</property>
</column>
</widget>
</item>
</layout>
</widget>
</widget>
</item>
</layout>
</widget>
<customwidgets>
<customwidget>
<class>DataBrowserTree</class>
<extends>QTreeWidget</extends>
<header>lrdatabrowsertree.h</header>
</customwidget>
</customwidgets>
<tabstops>
<tabstop>dataTree</tabstop>
<tabstop>addConnection</tabstop>
<tabstop>changeConnection</tabstop>
<tabstop>deleteConection</tabstop>
<tabstop>pbConnect</tabstop>
<tabstop>addDataSource</tabstop>
<tabstop>viewDataSource</tabstop>
<tabstop>editDataSource</tabstop>
<tabstop>deleteDataSource</tabstop>
<tabstop>variablesTree</tabstop>
<tabstop>addVariable</tabstop>
<tabstop>editVariable</tabstop>
<tabstop>deleteVariable</tabstop>
<tabstop>tabWidget</tabstop>
</tabstops>
<resources>
<include location="lrdatabrowser.qrc"/>
</resources>
<connections/>
<slots>
<slot>slotAddDataSource()</slot>
<slot>slotDeleteDataSource()</slot>
</slots>
</ui>

View File

@@ -0,0 +1,51 @@
/***************************************************************************
* This file is part of the Lime Report project *
* Copyright (C) 2015 by Alexander Arin *
* arin_a@bk.ru *
* *
** GNU General Public License Usage **
* *
* This library is free software: you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation, either version 3 of the License, or *
* (at your option) any later version. *
* You should have received a copy of the GNU General Public License *
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
* *
** GNU Lesser General Public License **
* *
* This library is free software: you can redistribute it and/or modify *
* it under the terms of the GNU Lesser General Public License as *
* published by the Free Software Foundation, either version 3 of the *
* License, or (at your option) any later version. *
* You should have received a copy of the GNU Lesser General Public *
* License along with this library. *
* If not, see <http://www.gnu.org/licenses/>. *
* *
* This library is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
****************************************************************************/
#include "lrdatabrowsertree.h"
#include <QDebug>
#include <QMimeData>
namespace LimeReport {
DataBrowserTree::DataBrowserTree(QWidget *parent) :
QTreeWidget(parent){}
QMimeData *DataBrowserTree::mimeData(const QList<QTreeWidgetItem *> items) const
{
QMimeData* result = QTreeWidget::mimeData(items);
if (items.at(0)->type()==Row){
result->setText("field:$D{"+items.at(0)->parent()->text(0)+"."+items.at(0)->data(0,Qt::DisplayRole).toString()+"}");
}
if (items.at(0)->type()==Variable){
result->setText("variable:$V{"+items.at(0)->text(0)+"}");
}
return result;
}
} // namespace LimeReport

View File

@@ -0,0 +1,53 @@
/***************************************************************************
* This file is part of the Lime Report project *
* Copyright (C) 2015 by Alexander Arin *
* arin_a@bk.ru *
* *
** GNU General Public License Usage **
* *
* This library is free software: you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation, either version 3 of the License, or *
* (at your option) any later version. *
* You should have received a copy of the GNU General Public License *
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
* *
** GNU Lesser General Public License **
* *
* This library is free software: you can redistribute it and/or modify *
* it under the terms of the GNU Lesser General Public License as *
* published by the Free Software Foundation, either version 3 of the *
* License, or (at your option) any later version. *
* You should have received a copy of the GNU Lesser General Public *
* License along with this library. *
* If not, see <http://www.gnu.org/licenses/>. *
* *
* This library is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
****************************************************************************/
#ifndef LRDATABROWSERTREE_H
#define LRDATABROWSERTREE_H
#include <QTreeWidget>
namespace LimeReport{
class DataBrowserTree : public QTreeWidget
{
Q_OBJECT
public:
enum NodeType{Connection,Table,Row,Category,Variable};
explicit DataBrowserTree(QWidget *parent = 0);
protected:
QMimeData* mimeData(const QList<QTreeWidgetItem *> items) const;
public slots:
};
} // namespace LimeReport
#endif // LRDATABROWSERTREE_H

View File

@@ -0,0 +1,346 @@
/***************************************************************************
* This file is part of the Lime Report project *
* Copyright (C) 2015 by Alexander Arin *
* arin_a@bk.ru *
* *
** GNU General Public License Usage **
* *
* This library is free software: you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation, either version 3 of the License, or *
* (at your option) any later version. *
* You should have received a copy of the GNU General Public License *
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
* *
** GNU Lesser General Public License **
* *
* This library is free software: you can redistribute it and/or modify *
* it under the terms of the GNU Lesser General Public License as *
* published by the Free Software Foundation, either version 3 of the *
* License, or (at your option) any later version. *
* You should have received a copy of the GNU Lesser General Public *
* License along with this library. *
* If not, see <http://www.gnu.org/licenses/>. *
* *
* This library is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
****************************************************************************/
#include "lrsqleditdialog.h"
#include "ui_lrsqleditdialog.h"
#include "lrreportengine_p.h"
#include <QDebug>
#include <QSqlDatabase>
#include <QMessageBox>
namespace LimeReport{
SQLEditDialog::SQLEditDialog(QWidget *parent, LimeReport::DataSourceManager *dataSources, SQLDialogMode dialogMode) :
QDialog(parent),
ui(new Ui::SQLEditDialog),m_datasources(dataSources),m_dialogMode(dialogMode), m_oldDatasourceName(""),
m_settings(0), m_ownedSettings(false)
{
ui->setupUi(this);
m_masterDatasources = new QCompleter(this);
ui->leMaster->setCompleter(m_masterDatasources);
ui->leChild->setCompleter(m_masterDatasources);
ui->gbFieldsMap->setVisible(false);
ui->gbDataPreview->setVisible(false);
ui->pbHidePreview->setVisible(false);
ui->rbSubQuery->setChecked(true);
ui->rbProxy->setVisible(false);
ui->rbSubQuery->setVisible(false);
ui->leMaster->setVisible(false);
ui->lbMaster->setVisible(false);
ui->fieldsMap->setHorizontalHeaderItem(0,new QTableWidgetItem("master"));
ui->fieldsMap->setHorizontalHeaderItem(1,new QTableWidgetItem("detail"));
#ifdef HAVE_QT5
ui->fieldsMap->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch);
#else
ui->fieldsMap->horizontalHeader()->setResizeMode(QHeaderView::Stretch);
#endif
ui->pnlChildDatasource->setVisible(false);
connect(ui->pbPreview, SIGNAL(pressed()), this, SLOT(slotPreviewData()));
connect(ui->pbHidePreview, SIGNAL(pressed()), this, SLOT(slotHidePreview()));
}
SQLEditDialog::~SQLEditDialog()
{
delete ui;
if (m_settings && m_ownedSettings)
delete m_settings;
}
QSettings *SQLEditDialog::settings(){
if (m_settings){
return m_settings;
} else {
m_settings = new QSettings("LimeReport",QApplication::applicationName());
m_ownedSettings = true;
return m_settings;
}
}
void SQLEditDialog::setSettings(QSettings *value, bool owned){
if (m_settings && m_ownedSettings) delete m_settings;
m_settings=value;
m_ownedSettings = owned;
}
void SQLEditDialog::accept()
{
SQLEditResult result;
if (!ui->cbSubdetail->isChecked()){
result.resultMode=SQLEditResult::Query;
} else {
if (ui->rbSubQuery->isChecked()) result.resultMode=SQLEditResult::SubQuery;
else result.resultMode=SQLEditResult::SubProxy;
}
result.connectionName=ui->cbbConnection->currentText();
result.datasourceName=ui->leDatasourceName->text();
result.sql=ui->textEditSQL->toPlainText();
result.dialogMode=m_dialogMode;
result.oldDatasourceName=m_oldDatasourceName;
result.subdetail = ui->cbSubdetail->isChecked();
result.masterDatasource=ui->leMaster->text();
result.childDataSource=ui->leChild->text();
if (ui->fieldsMap->rowCount()>0){
for(int i=0;i<ui->fieldsMap->rowCount();++i){
LimeReport::FieldsCorrelation fieldsCorrelation;
fieldsCorrelation.master=ui->fieldsMap->item(i,0)->data(Qt::DisplayRole).toString();
fieldsCorrelation.detail=ui->fieldsMap->item(i,1)->data(Qt::DisplayRole).toString();
result.fieldMap.append(fieldsCorrelation);
}
}
try {
check();
emit signalSqlEditingFinished(result);
QDialog::accept();
}catch(LimeReport::ReportError &exception){
QMessageBox::critical(this,tr("Error"),exception.what());
}
}
void SQLEditDialog::showEvent(QShowEvent *)
{
ui->lblInfo->setVisible(false);
initConnections();
readSettings();
}
void SQLEditDialog::closeEvent(QCloseEvent *)
{
writeSetting();
}
void SQLEditDialog::hideEvent(QHideEvent *)
{
writeSetting();
}
void SQLEditDialog::check()
{
if (ui->leDatasourceName->text().isEmpty()) throw LimeReport::ReportError(tr("Datasource Name is empty !"));
if (ui->textEditSQL->toPlainText().isEmpty() && (!ui->rbProxy) ) throw LimeReport::ReportError(tr("SQL is empty !"));
if (m_dialogMode==AddMode){
if (m_datasources->containsDatasource(ui->leDatasourceName->text())){
throw LimeReport::ReportError(QString(tr("Datasource with name: \"%1\" already exists !")).arg(ui->leDatasourceName->text()));
}
}
}
void SQLEditDialog::initConnections()
{
foreach(QString connectionName, QSqlDatabase::connectionNames()){
ui->cbbConnection->addItem(QIcon(":/databrowser/images/plug-connect.png"),connectionName);
}
foreach(QString connectionName, m_datasources->connectionNames()){
if (ui->cbbConnection->findText(connectionName,Qt::MatchExactly )==-1)
ui->cbbConnection->addItem(QIcon(":/databrowser/images/plug-disconnect.png"),connectionName);
}
ui->cbbConnection->setCurrentIndex(ui->cbbConnection->findText(m_defaultConnection));
if (!m_oldDatasourceName.isEmpty()){
ui->cbbConnection->setCurrentIndex(ui->cbbConnection->findText(m_datasources->connectionName(m_oldDatasourceName)));
}
}
void SQLEditDialog::setDataSources(LimeReport::DataSourceManager *dataSources, QString datasourceName)
{
m_datasources=dataSources;
if (!datasourceName.isEmpty()){
ui->cbSubdetail->setEnabled(false);
initQueryMode();
m_oldDatasourceName=datasourceName;
ui->leDatasourceName->setText(datasourceName);
ui->textEditSQL->setText(dataSources->queryText(datasourceName));
if (dataSources->isSubQuery(datasourceName)){
initSubQueryMode();
ui->leMaster->setText(dataSources->subQueryByName(datasourceName)->master());
}
if (dataSources->isProxy(datasourceName)){
initProxyMode();
LimeReport::ProxyDesc* proxyDesc = dataSources->proxyByName(datasourceName);
ui->leChild->setText(proxyDesc->child());
ui->leMaster->setText(proxyDesc->master());
int curIndex=0;
foreach(LimeReport::FieldMapDesc* fields, *proxyDesc->fieldsMap()){
ui->fieldsMap->setRowCount(curIndex+1);
ui->fieldsMap->setItem(curIndex,0,new QTableWidgetItem(fields->master()));
ui->fieldsMap->setItem(curIndex,1,new QTableWidgetItem(fields->detail()));
curIndex++;
}
}
}
}
void SQLEditDialog::setDefaultConnection(QString defaultConnection)
{
m_defaultConnection=defaultConnection;
}
void SQLEditDialog::slotDataSourceNameEditing()
{
if (m_dialogMode==AddMode){
QPalette palette=ui->leDatasourceName->palette();
if (m_datasources->containsDatasource(ui->leDatasourceName->text())){
palette.setColor(QPalette::Text,Qt::red);
ui->leDatasourceName->setPalette(palette);
ui->lblInfo->setText(QString(tr("Datasource with name %1 already exist")).arg(ui->leDatasourceName->text()));
ui->lblInfo->setVisible(true);
} else {
palette.setColor(QPalette::Text,QApplication::palette().text().color());
ui->leDatasourceName->setPalette(palette);
ui->lblInfo->setVisible(false);
}
}
}
void SQLEditDialog::on_cbSubdetail_clicked(bool checked)
{
if (checked){
m_masterDatasources->setModel(new QStringListModel(m_datasources->dataSourceNames(),m_datasources));
}
ui->leMaster->setEnabled(checked);
ui->rbProxy->setEnabled(checked);
ui->rbSubQuery->setEnabled(checked);
if ((checked)&&(ui->rbProxy->isChecked())) initProxyMode();
if ((checked)&&(ui->rbSubQuery->isChecked())) initSubQueryMode();
if (!checked) initQueryMode();
}
void SQLEditDialog::on_rbProxy_clicked(bool checked)
{
if (checked) initProxyMode();
}
void SQLEditDialog::on_rbSubQuery_clicked(bool checked)
{
if (checked) initSubQueryMode();
}
void SQLEditDialog::on_pbAddField_clicked()
{
ui->fieldsMap->setRowCount(ui->fieldsMap->rowCount()+1);
}
void SQLEditDialog::initQueryMode()
{
ui->gbSQL->setVisible(true);
ui->gbFieldsMap->setVisible(false);
ui->pnlChildDatasource->setVisible(false);
ui->rbSubQuery->setVisible(false);
ui->rbProxy->setVisible(false);
ui->cbSubdetail->setChecked(false);
ui->leMaster->setVisible(false);
ui->lbMaster->setVisible(false);
}
void SQLEditDialog::initSubQueryMode()
{
ui->gbSQL->setVisible(true);
ui->gbFieldsMap->setVisible(false);
ui->pnlChildDatasource->setVisible(false);
ui->rbSubQuery->setChecked(true);
ui->cbSubdetail->setChecked(true);
ui->rbSubQuery->setVisible(true);
ui->rbProxy->setVisible(true);
ui->leMaster->setVisible(true);
ui->leMaster->setEnabled(true);
ui->lbMaster->setVisible(true);
}
void SQLEditDialog::initProxyMode()
{
ui->gbSQL->setVisible(false);
ui->gbFieldsMap->setVisible(true);
ui->pnlChildDatasource->setVisible(true);
ui->rbProxy->setChecked(true);
ui->cbSubdetail->setChecked(true);
ui->rbSubQuery->setVisible(true);
ui->rbProxy->setVisible(true);
ui->leMaster->setVisible(true);
ui->leMaster->setEnabled(true);
ui->lbMaster->setVisible(true);
ui->cbSubdetail->setEnabled(false);
}
void SQLEditDialog::slotPreviewData()
{
if (ui->cbbConnection->currentText().isEmpty()){
QMessageBox::critical(this,tr("Attention"),tr("Connection is not specified"));
return;
}
m_previewModel = m_datasources->previewSQL(ui->cbbConnection->currentText(),ui->textEditSQL->toPlainText(),ui->leMaster->text());
if (m_previewModel){
ui->tvPreview->setModel(m_previewModel.data());
ui->gbDataPreview->setVisible(true);
ui->pbPreview->setText(tr("Refresh"));
ui->pbHidePreview->setVisible(true);
} else {
if (ui->gbDataPreview->isVisible())
hidePreview();
QMessageBox::critical(this,tr("Attention"),m_datasources->lastError());
}
}
void SQLEditDialog::slotHidePreview()
{
hidePreview();
}
void SQLEditDialog::writeSetting()
{
if (settings()!=0){
settings()->beginGroup("SQLEditor");
settings()->setValue("Geometry",saveGeometry());
settings()->endGroup();
}
}
void SQLEditDialog::readSettings()
{
if (settings()==0) return;
settings()->beginGroup("SQLEditor");
QVariant v = settings()->value("Geometry");
if (v.isValid()){
restoreGeometry(v.toByteArray());
}
settings()->endGroup();
}
void SQLEditDialog::hidePreview()
{
ui->gbDataPreview->setVisible(false);
ui->pbPreview->setText(tr("Preview"));
ui->pbHidePreview->setVisible(false);
}
} // namespace LimeReport

View File

@@ -0,0 +1,113 @@
/***************************************************************************
* This file is part of the Lime Report project *
* Copyright (C) 2015 by Alexander Arin *
* arin_a@bk.ru *
* *
** GNU General Public License Usage **
* *
* This library is free software: you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation, either version 3 of the License, or *
* (at your option) any later version. *
* You should have received a copy of the GNU General Public License *
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
* *
** GNU Lesser General Public License **
* *
* This library is free software: you can redistribute it and/or modify *
* it under the terms of the GNU Lesser General Public License as *
* published by the Free Software Foundation, either version 3 of the *
* License, or (at your option) any later version. *
* You should have received a copy of the GNU Lesser General Public *
* License along with this library. *
* If not, see <http://www.gnu.org/licenses/>. *
* *
* This library is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
****************************************************************************/
#ifndef LRSQLEDITDIALOG_H
#define LRSQLEDITDIALOG_H
#include <stdexcept>
#include <QDialog>
#include <QCompleter>
#include <QSettings>
#include "lrreportengine_p.h"
#include "lrdatasourcemanager.h"
#include "lrdatadesignintf.h"
namespace LimeReport{
namespace Ui {
class SQLEditDialog;
}
struct SQLEditResult;
class SQLEditDialog : public QDialog
{
Q_OBJECT
public:
enum SQLDialogMode {AddMode,EditMode};
explicit SQLEditDialog(QWidget *parent, LimeReport::DataSourceManager* dataSources,SQLDialogMode dialogMode);
void setDataSources(LimeReport::DataSourceManager *dataSources,QString datasourceName="");
void setDefaultConnection(QString defaultConnection);
~SQLEditDialog();
QSettings* settings();
void setSettings(QSettings* value, bool owned = false);
signals:
void signalSqlEditingFinished(SQLEditResult result);
protected:
void showEvent(QShowEvent *);
void closeEvent(QCloseEvent*);
void hideEvent(QHideEvent*);
void check();
void initConnections();
private slots:
void accept();
void slotDataSourceNameEditing();
void on_cbSubdetail_clicked(bool checked);
void on_rbProxy_clicked(bool checked);
void on_rbSubQuery_clicked(bool checked);
void on_pbAddField_clicked();
void initQueryMode();
void initSubQueryMode();
void initProxyMode();
void slotPreviewData();
void slotHidePreview();
private:
void writeSetting();
void readSettings();
void hidePreview();
private:
Ui::SQLEditDialog *ui;
LimeReport::DataSourceManager* m_datasources;
SQLDialogMode m_dialogMode;
QString m_oldDatasourceName;
QCompleter* m_masterDatasources;
QString m_defaultConnection;
QSettings* m_settings;
bool m_ownedSettings;
QSharedPointer<QAbstractItemModel> m_previewModel;
};
struct SQLEditResult{
enum ResultMode{Query,SubQuery,SubProxy};
QString connectionName;
QString datasourceName;
QString oldDatasourceName;
QString sql;
bool subdetail;
ResultMode resultMode;
QString masterDatasource;
QString childDataSource;
SQLEditDialog::SQLDialogMode dialogMode;
QList<LimeReport::FieldsCorrelation> fieldMap;
};
} // namespace LimeReport
#endif // LRSQLEDITDIALOG_H

View File

@@ -0,0 +1,859 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>LimeReport::SQLEditDialog</class>
<widget class="QDialog" name="LimeReport::SQLEditDialog">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>411</width>
<height>617</height>
</rect>
</property>
<property name="windowTitle">
<string>Datasource</string>
</property>
<property name="windowIcon">
<iconset resource="lrdatabrowser.qrc">
<normaloff>:/databrowser/images/database_disconnected</normaloff>:/databrowser/images/database_disconnected</iconset>
</property>
<property name="toolTip">
<string/>
</property>
<layout class="QVBoxLayout" name="verticalLayout_6">
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QLabel" name="label">
<property name="text">
<string>Connection</string>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="cbbConnection">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="focusPolicy">
<enum>Qt::NoFocus</enum>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QVBoxLayout" name="verticalLayout_3">
<item>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<widget class="QLabel" name="lblDatasourceName">
<property name="text">
<string>Datasource Name</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="leDatasourceName"/>
</item>
</layout>
</item>
<item>
<widget class="QLabel" name="lblInfo">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="palette">
<palette>
<active>
<colorrole role="WindowText">
<brush brushstyle="SolidPattern">
<color alpha="255">
<red>0</red>
<green>0</green>
<blue>0</blue>
</color>
</brush>
</colorrole>
<colorrole role="Button">
<brush brushstyle="SolidPattern">
<color alpha="255">
<red>255</red>
<green>255</green>
<blue>127</blue>
</color>
</brush>
</colorrole>
<colorrole role="Light">
<brush brushstyle="SolidPattern">
<color alpha="255">
<red>255</red>
<green>255</green>
<blue>255</blue>
</color>
</brush>
</colorrole>
<colorrole role="Midlight">
<brush brushstyle="SolidPattern">
<color alpha="255">
<red>255</red>
<green>255</green>
<blue>191</blue>
</color>
</brush>
</colorrole>
<colorrole role="Dark">
<brush brushstyle="SolidPattern">
<color alpha="255">
<red>127</red>
<green>127</green>
<blue>63</blue>
</color>
</brush>
</colorrole>
<colorrole role="Mid">
<brush brushstyle="SolidPattern">
<color alpha="255">
<red>170</red>
<green>170</green>
<blue>84</blue>
</color>
</brush>
</colorrole>
<colorrole role="Text">
<brush brushstyle="SolidPattern">
<color alpha="255">
<red>0</red>
<green>0</green>
<blue>0</blue>
</color>
</brush>
</colorrole>
<colorrole role="BrightText">
<brush brushstyle="SolidPattern">
<color alpha="255">
<red>255</red>
<green>255</green>
<blue>255</blue>
</color>
</brush>
</colorrole>
<colorrole role="ButtonText">
<brush brushstyle="SolidPattern">
<color alpha="255">
<red>0</red>
<green>0</green>
<blue>0</blue>
</color>
</brush>
</colorrole>
<colorrole role="Base">
<brush brushstyle="SolidPattern">
<color alpha="255">
<red>255</red>
<green>255</green>
<blue>255</blue>
</color>
</brush>
</colorrole>
<colorrole role="Window">
<brush brushstyle="SolidPattern">
<color alpha="255">
<red>255</red>
<green>255</green>
<blue>127</blue>
</color>
</brush>
</colorrole>
<colorrole role="Shadow">
<brush brushstyle="SolidPattern">
<color alpha="255">
<red>0</red>
<green>0</green>
<blue>0</blue>
</color>
</brush>
</colorrole>
<colorrole role="AlternateBase">
<brush brushstyle="SolidPattern">
<color alpha="255">
<red>255</red>
<green>255</green>
<blue>191</blue>
</color>
</brush>
</colorrole>
<colorrole role="ToolTipBase">
<brush brushstyle="SolidPattern">
<color alpha="255">
<red>255</red>
<green>255</green>
<blue>220</blue>
</color>
</brush>
</colorrole>
<colorrole role="ToolTipText">
<brush brushstyle="SolidPattern">
<color alpha="255">
<red>0</red>
<green>0</green>
<blue>0</blue>
</color>
</brush>
</colorrole>
</active>
<inactive>
<colorrole role="WindowText">
<brush brushstyle="SolidPattern">
<color alpha="255">
<red>0</red>
<green>0</green>
<blue>0</blue>
</color>
</brush>
</colorrole>
<colorrole role="Button">
<brush brushstyle="SolidPattern">
<color alpha="255">
<red>255</red>
<green>255</green>
<blue>127</blue>
</color>
</brush>
</colorrole>
<colorrole role="Light">
<brush brushstyle="SolidPattern">
<color alpha="255">
<red>255</red>
<green>255</green>
<blue>255</blue>
</color>
</brush>
</colorrole>
<colorrole role="Midlight">
<brush brushstyle="SolidPattern">
<color alpha="255">
<red>255</red>
<green>255</green>
<blue>191</blue>
</color>
</brush>
</colorrole>
<colorrole role="Dark">
<brush brushstyle="SolidPattern">
<color alpha="255">
<red>127</red>
<green>127</green>
<blue>63</blue>
</color>
</brush>
</colorrole>
<colorrole role="Mid">
<brush brushstyle="SolidPattern">
<color alpha="255">
<red>170</red>
<green>170</green>
<blue>84</blue>
</color>
</brush>
</colorrole>
<colorrole role="Text">
<brush brushstyle="SolidPattern">
<color alpha="255">
<red>0</red>
<green>0</green>
<blue>0</blue>
</color>
</brush>
</colorrole>
<colorrole role="BrightText">
<brush brushstyle="SolidPattern">
<color alpha="255">
<red>255</red>
<green>255</green>
<blue>255</blue>
</color>
</brush>
</colorrole>
<colorrole role="ButtonText">
<brush brushstyle="SolidPattern">
<color alpha="255">
<red>0</red>
<green>0</green>
<blue>0</blue>
</color>
</brush>
</colorrole>
<colorrole role="Base">
<brush brushstyle="SolidPattern">
<color alpha="255">
<red>255</red>
<green>255</green>
<blue>255</blue>
</color>
</brush>
</colorrole>
<colorrole role="Window">
<brush brushstyle="SolidPattern">
<color alpha="255">
<red>255</red>
<green>255</green>
<blue>127</blue>
</color>
</brush>
</colorrole>
<colorrole role="Shadow">
<brush brushstyle="SolidPattern">
<color alpha="255">
<red>0</red>
<green>0</green>
<blue>0</blue>
</color>
</brush>
</colorrole>
<colorrole role="AlternateBase">
<brush brushstyle="SolidPattern">
<color alpha="255">
<red>255</red>
<green>255</green>
<blue>191</blue>
</color>
</brush>
</colorrole>
<colorrole role="ToolTipBase">
<brush brushstyle="SolidPattern">
<color alpha="255">
<red>255</red>
<green>255</green>
<blue>220</blue>
</color>
</brush>
</colorrole>
<colorrole role="ToolTipText">
<brush brushstyle="SolidPattern">
<color alpha="255">
<red>0</red>
<green>0</green>
<blue>0</blue>
</color>
</brush>
</colorrole>
</inactive>
<disabled>
<colorrole role="WindowText">
<brush brushstyle="SolidPattern">
<color alpha="255">
<red>127</red>
<green>127</green>
<blue>63</blue>
</color>
</brush>
</colorrole>
<colorrole role="Button">
<brush brushstyle="SolidPattern">
<color alpha="255">
<red>255</red>
<green>255</green>
<blue>127</blue>
</color>
</brush>
</colorrole>
<colorrole role="Light">
<brush brushstyle="SolidPattern">
<color alpha="255">
<red>255</red>
<green>255</green>
<blue>255</blue>
</color>
</brush>
</colorrole>
<colorrole role="Midlight">
<brush brushstyle="SolidPattern">
<color alpha="255">
<red>255</red>
<green>255</green>
<blue>191</blue>
</color>
</brush>
</colorrole>
<colorrole role="Dark">
<brush brushstyle="SolidPattern">
<color alpha="255">
<red>127</red>
<green>127</green>
<blue>63</blue>
</color>
</brush>
</colorrole>
<colorrole role="Mid">
<brush brushstyle="SolidPattern">
<color alpha="255">
<red>170</red>
<green>170</green>
<blue>84</blue>
</color>
</brush>
</colorrole>
<colorrole role="Text">
<brush brushstyle="SolidPattern">
<color alpha="255">
<red>127</red>
<green>127</green>
<blue>63</blue>
</color>
</brush>
</colorrole>
<colorrole role="BrightText">
<brush brushstyle="SolidPattern">
<color alpha="255">
<red>255</red>
<green>255</green>
<blue>255</blue>
</color>
</brush>
</colorrole>
<colorrole role="ButtonText">
<brush brushstyle="SolidPattern">
<color alpha="255">
<red>127</red>
<green>127</green>
<blue>63</blue>
</color>
</brush>
</colorrole>
<colorrole role="Base">
<brush brushstyle="SolidPattern">
<color alpha="255">
<red>255</red>
<green>255</green>
<blue>127</blue>
</color>
</brush>
</colorrole>
<colorrole role="Window">
<brush brushstyle="SolidPattern">
<color alpha="255">
<red>255</red>
<green>255</green>
<blue>127</blue>
</color>
</brush>
</colorrole>
<colorrole role="Shadow">
<brush brushstyle="SolidPattern">
<color alpha="255">
<red>0</red>
<green>0</green>
<blue>0</blue>
</color>
</brush>
</colorrole>
<colorrole role="AlternateBase">
<brush brushstyle="SolidPattern">
<color alpha="255">
<red>255</red>
<green>255</green>
<blue>127</blue>
</color>
</brush>
</colorrole>
<colorrole role="ToolTipBase">
<brush brushstyle="SolidPattern">
<color alpha="255">
<red>255</red>
<green>255</green>
<blue>220</blue>
</color>
</brush>
</colorrole>
<colorrole role="ToolTipText">
<brush brushstyle="SolidPattern">
<color alpha="255">
<red>0</red>
<green>0</green>
<blue>0</blue>
</color>
</brush>
</colorrole>
</disabled>
</palette>
</property>
<property name="autoFillBackground">
<bool>true</bool>
</property>
<property name="text">
<string/>
</property>
<property name="indent">
<number>-1</number>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QVBoxLayout" name="verticalLayout_4">
<item>
<widget class="QCheckBox" name="cbSubdetail">
<property name="text">
<string>Subdetail</string>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="hlMasterDatasource">
<item>
<widget class="QLabel" name="lbMaster">
<property name="text">
<string>Master datasource</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="leMaster">
<property name="enabled">
<bool>false</bool>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="QRadioButton" name="rbSubQuery">
<property name="enabled">
<bool>false</bool>
</property>
<property name="text">
<string>Subquery mode</string>
</property>
</widget>
</item>
<item>
<widget class="QRadioButton" name="rbProxy">
<property name="enabled">
<bool>false</bool>
</property>
<property name="text">
<string>Filter mode</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="QGroupBox" name="gbSQL">
<property name="title">
<string>SQL</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_2">
<property name="spacing">
<number>4</number>
</property>
<property name="leftMargin">
<number>2</number>
</property>
<property name="topMargin">
<number>2</number>
</property>
<property name="rightMargin">
<number>2</number>
</property>
<property name="bottomMargin">
<number>2</number>
</property>
<item>
<widget class="QTextEdit" name="textEditSQL"/>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_6">
<item>
<spacer name="horizontalSpacer_2">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QPushButton" name="pbPreview">
<property name="text">
<string>Preview</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="pbHidePreview">
<property name="text">
<string>Hide Preview</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QFrame" name="pnlChildDatasource">
<property name="frameShape">
<enum>QFrame::NoFrame</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Raised</enum>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<property name="spacing">
<number>0</number>
</property>
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<layout class="QHBoxLayout" name="hlChildDatasource">
<item>
<widget class="QLabel" name="label_4">
<property name="text">
<string>Child datasource</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="leChild"/>
</item>
</layout>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QGroupBox" name="gbFieldsMap">
<property name="title">
<string>Fields map</string>
</property>
<layout class="QHBoxLayout" name="horizontalLayout_4">
<property name="leftMargin">
<number>4</number>
</property>
<property name="topMargin">
<number>4</number>
</property>
<property name="rightMargin">
<number>4</number>
</property>
<property name="bottomMargin">
<number>4</number>
</property>
<item>
<widget class="QTableWidget" name="fieldsMap">
<property name="columnCount">
<number>2</number>
</property>
<column/>
<column/>
</widget>
</item>
<item>
<layout class="QVBoxLayout" name="verticalLayout_5">
<item>
<widget class="QToolButton" name="pbAddField">
<property name="text">
<string>...</string>
</property>
<property name="icon">
<iconset resource="lrdatabrowser.qrc">
<normaloff>:/databrowser/images/add.png</normaloff>:/databrowser/images/add.png</iconset>
</property>
<property name="autoRaise">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QToolButton" name="pbDelField">
<property name="text">
<string>...</string>
</property>
<property name="icon">
<iconset resource="lrdatabrowser.qrc">
<normaloff>:/databrowser/images/remove.png</normaloff>:/databrowser/images/remove.png</iconset>
</property>
<property name="autoRaise">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QGroupBox" name="gbDataPreview">
<property name="title">
<string>Data preview</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_7">
<property name="spacing">
<number>2</number>
</property>
<property name="leftMargin">
<number>2</number>
</property>
<property name="topMargin">
<number>2</number>
</property>
<property name="rightMargin">
<number>2</number>
</property>
<property name="bottomMargin">
<number>2</number>
</property>
<item>
<widget class="QTableView" name="tvPreview"/>
</item>
</layout>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_5">
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QPushButton" name="pushButton_2">
<property name="text">
<string>Cancel</string>
</property>
<property name="autoDefault">
<bool>false</bool>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="pushButton">
<property name="text">
<string>Ok</string>
</property>
<property name="autoDefault">
<bool>false</bool>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
<tabstops>
<tabstop>leDatasourceName</tabstop>
<tabstop>cbSubdetail</tabstop>
<tabstop>leMaster</tabstop>
<tabstop>rbSubQuery</tabstop>
<tabstop>rbProxy</tabstop>
<tabstop>textEditSQL</tabstop>
<tabstop>leChild</tabstop>
<tabstop>fieldsMap</tabstop>
<tabstop>pbAddField</tabstop>
<tabstop>pbDelField</tabstop>
<tabstop>pushButton_2</tabstop>
<tabstop>pushButton</tabstop>
</tabstops>
<resources>
<include location="lrdatabrowser.qrc"/>
</resources>
<connections>
<connection>
<sender>leDatasourceName</sender>
<signal>textChanged(QString)</signal>
<receiver>LimeReport::SQLEditDialog</receiver>
<slot>slotDataSourceNameEditing()</slot>
<hints>
<hint type="sourcelabel">
<x>259</x>
<y>54</y>
</hint>
<hint type="destinationlabel">
<x>289</x>
<y>32</y>
</hint>
</hints>
</connection>
<connection>
<sender>pushButton</sender>
<signal>clicked()</signal>
<receiver>LimeReport::SQLEditDialog</receiver>
<slot>accept()</slot>
<hints>
<hint type="sourcelabel">
<x>397</x>
<y>536</y>
</hint>
<hint type="destinationlabel">
<x>380</x>
<y>360</y>
</hint>
</hints>
</connection>
<connection>
<sender>pushButton_2</sender>
<signal>clicked()</signal>
<receiver>LimeReport::SQLEditDialog</receiver>
<slot>reject()</slot>
<hints>
<hint type="sourcelabel">
<x>278</x>
<y>538</y>
</hint>
<hint type="destinationlabel">
<x>299</x>
<y>383</y>
</hint>
</hints>
</connection>
</connections>
<slots>
<slot>slotDataSourceNameEditing()</slot>
</slots>
</ui>

View File

@@ -0,0 +1,99 @@
/***************************************************************************
* This file is part of the Lime Report project *
* Copyright (C) 2015 by Alexander Arin *
* arin_a@bk.ru *
* *
** GNU General Public License Usage **
* *
* This library is free software: you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation, either version 3 of the License, or *
* (at your option) any later version. *
* You should have received a copy of the GNU General Public License *
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
* *
** GNU Lesser General Public License **
* *
* This library is free software: you can redistribute it and/or modify *
* it under the terms of the GNU Lesser General Public License as *
* published by the Free Software Foundation, either version 3 of the *
* License, or (at your option) any later version. *
* You should have received a copy of the GNU Lesser General Public *
* License along with this library. *
* If not, see <http://www.gnu.org/licenses/>. *
* *
* This library is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
****************************************************************************/
#include "lrvariabledialog.h"
#include "ui_lrvariabledialog.h"
#include "lrglobal.h"
#include <stdexcept>
#include <QMessageBox>
LRVariableDialog::LRVariableDialog(QWidget *parent) :
QDialog(parent),
ui(new Ui::LRVariableDialog),
m_variableName(""),
m_variablesContainer(0),
m_changeMode(false),
m_oldVariableName("")
{
ui->setupUi(this);
ui->cbbType->setVisible(false);
ui->lblType->setVisible(false);
}
LRVariableDialog::~LRVariableDialog()
{
delete ui;
}
void LRVariableDialog::setVariableContainer(LimeReport::IVariablesContainer *value)
{
m_variablesContainer=value;
}
void LRVariableDialog::setVariableName(const QString &value)
{
m_variableName=value;
m_changeMode=true;
m_oldVariableName=value;
}
void LRVariableDialog::showEvent(QShowEvent *)
{
ui->leName->setText(m_variableName);
if (!m_variableName.isEmpty()&&m_variablesContainer&&m_variablesContainer->containsVariable(m_variableName)){
ui->leValue->setText(m_variablesContainer->variable(m_variableName).toString());
}
}
void LRVariableDialog::accept()
{
try{
if (m_variablesContainer&&!ui->leName->text().isEmpty()){
if (m_changeMode){
if (m_oldVariableName==ui->leName->text()){
m_variablesContainer->changeVariable(m_oldVariableName,value());
} else {
m_variablesContainer->deleteVariable(m_oldVariableName);
m_variablesContainer->addVariable(ui->leName->text(),value());
}
} else {
m_variablesContainer->addVariable(ui->leName->text(),value());
}
emit signalVariableAccepted(ui->leName->text());
QDialog::accept();
}
} catch (LimeReport::ReportError &exception){
QMessageBox::critical(this,tr("Attention"),exception.what());
}
}
QVariant LRVariableDialog::value()
{
return ui->leValue->text();
}

View File

@@ -0,0 +1,65 @@
/***************************************************************************
* This file is part of the Lime Report project *
* Copyright (C) 2015 by Alexander Arin *
* arin_a@bk.ru *
* *
** GNU General Public License Usage **
* *
* This library is free software: you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation, either version 3 of the License, or *
* (at your option) any later version. *
* You should have received a copy of the GNU General Public License *
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
* *
** GNU Lesser General Public License **
* *
* This library is free software: you can redistribute it and/or modify *
* it under the terms of the GNU Lesser General Public License as *
* published by the Free Software Foundation, either version 3 of the *
* License, or (at your option) any later version. *
* You should have received a copy of the GNU Lesser General Public *
* License along with this library. *
* If not, see <http://www.gnu.org/licenses/>. *
* *
* This library is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
****************************************************************************/
#ifndef LRVARIABLEDIALOG_H
#define LRVARIABLEDIALOG_H
#include <QDialog>
#include "lrvariablesholder.h"
namespace Ui {
class LRVariableDialog;
}
class LRVariableDialog : public QDialog
{
Q_OBJECT
public:
explicit LRVariableDialog(QWidget *parent = 0);
~LRVariableDialog();
void setVariableContainer(LimeReport::IVariablesContainer *value);
void setVariableName(const QString &value);
protected:
void showEvent(QShowEvent *);
private slots:
void accept();
signals:
void signalVariableAccepted(const QString &variable);
private:
QVariant value();
private:
Ui::LRVariableDialog *ui;
QString m_variableName;
LimeReport::IVariablesContainer* m_variablesContainer;
bool m_changeMode;
QString m_oldVariableName;
};
#endif // LRVARIABLEDIALOG_H

View File

@@ -0,0 +1,131 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>LRVariableDialog</class>
<widget class="QDialog" name="LRVariableDialog">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>218</width>
<height>126</height>
</rect>
</property>
<property name="windowTitle">
<string>Variable</string>
</property>
<property name="windowIcon">
<iconset resource="lrdatabrowser.qrc">
<normaloff>:/databrowser/images/value</normaloff>:/databrowser/images/value</iconset>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<property name="spacing">
<number>2</number>
</property>
<property name="leftMargin">
<number>4</number>
</property>
<property name="topMargin">
<number>4</number>
</property>
<property name="rightMargin">
<number>4</number>
</property>
<property name="bottomMargin">
<number>4</number>
</property>
<item>
<layout class="QFormLayout" name="formLayout">
<property name="horizontalSpacing">
<number>7</number>
</property>
<property name="verticalSpacing">
<number>5</number>
</property>
<property name="leftMargin">
<number>4</number>
</property>
<property name="topMargin">
<number>8</number>
</property>
<item row="0" column="0">
<widget class="QLabel" name="lblName">
<property name="text">
<string>Name</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QLineEdit" name="leName"/>
</item>
<item row="1" column="0">
<widget class="QLabel" name="lblValue">
<property name="text">
<string>Value</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QLineEdit" name="leValue"/>
</item>
<item row="2" column="1">
<widget class="QComboBox" name="cbbType"/>
</item>
<item row="2" column="0">
<widget class="QLabel" name="lblType">
<property name="text">
<string>Type</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="QDialogButtonBox" name="buttonBox">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
</property>
</widget>
</item>
</layout>
</widget>
<resources>
<include location="lrdatabrowser.qrc"/>
</resources>
<connections>
<connection>
<sender>buttonBox</sender>
<signal>accepted()</signal>
<receiver>LRVariableDialog</receiver>
<slot>accept()</slot>
<hints>
<hint type="sourcelabel">
<x>248</x>
<y>254</y>
</hint>
<hint type="destinationlabel">
<x>157</x>
<y>274</y>
</hint>
</hints>
</connection>
<connection>
<sender>buttonBox</sender>
<signal>rejected()</signal>
<receiver>LRVariableDialog</receiver>
<slot>reject()</slot>
<hints>
<hint type="sourcelabel">
<x>316</x>
<y>260</y>
</hint>
<hint type="destinationlabel">
<x>286</x>
<y>274</y>
</hint>
</hints>
</connection>
</connections>
</ui>