From 09754e6906258ad0d2a01b5a9923fb014bb05db3 Mon Sep 17 00:00:00 2001 From: Arin Alexander Date: Thu, 14 Dec 2017 02:28:52 +0300 Subject: [PATCH] QJSEngine will be used if Qt version 5.6 and higher --- common.pri | 5 +- .../change_item_from_script.lrxml | 90 +++-- .../change_item_from_script.lrxml | 321 +++++++++++------- limereport/lrscriptenginemanager.cpp | 63 +++- limereport/lrscriptenginemanager.h | 20 +- limereport/scripteditor/lrscripteditor.cpp | 3 +- 6 files changed, 319 insertions(+), 183 deletions(-) diff --git a/common.pri b/common.pri index ce2a2c7..b8ea7a9 100644 --- a/common.pri +++ b/common.pri @@ -4,10 +4,13 @@ CONFIG *= build_translations CONFIG *= zint } -!contains(CONFIG, qtscriptengine){ +!contains(CONFIG, qtscriptengine): +greaterThan(QT_MAJOR_VERSION, 4): +greaterThan(QT_MINOR_VERSION, 5){ CONFIG *= qjsengine } + !contains(CONFIG, no_formdesigner){ CONFIG *= dialogdesigner } diff --git a/demo_r1/demo_reports/change_item_from_script.lrxml b/demo_r1/demo_reports/change_item_from_script.lrxml index 6d92ba8..301c326 100644 --- a/demo_r1/demo_reports/change_item_from_script.lrxml +++ b/demo_r1/demo_reports/change_item_from_script.lrxml @@ -1,27 +1,27 @@ - + - + page1 - + - + - + ReportPage1 - + - + DataBand1 - + - + TextItem2 - + @@ -51,7 +51,7 @@ if ($D{customers.CustomerID}=="ANTON"){ - + @@ -65,6 +65,13 @@ if ($D{customers.CustomerID}=="ANTON"){ + + + + + + + @@ -78,6 +85,7 @@ if ($D{customers.CustomerID}=="ANTON"){ + customers @@ -88,14 +96,16 @@ if ($D{customers.CustomerID}=="ANTON"){ + + - + ReportHeader1 - + - + TextItem1 - + @@ -107,10 +117,10 @@ if ($D{customers.CustomerID}=="ANTON"){ $S{ -var color = new QColor('#DEB887'); -var font = new QFont('Times New Roman',26,false,true); +var color = LimeReport.color('#DEB887'); +var font = LimeReport.font('Times New Roman',26,false,true); THIS.backgroundColor = color; -THIS.fontColor = QColor('red'); +THIS.fontColor = LimeReport.color('red'); THIS.font = font; 'Test'} @@ -118,7 +128,7 @@ THIS.font = font; - + @@ -132,10 +142,17 @@ THIS.font = font; + + + + + + + - + TextItem3 - + @@ -151,7 +168,7 @@ THIS.font = font; - + @@ -165,6 +182,13 @@ THIS.font = font; + + + + + + + @@ -178,8 +202,10 @@ THIS.font = font; + + @@ -197,13 +223,19 @@ THIS.font = font; + + + + + + - + datasources - + test QSQLITE @@ -212,10 +244,11 @@ THIS.font = font; + - + customers Select * from customers limit 5 @@ -225,18 +258,21 @@ THIS.font = font; - + TestName TestValue + + - + + diff --git a/demo_r2/demo_reports/change_item_from_script.lrxml b/demo_r2/demo_reports/change_item_from_script.lrxml index 2e79dbc..63d93d4 100644 --- a/demo_r2/demo_reports/change_item_from_script.lrxml +++ b/demo_r2/demo_reports/change_item_from_script.lrxml @@ -1,35 +1,37 @@ + - + - + page1 - - - - - - - + + + + + + + ReportPage1 - + - + DataBand1 - + - + TextItem2 - + - - + + DataBand1 - - - - - + + + + + + $S{ var selectedItemBegin = '<span style="background:black; color:red; font-weight:bold ">'; @@ -45,152 +47,208 @@ if ($D{customers.CustomerID}=="ANTON"){ '<span>Customer: </span>'+customer; } - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + - - + + ReportPage1 - - - - - + + + + + + - - + + + customers - - - - - - - + + + + + + + + + + - + ReportHeader1 - + - + TextItem1 - + - - + + ReportHeader1 - - - - - + + + + + + $S{ -var color = new QColor('#DEB887'); -var font = new QFont('Times New Roman',26,false,true); +var color = LimeReport.color('#DEB887'); +var font = LimeReport.font('Times New Roman',26,false,true); THIS.backgroundColor = color; -THIS.fontColor = QColor('red'); +THIS.fontColor = LimeReport.color('red'); THIS.font = font; 'Test'} - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + - + TextItem3 - + - - + + ReportHeader1 - - - - - + + + + + + <p> <span>test1</span> <span style="background:red">test</span> </p> - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + - - + + ReportPage1 - - - - - + + + + + + - - - + + + + + - - + + - - - - - - - - - + + + + + + + + + + + + + + + + + + - + datasources - + test QSQLITE - ./demo_reports/northwind.db + /home/alex/Work/C++Projects/LimeReport/build/5.6.2/linux64/release/demo_r1/demo_reports/northwind.db - + - + + - + customers Select * from customers limit 5 @@ -200,12 +258,21 @@ THIS.font = font; - + TestName TestValue + + + + + + + + + diff --git a/limereport/lrscriptenginemanager.cpp b/limereport/lrscriptenginemanager.cpp index 440fdfd..b5c1a8f 100644 --- a/limereport/lrscriptenginemanager.cpp +++ b/limereport/lrscriptenginemanager.cpp @@ -273,7 +273,10 @@ bool ScriptEngineManager::containsFunction(const QString& functionName){ } #ifndef USE_QJSENGINE -Q_DECL_DEPRECATED bool ScriptEngineManager::addFunction(const QString& name, +#if QT_VERSION > 0x050600 +Q_DECL_DEPRECATED +#endif +bool ScriptEngineManager::addFunction(const QString& name, QScriptEngine::FunctionSignature function, const QString& category, const QString& description) @@ -345,11 +348,6 @@ void ScriptEngineManager::setDataManager(DataSourceManager *dataManager){ addFunction(describer); } -// qDebug()<<"is script context exists before set datamanager is called"<< (m_context == 0); - -// ICallbackDatasource* tableOfContents = m_dataManager->createCallbackDatasource("tableofcontents"); -// connect(tableOfContents, SIGNAL(getCallbackData(LimeReport::CallbackInfo,QVariant&)), -// m_tableOfContents, SLOT(slotOneSlotDS(LimeReport::CallbackInfo,QVariant&))); } } } @@ -1548,11 +1546,7 @@ void ScriptFunctionsManager::clearTableOfContents() scriptEngineManager()->clearTableOfContents(); } - - -#ifdef USE_QJSENGINE - -QFont ScriptFunctionsManager::font(const QString &family, int pointSize, bool bold, bool italic, bool underLine) +QFont ScriptFunctionsManager::font(const QString &family, int pointSize, bool italic, bool bold, bool underLine) { QFont result (family, pointSize); result.setBold(bold); @@ -1561,6 +1555,8 @@ QFont ScriptFunctionsManager::font(const QString &family, int pointSize, bool bo return result; } +#ifdef USE_QJSENGINE + void ScriptFunctionsManager::addItemsToComboBox(QJSValue object, const QStringList &values) { QComboBox* comboBox = dynamic_cast(object.toQObject()); @@ -1599,7 +1595,48 @@ QJSValue ScriptFunctionsManager::createWrapper(QJSValue item) return QJSValue(); } +#else + +void ScriptFunctionsManager::addItemsToComboBox(QScriptValue object, const QStringList &values) +{ + QComboBox* comboBox = dynamic_cast(object.toQObject()); + if (comboBox){ + comboBox->addItems(values); + } +} + +void ScriptFunctionsManager::addItemToComboBox(QScriptValue object, const QString &value) +{ + QComboBox* comboBox = dynamic_cast(object.toQObject()); + if (comboBox){ + comboBox->addItem(value); + } +} + +QScriptValue ScriptFunctionsManager::createComboBoxWrapper(QScriptValue comboBox) +{ + QComboBox* item = dynamic_cast(comboBox.toQObject()); + if (item){ + ComboBoxWrapper* wrapper = new ComboBoxWrapper(item); + return m_scriptEngineManager->scriptEngine()->newQObject(wrapper); + } + return QScriptValue(); +} + +QScriptValue ScriptFunctionsManager::createWrapper(QScriptValue item) +{ + QObject* object = item.toQObject(); + if (object){ + IWrapperCreator* wrapper = m_wrappersFactory.value(object->metaObject()->className()); + if (wrapper){ + return m_scriptEngineManager->scriptEngine()->newQObject(wrapper->createWrapper(item.toQObject())); + } + } + return QScriptValue(); +} + #endif + QFont ScriptFunctionsManager::font(QVariantMap params){ if (!params.contains("family")){ return QFont(); @@ -1694,7 +1731,7 @@ void LimeReport::TableOfContents::clear(){ } -#ifdef USE_QJSENGINE +//#ifdef USE_QJSENGINE QObject* ComboBoxWrapperCreator::createWrapper(QObject *item) { @@ -1705,7 +1742,7 @@ QObject* ComboBoxWrapperCreator::createWrapper(QObject *item) return 0; } -#endif +//#endif #ifndef USE_QJSENGINE void ComboBoxPrototype::addItem(const QString &text) diff --git a/limereport/lrscriptenginemanager.h b/limereport/lrscriptenginemanager.h index 2549890..1586068 100644 --- a/limereport/lrscriptenginemanager.h +++ b/limereport/lrscriptenginemanager.h @@ -263,7 +263,6 @@ private: QString m_scriptWrapper; }; - #ifndef USE_QJSENGINE class ComboBoxPrototype : public QObject, public QScriptable{ Q_OBJECT @@ -275,8 +274,6 @@ public slots: }; #endif -#ifdef USE_QJSENGINE - class IWrapperCreator{ public: virtual QObject* createWrapper(QObject* item) = 0; @@ -298,20 +295,15 @@ private: QObject* createWrapper(QObject* item); }; -#endif - class ScriptFunctionsManager : public QObject{ Q_OBJECT public: explicit ScriptFunctionsManager(QObject* parent = 0):QObject(parent){ -#ifdef USE_QJSENGINE m_wrappersFactory.insert("QComboBox",new ComboBoxWrapperCreator()); -#endif + } ~ScriptFunctionsManager(){ -#ifdef USE_QJSENGINE foreach(IWrapperCreator* wrapper, m_wrappersFactory.values()){ delete wrapper;} m_wrappersFactory.clear(); -#endif } Q_INVOKABLE QVariant calcGroupFunction(const QString& name, const QString& expressionID, const QString& bandName); Q_INVOKABLE QVariant line(const QString& bandName); @@ -331,13 +323,17 @@ public: Q_INVOKABLE QVariant color(const QString& color){ return QColor(color);} Q_INVOKABLE void addTableOfContentsItem(const QString& uniqKey, const QString& content, int indent = 0); Q_INVOKABLE void clearTableOfContents(); - + Q_INVOKABLE QFont font(const QString& family, int pointSize = -1, bool bold = false, bool italic = false, bool underLine = false); #ifdef USE_QJSENGINE - Q_INVOKABLE QFont font(const QString& family, int pointSize = -1, bool bold = false, bool italic = false, bool underLine = false); Q_INVOKABLE void addItemsToComboBox(QJSValue object, const QStringList& values); Q_INVOKABLE void addItemToComboBox(QJSValue object, const QString& value); Q_INVOKABLE QJSValue createComboBoxWrapper(QJSValue comboBox); Q_INVOKABLE QJSValue createWrapper(QJSValue item); +#else + Q_INVOKABLE void addItemsToComboBox(QScriptValue object, const QStringList& values); + Q_INVOKABLE void addItemToComboBox(QScriptValue object, const QString& value); + Q_INVOKABLE QScriptValue createComboBoxWrapper(QScriptValue comboBox); + Q_INVOKABLE QScriptValue createWrapper(QScriptValue item); #endif Q_INVOKABLE QFont font(QVariantMap params); ScriptEngineManager *scriptEngineManager() const; @@ -345,9 +341,7 @@ public: static QColor createQColor(const QString& color){ return QColor(color);} private: ScriptEngineManager* m_scriptEngineManager; -#ifdef USE_QJSENGINE QMap m_wrappersFactory; -#endif }; class ScriptEngineManager : public QObject, public Singleton, public IScriptEngineManager diff --git a/limereport/scripteditor/lrscripteditor.cpp b/limereport/scripteditor/lrscripteditor.cpp index 667a238..a661e1c 100644 --- a/limereport/scripteditor/lrscripteditor.cpp +++ b/limereport/scripteditor/lrscripteditor.cpp @@ -89,9 +89,8 @@ void ScriptEditor::initCompleter() if (m_page) dm = m_page->datasourceManager(); - ScriptEngineManager& se = LimeReport::ScriptEngineManager::instance(); - #ifdef USE_QJSENGINE + ScriptEngineManager& se = LimeReport::ScriptEngineManager::instance(); QJSValue globalObject = se.scriptEngine()->globalObject(); QJSValueIterator it(globalObject); while (it.hasNext()){