From afd49445060a992358682d525245bc85fcfee0cb Mon Sep 17 00:00:00 2001 From: James Date: Wed, 23 May 2018 12:01:30 -0400 Subject: [PATCH] Report Engine: changed onSave() -> onSave(bool&) rename 'loaded' signal to 'loadFinshed' to be consistent with 'saveFinished' signal added signal 'onSaveAs' and corresponding added functions: 'emitSaveReportAs', 'emitLoadFinished' DesignWidget: add boolean functions checking whether emitSaveReport and emitSaveReportAs completed. DesignWindow: save / saveas / load functions are interceptable by reportengine signals --- include/lrreportengine.h | 7 +- limereport/lrreportdesignwidget.cpp | 22 ++++- limereport/lrreportdesignwidget.h | 2 + limereport/lrreportdesignwindow.cpp | 92 ++++++++++--------- limereport/lrreportengine.cpp | 30 ++++-- limereport/lrreportengine.h | 6 +- limereport/lrreportengine_p.h | 16 ++-- limereport/objectsbrowser/lrobjectbrowser.cpp | 2 +- limereport/scriptbrowser/lrscriptbrowser.cpp | 2 +- 9 files changed, 108 insertions(+), 71 deletions(-) diff --git a/include/lrreportengine.h b/include/lrreportengine.h index a4c1158..3b01f4f 100644 --- a/include/lrreportengine.h +++ b/include/lrreportengine.h @@ -119,13 +119,12 @@ signals: void renderStarted(); void renderFinished(); void renderPageFinished(int renderedPageCount); + void onSave(bool& saved); + void onSaveAs(bool& saved); void onLoad(bool& loaded); - void onSave(); void saveFinished(); - - void loaded(); + void loadFinished(); void printedToPDF(QString fileName); - void getAviableLanguages(QList* languages); void currentDefaulLanguageChanged(QLocale::Language); QLocale::Language getCurrentDefaultLanguage(); diff --git a/limereport/lrreportdesignwidget.cpp b/limereport/lrreportdesignwidget.cpp index b20d17e..8d48f61 100644 --- a/limereport/lrreportdesignwidget.cpp +++ b/limereport/lrreportdesignwidget.cpp @@ -79,7 +79,7 @@ ReportDesignWidget::ReportDesignWidget(ReportEnginePrivateInterface* report, QMa connect(dynamic_cast(m_report), SIGNAL(pagesLoadFinished()),this,SLOT(slotPagesLoadFinished())); connect(dynamic_cast(m_report), SIGNAL(cleared()), this, SIGNAL(cleared())); - connect(dynamic_cast(m_report), SIGNAL(loaded()), this, SLOT(slotReportLoaded())); + connect(dynamic_cast(m_report), SIGNAL(loadFinished()), this, SLOT(slotReportLoaded())); connect(m_tabWidget, SIGNAL(currentChanged(int)), this, SLOT(slotCurrentTabChanged(int))); #ifdef HAVE_UI_LOADER @@ -432,14 +432,15 @@ bool ReportDesignWidget::save() 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()){ m_report->emitSaveFinished(); result = true; } - } - else { - m_report->emitSaveReport(); + } else { if (m_report->isSaved()) { m_report->emitSaveFinished(); result = true; @@ -449,6 +450,7 @@ bool ReportDesignWidget::save() result = true; }; } + #ifdef HAVE_QTDESIGNER_INTEGRATION if (result){ m_dialogChanged = false; @@ -494,6 +496,16 @@ bool ReportDesignWidget::isNeedToSave() return false; } +bool ReportDesignWidget::emitSaveReport() +{ + return m_report->emitSaveReport(); +} + +bool ReportDesignWidget::emitSaveReportAs() +{ + return m_report->emitSaveReportAs(); +} + bool ReportDesignWidget::emitLoadReport() { return m_report->emitLoadReport(); diff --git a/limereport/lrreportdesignwidget.h b/limereport/lrreportdesignwidget.h index 8e812dc..7f67bb5 100644 --- a/limereport/lrreportdesignwidget.h +++ b/limereport/lrreportdesignwidget.h @@ -108,6 +108,8 @@ public: ReportEnginePrivateInterface* report(){return m_report;} QString reportFileName(); bool isNeedToSave(); + bool emitSaveReport(); + bool emitSaveReportAs(); bool emitLoadReport(); void saveState(QSettings *settings); void loadState(QSettings *settings); diff --git a/limereport/lrreportdesignwindow.cpp b/limereport/lrreportdesignwindow.cpp index fb2d073..d02cbef 100644 --- a/limereport/lrreportdesignwindow.cpp +++ b/limereport/lrreportdesignwindow.cpp @@ -1044,13 +1044,19 @@ void ReportDesignWindow::slotCommandHistoryChanged() void ReportDesignWindow::slotSaveReport() { + if (m_reportDesignWidget->emitSaveReport()) return; // report save as'd via signal + 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() { + 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(*)"); if (!fileName.isEmpty()){ m_reportDesignWidget->saveToFile(fileName); @@ -1061,49 +1067,49 @@ void ReportDesignWindow::slotSaveReportAs() void ReportDesignWindow::slotLoadReport() { - if (checkNeedToSave()){ - if (!m_reportDesignWidget->emitLoadReport()){ - QString fileName = QFileDialog::getOpenFileName( - this,tr("Report file name"), - m_reportDesignWidget->report()->currentReportsDir(), - "Report files(*.lrxml);; All files(*)" - ); - if (!fileName.isEmpty()) { - QApplication::processEvents(); - setCursor(Qt::WaitCursor); - m_reportDesignWidget->clear(); - if (m_reportDesignWidget->loadFromFile(fileName)){ - m_lblReportName->setText(fileName); - m_propertyModel->setObject(0); - updateRedoUndo(); - setWindowTitle(m_reportDesignWidget->report()->reportName() + " - Lime Report Designer"); - if (!m_recentFiles.contains(fileName)){ - if (m_recentFiles.count()==10){ - QMap::const_iterator it = m_recentFiles.constBegin(); - QDateTime minDate = QDateTime::currentDateTime(); - while (it != m_recentFiles.constEnd()) { - if (minDate>it.value()) minDate = it.value(); - ++it; - } - m_recentFiles.remove(m_recentFiles.key(minDate)); - } - m_recentFiles.insert(fileName,QDateTime::currentDateTime()); - } else { - m_recentFiles[fileName] = QDateTime::currentDateTime(); - } - createRecentFilesMenu(); - m_deletePageAction->setEnabled(m_reportDesignWidget->report()->pageCount()>1); - } else { - slotNewReport(); - } - unsetCursor(); - setWindowTitle(m_reportDesignWidget->report()->reportName() + " - Lime Report Designer"); - addRecentFile(fileName); - m_editorTabType = ReportDesignWidget::Page; - } - } + if (!checkNeedToSave()) return; // don't need to save + if (m_reportDesignWidget->emitLoadReport()) return; // report loaded via signal + + QString fileName = QFileDialog::getOpenFileName( + this,tr("Report file name"), + m_reportDesignWidget->report()->currentReportsDir(), + "Report files(*.lrxml);; All files(*)" + ); + if (!fileName.isEmpty()) { + QApplication::processEvents(); + setCursor(Qt::WaitCursor); + m_reportDesignWidget->clear(); + if (m_reportDesignWidget->loadFromFile(fileName)){ + m_lblReportName->setText(fileName); + m_propertyModel->setObject(0); + updateRedoUndo(); + setWindowTitle(m_reportDesignWidget->report()->reportName() + " - Lime Report Designer"); + if (!m_recentFiles.contains(fileName)){ + if (m_recentFiles.count()==10){ + QMap::const_iterator it = m_recentFiles.constBegin(); + QDateTime minDate = QDateTime::currentDateTime(); + while (it != m_recentFiles.constEnd()) { + if (minDate>it.value()) minDate = it.value(); + ++it; + } + m_recentFiles.remove(m_recentFiles.key(minDate)); + } + m_recentFiles.insert(fileName,QDateTime::currentDateTime()); + } else { + m_recentFiles[fileName] = QDateTime::currentDateTime(); + } + createRecentFilesMenu(); + m_deletePageAction->setEnabled(m_reportDesignWidget->report()->pageCount()>1); + } else { + slotNewReport(); + } + unsetCursor(); + setWindowTitle(m_reportDesignWidget->report()->reportName() + " - Lime Report Designer"); + addRecentFile(fileName); + m_editorTabType = ReportDesignWidget::Page; } + } void ReportDesignWindow::slotZoomIn() diff --git a/limereport/lrreportengine.cpp b/limereport/lrreportengine.cpp index 95275c2..a5d101e 100644 --- a/limereport/lrreportengine.cpp +++ b/limereport/lrreportengine.cpp @@ -585,9 +585,18 @@ PageDesignIntf* ReportEnginePrivate::createPreviewScene(QObject* parent){ 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() @@ -602,6 +611,11 @@ void ReportEnginePrivate::emitSaveFinished() emit saveFinished(); } +void ReportEnginePrivate::emitLoadFinished() +{ + emit loadFinished(); +} + void ReportEnginePrivate::emitPrintedToPDF(QString fileName) { emit printedToPDF(fileName); @@ -750,7 +764,7 @@ bool ReportEnginePrivate::loadFromFile(const QString &fileName, bool autoLoadPre bool result = slotLoadFromFile( fileName ); if (result) { - emit loaded(); + emit loadFinished(); } return result; } @@ -764,7 +778,7 @@ bool ReportEnginePrivate::loadFromByteArray(QByteArray* data, const QString &nam if (reader->readItem(this)){ m_fileName = ""; m_reportName = name; - emit loaded(); + emit loadFinished(); return true; }; } @@ -781,7 +795,7 @@ bool ReportEnginePrivate::loadFromString(const QString &report, const QString &n if (reader->readItem(this)){ m_fileName = ""; m_reportName = name; - emit loaded(); + emit loadFinished(); return true; }; } @@ -1162,11 +1176,11 @@ ReportEngine::ReportEngine(QObject *parent) connect(d, SIGNAL(renderPageFinished(int)), this, SIGNAL(renderPageFinished(int))); 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(saveFinished()), this, SIGNAL(saveFinished())); - - connect(d, SIGNAL(loaded()), this, SIGNAL(loaded())); + connect(d, SIGNAL(loadFinished()), this, SIGNAL(loadFinished())); connect(d, SIGNAL(printedToPDF(QString)), this, SIGNAL(printedToPDF(QString))); connect(d, SIGNAL(getAviableLanguages(QList*)), diff --git a/limereport/lrreportengine.h b/limereport/lrreportengine.h index a4c1158..a188cef 100644 --- a/limereport/lrreportengine.h +++ b/limereport/lrreportengine.h @@ -119,11 +119,11 @@ signals: void renderStarted(); void renderFinished(); void renderPageFinished(int renderedPageCount); + void onSave(bool& saved); + void onSaveAs(bool& saved); void onLoad(bool& loaded); - void onSave(); void saveFinished(); - - void loaded(); + void loadFinished(); void printedToPDF(QString fileName); void getAviableLanguages(QList* languages); diff --git a/limereport/lrreportengine_p.h b/limereport/lrreportengine_p.h index a5c7fb4..ea8c854 100644 --- a/limereport/lrreportengine_p.h +++ b/limereport/lrreportengine_p.h @@ -67,14 +67,16 @@ public: virtual DataSourceManager* dataManager() = 0; virtual QString reportFileName() = 0; virtual void setReportFileName(const QString& reportFileName) = 0; - virtual void emitSaveFinished() = 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 isSaved() = 0; virtual QString reportName() = 0; virtual bool loadFromFile(const QString& fileName, bool autoLoadPreviewOnChange) = 0; virtual bool emitLoadReport() = 0; + virtual void emitLoadFinished() = 0; virtual void clearSelection() = 0; virtual bool printReport(QPrinter *printer=0) = 0; virtual void previewReport(PreviewHints hints = PreviewBarsUserSetting) = 0; @@ -148,9 +150,11 @@ public: bool isNeedToSave(); QString lastError(); ReportEngine * q_ptr; - void emitSaveReport(); + bool emitSaveReport(); + bool emitSaveReportAs(); bool emitLoadReport(); void emitSaveFinished(); + void emitLoadFinished(); void emitPrintedToPDF(QString fileName); bool isSaved(); void setCurrentReportsDir(const QString& dirName); @@ -193,11 +197,11 @@ signals: void renderStarted(); void renderFinished(); void renderPageFinished(int renderedPageCount); + void onSave(bool& saved); + void onSaveAs(bool& saved); void onLoad(bool& loaded); - void onSave(); void saveFinished(); - - void loaded(); + void loadFinished(); void printedToPDF(QString fileName); void getAviableLanguages(QList* languages); diff --git a/limereport/objectsbrowser/lrobjectbrowser.cpp b/limereport/objectsbrowser/lrobjectbrowser.cpp index a5ee464..508f7a9 100644 --- a/limereport/objectsbrowser/lrobjectbrowser.cpp +++ b/limereport/objectsbrowser/lrobjectbrowser.cpp @@ -51,7 +51,7 @@ void ObjectBrowser::setReportEditor(ReportDesignWidget *report) { m_report=report; 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(itemAdded(LimeReport::PageDesignIntf*,LimeReport::BaseDesignIntf*)), diff --git a/limereport/scriptbrowser/lrscriptbrowser.cpp b/limereport/scriptbrowser/lrscriptbrowser.cpp index 98d0568..75f5842 100644 --- a/limereport/scriptbrowser/lrscriptbrowser.cpp +++ b/limereport/scriptbrowser/lrscriptbrowser.cpp @@ -58,7 +58,7 @@ void ScriptBrowser::setReportEditor(ReportDesignWidget* report) { m_report=report; connect(m_report,SIGNAL(cleared()),this,SLOT(slotClear())); - connect(m_report,SIGNAL(loaded()),this,SLOT(slotUpdate())); + connect(m_report,SIGNAL(loadFinished()),this,SLOT(slotUpdate())); #ifdef HAVE_UI_LOADER connect(m_report->scriptContext(), SIGNAL(dialogAdded(QString)), this, SLOT(slotDialogAdded(QString))); #endif