Prepared pages processing has been refactored

This commit is contained in:
Arin Alexander 2019-05-29 16:32:58 +03:00
parent fc04af2c89
commit 536a409393
15 changed files with 186 additions and 128 deletions

View File

@ -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}\"

View File

@ -4,6 +4,7 @@
#include <QWidget>
#include <QTimer>
#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);

View File

@ -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<PageItemDesignIntf> > 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();

View File

@ -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){

View File

@ -42,6 +42,7 @@ EXTRA_FILES += \
$$PWD/lrreportengine.h \
$$PWD/lrscriptenginemanagerintf.h \
$$PWD/lrcallbackdatasourceintf.h \
$$PWD/lrpreparedpagesintf.h \
$$PWD/lrpreviewreportwidget.h
include(limereport.pri)

View File

@ -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;
}
}

View File

@ -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

View File

@ -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

View File

@ -11,6 +11,7 @@
#include "lrreportengine_p.h"
#include "lrpreviewreportwidget_p.h"
#include "serializators/lrxmlwriter.h"
#include "lrpreparedpages.h"
namespace LimeReport {
@ -207,6 +208,10 @@ void PreviewReportWidget::pageNavigatorChanged(int value)
void PreviewReportWidget::saveToFile()
{
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());
@ -216,6 +221,7 @@ void PreviewReportWidget::saveToFile()
writer->saveToFile(fileName);
}
}
}
void PreviewReportWidget::setScalePercent(int percent)
{

View File

@ -4,6 +4,7 @@
#include <QWidget>
#include <QTimer>
#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);

View File

@ -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");

View File

@ -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();

View File

@ -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,7 +60,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")),
@ -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);
@ -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;
}
}

View File

@ -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<PageItemDesignIntf> > 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();

View File

@ -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<PageDesignIntf*> m_pages;
ReportPages m_preparedPages;
PreparedPages m_preparedPagesManager;
PreparedPages* m_preparedPagesManager;
DataSourceManager* m_datasources;
ScriptEngineContext* m_scriptEngineContext;
ReportRender::Ptr m_reportRender;