From 536a409393caa26c98d4088247088e183a9b3b04 Mon Sep 17 00:00:00 2001 From: Arin Alexander Date: Wed, 29 May 2019 16:32:58 +0300 Subject: [PATCH] Prepared pages processing has been refactored --- common.pri | 2 +- include/lrpreviewreportwidget.h | 2 + include/lrreportengine.h | 14 +---- limereport/limereport.pri | 3 + limereport/limereport.pro | 1 + limereport/lrpreparedpages.cpp | 85 ++++++++++++++++++++++++++ limereport/lrpreparedpages.h | 29 +++++++++ limereport/lrpreparedpagesintf.h | 17 ++++++ limereport/lrpreviewreportwidget.cpp | 18 ++++-- limereport/lrpreviewreportwidget.h | 2 + limereport/lrpreviewreportwindow.cpp | 11 +++- limereport/lrpreviewreportwindow.h | 3 + limereport/lrreportengine.cpp | 91 +++++----------------------- limereport/lrreportengine.h | 14 +---- limereport/lrreportengine_p.h | 22 +------ 15 files changed, 186 insertions(+), 128 deletions(-) create mode 100644 limereport/lrpreparedpages.cpp create mode 100644 limereport/lrpreparedpages.h create mode 100644 limereport/lrpreparedpagesintf.h diff --git a/common.pri b/common.pri index a86753b..820d980 100644 --- a/common.pri +++ b/common.pri @@ -77,7 +77,7 @@ RCC_DIR = $${ARCH_DIR}/$${BUILD_TYPE}/rcc LIMEREPORT_VERSION_MAJOR = 1 LIMEREPORT_VERSION_MINOR = 4 -LIMEREPORT_VERSION_RELEASE = 129 +LIMEREPORT_VERSION_RELEASE = 132 LIMEREPORT_VERSION = '\\"$${LIMEREPORT_VERSION_MAJOR}.$${LIMEREPORT_VERSION_MINOR}.$${LIMEREPORT_VERSION_RELEASE}\\"' DEFINES += LIMEREPORT_VERSION_STR=\"$${LIMEREPORT_VERSION}\" diff --git a/include/lrpreviewreportwidget.h b/include/lrpreviewreportwidget.h index d66ac70..74c0be6 100644 --- a/include/lrpreviewreportwidget.h +++ b/include/lrpreviewreportwidget.h @@ -4,6 +4,7 @@ #include #include #include "lrglobal.h" +#include "lrpreparedpagesintf.h" namespace LimeReport { @@ -49,6 +50,7 @@ signals: void pageChanged(int page); void scalePercentChanged(int percent); void pagesSet(int pageCount); + void onSave(bool& saved, LimeReport::IPreparedPages* pages); private slots: void slotSliderMoved(int value); void reportEngineDestroyed(QObject* object); diff --git a/include/lrreportengine.h b/include/lrreportengine.h index d786dde..8296abc 100644 --- a/include/lrreportengine.h +++ b/include/lrreportengine.h @@ -38,6 +38,7 @@ #include "lrdatasourcemanagerintf.h" #include "lrscriptenginemanagerintf.h" #include "lrpreviewreportwidget.h" +#include "lrpreparedpagesintf.h" class QPrinter; @@ -62,20 +63,10 @@ class DataSourceManager; class ReportEnginePrivate; class PageDesignIntf; class PageItemDesignIntf; +class PreparedPages; typedef QList< QSharedPointer > ReportPages; -class LIMEREPORT_EXPORT IPreparedPages{ -public: - virtual ~IPreparedPages(); - virtual bool loadFromFile(const QString& fileName) = 0; - virtual bool loadFromString(const QString data) = 0; - virtual bool loadFromByteArray(QByteArray* data) = 0; - virtual bool saveToFile(const QString& fileName) = 0; - virtual QString saveToString() = 0; - virtual QByteArray saveToByteArray() = 0; -}; - class LIMEREPORT_EXPORT ReportEngine : public QObject{ Q_OBJECT public: @@ -133,6 +124,7 @@ signals: void renderPageFinished(int renderedPageCount); void onLoad(bool& loaded); void onSave(); + void onSavePreview(bool& saved, LimeReport::IPreparedPages* pages); void saveFinished(); public slots: void cancelRender(); diff --git a/limereport/limereport.pri b/limereport/limereport.pri index d20810d..e96070b 100644 --- a/limereport/limereport.pri +++ b/limereport/limereport.pri @@ -90,6 +90,7 @@ SOURCES += \ $$REPORT_PATH/lraboutdialog.cpp \ $$REPORT_PATH/lrsettingdialog.cpp \ $$REPORT_PATH/scriptbrowser/lrscriptbrowser.cpp \ + $$REPORT_PATH/lrpreparedpages.cpp \ $$REPORT_PATH/lritemscontainerdesignitf.cpp contains(CONFIG, staticlib){ @@ -195,6 +196,8 @@ HEADERS += \ $$REPORT_PATH/lrsettingdialog.h \ $$REPORT_PATH/lrpreviewreportwidget_p.h \ $$REPORT_PATH/scriptbrowser/lrscriptbrowser.h \ + $$REPORT_PATH/lrpreparedpages.h \ + $$REPORT_PATH/lrpreparedpagesintf.h \ $$REPORT_PATH/lritemscontainerdesignitf.h contains(CONFIG, staticlib){ diff --git a/limereport/limereport.pro b/limereport/limereport.pro index 5193295..bdfcd42 100644 --- a/limereport/limereport.pro +++ b/limereport/limereport.pro @@ -42,6 +42,7 @@ EXTRA_FILES += \ $$PWD/lrreportengine.h \ $$PWD/lrscriptenginemanagerintf.h \ $$PWD/lrcallbackdatasourceintf.h \ + $$PWD/lrpreparedpagesintf.h \ $$PWD/lrpreviewreportwidget.h include(limereport.pri) diff --git a/limereport/lrpreparedpages.cpp b/limereport/lrpreparedpages.cpp new file mode 100644 index 0000000..2cc7a1b --- /dev/null +++ b/limereport/lrpreparedpages.cpp @@ -0,0 +1,85 @@ +#include "lrpreparedpages.h" + +#include "serializators/lrxmlreader.h" +#include "serializators/lrxmlwriter.h" + +namespace LimeReport { + +bool PreparedPages::loadFromFile(const QString &fileName) +{ + ItemsReaderIntf::Ptr reader = FileXMLReader::create(fileName); + return readPages(reader); +} + +bool PreparedPages::loadFromString(const QString data) +{ + ItemsReaderIntf::Ptr reader = StringXMLreader::create(data); + return readPages(reader); +} + +bool PreparedPages::loadFromByteArray(QByteArray *data) +{ + ItemsReaderIntf::Ptr reader = ByteArrayXMLReader::create(data); + return readPages(reader); +} + +bool PreparedPages::saveToFile(const QString &fileName) +{ + if (!fileName.isEmpty()){ + QScopedPointer< ItemsWriterIntf > writer(new XMLWriter()); + foreach (PageItemDesignIntf::Ptr page, *m_pages){ + writer->putItem(page.data()); + } + return writer->saveToFile(fileName); + } + return false; +} + +QString PreparedPages::saveToString() +{ + QScopedPointer< ItemsWriterIntf > writer(new XMLWriter()); + foreach (PageItemDesignIntf::Ptr page, *m_pages){ + writer->putItem(page.data()); + } + return writer->saveToString(); +} + +QByteArray PreparedPages::saveToByteArray() +{ + QScopedPointer< ItemsWriterIntf > writer(new XMLWriter()); + foreach (PageItemDesignIntf::Ptr page, *m_pages){ + writer->putItem(page.data()); + } + return writer->saveToByteArray(); +} + +void PreparedPages::clear() +{ + m_pages->clear(); +} + +bool PreparedPages::readPages(ItemsReaderIntf::Ptr reader) +{ + if (reader->first()){ + PageItemDesignIntf::Ptr page = PageItemDesignIntf::create(0); + if (!reader->readItem(page.data())) + return false; + else { + m_pages->append(page); + while (reader->next()){ + page = PageItemDesignIntf::create(0); + if (!reader->readItem(page.data())){ + m_pages->clear(); + return false; + } else { + m_pages->append(page); + } + } + } + + return true; + } + return false; +} + +} diff --git a/limereport/lrpreparedpages.h b/limereport/lrpreparedpages.h new file mode 100644 index 0000000..8a03679 --- /dev/null +++ b/limereport/lrpreparedpages.h @@ -0,0 +1,29 @@ +#ifndef LRPREPAREDPAGES_H +#define LRPREPAREDPAGES_H + +#include "lrpagedesignintf.h" +#include "lrpreparedpagesintf.h" + +namespace LimeReport { + +class PreparedPages: public IPreparedPages{ +public: + PreparedPages(ReportPages* pages):m_pages(pages){} + ~PreparedPages(){} +// IPreviewPages interface +private: + bool loadFromFile(const QString &fileName); + bool loadFromString(const QString data); + bool loadFromByteArray(QByteArray *data); + bool saveToFile(const QString &fileName); + QString saveToString(); + QByteArray saveToByteArray(); + void clear(); +private: + bool readPages(ItemsReaderIntf::Ptr reader); + ReportPages* m_pages; +}; + +} // namespace LimeReport + +#endif // LRPREPAREDPAGES_H diff --git a/limereport/lrpreparedpagesintf.h b/limereport/lrpreparedpagesintf.h new file mode 100644 index 0000000..a079a9a --- /dev/null +++ b/limereport/lrpreparedpagesintf.h @@ -0,0 +1,17 @@ +#ifndef LRPREPAREDPAGESINTF_H +#define LRPREPAREDPAGESINTF_H +#include "lrglobal.h" +namespace LimeReport { +class LIMEREPORT_EXPORT IPreparedPages{ +public: + virtual ~IPreparedPages(){}; + virtual bool loadFromFile(const QString& fileName) = 0; + virtual bool loadFromString(const QString data) = 0; + virtual bool loadFromByteArray(QByteArray* data) = 0; + virtual bool saveToFile(const QString& fileName) = 0; + virtual QString saveToString() = 0; + virtual QByteArray saveToByteArray() = 0; + virtual void clear() = 0; +}; +} //namespace LimeReport +#endif // LRPREPAREDPAGESINTF_H diff --git a/limereport/lrpreviewreportwidget.cpp b/limereport/lrpreviewreportwidget.cpp index 4c54ecc..da0202e 100644 --- a/limereport/lrpreviewreportwidget.cpp +++ b/limereport/lrpreviewreportwidget.cpp @@ -11,6 +11,7 @@ #include "lrreportengine_p.h" #include "lrpreviewreportwidget_p.h" #include "serializators/lrxmlwriter.h" +#include "lrpreparedpages.h" namespace LimeReport { @@ -207,13 +208,18 @@ void PreviewReportWidget::pageNavigatorChanged(int value) void PreviewReportWidget::saveToFile() { - QString fileName = QFileDialog::getSaveFileName(this,tr("Report file name")); - if (!fileName.isEmpty()){ - QScopedPointer< ItemsWriterIntf > writer(new XMLWriter()); - foreach (PageItemDesignIntf::Ptr page, d_ptr->m_reportPages){ - writer->putItem(page.data()); + bool saved = false; + PreparedPages pagesManager = PreparedPages(&d_ptr->m_reportPages); + emit onSave(saved, &pagesManager); + if (!saved){ + QString fileName = QFileDialog::getSaveFileName(this,tr("Report file name")); + if (!fileName.isEmpty()){ + QScopedPointer< ItemsWriterIntf > writer(new XMLWriter()); + foreach (PageItemDesignIntf::Ptr page, d_ptr->m_reportPages){ + writer->putItem(page.data()); + } + writer->saveToFile(fileName); } - writer->saveToFile(fileName); } } diff --git a/limereport/lrpreviewreportwidget.h b/limereport/lrpreviewreportwidget.h index d66ac70..74c0be6 100644 --- a/limereport/lrpreviewreportwidget.h +++ b/limereport/lrpreviewreportwidget.h @@ -4,6 +4,7 @@ #include #include #include "lrglobal.h" +#include "lrpreparedpagesintf.h" namespace LimeReport { @@ -49,6 +50,7 @@ signals: void pageChanged(int page); void scalePercentChanged(int percent); void pagesSet(int pageCount); + void onSave(bool& saved, LimeReport::IPreparedPages* pages); private slots: void slotSliderMoved(int value); void reportEngineDestroyed(QObject* object); diff --git a/limereport/lrpreviewreportwindow.cpp b/limereport/lrpreviewreportwindow.cpp index 7fe5f23..f9b0981 100644 --- a/limereport/lrpreviewreportwindow.cpp +++ b/limereport/lrpreviewreportwindow.cpp @@ -60,9 +60,14 @@ PreviewReportWindow::PreviewReportWindow(ReportEnginePrivate *report,QWidget *pa m_previewReportWidget = new PreviewReportWidget(report,this); setCentralWidget(m_previewReportWidget); layout()->setContentsMargins(1,1,1,1); - connect(m_previewReportWidget,SIGNAL(pageChanged(int)), this,SLOT(slotPageChanged(int)) ); - connect(m_previewReportWidget->d_ptr->m_previewPage,SIGNAL(selectionChanged()),this,SLOT(slotSelectionChanged())); - connect(m_pagesNavigator,SIGNAL(valueChanged(int)),this,SLOT(slotPageNavigatorChanged(int))); + connect(m_previewReportWidget, SIGNAL(pageChanged(int)), + this, SLOT(slotPageChanged(int)) ); + connect(m_previewReportWidget->d_ptr->m_previewPage, SIGNAL(selectionChanged()), + this, SLOT(slotSelectionChanged())); + connect(m_pagesNavigator, SIGNAL(valueChanged(int)), + this, SLOT(slotPageNavigatorChanged(int))); + connect(m_previewReportWidget, SIGNAL(onSave(bool&, LimeReport::IPreparedPages*)), + this, SIGNAL(onSave(bool&, LimeReport::IPreparedPages*))); m_fontEditor = new FontEditorWidget(m_previewReportWidget->d_ptr->m_previewPage,tr("Font"),this); m_fontEditor->setObjectName("fontTools"); diff --git a/limereport/lrpreviewreportwindow.h b/limereport/lrpreviewreportwindow.h index 72ae3b7..ce9db57 100644 --- a/limereport/lrpreviewreportwindow.h +++ b/limereport/lrpreviewreportwindow.h @@ -40,6 +40,7 @@ #include "serializators/lrstorageintf.h" #include "serializators/lrxmlreader.h" #include "lrpreviewreportwidget.h" +#include "lrpreparedpagesintf.h" #include "items/editors/lrfonteditorwidget.h" #include "items/editors/lrtextalignmenteditorwidget.h" @@ -106,6 +107,8 @@ private slots: void slotScalePercentChanged(int percent); void on_actionShowMessages_toggled(bool value); void on_actionShow_Toolbar_triggered(); +signals: + void onSave(bool& saved, LimeReport::IPreparedPages* pages); private: ItemsReaderIntf* reader(); void initPercentCombobox(); diff --git a/limereport/lrreportengine.cpp b/limereport/lrreportengine.cpp index 724c902..5288a80 100644 --- a/limereport/lrreportengine.cpp +++ b/limereport/lrreportengine.cpp @@ -50,6 +50,8 @@ #include "lrpreviewreportwindow.h" #include "lrpreviewreportwidget.h" #include "lrpreviewreportwidget_p.h" +#include "lrpreparedpages.h" + #ifdef HAVE_STATIC_BUILD #include "lrfactoryinitializer.h" #endif @@ -58,12 +60,12 @@ namespace LimeReport{ QSettings* ReportEngine::m_settings = 0; ReportEnginePrivate::ReportEnginePrivate(QObject *parent) : - QObject(parent), m_preparedPagesManager(PreparedPages(&m_preparedPages)), m_fileName(""), m_settings(0), m_ownedSettings(false), + QObject(parent), m_preparedPagesManager(new PreparedPages(&m_preparedPages)), m_fileName(""), m_settings(0), m_ownedSettings(false), m_printer(new QPrinter(QPrinter::HighResolution)), m_printerSelected(false), m_showProgressDialog(true), m_reportName(""), m_activePreview(0), m_previewWindowIcon(":/report/images/logo32"), m_previewWindowTitle(tr("Preview")), m_reportRendering(false), m_resultIsEditable(true), m_passPhrase("HjccbzHjlbyfCkjy"), - m_fileWatcher( new QFileSystemWatcher( this ) ), m_previewLayoutDirection(Qt::LayoutDirectionAuto), + m_fileWatcher( new QFileSystemWatcher(this) ), m_previewLayoutDirection(Qt::LayoutDirectionAuto), m_previewScaleType(FitWidth), m_previewScalePercent(0), m_saveToFileVisible(true), m_printToPdfVisible(true), m_printVisible(true) { @@ -93,6 +95,7 @@ ReportEnginePrivate::~ReportEnginePrivate() foreach(PageDesignIntf* page,m_pages) delete page; m_pages.clear(); if (m_ownedSettings&&m_settings) delete m_settings; + delete m_preparedPagesManager; } QObject* ReportEnginePrivate::createElement(const QString &, const QString &) @@ -400,6 +403,8 @@ bool ReportEnginePrivate::showPreviewWindow(ReportPages pages, PreviewHints hint w->setPreviewScaleType(m_previewScaleType, m_previewScalePercent); connect(w,SIGNAL(destroyed(QObject*)), this, SLOT(slotPreviewWindowDestroyed(QObject*))); + connect(w, SIGNAL(onSave(bool&, LimeReport::IPreparedPages*)), + this, SIGNAL(onSavePreview(bool&, LimeReport::IPreparedPages*))); w->exec(); return true; } @@ -756,6 +761,10 @@ void ReportEnginePrivate::setPreviewScaleType(const ScaleType &scaleType, int pe m_previewScalePercent = percent; } +IPreparedPages *ReportEnginePrivate::preparedPages(){ + return m_preparedPagesManager; +} + bool ReportEnginePrivate::showPreparedPages(PreviewHints hints) { return showPreviewWindow(m_preparedPages, hints); @@ -903,7 +912,7 @@ ReportPages ReportEnginePrivate::renderToPages() foreach(PageDesignIntf* page , m_pages){ m_pages.at(0)->setReportSettings(&m_reportSettings); - result.append(m_reportRender->renderPageToPages(page)); + result.append(m_reportRender->renderPageToPages(page)); } m_reportRender->secondRenderPass(result); @@ -933,6 +942,8 @@ ReportEngine::ReportEngine(QObject *parent) connect(d, SIGNAL(onSave()), this, SIGNAL(onSave())); connect(d, SIGNAL(onLoad(bool&)), this, SIGNAL(onLoad(bool&))); connect(d, SIGNAL(saveFinished()), this, SIGNAL(saveFinished())); + connect(d, SIGNAL(onSavePreview(bool&, LimeReport::IPreparedPages*)), + this, SIGNAL(onSavePreview(bool&, LimeReport::IPreparedPages*))); } ReportEngine::~ReportEngine() @@ -1218,78 +1229,4 @@ ReportEngine::ReportEngine(ReportEnginePrivate &dd, QObject *parent) connect(d, SIGNAL(renderFinished()), this, SIGNAL(renderFinished())); } -IPreparedPages::~IPreparedPages(){} - -bool PreparedPages::loadFromFile(const QString &fileName) -{ - ItemsReaderIntf::Ptr reader = FileXMLReader::create(fileName); - return readPages(reader); -} - -bool PreparedPages::loadFromString(const QString data) -{ - ItemsReaderIntf::Ptr reader = StringXMLreader::create(data); - return readPages(reader); -} - -bool PreparedPages::loadFromByteArray(QByteArray *data) -{ - ItemsReaderIntf::Ptr reader = ByteArrayXMLReader::create(data); - return readPages(reader); -} - -bool PreparedPages::saveToFile(const QString &fileName) -{ - if (!fileName.isEmpty()){ - QScopedPointer< ItemsWriterIntf > writer(new XMLWriter()); - foreach (PageItemDesignIntf::Ptr page, *m_pages){ - writer->putItem(page.data()); - } - return writer->saveToFile(fileName); - } - return false; -} - -QString PreparedPages::saveToString() -{ - QScopedPointer< ItemsWriterIntf > writer(new XMLWriter()); - foreach (PageItemDesignIntf::Ptr page, *m_pages){ - writer->putItem(page.data()); - } - return writer->saveToString(); -} - -QByteArray PreparedPages::saveToByteArray() -{ - QScopedPointer< ItemsWriterIntf > writer(new XMLWriter()); - foreach (PageItemDesignIntf::Ptr page, *m_pages){ - writer->putItem(page.data()); - } - return writer->saveToByteArray(); -} - -bool PreparedPages::readPages(ItemsReaderIntf::Ptr reader) -{ - if (reader->first()){ - PageItemDesignIntf::Ptr page = PageItemDesignIntf::create(0); - if (!reader->readItem(page.data())) - return false; - else { - m_pages->append(page); - while (reader->next()){ - page = PageItemDesignIntf::create(0); - if (!reader->readItem(page.data())){ - m_pages->clear(); - return false; - } else { - m_pages->append(page); - } - } - } - - return true; - } - return false; -} - } diff --git a/limereport/lrreportengine.h b/limereport/lrreportengine.h index d786dde..8296abc 100644 --- a/limereport/lrreportengine.h +++ b/limereport/lrreportengine.h @@ -38,6 +38,7 @@ #include "lrdatasourcemanagerintf.h" #include "lrscriptenginemanagerintf.h" #include "lrpreviewreportwidget.h" +#include "lrpreparedpagesintf.h" class QPrinter; @@ -62,20 +63,10 @@ class DataSourceManager; class ReportEnginePrivate; class PageDesignIntf; class PageItemDesignIntf; +class PreparedPages; typedef QList< QSharedPointer > ReportPages; -class LIMEREPORT_EXPORT IPreparedPages{ -public: - virtual ~IPreparedPages(); - virtual bool loadFromFile(const QString& fileName) = 0; - virtual bool loadFromString(const QString data) = 0; - virtual bool loadFromByteArray(QByteArray* data) = 0; - virtual bool saveToFile(const QString& fileName) = 0; - virtual QString saveToString() = 0; - virtual QByteArray saveToByteArray() = 0; -}; - class LIMEREPORT_EXPORT ReportEngine : public QObject{ Q_OBJECT public: @@ -133,6 +124,7 @@ signals: void renderPageFinished(int renderedPageCount); void onLoad(bool& loaded); void onSave(); + void onSavePreview(bool& saved, LimeReport::IPreparedPages* pages); void saveFinished(); public slots: void cancelRender(); diff --git a/limereport/lrreportengine_p.h b/limereport/lrreportengine_p.h index e945ea8..d0d312b 100644 --- a/limereport/lrreportengine_p.h +++ b/limereport/lrreportengine_p.h @@ -50,23 +50,6 @@ class PageDesignIntf; class PrintRange; class ReportDesignWindow; -class PreparedPages: public IPreparedPages{ -public: - PreparedPages(ReportPages* pages):m_pages(pages){} - ~PreparedPages(){} -// IPreviewPages interface -private: - bool loadFromFile(const QString &fileName); - bool loadFromString(const QString data); - bool loadFromByteArray(QByteArray *data); - bool saveToFile(const QString &fileName); - QString saveToString(); - QByteArray saveToByteArray(); -private: - bool readPages(ItemsReaderIntf::Ptr reader); - ReportPages* m_pages; -}; - class ReportEnginePrivate : public QObject, public ICollectionContainer { Q_OBJECT @@ -156,7 +139,7 @@ public: ScaleType previewScaleType(); int previewScalePercent(); void setPreviewScaleType(const ScaleType &previewScaleType, int percent = 0); - IPreparedPages* preparedPages(){return &m_preparedPagesManager;} + IPreparedPages* preparedPages(); bool showPreparedPages(PreviewHints hints); bool prepareReportPages(); signals: @@ -169,6 +152,7 @@ signals: void onLoad(bool& loaded); void onSave(); void saveFinished(); + void onSavePreview(bool& saved, LimeReport::IPreparedPages* pages); public slots: bool slotLoadFromFile(const QString& fileName); void cancelRender(); @@ -193,7 +177,7 @@ private: private: QList m_pages; ReportPages m_preparedPages; - PreparedPages m_preparedPagesManager; + PreparedPages* m_preparedPagesManager; DataSourceManager* m_datasources; ScriptEngineContext* m_scriptEngineContext; ReportRender::Ptr m_reportRender;