Prepared pages processing has been added

This commit is contained in:
Arin Alexander 2019-05-29 03:41:18 +03:00
parent 9a02dd891e
commit 6a36f26128
5 changed files with 205 additions and 39 deletions

View File

@ -65,6 +65,17 @@ class PageItemDesignIntf;
typedef QList< QSharedPointer<PageItemDesignIntf> > ReportPages; 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{ class LIMEREPORT_EXPORT ReportEngine : public QObject{
Q_OBJECT Q_OBJECT
public: public:
@ -113,6 +124,9 @@ public:
ScaleType previewScaleType(); ScaleType previewScaleType();
int previewScalePercent(); int previewScalePercent();
void setPreviewScaleType(const ScaleType &previewScaleType, int percent = 0); void setPreviewScaleType(const ScaleType &previewScaleType, int percent = 0);
IPreparedPages* preparedPages();
bool showPreparedPages(PreviewHints hints = PreviewBarsUserSetting);
bool prepareReportPages();
signals: signals:
void renderStarted(); void renderStarted();
void renderFinished(); void renderFinished();

View File

@ -1306,7 +1306,9 @@ QObject *BaseDesignIntf::createElement(const QString& /*collectionName*/, const
try{ try{
if (LimeReport::DesignElementsFactory::instance().objectCreator(elementType)){ if (LimeReport::DesignElementsFactory::instance().objectCreator(elementType)){
obj = LimeReport::DesignElementsFactory::instance().objectCreator(elementType)(this, this); obj = LimeReport::DesignElementsFactory::instance().objectCreator(elementType)(this, this);
connect(obj,SIGNAL(propertyChanged(QString,QVariant,QVariant)),page(),SLOT(slotItemPropertyChanged(QString,QVariant,QVariant))); if (page())
connect(obj, SIGNAL(propertyChanged(QString,QVariant,QVariant)),
page(), SLOT(slotItemPropertyChanged(QString,QVariant,QVariant)));
} }
} catch (ReportError error){ } catch (ReportError error){
qDebug()<<error.what(); qDebug()<<error.what();

View File

@ -58,7 +58,7 @@ namespace LimeReport{
QSettings* ReportEngine::m_settings = 0; QSettings* ReportEngine::m_settings = 0;
ReportEnginePrivate::ReportEnginePrivate(QObject *parent) : ReportEnginePrivate::ReportEnginePrivate(QObject *parent) :
QObject(parent), m_fileName(""), m_settings(0), m_ownedSettings(false), QObject(parent), m_preparedPagesManager(PreparedPages(&m_preparedPages)), m_fileName(""), m_settings(0), m_ownedSettings(false),
m_printer(new QPrinter(QPrinter::HighResolution)), m_printerSelected(false), m_printer(new QPrinter(QPrinter::HighResolution)), m_printerSelected(false),
m_showProgressDialog(true), m_reportName(""), m_activePreview(0), m_showProgressDialog(true), m_reportName(""), m_activePreview(0),
m_previewWindowIcon(":/report/images/logo32"), m_previewWindowTitle(tr("Preview")), m_previewWindowIcon(":/report/images/logo32"), m_previewWindowTitle(tr("Preview")),
@ -365,13 +365,8 @@ bool ReportEnginePrivate::printToPDF(const QString &fileName)
return false; return false;
} }
void ReportEnginePrivate::previewReport(PreviewHints hints) bool ReportEnginePrivate::showPreviewWindow(ReportPages pages, PreviewHints hints)
{ {
// QTime start = QTime::currentTime();
try{
dataManager()->setDesignTime(false);
ReportPages pages = renderToPages();
dataManager()->setDesignTime(true);
if (pages.count()>0){ if (pages.count()>0){
PreviewReportWindow* w = new PreviewReportWindow(this,0,settings()); PreviewReportWindow* w = new PreviewReportWindow(this,0,settings());
w->setWindowFlags(Qt::Dialog|Qt::WindowMaximizeButtonHint|Qt::WindowCloseButtonHint| Qt::WindowMinMaxButtonsHint); w->setWindowFlags(Qt::Dialog|Qt::WindowMaximizeButtonHint|Qt::WindowCloseButtonHint| Qt::WindowMinMaxButtonsHint);
@ -406,7 +401,19 @@ void ReportEnginePrivate::previewReport(PreviewHints hints)
connect(w,SIGNAL(destroyed(QObject*)), this, SLOT(slotPreviewWindowDestroyed(QObject*))); connect(w,SIGNAL(destroyed(QObject*)), this, SLOT(slotPreviewWindowDestroyed(QObject*)));
w->exec(); w->exec();
return true;
} }
return false;
}
void ReportEnginePrivate::previewReport(PreviewHints hints)
{
// QTime start = QTime::currentTime();
try{
dataManager()->setDesignTime(false);
ReportPages pages = renderToPages();
dataManager()->setDesignTime(true);
showPreviewWindow(pages, hints);
} catch (ReportError &exception){ } catch (ReportError &exception){
saveError(exception.what()); saveError(exception.what());
showError(exception.what()); showError(exception.what());
@ -749,6 +756,25 @@ void ReportEnginePrivate::setPreviewScaleType(const ScaleType &scaleType, int pe
m_previewScalePercent = percent; m_previewScalePercent = percent;
} }
bool ReportEnginePrivate::showPreparedPages(PreviewHints hints)
{
return showPreviewWindow(m_preparedPages, hints);
}
bool ReportEnginePrivate::prepareReportPages()
{
try{
dataManager()->setDesignTime(false);
m_preparedPages = renderToPages();
dataManager()->setDesignTime(true);
} catch (ReportError &exception){
saveError(exception.what());
showError(exception.what());
return false;
}
return !m_preparedPages.isEmpty();
}
Qt::LayoutDirection ReportEnginePrivate::previewLayoutDirection() Qt::LayoutDirection ReportEnginePrivate::previewLayoutDirection()
{ {
return m_previewLayoutDirection; return m_previewLayoutDirection;
@ -1061,6 +1087,24 @@ void ReportEngine::setPreviewScaleType(const ScaleType &previewScaleType, int pe
d->setPreviewScaleType(previewScaleType, percent); d->setPreviewScaleType(previewScaleType, percent);
} }
IPreparedPages *ReportEngine::preparedPages()
{
Q_D(ReportEngine);
return d->preparedPages();
}
bool ReportEngine::showPreparedPages(PreviewHints hints)
{
Q_D(ReportEngine);
return d->showPreparedPages(hints);
}
bool ReportEngine::prepareReportPages()
{
Q_D(ReportEngine);
return d->prepareReportPages();
}
void ReportEngine::setShowProgressDialog(bool value) void ReportEngine::setShowProgressDialog(bool value)
{ {
@ -1174,6 +1218,78 @@ ReportEngine::ReportEngine(ReportEnginePrivate &dd, QObject *parent)
connect(d, SIGNAL(renderFinished()), this, SIGNAL(renderFinished())); 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

@ -65,6 +65,17 @@ class PageItemDesignIntf;
typedef QList< QSharedPointer<PageItemDesignIntf> > ReportPages; 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{ class LIMEREPORT_EXPORT ReportEngine : public QObject{
Q_OBJECT Q_OBJECT
public: public:
@ -113,6 +124,9 @@ public:
ScaleType previewScaleType(); ScaleType previewScaleType();
int previewScalePercent(); int previewScalePercent();
void setPreviewScaleType(const ScaleType &previewScaleType, int percent = 0); void setPreviewScaleType(const ScaleType &previewScaleType, int percent = 0);
IPreparedPages* preparedPages();
bool showPreparedPages(PreviewHints hints = PreviewBarsUserSetting);
bool prepareReportPages();
signals: signals:
void renderStarted(); void renderStarted();
void renderFinished(); void renderFinished();

View File

@ -50,7 +50,22 @@ class PageDesignIntf;
class PrintRange; class PrintRange;
class ReportDesignWindow; class ReportDesignWindow;
//TODO: Add on render callback 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 class ReportEnginePrivate : public QObject, public ICollectionContainer
{ {
@ -141,7 +156,9 @@ public:
ScaleType previewScaleType(); ScaleType previewScaleType();
int previewScalePercent(); int previewScalePercent();
void setPreviewScaleType(const ScaleType &previewScaleType, int percent = 0); void setPreviewScaleType(const ScaleType &previewScaleType, int percent = 0);
IPreparedPages* preparedPages(){return &m_preparedPagesManager;}
bool showPreparedPages(PreviewHints hints);
bool prepareReportPages();
signals: signals:
void pagesLoadFinished(); void pagesLoadFinished();
void datasourceCollectionLoadFinished(const QString& collectionName); void datasourceCollectionLoadFinished(const QString& collectionName);
@ -157,6 +174,7 @@ public slots:
void cancelRender(); void cancelRender();
protected: protected:
PageDesignIntf* createPage(const QString& pageName=""); PageDesignIntf* createPage(const QString& pageName="");
bool showPreviewWindow(ReportPages pages, PreviewHints hints);
protected slots: protected slots:
void slotDataSourceCollectionLoaded(const QString& collectionName); void slotDataSourceCollectionLoaded(const QString& collectionName);
private slots: private slots:
@ -174,6 +192,8 @@ private:
QString renderToString(); QString renderToString();
private: private:
QList<PageDesignIntf*> m_pages; QList<PageDesignIntf*> m_pages;
ReportPages m_preparedPages;
PreparedPages m_preparedPagesManager;
DataSourceManager* m_datasources; DataSourceManager* m_datasources;
ScriptEngineContext* m_scriptEngineContext; ScriptEngineContext* m_scriptEngineContext;
ReportRender::Ptr m_reportRender; ReportRender::Ptr m_reportRender;