From e5a0d2943d5a27e80894066df8c92deb197c12bb Mon Sep 17 00:00:00 2001 From: Arin Alexander Date: Thu, 24 Jan 2019 22:10:15 +0300 Subject: [PATCH 1/3] IDataSource extracted to own file --- include/lrdatasourcemanagerintf.h | 6 ++- limereport/limereport.pri | 1 + limereport/limereport.pro | 1 + limereport/lrdatadesignintf.h | 69 ++++++++++++++-------------- limereport/lrdatasourceintf.h | 47 +++++++++++++++++++ limereport/lrdatasourcemanager.h | 1 + limereport/lrdatasourcemanagerintf.h | 6 ++- 7 files changed, 95 insertions(+), 36 deletions(-) create mode 100644 limereport/lrdatasourceintf.h diff --git a/include/lrdatasourcemanagerintf.h b/include/lrdatasourcemanagerintf.h index f86e51e..a10cb05 100644 --- a/include/lrdatasourcemanagerintf.h +++ b/include/lrdatasourcemanagerintf.h @@ -32,6 +32,7 @@ #include "lrcallbackdatasourceintf.h" #include "lrglobal.h" +#include "lrdatasourceintf.h" class QVariant; class QString; @@ -40,12 +41,14 @@ namespace LimeReport{ class IDbCredentialsProvider{ public: + virtual ~IDbCredentialsProvider(){} virtual QString getUserName(const QString& connectionName) = 0; virtual QString getPassword(const QString& connectionName) = 0; }; class IDataSourceManager{ public: + virtual ~IDataSourceManager(){} virtual void setReportVariable(const QString& name, const QVariant& value) = 0; virtual void setDefaultDatabasePath(const QString &defaultDatabasePath) = 0; virtual void deleteVariable(const QString& name) = 0; @@ -57,12 +60,13 @@ public: virtual void clearUserVariables()=0; virtual ICallbackDatasource* createCallbackDatasource(const QString& name) = 0; virtual void registerDbCredentialsProvider(IDbCredentialsProvider* provider) = 0; - virtual QStringList variableNames() = 0; virtual bool variableIsMandatory(const QString& name) = 0; virtual VariableDataType variableDataType(const QString& name) = 0; virtual bool variableIsSystem(const QString& name) = 0; + virtual IDataSource* dataSource(const QString& name) = 0; }; } #endif // LRDATASOURCEMANAGERINTF_H + diff --git a/limereport/limereport.pri b/limereport/limereport.pri index 5e086a7..bc752e2 100644 --- a/limereport/limereport.pri +++ b/limereport/limereport.pri @@ -131,6 +131,7 @@ HEADERS += \ $$REPORT_PATH/lrvariablesholder.h \ $$REPORT_PATH/lrgroupfunctions.h \ $$REPORT_PATH/lrreportengine.h \ + $$REPORT_PATH/lrdatasourceintf.h \ $$REPORT_PATH/lrdatasourcemanagerintf.h \ $$REPORT_PATH/lrscriptenginemanagerintf.h \ $$REPORT_PATH/lrsimplecrypt.h \ diff --git a/limereport/limereport.pro b/limereport/limereport.pro index 3c324b0..f790982 100644 --- a/limereport/limereport.pro +++ b/limereport/limereport.pro @@ -34,6 +34,7 @@ contains(CONFIG, staticlib){ EXTRA_FILES += \ $$PWD/lrglobal.h \ + $$PWD/lrdatasourceintf.h \ $$PWD/lrdatasourcemanagerintf.h \ $$PWD/lrreportengine.h \ $$PWD/lrscriptenginemanagerintf.h \ diff --git a/limereport/lrdatadesignintf.h b/limereport/lrdatadesignintf.h index 2336ad5..85d7957 100644 --- a/limereport/lrdatadesignintf.h +++ b/limereport/lrdatadesignintf.h @@ -40,46 +40,47 @@ #include #include "lrcollection.h" #include "lrcallbackdatasourceintf.h" +#include "lrdatasourceintf.h" namespace LimeReport{ class DataSourceManager; -class IDataSource { -public: - enum DatasourceMode{DESIGN_MODE,RENDER_MODE}; - typedef QSharedPointer Ptr; - virtual ~IDataSource(){} - virtual bool next() = 0; - virtual bool hasNext() = 0; - virtual bool prior() = 0; - virtual void first() = 0; - virtual void last() = 0; - virtual bool bof() = 0; - virtual bool eof() = 0; - virtual QVariant data(const QString& columnName) = 0; - virtual QVariant dataByKeyField(const QString& columnName, const QString& keyColumnName, QVariant keyData) = 0; - virtual int columnCount() = 0; - virtual QString columnNameByIndex(int columnIndex) = 0; - virtual int columnIndexByName(QString name) = 0; - virtual bool isInvalid() const = 0; - virtual QString lastError() = 0; - virtual QAbstractItemModel* model() = 0; -}; +//class IDataSource { +//public: +// enum DatasourceMode{DESIGN_MODE,RENDER_MODE}; +// typedef QSharedPointer Ptr; +// virtual ~IDataSource(){} +// virtual bool next() = 0; +// virtual bool hasNext() = 0; +// virtual bool prior() = 0; +// virtual void first() = 0; +// virtual void last() = 0; +// virtual bool bof() = 0; +// virtual bool eof() = 0; +// virtual QVariant data(const QString& columnName) = 0; +// virtual QVariant dataByKeyField(const QString& columnName, const QString& keyColumnName, QVariant keyData) = 0; +// virtual int columnCount() = 0; +// virtual QString columnNameByIndex(int columnIndex) = 0; +// virtual int columnIndexByName(QString name) = 0; +// virtual bool isInvalid() const = 0; +// virtual QString lastError() = 0; +// virtual QAbstractItemModel* model() = 0; +//}; -class IDataSourceHolder { -public: - virtual IDataSource* dataSource(IDataSource::DatasourceMode mode = IDataSource::RENDER_MODE) = 0; - virtual QString lastError() const = 0; - virtual bool isInvalid() const = 0; - virtual bool isOwned() const = 0; - virtual bool isEditable() const = 0; - virtual bool isRemovable() const = 0; - virtual void invalidate(IDataSource::DatasourceMode mode, bool dbWillBeClosed = false) = 0; - virtual void update() = 0; - virtual void clearErrors() = 0; - virtual ~IDataSourceHolder(){} -}; +//class IDataSourceHolder { +//public: +// virtual IDataSource* dataSource(IDataSource::DatasourceMode mode = IDataSource::RENDER_MODE) = 0; +// virtual QString lastError() const = 0; +// virtual bool isInvalid() const = 0; +// virtual bool isOwned() const = 0; +// virtual bool isEditable() const = 0; +// virtual bool isRemovable() const = 0; +// virtual void invalidate(IDataSource::DatasourceMode mode, bool dbWillBeClosed = false) = 0; +// virtual void update() = 0; +// virtual void clearErrors() = 0; +// virtual ~IDataSourceHolder(){} +//}; class ModelHolder: public QObject, public IDataSourceHolder{ Q_OBJECT diff --git a/limereport/lrdatasourceintf.h b/limereport/lrdatasourceintf.h new file mode 100644 index 0000000..c2a6c90 --- /dev/null +++ b/limereport/lrdatasourceintf.h @@ -0,0 +1,47 @@ +#ifndef LRDATASOURCEINTF_H +#define LRDATASOURCEINTF_H +#include +#include +namespace LimeReport { + +class IDataSource { +public: + enum DatasourceMode{DESIGN_MODE,RENDER_MODE}; + typedef QSharedPointer Ptr; + virtual ~IDataSource() {} + virtual bool next() = 0; + virtual bool hasNext() = 0; + virtual bool prior() = 0; + virtual void first() = 0; + virtual void last() = 0; + virtual bool bof() = 0; + virtual bool eof() = 0; + virtual QVariant data(const QString& columnName) = 0; + virtual QVariant dataByKeyField(const QString& columnName, const QString& keyColumnName, QVariant keyData) = 0; + virtual int columnCount() = 0; + virtual QString columnNameByIndex(int columnIndex) = 0; + virtual int columnIndexByName(QString name) = 0; + virtual bool isInvalid() const = 0; + virtual QString lastError() = 0; + virtual QAbstractItemModel* model() = 0; +}; + +class IDataSourceHolder { +public: + virtual ~IDataSourceHolder(){} + virtual IDataSource* dataSource(IDataSource::DatasourceMode mode = IDataSource::RENDER_MODE) = 0; + virtual QString lastError() const = 0; + virtual bool isInvalid() const = 0; + virtual bool isOwned() const = 0; + virtual bool isEditable() const = 0; + virtual bool isRemovable() const = 0; + virtual void invalidate(IDataSource::DatasourceMode mode, bool dbWillBeClosed = false) = 0; + virtual void update() = 0; + virtual void clearErrors() = 0; +}; + +} // namespace LimeReport + +#endif // LRDATASOURCEINTF_H + + diff --git a/limereport/lrdatasourcemanager.h b/limereport/lrdatasourcemanager.h index 628a5f5..74dfe20 100644 --- a/limereport/lrdatasourcemanager.h +++ b/limereport/lrdatasourcemanager.h @@ -38,6 +38,7 @@ #include "lrvariablesholder.h" #include "lrgroupfunctions.h" #include "lrdatasourcemanagerintf.h" +#include "lrdatasourceintf.h" namespace LimeReport{ diff --git a/limereport/lrdatasourcemanagerintf.h b/limereport/lrdatasourcemanagerintf.h index f86e51e..a10cb05 100644 --- a/limereport/lrdatasourcemanagerintf.h +++ b/limereport/lrdatasourcemanagerintf.h @@ -32,6 +32,7 @@ #include "lrcallbackdatasourceintf.h" #include "lrglobal.h" +#include "lrdatasourceintf.h" class QVariant; class QString; @@ -40,12 +41,14 @@ namespace LimeReport{ class IDbCredentialsProvider{ public: + virtual ~IDbCredentialsProvider(){} virtual QString getUserName(const QString& connectionName) = 0; virtual QString getPassword(const QString& connectionName) = 0; }; class IDataSourceManager{ public: + virtual ~IDataSourceManager(){} virtual void setReportVariable(const QString& name, const QVariant& value) = 0; virtual void setDefaultDatabasePath(const QString &defaultDatabasePath) = 0; virtual void deleteVariable(const QString& name) = 0; @@ -57,12 +60,13 @@ public: virtual void clearUserVariables()=0; virtual ICallbackDatasource* createCallbackDatasource(const QString& name) = 0; virtual void registerDbCredentialsProvider(IDbCredentialsProvider* provider) = 0; - virtual QStringList variableNames() = 0; virtual bool variableIsMandatory(const QString& name) = 0; virtual VariableDataType variableDataType(const QString& name) = 0; virtual bool variableIsSystem(const QString& name) = 0; + virtual IDataSource* dataSource(const QString& name) = 0; }; } #endif // LRDATASOURCEMANAGERINTF_H + From eb9744932cde75d24d1cbf910a4e71c99ee956c6 Mon Sep 17 00:00:00 2001 From: Arin Alexander Date: Thu, 24 Jan 2019 23:48:01 +0300 Subject: [PATCH 2/3] Data source holder from now is accessible via IDataSourceManager --- include/lrdatasourcemanagerintf.h | 1 + limereport/lrdatadesignintf.h | 36 ---------------------------- limereport/lrdatasourcemanagerintf.h | 1 + 3 files changed, 2 insertions(+), 36 deletions(-) diff --git a/include/lrdatasourcemanagerintf.h b/include/lrdatasourcemanagerintf.h index a10cb05..040dd1d 100644 --- a/include/lrdatasourcemanagerintf.h +++ b/include/lrdatasourcemanagerintf.h @@ -65,6 +65,7 @@ public: virtual VariableDataType variableDataType(const QString& name) = 0; virtual bool variableIsSystem(const QString& name) = 0; virtual IDataSource* dataSource(const QString& name) = 0; + virtual IDataSourceHolder* dataSourceHolder(const QString& name) = 0; }; } diff --git a/limereport/lrdatadesignintf.h b/limereport/lrdatadesignintf.h index 85d7957..06edc3d 100644 --- a/limereport/lrdatadesignintf.h +++ b/limereport/lrdatadesignintf.h @@ -46,42 +46,6 @@ namespace LimeReport{ class DataSourceManager; -//class IDataSource { -//public: -// enum DatasourceMode{DESIGN_MODE,RENDER_MODE}; -// typedef QSharedPointer Ptr; -// virtual ~IDataSource(){} -// virtual bool next() = 0; -// virtual bool hasNext() = 0; -// virtual bool prior() = 0; -// virtual void first() = 0; -// virtual void last() = 0; -// virtual bool bof() = 0; -// virtual bool eof() = 0; -// virtual QVariant data(const QString& columnName) = 0; -// virtual QVariant dataByKeyField(const QString& columnName, const QString& keyColumnName, QVariant keyData) = 0; -// virtual int columnCount() = 0; -// virtual QString columnNameByIndex(int columnIndex) = 0; -// virtual int columnIndexByName(QString name) = 0; -// virtual bool isInvalid() const = 0; -// virtual QString lastError() = 0; -// virtual QAbstractItemModel* model() = 0; -//}; - -//class IDataSourceHolder { -//public: -// virtual IDataSource* dataSource(IDataSource::DatasourceMode mode = IDataSource::RENDER_MODE) = 0; -// virtual QString lastError() const = 0; -// virtual bool isInvalid() const = 0; -// virtual bool isOwned() const = 0; -// virtual bool isEditable() const = 0; -// virtual bool isRemovable() const = 0; -// virtual void invalidate(IDataSource::DatasourceMode mode, bool dbWillBeClosed = false) = 0; -// virtual void update() = 0; -// virtual void clearErrors() = 0; -// virtual ~IDataSourceHolder(){} -//}; - class ModelHolder: public QObject, public IDataSourceHolder{ Q_OBJECT public: diff --git a/limereport/lrdatasourcemanagerintf.h b/limereport/lrdatasourcemanagerintf.h index a10cb05..040dd1d 100644 --- a/limereport/lrdatasourcemanagerintf.h +++ b/limereport/lrdatasourcemanagerintf.h @@ -65,6 +65,7 @@ public: virtual VariableDataType variableDataType(const QString& name) = 0; virtual bool variableIsSystem(const QString& name) = 0; virtual IDataSource* dataSource(const QString& name) = 0; + virtual IDataSourceHolder* dataSourceHolder(const QString& name) = 0; }; } From f48e414114a9d49c4266b6243b96cf2893052de8 Mon Sep 17 00:00:00 2001 From: Arin Alexander Date: Wed, 30 Jan 2019 01:53:21 +0300 Subject: [PATCH 3/3] moveQObjectToScript() has been added to ScriptManager --- include/lrscriptenginemanagerintf.h | 2 ++ limereport/lrscriptenginemanager.cpp | 7 +++++++ limereport/lrscriptenginemanager.h | 2 +- limereport/lrscriptenginemanagerintf.h | 2 ++ 4 files changed, 12 insertions(+), 1 deletion(-) diff --git a/include/lrscriptenginemanagerintf.h b/include/lrscriptenginemanagerintf.h index 4c2767a..1d306bd 100644 --- a/include/lrscriptenginemanagerintf.h +++ b/include/lrscriptenginemanagerintf.h @@ -46,7 +46,9 @@ public: virtual bool addFunction(const QString &name, const QString& script, const QString &category="", const QString &description="") = 0; virtual const QString& lastError() const = 0; + virtual ScriptValueType moveQObjectToScript(QObject* object, const QString objectName) = 0; virtual ~IScriptEngineManager(){} + }; } //namespace LimeReport diff --git a/limereport/lrscriptenginemanager.cpp b/limereport/lrscriptenginemanager.cpp index ae3abad..30cd800 100644 --- a/limereport/lrscriptenginemanager.cpp +++ b/limereport/lrscriptenginemanager.cpp @@ -562,6 +562,13 @@ void ScriptEngineManager::clearTableOfContents(){ } } +ScriptValueType ScriptEngineManager::moveQObjectToScript(QObject* object, const QString objectName) +{ + ScriptValueType result = scriptEngine()->newQObject(object); + scriptEngine()->globalObject().setProperty(objectName, result); + return result; +} + void ScriptEngineManager::updateModel() { diff --git a/limereport/lrscriptenginemanager.h b/limereport/lrscriptenginemanager.h index 2241c85..076ee21 100644 --- a/limereport/lrscriptenginemanager.h +++ b/limereport/lrscriptenginemanager.h @@ -377,7 +377,7 @@ public: QVariant evaluateScript(const QString &script); void addTableOfContentsItem(const QString& uniqKey, const QString& content, int indent); void clearTableOfContents(); - + ScriptValueType moveQObjectToScript(QObject* object, const QString objectName); protected: void updateModel(); bool containsFunction(const QString &functionName); diff --git a/limereport/lrscriptenginemanagerintf.h b/limereport/lrscriptenginemanagerintf.h index 4c2767a..1d306bd 100644 --- a/limereport/lrscriptenginemanagerintf.h +++ b/limereport/lrscriptenginemanagerintf.h @@ -46,7 +46,9 @@ public: virtual bool addFunction(const QString &name, const QString& script, const QString &category="", const QString &description="") = 0; virtual const QString& lastError() const = 0; + virtual ScriptValueType moveQObjectToScript(QObject* object, const QString objectName) = 0; virtual ~IScriptEngineManager(){} + }; } //namespace LimeReport