mirror of
https://github.com/fralx/LimeReport.git
synced 2024-12-24 00:33:02 +03:00
Building for different script engine has been fixed
This commit is contained in:
parent
0a0e1504fa
commit
e0ef984fca
@ -47,6 +47,7 @@ lessThan(QT_MAJOR_VERSION, 5){
|
||||
contains(CONFIG, qtscriptengine){
|
||||
CONFIG -= qjsengine
|
||||
QT *= script
|
||||
DEFINES *= USE_QTSCRIPTENGINE
|
||||
message(qtscriptengine)
|
||||
}
|
||||
|
||||
|
@ -42,13 +42,6 @@
|
||||
# define LIMEREPORT_EXPORT /**/
|
||||
#endif
|
||||
|
||||
#ifdef USE_QJSENGINE
|
||||
//#include <QJSEngine>
|
||||
#include <QQmlEngine>
|
||||
#else
|
||||
#include <QtScript/QScriptEngine>
|
||||
#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 <typename T>
|
||||
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
|
||||
|
@ -29,17 +29,47 @@
|
||||
****************************************************************************/
|
||||
#ifndef LRSCRIPTENGINEMANAGERINTF_H
|
||||
#define LRSCRIPTENGINEMANAGERINTF_H
|
||||
#include "qglobal.h"
|
||||
|
||||
//#include <QJSEngine>
|
||||
#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 <QQmlEngine>
|
||||
#else
|
||||
#include <QtScript/QScriptEngine>
|
||||
#endif
|
||||
|
||||
namespace LimeReport{
|
||||
|
||||
#ifdef USE_QJSENGINE
|
||||
typedef QJSEngine ScriptEngineType;
|
||||
typedef QJSValue ScriptValueType;
|
||||
template <typename T>
|
||||
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
|
||||
|
@ -29,9 +29,6 @@
|
||||
****************************************************************************/
|
||||
#include <QtGui>
|
||||
#include <QTextLayout>
|
||||
#ifndef USE_QJSENGINE
|
||||
#include <QtScript/QScriptEngine>
|
||||
#endif
|
||||
#include <QLocale>
|
||||
#include <QMessageBox>
|
||||
#include <math.h>
|
||||
|
@ -42,13 +42,6 @@
|
||||
# define LIMEREPORT_EXPORT /**/
|
||||
#endif
|
||||
|
||||
#ifdef USE_QJSENGINE
|
||||
//#include <QJSEngine>
|
||||
#include <QQmlEngine>
|
||||
#else
|
||||
#include <QtScript/QScriptEngine>
|
||||
#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 <typename T>
|
||||
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
|
||||
|
@ -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();
|
||||
|
@ -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()) {
|
||||
|
@ -32,7 +32,7 @@
|
||||
#include <QDate>
|
||||
#include <QStringList>
|
||||
#include <QUuid>
|
||||
#ifndef USE_QJSENGINE
|
||||
#ifdef USE_QTSCRIPTENGINE
|
||||
#include <QScriptValueIterator>
|
||||
#endif
|
||||
#include <QMessageBox>
|
||||
@ -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<QComboBox*>(),
|
||||
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<QComboBox*>(thisObject());
|
||||
|
@ -29,7 +29,7 @@
|
||||
****************************************************************************/
|
||||
#ifndef LRSCRIPTENGINEMANAGER_H
|
||||
#define LRSCRIPTENGINEMANAGER_H
|
||||
#ifndef USE_QJSENGINE
|
||||
#ifdef USE_QTSCRIPTENGINE
|
||||
#include <QtScript/QScriptEngine>
|
||||
#include <QScriptable>
|
||||
#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
|
||||
|
@ -29,17 +29,47 @@
|
||||
****************************************************************************/
|
||||
#ifndef LRSCRIPTENGINEMANAGERINTF_H
|
||||
#define LRSCRIPTENGINEMANAGERINTF_H
|
||||
#include "qglobal.h"
|
||||
|
||||
//#include <QJSEngine>
|
||||
#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 <QQmlEngine>
|
||||
#else
|
||||
#include <QtScript/QScriptEngine>
|
||||
#endif
|
||||
|
||||
namespace LimeReport{
|
||||
|
||||
#ifdef USE_QJSENGINE
|
||||
typedef QJSEngine ScriptEngineType;
|
||||
typedef QJSValue ScriptValueType;
|
||||
template <typename T>
|
||||
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
|
||||
|
Loading…
Reference in New Issue
Block a user