diff --git a/common.pri b/common.pri index 7482787..318e852 100644 --- a/common.pri +++ b/common.pri @@ -120,7 +120,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 e7ff76e..1e24e9b 100644 --- a/include/lrpreviewreportwidget.h +++ b/include/lrpreviewreportwidget.h @@ -5,6 +5,7 @@ #include #include #include "lrglobal.h" +#include "lrpreparedpagesintf.h" namespace LimeReport { @@ -64,6 +65,7 @@ signals: void scalePercentChanged(int percent); void pagesSet(int pageCount); void itemInserted(LimeReport::PageDesignIntf* report, QPointF pos, const QString& ItemType); + 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 3194ec7..07fcf91 100644 --- a/include/lrreportengine.h +++ b/include/lrreportengine.h @@ -40,6 +40,7 @@ #include "lrscriptenginemanagerintf.h" #include "lrpreviewreportwidget.h" #include "lrreportdesignwindowintrerface.h" +#include "lrpreparedpagesintf.h" class QPrinter; class QGraphicsScene; @@ -137,20 +138,10 @@ class PageDesignIntf; class PageItemDesignIntf; class ReportDesignWidget; class PreviewReportWidget; +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 friend class ReportDesignWidget; @@ -223,6 +214,7 @@ signals: void onSave(bool& saved); void onSaveAs(bool& saved); void onLoad(bool& loaded); + void onSavePreview(bool& saved, LimeReport::IPreparedPages* pages); void saveFinished(); void loadFinished(); void printedToPDF(QString fileName); diff --git a/limereport/limereport.pri b/limereport/limereport.pri index bc752e2..e039138 100644 --- a/limereport/limereport.pri +++ b/limereport/limereport.pri @@ -67,7 +67,9 @@ SOURCES += \ $$REPORT_PATH/items/lrchartitem.cpp \ $$REPORT_PATH/items/lrchartitemeditor.cpp \ $$REPORT_PATH/lrreporttranslation.cpp \ - $$REPORT_PATH/exporters/lrpdfexporter.cpp + $$REPORT_PATH/exporters/lrpdfexporter.cpp \ + $$REPORT_PATH/lrpreparedpages.cpp + contains(CONFIG, staticlib){ SOURCES += $$REPORT_PATH/lrfactoryinitializer.cpp @@ -149,7 +151,10 @@ HEADERS += \ $$REPORT_PATH/lrreportdesignwindowintrerface.h \ $$REPORT_PATH/lrexporterintf.h \ $$REPORT_PATH/lrexportersfactory.h \ - $$REPORT_PATH/exporters/lrpdfexporter.h + $$REPORT_PATH/exporters/lrpdfexporter.h \ + $$REPORT_PATH/lrpreparedpages.h \ + $$REPORT_PATH/lrpreparedpagesintf.h + contains(CONFIG, staticlib){ HEADERS += $$REPORT_PATH/lrfactoryinitializer.h diff --git a/limereport/limereport.pro b/limereport/limereport.pro index 962d5f2..c4963e1 100644 --- a/limereport/limereport.pro +++ b/limereport/limereport.pro @@ -40,7 +40,8 @@ EXTRA_FILES += \ $$PWD/lrscriptenginemanagerintf.h \ $$PWD/lrcallbackdatasourceintf.h \ $$PWD/lrpreviewreportwidget.h \ - $$PWD/lrreportdesignwindowintrerface.h + $$PWD/lrreportdesignwindowintrerface.h \ + $$PWD/lrpreparedpagesintf.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 18b5815..01cc68e 100644 --- a/limereport/lrpreviewreportwidget.cpp +++ b/limereport/lrpreviewreportwidget.cpp @@ -12,6 +12,7 @@ #include "lrreportengine_p.h" #include "lrpreviewreportwidget_p.h" #include "serializators/lrxmlwriter.h" +#include "lrpreparedpages.h" #include "lrexportersfactory.h" @@ -281,13 +282,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 e7ff76e..1e24e9b 100644 --- a/limereport/lrpreviewreportwidget.h +++ b/limereport/lrpreviewreportwidget.h @@ -5,6 +5,7 @@ #include #include #include "lrglobal.h" +#include "lrpreparedpagesintf.h" namespace LimeReport { @@ -64,6 +65,7 @@ signals: void scalePercentChanged(int percent); void pagesSet(int pageCount); void itemInserted(LimeReport::PageDesignIntf* report, QPointF pos, const QString& ItemType); + 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 9900b33..a4666bb 100644 --- a/limereport/lrpreviewreportwindow.cpp +++ b/limereport/lrpreviewreportwindow.cpp @@ -64,9 +64,14 @@ PreviewReportWindow::PreviewReportWindow(ReportEngine *report, QWidget *parent, 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 FontEditorWidgetForPage(m_previewReportWidget->d_ptr->m_previewPage,tr("Font"),this); m_fontEditor->setObjectName("fontTools"); diff --git a/limereport/lrpreviewreportwindow.h b/limereport/lrpreviewreportwindow.h index d7c4652..4935201 100644 --- a/limereport/lrpreviewreportwindow.h +++ b/limereport/lrpreviewreportwindow.h @@ -39,6 +39,7 @@ #include #include "serializators/lrxmlreader.h" +#include "lrpreparedpagesintf.h" namespace LimeReport { @@ -117,6 +118,8 @@ private slots: void on_actionShow_Toolbar_triggered(); void slotCurrentPageChanged(int page); void slotItemInserted(LimeReport::PageDesignIntf* report, QPointF pos, const QString& ItemType); +signals: + void onSave(bool& saved, LimeReport::IPreparedPages* pages); private: ItemsReaderIntf* reader(); void initPercentCombobox(); diff --git a/limereport/lrreportengine.cpp b/limereport/lrreportengine.cpp index 23ab2d6..6442f68 100644 --- a/limereport/lrreportengine.cpp +++ b/limereport/lrreportengine.cpp @@ -66,6 +66,7 @@ # define EASY_BLOCK(...) # define EASY_END_BLOCK #endif +#include "lrpreparedpages.h" #ifdef HAVE_STATIC_BUILD #include "lrfactoryinitializer.h" @@ -76,7 +77,7 @@ 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")), @@ -146,6 +147,7 @@ ReportEnginePrivate::~ReportEnginePrivate() m_translations.clear(); if (m_ownedSettings&&m_settings) delete m_settings; + delete m_preparedPagesManager; } QObject* ReportEnginePrivate::createElement(const QString &, const QString &) @@ -534,6 +536,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; } @@ -969,6 +973,10 @@ PageItemDesignIntf* ReportEnginePrivate::getPageByName(const QString& pageName) return 0; } +IPreparedPages *ReportEnginePrivate::preparedPages(){ + return m_preparedPagesManager; +} + bool ReportEnginePrivate::showPreparedPages(PreviewHints hints) { return showPreviewWindow(m_preparedPages, hints); @@ -1383,7 +1391,8 @@ ReportEngine::ReportEngine(QObject *parent) connect(d, SIGNAL(externalPaint(const QString&, QPainter*, const QStyleOptionGraphicsItem*)), this, SIGNAL(externalPaint(const QString&, QPainter*, const QStyleOptionGraphicsItem*))); - + connect(d, SIGNAL(onSavePreview(bool&, LimeReport::IPreparedPages*)), + this, SIGNAL(onSavePreview(bool&, LimeReport::IPreparedPages*))); } ReportEngine::~ReportEngine() @@ -1788,80 +1797,6 @@ bool PrintProcessor::printPage(PageItemDesignIntf::Ptr page) return true; } -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; -} - void PrintProcessor::initPrinter(PageItemDesignIntf* page) { if (page->oldPrintMode()){ diff --git a/limereport/lrreportengine.h b/limereport/lrreportengine.h index 3194ec7..07fcf91 100644 --- a/limereport/lrreportengine.h +++ b/limereport/lrreportengine.h @@ -40,6 +40,7 @@ #include "lrscriptenginemanagerintf.h" #include "lrpreviewreportwidget.h" #include "lrreportdesignwindowintrerface.h" +#include "lrpreparedpagesintf.h" class QPrinter; class QGraphicsScene; @@ -137,20 +138,10 @@ class PageDesignIntf; class PageItemDesignIntf; class ReportDesignWidget; class PreviewReportWidget; +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 friend class ReportDesignWidget; @@ -223,6 +214,7 @@ signals: void onSave(bool& saved); void onSaveAs(bool& saved); void onLoad(bool& loaded); + void onSavePreview(bool& saved, LimeReport::IPreparedPages* pages); void saveFinished(); void loadFinished(); void printedToPDF(QString fileName); diff --git a/limereport/lrreportengine_p.h b/limereport/lrreportengine_p.h index dbd0eb4..47cf6c3 100644 --- a/limereport/lrreportengine_p.h +++ b/limereport/lrreportengine_p.h @@ -112,24 +112,6 @@ public: virtual void setCurrentDesignerLanguage(QLocale::Language language) = 0; }; -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 PrintProcessor{ public: explicit PrintProcessor(QPrinter* printer); @@ -262,7 +244,7 @@ public: void setPreviewScaleType(const ScaleType &previewScaleType, int percent = 0); void addWatermark(const WatermarkSetting& watermarkSetting); void clearWatermarks(); - IPreparedPages* preparedPages(){return &m_preparedPagesManager;} + IPreparedPages* preparedPages(); bool showPreparedPages(PreviewHints hints); bool prepareReportPages(); signals: @@ -274,6 +256,7 @@ signals: void renderPageFinished(int renderedPageCount); void onSave(bool& saved); void onSaveAs(bool& saved); + void onSavePreview(bool& saved, LimeReport::IPreparedPages* pages); void onLoad(bool& loaded); void saveFinished(); void loadFinished(); @@ -320,7 +303,7 @@ private: QList m_pages; QList m_renderingPages; ReportPages m_preparedPages; - PreparedPages m_preparedPagesManager; + PreparedPages* m_preparedPagesManager; DataSourceManager* m_datasources; ScriptEngineContext* m_scriptEngineContext; ReportRender::Ptr m_reportRender;