From d07c44d6bb024df4552ef2b972d69c72896662fb Mon Sep 17 00:00:00 2001 From: Arin Alex Date: Fri, 24 Jun 2016 23:06:35 +0300 Subject: [PATCH 1/5] ReportSetting has been added ReportSetting has been added --- include/lrglobal.cpp | 16 +++++++++++++++- include/lrglobal.h | 10 ++++++++++ limereport/lrglobal.cpp | 16 +++++++++++++++- limereport/lrglobal.h | 10 ++++++++++ 4 files changed, 50 insertions(+), 2 deletions(-) diff --git a/include/lrglobal.cpp b/include/lrglobal.cpp index 34bd880..47b31f0 100644 --- a/include/lrglobal.cpp +++ b/include/lrglobal.cpp @@ -31,10 +31,24 @@ #include #include "lrglobal.h" -QString LimeReport::extractClassName(QString className) +namespace LimeReport { + +QString extractClassName(QString className) { int startPos=className.lastIndexOf("::"); if(startPos==-1) startPos=0; else startPos+=2; return className.right(className.length()-startPos); } + +bool ReportSettings::suppressAbsentFieldsAndVarsWarnings() const +{ + return m_suppressAbsentFieldsAndVarsWarnings; +} + +void ReportSettings::setSuppressAbsentFieldsAndVarsWarnings(bool suppressAbsentFieldsAndVarsWarnings) +{ + m_suppressAbsentFieldsAndVarsWarnings = suppressAbsentFieldsAndVarsWarnings; +} + +} //namespace LimeReport diff --git a/include/lrglobal.h b/include/lrglobal.h index baf2bd8..4d1a456 100644 --- a/include/lrglobal.h +++ b/include/lrglobal.h @@ -84,6 +84,16 @@ namespace Const{ ReportError(const QString& message):std::runtime_error(message.toStdString()){} }; + class ReportSettings{ + public: + ReportSettings():m_suppressAbsentFieldsAndVarsWarnings(false){} + void setDefaultValues(){m_suppressAbsentFieldsAndVarsWarnings = false;} + bool suppressAbsentFieldsAndVarsWarnings() const; + void setSuppressAbsentFieldsAndVarsWarnings(bool suppressAbsentFieldsAndVarsWarnings); + private: + bool m_suppressAbsentFieldsAndVarsWarnings; + }; + } // namespace LimeReport diff --git a/limereport/lrglobal.cpp b/limereport/lrglobal.cpp index 34bd880..47b31f0 100644 --- a/limereport/lrglobal.cpp +++ b/limereport/lrglobal.cpp @@ -31,10 +31,24 @@ #include #include "lrglobal.h" -QString LimeReport::extractClassName(QString className) +namespace LimeReport { + +QString extractClassName(QString className) { int startPos=className.lastIndexOf("::"); if(startPos==-1) startPos=0; else startPos+=2; return className.right(className.length()-startPos); } + +bool ReportSettings::suppressAbsentFieldsAndVarsWarnings() const +{ + return m_suppressAbsentFieldsAndVarsWarnings; +} + +void ReportSettings::setSuppressAbsentFieldsAndVarsWarnings(bool suppressAbsentFieldsAndVarsWarnings) +{ + m_suppressAbsentFieldsAndVarsWarnings = suppressAbsentFieldsAndVarsWarnings; +} + +} //namespace LimeReport diff --git a/limereport/lrglobal.h b/limereport/lrglobal.h index baf2bd8..4d1a456 100644 --- a/limereport/lrglobal.h +++ b/limereport/lrglobal.h @@ -84,6 +84,16 @@ namespace Const{ ReportError(const QString& message):std::runtime_error(message.toStdString()){} }; + class ReportSettings{ + public: + ReportSettings():m_suppressAbsentFieldsAndVarsWarnings(false){} + void setDefaultValues(){m_suppressAbsentFieldsAndVarsWarnings = false;} + bool suppressAbsentFieldsAndVarsWarnings() const; + void setSuppressAbsentFieldsAndVarsWarnings(bool suppressAbsentFieldsAndVarsWarnings); + private: + bool m_suppressAbsentFieldsAndVarsWarnings; + }; + } // namespace LimeReport From a8b193de0517591da9dc1a1379e7c92ac213e7e5 Mon Sep 17 00:00:00 2001 From: Arin Alex Date: Fri, 24 Jun 2016 23:12:33 +0300 Subject: [PATCH 2/5] Errors messages have been modified --- limereport/lrdatasourcemanager.cpp | 7 +++++-- limereport/lrdatasourcemanager.h | 2 +- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/limereport/lrdatasourcemanager.cpp b/limereport/lrdatasourcemanager.cpp index 1e7d5b9..d140a16 100644 --- a/limereport/lrdatasourcemanager.cpp +++ b/limereport/lrdatasourcemanager.cpp @@ -323,13 +323,16 @@ QSharedPointerDataSourceManager::previewSQL(const QString &c query.exec(); model->setQuery(query); m_lastError = model->lastError().text(); + putError(m_lastError); if (model->query().isActive()) return QSharedPointer(model); else return QSharedPointer(0); } - if (!db.isOpen()) + if (!db.isOpen()){ m_lastError = tr("Connection \"%1\" is not open").arg(connectionName); + putError(m_lastError); + } return QSharedPointer(0); } @@ -657,7 +660,7 @@ void DataSourceManager::putProxyDesc(ProxyDesc *proxyDesc) bool DataSourceManager::connectConnection(ConnectionDesc *connectionDesc) { bool connected = false; - clearErrorsList(); + clearErrors(); QString lastError =""; foreach(QString datasourceName, dataSourceNames()){ diff --git a/limereport/lrdatasourcemanager.h b/limereport/lrdatasourcemanager.h index 494ec20..aac8778 100644 --- a/limereport/lrdatasourcemanager.h +++ b/limereport/lrdatasourcemanager.h @@ -178,7 +178,7 @@ public: QString lastError() const { return m_lastError;} void putError(QString error){ if (!m_errorsList.contains(error)) m_errorsList.append(error);} - void clearErrorsList(){ m_errorsList.clear();} + void clearErrors(){ m_errorsList.clear(); m_lastError = "";} QStringList errorsList(){ return m_errorsList;} bool designTime() const; void setDesignTime(bool designTime); From 779eefcab59f36c34d9c2d916f92d9e481bd8a87 Mon Sep 17 00:00:00 2001 From: Arin Alex Date: Fri, 24 Jun 2016 23:10:47 +0300 Subject: [PATCH 3/5] Setting dialog has been modified to edit report settings Setting dialog has been modified to edit report settings --- limereport/lrreportdesignwidget.cpp | 2 + limereport/lrsettingdialog.cpp | 9 ++ limereport/lrsettingdialog.h | 2 + limereport/lrsettingdialog.ui | 163 ++++++++++++++++------------ 4 files changed, 107 insertions(+), 69 deletions(-) diff --git a/limereport/lrreportdesignwidget.cpp b/limereport/lrreportdesignwidget.cpp index bdaab42..1b590c3 100644 --- a/limereport/lrreportdesignwidget.cpp +++ b/limereport/lrreportdesignwidget.cpp @@ -394,11 +394,13 @@ void ReportDesignWidget::editSetting() setting.setVerticalGridStep(m_verticalGridStep); setting.setHorizontalGridStep(m_horizontalGridStep); setting.setDefaultFont(m_defaultFont); + setting.setSuppressAbsentFieldsAndVarsWarnings(m_report->suppressFieldAndVarError()); if (setting.exec()){ m_horizontalGridStep = setting.horizontalGridStep(); m_verticalGridStep = setting.verticalGridStep(); m_defaultFont = setting.defaultFont(); + m_report->setSuppressFieldAndVarError(setting.suppressAbsentFieldsAndVarsWarnings()); applySettings(); } } diff --git a/limereport/lrsettingdialog.cpp b/limereport/lrsettingdialog.cpp index 15a86c5..0b929be 100644 --- a/limereport/lrsettingdialog.cpp +++ b/limereport/lrsettingdialog.cpp @@ -32,6 +32,15 @@ QFont SettingDialog::defaultFont() return result; } +bool SettingDialog::suppressAbsentFieldsAndVarsWarnings() +{ + return ui->cbSuppressWarnings->isChecked(); +} + +void SettingDialog::setSuppressAbsentFieldsAndVarsWarnings(bool value){ + ui->cbSuppressWarnings->setChecked(value); +} + void SettingDialog::setHorizontalGridStep(int value) { ui->horizontalGridStep->setValue(value); diff --git a/limereport/lrsettingdialog.h b/limereport/lrsettingdialog.h index 5a2cb48..e9a740d 100644 --- a/limereport/lrsettingdialog.h +++ b/limereport/lrsettingdialog.h @@ -19,6 +19,8 @@ public: int verticalGridStep(); int horizontalGridStep(); QFont defaultFont(); + bool suppressAbsentFieldsAndVarsWarnings(); + void setSuppressAbsentFieldsAndVarsWarnings(bool value); void setHorizontalGridStep(int value); void setVerticalGridStep(int value); void setDefaultFont(const QFont& value); diff --git a/limereport/lrsettingdialog.ui b/limereport/lrsettingdialog.ui index 6fd8520..d3a143a 100644 --- a/limereport/lrsettingdialog.ui +++ b/limereport/lrsettingdialog.ui @@ -7,97 +7,122 @@ 0 0 351 - 185 + 318 Designer setting - + - - - - - Default font - - - - - - - - - - 10 - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - + - Grid + Designer Setting - + - - - + + + - Vertical grid step + Default font - - + + + + + 10 - - - - Horizontal grid step + + + + Qt::Horizontal - - - - - - 10 + + + 40 + 20 + - + - - - Qt::Horizontal + + + Grid - - - 73 - 20 - + + + + + + + Vertical grid step + + + + + + + 10 + + + + + + + Horizontal grid step + + + + + + + 10 + + + + + + + + + Qt::Horizontal + + + + 73 + 20 + + + + + + + + + + + + + + Report Setting + + + + + + Suppress absent fields and variables warning - + @@ -153,8 +178,8 @@ accept() - 248 - 254 + 221 + 307 157 @@ -169,8 +194,8 @@ reject() - 316 - 260 + 221 + 307 286 From ac98da1394aec610835d05b8f81e3213b9ae6324 Mon Sep 17 00:00:00 2001 From: Arin Alex Date: Fri, 24 Jun 2016 23:15:59 +0300 Subject: [PATCH 4/5] ReportSettings have been added to report items --- limereport/lrbasedesignintf.cpp | 17 ++++++++++++++++- limereport/lrbasedesignintf.h | 5 ++++- limereport/lrpagedesignintf.cpp | 14 +++++++++++++- limereport/lrpagedesignintf.h | 4 ++++ limereport/lrreportengine.cpp | 16 +++++++++++++++- limereport/lrreportengine_p.h | 5 +++++ 6 files changed, 57 insertions(+), 4 deletions(-) diff --git a/limereport/lrbasedesignintf.cpp b/limereport/lrbasedesignintf.cpp index 5fe5db7..1a9f47b 100644 --- a/limereport/lrbasedesignintf.cpp +++ b/limereport/lrbasedesignintf.cpp @@ -75,7 +75,8 @@ BaseDesignIntf::BaseDesignIntf(const QString &storageTypeName, QObject *owner, Q m_margin(4), m_itemAlign(DesignedItemAlign), m_changingItemAlign(false), - m_borderColor(Qt::black) + m_borderColor(Qt::black), + m_reportSettings(0) { setGeometry(QRectF(0, 0, m_width, m_height)); if (BaseDesignIntf *item = dynamic_cast(parent)) { @@ -626,6 +627,19 @@ void BaseDesignIntf::turnOnSelectionMarker(bool value) } } +ReportSettings *BaseDesignIntf::reportSettings() const +{ + return m_reportSettings; +} + +void BaseDesignIntf::setReportSettings(ReportSettings *reportSettings) +{ + m_reportSettings = reportSettings; + foreach(BaseDesignIntf* child, childBaseItems()){ + child->setReportSettings(reportSettings); + } +} + QColor BaseDesignIntf::borderColor() const { return m_borderColor; @@ -1187,6 +1201,7 @@ BaseDesignIntf *BaseDesignIntf::cloneItemWOChild(ItemMode mode, QObject *owner, clone->setObjectName(this->objectName()); clone->setItemMode(mode); clone->objectLoadStarted(); + clone->setReportSettings(this->reportSettings()); for (int i = 0; i < clone->metaObject()->propertyCount(); i++) { if (clone->metaObject()->property(i).isWritable()) clone->setProperty(clone->metaObject()->property(i).name(), property(clone->metaObject()->property(i).name())); diff --git a/limereport/lrbasedesignintf.h b/limereport/lrbasedesignintf.h index a3d21c6..440a53e 100644 --- a/limereport/lrbasedesignintf.h +++ b/limereport/lrbasedesignintf.h @@ -245,7 +245,9 @@ public: QColor borderColor() const; void setBorderColor(const QColor &borderColor); void setItemVisible(const bool& value); - virtual bool canContainChildren(){ return false;} + virtual bool canContainChildren(){ return false;} + ReportSettings* reportSettings() const; + void setReportSettings(ReportSettings *reportSettings); protected: //ICollectionContainer @@ -347,6 +349,7 @@ private: ItemAlign m_itemAlign; bool m_changingItemAlign; QColor m_borderColor; + ReportSettings* m_reportSettings; signals: void geometryChanged(QObject* object, QRectF newGeometry, QRectF oldGeometry); void posChanged(QObject* object, QPointF newPos, QPointF oldPos); diff --git a/limereport/lrpagedesignintf.cpp b/limereport/lrpagedesignintf.cpp index dfda279..bb3f2b0 100644 --- a/limereport/lrpagedesignintf.cpp +++ b/limereport/lrpagedesignintf.cpp @@ -92,7 +92,8 @@ PageDesignIntf::PageDesignIntf(QObject *parent): m_multiSelectStarted(false), m_movedItem(0), m_joinItem(0), - m_magneticMovement(false) + m_magneticMovement(false), + m_reportSettings(0) { m_reportEditor = dynamic_cast(parent); updatePageRect(); @@ -1044,6 +1045,17 @@ void PageDesignIntf::changeSelectedGroupProperty(const QString &name, const QVar } } +ReportSettings *PageDesignIntf::getReportSettings() const +{ + return m_reportSettings; +} + +void PageDesignIntf::setReportSettings(ReportSettings *reportSettings) +{ + m_reportSettings = reportSettings; + m_pageItem->setReportSettings(m_reportSettings); +} + bool PageDesignIntf::magneticMovement() const { return m_magneticMovement; diff --git a/limereport/lrpagedesignintf.h b/limereport/lrpagedesignintf.h index 5dd36d4..40572d5 100644 --- a/limereport/lrpagedesignintf.h +++ b/limereport/lrpagedesignintf.h @@ -178,6 +178,9 @@ namespace LimeReport { bool magneticMovement() const; void setMagneticMovement(bool magneticMovement); + ReportSettings *getReportSettings() const; + void setReportSettings(ReportSettings *reportSettings); + protected: virtual void keyPressEvent(QKeyEvent *event); @@ -309,6 +312,7 @@ namespace LimeReport { BaseDesignIntf* m_joinItem; JoinType m_joinType; bool m_magneticMovement; + ReportSettings* m_reportSettings; }; class AbstractPageCommand : public CommandIf{ diff --git a/limereport/lrreportengine.cpp b/limereport/lrreportengine.cpp index 7a63217..06fe5ab 100644 --- a/limereport/lrreportengine.cpp +++ b/limereport/lrreportengine.cpp @@ -93,6 +93,7 @@ PageDesignIntf *ReportEnginePrivate::createPage(const QString &pageName) PageDesignIntf* page =new PageDesignIntf(); page->setObjectName(pageName); page->setReportEditor(this); + page->setReportSettings(&m_reportSettings); return page; } @@ -117,6 +118,7 @@ void ReportEnginePrivate::collectionLoadFinished(const QString &) { foreach (PageDesignIntf* page, m_pages) { page->setReportEditor(this); + page->setReportSettings(&m_reportSettings); page->setSceneRect(-Const::SCENE_MARGIN,-Const::SCENE_MARGIN, page->pageItem()->width()+Const::SCENE_MARGIN*2, page->pageItem()->height()+Const::SCENE_MARGIN*2); @@ -152,6 +154,7 @@ void ReportEnginePrivate::clearReport() m_pages.clear(); m_datasources->clear(DataSourceManager::Owned); m_fileName=""; + m_reportSettings.setDefaultValues(); emit cleared(); } @@ -559,6 +562,16 @@ QString ReportEnginePrivate::renderToString() }else return QString(); } +bool ReportEnginePrivate::suppressFieldAndVarError() const +{ + return m_reportSettings.suppressAbsentFieldsAndVarsWarnings(); +} + +void ReportEnginePrivate::setSuppressFieldAndVarError(bool suppressFieldAndVarError) +{ + m_reportSettings.setSuppressAbsentFieldsAndVarsWarnings(suppressFieldAndVarError); +} + QString ReportEnginePrivate::previewWindowTitle() const { return m_previewWindowTitle; @@ -582,7 +595,7 @@ void ReportEnginePrivate::setPreviewWindowIcon(const QIcon &previewWindowIcon) ReportPages ReportEnginePrivate::renderToPages() { m_reportRender = ReportRender::Ptr(new ReportRender); - dataManager()->clearErrorsList(); + dataManager()->clearErrors(); dataManager()->connectAllDatabases(); dataManager()->setDesignTime(false); connect(m_reportRender.data(),SIGNAL(pageRendered(int)), @@ -590,6 +603,7 @@ ReportPages ReportEnginePrivate::renderToPages() if (m_pages.count()){ emit renderStarted(); m_reportRender->setDatasources(dataManager()); + m_pages.at(0)->setReportSettings(&m_reportSettings); ReportPages result = m_reportRender->renderPageToPages(m_pages.at(0)); emit renderFinished(); return result; diff --git a/limereport/lrreportengine_p.h b/limereport/lrreportengine_p.h index da9ce08..e489cc9 100644 --- a/limereport/lrreportengine_p.h +++ b/limereport/lrreportengine_p.h @@ -56,6 +56,7 @@ class ReportEnginePrivate : public QObject, public ICollectionContainer Q_DECLARE_PUBLIC(ReportEngine) Q_PROPERTY(ACollectionProperty pages READ fakeCollectionReader()) Q_PROPERTY(QObject* datasourcesManager READ dataManager()) + Q_PROPERTY(bool suppressFieldAndVarError READ suppressFieldAndVarError WRITE setSuppressFieldAndVarError) friend class PreviewReportWidget; public: static void printReport(ItemsReaderIntf::Ptr reader, QPrinter &printer); @@ -112,6 +113,9 @@ public: QString previewWindowTitle() const; void setPreviewWindowTitle(const QString &previewWindowTitle); + bool suppressFieldAndVarError() const; + void setSuppressFieldAndVarError(bool suppressFieldAndVarError); + signals: void pagesLoadFinished(); void datasourceCollectionLoadFinished(const QString& collectionName); @@ -158,6 +162,7 @@ private: QIcon m_previewWindowIcon; QString m_previewWindowTitle; QPointer m_designerWindow; + ReportSettings m_reportSettings; }; } From 43089b55d64059efc8868c0c4b0fc82e8807fe4d Mon Sep 17 00:00:00 2001 From: Arin Alex Date: Fri, 24 Jun 2016 23:17:13 +0300 Subject: [PATCH 5/5] Fix: #38 Allow to suppress warnings for unknown fields --- limereport/lritemdesignintf.cpp | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/limereport/lritemdesignintf.cpp b/limereport/lritemdesignintf.cpp index 8f48285..1cf1774 100644 --- a/limereport/lritemdesignintf.cpp +++ b/limereport/lritemdesignintf.cpp @@ -149,14 +149,12 @@ QString ContentItemDesignIntf::expandDataFields(QString context, ExpandType expa context.replace(rx.cap(0),fieldValue); } else { - QString error; - if (dataManager->lastError().isEmpty()){ - error = QString("Field %1 not found in %2 !!! ").arg(field).arg(this->objectName()); - dataManager->putError(error); - } else { - error = dataManager->lastError(); - } - context.replace(rx.cap(0),error); + QString error = QString("Field %1 not found in %2 !!! ").arg(field).arg(this->objectName()); + dataManager->putError(error); + if (!reportSettings() || !reportSettings()->suppressAbsentFieldsAndVarsWarnings()) + context.replace(rx.cap(0),error); + else + context.replace(rx.cap(0),""); } } } @@ -188,7 +186,13 @@ QString ContentItemDesignIntf::expandUserVariables(QString context, RenderPass p pos=0; } } else { - context.replace(rx.cap(0),tr("Variable %1 not found").arg(variable)); + QString error; + error = tr("Variable %1 not found").arg(variable); + dataManager->putError(error); + if (!reportSettings() || reportSettings()->suppressAbsentFieldsAndVarsWarnings()) + context.replace(rx.cap(0),error); + else + context.replace(rx.cap(0),""); } } }