0
0
mirror of https://github.com/fralx/LimeReport.git synced 2024-12-24 08:34:38 +03:00

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
This commit is contained in:
James 2018-05-23 12:01:30 -04:00
parent 56e78f86ba
commit afd4944506
9 changed files with 108 additions and 71 deletions

View File

@ -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<QLocale::Language>* languages);
void currentDefaulLanguageChanged(QLocale::Language);
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(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)));
#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();

View File

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

View File

@ -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,8 +1067,10 @@ void ReportDesignWindow::slotSaveReportAs()
void ReportDesignWindow::slotLoadReport()
{
if (checkNeedToSave()){
if (!m_reportDesignWidget->emitLoadReport()){
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(),
@ -1101,9 +1109,7 @@ void ReportDesignWindow::slotLoadReport()
addRecentFile(fileName);
m_editorTabType = ReportDesignWidget::Page;
}
}
}
}
void ReportDesignWindow::slotZoomIn()

View File

@ -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<QLocale::Language>*)),

View File

@ -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<QLocale::Language>* languages);

View File

@ -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<QLocale::Language>* languages);

View File

@ -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*)),

View File

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