diff --git a/kexi/plugins/reports/kexireportdesignview.h b/kexi/plugins/reports/kexireportdesignview.h --- a/kexi/plugins/reports/kexireportdesignview.h +++ b/kexi/plugins/reports/kexireportdesignview.h @@ -75,9 +75,7 @@ private Q_SLOTS: void slotDesignerPropertySetChanged(); - -public Q_SLOTS: - void slotSetData(KoReportData*); + void slotSourceDataChanged(); }; #endif diff --git a/kexi/plugins/reports/kexireportdesignview.cpp b/kexi/plugins/reports/kexireportdesignview.cpp --- a/kexi/plugins/reports/kexireportdesignview.cpp +++ b/kexi/plugins/reports/kexireportdesignview.cpp @@ -196,9 +196,9 @@ return static_cast(window()->data()); } -void KexiReportDesignView::slotSetData(KoReportData* kodata) +void KexiReportDesignView::slotSourceDataChanged() { - m_reportDesigner->setReportData(kodata); + m_reportDesigner->setReportData(m_sourceSelector->createSourceData()); tempData()->connectionDefinition = m_sourceSelector->connectionData(); setDirty(true); } diff --git a/kexi/plugins/reports/kexireportpart.cpp b/kexi/plugins/reports/kexireportpart.cpp --- a/kexi/plugins/reports/kexireportpart.cpp +++ b/kexi/plugins/reports/kexireportpart.cpp @@ -92,7 +92,7 @@ } else if (viewMode == Kexi::DesignViewMode) { view = new KexiReportDesignView(parent, d->sourceSelector); - connect(d->sourceSelector, SIGNAL(setData(KoReportData*)), view, SLOT(slotSetData(KoReportData*))); + connect(d->sourceSelector, SIGNAL(sourceDataChanged()), view, SLOT(slotSourceDataChanged())); connect(view, SIGNAL(itemInserted(QString)), this, SLOT(slotItemInserted(QString))); } return view; diff --git a/kexi/plugins/reports/kexireportview.h b/kexi/plugins/reports/kexireportview.h --- a/kexi/plugins/reports/kexireportview.h +++ b/kexi/plugins/reports/kexireportview.h @@ -72,7 +72,7 @@ int m_currentPage; int m_pageCount; KexiReportPart::TempData* tempData() const; - KoReportData* sourceData(const QDomElement &e); + KoReportData* createSourceData(const QDomElement &e); KexiScriptAdaptor *m_kexi; KRScriptFunctions *m_functions; diff --git a/kexi/plugins/reports/kexireportview.cpp b/kexi/plugins/reports/kexireportview.cpp --- a/kexi/plugins/reports/kexireportview.cpp +++ b/kexi/plugins/reports/kexireportview.cpp @@ -397,7 +397,7 @@ if (m_preRenderer->isValid()) { KoReportData *reportData = 0; if (!tempData()->connectionDefinition.isNull()) { - reportData = sourceData(tempData()->connectionDefinition); + reportData = createSourceData(tempData()->connectionDefinition); } if (!reportData) { reportData = new KexiDBReportData(QString(), QString(), @@ -442,7 +442,7 @@ return true; } -KoReportData* KexiReportView::sourceData(const QDomElement &e) +KoReportData* KexiReportView::createSourceData(const QDomElement &e) { KoReportData *kodata = 0; diff --git a/kexi/plugins/reports/kexisourceselector.h b/kexi/plugins/reports/kexisourceselector.h --- a/kexi/plugins/reports/kexisourceselector.h +++ b/kexi/plugins/reports/kexisourceselector.h @@ -1,6 +1,7 @@ /* * Kexi Report Plugin * Copyright (C) 2007-2009 by Adam Pigg (adam@piggz.co.uk) +* Copyright (C) 2016 Jarosław Staniek * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -39,15 +40,12 @@ explicit KexiSourceSelector(KexiProject* project, QWidget* parent = 0); ~KexiSourceSelector(); - KoReportData* sourceData(); + KoReportData* createSourceData() const Q_REQUIRED_RESULT; void setConnectionData(const QDomElement &c); QDomElement connectionData(); Q_SIGNALS: - void setData(KoReportData*); - -private Q_SLOTS: - void setDataClicked(); + void sourceDataChanged(); private: class Private; diff --git a/kexi/plugins/reports/kexisourceselector.cpp b/kexi/plugins/reports/kexisourceselector.cpp --- a/kexi/plugins/reports/kexisourceselector.cpp +++ b/kexi/plugins/reports/kexisourceselector.cpp @@ -1,6 +1,7 @@ /* * Kexi Report Plugin * Copyright (C) 2007-2009 by Adam Pigg (adam@piggz.co.uk) +* Copyright (C) 2016 Jarosław Staniek * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -45,16 +46,11 @@ { public: Private() - : kexiDBData(0) { } ~Private() { - delete kexiDBData; -#ifndef KEXI_MOBILE - delete kexiMigrateData; -#endif } KexiDB::Connection *conn; @@ -64,34 +60,21 @@ KexiDataSourceComboBox *internalSource; KLineEdit *externalSource; KPushButton *setData; - - KexiDBReportData *kexiDBData; - -#ifndef KEXI_MOBILE - KexiMigrateReportData *kexiMigrateData; -#endif - }; KexiSourceSelector::KexiSourceSelector(KexiProject* project, QWidget* parent) : QWidget(parent) , d(new Private) { d->conn = project->dbConnection(); - d->kexiDBData = 0; - -#ifndef KEXI_MOBILE - d->kexiMigrateData = 0; -#endif - d->layout = new QVBoxLayout(this); d->sourceType = new QComboBox(this); d->internalSource = new KexiDataSourceComboBox(this); d->internalSource->setProject(project); d->externalSource = new KLineEdit(this); d->setData = new KPushButton(i18n("Set Data")); - connect(d->setData, SIGNAL(clicked()), this, SLOT(setDataClicked())); + connect(d->setData, SIGNAL(clicked()), this, SIGNAL(sourceDataChanged())); d->sourceType->addItem(i18n("Internal"), QVariant("internal")); d->sourceType->addItem(i18n("External"), QVariant("external")); @@ -140,7 +123,7 @@ d->externalSource->setText(c.attribute("source")); } - emit setData(sourceData()); + emit sourceDataChanged(); } QDomElement KexiSourceSelector::connectionData() @@ -170,20 +153,8 @@ return conndata; } -KoReportData* KexiSourceSelector::sourceData() +KoReportData* KexiSourceSelector::createSourceData() const { - if (d->kexiDBData) { - delete d->kexiDBData; - d->kexiDBData = 0; - } - -#ifndef KEXI_MOBILE - if (d->kexiMigrateData) { - delete d->kexiMigrateData; - d->kexiMigrateData = 0; - } -#endif - //!@TODO Fix when enable external data #ifndef NO_EXTERNAL_SOURCES KexiReportView *view = 0; @@ -194,29 +165,21 @@ } } if (d->sourceType->itemData(d->sourceType->currentIndex()).toString() == "internal" && d->internalSource->isSelectionValid()) { - d->kexiDBData = new KexiDBReportData(d->internalSource->selectedName(), + return new KexiDBReportData(d->internalSource->selectedName(), d->internalSource->selectedPartClass(), d->conn, view); - return d->kexiDBData; } #ifndef KEXI_MOBILE if (d->sourceType->itemData(d->sourceType->currentIndex()).toString() == "external") { - d->kexiMigrateData = new KexiMigrateReportData(d->externalSource->text()); - return d->kexiMigrateData; + return new KexiMigrateReportData(d->externalSource->text()); } #endif #else if (d->internalSource->isSelectionValid()) { - d->kexiDBData = new KexiDBReportData(d->internalSource->selectedName(), d->conn); - return d->kexiDBData; + return new KexiDBReportData(d->internalSource->selectedName(), d->conn); } #endif return 0; } - -void KexiSourceSelector::setDataClicked() -{ - emit(setData(sourceData())); -} diff --git a/libs/koreport/renderer/KoReportPreRenderer.h b/libs/koreport/renderer/KoReportPreRenderer.h --- a/libs/koreport/renderer/KoReportPreRenderer.h +++ b/libs/koreport/renderer/KoReportPreRenderer.h @@ -44,7 +44,8 @@ virtual ~KoReportPreRenderer(); - void setSourceData(KoReportData*); + //! Sets source data to @a data, takes ownership + void setSourceData(KoReportData *data); void registerScriptObject(QObject*, const QString&); bool generateDocument(); diff --git a/libs/koreport/renderer/KoReportPreRenderer.cpp b/libs/koreport/renderer/KoReportPreRenderer.cpp --- a/libs/koreport/renderer/KoReportPreRenderer.cpp +++ b/libs/koreport/renderer/KoReportPreRenderer.cpp @@ -119,6 +119,7 @@ m_postProcText.clear(); delete m_document; + delete m_kodata; } void KoReportPreRendererPrivate::createNewPage() @@ -634,7 +635,9 @@ return false; } delete m_scriptHandler; + m_scriptHandler = 0; delete m_kodata; + m_kodata = 0; m_postProcText.clear(); return true; } @@ -668,7 +671,8 @@ void KoReportPreRenderer::setSourceData(KoReportData *data) { - if (d && data) { + if (d && d->m_kodata != data) { + delete d->m_kodata; d->m_kodata = data; } } diff --git a/libs/koreport/wrtembed/KoReportDesigner.h b/libs/koreport/wrtembed/KoReportDesigner.h --- a/libs/koreport/wrtembed/KoReportDesigner.h +++ b/libs/koreport/wrtembed/KoReportDesigner.h @@ -89,7 +89,7 @@ @brief Sets the report data The report data interface contains functions to retrieve data and information about the fields. - @param kodata Pointer to KoReportData instance + @param kodata Pointer to KoReportData instance, ownership is transferred */ void setReportData(KoReportData* kodata); diff --git a/libs/koreport/wrtembed/KoReportDesigner.cpp b/libs/koreport/wrtembed/KoReportDesigner.cpp --- a/libs/koreport/wrtembed/KoReportDesigner.cpp +++ b/libs/koreport/wrtembed/KoReportDesigner.cpp @@ -196,6 +196,7 @@ delete d; delete m_sectionData; delete m_set; + delete m_kordata; } ///The loading Code @@ -375,6 +376,10 @@ void KoReportDesigner::setReportData(KoReportData* kodata) { + if (m_kordata == kodata) { + return; + } + delete m_kordata; m_kordata = kodata; slotPageButton_Pressed(); setModified(true);