diff --git a/limereport/databrowser/images/varToReport.png b/limereport/databrowser/images/varToReport.png new file mode 100644 index 0000000..8fd0afe Binary files /dev/null and b/limereport/databrowser/images/varToReport.png differ diff --git a/limereport/databrowser/lrdatabrowser.cpp b/limereport/databrowser/lrdatabrowser.cpp index 6b26163..4629d0e 100644 --- a/limereport/databrowser/lrdatabrowser.cpp +++ b/limereport/databrowser/lrdatabrowser.cpp @@ -208,12 +208,15 @@ void DataBrowser::updateDataTree() void DataBrowser::updateVariablesTree() { ui->variablesTree->clear(); - QTreeWidgetItem *userVariables =new QTreeWidgetItem(QStringList(tr("User variables")),DataBrowserTree::Category); - userVariables->setIcon(0,QIcon(":/report/images/folder")); + QTreeWidgetItem *reportVariables = new QTreeWidgetItem(QStringList(tr("Report variables")),DataBrowserTree::Category); + reportVariables->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); + QTreeWidgetItem *externalVariables = new QTreeWidgetItem(QStringList(tr("External variables")),DataBrowserTree::Category); + externalVariables->setIcon(0,QIcon(":/report/images/folder")); + ui->variablesTree->addTopLevelItem(reportVariables); ui->variablesTree->addTopLevelItem(systemVariables); + ui->variablesTree->addTopLevelItem(externalVariables); foreach(QString variableName,m_report->dataManager()->variableNames()){ QStringList values; @@ -227,12 +230,24 @@ void DataBrowser::updateVariablesTree() if (m_report->dataManager()->variableIsSystem(variableName)){ systemVariables->addChild(item); } else { - userVariables->addChild(item); + reportVariables->addChild(item); } } - ui->variablesTree->expandItem(userVariables); + foreach(QString variableName,m_report->dataManager()->namesOfUserVariables()){ + if (!m_report->dataManager()->variableNames().contains(variableName)){ + QStringList values; + values<dataManager()->variable(variableName).toString()+"]" + <setIcon(0,QIcon(":/databrowser/images/value")); + externalVariables->addChild(item); + } + } + + ui->variablesTree->expandItem(reportVariables); ui->variablesTree->expandItem(systemVariables); + ui->variablesTree->expandItem(externalVariables); } void DataBrowser::closeAllDataWindows() @@ -333,7 +348,11 @@ QString DataBrowser::getConnectionName() QString DataBrowser::getVariable() { - if(ui->variablesTree->currentItem()&&ui->variablesTree->currentItem()->type() == DataBrowserTree::Variable){ + if( + ui->variablesTree->currentItem() && + (ui->variablesTree->currentItem()->type() == DataBrowserTree::Variable || + ui->variablesTree->currentItem()->type() == DataBrowserTree::ExternalVariable) + ){ return ui->variablesTree->currentItem()->text(1); } return QString(); @@ -369,7 +388,7 @@ void DataBrowser::slotDeleteDatasource() tr("Do you really want to delete \"%1\" datasource ?").arg(datasourceName), QMessageBox::Ok|QMessageBox::No, QMessageBox::No - )==QMessageBox::Ok + ) == QMessageBox::Ok ){ removeDatasource(datasourceName); } @@ -390,6 +409,7 @@ void DataBrowser::slotClear() ui->dataTree->clear(); foreach(QDockWidget* window,m_dataWindows.values()) window->close(); updateDataTree(); + updateVariablesTree(); } void DataBrowser::initConnections() @@ -696,16 +716,24 @@ void DataBrowser::on_deleteVariable_clicked() 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); + if (m_report->dataManager()->containsVariable(current->text(1))){ + if (m_report->dataManager()->variableType(current->text(1)) == VarDesc::Report){ + ui->editVariable->setEnabled(true); + ui->deleteVariable->setEnabled(true); + } else { + ui->editVariable->setEnabled(false); + ui->deleteVariable->setEnabled(false); + } + if (m_report->dataManager()->variableType(current->text(1)) == VarDesc::User){ + ui->varToReport->setEnabled(true); + } else { + ui->varToReport->setEnabled(false); + } } else { ui->editVariable->setEnabled(false); ui->deleteVariable->setEnabled(false); + ui->varToReport->setEnabled(false); } } } @@ -717,8 +745,47 @@ void DataBrowser::on_errorMessage_clicked() } } +void DataBrowser::on_varToReport_clicked() +{ + QString varName = getVariable(); + if (!varName.isEmpty()){ + m_report->dataManager()->addVariable(varName,m_report->dataManager()->variable(varName), VarDesc::Report); + ui->varToReport->setEnabled(false); + updateVariablesTree(); + } + +} + +void DataBrowser::on_variablesTree_itemDoubleClicked(QTreeWidgetItem *item, int ) +{ + if (item){ + QString varName = item->text(1); + if ( + !varName.isEmpty() && + (m_report->dataManager()->variableType(varName) == VarDesc::Report) + ){ + LRVariableDialog dialog(this); + #ifdef Q_OS_MAC + dialog.setWindowModality(Qt::WindowModal); + #else + dialog.setWindowModality(Qt::ApplicationModal); + #endif + dialog.setVariableContainer(m_report->dataManager()); + dialog.setVariableName(varName); + connect(&dialog,SIGNAL(signalVariableAccepted(QString)),this,SLOT(slotVariableEditorAccept(QString))); + dialog.exec(); + } + } +} + } // namespace LimeReport + + + + + + diff --git a/limereport/databrowser/lrdatabrowser.h b/limereport/databrowser/lrdatabrowser.h index 4aa9de8..b068742 100644 --- a/limereport/databrowser/lrdatabrowser.h +++ b/limereport/databrowser/lrdatabrowser.h @@ -83,6 +83,9 @@ private slots: void on_addVariable_clicked(); void on_variablesTree_currentItemChanged(QTreeWidgetItem *current, QTreeWidgetItem *previous); void on_errorMessage_clicked(); + void on_varToReport_clicked(); + void on_variablesTree_itemDoubleClicked(QTreeWidgetItem *item, int); + private: QString getDatasourceName(); QString getConnectionName(); diff --git a/limereport/databrowser/lrdatabrowser.qrc b/limereport/databrowser/lrdatabrowser.qrc index 7a46b64..aa4f852 100644 --- a/limereport/databrowser/lrdatabrowser.qrc +++ b/limereport/databrowser/lrdatabrowser.qrc @@ -43,5 +43,6 @@ images/value_add2.png images/value_edit2.png images/value1.png + images/varToReport.png diff --git a/limereport/databrowser/lrdatabrowser.ui b/limereport/databrowser/lrdatabrowser.ui index 26e070a..2bfc7a6 100644 --- a/limereport/databrowser/lrdatabrowser.ui +++ b/limereport/databrowser/lrdatabrowser.ui @@ -35,7 +35,7 @@ QTabWidget::South - 0 + 1 @@ -429,6 +429,26 @@ + + + + false + + + Grab variable + + + ... + + + + :/databrowser/images/varToReport:/databrowser/images/varToReport + + + true + + + diff --git a/limereport/databrowser/lrdatabrowsertree.h b/limereport/databrowser/lrdatabrowsertree.h index 9cce57f..0614cdc 100644 --- a/limereport/databrowser/lrdatabrowsertree.h +++ b/limereport/databrowser/lrdatabrowsertree.h @@ -39,7 +39,7 @@ class DataBrowserTree : public QTreeWidget { Q_OBJECT public: - enum NodeType{Connection,Table,Row,Category,Variable}; + enum NodeType{Connection, Table, Row, Category, Variable, ExternalVariable}; explicit DataBrowserTree(QWidget *parent = 0); protected: QMimeData* mimeData(const QList items) const; diff --git a/limereport/databrowser/lrvariabledialog.cpp b/limereport/databrowser/lrvariabledialog.cpp index a2d5dec..4cebd55 100644 --- a/limereport/databrowser/lrvariabledialog.cpp +++ b/limereport/databrowser/lrvariabledialog.cpp @@ -80,10 +80,10 @@ void LRVariableDialog::accept() m_variablesContainer->changeVariable(m_oldVariableName,value()); } else { m_variablesContainer->deleteVariable(m_oldVariableName); - m_variablesContainer->addVariable(ui->leName->text(),value()); + m_variablesContainer->addVariable(ui->leName->text(),value(), LimeReport::VarDesc::Report); } } else { - m_variablesContainer->addVariable(ui->leName->text(),value()); + m_variablesContainer->addVariable(ui->leName->text(),value(), LimeReport::VarDesc::Report); } emit signalVariableAccepted(ui->leName->text()); QDialog::accept(); diff --git a/limereport/lrdatadesignintf.cpp b/limereport/lrdatadesignintf.cpp index 4281494..9b8e86a 100644 --- a/limereport/lrdatadesignintf.cpp +++ b/limereport/lrdatadesignintf.cpp @@ -563,10 +563,10 @@ bool MasterDetailProxyModel::filterAcceptsRow(int source_row, const QModelIndex int MasterDetailProxyModel::fieldIndexByName(QString fieldName) const { for(int i=0;icolumnCount();++i){ - QString fieldName = sourceModel()->headerData(i,Qt::Horizontal,Qt::UserRole).isValid()? + QString sourceFieldName = sourceModel()->headerData(i,Qt::Horizontal,Qt::UserRole).isValid()? sourceModel()->headerData(i,Qt::Horizontal,Qt::UserRole).toString(): sourceModel()->headerData(i,Qt::Horizontal).toString(); - if (fieldName.compare(fieldName,Qt::CaseInsensitive)==0){ + if (sourceFieldName.compare(fieldName,Qt::CaseInsensitive)==0){ return i; } } diff --git a/limereport/lrdatasourcemanager.cpp b/limereport/lrdatasourcemanager.cpp index 943ad03..55a3423 100644 --- a/limereport/lrdatasourcemanager.cpp +++ b/limereport/lrdatasourcemanager.cpp @@ -322,6 +322,10 @@ QSharedPointerDataSourceManager::previewSQL(const QString &c } query.exec(); + while (query.next()){ + qDebug()<setQuery(query); m_lastError = model->lastError().text(); if (model->query().isActive()) @@ -705,6 +709,11 @@ bool DataSourceManager::connectConnection(ConnectionDesc *connectionDesc) return true; } +void DataSourceManager::clearReportVariables() +{ + m_reportVariables.clearUserVariables(); +} + void DataSourceManager::connectAutoConnections() { foreach(ConnectionDesc* conn,m_connections){ @@ -918,7 +927,7 @@ int DataSourceManager::elementsCount(const QString &collectionName) return m_proxies.count(); } if (collectionName=="variables"){ - return m_varHolder.userVariablesCount(); + return m_reportVariables.userVariablesCount(); } return 0; } @@ -938,7 +947,7 @@ QObject* DataSourceManager::elementAt(const QString &collectionName, int index) return m_proxies.at(index); } if (collectionName=="variables"){ - return m_varHolder.userVariableAt(index); + return m_reportVariables.userVariableAt(index); } return 0; } @@ -970,8 +979,8 @@ void DataSourceManager::collectionLoadFinished(const QString &collectionName) if(collectionName.compare("variables",Qt::CaseInsensitive)==0){ foreach (VarDesc* item, m_tempVars) { - if (!m_varHolder.containsVariable(item->name())){ - m_varHolder.addVariable(item->name(),item->value(),VarDesc::User,FirstPass); + if (!m_reportVariables.containsVariable(item->name())){ + m_reportVariables.addVariable(item->name(),item->value(),VarDesc::Report,FirstPass); } delete item; } @@ -984,15 +993,20 @@ void DataSourceManager::collectionLoadFinished(const QString &collectionName) void DataSourceManager::addVariable(const QString &name, const QVariant &value, VarDesc::VarType type, RenderPass pass) { - m_varHolder.addVariable(name,value,type,pass); + if (type == VarDesc::User){ + m_userVariables.addVariable(name, value, type, pass); + } else { + m_reportVariables.addVariable(name,value,type,pass); + } if (designTime()) emit datasourcesChanged(); } void DataSourceManager::deleteVariable(const QString& name) { - if (m_varHolder.containsVariable(name)&&m_varHolder.variableType(name)==VarDesc::User){ - m_varHolder.deleteVariable(name); + m_userVariables.deleteVariable(name); + if (m_reportVariables.containsVariable(name)&&m_reportVariables.variableType(name)==VarDesc::Report){ + m_reportVariables.deleteVariable(name); if (designTime()) emit datasourcesChanged(); } @@ -1000,7 +1014,12 @@ void DataSourceManager::deleteVariable(const QString& name) void DataSourceManager::changeVariable(const QString& name,const QVariant& value) { - m_varHolder.changeVariable(name,value); + if (m_userVariables.containsVariable(name)){ + m_userVariables.changeVariable(name,value); + } + if (m_reportVariables.containsVariable(name)){ + m_reportVariables.changeVariable(name,value); + } } void DataSourceManager::setSystemVariable(const QString &name, const QVariant &value, RenderPass pass) @@ -1079,8 +1098,9 @@ void DataSourceManager::clear(ClearMethod method) m_queries.clear(); m_subqueries.clear(); m_proxies.clear(); - - clearUserVariables(); +// if (method == All) +// clearUserVariables(); + clearReportVariables(); emit cleared(); } @@ -1161,12 +1181,14 @@ bool DataSourceManager::containsField(const QString &fieldName) bool DataSourceManager::containsVariable(const QString& variableName) { - return m_varHolder.containsVariable(variableName); + if (m_userVariables.containsVariable(variableName)) return true; + return m_reportVariables.containsVariable(variableName); } void DataSourceManager::clearUserVariables() { - m_varHolder.clearUserVariables(); + m_userVariables.clearUserVariables(); + m_reportVariables.clearUserVariables(); } QVariant DataSourceManager::fieldData(const QString &fieldName) @@ -1180,28 +1202,38 @@ QVariant DataSourceManager::fieldData(const QString &fieldName) QVariant DataSourceManager::variable(const QString &variableName) { - return m_varHolder.variable(variableName); + if (m_userVariables.containsVariable(variableName)) + return m_userVariables.variable(variableName); + return m_reportVariables.variable(variableName); } RenderPass DataSourceManager::variablePass(const QString &name) { - return (m_varHolder.variablePass(name)==FirstPass)?FirstPass:SecondPass; + return (m_reportVariables.variablePass(name)==FirstPass)?FirstPass:SecondPass; } bool DataSourceManager::variableIsSystem(const QString &name) { - return (m_varHolder.variableType(name)==VarDesc::System); + if (m_reportVariables.containsVariable(name)) + return (m_reportVariables.variableType(name)==VarDesc::System); + return false; } QStringList DataSourceManager::variableNames() { - return m_varHolder.variableNames(); + return m_reportVariables.variableNames(); +} + +QStringList DataSourceManager::namesOfUserVariables(){ + return m_userVariables.variableNames(); } VarDesc::VarType DataSourceManager::variableType(const QString &name) { - return m_varHolder.variableType(name); + if (m_reportVariables.containsVariable(name)) + return m_reportVariables.variableType(name); + return VarDesc::User; } void DataSourceManager::setAllDatasourcesToFirst() diff --git a/limereport/lrdatasourcemanager.h b/limereport/lrdatasourcemanager.h index 642757a..494ec20 100644 --- a/limereport/lrdatasourcemanager.h +++ b/limereport/lrdatasourcemanager.h @@ -121,9 +121,12 @@ public: void deleteVariable(const QString& name); bool containsVariable(const QString& variableName); void clearUserVariables(); + void addVariable(const QString& name, const QVariant& value, VarDesc::VarType type=VarDesc::User, RenderPass pass=FirstPass); + void changeVariable(const QString& name,const QVariant& value); QVariant variable(const QString& variableName); RenderPass variablePass(const QString& name); QStringList variableNames(); + QStringList namesOfUserVariables(); VarDesc::VarType variableType(const QString& name); bool variableIsSystem(const QString& name); QString queryText(const QString& dataSourceName); @@ -198,7 +201,7 @@ protected: void putSubQueryDesc(SubQueryDesc *subQueryDesc); void putProxyDesc(ProxyDesc *proxyDesc); bool connectConnection(ConnectionDesc* connectionDesc); - + void clearReportVariables(); QList childDatasources(const QString& datasourceName); void invalidateChildren(const QString& parentDatasourceName); //ICollectionContainer @@ -207,8 +210,7 @@ protected: virtual QObject *elementAt(const QString& collectionName,int index); virtual void collectionLoadFinished(const QString& collectionName); - void addVariable(const QString& name, const QVariant& value, VarDesc::VarType type=VarDesc::User, RenderPass pass=FirstPass); - void changeVariable(const QString& name,const QVariant& value); + void setSystemVariable(const QString& name, const QVariant& value, RenderPass pass); void setLastError(const QString& value); void invalidateLinkedDatasources(QString datasourceName); @@ -227,7 +229,8 @@ private: QMultiMap m_groupFunctions; GroupFunctionFactory m_groupFunctionFactory; - AVariablesHolder m_varHolder; + VariablesHolder m_reportVariables; + VariablesHolder m_userVariables; DataSourcesMap m_datasources; DataSourceModel m_datasourcesModel; QString m_lastError; diff --git a/limereport/lrreportrender.cpp b/limereport/lrreportrender.cpp index c1b84ca..8446336 100644 --- a/limereport/lrreportrender.cpp +++ b/limereport/lrreportrender.cpp @@ -147,8 +147,8 @@ void ReportRender::renameChildItems(BaseDesignIntf *item){ } ReportRender::ReportRender(QObject *parent) - :QObject(parent), m_renderPageItem(0), m_pageCount(0), m_currentColumn(0), - m_lastDataBand(0), m_lastRenderedFooter(0) + :QObject(parent), m_renderPageItem(0), m_pageCount(0), + m_lastDataBand(0), m_lastRenderedFooter(0), m_currentColumn(0) { initColumns(); } diff --git a/limereport/lrvariablesholder.cpp b/limereport/lrvariablesholder.cpp index 7b3d224..b9a92ea 100644 --- a/limereport/lrvariablesholder.cpp +++ b/limereport/lrvariablesholder.cpp @@ -34,12 +34,12 @@ namespace LimeReport{ -AVariablesHolder::AVariablesHolder(QObject *parent) : +VariablesHolder::VariablesHolder(QObject *parent) : QObject(parent) { } -AVariablesHolder::~AVariablesHolder() +VariablesHolder::~VariablesHolder() { QMap::iterator it = m_varNames.begin(); while(it!=m_varNames.end()){ @@ -50,7 +50,7 @@ AVariablesHolder::~AVariablesHolder() m_userVariables.clear(); } -void AVariablesHolder::addVariable(const QString& name, const QVariant& value, VarDesc::VarType type, RenderPass pass) +void VariablesHolder::addVariable(const QString& name, const QVariant& value, VarDesc::VarType type, RenderPass pass) { if (!m_varNames.contains(name)){ VarDesc* varValue = new VarDesc; @@ -66,21 +66,21 @@ void AVariablesHolder::addVariable(const QString& name, const QVariant& value, V } } -QVariant AVariablesHolder::variable(const QString &name) +QVariant VariablesHolder::variable(const QString &name) { if (m_varNames.contains(name)) return m_varNames.value(name)->value(); else return QVariant(); } -VarDesc::VarType AVariablesHolder::variableType(const QString &name) +VarDesc::VarType VariablesHolder::variableType(const QString &name) { if (m_varNames.contains(name)) return m_varNames.value(name)->varType(); else throw ReportError(tr("variable with name ")+name+tr(" does not exists !!")); } -void AVariablesHolder::deleteVariable(const QString &name) +void VariablesHolder::deleteVariable(const QString &name) { if (m_varNames.contains(name)) { m_userVariables.removeOne(m_varNames.value(name)); @@ -89,7 +89,7 @@ void AVariablesHolder::deleteVariable(const QString &name) } } -void AVariablesHolder::changeVariable(const QString &name, const QVariant &value) +void VariablesHolder::changeVariable(const QString &name, const QVariant &value) { if(m_varNames.contains(name)) { m_varNames.value(name)->setValue(value); @@ -97,11 +97,12 @@ void AVariablesHolder::changeVariable(const QString &name, const QVariant &value throw ReportError(tr("variable with name ")+name+tr(" does not exists !!")); } -void AVariablesHolder::clearUserVariables() +void VariablesHolder::clearUserVariables() { QMap::iterator it = m_varNames.begin(); while (it != m_varNames.end()){ - if (it.value()->varType()==VarDesc::User){ + if (it.value()->varType()==VarDesc::User || + it.value()->varType()==VarDesc::Report){ m_userVariables.removeAll(it.value()); delete it.value(); it = m_varNames.erase(it); @@ -113,22 +114,22 @@ void AVariablesHolder::clearUserVariables() } -bool AVariablesHolder::containsVariable(const QString &name) +bool VariablesHolder::containsVariable(const QString &name) { return m_varNames.contains(name); } -int AVariablesHolder::userVariablesCount() +int VariablesHolder::userVariablesCount() { return m_userVariables.count(); } -VarDesc *AVariablesHolder::userVariableAt(int index) +VarDesc *VariablesHolder::userVariableAt(int index) { return m_userVariables.at(index); } -QStringList AVariablesHolder::variableNames() +QStringList VariablesHolder::variableNames() { QStringList result; foreach(QString varName,m_varNames.keys()){ @@ -137,7 +138,7 @@ QStringList AVariablesHolder::variableNames() return result; } -RenderPass AVariablesHolder::variablePass(const QString &name) +RenderPass VariablesHolder::variablePass(const QString &name) { if (m_varNames.contains(name)) return m_varNames.value(name)->renderPass(); diff --git a/limereport/lrvariablesholder.h b/limereport/lrvariablesholder.h index c55397f..ede1ac6 100644 --- a/limereport/lrvariablesholder.h +++ b/limereport/lrvariablesholder.h @@ -43,7 +43,7 @@ class VarDesc : public QObject{ Q_PROPERTY(QString name READ name WRITE setName) Q_PROPERTY(QVariant value READ value WRITE setValue) public: - enum VarType {System,User}; + enum VarType {System, User, Report}; void setVarType(VarType value){m_varType=value;} VarType varType(){return m_varType;} void setRenderPass(RenderPass value){m_varPass=value;} @@ -74,12 +74,12 @@ public: virtual QStringList variableNames()=0; }; -class AVariablesHolder : public QObject, public IVariablesContainer +class VariablesHolder : public QObject, public IVariablesContainer { Q_OBJECT public: - explicit AVariablesHolder(QObject *parent = 0); - ~AVariablesHolder(); + explicit VariablesHolder(QObject *parent = 0); + ~VariablesHolder(); void addVariable(const QString &name, const QVariant &value, VarDesc::VarType type=VarDesc::User, RenderPass pass=FirstPass); void deleteVariable(const QString &name); void changeVariable(const QString &name, const QVariant &value);