From e0ef984fcaddac42e105bed494a056a75b0b4a37 Mon Sep 17 00:00:00 2001 From: Arin Alexander Date: Tue, 19 Feb 2019 02:23:53 +0300 Subject: [PATCH] Building for different script engine has been fixed --- common.pri | 1 + include/lrglobal.h | 24 +--------------- include/lrscriptenginemanagerintf.h | 36 ++++++++++++++++++++++-- limereport/items/lrtextitem.cpp | 3 -- limereport/lrglobal.h | 24 +--------------- limereport/lrreportengine.cpp | 7 ++++- limereport/lrreportrender.cpp | 7 ++--- limereport/lrscriptenginemanager.cpp | 39 ++++++++++++++++++++------ limereport/lrscriptenginemanager.h | 12 ++++---- limereport/lrscriptenginemanagerintf.h | 36 ++++++++++++++++++++++-- 10 files changed, 114 insertions(+), 75 deletions(-) diff --git a/common.pri b/common.pri index 3e4ae74..dca1d40 100644 --- a/common.pri +++ b/common.pri @@ -47,6 +47,7 @@ lessThan(QT_MAJOR_VERSION, 5){ contains(CONFIG, qtscriptengine){ CONFIG -= qjsengine QT *= script + DEFINES *= USE_QTSCRIPTENGINE message(qtscriptengine) } diff --git a/include/lrglobal.h b/include/lrglobal.h index a82998f..ba5a363 100644 --- a/include/lrglobal.h +++ b/include/lrglobal.h @@ -42,13 +42,6 @@ # define LIMEREPORT_EXPORT /**/ #endif -#ifdef USE_QJSENGINE -//#include -#include -#else -#include -#endif - namespace LimeReport { #ifdef __GNUC__ @@ -146,27 +139,12 @@ namespace Const{ virtual ~IPainterProxy(); }; -#ifdef HAVE_QT4 +#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0) typedef QStyleOptionViewItemV4 StyleOptionViewItem; #else typedef QStyleOptionViewItem StyleOptionViewItem; #endif -#ifdef USE_QJSENGINE - typedef QJSEngine ScriptEngineType; - typedef QJSValue ScriptValueType; - template - static inline QJSValue getJSValue(QJSEngine &e, T *p) - { - QJSValue res = e.newQObject(p); - QQmlEngine::setObjectOwnership(p, QQmlEngine::CppOwnership); - return res; - } -#else - typedef QScriptEngine ScriptEngineType; - typedef QScriptValue ScriptValueType; -#endif - #if QT_VERSION >= QT_VERSION_CHECK(5, 8, 0) Q_NAMESPACE #endif diff --git a/include/lrscriptenginemanagerintf.h b/include/lrscriptenginemanagerintf.h index 1d306bd..a8a7c63 100644 --- a/include/lrscriptenginemanagerintf.h +++ b/include/lrscriptenginemanagerintf.h @@ -29,17 +29,47 @@ ****************************************************************************/ #ifndef LRSCRIPTENGINEMANAGERINTF_H #define LRSCRIPTENGINEMANAGERINTF_H +#include "qglobal.h" -//#include -#include "lrglobal.h" +#if QT_VERSION >= QT_VERSION_CHECK(5, 6, 0) + #ifndef USE_QTSCRIPTENGINE + #ifndef USE_QJSENGINE + #define USE_QJSENGINE + #endif + #endif +#else + #ifndef USE_QTSCRIPTENGINE + #define USE_QTSCRIPTENGINE + #endif +#endif + +#ifdef USE_QJSENGINE +#include +#else +#include +#endif namespace LimeReport{ +#ifdef USE_QJSENGINE + typedef QJSEngine ScriptEngineType; + typedef QJSValue ScriptValueType; + template + static inline QJSValue getJSValue(QJSEngine &e, T *p) + { + QJSValue res = e.newQObject(p); + QQmlEngine::setObjectOwnership(p, QQmlEngine::CppOwnership); + return res; + } +#else + typedef QScriptEngine ScriptEngineType; + typedef QScriptValue ScriptValueType; +#endif class IScriptEngineManager{ public: virtual ScriptEngineType* scriptEngine() = 0; -#ifndef USE_QJSENGINE +#ifdef USE_QTSCRIPTENGINE virtual bool addFunction(const QString& name, ScriptEngineType::FunctionSignature function, const QString& category="", const QString& description="") = 0; #endif diff --git a/limereport/items/lrtextitem.cpp b/limereport/items/lrtextitem.cpp index ee729e8..6fca5b5 100644 --- a/limereport/items/lrtextitem.cpp +++ b/limereport/items/lrtextitem.cpp @@ -29,9 +29,6 @@ ****************************************************************************/ #include #include -#ifndef USE_QJSENGINE -#include -#endif #include #include #include diff --git a/limereport/lrglobal.h b/limereport/lrglobal.h index a82998f..ba5a363 100644 --- a/limereport/lrglobal.h +++ b/limereport/lrglobal.h @@ -42,13 +42,6 @@ # define LIMEREPORT_EXPORT /**/ #endif -#ifdef USE_QJSENGINE -//#include -#include -#else -#include -#endif - namespace LimeReport { #ifdef __GNUC__ @@ -146,27 +139,12 @@ namespace Const{ virtual ~IPainterProxy(); }; -#ifdef HAVE_QT4 +#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0) typedef QStyleOptionViewItemV4 StyleOptionViewItem; #else typedef QStyleOptionViewItem StyleOptionViewItem; #endif -#ifdef USE_QJSENGINE - typedef QJSEngine ScriptEngineType; - typedef QJSValue ScriptValueType; - template - static inline QJSValue getJSValue(QJSEngine &e, T *p) - { - QJSValue res = e.newQObject(p); - QQmlEngine::setObjectOwnership(p, QQmlEngine::CppOwnership); - return res; - } -#else - typedef QScriptEngine ScriptEngineType; - typedef QScriptValue ScriptValueType; -#endif - #if QT_VERSION >= QT_VERSION_CHECK(5, 8, 0) Q_NAMESPACE #endif diff --git a/limereport/lrreportengine.cpp b/limereport/lrreportengine.cpp index 9591c13..a17a911 100644 --- a/limereport/lrreportengine.cpp +++ b/limereport/lrreportengine.cpp @@ -1172,7 +1172,9 @@ ReportPages ReportEnginePrivate::renderToPages() } scriptContext()->qobjectToScript("engine",this); - +#ifdef USE_QTSCRIPTENGINE + ScriptEngineManager::instance().scriptEngine()->pushContext(); +#endif if (m_scriptEngineContext->runInitScript()){ dataManager()->clearErrors(); @@ -1230,6 +1232,9 @@ ReportPages ReportEnginePrivate::renderToPages() } m_reportRendering = false; //activateLanguage(QLocale::AnyLanguage); +#ifdef USE_QTSCRIPTENGINE + ScriptEngineManager::instance().scriptEngine()->popContext(); +#endif return result; } else { return ReportPages(); diff --git a/limereport/lrreportrender.cpp b/limereport/lrreportrender.cpp index 7c3ed0a..96f83f7 100644 --- a/limereport/lrreportrender.cpp +++ b/limereport/lrreportrender.cpp @@ -243,10 +243,6 @@ void ReportRender::renderPage(PageItemDesignIntf* patternPage, bool isTOC, bool savePage(true); -#ifndef USE_QJSENGINE - ScriptEngineManager::instance().scriptEngine()->popContext(); -#endif - } int ReportRender::pageCount() @@ -1422,7 +1418,8 @@ void ReportRender::savePage(bool isLast) moveTearOffBand(); m_scriptEngineContext->setCurrentPage(m_renderPageItem); emit m_patternPageItem->afterRender(); - if (isLast) emit m_patternPageItem->afterLastPageRendered(); + if (isLast) + emit m_patternPageItem->afterLastPageRendered(); if (isLast && m_patternPageItem->endlessHeight()){ qreal pageHeight = 0; foreach (BandDesignIntf* band, m_renderPageItem->bands()) { diff --git a/limereport/lrscriptenginemanager.cpp b/limereport/lrscriptenginemanager.cpp index c73b660..2689501 100644 --- a/limereport/lrscriptenginemanager.cpp +++ b/limereport/lrscriptenginemanager.cpp @@ -32,7 +32,7 @@ #include #include #include -#ifndef USE_QJSENGINE +#ifdef USE_QTSCRIPTENGINE #include #endif #include @@ -50,7 +50,7 @@ Q_DECLARE_METATYPE(QColor) Q_DECLARE_METATYPE(QFont) Q_DECLARE_METATYPE(LimeReport::ScriptEngineManager *) -#ifndef USE_QJSENGINE +#ifdef USE_QTSCRIPTENGINE QScriptValue constructColor(QScriptContext *context, QScriptEngine *engine) { QColor color(context->argument(0).toString()); @@ -278,7 +278,7 @@ bool ScriptEngineManager::containsFunction(const QString& functionName){ return false; } -#ifndef USE_QJSENGINE +#ifdef USE_QTSCRIPTENGINE #if QT_VERSION > 0x050600 Q_DECL_DEPRECATED #endif @@ -818,6 +818,23 @@ bool ScriptEngineManager::createGetFieldByKeyFunction() return addFunction(fd); } +bool ScriptEngineManager::createGetFieldByRowIndex() +{ + JSFunctionDesc fd; + fd.setManager(m_functionManager); + fd.setManagerName(LimeReport::Const::FUNCTION_MANAGER_NAME); + fd.setCategory(tr("GENERAL")); + fd.setName("getFieldByRowIndex"); + fd.setDescription("getFieldByRowIndex(\""+tr("FieldName")+"\", \""+ + tr("RowIndex")+"\")" + ); + fd.setScriptWrapper(QString("function getFieldByRowIndex(fieldName, rowIndex){" + "return %1.getFieldByRowIndex(fieldName, rowIndex);}" + ).arg(LimeReport::Const::FUNCTION_MANAGER_NAME) + ); + return addFunction(fd); +} + bool ScriptEngineManager::createAddTableOfContentsItemFunction() { JSFunctionDesc fd; @@ -869,7 +886,7 @@ ScriptEngineManager::ScriptEngineManager() m_scriptEngine = new ScriptEngineType; m_functionManager = new ScriptFunctionsManager(this); m_functionManager->setScriptEngineManager(this); -#ifndef USE_QJSENGINE +#ifdef USE_QTSCRIPTENGINE m_scriptEngine->setDefaultPrototype(qMetaTypeId(), m_scriptEngine->newQObject(new ComboBoxPrototype())); #endif @@ -887,9 +904,10 @@ ScriptEngineManager::ScriptEngineManager() #endif createSetVariableFunction(); createGetFieldFunction(); + createGetFieldByRowIndex(); createGetFieldByKeyFunction(); createGetVariableFunction(); -#ifndef USE_QJSENGINE +#ifdef USE_QTSCRIPTENGINE QScriptValue colorCtor = m_scriptEngine->newFunction(constructColor); m_scriptEngine->globalObject().setProperty("QColor", colorCtor); @@ -1362,9 +1380,6 @@ bool ScriptEngineContext::runInitScript(){ ScriptEngineManager::instance().setContext(this); m_tableOfContents->clear(); -#ifndef USE_QJSENGINE - engine->pushContext(); -#endif ScriptValueType res = engine->evaluate(initScript()); if (res.isBool()) return res.toBool(); #ifdef USE_QJSENGINE @@ -1595,6 +1610,12 @@ QVariant ScriptFunctionsManager::getFieldByKeyField(const QString& datasourceNam return dm->fieldDataByKey(datasourceName, valueFieldName, keyFieldName, keyValue); } +QVariant ScriptFunctionsManager::getFieldByRowIndex(const QString &fieldName, int rowIndex) +{ + DataSourceManager* dm = scriptEngineManager()->dataManager(); + return dm->fieldDataByRowIndex(fieldName, rowIndex); +} + void ScriptFunctionsManager::reopenDatasource(const QString& datasourceName) { DataSourceManager* dm = scriptEngineManager()->dataManager(); @@ -1923,7 +1944,7 @@ void TableBuilder::checkBaseLayout() } } -#ifndef USE_QJSENGINE +#ifdef USE_QTSCRIPTENGINE void ComboBoxPrototype::addItem(const QString &text) { QComboBox* comboBox = qscriptvalue_cast(thisObject()); diff --git a/limereport/lrscriptenginemanager.h b/limereport/lrscriptenginemanager.h index bb60dee..bcddffb 100644 --- a/limereport/lrscriptenginemanager.h +++ b/limereport/lrscriptenginemanager.h @@ -29,7 +29,7 @@ ****************************************************************************/ #ifndef LRSCRIPTENGINEMANAGER_H #define LRSCRIPTENGINEMANAGER_H -#ifndef USE_QJSENGINE +#ifdef USE_QTSCRIPTENGINE #include #include #endif @@ -272,7 +272,7 @@ private: QString m_scriptWrapper; }; -#ifndef USE_QJSENGINE +#ifdef USE_QTSCRIPTENGINE class ComboBoxPrototype : public QObject, public QScriptable{ Q_OBJECT public: @@ -363,6 +363,7 @@ public: Q_INVOKABLE QVariant getVariable(const QString& name); Q_INVOKABLE QVariant getField(const QString& field); Q_INVOKABLE QVariant getFieldByKeyField(const QString& datasourceName, const QString& valueFieldName, const QString& keyFieldName, QVariant keyValue); + Q_INVOKABLE QVariant getFieldByRowIndex(const QString& fieldName, int rowIndex); Q_INVOKABLE void reopenDatasource(const QString& datasourceName); Q_INVOKABLE QVariant color(const QString& color){ return QColor(color);} Q_INVOKABLE void addTableOfContentsItem(const QString& uniqKey, const QString& content, int indent = 0); @@ -399,7 +400,7 @@ public: void deleteFunction(const QString& functionsName); bool addFunction(const JSFunctionDesc& functionsDescriber); -#ifndef USE_QJSENGINE +#ifdef USE_QTSCRIPTENGINE bool addFunction(const QString &name, QScriptEngine::FunctionSignature function, const QString &category, const QString &description); #endif bool addFunction(const QString &name, const QString& script, @@ -438,6 +439,7 @@ private: bool createGetVariableFunction(); bool createGetFieldFunction(); bool createGetFieldByKeyFunction(); + bool createGetFieldByRowIndex(); bool createAddTableOfContentsItemFunction(); bool createClearTableOfContentsFunction(); bool createReopenDatasourceFunction(); @@ -483,7 +485,7 @@ private: }; -#ifndef USE_QJSENGINE +#ifdef USE_QTSCRIPTENGINE class QFontPrototype : public QObject, public QScriptable { Q_OBJECT Q_PROPERTY(QString family READ family) @@ -533,7 +535,7 @@ public: #endif } -#ifndef USE_QJSENGINE +#ifdef USE_QTSCRIPTENGINE Q_DECLARE_METATYPE(LimeReport::ComboBoxPrototype*) Q_DECLARE_METATYPE(QComboBox*) #endif diff --git a/limereport/lrscriptenginemanagerintf.h b/limereport/lrscriptenginemanagerintf.h index 1d306bd..a8a7c63 100644 --- a/limereport/lrscriptenginemanagerintf.h +++ b/limereport/lrscriptenginemanagerintf.h @@ -29,17 +29,47 @@ ****************************************************************************/ #ifndef LRSCRIPTENGINEMANAGERINTF_H #define LRSCRIPTENGINEMANAGERINTF_H +#include "qglobal.h" -//#include -#include "lrglobal.h" +#if QT_VERSION >= QT_VERSION_CHECK(5, 6, 0) + #ifndef USE_QTSCRIPTENGINE + #ifndef USE_QJSENGINE + #define USE_QJSENGINE + #endif + #endif +#else + #ifndef USE_QTSCRIPTENGINE + #define USE_QTSCRIPTENGINE + #endif +#endif + +#ifdef USE_QJSENGINE +#include +#else +#include +#endif namespace LimeReport{ +#ifdef USE_QJSENGINE + typedef QJSEngine ScriptEngineType; + typedef QJSValue ScriptValueType; + template + static inline QJSValue getJSValue(QJSEngine &e, T *p) + { + QJSValue res = e.newQObject(p); + QQmlEngine::setObjectOwnership(p, QQmlEngine::CppOwnership); + return res; + } +#else + typedef QScriptEngine ScriptEngineType; + typedef QScriptValue ScriptValueType; +#endif class IScriptEngineManager{ public: virtual ScriptEngineType* scriptEngine() = 0; -#ifndef USE_QJSENGINE +#ifdef USE_QTSCRIPTENGINE virtual bool addFunction(const QString& name, ScriptEngineType::FunctionSignature function, const QString& category="", const QString& description="") = 0; #endif