diff --git a/limereport/lrscriptenginemanager.cpp b/limereport/lrscriptenginemanager.cpp index 30cd800..3c16fbb 100644 --- a/limereport/lrscriptenginemanager.cpp +++ b/limereport/lrscriptenginemanager.cpp @@ -353,7 +353,7 @@ void ScriptEngineManager::setDataManager(DataSourceManager *dataManager){ ); addFunction(describer); } - + moveQObjectToScript(new DatasourceFunctions(dataManager), LimeReport::Const::DATAFUNCTIONS_MANAGER_NAME); } } } @@ -564,6 +564,9 @@ void ScriptEngineManager::clearTableOfContents(){ ScriptValueType ScriptEngineManager::moveQObjectToScript(QObject* object, const QString objectName) { + + ScriptValueType obj = scriptEngine()->globalObject().property(objectName); + if (!obj.isNull()) delete obj.toQObject(); ScriptValueType result = scriptEngine()->newQObject(object); scriptEngine()->globalObject().setProperty(objectName, result); return result; @@ -866,7 +869,6 @@ ScriptEngineManager::ScriptEngineManager() m_scriptEngine->setDefaultPrototype(qMetaTypeId(), m_scriptEngine->newQObject(new ComboBoxPrototype())); #endif - createLineFunction(); createNumberFomatFunction(); createDateFormatFunction(); @@ -1786,8 +1788,6 @@ void LimeReport::TableOfContents::clear(){ } -//#ifdef USE_QJSENGINE - QObject* ComboBoxWrapperCreator::createWrapper(QObject *item) { QComboBox* comboBox = dynamic_cast(item); @@ -1797,7 +1797,19 @@ QObject* ComboBoxWrapperCreator::createWrapper(QObject *item) return 0; } -//#endif +bool DatasourceFunctions::next(const QString &datasourceName){ + if (m_dataManager && m_dataManager->dataSource(datasourceName)) + return m_dataManager->dataSource(datasourceName)->next(); + return false; +} + +bool DatasourceFunctions::isEOF(const QString &datasourceName) +{ + if (m_dataManager && m_dataManager->dataSource(datasourceName)) + return m_dataManager->dataSource(datasourceName)->eof(); + return false; +} + #ifndef USE_QJSENGINE void ComboBoxPrototype::addItem(const QString &text) diff --git a/limereport/lrscriptenginemanager.h b/limereport/lrscriptenginemanager.h index 076ee21..30c5d38 100644 --- a/limereport/lrscriptenginemanager.h +++ b/limereport/lrscriptenginemanager.h @@ -52,6 +52,8 @@ #include "lrscriptenginemanagerintf.h" #include "lrcallbackdatasourceintf.h" #include "lrcollection.h" +#include "lrdatasourceintf.h" +#include "lrdatasourcemanagerintf.h" namespace LimeReport{ @@ -296,6 +298,16 @@ private: QObject* createWrapper(QObject* item); }; +class DatasourceFunctions : public QObject{ + Q_OBJECT +public: + explicit DatasourceFunctions(IDataSourceManager* dataManager): m_dataManager(dataManager){} + Q_INVOKABLE bool next(const QString& datasourceName); + Q_INVOKABLE bool isEOF(const QString& datasourceName); +private: + IDataSourceManager* m_dataManager; +}; + class ScriptFunctionsManager : public QObject{ Q_OBJECT public: