mirror of
https://github.com/fralx/LimeReport.git
synced 2025-09-23 08:29:07 +03:00
QJSEngine will be used if Qt version 5.6 and higher
This commit is contained in:
@@ -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<QComboBox*>(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<QComboBox*>(object.toQObject());
|
||||
if (comboBox){
|
||||
comboBox->addItems(values);
|
||||
}
|
||||
}
|
||||
|
||||
void ScriptFunctionsManager::addItemToComboBox(QScriptValue object, const QString &value)
|
||||
{
|
||||
QComboBox* comboBox = dynamic_cast<QComboBox*>(object.toQObject());
|
||||
if (comboBox){
|
||||
comboBox->addItem(value);
|
||||
}
|
||||
}
|
||||
|
||||
QScriptValue ScriptFunctionsManager::createComboBoxWrapper(QScriptValue comboBox)
|
||||
{
|
||||
QComboBox* item = dynamic_cast<QComboBox*>(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)
|
||||
|
@@ -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<QString, IWrapperCreator*> m_wrappersFactory;
|
||||
#endif
|
||||
};
|
||||
|
||||
class ScriptEngineManager : public QObject, public Singleton<ScriptEngineManager>, public IScriptEngineManager
|
||||
|
@@ -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()){
|
||||
|
Reference in New Issue
Block a user