diff --git a/src/lrreportengine.cpp b/src/lrreportengine.cpp index fcb482a..acfa4aa 100644 --- a/src/lrreportengine.cpp +++ b/src/lrreportengine.cpp @@ -55,7 +55,7 @@ QSettings* ReportEngine::m_settings = 0; ReportEnginePrivate::ReportEnginePrivate(QObject *parent) : QObject(parent), m_fileName(""), m_settings(0), m_ownedSettings(false), m_printer(new QPrinter(QPrinter::HighResolution)), m_printerSelected(false), - m_showProgressDialog(true), m_reportName("") + m_showProgressDialog(true), m_reportName(""), m_activePreview(0) { m_datasources= new DataSourceManager(this); m_datasources->setObjectName("datasources"); @@ -64,6 +64,9 @@ ReportEnginePrivate::ReportEnginePrivate(QObject *parent) : ReportEnginePrivate::~ReportEnginePrivate() { + if (m_activePreview){ + m_activePreview->close(); + } foreach(PageDesignIntf* page,m_pages) delete page; m_pages.clear(); if (m_ownedSettings&&m_settings) delete m_settings; @@ -81,7 +84,7 @@ QObject *ReportEnginePrivate::elementAt(const QString &, int index) PageDesignIntf *ReportEnginePrivate::createPage(const QString &pageName) { - PageDesignIntf* page =new PageDesignIntf(this); + PageDesignIntf* page =new PageDesignIntf(); page->setObjectName(pageName); page->setReportEditor(this); return page; @@ -130,6 +133,13 @@ void ReportEnginePrivate::slotDataSourceCollectionLoaded(const QString &collecti emit datasourceCollectionLoadFinished(collectionName); } +void ReportEnginePrivate::slotPreviewWindowDestroed(QObject* window) +{ + if (m_activePreview == window){ + m_activePreview = 0; + } +} + void ReportEnginePrivate::clearReport() { foreach(PageDesignIntf* page,m_pages) delete page; @@ -291,6 +301,8 @@ void ReportEnginePrivate::previewReport() if (!dataManager()->errorsList().isEmpty()){ w->setErrorMessages(dataManager()->errorsList()); } + m_activePreview = w; + connect(w,SIGNAL(destroyed(QObject*)), this, SLOT(slotPreviewWindowDestroed(QObject*))); qDebug()<<"render time ="<exec(); } diff --git a/src/lrreportengine_p.h b/src/lrreportengine_p.h index d45f311..5fbcd9d 100644 --- a/src/lrreportengine_p.h +++ b/src/lrreportengine_p.h @@ -32,6 +32,7 @@ #include #include +#include #include "lrreportengine.h" #include "lrcollection.h" #include "lrglobal.h" @@ -100,6 +101,7 @@ public: QString currentReportsDir(){ return m_reportsDir;} void setReportName(const QString& reportName){ m_reportName=reportName;} QString reportName(){ return m_reportName;} + bool hasActivePreview(){return m_activePreview;} signals: void pagesLoadFinished(); void datasourceCollectionLoadFinished(const QString& collectionName); @@ -115,6 +117,8 @@ protected: PageDesignIntf* createPage(const QString& pageName=""); protected slots: void slotDataSourceCollectionLoaded(const QString& collectionName); +private slots: + void slotPreviewWindowDestroed(QObject *window); private: //ICollectionContainer virtual QObject* createElement(const QString&,const QString&); @@ -139,6 +143,7 @@ private: bool m_showProgressDialog; QString m_reportsDir; QString m_reportName; + QMainWindow* m_activePreview; }; }