0
0
mirror of https://github.com/fralx/LimeReport.git synced 2024-12-25 17:14:40 +03:00

Merge pull request #111 from sg-james/feature/save-load-intercept

Report Engine:
This commit is contained in:
fralx 2018-05-30 09:13:27 +03:00 committed by GitHub
commit 8d8bea869e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 107 additions and 70 deletions

View File

@ -119,13 +119,12 @@ signals:
void renderStarted(); void renderStarted();
void renderFinished(); void renderFinished();
void renderPageFinished(int renderedPageCount); void renderPageFinished(int renderedPageCount);
void onSave(bool& saved);
void onSaveAs(bool& saved);
void onLoad(bool& loaded); void onLoad(bool& loaded);
void onSave();
void saveFinished(); void saveFinished();
void loadFinished();
void loaded();
void printedToPDF(QString fileName); void printedToPDF(QString fileName);
void getAviableLanguages(QList<QLocale::Language>* languages); void getAviableLanguages(QList<QLocale::Language>* languages);
void currentDefaulLanguageChanged(QLocale::Language); void currentDefaulLanguageChanged(QLocale::Language);
QLocale::Language getCurrentDefaultLanguage(); QLocale::Language getCurrentDefaultLanguage();

View File

@ -79,7 +79,7 @@ ReportDesignWidget::ReportDesignWidget(ReportEnginePrivateInterface* report, QMa
connect(dynamic_cast<QObject*>(m_report), SIGNAL(pagesLoadFinished()),this,SLOT(slotPagesLoadFinished())); connect(dynamic_cast<QObject*>(m_report), SIGNAL(pagesLoadFinished()),this,SLOT(slotPagesLoadFinished()));
connect(dynamic_cast<QObject*>(m_report), SIGNAL(cleared()), this, SIGNAL(cleared())); connect(dynamic_cast<QObject*>(m_report), SIGNAL(cleared()), this, SIGNAL(cleared()));
connect(dynamic_cast<QObject*>(m_report), SIGNAL(loaded()), this, SLOT(slotReportLoaded())); connect(dynamic_cast<QObject*>(m_report), SIGNAL(loadFinished()), this, SLOT(slotReportLoaded()));
connect(m_tabWidget, SIGNAL(currentChanged(int)), this, SLOT(slotCurrentTabChanged(int))); connect(m_tabWidget, SIGNAL(currentChanged(int)), this, SLOT(slotCurrentTabChanged(int)));
#ifdef HAVE_UI_LOADER #ifdef HAVE_UI_LOADER
@ -432,14 +432,15 @@ bool ReportDesignWidget::save()
bool result = false; bool result = false;
if (!m_report->reportFileName().isEmpty()){ if (emitSaveReport()) {
result = true; // saved via signal
}
else if (!m_report->reportFileName().isEmpty()){
if (m_report->saveToFile()){ if (m_report->saveToFile()){
m_report->emitSaveFinished(); m_report->emitSaveFinished();
result = true; result = true;
} }
} } else {
else {
m_report->emitSaveReport();
if (m_report->isSaved()) { if (m_report->isSaved()) {
m_report->emitSaveFinished(); m_report->emitSaveFinished();
result = true; result = true;
@ -449,6 +450,7 @@ bool ReportDesignWidget::save()
result = true; result = true;
}; };
} }
#ifdef HAVE_QTDESIGNER_INTEGRATION #ifdef HAVE_QTDESIGNER_INTEGRATION
if (result){ if (result){
m_dialogChanged = false; m_dialogChanged = false;
@ -494,6 +496,16 @@ bool ReportDesignWidget::isNeedToSave()
return false; return false;
} }
bool ReportDesignWidget::emitSaveReport()
{
return m_report->emitSaveReport();
}
bool ReportDesignWidget::emitSaveReportAs()
{
return m_report->emitSaveReportAs();
}
bool ReportDesignWidget::emitLoadReport() bool ReportDesignWidget::emitLoadReport()
{ {
return m_report->emitLoadReport(); return m_report->emitLoadReport();

View File

@ -108,6 +108,8 @@ public:
ReportEnginePrivateInterface* report(){return m_report;} ReportEnginePrivateInterface* report(){return m_report;}
QString reportFileName(); QString reportFileName();
bool isNeedToSave(); bool isNeedToSave();
bool emitSaveReport();
bool emitSaveReportAs();
bool emitLoadReport(); bool emitLoadReport();
void saveState(QSettings *settings); void saveState(QSettings *settings);
void loadState(QSettings *settings); void loadState(QSettings *settings);

View File

@ -1044,13 +1044,19 @@ void ReportDesignWindow::slotCommandHistoryChanged()
void ReportDesignWindow::slotSaveReport() void ReportDesignWindow::slotSaveReport()
{ {
if (m_reportDesignWidget->emitSaveReport()) return; // report save as'd via signal
m_reportDesignWidget->save(); m_reportDesignWidget->save();
m_lblReportName->setText(m_reportDesignWidget->reportFileName());
if (!m_reportDesignWidget->reportFileName().isEmpty()) addRecentFile(m_reportDesignWidget->reportFileName()); QString filename = m_reportDesignWidget->reportFileName();
m_lblReportName->setText(filename);
if(!filename.isEmpty()) addRecentFile(filename);
} }
void ReportDesignWindow::slotSaveReportAs() void ReportDesignWindow::slotSaveReportAs()
{ {
if (m_reportDesignWidget->emitSaveReportAs()) return; // report save as'd via signal
QString fileName = QFileDialog::getSaveFileName(this,tr("Report file name"),"","Report files(*.lrxml);; All files(*)"); QString fileName = QFileDialog::getSaveFileName(this,tr("Report file name"),"","Report files(*.lrxml);; All files(*)");
if (!fileName.isEmpty()){ if (!fileName.isEmpty()){
m_reportDesignWidget->saveToFile(fileName); m_reportDesignWidget->saveToFile(fileName);
@ -1061,8 +1067,10 @@ void ReportDesignWindow::slotSaveReportAs()
void ReportDesignWindow::slotLoadReport() void ReportDesignWindow::slotLoadReport()
{ {
if (checkNeedToSave()){ if (!checkNeedToSave()) return; // don't need to save
if (!m_reportDesignWidget->emitLoadReport()){
if (m_reportDesignWidget->emitLoadReport()) return; // report loaded via signal
QString fileName = QFileDialog::getOpenFileName( QString fileName = QFileDialog::getOpenFileName(
this,tr("Report file name"), this,tr("Report file name"),
m_reportDesignWidget->report()->currentReportsDir(), m_reportDesignWidget->report()->currentReportsDir(),
@ -1101,10 +1109,8 @@ void ReportDesignWindow::slotLoadReport()
addRecentFile(fileName); addRecentFile(fileName);
m_editorTabType = ReportDesignWidget::Page; m_editorTabType = ReportDesignWidget::Page;
} }
}
} }
}
void ReportDesignWindow::slotZoomIn() void ReportDesignWindow::slotZoomIn()
{ {

View File

@ -585,9 +585,18 @@ PageDesignIntf* ReportEnginePrivate::createPreviewScene(QObject* parent){
return result; return result;
} }
void ReportEnginePrivate::emitSaveReport() bool ReportEnginePrivate::emitSaveReport()
{ {
emit onSave(); bool result = false;
emit onSave(result);
return result;
}
bool ReportEnginePrivate::emitSaveReportAs()
{
bool result = false;
emit onSaveAs(result);
return result;
} }
bool ReportEnginePrivate::emitLoadReport() bool ReportEnginePrivate::emitLoadReport()
@ -602,6 +611,11 @@ void ReportEnginePrivate::emitSaveFinished()
emit saveFinished(); emit saveFinished();
} }
void ReportEnginePrivate::emitLoadFinished()
{
emit loadFinished();
}
void ReportEnginePrivate::emitPrintedToPDF(QString fileName) void ReportEnginePrivate::emitPrintedToPDF(QString fileName)
{ {
emit printedToPDF(fileName); emit printedToPDF(fileName);
@ -750,7 +764,7 @@ bool ReportEnginePrivate::loadFromFile(const QString &fileName, bool autoLoadPre
bool result = slotLoadFromFile( fileName ); bool result = slotLoadFromFile( fileName );
if (result) { if (result) {
emit loaded(); emit loadFinished();
} }
return result; return result;
} }
@ -764,7 +778,7 @@ bool ReportEnginePrivate::loadFromByteArray(QByteArray* data, const QString &nam
if (reader->readItem(this)){ if (reader->readItem(this)){
m_fileName = ""; m_fileName = "";
m_reportName = name; m_reportName = name;
emit loaded(); emit loadFinished();
return true; return true;
}; };
} }
@ -781,7 +795,7 @@ bool ReportEnginePrivate::loadFromString(const QString &report, const QString &n
if (reader->readItem(this)){ if (reader->readItem(this)){
m_fileName = ""; m_fileName = "";
m_reportName = name; m_reportName = name;
emit loaded(); emit loadFinished();
return true; return true;
}; };
} }
@ -1162,11 +1176,11 @@ ReportEngine::ReportEngine(QObject *parent)
connect(d, SIGNAL(renderPageFinished(int)), connect(d, SIGNAL(renderPageFinished(int)),
this, SIGNAL(renderPageFinished(int))); this, SIGNAL(renderPageFinished(int)));
connect(d, SIGNAL(renderFinished()), this, SIGNAL(renderFinished())); connect(d, SIGNAL(renderFinished()), this, SIGNAL(renderFinished()));
connect(d, SIGNAL(onSave()), this, SIGNAL(onSave())); connect(d, SIGNAL(onSave(bool&)), this, SIGNAL(onSave(bool&)));
connect(d, SIGNAL(onSaveAs(bool&)), this, SIGNAL(onSaveAs(bool&)));
connect(d, SIGNAL(onLoad(bool&)), this, SIGNAL(onLoad(bool&))); connect(d, SIGNAL(onLoad(bool&)), this, SIGNAL(onLoad(bool&)));
connect(d, SIGNAL(saveFinished()), this, SIGNAL(saveFinished())); connect(d, SIGNAL(saveFinished()), this, SIGNAL(saveFinished()));
connect(d, SIGNAL(loadFinished()), this, SIGNAL(loadFinished()));
connect(d, SIGNAL(loaded()), this, SIGNAL(loaded()));
connect(d, SIGNAL(printedToPDF(QString)), this, SIGNAL(printedToPDF(QString))); connect(d, SIGNAL(printedToPDF(QString)), this, SIGNAL(printedToPDF(QString)));
connect(d, SIGNAL(getAviableLanguages(QList<QLocale::Language>*)), connect(d, SIGNAL(getAviableLanguages(QList<QLocale::Language>*)),

View File

@ -119,11 +119,11 @@ signals:
void renderStarted(); void renderStarted();
void renderFinished(); void renderFinished();
void renderPageFinished(int renderedPageCount); void renderPageFinished(int renderedPageCount);
void onSave(bool& saved);
void onSaveAs(bool& saved);
void onLoad(bool& loaded); void onLoad(bool& loaded);
void onSave();
void saveFinished(); void saveFinished();
void loadFinished();
void loaded();
void printedToPDF(QString fileName); void printedToPDF(QString fileName);
void getAviableLanguages(QList<QLocale::Language>* languages); void getAviableLanguages(QList<QLocale::Language>* languages);

View File

@ -67,14 +67,16 @@ public:
virtual DataSourceManager* dataManager() = 0; virtual DataSourceManager* dataManager() = 0;
virtual QString reportFileName() = 0; virtual QString reportFileName() = 0;
virtual void setReportFileName(const QString& reportFileName) = 0; virtual void setReportFileName(const QString& reportFileName) = 0;
virtual void emitSaveFinished() = 0;
virtual bool isNeedToSave() = 0; virtual bool isNeedToSave() = 0;
virtual void emitSaveReport() = 0; virtual bool emitSaveReport() = 0;
virtual bool emitSaveReportAs() = 0;
virtual void emitSaveFinished() = 0;
virtual bool saveToFile(const QString& fileName = "") = 0; virtual bool saveToFile(const QString& fileName = "") = 0;
virtual bool isSaved() = 0; virtual bool isSaved() = 0;
virtual QString reportName() = 0; virtual QString reportName() = 0;
virtual bool loadFromFile(const QString& fileName, bool autoLoadPreviewOnChange) = 0; virtual bool loadFromFile(const QString& fileName, bool autoLoadPreviewOnChange) = 0;
virtual bool emitLoadReport() = 0; virtual bool emitLoadReport() = 0;
virtual void emitLoadFinished() = 0;
virtual void clearSelection() = 0; virtual void clearSelection() = 0;
virtual bool printReport(QPrinter *printer=0) = 0; virtual bool printReport(QPrinter *printer=0) = 0;
virtual void previewReport(PreviewHints hints = PreviewBarsUserSetting) = 0; virtual void previewReport(PreviewHints hints = PreviewBarsUserSetting) = 0;
@ -148,9 +150,11 @@ public:
bool isNeedToSave(); bool isNeedToSave();
QString lastError(); QString lastError();
ReportEngine * q_ptr; ReportEngine * q_ptr;
void emitSaveReport(); bool emitSaveReport();
bool emitSaveReportAs();
bool emitLoadReport(); bool emitLoadReport();
void emitSaveFinished(); void emitSaveFinished();
void emitLoadFinished();
void emitPrintedToPDF(QString fileName); void emitPrintedToPDF(QString fileName);
bool isSaved(); bool isSaved();
void setCurrentReportsDir(const QString& dirName); void setCurrentReportsDir(const QString& dirName);
@ -193,11 +197,11 @@ signals:
void renderStarted(); void renderStarted();
void renderFinished(); void renderFinished();
void renderPageFinished(int renderedPageCount); void renderPageFinished(int renderedPageCount);
void onSave(bool& saved);
void onSaveAs(bool& saved);
void onLoad(bool& loaded); void onLoad(bool& loaded);
void onSave();
void saveFinished(); void saveFinished();
void loadFinished();
void loaded();
void printedToPDF(QString fileName); void printedToPDF(QString fileName);
void getAviableLanguages(QList<QLocale::Language>* languages); void getAviableLanguages(QList<QLocale::Language>* languages);

View File

@ -51,7 +51,7 @@ void ObjectBrowser::setReportEditor(ReportDesignWidget *report)
{ {
m_report=report; m_report=report;
connect(m_report,SIGNAL(cleared()),this,SLOT(slotClear())); connect(m_report,SIGNAL(cleared()),this,SLOT(slotClear()));
connect(m_report, SIGNAL(loaded()), this, SLOT(slotReportLoaded())); connect(m_report, SIGNAL(loadFinished()), this, SLOT(slotReportLoaded()));
connect(m_report, SIGNAL(activePageChanged()), this, SLOT(slotActivePageChanged())); connect(m_report, SIGNAL(activePageChanged()), this, SLOT(slotActivePageChanged()));
connect(m_report,SIGNAL(itemAdded(LimeReport::PageDesignIntf*,LimeReport::BaseDesignIntf*)), connect(m_report,SIGNAL(itemAdded(LimeReport::PageDesignIntf*,LimeReport::BaseDesignIntf*)),