diff --git a/examples/KReportExampleData.h b/examples/KReportExampleData.h --- a/examples/KReportExampleData.h +++ b/examples/KReportExampleData.h @@ -20,18 +20,18 @@ #ifndef KREPORTEXAMPLEDATA_H #define KREPORTEXAMPLEDATA_H -#include +#include #include #include #include -class KReportExampleData : public KReportData +class KReportExampleData : public KReportDataSource { public: KReportExampleData(); ~KReportExampleData(); virtual QVariant value(const QString& field) const; - virtual QVariant value(unsigned int) const; + virtual QVariant value(int) const; virtual QStringList fieldNames() const; virtual QStringList fieldKeys() const; virtual int fieldNumber(const QString& field) const; @@ -46,6 +46,8 @@ virtual QStringList scriptList() const; virtual QString scriptCode(const QString &script) const; + + virtual QStringList dataSourceNames() const; private: struct Data diff --git a/examples/KReportExampleData.cpp b/examples/KReportExampleData.cpp --- a/examples/KReportExampleData.cpp +++ b/examples/KReportExampleData.cpp @@ -41,7 +41,7 @@ return value(fieldNumber(field)); } -QVariant KReportExampleData::value(unsigned int f) const +QVariant KReportExampleData::value(int f) const { switch(f) { case 0: @@ -190,3 +190,8 @@ return scriptcode; } + +QStringList KReportExampleData::dataSourceNames() const +{ + return QStringList(); +} diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -21,7 +21,7 @@ common/KReportPluginManager.cpp common/KReportJsonTrader_p.cpp common/KReportPluginMetaData.cpp - common/KReportData.cpp + common/KReportDataSource.cpp common/KReportUtils.cpp common/KReportPageSize.cpp common/KReportUnit.cpp @@ -254,7 +254,7 @@ RELATIVE common HEADER_NAMES KReportPageSize - KReportData + KReportDataSource KReportItemBase KReportItemLine KReportPluginMetaData diff --git a/src/common/KReportData.h b/src/common/KReportDataSource.h rename from src/common/KReportData.h rename to src/common/KReportDataSource.h --- a/src/common/KReportData.h +++ b/src/common/KReportDataSource.h @@ -25,12 +25,12 @@ /** @brief Abstraction of report data source */ -class KREPORT_EXPORT KReportData +class KREPORT_EXPORT KReportDataSource { public: - KReportData(); - virtual ~KReportData(); + KReportDataSource(); + virtual ~KReportDataSource(); //! Describes sorting for single field /*! By default the order is ascending. */ @@ -87,7 +87,7 @@ virtual QStringList fieldKeys() const; //! Return the value of the field at the given position for the current record - virtual QVariant value(unsigned int) const = 0; + virtual QVariant value(int) const = 0; //! Return the value of the field fir the given name for the current record virtual QVariant value(const QString &field) const = 0; @@ -104,7 +104,7 @@ virtual void setSorting(const QList &sorting); //! Adds an expression to the data source - virtual void addExpression(const QString &field, const QVariant &value, char relation = '='); + virtual void addCondition(const QString &field, const QVariant &value, char relation = '='); //! Utility Functions //! @todo These are probably eligable to be moved into a new class @@ -118,20 +118,22 @@ virtual QString scriptCode(const QString& script) const; #endif - //! Return a list of data sources possible for advanced controls - virtual QStringList dataSources() const; + //! Return a list of data source names available for this data source + //! Works after the source is opened + virtual QStringList dataSourceNames() const = 0; - //! Return a list of data source names possible for advanced controls. - //! Returns dataSources() by default - virtual QStringList dataSourceNames() const; + //! Return data source caption for specified @a dataSourceName + //! It is possibly translated. As such it is suitable for use in GUIs. + //! Default implementation just returns @a dataSourceName. + virtual QString dataSourceCaption(const QString &dataSourceName) const; //! Creates a new instance with data source. Default implementation returns @c nullptr. //! @a source is implementation-specific identifier. //! Owner of the returned pointer is the caller. - virtual KReportData* create(const QString &source) const Q_REQUIRED_RESULT; + virtual KReportDataSource* create(const QString &source) const Q_REQUIRED_RESULT; private: - Q_DISABLE_COPY(KReportData) + Q_DISABLE_COPY(KReportDataSource) class Private; Private * const d; }; diff --git a/src/common/KReportData.cpp b/src/common/KReportDataSource.cpp rename from src/common/KReportData.cpp rename to src/common/KReportDataSource.cpp --- a/src/common/KReportData.cpp +++ b/src/common/KReportDataSource.cpp @@ -15,12 +15,12 @@ * License along with this library. If not, see . */ -#include "KReportData.h" +#include "KReportDataSource.h" #include #define KReportDataSortedFieldPrivateArgs(o) std::tie(o.field, o.order) -class KReportData::SortedField::Private +class KReportDataSource::SortedField::Private { public: @@ -32,131 +32,131 @@ Qt::SortOrder order = Qt::AscendingOrder; }; -class KReportData::Private +class KReportDataSource::Private { public: bool dummy = true; }; //==========KReportData::SortedField========== -KReportData::SortedField::SortedField() +KReportDataSource::SortedField::SortedField() : d(new Private) { } -KReportData::SortedField::SortedField(const KReportData::SortedField& other) : d(new Private(*other.d)) +KReportDataSource::SortedField::SortedField(const KReportDataSource::SortedField& other) : d(new Private(*other.d)) { } -KReportData::SortedField::~SortedField() +KReportDataSource::SortedField::~SortedField() { delete d; } -KReportData::SortedField & KReportData::SortedField::operator=(const KReportData::SortedField& other) +KReportDataSource::SortedField & KReportDataSource::SortedField::operator=(const KReportDataSource::SortedField& other) { if (this != &other) { setField(other.field()); setOrder(other.order()); } return *this; } -bool KReportData::SortedField::operator==(const KReportData::SortedField& other) const +bool KReportDataSource::SortedField::operator==(const KReportDataSource::SortedField& other) const { return KReportDataSortedFieldPrivateArgs((*d)) == KReportDataSortedFieldPrivateArgs((*other.d)); } -bool KReportData::SortedField::operator!=(const KReportData::SortedField& other) const +bool KReportDataSource::SortedField::operator!=(const KReportDataSource::SortedField& other) const { return KReportDataSortedFieldPrivateArgs((*d)) != KReportDataSortedFieldPrivateArgs((*other.d)); } -QString KReportData::SortedField::field() const +QString KReportDataSource::SortedField::field() const { return d->field; } -Qt::SortOrder KReportData::SortedField::order() const +Qt::SortOrder KReportDataSource::SortedField::order() const { return d->order; } -void KReportData::SortedField::setField(const QString& field) +void KReportDataSource::SortedField::setField(const QString& field) { d->field = field; } -void KReportData::SortedField::setOrder(Qt::SortOrder order) +void KReportDataSource::SortedField::setOrder(Qt::SortOrder order) { d->order = order; } //==========KReportData========== -KReportData::KReportData() : d(new Private()) +KReportDataSource::KReportDataSource() : d(new Private()) { } -KReportData::~KReportData() +KReportDataSource::~KReportDataSource() { delete d; } -QStringList KReportData::fieldKeys() const +QStringList KReportDataSource::fieldKeys() const { return fieldNames(); } -QString KReportData::sourceName() const +QString KReportDataSource::sourceName() const { return QString(); } -QString KReportData::sourceClass() const +QString KReportDataSource::sourceClass() const { return QString(); } -void KReportData::setSorting(const QList &sorting) +void KReportDataSource::setSorting(const QList &sorting) { Q_UNUSED(sorting); } -void KReportData::addExpression(const QString &field, const QVariant &value, char relation) +void KReportDataSource::addCondition(const QString &field, const QVariant &value, char relation) { Q_UNUSED(field); Q_UNUSED(value); Q_UNUSED(relation); } #ifdef KREPORT_SCRIPTING -QStringList KReportData::scriptList() const +QStringList KReportDataSource::scriptList() const { return QStringList(); } -QString KReportData::scriptCode(const QString &script) const +QString KReportDataSource::scriptCode(const QString &script) const { Q_UNUSED(script); return QString(); } #endif -QStringList KReportData::dataSources() const +QStringList KReportDataSource::dataSourceNames() const { return QStringList(); } -QStringList KReportData::dataSourceNames() const +QString KReportDataSource::dataSourceCaption(const QString &dataSourceName) const { - return dataSources(); + return dataSourceName; } -KReportData* KReportData::create(const QString &source) const +KReportDataSource* KReportDataSource::create(const QString &source) const { Q_UNUSED(source); return 0; diff --git a/src/common/KReportDetailSectionData.h b/src/common/KReportDetailSectionData.h --- a/src/common/KReportDetailSectionData.h +++ b/src/common/KReportDetailSectionData.h @@ -21,7 +21,7 @@ #include -#include "KReportData.h" +#include "KReportDataSource.h" class KReportSectionData; class KReportDetailGroupSectionData; @@ -46,7 +46,7 @@ QString m_name; int m_pageBreak; - QList m_sortedFields; + QList m_sortedFields; KReportSectionData * m_detailSection; diff --git a/src/common/KReportDetailSectionData.cpp b/src/common/KReportDetailSectionData.cpp --- a/src/common/KReportDetailSectionData.cpp +++ b/src/common/KReportDetailSectionData.cpp @@ -90,7 +90,7 @@ } } m_groupList.append(dgsd); - KReportData::SortedField s; + KReportDataSource::SortedField s; s.setField(dgsd->m_column); s.setOrder(dgsd->m_sort); m_sortedFields.append(s); diff --git a/src/common/KReportItemBase.h b/src/common/KReportItemBase.h --- a/src/common/KReportItemBase.h +++ b/src/common/KReportItemBase.h @@ -29,7 +29,7 @@ class OROPage; class OROSection; class KReportSize; -class KReportData; +class KReportDataSource; class KReportLineStyle; #ifdef KREPORT_SCRIPTING @@ -90,7 +90,7 @@ @brief Render a complex item that uses a sub query as a data source @return the height required by the object */ - virtual int renderReportData(OROPage *page, OROSection *section, const QPointF &offset, KReportData *data, KReportScriptHandler *script); + virtual int renderReportData(OROPage *page, OROSection *section, const QPointF &offset, KReportDataSource *data, KReportScriptHandler *script); /** @brief Override if the item supports a simple data source, such as a field diff --git a/src/common/KReportItemBase.cpp b/src/common/KReportItemBase.cpp --- a/src/common/KReportItemBase.cpp +++ b/src/common/KReportItemBase.cpp @@ -116,7 +116,7 @@ } int KReportItemBase::renderReportData(OROPage *page, OROSection *section, const QPointF &offset, - KReportData *data, KReportScriptHandler* script) + KReportDataSource *data, KReportScriptHandler* script) { Q_UNUSED(page) Q_UNUSED(section) diff --git a/src/common/KReportRenderObjects.h b/src/common/KReportRenderObjects.h --- a/src/common/KReportRenderObjects.h +++ b/src/common/KReportRenderObjects.h @@ -29,7 +29,7 @@ #include #include -#include "KReportData.h" +#include "KReportDataSource.h" #include "KReportItemBase.h" #include "KReportSectionData.h" #include "KReportLineStyle.h" diff --git a/src/plugins/web/KReportItemWeb.h b/src/plugins/web/KReportItemWeb.h --- a/src/plugins/web/KReportItemWeb.h +++ b/src/plugins/web/KReportItemWeb.h @@ -22,7 +22,7 @@ #define KREPORTITEMWEB_H #include "KReportAsyncItemBase.h" -#include "KReportData.h" +#include "KReportDataSource.h" #include #include diff --git a/src/renderer/KReportOneRecordData_p.h b/src/renderer/KReportOneRecordData_p.h --- a/src/renderer/KReportOneRecordData_p.h +++ b/src/renderer/KReportOneRecordData_p.h @@ -22,7 +22,7 @@ #ifndef KREPORTONERECORDDATA_H #define KREPORTONERECORDDATA_H -#include +#include namespace KReportPrivate { /** @@ -34,13 +34,13 @@ * a report with a static page of data, or a report page * generated from a script only. */ -class OneRecordData : public KReportData +class OneRecordData : public KReportDataSource { public: OneRecordData(); ~OneRecordData(); virtual QVariant value(const QString& field) const; - virtual QVariant value(unsigned int fieldNum) const; + virtual QVariant value(int fieldNum) const; virtual QStringList fieldNames() const; virtual int fieldNumber(const QString& field) const; virtual qint64 recordCount() const; @@ -51,6 +51,7 @@ virtual bool moveNext(); virtual bool close(); virtual bool open(); + virtual QStringList dataSourceNames() const; }; } diff --git a/src/renderer/KReportOneRecordData_p.cpp b/src/renderer/KReportOneRecordData_p.cpp --- a/src/renderer/KReportOneRecordData_p.cpp +++ b/src/renderer/KReportOneRecordData_p.cpp @@ -38,7 +38,7 @@ return QVariant(); } -QVariant OneRecordData::value(unsigned int fieldNum) const +QVariant OneRecordData::value(int fieldNum) const { Q_UNUSED(fieldNum); return QVariant(); @@ -95,4 +95,9 @@ return true; } -} \ No newline at end of file +QStringList OneRecordData::dataSourceNames() const +{ + return QStringList(); +} + +} diff --git a/src/renderer/KReportPreRenderer.h b/src/renderer/KReportPreRenderer.h --- a/src/renderer/KReportPreRenderer.h +++ b/src/renderer/KReportPreRenderer.h @@ -31,7 +31,7 @@ #endif class KReportPreRendererPrivate; class ORODocument; -class KReportData; +class KReportDataSource; class KReportDocument; class QDomElement; @@ -49,7 +49,7 @@ virtual ~KReportPreRenderer(); //! Sets source data to @a data, takes ownership - void setSourceData(KReportData* data); + void setSourceData(KReportDataSource* data); #ifdef KREPORT_SCRIPTING KReportScriptHandler *scriptHandler(); diff --git a/src/renderer/KReportPreRenderer.cpp b/src/renderer/KReportPreRenderer.cpp --- a/src/renderer/KReportPreRenderer.cpp +++ b/src/renderer/KReportPreRenderer.cpp @@ -22,7 +22,7 @@ #include "KReportOneRecordData_p.h" #include "KReportRenderObjects.h" -#include "KReportData.h" +#include "KReportDataSource.h" #include "KReportItemBase.h" #include "KReportDocument.h" #include "KReportDetailSectionData.h" @@ -529,7 +529,7 @@ KReportDetailSectionData * detailData = m_reportDocument->m_detailSection; if (detailData->m_detailSection) { - KReportData *mydata = m_kodata; + KReportDataSource *mydata = m_kodata; if (mydata && mydata->recordCount() > 0) { /* && !((query = orqThis->getQuery())->eof()))*/ if (!mydata->moveFirst()) { @@ -655,7 +655,7 @@ return d->m_document; } -void KReportPreRenderer::setSourceData(KReportData *data) +void KReportPreRenderer::setSourceData(KReportDataSource *data) { if (d && data != d->m_kodata) { delete d->m_kodata; diff --git a/src/renderer/KReportPreRenderer_p.h b/src/renderer/KReportPreRenderer_p.h --- a/src/renderer/KReportPreRenderer_p.h +++ b/src/renderer/KReportPreRenderer_p.h @@ -59,7 +59,7 @@ qreal m_maxWidth; // -- same as above -- int m_pageCounter; // what page are we currently on? - KReportData* m_kodata; + KReportDataSource* m_kodata; KReportPrivate::OneRecordData *m_oneRecord; QList m_postProcText; diff --git a/src/renderer/scripting/KReportScriptHandler.h b/src/renderer/scripting/KReportScriptHandler.h --- a/src/renderer/scripting/KReportScriptHandler.h +++ b/src/renderer/scripting/KReportScriptHandler.h @@ -23,7 +23,7 @@ #ifdef KREPORT_SCRIPTING #include "KReportScriptConstants.h" -#include "KReportData.h" +#include "KReportDataSource.h" #include class KReportScriptDebug; @@ -43,7 +43,7 @@ { Q_OBJECT public: - KReportScriptHandler(const KReportData *, KReportDocument*); + KReportScriptHandler(const KReportDataSource *, KReportDocument*); ~KReportScriptHandler(); QVariant evaluate(const QString&); diff --git a/src/renderer/scripting/KReportScriptHandler.cpp b/src/renderer/scripting/KReportScriptHandler.cpp --- a/src/renderer/scripting/KReportScriptHandler.cpp +++ b/src/renderer/scripting/KReportScriptHandler.cpp @@ -43,7 +43,7 @@ KReportScriptDebug *debug; KReportScriptDraw *draw; Scripting::Report *report; - const KReportData *reportData; + const KReportDataSource *reportData; QString source; KReportDocument *reportDocument; QJSEngine engine; @@ -60,7 +60,7 @@ { } -KReportScriptHandler::KReportScriptHandler(const KReportData* kodata, KReportDocument* doc) : d(new Private()) +KReportScriptHandler::KReportScriptHandler(const KReportDataSource* kodata, KReportDocument* doc) : d(new Private()) { d->reportDocument = doc; d->reportData = kodata; diff --git a/src/wrtembed/KReportDesigner.h b/src/wrtembed/KReportDesigner.h --- a/src/wrtembed/KReportDesigner.h +++ b/src/wrtembed/KReportDesigner.h @@ -22,7 +22,7 @@ #include #include "KReportDocument.h" -#include "KReportData.h" +#include "KReportDataSource.h" class KProperty; class KPropertySet; @@ -72,15 +72,15 @@ @brief Sets the report data The report data interface contains functions to retrieve data and information about the fields. - @param kodata Pointer to KReportData instance, ownership is transferred + @param kodata Pointer to KReportDataSource instance, ownership is transferred */ - void setReportData(KReportData* kodata); + void setReportData(KReportDataSource* kodata); /** @brief Return a pointer to the reports data @return Pointer to report data */ - KReportData *reportData() const; + KReportDataSource *reportData() const; /** @brief Return a pointer to the section specified diff --git a/src/wrtembed/KReportDesigner.cpp b/src/wrtembed/KReportDesigner.cpp --- a/src/wrtembed/KReportDesigner.cpp +++ b/src/wrtembed/KReportDesigner.cpp @@ -182,7 +182,7 @@ QString originalInterpreter; //Value of the script interpreter at load time QString originalScript; //Value of the script at load time - KReportData *kordata = nullptr; + KReportDataSource *kordata = nullptr; }; KReportDesigner::KReportDesigner(QWidget * parent) @@ -441,7 +441,7 @@ (void)se.exec(); } -void KReportDesigner::setReportData(KReportData* kodata) +void KReportDesigner::setReportData(KReportDataSource* kodata) { if (d->kordata == kodata) { return; @@ -648,7 +648,7 @@ return d->itmset; } -KReportData *KReportDesigner::reportData() const +KReportDataSource *KReportDesigner::reportData() const { return d->kordata; }