diff --git a/kexi/plugins/reports/kexidbreportdata.h b/kexi/plugins/reports/kexidbreportdata.h --- a/kexi/plugins/reports/kexidbreportdata.h +++ b/kexi/plugins/reports/kexidbreportdata.h @@ -1,7 +1,7 @@ /* * Kexi Report Plugin * Copyright (C) 2007-2009 by Adam Pigg (adam@piggz.co.uk) -* Copyright (C) 2015 Jarosław Staniek +* Copyright (C) 2015-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 @@ -36,23 +36,22 @@ class KexiDBReportData : public KoReportData { public: - KexiDBReportData(const QString &objectName, KexiDB::Connection *conn, KexiReportView *view); - /*! - * @a partClass specifies @a objectName type: a table or query. + * @a objectClass specifies @a objectName type: a table or query. * Types accepted: * -"org.kexi-project.table" * -"org.kexi-project.query" * -empty QString() - attempt to resolve @a objectName */ - KexiDBReportData(const QString &objectName, const QString& partClass, KexiDB::Connection *conn, KexiReportView *view); + KexiDBReportData(const QString &objectName, const QString& objectClass, KexiDB::Connection *conn, KexiReportView *view); virtual ~KexiDBReportData(); virtual QStringList fieldNames() const; virtual void setSorting(const QList& sorting); virtual void addExpression(const QString &field, const QVariant &value, int relation = '='); virtual QString sourceName() const; + virtual QString sourceClass() const; virtual int fieldNumber(const QString &field) const; virtual QVariant value(unsigned int) const; virtual QVariant value(const QString &field) const; @@ -77,7 +76,7 @@ class Private; Private * const d; - bool getSchema(const QString& partClass = QString()); + bool getSchema(); }; #endif diff --git a/kexi/plugins/reports/kexidbreportdata.cpp b/kexi/plugins/reports/kexidbreportdata.cpp --- a/kexi/plugins/reports/kexidbreportdata.cpp +++ b/kexi/plugins/reports/kexidbreportdata.cpp @@ -1,7 +1,7 @@ /* * Kexi Report Plugin * Copyright (C) 2007-2009 by Adam Pigg (adam@piggz.co.uk) -* Copyright (C) 2015 Jarosław Staniek +* Copyright (C) 2015-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 @@ -41,28 +41,22 @@ } QString objectName; + QString objectClass; KexiDB::Cursor *cursor; KexiDB::Connection * const connection; KexiReportView * const view; KexiDB::QuerySchema *originalSchema; KexiDB::QuerySchema *copySchema; }; -KexiDBReportData::KexiDBReportData (const QString &objectName, - KexiDB::Connection * pDb, KexiReportView *view) - : d(new Private(pDb, view)) -{ - d->objectName = objectName; - getSchema(); -} - KexiDBReportData::KexiDBReportData(const QString& objectName, - const QString& partClass, + const QString& objectClass, KexiDB::Connection* pDb, KexiReportView *view) : d(new Private(pDb, view)) { d->objectName = objectName; - getSchema(partClass); + d->objectClass = objectClass; + getSchema(); } void KexiDBReportData::setSorting(const QList& sorting) @@ -138,22 +132,22 @@ return true; } -bool KexiDBReportData::getSchema(const QString& partClass) +bool KexiDBReportData::getSchema() { if (d->connection) { delete d->originalSchema; d->originalSchema = 0; delete d->copySchema; d->copySchema = 0; - if ((partClass.isEmpty() || partClass == "org.kexi-project.table") + if ((d->objectClass.isEmpty() || d->objectClass == "org.kexi-project.table") && d->connection->tableSchema(d->objectName)) { kDebug() << d->objectName << "is a table.."; d->originalSchema = new KexiDB::QuerySchema(*(d->connection->tableSchema(d->objectName))); } - else if ((partClass.isEmpty() || partClass == "org.kexi-project.query") + else if ((d->objectClass.isEmpty() || d->objectClass == "org.kexi-project.query") && d->connection->querySchema(d->objectName)) { kDebug() << d->objectName << "is a query.."; @@ -180,6 +174,11 @@ return d->objectName; } +QString KexiDBReportData::sourceClass() const +{ + return d->objectClass; +} + int KexiDBReportData::fieldNumber ( const QString &fld ) const { @@ -400,5 +399,5 @@ KoReportData* KexiDBReportData::create(const QString& source) const { - return new KexiDBReportData(source, d->connection, d->view); + return new KexiDBReportData(source, QString(), d->connection, d->view); } 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 @@ -200,6 +200,7 @@ { m_reportDesigner->setReportData(kodata); tempData()->connectionDefinition = m_sourceSelector->connectionData(); + setDirty(true); } void KexiReportDesignView::triggerAction(const QString &action) diff --git a/kexi/plugins/reports/kexireportpart.h b/kexi/plugins/reports/kexireportpart.h --- a/kexi/plugins/reports/kexireportpart.h +++ b/kexi/plugins/reports/kexireportpart.h @@ -64,6 +64,7 @@ Check this flag to see if we should refresh data for DataViewMode. */ bool reportSchemaChangedInPreviousView; QString name; + QString className; //!< org.kexi-project.table or org.kexi-project.query }; virtual KLocalizedString i18nMessage(const QString& englishMessage, 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 @@ -158,8 +158,6 @@ td->reportDefinition = korep; td->connectionDefinition = conn; - - td->name = window->partItem()->name(); return td; } 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(QDomElement e); + KoReportData* sourceData(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 @@ -1,7 +1,7 @@ /* * Kexi Report Plugin * Copyright (C) 2007-2008 by Adam Pigg (adam@piggz.co.uk) - Copyright (C) 2014 Jarosław Staniek + Copyright (C) 2014-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 @@ -400,11 +400,11 @@ reportData = sourceData(tempData()->connectionDefinition); } if (!reportData) { - reportData = new KexiDBReportData(QString(), KexiMainWindowIface::global()->project()->dbConnection(), this); + reportData = new KexiDBReportData(QString(), QString(), + KexiMainWindowIface::global()->project()->dbConnection(), this); } m_preRenderer->setSourceData(reportData); - - m_preRenderer->setName(tempData()->name); + m_currentPage = 1; //Add a kexi object to provide kexidb and extra functionality @@ -442,12 +442,13 @@ return true; } -KoReportData* KexiReportView::sourceData(QDomElement e) +KoReportData* KexiReportView::sourceData(const QDomElement &e) { KoReportData *kodata = 0; if (e.attribute("type") == "internal") { kodata = new KexiDBReportData(e.attribute("source"), + e.attribute("source-class"), KexiMainWindowIface::global()->project()->dbConnection(), this); } 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 @@ -131,7 +131,8 @@ { if (c.attribute("type") == "internal") { d->sourceType->setCurrentIndex(d->sourceType->findData("internal")); - d->internalSource->setCurrentIndex(d->internalSource->findText(c.attribute("source"))); + d->internalSource->setDataSource( + c.attribute("source-class"), c.attribute("source")); } if (c.attribute("type") == "external") { @@ -155,6 +156,10 @@ if (d->sourceType->itemData(d->sourceType->currentIndex()).toString() == "internal") { conndata.setAttribute("source", d->internalSource->currentText()); + const QString sourceClass(d->internalSource->selectedPartClass()); + if (!sourceClass.isEmpty()) { + conndata.setAttribute("source-class", sourceClass); + } } else { conndata.setAttribute("source", d->externalSource->text()); } diff --git a/kexi/plugins/reports/krscriptfunctions.cpp b/kexi/plugins/reports/krscriptfunctions.cpp --- a/kexi/plugins/reports/krscriptfunctions.cpp +++ b/kexi/plugins/reports/krscriptfunctions.cpp @@ -1,7 +1,7 @@ /* * Kexi Report Plugin * Copyright (C) 2007-2008 by Adam Pigg - * Copyright (C) 2012 Jarosław Staniek + * Copyright (C) 2012-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 @@ -26,10 +26,15 @@ m_cursor = kodata; m_connection = conn; - if (m_connection->tableSchema(kodata->sourceName())) { - m_source = kodata->sourceName(); - } else if (m_connection->querySchema(kodata->sourceName())) { - m_source = m_connection->selectStatement(*(m_connection->querySchema(kodata->sourceName()))); + if (kodata->sourceClass().isEmpty() || kodata->sourceClass() == "org.kexi-project.table") { + if (m_connection->tableSchema(kodata->sourceName())) { + m_source = kodata->sourceName(); + } + } + if (m_source.isEmpty() && (kodata->sourceClass().isEmpty() || kodata->sourceClass() == "org.kexi-project.query")) { + if (m_connection->querySchema(kodata->sourceName())) { + m_source = m_connection->selectStatement(*(m_connection->querySchema(kodata->sourceName()))); + } } } diff --git a/libs/koreport/common/KoReportData.h b/libs/koreport/common/KoReportData.h --- a/libs/koreport/common/KoReportData.h +++ b/libs/koreport/common/KoReportData.h @@ -81,6 +81,9 @@ //!Return the name of this source virtual QString sourceName() const; + //! @return the class name of this source + virtual QString sourceClass() const; + //!Sets the sorting for the data //!Should be called before open() so that the data source can be edited accordingly //!Default impl does nothing diff --git a/libs/koreport/common/KoReportData.cpp b/libs/koreport/common/KoReportData.cpp --- a/libs/koreport/common/KoReportData.cpp +++ b/libs/koreport/common/KoReportData.cpp @@ -38,6 +38,11 @@ return QString(); } +QString KoReportData::sourceClass() const +{ + return QString(); +} + void KoReportData::setSorting(const QList &sorting) { Q_UNUSED(sorting); 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 @@ -51,11 +51,6 @@ ORODocument *document(); - /** - @brief Set the name of the report so that it can be used internally by the script engine - */ - void setName(const QString &); - bool isValid() const; const KoReportReportData *reportData() const; 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 @@ -651,11 +651,6 @@ delete d; } -void KoReportPreRenderer::setName(const QString &n) -{ - d->m_reportData->setName(n); -} - ORODocument* KoReportPreRenderer::document() { return d->m_document; 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 @@ -375,13 +375,10 @@ void KoReportDesigner::setReportData(KoReportData* kodata) { - //kDebug(); - if (kodata) { - m_kordata = kodata; - slotPageButton_Pressed(); - setModified(true); - emit reportDataChanged(); - } + m_kordata = kodata; + slotPageButton_Pressed(); + setModified(true); + emit reportDataChanged(); } ReportSection * KoReportDesigner::section(KRSectionData::Section s) const