From 3de208b589f499672927288acd96fc0ebbcc8c95 Mon Sep 17 00:00:00 2001 From: Arin Alex Date: Thu, 25 Jul 2024 21:44:11 +0300 Subject: [PATCH] bool setDefaultExportDir(const QString& dirname) has been added --- include/lrreportengine.h | 1 + limereport/lrpreviewreportwidget.cpp | 4 ++-- limereport/lrreportengine.cpp | 18 +++++++++++++++++- limereport/lrreportengine.h | 1 + limereport/lrreportengine_p.h | 5 +++++ 5 files changed, 26 insertions(+), 3 deletions(-) diff --git a/include/lrreportengine.h b/include/lrreportengine.h index 4fdfa37..a8716e8 100644 --- a/include/lrreportengine.h +++ b/include/lrreportengine.h @@ -177,6 +177,7 @@ public: QString saveToString(); QString lastError(); void setCurrentReportsDir(const QString& dirName); + bool setDefaultExportDir(const QString& dirName); void setReportName(const QString& name); QString reportName(); PreviewReportWidget *createPreviewWidget(QWidget *parent = 0); diff --git a/limereport/lrpreviewreportwidget.cpp b/limereport/lrpreviewreportwidget.cpp index ae5d5a5..41fb6a6 100644 --- a/limereport/lrpreviewreportwidget.cpp +++ b/limereport/lrpreviewreportwidget.cpp @@ -125,7 +125,7 @@ bool PreviewReportWidget::exportReport(QString exporterName, const QMapm_report); - QString defaultFileName = d_ptr->m_report->reportName().split(".")[0]; + QString defaultFileName = d_ptr->m_report->defaultExportDir() + d_ptr->m_report->reportName().split(".")[0]; QString filter = QString("%1 (*.%2)").arg(e->exporterName()).arg(e->exporterFileExt()); QString fileName = QFileDialog::getSaveFileName(this,tr("%1 file name").arg(e->exporterName()), defaultFileName, filter); if (!fileName.isEmpty()){ @@ -286,7 +286,7 @@ void PreviewReportWidget::saveToFile() PreparedPages pagesManager = PreparedPages(&d_ptr->m_reportPages); emit onSave(saved, &pagesManager); if (!saved){ - QString fileName = QFileDialog::getSaveFileName(this,tr("Report file name")); + QString fileName = QFileDialog::getSaveFileName(this,tr("Report file name"), d_ptr->m_report->defaultExportDir()); if (!fileName.isEmpty()){ QScopedPointer< ItemsWriterIntf > writer(new XMLWriter()); foreach (PageItemDesignIntf::Ptr page, d_ptr->m_reportPages){ diff --git a/limereport/lrreportengine.cpp b/limereport/lrreportengine.cpp index 6e5d2b4..306aca7 100644 --- a/limereport/lrreportengine.cpp +++ b/limereport/lrreportengine.cpp @@ -474,7 +474,8 @@ bool ReportEnginePrivate::exportReport(QString exporterName, const QString &file QFileInfo fi(fn); if (fi.suffix().isEmpty()) fn += QString(".%1").arg(e->exporterFileExt()); - + if (fi.absolutePath().compare(QDir::currentPath())==0) + fn = defaultExportDir() + fn; bool designTime = dataManager()->designTime(); dataManager()->setDesignTime(false); ReportPages pages = renderToPages(); @@ -657,6 +658,15 @@ void ReportEnginePrivate::setCurrentReportsDir(const QString &dirName) m_reportsDir = dirName; } +bool ReportEnginePrivate::setDefaultExportDir(const QString &dirName) +{ + if (QDir(dirName).exists()){ + m_exportDir = dirName; + return true; + } + return false; +} + bool ReportEnginePrivate::slotLoadFromFile(const QString &fileName) { EASY_BLOCK("ReportEnginePrivate::slotLoadFromFile") @@ -1770,6 +1780,12 @@ void ReportEngine::setCurrentReportsDir(const QString &dirName) return d->setCurrentReportsDir(dirName); } +bool ReportEngine::setDefaultExportDir(const QString &dirName) +{ + Q_D(ReportEngine); + return d->setDefaultExportDir(dirName); +} + void ReportEngine::setReportName(const QString &name) { Q_D(ReportEngine); diff --git a/limereport/lrreportengine.h b/limereport/lrreportengine.h index 4fdfa37..a8716e8 100644 --- a/limereport/lrreportengine.h +++ b/limereport/lrreportengine.h @@ -177,6 +177,7 @@ public: QString saveToString(); QString lastError(); void setCurrentReportsDir(const QString& dirName); + bool setDefaultExportDir(const QString& dirName); void setReportName(const QString& name); QString reportName(); PreviewReportWidget *createPreviewWidget(QWidget *parent = 0); diff --git a/limereport/lrreportengine_p.h b/limereport/lrreportengine_p.h index 6b6a04b..263f91f 100644 --- a/limereport/lrreportengine_p.h +++ b/limereport/lrreportengine_p.h @@ -103,6 +103,8 @@ public: virtual void previewReport(PreviewHints hints = PreviewBarsUserSetting) = 0; virtual void setCurrentReportsDir(const QString& dirName) = 0; virtual QString currentReportsDir() = 0; + virtual bool setDefaultExportDir(const QString& dirName) = 0; + virtual QString defaultExportDir() = 0; virtual bool suppressFieldAndVarError() const = 0; virtual void setSuppressFieldAndVarError(bool suppressFieldAndVarError) = 0; virtual void setStyleSheet(const QString& styleSheet) = 0; @@ -210,6 +212,8 @@ public: bool isSaved(); void setCurrentReportsDir(const QString& dirName); QString currentReportsDir(){ return m_reportsDir;} + bool setDefaultExportDir(const QString& dirname); + QString defaultExportDir(){ return m_exportDir;} void setReportName(const QString& reportName){ m_reportName=reportName;} QString reportName(){ return m_reportName;} bool hasActivePreview(){return m_activePreview;} @@ -336,6 +340,7 @@ private: bool m_printerSelected; bool m_showProgressDialog; QString m_reportsDir; + QString m_exportDir; QString m_reportName; QMainWindow* m_activePreview; QIcon m_previewWindowIcon;