2016-02-17 10:11:00 +03:00
|
|
|
/***************************************************************************
|
|
|
|
* This file is part of the Lime Report project *
|
2021-08-18 20:21:36 +03:00
|
|
|
* Copyright (C) 2021 by Alexander Arin *
|
2016-02-17 10:11:00 +03:00
|
|
|
* arin_a@bk.ru *
|
|
|
|
* *
|
|
|
|
** GNU General Public License Usage **
|
|
|
|
* *
|
|
|
|
* This library is free software: you can redistribute it and/or modify *
|
|
|
|
* it under the terms of the GNU General Public License as published by *
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or *
|
|
|
|
* (at your option) any later version. *
|
|
|
|
* You should have received a copy of the GNU General Public License *
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
|
|
|
|
* *
|
|
|
|
** GNU Lesser General Public License **
|
|
|
|
* *
|
|
|
|
* This library is free software: you can redistribute it and/or modify *
|
|
|
|
* it under the terms of the GNU Lesser General Public License as *
|
|
|
|
* published by the Free Software Foundation, either version 3 of the *
|
|
|
|
* License, or (at your option) any later version. *
|
|
|
|
* You should have received a copy of the GNU Lesser General Public *
|
|
|
|
* License along with this library. *
|
|
|
|
* If not, see <http://www.gnu.org/licenses/>. *
|
|
|
|
* *
|
|
|
|
* This library is distributed in the hope that it will be useful, *
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
|
|
|
* GNU General Public License for more details. *
|
|
|
|
****************************************************************************/
|
|
|
|
#include "lrscriptenginemanager.h"
|
|
|
|
|
|
|
|
#include <QDate>
|
|
|
|
#include <QStringList>
|
2019-02-05 01:04:23 +03:00
|
|
|
#include <QUuid>
|
2019-02-19 02:23:53 +03:00
|
|
|
#ifdef USE_QTSCRIPTENGINE
|
2016-02-17 10:11:00 +03:00
|
|
|
#include <QScriptValueIterator>
|
2018-03-22 02:38:42 +03:00
|
|
|
#endif
|
2017-04-20 23:34:32 +03:00
|
|
|
#include <QMessageBox>
|
2016-06-10 18:05:18 +03:00
|
|
|
#ifdef HAVE_UI_LOADER
|
|
|
|
#include <QBuffer>
|
2024-09-04 17:31:16 +03:00
|
|
|
#include <QUiLoader>
|
2016-06-10 18:05:18 +03:00
|
|
|
#include <QWidget>
|
|
|
|
#endif
|
2017-08-25 18:01:59 +03:00
|
|
|
#include "lrbanddesignintf.h"
|
2024-09-04 17:31:16 +03:00
|
|
|
#include "lrbasedesignintf.h"
|
|
|
|
#include "lrdatasourcemanager.h"
|
2018-03-14 11:22:03 +03:00
|
|
|
#include "lrpageitemdesignintf.h"
|
2016-02-17 10:11:00 +03:00
|
|
|
|
|
|
|
Q_DECLARE_METATYPE(QColor)
|
|
|
|
Q_DECLARE_METATYPE(QFont)
|
2024-09-04 17:31:16 +03:00
|
|
|
Q_DECLARE_METATYPE(LimeReport::ScriptEngineManager*)
|
2016-02-17 10:11:00 +03:00
|
|
|
|
2019-02-19 02:23:53 +03:00
|
|
|
#ifdef USE_QTSCRIPTENGINE
|
2024-09-04 17:31:16 +03:00
|
|
|
QScriptValue constructColor(QScriptContext* context, QScriptEngine* engine)
|
2016-02-17 10:11:00 +03:00
|
|
|
{
|
2022-03-29 15:33:34 +03:00
|
|
|
QColor color(context->argument(0).toString());
|
|
|
|
return engine->toScriptValue(color);
|
2016-02-17 10:11:00 +03:00
|
|
|
}
|
2018-03-22 02:38:42 +03:00
|
|
|
#endif
|
2016-02-17 10:11:00 +03:00
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
namespace LimeReport {
|
2020-02-04 17:16:48 +03:00
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
ScriptEngineNode::ScriptEngineNode(const QString& name, const QString& description,
|
|
|
|
ScriptEngineNode::NodeType type, ScriptEngineNode* parent,
|
|
|
|
const QIcon& icon):
|
|
|
|
m_name(name),
|
|
|
|
m_description(description),
|
|
|
|
m_icon(icon),
|
|
|
|
m_type(type),
|
|
|
|
m_parent(parent)
|
2016-02-17 10:11:00 +03:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
ScriptEngineNode::~ScriptEngineNode() { qDeleteAll(m_childs.begin(), m_childs.end()); }
|
|
|
|
|
|
|
|
ScriptEngineNode* ScriptEngineNode::addChild(const QString& name, const QString& description,
|
|
|
|
ScriptEngineNode::NodeType type, const QIcon& icon)
|
2016-02-17 10:11:00 +03:00
|
|
|
{
|
2024-09-04 17:31:16 +03:00
|
|
|
ScriptEngineNode* res = new ScriptEngineNode(name, description, type, this, icon);
|
2016-02-17 10:11:00 +03:00
|
|
|
m_childs.push_back(res);
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
int ScriptEngineNode::row()
|
|
|
|
{
|
2024-09-04 17:31:16 +03:00
|
|
|
if (m_parent) {
|
2016-02-17 10:11:00 +03:00
|
|
|
return m_parent->m_childs.indexOf(const_cast<ScriptEngineNode*>(this));
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ScriptEngineNode::clear()
|
|
|
|
{
|
2024-09-04 17:31:16 +03:00
|
|
|
for (int i = 0; i < m_childs.count(); ++i) {
|
2016-02-17 10:11:00 +03:00
|
|
|
delete m_childs[i];
|
|
|
|
}
|
|
|
|
m_childs.clear();
|
|
|
|
}
|
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
ScriptEngineModel::ScriptEngineModel(ScriptEngineManager* scriptManager):
|
|
|
|
m_rootNode(new ScriptEngineNode())
|
2016-02-17 10:11:00 +03:00
|
|
|
{
|
|
|
|
setScriptEngineManager(scriptManager);
|
|
|
|
}
|
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
ScriptEngineModel::~ScriptEngineModel() { delete m_rootNode; }
|
2016-02-17 10:11:00 +03:00
|
|
|
|
|
|
|
QModelIndex ScriptEngineModel::parent(const QModelIndex& child) const
|
|
|
|
{
|
2024-09-04 17:31:16 +03:00
|
|
|
if (!child.isValid())
|
|
|
|
return QModelIndex();
|
2016-02-17 10:11:00 +03:00
|
|
|
|
|
|
|
ScriptEngineNode* childNode = nodeFromIndex(child);
|
2024-09-04 17:31:16 +03:00
|
|
|
if (!childNode)
|
|
|
|
return QModelIndex();
|
2016-02-17 10:11:00 +03:00
|
|
|
|
|
|
|
ScriptEngineNode* parentNode = childNode->parent();
|
2024-09-04 17:31:16 +03:00
|
|
|
if ((parentNode == m_rootNode) || (!parentNode))
|
|
|
|
return QModelIndex();
|
|
|
|
return createIndex(parentNode->row(), 0, parentNode);
|
2016-02-17 10:11:00 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
QModelIndex ScriptEngineModel::index(int row, int column, const QModelIndex& parent) const
|
|
|
|
{
|
|
|
|
if (!m_rootNode)
|
|
|
|
return QModelIndex();
|
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
if (!hasIndex(row, column, parent))
|
2016-02-17 10:11:00 +03:00
|
|
|
return QModelIndex();
|
|
|
|
|
|
|
|
ScriptEngineNode* parentNode;
|
2024-09-04 17:31:16 +03:00
|
|
|
if (parent.isValid()) {
|
2016-02-17 10:11:00 +03:00
|
|
|
parentNode = nodeFromIndex(parent);
|
|
|
|
} else {
|
|
|
|
parentNode = m_rootNode;
|
|
|
|
}
|
|
|
|
|
|
|
|
ScriptEngineNode* childNode = parentNode->child(row);
|
2024-09-04 17:31:16 +03:00
|
|
|
if (childNode) {
|
|
|
|
return createIndex(row, column, childNode);
|
|
|
|
} else
|
|
|
|
return QModelIndex();
|
2016-02-17 10:11:00 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
int ScriptEngineModel::rowCount(const QModelIndex& parent) const
|
|
|
|
{
|
2024-09-04 17:31:16 +03:00
|
|
|
if (!m_rootNode)
|
|
|
|
return 0;
|
2016-02-17 10:11:00 +03:00
|
|
|
ScriptEngineNode* parentNode;
|
|
|
|
if (parent.isValid())
|
|
|
|
parentNode = nodeFromIndex(parent);
|
|
|
|
else
|
|
|
|
parentNode = m_rootNode;
|
|
|
|
return parentNode->childCount();
|
|
|
|
}
|
|
|
|
|
|
|
|
int ScriptEngineModel::columnCount(const QModelIndex& parent) const
|
|
|
|
{
|
|
|
|
Q_UNUSED(parent)
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
QVariant ScriptEngineModel::data(const QModelIndex& index, int role) const
|
|
|
|
{
|
2024-09-04 17:31:16 +03:00
|
|
|
ScriptEngineNode* node = nodeFromIndex(index);
|
2016-02-17 10:11:00 +03:00
|
|
|
switch (role) {
|
|
|
|
case Qt::DisplayRole:
|
2024-09-04 17:31:16 +03:00
|
|
|
if (!node)
|
|
|
|
return QVariant();
|
2016-02-17 10:11:00 +03:00
|
|
|
return node->name();
|
|
|
|
break;
|
2024-09-04 17:31:16 +03:00
|
|
|
case Qt::DecorationRole:
|
|
|
|
if (!node)
|
|
|
|
return QIcon();
|
2016-02-17 10:11:00 +03:00
|
|
|
return node->icon();
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return QVariant();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ScriptEngineModel::setScriptEngineManager(ScriptEngineManager* scriptManager)
|
|
|
|
{
|
|
|
|
m_scriptManager = scriptManager;
|
|
|
|
updateModel();
|
|
|
|
}
|
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
void ScriptEngineModel::slotScriptEngineChanged() { updateModel(); }
|
2016-02-17 10:11:00 +03:00
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
ScriptEngineNode* ScriptEngineModel::nodeFromIndex(const QModelIndex& index) const
|
2016-02-17 10:11:00 +03:00
|
|
|
{
|
2024-09-04 17:31:16 +03:00
|
|
|
if (index.isValid()) {
|
2016-02-17 10:11:00 +03:00
|
|
|
return static_cast<ScriptEngineNode*>(index.internalPointer());
|
2024-09-04 17:31:16 +03:00
|
|
|
} else
|
|
|
|
return m_rootNode;
|
2016-02-17 10:11:00 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void ScriptEngineModel::updateModel()
|
|
|
|
{
|
|
|
|
beginResetModel();
|
|
|
|
m_rootNode->clear();
|
2024-09-04 17:31:16 +03:00
|
|
|
QMap<QString, ScriptEngineNode*> categories;
|
|
|
|
foreach (ScriptFunctionDesc funcDesc, m_scriptManager->functionsDescribers()) {
|
2016-02-17 10:11:00 +03:00
|
|
|
ScriptEngineNode* categ;
|
2024-09-04 17:31:16 +03:00
|
|
|
QString categoryName = (!funcDesc.category.isEmpty()) ? funcDesc.category : "NO CATEGORY";
|
|
|
|
if (categories.contains(categoryName)) {
|
2016-02-17 10:11:00 +03:00
|
|
|
categ = categories.value(categoryName);
|
|
|
|
} else {
|
2024-09-04 17:31:16 +03:00
|
|
|
categ = m_rootNode->addChild(categoryName, "", ScriptEngineNode::Category,
|
|
|
|
QIcon(":/report/images/folder"));
|
|
|
|
categories.insert(categoryName, categ);
|
2016-02-17 10:11:00 +03:00
|
|
|
}
|
2024-09-04 17:31:16 +03:00
|
|
|
categ->addChild(funcDesc.name, funcDesc.description, ScriptEngineNode::Function,
|
|
|
|
QIcon(":/report/images/function"));
|
2016-02-17 10:11:00 +03:00
|
|
|
}
|
|
|
|
endResetModel();
|
|
|
|
}
|
|
|
|
|
|
|
|
ScriptEngineManager::~ScriptEngineManager()
|
|
|
|
{
|
2016-02-18 21:09:00 +03:00
|
|
|
delete m_model;
|
|
|
|
m_model = 0;
|
2016-02-17 10:11:00 +03:00
|
|
|
delete m_scriptEngine;
|
|
|
|
}
|
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
bool ScriptEngineManager::isFunctionExists(const QString& functionName) const
|
2016-02-17 10:28:27 +03:00
|
|
|
{
|
2020-02-04 17:16:48 +03:00
|
|
|
return m_functions.contains(functionName);
|
2022-03-29 15:33:34 +03:00
|
|
|
// foreach (ScriptFunctionDesc desc, m_functions.values()) {
|
|
|
|
// if (desc.name.compare(functionName,Qt::CaseInsensitive)==0){
|
|
|
|
// return true;
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
// return false;
|
2016-02-17 10:28:27 +03:00
|
|
|
}
|
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
void ScriptEngineManager::deleteFunction(const QString& functionsName)
|
2016-02-17 10:28:27 +03:00
|
|
|
{
|
2020-02-04 17:16:48 +03:00
|
|
|
m_functions.remove(functionsName);
|
2016-02-17 10:28:27 +03:00
|
|
|
}
|
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
bool ScriptEngineManager::addFunction(const JSFunctionDesc& functionDescriber)
|
2016-11-01 20:42:45 +03:00
|
|
|
{
|
2024-09-04 17:31:16 +03:00
|
|
|
if (m_functions.contains(functionDescriber.name()))
|
|
|
|
return false;
|
|
|
|
ScriptValueType functionManager
|
|
|
|
= scriptEngine()->globalObject().property(functionDescriber.managerName());
|
2016-11-01 20:42:45 +03:00
|
|
|
#ifdef USE_QJSENGINE
|
2024-09-04 17:31:16 +03:00
|
|
|
if (functionManager.isUndefined()) {
|
2016-11-01 20:42:45 +03:00
|
|
|
#else
|
2024-09-04 17:31:16 +03:00
|
|
|
if (!functionManager.isValid()) {
|
2016-11-01 20:42:45 +03:00
|
|
|
#endif
|
|
|
|
functionManager = scriptEngine()->newQObject(functionDescriber.manager());
|
2024-09-04 17:31:16 +03:00
|
|
|
scriptEngine()->globalObject().setProperty(functionDescriber.managerName(),
|
|
|
|
functionManager);
|
2016-11-01 20:42:45 +03:00
|
|
|
}
|
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
if (functionManager.toQObject() == functionDescriber.manager()) {
|
2016-11-01 20:42:45 +03:00
|
|
|
ScriptValueType checkWrapper = scriptEngine()->evaluate(functionDescriber.scriptWrapper());
|
2024-09-04 17:31:16 +03:00
|
|
|
if (!checkWrapper.isError()) {
|
2016-11-01 20:42:45 +03:00
|
|
|
ScriptFunctionDesc funct;
|
|
|
|
funct.name = functionDescriber.name();
|
|
|
|
funct.description = functionDescriber.description();
|
|
|
|
funct.category = functionDescriber.category();
|
|
|
|
funct.type = ScriptFunctionDesc::Native;
|
2020-02-04 17:16:48 +03:00
|
|
|
m_functions.insert(funct.name, funct);
|
2016-11-01 20:42:45 +03:00
|
|
|
if (m_model)
|
|
|
|
m_model->updateModel();
|
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
m_lastError = checkWrapper.toString();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
} else {
|
2018-05-22 11:13:36 +03:00
|
|
|
m_lastError = tr("Function manager with name \"%1\" already exists!");
|
2016-11-01 20:42:45 +03:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-02-19 02:23:53 +03:00
|
|
|
#ifdef USE_QTSCRIPTENGINE
|
2017-12-14 02:28:52 +03:00
|
|
|
#if QT_VERSION > 0x050600
|
|
|
|
Q_DECL_DEPRECATED
|
|
|
|
#endif
|
|
|
|
bool ScriptEngineManager::addFunction(const QString& name,
|
2022-03-29 15:33:34 +03:00
|
|
|
QScriptEngine::FunctionSignature function,
|
2024-09-04 17:31:16 +03:00
|
|
|
const QString& category, const QString& description)
|
2016-02-17 10:11:00 +03:00
|
|
|
{
|
2024-09-04 17:31:16 +03:00
|
|
|
if (!isFunctionExists(name)) {
|
2016-08-12 21:14:05 +03:00
|
|
|
ScriptFunctionDesc funct;
|
|
|
|
funct.name = name;
|
|
|
|
funct.description = description;
|
|
|
|
funct.category = category;
|
|
|
|
funct.scriptValue = scriptEngine()->newFunction(function);
|
2020-02-05 09:08:54 +03:00
|
|
|
funct.scriptValue.setProperty("functionName", name);
|
2016-08-12 21:14:05 +03:00
|
|
|
funct.scriptValue.setData(m_scriptEngine->toScriptValue(this));
|
|
|
|
funct.type = ScriptFunctionDesc::Native;
|
2020-02-05 09:08:54 +03:00
|
|
|
m_functions.insert(name, funct);
|
2016-08-12 21:14:05 +03:00
|
|
|
if (m_model)
|
|
|
|
m_model->updateModel();
|
2020-02-05 09:08:54 +03:00
|
|
|
m_scriptEngine->globalObject().setProperty(funct.name, funct.scriptValue);
|
2016-08-12 21:14:05 +03:00
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2016-11-01 20:42:45 +03:00
|
|
|
#endif
|
2016-08-12 21:14:05 +03:00
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
bool ScriptEngineManager::addFunction(const QString& name, const QString& script,
|
|
|
|
const QString& category, const QString& description)
|
2016-02-17 10:11:00 +03:00
|
|
|
{
|
2016-11-01 20:42:45 +03:00
|
|
|
ScriptValueType functionValue = m_scriptEngine->evaluate(script);
|
2024-09-04 17:31:16 +03:00
|
|
|
if (!functionValue.isError()) {
|
2016-02-17 10:11:00 +03:00
|
|
|
ScriptFunctionDesc funct;
|
2016-11-01 20:42:45 +03:00
|
|
|
funct.scriptValue = functionValue;
|
2024-09-04 17:31:16 +03:00
|
|
|
funct.name = name;
|
2016-02-17 10:11:00 +03:00
|
|
|
funct.category = category;
|
|
|
|
funct.description = description;
|
|
|
|
funct.type = ScriptFunctionDesc::Script;
|
2020-02-04 17:16:48 +03:00
|
|
|
m_functions.insert(name, funct);
|
2022-03-29 15:33:34 +03:00
|
|
|
m_model->updateModel();
|
2016-08-12 21:14:05 +03:00
|
|
|
return true;
|
2016-02-17 10:11:00 +03:00
|
|
|
} else {
|
2016-11-01 20:42:45 +03:00
|
|
|
m_lastError = functionValue.toString();
|
2016-08-12 21:14:05 +03:00
|
|
|
return false;
|
2016-02-17 10:11:00 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
QStringList ScriptEngineManager::functionsNames()
|
|
|
|
{
|
2020-02-04 17:16:48 +03:00
|
|
|
return m_functions.keys();
|
2022-03-29 15:33:34 +03:00
|
|
|
// QStringList res;
|
|
|
|
// foreach(ScriptFunctionDesc func, m_functions){
|
|
|
|
// res<<func.name;
|
|
|
|
// }
|
|
|
|
// return res;
|
2016-02-17 10:11:00 +03:00
|
|
|
}
|
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
void ScriptEngineManager::setDataManager(DataSourceManager* dataManager)
|
|
|
|
{
|
|
|
|
if (dataManager && m_dataManager != dataManager) {
|
2020-02-04 17:16:48 +03:00
|
|
|
m_dataManager = dataManager;
|
2024-09-04 17:31:16 +03:00
|
|
|
if (m_dataManager) {
|
|
|
|
foreach (QString func, m_dataManager->groupFunctionNames()) {
|
2016-11-01 20:42:45 +03:00
|
|
|
JSFunctionDesc describer(
|
2024-09-04 17:31:16 +03:00
|
|
|
func, tr("GROUP FUNCTIONS"),
|
|
|
|
func + "(\"" + tr("FieldName") + "\",\"" + tr("BandName") + "\")",
|
|
|
|
LimeReport::Const::FUNCTION_MANAGER_NAME, m_functionManager,
|
|
|
|
QString("function %1(fieldName, bandName, pageitem){\
|
2022-03-29 15:33:34 +03:00
|
|
|
if (typeof pageitem == 'undefined') return %2.calcGroupFunction(\"%1\", fieldName, bandName); \
|
2024-09-04 17:31:16 +03:00
|
|
|
else return %2.calcGroupFunction(\"%1\", fieldName, bandName, pageitem);}")
|
|
|
|
.arg(func)
|
|
|
|
.arg(LimeReport::Const::FUNCTION_MANAGER_NAME));
|
|
|
|
addFunction(describer);
|
2016-02-17 10:28:27 +03:00
|
|
|
}
|
2024-09-04 17:31:16 +03:00
|
|
|
moveQObjectToScript(new DatasourceFunctions(dataManager),
|
|
|
|
LimeReport::Const::DATAFUNCTIONS_MANAGER_NAME);
|
2016-02-17 10:28:27 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
QString ScriptEngineManager::expandUserVariables(QString context, RenderPass /* pass */,
|
|
|
|
ExpandType expandType, QVariant& varValue)
|
2017-01-28 02:20:15 +03:00
|
|
|
{
|
2021-12-16 00:13:39 +03:00
|
|
|
#if (QT_VERSION < QT_VERSION_CHECK(5, 15, 1))
|
2017-01-28 02:20:15 +03:00
|
|
|
QRegExp rx(Const::VARIABLE_RX);
|
2024-09-04 17:31:16 +03:00
|
|
|
if (context.contains(rx)) {
|
2017-01-28 02:20:15 +03:00
|
|
|
int pos = 0;
|
2024-09-04 17:31:16 +03:00
|
|
|
while ((pos = rx.indexIn(context, pos)) != -1) {
|
|
|
|
QString variable = rx.cap(1);
|
2017-01-28 02:20:15 +03:00
|
|
|
pos += rx.matchedLength();
|
2024-09-04 17:31:16 +03:00
|
|
|
if (dataManager()->containsVariable(variable)) {
|
2017-01-28 02:20:15 +03:00
|
|
|
try {
|
2017-08-31 02:53:34 +03:00
|
|
|
|
|
|
|
varValue = dataManager()->variable(variable);
|
2024-09-04 17:31:16 +03:00
|
|
|
switch (expandType) {
|
2017-08-31 02:53:34 +03:00
|
|
|
case EscapeSymbols:
|
2024-09-04 17:31:16 +03:00
|
|
|
context.replace(rx.cap(0), escapeSimbols(varValue.toString()));
|
2022-03-29 15:33:34 +03:00
|
|
|
break;
|
2017-08-31 02:53:34 +03:00
|
|
|
case NoEscapeSymbols:
|
2024-09-04 17:31:16 +03:00
|
|
|
context.replace(rx.cap(0), varValue.toString());
|
2022-03-29 15:33:34 +03:00
|
|
|
break;
|
2017-08-31 02:53:34 +03:00
|
|
|
case ReplaceHTMLSymbols:
|
2024-09-04 17:31:16 +03:00
|
|
|
context.replace(rx.cap(0), replaceHTMLSymbols(varValue.toString()));
|
2022-03-29 15:33:34 +03:00
|
|
|
break;
|
2017-01-28 02:20:15 +03:00
|
|
|
}
|
2024-09-04 17:31:16 +03:00
|
|
|
pos = 0;
|
2017-08-31 02:53:34 +03:00
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
} catch (ReportError& e) {
|
2017-01-28 02:20:15 +03:00
|
|
|
dataManager()->putError(e.what());
|
2024-09-04 17:31:16 +03:00
|
|
|
if (!dataManager()->reportSettings()
|
|
|
|
|| dataManager()->reportSettings()->suppressAbsentFieldsAndVarsWarnings())
|
|
|
|
context.replace(rx.cap(0), e.what());
|
2017-01-28 02:20:15 +03:00
|
|
|
else
|
2024-09-04 17:31:16 +03:00
|
|
|
context.replace(rx.cap(0), "");
|
2017-01-28 02:20:15 +03:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
QString error;
|
|
|
|
error = tr("Variable %1 not found").arg(variable);
|
|
|
|
dataManager()->putError(error);
|
2024-09-04 17:31:16 +03:00
|
|
|
if (!dataManager()->reportSettings()
|
|
|
|
|| dataManager()->reportSettings()->suppressAbsentFieldsAndVarsWarnings())
|
|
|
|
context.replace(rx.cap(0), error);
|
2017-01-28 02:20:15 +03:00
|
|
|
else
|
2024-09-04 17:31:16 +03:00
|
|
|
context.replace(rx.cap(0), "");
|
2017-01-28 02:20:15 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return context;
|
2021-08-24 10:22:30 +03:00
|
|
|
#else
|
2022-07-16 02:33:39 +03:00
|
|
|
QRegularExpression rx = getVariableRegEx();
|
2024-09-04 17:31:16 +03:00
|
|
|
if (context.contains(rx)) {
|
2022-03-29 15:33:34 +03:00
|
|
|
int pos = 0;
|
|
|
|
QRegularExpressionMatch match = rx.match(context, pos);
|
2024-09-04 17:31:16 +03:00
|
|
|
while (match.hasMatch()) {
|
2022-03-29 15:33:34 +03:00
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
QString variable = match.captured(1);
|
2022-03-29 15:33:34 +03:00
|
|
|
pos = match.capturedEnd();
|
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
if (dataManager()->containsVariable(variable)) {
|
2022-03-29 15:33:34 +03:00
|
|
|
try {
|
|
|
|
|
|
|
|
varValue = dataManager()->variable(variable);
|
2024-09-04 17:31:16 +03:00
|
|
|
switch (expandType) {
|
2022-03-29 15:33:34 +03:00
|
|
|
case EscapeSymbols:
|
|
|
|
context.replace(match.captured(0), escapeSimbols(varValue.toString()));
|
|
|
|
break;
|
|
|
|
case NoEscapeSymbols:
|
|
|
|
context.replace(match.captured(0), varValue.toString());
|
|
|
|
break;
|
|
|
|
case ReplaceHTMLSymbols:
|
|
|
|
context.replace(match.captured(0), replaceHTMLSymbols(varValue.toString()));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
pos = 0;
|
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
} catch (ReportError& e) {
|
2022-03-29 15:33:34 +03:00
|
|
|
dataManager()->putError(e.what());
|
2024-09-04 17:31:16 +03:00
|
|
|
if (!dataManager()->reportSettings()
|
|
|
|
|| dataManager()->reportSettings()->suppressAbsentFieldsAndVarsWarnings())
|
2022-03-29 15:33:34 +03:00
|
|
|
context.replace(match.captured(0), e.what());
|
|
|
|
else
|
|
|
|
context.replace(match.captured(0), "");
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
|
|
|
|
QString error;
|
|
|
|
error = tr("Variable %1 not found").arg(variable);
|
|
|
|
dataManager()->putError(error);
|
2024-09-04 17:31:16 +03:00
|
|
|
if (!dataManager()->reportSettings()
|
|
|
|
|| dataManager()->reportSettings()->suppressAbsentFieldsAndVarsWarnings())
|
2022-03-29 15:33:34 +03:00
|
|
|
context.replace(match.captured(0), error);
|
|
|
|
else
|
|
|
|
context.replace(match.captured(0), "");
|
|
|
|
}
|
|
|
|
|
|
|
|
match = rx.match(context, pos);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return context;
|
2021-08-24 10:22:30 +03:00
|
|
|
#endif
|
2017-01-28 02:20:15 +03:00
|
|
|
}
|
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
QString ScriptEngineManager::expandDataFields(QString context, ExpandType expandType,
|
|
|
|
QVariant& varValue, QObject* reportItem)
|
2017-01-28 02:20:15 +03:00
|
|
|
{
|
2021-12-16 00:13:39 +03:00
|
|
|
#if (QT_VERSION < QT_VERSION_CHECK(5, 15, 1))
|
2017-01-28 02:20:15 +03:00
|
|
|
QRegExp rx(Const::FIELD_RX);
|
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
if (context.contains(rx)) {
|
|
|
|
while ((rx.indexIn(context)) != -1) {
|
|
|
|
QString field = rx.cap(1);
|
2017-01-28 02:20:15 +03:00
|
|
|
|
|
|
|
if (dataManager()->containsField(field)) {
|
|
|
|
QString fieldValue;
|
|
|
|
varValue = dataManager()->fieldData(field);
|
|
|
|
if (expandType == EscapeSymbols) {
|
2018-07-12 00:00:19 +03:00
|
|
|
if (varValue.isNull()) {
|
2024-09-04 17:31:16 +03:00
|
|
|
fieldValue = "\"\"";
|
2017-01-28 02:20:15 +03:00
|
|
|
} else {
|
|
|
|
fieldValue = escapeSimbols(varValue.toString());
|
|
|
|
switch (dataManager()->fieldData(field).type()) {
|
|
|
|
case QVariant::Char:
|
|
|
|
case QVariant::String:
|
|
|
|
case QVariant::StringList:
|
|
|
|
case QVariant::Date:
|
|
|
|
case QVariant::DateTime:
|
2024-09-04 17:31:16 +03:00
|
|
|
fieldValue = "\"" + fieldValue + "\"";
|
2017-01-28 02:20:15 +03:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (expandType == ReplaceHTMLSymbols)
|
|
|
|
fieldValue = replaceHTMLSymbols(varValue.toString());
|
2024-09-04 17:31:16 +03:00
|
|
|
else
|
|
|
|
fieldValue = varValue.toString();
|
2017-01-28 02:20:15 +03:00
|
|
|
}
|
2018-07-12 00:00:19 +03:00
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
context.replace(rx.cap(0), fieldValue);
|
2017-01-28 02:20:15 +03:00
|
|
|
|
|
|
|
} else {
|
2017-03-03 01:12:29 +03:00
|
|
|
QString error;
|
2024-09-04 17:31:16 +03:00
|
|
|
if (reportItem) {
|
|
|
|
error
|
|
|
|
= tr("Field %1 not found in %2!").arg(field).arg(reportItem->objectName());
|
2017-03-03 01:12:29 +03:00
|
|
|
dataManager()->putError(error);
|
|
|
|
}
|
2017-01-28 02:20:15 +03:00
|
|
|
varValue = QVariant();
|
2024-09-04 17:31:16 +03:00
|
|
|
if (!dataManager()->reportSettings()
|
|
|
|
|| !dataManager()->reportSettings()->suppressAbsentFieldsAndVarsWarnings())
|
|
|
|
context.replace(rx.cap(0), error);
|
2017-01-28 02:20:15 +03:00
|
|
|
else
|
2024-09-04 17:31:16 +03:00
|
|
|
context.replace(rx.cap(0), "");
|
2017-01-28 02:20:15 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return context;
|
2021-08-24 10:22:30 +03:00
|
|
|
#else
|
2022-07-16 02:33:39 +03:00
|
|
|
QRegularExpression rx = getFieldRegEx();
|
2024-09-04 17:31:16 +03:00
|
|
|
if (context.contains(rx)) {
|
2021-08-24 10:22:30 +03:00
|
|
|
QRegularExpressionMatch match = rx.match(context);
|
2024-09-04 17:31:16 +03:00
|
|
|
while (match.hasMatch()) {
|
2021-08-24 10:22:30 +03:00
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
QString field = match.captured(1);
|
2021-08-24 10:22:30 +03:00
|
|
|
|
|
|
|
if (dataManager()->containsField(field)) {
|
|
|
|
QString fieldValue;
|
|
|
|
varValue = dataManager()->fieldData(field);
|
|
|
|
if (expandType == EscapeSymbols) {
|
|
|
|
if (varValue.isNull()) {
|
2024-09-04 17:31:16 +03:00
|
|
|
fieldValue = "\"\"";
|
2021-08-24 10:22:30 +03:00
|
|
|
} else {
|
|
|
|
fieldValue = escapeSimbols(varValue.toString());
|
2024-09-04 17:31:16 +03:00
|
|
|
// TODO: Migrate to QMetaType
|
2022-07-19 00:43:54 +03:00
|
|
|
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
|
|
|
|
switch (dataManager()->fieldData(field).typeId()) {
|
2024-09-04 17:31:16 +03:00
|
|
|
case QMetaType::QChar:
|
|
|
|
case QMetaType::QString:
|
|
|
|
case QMetaType::QStringList:
|
|
|
|
case QMetaType::QDate:
|
|
|
|
case QMetaType::QDateTime:
|
|
|
|
fieldValue = "\"" + fieldValue + "\"";
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
2022-07-19 00:43:54 +03:00
|
|
|
}
|
|
|
|
#else
|
2021-08-24 10:22:30 +03:00
|
|
|
switch (dataManager()->fieldData(field).type()) {
|
2024-09-04 17:31:16 +03:00
|
|
|
case QVariant::Char:
|
|
|
|
case QVariant::String:
|
|
|
|
case QVariant::StringList:
|
|
|
|
case QVariant::Date:
|
|
|
|
case QVariant::DateTime:
|
|
|
|
fieldValue = "\"" + fieldValue + "\"";
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
2021-08-24 10:22:30 +03:00
|
|
|
}
|
2022-07-19 00:43:54 +03:00
|
|
|
#endif
|
2021-08-24 10:22:30 +03:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (expandType == ReplaceHTMLSymbols)
|
|
|
|
fieldValue = replaceHTMLSymbols(varValue.toString());
|
2024-09-04 17:31:16 +03:00
|
|
|
else
|
|
|
|
fieldValue = varValue.toString();
|
2021-08-24 10:22:30 +03:00
|
|
|
}
|
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
context.replace(match.captured(0), fieldValue);
|
2021-08-24 10:22:30 +03:00
|
|
|
|
|
|
|
} else {
|
|
|
|
QString error;
|
2024-09-04 17:31:16 +03:00
|
|
|
if (reportItem) {
|
|
|
|
error
|
|
|
|
= tr("Field %1 not found in %2!").arg(field).arg(reportItem->objectName());
|
2021-08-24 10:22:30 +03:00
|
|
|
dataManager()->putError(error);
|
|
|
|
}
|
|
|
|
varValue = QVariant();
|
2024-09-04 17:31:16 +03:00
|
|
|
if (!dataManager()->reportSettings()
|
|
|
|
|| !dataManager()->reportSettings()->suppressAbsentFieldsAndVarsWarnings())
|
2021-08-24 10:22:30 +03:00
|
|
|
context.replace(match.captured(0), error);
|
|
|
|
else
|
|
|
|
context.replace(match.captured(0), "");
|
|
|
|
}
|
|
|
|
match = rx.match(context);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return context;
|
|
|
|
#endif
|
2017-01-28 02:20:15 +03:00
|
|
|
}
|
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
QString ScriptEngineManager::expandScripts(QString context, QVariant& varValue, QObject* reportItem)
|
2017-01-28 02:20:15 +03:00
|
|
|
{
|
2021-12-16 00:13:39 +03:00
|
|
|
#if (QT_VERSION < QT_VERSION_CHECK(5, 15, 1))
|
2017-01-28 02:20:15 +03:00
|
|
|
QRegExp rx(Const::SCRIPT_RX);
|
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
if (context.contains(rx)) {
|
2021-08-24 10:22:30 +03:00
|
|
|
#else
|
2022-07-16 02:33:39 +03:00
|
|
|
QRegularExpression rx = getScriptRegEx();
|
2024-09-04 17:31:16 +03:00
|
|
|
if (context.contains(rx)) {
|
2021-08-24 10:22:30 +03:00
|
|
|
#endif
|
2017-01-28 02:20:15 +03:00
|
|
|
|
2019-09-09 21:25:08 +03:00
|
|
|
if (ScriptEngineManager::instance().dataManager() != dataManager())
|
2017-01-28 02:20:15 +03:00
|
|
|
ScriptEngineManager::instance().setDataManager(dataManager());
|
|
|
|
|
2017-02-11 00:21:03 +03:00
|
|
|
ScriptEngineType* se = ScriptEngineManager::instance().scriptEngine();
|
2017-01-28 02:20:15 +03:00
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
if (reportItem) {
|
2017-02-11 00:21:03 +03:00
|
|
|
ScriptValueType svThis;
|
|
|
|
#ifdef USE_QJSENGINE
|
2018-05-08 10:52:23 +03:00
|
|
|
svThis = getJSValue(*se, reportItem);
|
2024-09-04 17:31:16 +03:00
|
|
|
se->globalObject().setProperty("THIS", svThis);
|
2017-02-11 00:21:03 +03:00
|
|
|
#else
|
|
|
|
svThis = se->globalObject().property("THIS");
|
2024-09-04 17:31:16 +03:00
|
|
|
if (svThis.isValid()) {
|
2017-02-11 00:21:03 +03:00
|
|
|
se->newQObject(svThis, reportItem);
|
2017-01-28 02:20:15 +03:00
|
|
|
} else {
|
2017-02-11 00:21:03 +03:00
|
|
|
svThis = se->newQObject(reportItem);
|
2024-09-04 17:31:16 +03:00
|
|
|
se->globalObject().setProperty("THIS", svThis);
|
2017-01-28 02:20:15 +03:00
|
|
|
}
|
2017-02-11 00:21:03 +03:00
|
|
|
#endif
|
2017-01-28 02:20:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
ScriptExtractor scriptExtractor(context);
|
2024-09-04 17:31:16 +03:00
|
|
|
if (scriptExtractor.parse()) {
|
|
|
|
context
|
|
|
|
= replaceScripts(context, varValue, reportItem, se, scriptExtractor.scriptTree());
|
2019-09-09 21:25:08 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return context;
|
|
|
|
}
|
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
QString ScriptEngineManager::replaceScripts(QString context, QVariant& varValue,
|
|
|
|
QObject* reportItem, ScriptEngineType* se,
|
|
|
|
ScriptNode::Ptr scriptTree)
|
2019-09-09 21:25:08 +03:00
|
|
|
{
|
2024-09-04 17:31:16 +03:00
|
|
|
foreach (ScriptNode::Ptr item, scriptTree->children()) {
|
2019-09-09 21:25:08 +03:00
|
|
|
QString scriptBody = expandDataFields(item->body(), EscapeSymbols, varValue, reportItem);
|
|
|
|
if (item->children().size() > 0)
|
|
|
|
scriptBody = replaceScripts(scriptBody, varValue, reportItem, se, item);
|
|
|
|
scriptBody = expandUserVariables(scriptBody, FirstPass, EscapeSymbols, varValue);
|
|
|
|
ScriptValueType value = se->evaluate(scriptBody);
|
2017-02-11 00:21:03 +03:00
|
|
|
#ifdef USE_QJSENGINE
|
2024-09-04 17:31:16 +03:00
|
|
|
if (!value.isError()) {
|
2019-09-09 21:25:08 +03:00
|
|
|
varValue = value.toVariant();
|
|
|
|
context.replace(item->script(), value.toString());
|
|
|
|
} else {
|
|
|
|
context.replace(item->script(), value.toString());
|
|
|
|
}
|
2017-02-11 00:21:03 +03:00
|
|
|
#else
|
2019-09-09 21:25:08 +03:00
|
|
|
if (!se->hasUncaughtException()) {
|
|
|
|
varValue = value.toVariant();
|
2019-09-09 22:33:13 +03:00
|
|
|
context.replace(item->script(), value.toString());
|
2019-09-09 21:25:08 +03:00
|
|
|
} else {
|
2019-09-09 22:33:13 +03:00
|
|
|
context.replace(item->script(), se->uncaughtException().toString());
|
2017-01-28 02:20:15 +03:00
|
|
|
}
|
2019-09-09 21:25:08 +03:00
|
|
|
#endif
|
2017-01-28 02:20:15 +03:00
|
|
|
}
|
|
|
|
return context;
|
|
|
|
}
|
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
QVariant ScriptEngineManager::evaluateScript(const QString& script)
|
|
|
|
{
|
2017-01-28 02:20:15 +03:00
|
|
|
|
2021-12-16 00:13:39 +03:00
|
|
|
#if (QT_VERSION < QT_VERSION_CHECK(5, 15, 1))
|
2017-01-28 02:20:15 +03:00
|
|
|
QRegExp rx(Const::SCRIPT_RX);
|
|
|
|
QVariant varValue;
|
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
if (script.contains(rx)) {
|
|
|
|
#else
|
2022-07-16 02:33:39 +03:00
|
|
|
QRegularExpression rx = getScriptRegEx();
|
2021-08-24 10:22:30 +03:00
|
|
|
QVariant varValue;
|
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
if (script.contains(rx)) {
|
2021-08-24 10:22:30 +03:00
|
|
|
#endif
|
2017-01-28 02:20:15 +03:00
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
if (ScriptEngineManager::instance().dataManager() != dataManager())
|
2017-01-28 02:20:15 +03:00
|
|
|
ScriptEngineManager::instance().setDataManager(dataManager());
|
|
|
|
|
2017-02-11 00:21:03 +03:00
|
|
|
ScriptEngineType* se = ScriptEngineManager::instance().scriptEngine();
|
2017-01-28 02:20:15 +03:00
|
|
|
|
|
|
|
ScriptExtractor scriptExtractor(script);
|
2024-09-04 17:31:16 +03:00
|
|
|
if (scriptExtractor.parse()) {
|
|
|
|
QString scriptBody = expandDataFields(scriptExtractor.scriptTree()->body(),
|
|
|
|
EscapeSymbols, varValue, 0);
|
2017-01-28 02:20:15 +03:00
|
|
|
scriptBody = expandUserVariables(scriptBody, FirstPass, EscapeSymbols, varValue);
|
2017-02-11 00:21:03 +03:00
|
|
|
ScriptValueType value = se->evaluate(scriptBody);
|
|
|
|
#ifdef USE_QJSENGINE
|
2024-09-04 17:31:16 +03:00
|
|
|
if (!value.isError()) {
|
2017-02-11 00:21:03 +03:00
|
|
|
#else
|
2017-01-28 02:20:15 +03:00
|
|
|
if (!se->hasUncaughtException()) {
|
2017-02-11 00:21:03 +03:00
|
|
|
#endif
|
2017-01-28 02:20:15 +03:00
|
|
|
return value.toVariant();
|
2016-02-17 10:28:27 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2017-01-28 02:20:15 +03:00
|
|
|
return QVariant();
|
2016-02-17 10:28:27 +03:00
|
|
|
}
|
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
void ScriptEngineManager::addBookMark(const QString& uniqKey, const QString& content)
|
|
|
|
{
|
2017-08-25 18:01:59 +03:00
|
|
|
Q_ASSERT(m_context != 0);
|
2024-09-04 17:31:16 +03:00
|
|
|
if (m_context) {
|
2021-04-12 20:22:34 +03:00
|
|
|
BandDesignIntf* currentBand = m_context->currentBand();
|
2017-08-25 18:01:59 +03:00
|
|
|
if (currentBand)
|
|
|
|
currentBand->addBookmark(uniqKey, content);
|
2021-04-12 20:22:34 +03:00
|
|
|
else if (m_context->currentPage()) {
|
|
|
|
m_context->currentPage()->addBookmark(uniqKey, content);
|
2019-02-12 22:45:35 +03:00
|
|
|
}
|
2017-08-25 18:01:59 +03:00
|
|
|
}
|
2019-03-06 22:16:30 +03:00
|
|
|
}
|
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
int ScriptEngineManager::findPageIndexByBookmark(const QString& uniqKey)
|
2019-03-06 22:16:30 +03:00
|
|
|
{
|
2024-09-04 17:31:16 +03:00
|
|
|
for (int i = 0; i < m_context->reportPages()->size(); ++i) {
|
2019-03-06 22:16:30 +03:00
|
|
|
if (m_context->reportPages()->at(i)->bookmarks().contains(uniqKey))
|
2024-09-04 17:31:16 +03:00
|
|
|
return i + 1;
|
|
|
|
foreach (BandDesignIntf* band, m_context->reportPages()->at(i)->bands()) {
|
2019-03-06 22:16:30 +03:00
|
|
|
if (band->bookmarks().contains(uniqKey))
|
2024-09-04 17:31:16 +03:00
|
|
|
return i + 1;
|
2019-03-06 22:16:30 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
int ScriptEngineManager::getPageFreeSpace(PageItemDesignIntf* page)
|
|
|
|
{
|
|
|
|
if (page) {
|
2021-04-12 20:22:34 +03:00
|
|
|
int height = 0;
|
2024-09-04 17:31:16 +03:00
|
|
|
foreach (BandDesignIntf* band, page->bands()) {
|
|
|
|
if (band->type() == BandDesignIntf::Data) {
|
|
|
|
height += band->geometry().height()
|
|
|
|
* m_dataManager->dataSource(band->datasourceName())->model()->rowCount();
|
|
|
|
} else
|
|
|
|
height += band->height();
|
2021-04-12 20:22:34 +03:00
|
|
|
}
|
2024-09-04 17:31:16 +03:00
|
|
|
return page->height() - height - (page->pageFooter() ? page->pageFooter()->height() : 0);
|
|
|
|
} else
|
|
|
|
return -1;
|
2021-04-12 20:22:34 +03:00
|
|
|
}
|
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
void ScriptEngineManager::addTableOfContentsItem(const QString& uniqKey, const QString& content,
|
|
|
|
int indent)
|
2019-03-06 22:16:30 +03:00
|
|
|
{
|
|
|
|
Q_ASSERT(m_context != 0);
|
2024-09-04 17:31:16 +03:00
|
|
|
if (m_context) {
|
2019-03-06 22:16:30 +03:00
|
|
|
m_context->tableOfContents()->setItem(uniqKey, content, 0, indent);
|
|
|
|
addBookMark(uniqKey, content);
|
|
|
|
}
|
2017-08-25 18:01:59 +03:00
|
|
|
}
|
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
void ScriptEngineManager::clearTableOfContents()
|
|
|
|
{
|
2017-08-25 18:01:59 +03:00
|
|
|
if (m_context) {
|
2017-11-04 21:17:49 +03:00
|
|
|
if (m_context->tableOfContents())
|
|
|
|
m_context->tableOfContents()->clear();
|
2017-08-25 18:01:59 +03:00
|
|
|
}
|
2017-08-18 22:55:29 +03:00
|
|
|
}
|
|
|
|
|
2019-01-30 01:53:21 +03:00
|
|
|
ScriptValueType ScriptEngineManager::moveQObjectToScript(QObject* object, const QString objectName)
|
2022-03-29 15:33:34 +03:00
|
|
|
{
|
2019-01-30 22:50:22 +03:00
|
|
|
ScriptValueType obj = scriptEngine()->globalObject().property(objectName);
|
2024-09-04 17:31:16 +03:00
|
|
|
if (!obj.isNull())
|
|
|
|
delete obj.toQObject();
|
2019-01-30 01:53:21 +03:00
|
|
|
ScriptValueType result = scriptEngine()->newQObject(object);
|
|
|
|
scriptEngine()->globalObject().setProperty(objectName, result);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
void ScriptEngineManager::updateModel() { }
|
2016-06-10 18:05:18 +03:00
|
|
|
|
2016-11-01 20:42:45 +03:00
|
|
|
bool ScriptEngineManager::createLineFunction()
|
|
|
|
{
|
|
|
|
JSFunctionDesc fd;
|
|
|
|
|
|
|
|
fd.setManager(m_functionManager);
|
|
|
|
fd.setManagerName(LimeReport::Const::FUNCTION_MANAGER_NAME);
|
2017-06-29 03:04:30 +03:00
|
|
|
fd.setCategory(tr("SYSTEM"));
|
2016-11-01 20:42:45 +03:00
|
|
|
fd.setName("line");
|
2024-09-04 17:31:16 +03:00
|
|
|
fd.setDescription("line(\"" + tr("BandName") + "\")");
|
|
|
|
fd.setScriptWrapper(QString("function line(bandName){ return %1.line(bandName);}")
|
|
|
|
.arg(LimeReport::Const::FUNCTION_MANAGER_NAME));
|
2016-11-01 20:42:45 +03:00
|
|
|
|
|
|
|
return addFunction(fd);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ScriptEngineManager::createNumberFomatFunction()
|
|
|
|
{
|
|
|
|
JSFunctionDesc fd;
|
|
|
|
|
|
|
|
fd.setManager(m_functionManager);
|
|
|
|
fd.setManagerName(LimeReport::Const::FUNCTION_MANAGER_NAME);
|
2017-06-29 03:04:30 +03:00
|
|
|
fd.setCategory(tr("NUMBER"));
|
2016-11-01 20:42:45 +03:00
|
|
|
fd.setName("numberFormat");
|
2024-09-04 17:31:16 +03:00
|
|
|
fd.setDescription("numberFormat(\"" + tr("Value") + "\",\"" + tr("Format") + "\",\""
|
|
|
|
+ tr("Precision") + "\",\"" + tr("Locale") + "\")");
|
2016-11-01 20:42:45 +03:00
|
|
|
fd.setScriptWrapper(QString("function numberFormat(value, format, precision, locale){"
|
|
|
|
" if(typeof(format)==='undefined') format = \"f\"; "
|
|
|
|
" if(typeof(precision)==='undefined') precision=2; "
|
|
|
|
" if(typeof(locale)==='undefined') locale=\"\"; "
|
2024-09-04 17:31:16 +03:00
|
|
|
"return %1.numberFormat(value,format,precision,locale);}")
|
|
|
|
.arg(LimeReport::Const::FUNCTION_MANAGER_NAME));
|
2016-11-01 20:42:45 +03:00
|
|
|
return addFunction(fd);
|
|
|
|
}
|
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
bool ScriptEngineManager::createDateFormatFunction()
|
|
|
|
{
|
2016-11-01 20:42:45 +03:00
|
|
|
JSFunctionDesc fd;
|
|
|
|
|
|
|
|
fd.setManager(m_functionManager);
|
|
|
|
fd.setManagerName(LimeReport::Const::FUNCTION_MANAGER_NAME);
|
2017-06-29 03:04:30 +03:00
|
|
|
fd.setCategory(tr("DATE&TIME"));
|
2016-11-01 20:42:45 +03:00
|
|
|
fd.setName("dateFormat");
|
2024-09-04 17:31:16 +03:00
|
|
|
fd.setDescription("dateFormat(\"" + tr("Value") + "\",\"" + tr("Format") + "\", \""
|
|
|
|
+ tr("Locale") + "\")");
|
2019-07-01 17:01:55 +03:00
|
|
|
fd.setScriptWrapper(QString("function dateFormat(value, format, locale){"
|
2016-11-01 20:42:45 +03:00
|
|
|
" if(typeof(format)==='undefined') format = \"dd.MM.yyyy\"; "
|
2024-09-04 17:31:16 +03:00
|
|
|
"return %1.dateFormat(value,format, locale);}")
|
|
|
|
.arg(LimeReport::Const::FUNCTION_MANAGER_NAME));
|
2016-11-01 20:42:45 +03:00
|
|
|
return addFunction(fd);
|
|
|
|
}
|
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
bool ScriptEngineManager::createTimeFormatFunction()
|
|
|
|
{
|
2016-11-01 20:42:45 +03:00
|
|
|
JSFunctionDesc fd;
|
|
|
|
|
|
|
|
fd.setManager(m_functionManager);
|
|
|
|
fd.setManagerName(LimeReport::Const::FUNCTION_MANAGER_NAME);
|
2017-06-29 03:04:30 +03:00
|
|
|
fd.setCategory(tr("DATE&TIME"));
|
2016-11-01 20:42:45 +03:00
|
|
|
fd.setName("timeFormat");
|
2024-09-04 17:31:16 +03:00
|
|
|
fd.setDescription("timeFormat(\"" + tr("Value") + "\",\"" + tr("Format") + "\")");
|
2016-11-01 20:42:45 +03:00
|
|
|
fd.setScriptWrapper(QString("function timeFormat(value, format){"
|
|
|
|
" if(typeof(format)==='undefined') format = \"hh:mm\"; "
|
2024-09-04 17:31:16 +03:00
|
|
|
"return %1.timeFormat(value,format);}")
|
|
|
|
.arg(LimeReport::Const::FUNCTION_MANAGER_NAME));
|
2016-11-01 20:42:45 +03:00
|
|
|
return addFunction(fd);
|
|
|
|
}
|
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
bool ScriptEngineManager::createDateTimeFormatFunction()
|
|
|
|
{
|
2016-11-01 20:42:45 +03:00
|
|
|
JSFunctionDesc fd;
|
|
|
|
|
|
|
|
fd.setManager(m_functionManager);
|
|
|
|
fd.setManagerName(LimeReport::Const::FUNCTION_MANAGER_NAME);
|
2017-06-29 03:04:30 +03:00
|
|
|
fd.setCategory(tr("DATE&TIME"));
|
2016-11-01 20:42:45 +03:00
|
|
|
fd.setName("dateTimeFormat");
|
2024-09-04 17:31:16 +03:00
|
|
|
fd.setDescription("dateTimeFormat(\"" + tr("Value") + "\",\"" + tr("Format") + "\", \""
|
|
|
|
+ tr("Locale") + "\")");
|
2019-07-01 17:01:55 +03:00
|
|
|
fd.setScriptWrapper(QString("function dateTimeFormat(value, format, locale){"
|
2016-11-01 20:42:45 +03:00
|
|
|
" if(typeof(format)==='undefined') format = \"dd.MM.yyyy hh:mm\"; "
|
2024-09-04 17:31:16 +03:00
|
|
|
"return %1.dateTimeFormat(value, format, locale);}")
|
|
|
|
.arg(LimeReport::Const::FUNCTION_MANAGER_NAME));
|
2016-11-01 20:42:45 +03:00
|
|
|
return addFunction(fd);
|
|
|
|
}
|
|
|
|
|
2017-12-22 12:36:46 +03:00
|
|
|
bool ScriptEngineManager::createSectotimeFormatFunction()
|
|
|
|
{
|
|
|
|
JSFunctionDesc fd;
|
|
|
|
|
|
|
|
fd.setManager(m_functionManager);
|
|
|
|
fd.setManagerName(LimeReport::Const::FUNCTION_MANAGER_NAME);
|
|
|
|
fd.setCategory(tr("DATE&TIME"));
|
|
|
|
fd.setName("sectotimeFormat");
|
2024-09-04 17:31:16 +03:00
|
|
|
fd.setDescription("sectotimeFormat(\"" + tr("Value") + "\",\"" + tr("Format") + "\")");
|
2017-12-22 12:36:46 +03:00
|
|
|
fd.setScriptWrapper(QString("function sectotimeFormat(value, format){"
|
|
|
|
" if(typeof(format)==='undefined') format = \"hh:mm:ss\"; "
|
2024-09-04 17:31:16 +03:00
|
|
|
"return %1.sectotimeFormat(value,format);}")
|
|
|
|
.arg(LimeReport::Const::FUNCTION_MANAGER_NAME));
|
2017-12-22 12:36:46 +03:00
|
|
|
return addFunction(fd);
|
|
|
|
}
|
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
bool ScriptEngineManager::createDateFunction()
|
|
|
|
{
|
2022-03-29 15:33:34 +03:00
|
|
|
// addFunction("date",date,"DATE&TIME","date()");
|
2016-11-01 20:42:45 +03:00
|
|
|
JSFunctionDesc fd;
|
|
|
|
|
|
|
|
fd.setManager(m_functionManager);
|
|
|
|
fd.setManagerName(LimeReport::Const::FUNCTION_MANAGER_NAME);
|
2017-06-29 03:04:30 +03:00
|
|
|
fd.setCategory(tr("DATE&TIME"));
|
2016-11-01 20:42:45 +03:00
|
|
|
fd.setName("date");
|
|
|
|
fd.setDescription("date()");
|
|
|
|
fd.setScriptWrapper(QString("function date(){"
|
2024-09-04 17:31:16 +03:00
|
|
|
"return %1.date();}")
|
|
|
|
.arg(LimeReport::Const::FUNCTION_MANAGER_NAME));
|
2016-11-01 20:42:45 +03:00
|
|
|
return addFunction(fd);
|
|
|
|
}
|
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
bool ScriptEngineManager::createNowFunction()
|
|
|
|
{
|
2022-03-29 15:33:34 +03:00
|
|
|
// addFunction("now",now,"DATE&TIME","now()");
|
2016-11-01 20:42:45 +03:00
|
|
|
JSFunctionDesc fd;
|
|
|
|
|
|
|
|
fd.setManager(m_functionManager);
|
|
|
|
fd.setManagerName(LimeReport::Const::FUNCTION_MANAGER_NAME);
|
2017-06-29 03:04:30 +03:00
|
|
|
fd.setCategory(tr("DATE&TIME"));
|
2016-11-01 20:42:45 +03:00
|
|
|
fd.setName("now");
|
|
|
|
fd.setDescription("now()");
|
|
|
|
fd.setScriptWrapper(QString("function now(){"
|
2024-09-04 17:31:16 +03:00
|
|
|
"return %1.now();}")
|
|
|
|
.arg(LimeReport::Const::FUNCTION_MANAGER_NAME));
|
2016-11-01 20:42:45 +03:00
|
|
|
return addFunction(fd);
|
|
|
|
}
|
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
bool ScriptEngineManager::createCurrencyFormatFunction()
|
|
|
|
{
|
2022-03-29 15:33:34 +03:00
|
|
|
// addFunction("currencyFormat",currencyFormat,"NUMBER","currencyFormat(\""+tr("Value")+"\",\""+tr("Locale")+"\")");
|
2016-11-01 20:42:45 +03:00
|
|
|
JSFunctionDesc fd;
|
|
|
|
|
|
|
|
fd.setManager(m_functionManager);
|
|
|
|
fd.setManagerName(LimeReport::Const::FUNCTION_MANAGER_NAME);
|
2017-06-29 03:04:30 +03:00
|
|
|
fd.setCategory(tr("NUMBER"));
|
2016-11-01 20:42:45 +03:00
|
|
|
fd.setName("currencyFormat");
|
2024-09-04 17:31:16 +03:00
|
|
|
fd.setDescription("currencyFormat(\"" + tr("Value") + "\",\"" + tr("Locale") + "\")");
|
2016-11-01 20:42:45 +03:00
|
|
|
fd.setScriptWrapper(QString("function currencyFormat(value, locale){"
|
|
|
|
" if(typeof(locale)==='undefined') locale = \"\"; "
|
2024-09-04 17:31:16 +03:00
|
|
|
"return %1.currencyFormat(value,locale);}")
|
|
|
|
.arg(LimeReport::Const::FUNCTION_MANAGER_NAME));
|
2016-11-01 20:42:45 +03:00
|
|
|
return addFunction(fd);
|
|
|
|
}
|
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
bool ScriptEngineManager::createCurrencyUSBasedFormatFunction()
|
|
|
|
{
|
2022-03-29 15:33:34 +03:00
|
|
|
// addFunction("currencyUSBasedFormat",currencyUSBasedFormat,"NUMBER","currencyUSBasedFormat(\""+tr("Value")+",\""+tr("CurrencySymbol")+"\")");
|
2016-11-01 20:42:45 +03:00
|
|
|
JSFunctionDesc fd;
|
|
|
|
|
|
|
|
fd.setManager(m_functionManager);
|
|
|
|
fd.setManagerName(LimeReport::Const::FUNCTION_MANAGER_NAME);
|
2017-06-29 03:04:30 +03:00
|
|
|
fd.setCategory(tr("NUMBER"));
|
2016-11-01 20:42:45 +03:00
|
|
|
fd.setName("currencyUSBasedFormat");
|
2024-09-04 17:31:16 +03:00
|
|
|
fd.setDescription("currencyUSBasedFormat(\"" + tr("Value") + ",\"" + tr("CurrencySymbol")
|
|
|
|
+ "\")");
|
2016-11-01 20:42:45 +03:00
|
|
|
fd.setScriptWrapper(QString("function currencyUSBasedFormat(value, currencySymbol){"
|
|
|
|
" if(typeof(currencySymbol)==='undefined') currencySymbol = \"\"; "
|
2024-09-04 17:31:16 +03:00
|
|
|
"return %1.currencyUSBasedFormat(value,currencySymbol);}")
|
|
|
|
.arg(LimeReport::Const::FUNCTION_MANAGER_NAME));
|
2016-11-01 20:42:45 +03:00
|
|
|
return addFunction(fd);
|
|
|
|
}
|
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
bool ScriptEngineManager::createSetVariableFunction()
|
|
|
|
{
|
|
|
|
// addFunction("setVariable", setVariable, "GENERAL",
|
|
|
|
// "setVariable(\""+tr("Name")+"\",\""+tr("Value")+"\")");
|
2016-11-01 20:42:45 +03:00
|
|
|
JSFunctionDesc fd;
|
|
|
|
|
|
|
|
fd.setManager(m_functionManager);
|
|
|
|
fd.setManagerName(LimeReport::Const::FUNCTION_MANAGER_NAME);
|
2017-06-29 03:04:30 +03:00
|
|
|
fd.setCategory(tr("GENERAL"));
|
2016-11-01 20:42:45 +03:00
|
|
|
fd.setName("setVariable");
|
2024-09-04 17:31:16 +03:00
|
|
|
fd.setDescription("setVariable(\"" + tr("Name") + "\",\"" + tr("Value") + "\")");
|
2016-11-01 20:42:45 +03:00
|
|
|
fd.setScriptWrapper(QString("function setVariable(name, value){"
|
2024-09-04 17:31:16 +03:00
|
|
|
"return %1.setVariable(name,value);}")
|
|
|
|
.arg(LimeReport::Const::FUNCTION_MANAGER_NAME));
|
2016-11-01 20:42:45 +03:00
|
|
|
return addFunction(fd);
|
|
|
|
}
|
|
|
|
|
2017-02-11 00:21:03 +03:00
|
|
|
bool ScriptEngineManager::createGetVariableFunction()
|
|
|
|
{
|
|
|
|
JSFunctionDesc fd;
|
|
|
|
fd.setManager(m_functionManager);
|
|
|
|
fd.setManagerName(LimeReport::Const::FUNCTION_MANAGER_NAME);
|
2017-06-29 03:04:30 +03:00
|
|
|
fd.setCategory(tr("GENERAL"));
|
2017-02-11 00:21:03 +03:00
|
|
|
fd.setName("getVariable");
|
2024-09-04 17:31:16 +03:00
|
|
|
fd.setDescription("getVariable(\"" + tr("Name") + "\")");
|
2017-02-11 00:21:03 +03:00
|
|
|
fd.setScriptWrapper(QString("function getVariable(name){"
|
2024-09-04 17:31:16 +03:00
|
|
|
"return %1.getVariable(name);}")
|
|
|
|
.arg(LimeReport::Const::FUNCTION_MANAGER_NAME));
|
2017-02-11 00:21:03 +03:00
|
|
|
return addFunction(fd);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ScriptEngineManager::createGetFieldFunction()
|
|
|
|
{
|
|
|
|
JSFunctionDesc fd;
|
|
|
|
fd.setManager(m_functionManager);
|
|
|
|
fd.setManagerName(LimeReport::Const::FUNCTION_MANAGER_NAME);
|
2017-06-29 03:04:30 +03:00
|
|
|
fd.setCategory(tr("GENERAL"));
|
2017-02-11 00:21:03 +03:00
|
|
|
fd.setName("getField");
|
2024-09-04 17:31:16 +03:00
|
|
|
fd.setDescription("getField(\"" + tr("Name") + "\")");
|
2017-02-11 00:21:03 +03:00
|
|
|
fd.setScriptWrapper(QString("function getField(name){"
|
2024-09-04 17:31:16 +03:00
|
|
|
"return %1.getField(name);}")
|
|
|
|
.arg(LimeReport::Const::FUNCTION_MANAGER_NAME));
|
2017-02-11 00:21:03 +03:00
|
|
|
return addFunction(fd);
|
|
|
|
}
|
|
|
|
|
2017-08-31 02:53:34 +03:00
|
|
|
bool ScriptEngineManager::createGetFieldByKeyFunction()
|
|
|
|
{
|
|
|
|
JSFunctionDesc fd;
|
|
|
|
fd.setManager(m_functionManager);
|
|
|
|
fd.setManagerName(LimeReport::Const::FUNCTION_MANAGER_NAME);
|
|
|
|
fd.setCategory(tr("GENERAL"));
|
|
|
|
fd.setName("getFieldByKeyField");
|
2024-09-04 17:31:16 +03:00
|
|
|
fd.setDescription("getFieldByKeyField(\"" + tr("Datasource") + "\", \"" + tr("ValueField")
|
|
|
|
+ "\",\"" + tr("KeyField") + "\", \"" + tr("KeyFieldValue") + "\")");
|
|
|
|
fd.setScriptWrapper(
|
|
|
|
QString("function getFieldByKeyField(datasource, valueFieldName, keyFieldName, keyValue){"
|
|
|
|
"return %1.getFieldByKeyField(datasource, valueFieldName, keyFieldName, "
|
|
|
|
"keyValue);}")
|
|
|
|
.arg(LimeReport::Const::FUNCTION_MANAGER_NAME));
|
2017-08-31 02:53:34 +03:00
|
|
|
return addFunction(fd);
|
|
|
|
}
|
|
|
|
|
2019-02-19 02:23:53 +03:00
|
|
|
bool ScriptEngineManager::createGetFieldByRowIndex()
|
|
|
|
{
|
|
|
|
JSFunctionDesc fd;
|
|
|
|
fd.setManager(m_functionManager);
|
|
|
|
fd.setManagerName(LimeReport::Const::FUNCTION_MANAGER_NAME);
|
|
|
|
fd.setCategory(tr("GENERAL"));
|
|
|
|
fd.setName("getFieldByRowIndex");
|
2024-09-04 17:31:16 +03:00
|
|
|
fd.setDescription("getFieldByRowIndex(\"" + tr("FieldName") + "\", \"" + tr("RowIndex")
|
|
|
|
+ "\")");
|
2019-02-19 02:23:53 +03:00
|
|
|
fd.setScriptWrapper(QString("function getFieldByRowIndex(fieldName, rowIndex){"
|
2024-09-04 17:31:16 +03:00
|
|
|
"return %1.getFieldByRowIndex(fieldName, rowIndex);}")
|
|
|
|
.arg(LimeReport::Const::FUNCTION_MANAGER_NAME));
|
2019-02-19 02:23:53 +03:00
|
|
|
return addFunction(fd);
|
|
|
|
}
|
|
|
|
|
2019-03-06 22:16:30 +03:00
|
|
|
bool ScriptEngineManager::createAddBookmarkFunction()
|
|
|
|
{
|
|
|
|
JSFunctionDesc fd;
|
|
|
|
fd.setManager(m_functionManager);
|
|
|
|
fd.setManagerName(LimeReport::Const::FUNCTION_MANAGER_NAME);
|
|
|
|
fd.setCategory(tr("GENERAL"));
|
|
|
|
fd.setName("addBookmark");
|
2024-09-04 17:31:16 +03:00
|
|
|
fd.setDescription("addBookmark(\"" + tr("Unique identifier") + " \"" + tr("Content") + "\")");
|
2019-03-06 22:16:30 +03:00
|
|
|
fd.setScriptWrapper(QString("function addBookmark(uniqKey, content){"
|
2024-09-04 17:31:16 +03:00
|
|
|
"return %1.addBookmark(uniqKey, content);}")
|
|
|
|
.arg(LimeReport::Const::FUNCTION_MANAGER_NAME));
|
2019-03-06 22:16:30 +03:00
|
|
|
return addFunction(fd);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ScriptEngineManager::createFindPageIndexByBookmark()
|
|
|
|
{
|
|
|
|
JSFunctionDesc fd;
|
|
|
|
fd.setManager(m_functionManager);
|
|
|
|
fd.setManagerName(LimeReport::Const::FUNCTION_MANAGER_NAME);
|
|
|
|
fd.setCategory(tr("GENERAL"));
|
|
|
|
fd.setName("findPageIndexByBookmark");
|
2024-09-04 17:31:16 +03:00
|
|
|
fd.setDescription("findPageIndexByBookmark(\"" + tr("Unique identifier") + "\")");
|
2019-03-06 22:16:30 +03:00
|
|
|
fd.setScriptWrapper(QString("function findPageIndexByBookmark(uniqKey){"
|
2024-09-04 17:31:16 +03:00
|
|
|
"return %1.findPageIndexByBookmark(uniqKey);}")
|
|
|
|
.arg(LimeReport::Const::FUNCTION_MANAGER_NAME));
|
2019-03-06 22:16:30 +03:00
|
|
|
return addFunction(fd);
|
|
|
|
}
|
|
|
|
|
2017-11-04 21:17:49 +03:00
|
|
|
bool ScriptEngineManager::createAddTableOfContentsItemFunction()
|
2017-08-18 22:55:29 +03:00
|
|
|
{
|
|
|
|
JSFunctionDesc fd;
|
|
|
|
fd.setManager(m_functionManager);
|
|
|
|
fd.setManagerName(LimeReport::Const::FUNCTION_MANAGER_NAME);
|
|
|
|
fd.setCategory(tr("GENERAL"));
|
2017-11-04 21:17:49 +03:00
|
|
|
fd.setName("addTableOfContentsItem");
|
2024-09-04 17:31:16 +03:00
|
|
|
fd.setDescription("addTableOfContentsItem(\"" + tr("Unique identifier") + " \"" + tr("Content")
|
|
|
|
+ "\", \"" + tr("Indent") + "\")");
|
2017-11-04 21:17:49 +03:00
|
|
|
fd.setScriptWrapper(QString("function addTableOfContentsItem(uniqKey, content, indent){"
|
2024-09-04 17:31:16 +03:00
|
|
|
"return %1.addTableOfContentsItem(uniqKey, content, indent);}")
|
|
|
|
.arg(LimeReport::Const::FUNCTION_MANAGER_NAME));
|
2017-08-18 22:55:29 +03:00
|
|
|
return addFunction(fd);
|
|
|
|
}
|
|
|
|
|
2017-11-04 21:17:49 +03:00
|
|
|
bool ScriptEngineManager::createClearTableOfContentsFunction()
|
2017-08-18 22:55:29 +03:00
|
|
|
{
|
|
|
|
JSFunctionDesc fd;
|
|
|
|
fd.setManager(m_functionManager);
|
|
|
|
fd.setManagerName(LimeReport::Const::FUNCTION_MANAGER_NAME);
|
|
|
|
fd.setCategory(tr("GENERAL"));
|
2017-11-04 21:17:49 +03:00
|
|
|
fd.setName("clearTableOfContents");
|
|
|
|
fd.setDescription("clearTableOfContents()");
|
|
|
|
fd.setScriptWrapper(QString("function clearTableOfContents(){"
|
2024-09-04 17:31:16 +03:00
|
|
|
"return %1.clearTableOfContents();}")
|
|
|
|
.arg(LimeReport::Const::FUNCTION_MANAGER_NAME));
|
2017-08-18 22:55:29 +03:00
|
|
|
return addFunction(fd);
|
|
|
|
}
|
|
|
|
|
2017-09-19 21:02:55 +03:00
|
|
|
bool ScriptEngineManager::createReopenDatasourceFunction()
|
|
|
|
{
|
|
|
|
JSFunctionDesc fd;
|
|
|
|
fd.setManager(m_functionManager);
|
|
|
|
fd.setManagerName(LimeReport::Const::FUNCTION_MANAGER_NAME);
|
|
|
|
fd.setCategory(tr("GENERAL"));
|
|
|
|
fd.setName("reopenDatasource");
|
2024-09-04 17:31:16 +03:00
|
|
|
fd.setDescription("reopenDatasource(\"" + tr("datasourceName") + "\")");
|
2017-09-19 21:02:55 +03:00
|
|
|
fd.setScriptWrapper(QString("function reopenDatasource(datasourceName){"
|
2024-09-04 17:31:16 +03:00
|
|
|
"return %1.reopenDatasource(datasourceName);}")
|
|
|
|
.arg(LimeReport::Const::FUNCTION_MANAGER_NAME));
|
2017-09-19 21:02:55 +03:00
|
|
|
return addFunction(fd);
|
|
|
|
}
|
|
|
|
|
Add: added a function to get an arbitrary role of a model item
Example:
$D{appdata.Column_1}
$S{
var vRow = line('DataBand1') - 1;
// 8 - Qt::BackgroundRole
var vColor = getFieldByRowIndexEx('appdata.Column_1', vRow, 8);
THIS.backgroundColor = LimeReport.color('lightgray');
if(vColor > '')
{
THIS.backgroundColor = vColor;
}
''
}
Added several functions to get extended information from the model
- getFieldByRowIndexEx2(fieldName, rowIndex, roleName), default:
Qt::DisplayRole
- getHeaderData(fieldName, roleName), default: Qt::DisplayRole
- getHeaderColumnNameByIndex(datasourceName, columnIndex), default:
Qt::UserRole or Qt::DisplayRole
- getColumnCount(datasourceName), default: -1
2024-03-26 11:43:58 +03:00
|
|
|
bool ScriptEngineManager::createGetFieldByRowIndexEx()
|
|
|
|
{
|
|
|
|
JSFunctionDesc fd;
|
|
|
|
fd.setManager(m_functionManager);
|
|
|
|
fd.setManagerName(LimeReport::Const::FUNCTION_MANAGER_NAME);
|
|
|
|
fd.setCategory(tr("GENERAL"));
|
|
|
|
fd.setName("getFieldByRowIndexEx");
|
|
|
|
fd.setDescription("getFieldByRowIndexEx(\"" + tr("FieldName") + "\", \"" + tr("RowIndex")
|
2024-09-04 17:31:16 +03:00
|
|
|
+ "\", \"" + tr("RoleIndex") + "\")");
|
Add: added a function to get an arbitrary role of a model item
Example:
$D{appdata.Column_1}
$S{
var vRow = line('DataBand1') - 1;
// 8 - Qt::BackgroundRole
var vColor = getFieldByRowIndexEx('appdata.Column_1', vRow, 8);
THIS.backgroundColor = LimeReport.color('lightgray');
if(vColor > '')
{
THIS.backgroundColor = vColor;
}
''
}
Added several functions to get extended information from the model
- getFieldByRowIndexEx2(fieldName, rowIndex, roleName), default:
Qt::DisplayRole
- getHeaderData(fieldName, roleName), default: Qt::DisplayRole
- getHeaderColumnNameByIndex(datasourceName, columnIndex), default:
Qt::UserRole or Qt::DisplayRole
- getColumnCount(datasourceName), default: -1
2024-03-26 11:43:58 +03:00
|
|
|
fd.setScriptWrapper(QString("function getFieldByRowIndexEx(fieldName, rowIndex, role){"
|
2024-09-04 17:31:16 +03:00
|
|
|
"return %1.getFieldByRowIndexEx(fieldName, rowIndex, role);}")
|
|
|
|
.arg(LimeReport::Const::FUNCTION_MANAGER_NAME));
|
Add: added a function to get an arbitrary role of a model item
Example:
$D{appdata.Column_1}
$S{
var vRow = line('DataBand1') - 1;
// 8 - Qt::BackgroundRole
var vColor = getFieldByRowIndexEx('appdata.Column_1', vRow, 8);
THIS.backgroundColor = LimeReport.color('lightgray');
if(vColor > '')
{
THIS.backgroundColor = vColor;
}
''
}
Added several functions to get extended information from the model
- getFieldByRowIndexEx2(fieldName, rowIndex, roleName), default:
Qt::DisplayRole
- getHeaderData(fieldName, roleName), default: Qt::DisplayRole
- getHeaderColumnNameByIndex(datasourceName, columnIndex), default:
Qt::UserRole or Qt::DisplayRole
- getColumnCount(datasourceName), default: -1
2024-03-26 11:43:58 +03:00
|
|
|
return addFunction(fd);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ScriptEngineManager::createGetFieldByRowIndexEx2()
|
|
|
|
{
|
|
|
|
JSFunctionDesc fd;
|
|
|
|
fd.setManager(m_functionManager);
|
|
|
|
fd.setManagerName(LimeReport::Const::FUNCTION_MANAGER_NAME);
|
|
|
|
fd.setCategory(tr("GENERAL"));
|
|
|
|
fd.setName("getFieldByRowIndexEx2");
|
|
|
|
fd.setDescription("getFieldByRowIndexEx2(\"" + tr("FieldName") + "\", \"" + tr("RowIndex")
|
|
|
|
+ "\", \"" + tr("RoleName") + "\")");
|
|
|
|
fd.setScriptWrapper(QString("function getFieldByRowIndexEx2(fieldName, rowIndex, role){"
|
|
|
|
"return %1.getFieldByRowIndexEx2(fieldName, rowIndex, role);}")
|
|
|
|
.arg(LimeReport::Const::FUNCTION_MANAGER_NAME));
|
|
|
|
return addFunction(fd);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ScriptEngineManager::createHeaderData()
|
|
|
|
{
|
|
|
|
JSFunctionDesc fd;
|
|
|
|
fd.setManager(m_functionManager);
|
|
|
|
fd.setManagerName(LimeReport::Const::FUNCTION_MANAGER_NAME);
|
|
|
|
fd.setCategory(tr("GENERAL"));
|
|
|
|
fd.setName("getHeaderData");
|
|
|
|
fd.setDescription("getHeaderData(\"" + tr("FieldName") + "\", \"" + tr("RoleName") + "\")");
|
|
|
|
fd.setScriptWrapper(QString("function getHeaderData(fieldName, role){"
|
|
|
|
"return %1.getHeaderData(fieldName, role);}")
|
|
|
|
.arg(LimeReport::Const::FUNCTION_MANAGER_NAME));
|
|
|
|
return addFunction(fd);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ScriptEngineManager::createHeaderColumnNameByIndex()
|
|
|
|
{
|
|
|
|
JSFunctionDesc fd;
|
|
|
|
fd.setManager(m_functionManager);
|
|
|
|
fd.setManagerName(LimeReport::Const::FUNCTION_MANAGER_NAME);
|
|
|
|
fd.setCategory(tr("GENERAL"));
|
|
|
|
fd.setName("getHeaderColumnNameByIndex");
|
|
|
|
fd.setDescription("getHeaderColumnNameByIndex(\"" + tr("datasourceName") + "\", \""
|
|
|
|
+ tr("columnIndex") + "\")");
|
2024-09-04 17:31:16 +03:00
|
|
|
fd.setScriptWrapper(
|
|
|
|
QString("function getHeaderColumnNameByIndex(datasourceName, columnIndex){"
|
|
|
|
"return %1.getHeaderColumnNameByIndex(datasourceName, columnIndex);}")
|
|
|
|
.arg(LimeReport::Const::FUNCTION_MANAGER_NAME));
|
Add: added a function to get an arbitrary role of a model item
Example:
$D{appdata.Column_1}
$S{
var vRow = line('DataBand1') - 1;
// 8 - Qt::BackgroundRole
var vColor = getFieldByRowIndexEx('appdata.Column_1', vRow, 8);
THIS.backgroundColor = LimeReport.color('lightgray');
if(vColor > '')
{
THIS.backgroundColor = vColor;
}
''
}
Added several functions to get extended information from the model
- getFieldByRowIndexEx2(fieldName, rowIndex, roleName), default:
Qt::DisplayRole
- getHeaderData(fieldName, roleName), default: Qt::DisplayRole
- getHeaderColumnNameByIndex(datasourceName, columnIndex), default:
Qt::UserRole or Qt::DisplayRole
- getColumnCount(datasourceName), default: -1
2024-03-26 11:43:58 +03:00
|
|
|
return addFunction(fd);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ScriptEngineManager::createColumnCount()
|
|
|
|
{
|
|
|
|
JSFunctionDesc fd;
|
|
|
|
fd.setManager(m_functionManager);
|
|
|
|
fd.setManagerName(LimeReport::Const::FUNCTION_MANAGER_NAME);
|
|
|
|
fd.setCategory(tr("GENERAL"));
|
|
|
|
fd.setName("getColumnCount");
|
|
|
|
fd.setDescription("getColumnCount(\"" + tr("datasourceName") + "\")");
|
|
|
|
fd.setScriptWrapper(QString("function getColumnCount(datasourceName){"
|
|
|
|
"return %1.getColumnCount(datasourceName);}")
|
|
|
|
.arg(LimeReport::Const::FUNCTION_MANAGER_NAME));
|
|
|
|
return addFunction(fd);
|
|
|
|
}
|
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
ScriptEngineManager::ScriptEngineManager(): m_model(0), m_context(0), m_dataManager(0)
|
2016-02-17 10:11:00 +03:00
|
|
|
{
|
2016-11-01 20:42:45 +03:00
|
|
|
m_scriptEngine = new ScriptEngineType;
|
|
|
|
m_functionManager = new ScriptFunctionsManager(this);
|
|
|
|
m_functionManager->setScriptEngineManager(this);
|
2019-02-19 02:23:53 +03:00
|
|
|
#ifdef USE_QTSCRIPTENGINE
|
2017-09-01 02:02:51 +03:00
|
|
|
m_scriptEngine->setDefaultPrototype(qMetaTypeId<QComboBox*>(),
|
2022-03-29 15:33:34 +03:00
|
|
|
m_scriptEngine->newQObject(new ComboBoxPrototype()));
|
2017-09-01 02:02:51 +03:00
|
|
|
#endif
|
2016-11-01 20:42:45 +03:00
|
|
|
createLineFunction();
|
|
|
|
createNumberFomatFunction();
|
|
|
|
createDateFormatFunction();
|
|
|
|
createTimeFormatFunction();
|
|
|
|
createDateTimeFormatFunction();
|
2017-12-22 12:36:46 +03:00
|
|
|
createSectotimeFormatFunction();
|
2016-11-01 20:42:45 +03:00
|
|
|
createDateFunction();
|
|
|
|
createNowFunction();
|
2024-09-04 17:31:16 +03:00
|
|
|
#if QT_VERSION > 0x040800
|
2016-11-01 20:42:45 +03:00
|
|
|
createCurrencyFormatFunction();
|
|
|
|
createCurrencyUSBasedFormatFunction();
|
2016-10-03 21:56:48 +03:00
|
|
|
#endif
|
2016-11-01 20:42:45 +03:00
|
|
|
createSetVariableFunction();
|
2017-02-11 00:21:03 +03:00
|
|
|
createGetFieldFunction();
|
2019-02-19 02:23:53 +03:00
|
|
|
createGetFieldByRowIndex();
|
2017-08-31 02:53:34 +03:00
|
|
|
createGetFieldByKeyFunction();
|
2017-02-11 00:21:03 +03:00
|
|
|
createGetVariableFunction();
|
2019-02-19 02:23:53 +03:00
|
|
|
#ifdef USE_QTSCRIPTENGINE
|
2016-02-17 10:11:00 +03:00
|
|
|
QScriptValue colorCtor = m_scriptEngine->newFunction(constructColor);
|
|
|
|
m_scriptEngine->globalObject().setProperty("QColor", colorCtor);
|
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
QScriptValue fontProto(
|
|
|
|
m_scriptEngine->newQObject(new QFontPrototype, QScriptEngine::ScriptOwnership));
|
2016-02-17 10:11:00 +03:00
|
|
|
m_scriptEngine->setDefaultPrototype(qMetaTypeId<QFont>(), fontProto);
|
2024-09-04 17:31:16 +03:00
|
|
|
QScriptValue fontConstructor
|
|
|
|
= m_scriptEngine->newFunction(QFontPrototype::constructorQFont, fontProto);
|
2016-02-17 10:11:00 +03:00
|
|
|
m_scriptEngine->globalObject().setProperty("QFont", fontConstructor);
|
2016-11-01 20:42:45 +03:00
|
|
|
#endif
|
2019-03-06 22:16:30 +03:00
|
|
|
createAddBookmarkFunction();
|
|
|
|
createFindPageIndexByBookmark();
|
2017-11-04 21:17:49 +03:00
|
|
|
createAddTableOfContentsItemFunction();
|
|
|
|
createClearTableOfContentsFunction();
|
2017-09-19 21:02:55 +03:00
|
|
|
createReopenDatasourceFunction();
|
Add: added a function to get an arbitrary role of a model item
Example:
$D{appdata.Column_1}
$S{
var vRow = line('DataBand1') - 1;
// 8 - Qt::BackgroundRole
var vColor = getFieldByRowIndexEx('appdata.Column_1', vRow, 8);
THIS.backgroundColor = LimeReport.color('lightgray');
if(vColor > '')
{
THIS.backgroundColor = vColor;
}
''
}
Added several functions to get extended information from the model
- getFieldByRowIndexEx2(fieldName, rowIndex, roleName), default:
Qt::DisplayRole
- getHeaderData(fieldName, roleName), default: Qt::DisplayRole
- getHeaderColumnNameByIndex(datasourceName, columnIndex), default:
Qt::UserRole or Qt::DisplayRole
- getColumnCount(datasourceName), default: -1
2024-03-26 11:43:58 +03:00
|
|
|
createGetFieldByRowIndexEx();
|
|
|
|
createGetFieldByRowIndexEx2();
|
|
|
|
createHeaderData();
|
|
|
|
createHeaderColumnNameByIndex();
|
|
|
|
createColumnCount();
|
2016-02-17 10:11:00 +03:00
|
|
|
|
2017-08-18 22:55:29 +03:00
|
|
|
m_model = new ScriptEngineModel(this);
|
2016-02-17 10:11:00 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
bool ScriptExtractor::parse()
|
|
|
|
{
|
|
|
|
int currentPos = 0;
|
2019-09-09 21:25:08 +03:00
|
|
|
parse(currentPos, None, m_scriptTree);
|
|
|
|
return m_scriptTree->children().count() > 0;
|
2016-02-17 10:11:00 +03:00
|
|
|
}
|
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
bool ScriptExtractor::parse(int& curPos, const State& state, ScriptNode::Ptr scriptNode)
|
2016-02-17 10:11:00 +03:00
|
|
|
{
|
2024-09-04 17:31:16 +03:00
|
|
|
while (curPos < m_context.length()) {
|
2016-02-17 10:11:00 +03:00
|
|
|
switch (state) {
|
|
|
|
case OpenBracketFound:
|
2024-09-04 17:31:16 +03:00
|
|
|
if (m_context[curPos] == '}') {
|
2016-02-17 10:11:00 +03:00
|
|
|
return true;
|
|
|
|
} else {
|
2024-09-04 17:31:16 +03:00
|
|
|
if (m_context[curPos] == '{')
|
2022-03-29 15:33:34 +03:00
|
|
|
extractBracket(curPos, scriptNode);
|
2016-02-17 10:11:00 +03:00
|
|
|
}
|
|
|
|
case None:
|
2024-09-04 17:31:16 +03:00
|
|
|
if (m_context[curPos] == '$') {
|
2016-02-17 10:11:00 +03:00
|
|
|
int startPos = curPos;
|
|
|
|
if (isStartScriptLexem(curPos))
|
2024-09-04 17:31:16 +03:00
|
|
|
extractScript(curPos, substring(m_context, startPos, curPos),
|
|
|
|
scriptNode->createChildNode());
|
2016-02-17 10:11:00 +03:00
|
|
|
if (isStartFieldLexem(curPos) || isStartVariableLexem(curPos))
|
|
|
|
skipField(curPos);
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
curPos++;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
void ScriptExtractor::extractScript(int& curPos, const QString& startStr,
|
|
|
|
ScriptNode::Ptr scriptNode)
|
2016-02-17 10:11:00 +03:00
|
|
|
{
|
|
|
|
int startPos = curPos;
|
2024-09-04 17:31:16 +03:00
|
|
|
if (extractBracket(curPos, scriptNode)) {
|
|
|
|
QString scriptBody = substring(m_context, startPos + 1, curPos);
|
2019-09-09 21:25:08 +03:00
|
|
|
scriptNode->setBody(scriptBody);
|
2024-09-04 17:31:16 +03:00
|
|
|
scriptNode->setStartLex(startStr + '{');
|
2016-02-17 10:11:00 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
void ScriptExtractor::skipField(int& curPos)
|
|
|
|
{
|
|
|
|
while (curPos < m_context.length()) {
|
|
|
|
if (m_context[curPos] == '}') {
|
2016-02-17 10:11:00 +03:00
|
|
|
return;
|
|
|
|
} else {
|
|
|
|
curPos++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
bool ScriptExtractor::extractBracket(int& curPos, ScriptNode::Ptr scriptNode)
|
2016-02-17 10:11:00 +03:00
|
|
|
{
|
|
|
|
curPos++;
|
2024-09-04 17:31:16 +03:00
|
|
|
return parse(curPos, OpenBracketFound, scriptNode);
|
2016-02-17 10:11:00 +03:00
|
|
|
}
|
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
bool ScriptExtractor::isStartLexem(int& curPos, QChar value)
|
|
|
|
{
|
|
|
|
int pos = curPos + 1;
|
2016-02-17 10:11:00 +03:00
|
|
|
State ls = BuksFound;
|
2024-09-04 17:31:16 +03:00
|
|
|
while (pos < m_context.length()) {
|
|
|
|
switch (ls) {
|
2016-02-17 10:11:00 +03:00
|
|
|
case BuksFound:
|
2024-09-04 17:31:16 +03:00
|
|
|
if (m_context[pos] == value) {
|
2016-02-17 10:11:00 +03:00
|
|
|
ls = SignFound;
|
|
|
|
} else {
|
2024-09-04 17:31:16 +03:00
|
|
|
if (m_context[pos] != ' ')
|
2016-02-17 10:11:00 +03:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case SignFound:
|
2024-09-04 17:31:16 +03:00
|
|
|
if (m_context[pos] == '{') {
|
|
|
|
curPos = pos;
|
2016-02-17 10:11:00 +03:00
|
|
|
return true;
|
2024-09-04 17:31:16 +03:00
|
|
|
} else if (m_context[pos] != ' ')
|
|
|
|
return false;
|
2016-02-17 10:11:00 +03:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
pos++;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ScriptExtractor::isStartScriptLexem(int& curPos)
|
|
|
|
{
|
2019-09-09 21:25:08 +03:00
|
|
|
return isStartLexem(curPos, Const::SCRIPT_SIGN);
|
2016-02-17 10:11:00 +03:00
|
|
|
}
|
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
bool ScriptExtractor::isStartFieldLexem(int& curPos)
|
|
|
|
{
|
2019-09-09 21:25:08 +03:00
|
|
|
return isStartLexem(curPos, Const::FIELD_SIGN);
|
2016-02-17 10:11:00 +03:00
|
|
|
}
|
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
bool ScriptExtractor::isStartVariableLexem(int& curPos)
|
2016-02-17 10:11:00 +03:00
|
|
|
{
|
2019-09-09 21:25:08 +03:00
|
|
|
return isStartLexem(curPos, Const::VARIABLE_SIGN);
|
2016-02-17 10:11:00 +03:00
|
|
|
}
|
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
QString ScriptExtractor::substring(const QString& value, int start, int end)
|
2016-02-17 10:11:00 +03:00
|
|
|
{
|
2024-09-04 17:31:16 +03:00
|
|
|
return value.mid(start, end - start);
|
2016-02-17 10:11:00 +03:00
|
|
|
}
|
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
QString DialogDescriber::name() const { return m_name; }
|
2016-06-10 18:05:18 +03:00
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
void DialogDescriber::setName(const QString& name) { m_name = name; }
|
2016-06-10 18:05:18 +03:00
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
QByteArray DialogDescriber::description() const { return m_description; }
|
2016-06-10 18:05:18 +03:00
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
void DialogDescriber::setDescription(const QByteArray& description) { m_description = description; }
|
2016-06-10 18:05:18 +03:00
|
|
|
|
|
|
|
#ifdef HAVE_UI_LOADER
|
|
|
|
void ScriptEngineContext::addDialog(const QString& name, const QByteArray& description)
|
|
|
|
{
|
2024-09-04 17:31:16 +03:00
|
|
|
m_dialogs.push_back(DialogDescriber::create(name, description));
|
2017-04-14 02:43:34 +03:00
|
|
|
emit dialogAdded(name);
|
2016-06-10 18:05:18 +03:00
|
|
|
}
|
|
|
|
|
2017-04-11 11:23:34 +03:00
|
|
|
bool ScriptEngineContext::changeDialog(const QString& name, const QByteArray& description)
|
|
|
|
{
|
2024-09-04 17:31:16 +03:00
|
|
|
foreach (DialogDescriber::Ptr describer, m_dialogs) {
|
|
|
|
if (describer->name().compare(name) == 0) {
|
2017-04-11 11:23:34 +03:00
|
|
|
describer->setDescription(description);
|
2017-04-14 02:43:34 +03:00
|
|
|
{
|
|
|
|
QList<DialogPtr>::Iterator it = m_createdDialogs.begin();
|
2024-09-04 17:31:16 +03:00
|
|
|
while (it != m_createdDialogs.end()) {
|
|
|
|
if ((*it)->objectName() == name) {
|
2017-04-14 02:43:34 +03:00
|
|
|
it = m_createdDialogs.erase(it);
|
|
|
|
} else {
|
|
|
|
++it;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ScriptEngineContext::changeDialogName(const QString& oldName, const QString& newName)
|
|
|
|
{
|
2024-09-04 17:31:16 +03:00
|
|
|
foreach (DialogDescriber::Ptr describer, m_dialogs) {
|
|
|
|
if (describer->name().compare(oldName) == 0) {
|
2017-04-14 02:43:34 +03:00
|
|
|
describer->setName(newName);
|
|
|
|
{
|
|
|
|
QList<DialogPtr>::Iterator it = m_createdDialogs.begin();
|
2024-09-04 17:31:16 +03:00
|
|
|
while (it != m_createdDialogs.end()) {
|
|
|
|
if ((*it)->objectName() == oldName) {
|
2017-04-14 02:43:34 +03:00
|
|
|
it = m_createdDialogs.erase(it);
|
|
|
|
} else {
|
|
|
|
++it;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2017-04-11 11:23:34 +03:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-06-10 18:05:18 +03:00
|
|
|
bool ScriptEngineContext::previewDialog(const QString& dialogName)
|
|
|
|
{
|
|
|
|
QDialog* dialog = getDialog(dialogName);
|
|
|
|
if (dialog) {
|
|
|
|
dialog->exec();
|
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
m_lastError = tr("Dialog with name: %1 can`t be created").arg(dialogName);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ScriptEngineContext::containsDialog(const QString& dialogName)
|
|
|
|
{
|
2024-09-04 17:31:16 +03:00
|
|
|
foreach (DialogDescriber::Ptr dialog, m_dialogs) {
|
|
|
|
if (dialog->name() == dialogName)
|
2016-06-10 18:05:18 +03:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ScriptEngineContext::deleteDialog(const QString& dialogName)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
QVector<DialogDescriber::Ptr>::Iterator it = m_dialogs.begin();
|
2024-09-04 17:31:16 +03:00
|
|
|
while (it != m_dialogs.end()) {
|
|
|
|
if ((*it)->name() == dialogName) {
|
2016-06-10 18:05:18 +03:00
|
|
|
it = m_dialogs.erase(it);
|
2017-04-14 02:43:34 +03:00
|
|
|
emit dialogDeleted(dialogName);
|
2016-06-10 18:05:18 +03:00
|
|
|
} else {
|
|
|
|
++it;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
{
|
|
|
|
QList<DialogPtr>::Iterator it = m_createdDialogs.begin();
|
2024-09-04 17:31:16 +03:00
|
|
|
while (it != m_createdDialogs.end()) {
|
|
|
|
if ((*it)->objectName() == dialogName) {
|
2016-06-10 18:05:18 +03:00
|
|
|
it = m_createdDialogs.erase(it);
|
|
|
|
} else {
|
|
|
|
++it;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
void ScriptEngineContext::clear()
|
|
|
|
{
|
|
|
|
#ifdef HAVE_UI_LOADER
|
|
|
|
m_dialogs.clear();
|
|
|
|
m_createdDialogs.clear();
|
|
|
|
#endif
|
|
|
|
m_initScript.clear();
|
2017-11-04 21:17:49 +03:00
|
|
|
m_tableOfContents->clear();
|
2024-09-04 17:31:16 +03:00
|
|
|
m_lastError = "";
|
2016-06-10 18:05:18 +03:00
|
|
|
}
|
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
QObject* ScriptEngineContext::createElement(const QString& collectionName,
|
|
|
|
const QString& elementType)
|
2016-06-10 18:05:18 +03:00
|
|
|
{
|
|
|
|
Q_UNUSED(elementType)
|
|
|
|
#ifdef HAVE_UI_LOADER
|
2024-09-04 17:31:16 +03:00
|
|
|
if (collectionName.compare("dialogs", Qt::CaseInsensitive) == 0) {
|
2016-06-10 18:05:18 +03:00
|
|
|
m_dialogs.push_back(DialogDescriber::create());
|
2024-09-04 17:31:16 +03:00
|
|
|
return m_dialogs.at(m_dialogs.count() - 1).data();
|
2016-06-10 18:05:18 +03:00
|
|
|
}
|
|
|
|
#else
|
|
|
|
Q_UNUSED(collectionName)
|
|
|
|
#endif
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int ScriptEngineContext::elementsCount(const QString& collectionName)
|
|
|
|
{
|
|
|
|
#ifdef HAVE_UI_LOADER
|
2024-09-04 17:31:16 +03:00
|
|
|
if (collectionName.compare("dialogs", Qt::CaseInsensitive) == 0) {
|
2016-06-10 18:05:18 +03:00
|
|
|
return m_dialogs.count();
|
|
|
|
};
|
|
|
|
#else
|
|
|
|
Q_UNUSED(collectionName)
|
|
|
|
#endif
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
QObject* ScriptEngineContext::elementAt(const QString& collectionName, int index)
|
|
|
|
{
|
|
|
|
#ifdef HAVE_UI_LOADER
|
2024-09-04 17:31:16 +03:00
|
|
|
if (collectionName.compare("dialogs", Qt::CaseInsensitive) == 0) {
|
2016-06-10 18:05:18 +03:00
|
|
|
return m_dialogs.at(index).data();
|
|
|
|
};
|
|
|
|
#else
|
|
|
|
Q_UNUSED(collectionName)
|
|
|
|
Q_UNUSED(index)
|
|
|
|
#endif
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ScriptEngineContext::collectionLoadFinished(const QString& collectionName)
|
|
|
|
{
|
|
|
|
Q_UNUSED(collectionName);
|
|
|
|
}
|
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
ReportPages* ScriptEngineContext::reportPages() const { return m_reportPages; }
|
2019-03-06 22:16:30 +03:00
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
void ScriptEngineContext::setReportPages(ReportPages* value) { m_reportPages = value; }
|
2019-03-06 22:16:30 +03:00
|
|
|
|
2016-06-10 18:05:18 +03:00
|
|
|
#ifdef HAVE_UI_LOADER
|
|
|
|
QDialog* ScriptEngineContext::createDialog(DialogDescriber* cont)
|
|
|
|
{
|
|
|
|
QUiLoader loader;
|
|
|
|
QByteArray desc = cont->description();
|
|
|
|
QBuffer buffer(&desc);
|
|
|
|
buffer.open(QIODevice::ReadOnly);
|
|
|
|
QDialog* dialog = dynamic_cast<QDialog*>(loader.load(&buffer));
|
|
|
|
m_createdDialogs.push_back(QSharedPointer<QDialog>(dialog));
|
2024-09-04 17:31:16 +03:00
|
|
|
if (cont->name().compare(dialog->objectName())) {
|
2017-04-14 02:43:34 +03:00
|
|
|
cont->setName(dialog->objectName());
|
|
|
|
emit dialogNameChanged(dialog->objectName());
|
|
|
|
}
|
2016-06-10 18:05:18 +03:00
|
|
|
return dialog;
|
|
|
|
}
|
|
|
|
|
|
|
|
QDialog* ScriptEngineContext::findDialog(const QString& dialogName)
|
|
|
|
{
|
2024-09-04 17:31:16 +03:00
|
|
|
foreach (DialogPtr dialog, m_createdDialogs) {
|
|
|
|
if (dialog->objectName() == dialogName)
|
2016-06-10 18:05:18 +03:00
|
|
|
return dialog.data();
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
DialogDescriber* ScriptEngineContext::findDialogContainer(const QString& dialogName)
|
|
|
|
{
|
2024-09-04 17:31:16 +03:00
|
|
|
foreach (DialogDescriber::Ptr dialogCont, m_dialogs) {
|
|
|
|
if (dialogCont->name().compare(dialogName, Qt::CaseInsensitive) == 0) {
|
2016-06-10 18:05:18 +03:00
|
|
|
return dialogCont.data();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2023-01-11 20:47:11 +03:00
|
|
|
#endif
|
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
TableOfContents* ScriptEngineContext::tableOfContents() const { return m_tableOfContents; }
|
2017-08-25 18:01:59 +03:00
|
|
|
|
2017-11-04 21:17:49 +03:00
|
|
|
void ScriptEngineContext::setTableOfContents(TableOfContents* tableOfContents)
|
2017-08-25 18:01:59 +03:00
|
|
|
{
|
2017-11-04 21:17:49 +03:00
|
|
|
m_tableOfContents = tableOfContents;
|
2017-08-25 18:01:59 +03:00
|
|
|
}
|
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
PageItemDesignIntf* ScriptEngineContext::currentPage() const { return m_currentPage; }
|
2017-08-25 18:01:59 +03:00
|
|
|
|
|
|
|
void ScriptEngineContext::setCurrentPage(PageItemDesignIntf* currentPage)
|
|
|
|
{
|
|
|
|
m_currentPage = currentPage;
|
2019-02-12 22:45:35 +03:00
|
|
|
m_currentBand = 0;
|
2017-08-25 18:01:59 +03:00
|
|
|
}
|
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
BandDesignIntf* ScriptEngineContext::currentBand() const { return m_currentBand; }
|
2017-08-25 18:01:59 +03:00
|
|
|
|
|
|
|
void ScriptEngineContext::setCurrentBand(BandDesignIntf* currentBand)
|
|
|
|
{
|
|
|
|
m_currentBand = currentBand;
|
|
|
|
}
|
|
|
|
|
2023-01-11 20:47:11 +03:00
|
|
|
#ifdef HAVE_UI_LOADER
|
|
|
|
|
2016-06-10 18:05:18 +03:00
|
|
|
QDialog* ScriptEngineContext::getDialog(const QString& dialogName)
|
|
|
|
{
|
|
|
|
QDialog* dialog = findDialog(dialogName);
|
2024-09-04 17:31:16 +03:00
|
|
|
if (dialog) {
|
2016-06-10 18:05:18 +03:00
|
|
|
return dialog;
|
|
|
|
} else {
|
|
|
|
DialogDescriber* cont = findDialogContainer(dialogName);
|
2024-09-04 17:31:16 +03:00
|
|
|
if (cont) {
|
2016-06-10 18:05:18 +03:00
|
|
|
dialog = createDialog(cont);
|
|
|
|
if (dialog)
|
|
|
|
return dialog;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
2017-04-14 02:43:34 +03:00
|
|
|
|
|
|
|
QString ScriptEngineContext::getNewDialogName()
|
|
|
|
{
|
|
|
|
QString result = "Dialog";
|
|
|
|
int index = m_dialogs.size() - 1;
|
2024-09-04 17:31:16 +03:00
|
|
|
while (containsDialog(result)) {
|
2017-04-14 02:43:34 +03:00
|
|
|
index++;
|
|
|
|
result = QString("Dialog%1").arg(index);
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2016-06-10 18:05:18 +03:00
|
|
|
#endif
|
2017-04-20 23:34:32 +03:00
|
|
|
|
2017-08-18 22:55:29 +03:00
|
|
|
void ScriptEngineContext::baseDesignIntfToScript(const QString& pageName, BaseDesignIntf* item)
|
2017-04-20 23:34:32 +03:00
|
|
|
{
|
2024-09-04 17:31:16 +03:00
|
|
|
if (item) {
|
|
|
|
if (item->metaObject()->indexOfSignal("beforeRender()") != -1)
|
2017-04-20 23:34:32 +03:00
|
|
|
item->disconnect(SIGNAL(beforeRender()));
|
2024-09-04 17:31:16 +03:00
|
|
|
if (item->metaObject()->indexOfSignal("afterData()") != -1)
|
2017-04-20 23:34:32 +03:00
|
|
|
item->disconnect(SIGNAL(afterData()));
|
2024-09-04 17:31:16 +03:00
|
|
|
if (item->metaObject()->indexOfSignal("afterRender()") != -1)
|
2017-04-20 23:34:32 +03:00
|
|
|
item->disconnect(SIGNAL(afterRender()));
|
|
|
|
|
|
|
|
ScriptEngineType* engine = ScriptEngineManager::instance().scriptEngine();
|
|
|
|
|
|
|
|
#ifdef USE_QJSENGINE
|
2018-05-08 10:52:23 +03:00
|
|
|
ScriptValueType sItem = getJSValue(*engine, item);
|
2024-09-04 17:31:16 +03:00
|
|
|
QString on = item->patternName().compare(pageName) == 0
|
|
|
|
? pageName
|
|
|
|
: pageName + "_" + item->patternName();
|
2018-02-15 02:21:00 +03:00
|
|
|
engine->globalObject().setProperty(on, sItem);
|
2017-04-20 23:34:32 +03:00
|
|
|
#else
|
2024-09-04 17:31:16 +03:00
|
|
|
QString on = item->patternName().compare(pageName) == 0
|
|
|
|
? pageName
|
|
|
|
: pageName + "_" + item->patternName();
|
2018-02-15 02:21:00 +03:00
|
|
|
ScriptValueType sItem = engine->globalObject().property(on);
|
2024-09-04 17:31:16 +03:00
|
|
|
if (sItem.isValid()) {
|
2017-04-20 23:34:32 +03:00
|
|
|
engine->newQObject(sItem, item);
|
|
|
|
} else {
|
|
|
|
sItem = engine->newQObject(item);
|
2024-09-04 17:31:16 +03:00
|
|
|
engine->globalObject().setProperty(on, sItem);
|
2017-04-20 23:34:32 +03:00
|
|
|
}
|
|
|
|
#endif
|
2024-09-04 17:31:16 +03:00
|
|
|
foreach (BaseDesignIntf* child, item->childBaseItems()) {
|
2017-08-18 22:55:29 +03:00
|
|
|
baseDesignIntfToScript(pageName, child);
|
2017-04-20 23:34:32 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
void ScriptEngineContext::qobjectToScript(const QString& name, QObject* item)
|
2017-09-01 02:02:51 +03:00
|
|
|
{
|
|
|
|
ScriptEngineType* engine = ScriptEngineManager::instance().scriptEngine();
|
|
|
|
#ifdef USE_QJSENGINE
|
2022-03-29 15:33:34 +03:00
|
|
|
ScriptValueType sItem = getJSValue(*engine, item);
|
|
|
|
engine->globalObject().setProperty(name, sItem);
|
2017-09-01 02:02:51 +03:00
|
|
|
#else
|
2022-03-29 15:33:34 +03:00
|
|
|
ScriptValueType sItem = engine->globalObject().property(name);
|
2024-09-04 17:31:16 +03:00
|
|
|
if (sItem.isValid()) {
|
2022-03-29 15:33:34 +03:00
|
|
|
engine->newQObject(sItem, item);
|
|
|
|
} else {
|
|
|
|
sItem = engine->newQObject(item);
|
2024-09-04 17:31:16 +03:00
|
|
|
engine->globalObject().setProperty(name, sItem);
|
2022-03-29 15:33:34 +03:00
|
|
|
}
|
2017-09-01 02:02:51 +03:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2017-04-20 23:34:32 +03:00
|
|
|
#ifdef HAVE_UI_LOADER
|
|
|
|
|
|
|
|
#ifdef USE_QJSENGINE
|
2024-09-04 17:31:16 +03:00
|
|
|
void registerChildObjects(ScriptEngineType* se, ScriptValueType* root, QObject* currObj)
|
|
|
|
{
|
|
|
|
foreach (QObject* obj, currObj->children()) {
|
|
|
|
if (!obj->objectName().isEmpty()) {
|
2020-03-24 23:42:05 +03:00
|
|
|
ScriptValueType child = se->newQObject(obj);
|
2024-09-04 17:31:16 +03:00
|
|
|
root->setProperty(obj->objectName(), child);
|
2020-03-24 23:42:05 +03:00
|
|
|
}
|
|
|
|
registerChildObjects(se, root, obj);
|
2017-04-20 23:34:32 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
void ScriptEngineContext::initDialogs()
|
|
|
|
{
|
2017-04-20 23:34:32 +03:00
|
|
|
ScriptEngineType* se = ScriptEngineManager::instance().scriptEngine();
|
2024-09-04 17:31:16 +03:00
|
|
|
foreach (DialogDescriber::Ptr dialog, dialogDescribers()) {
|
2017-04-20 23:34:32 +03:00
|
|
|
ScriptValueType sv = se->newQObject(getDialog(dialog->name()));
|
|
|
|
#ifdef USE_QJSENGINE
|
2020-03-24 23:42:05 +03:00
|
|
|
registerChildObjects(se, &sv, sv.toQObject());
|
2017-04-20 23:34:32 +03:00
|
|
|
#endif
|
2024-09-04 17:31:16 +03:00
|
|
|
se->globalObject().setProperty(dialog->name(), sv);
|
2017-04-20 23:34:32 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
bool ScriptEngineContext::runInitScript()
|
|
|
|
{
|
2017-04-20 23:34:32 +03:00
|
|
|
|
|
|
|
ScriptEngineType* engine = ScriptEngineManager::instance().scriptEngine();
|
2017-08-25 18:01:59 +03:00
|
|
|
ScriptEngineManager::instance().setContext(this);
|
2017-11-04 21:17:49 +03:00
|
|
|
m_tableOfContents->clear();
|
2017-08-25 18:01:59 +03:00
|
|
|
|
2017-04-20 23:34:32 +03:00
|
|
|
ScriptValueType res = engine->evaluate(initScript());
|
2024-09-04 17:31:16 +03:00
|
|
|
if (res.isBool())
|
|
|
|
return res.toBool();
|
|
|
|
#ifdef USE_QJSENGINE
|
|
|
|
if (res.isError()) {
|
|
|
|
QMessageBox::critical(
|
|
|
|
0, tr("Error"),
|
|
|
|
QString("Line %1: %2 ").arg(res.property("lineNumber").toString()).arg(res.toString()));
|
2017-04-20 23:34:32 +03:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
if (engine->hasUncaughtException()) {
|
2024-09-04 17:31:16 +03:00
|
|
|
QMessageBox::critical(0, tr("Error"),
|
|
|
|
QString("Line %1: %2 ")
|
|
|
|
.arg(engine->uncaughtExceptionLineNumber())
|
|
|
|
.arg(engine->uncaughtException().toString()));
|
2017-04-20 23:34:32 +03:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
QString ScriptEngineContext::initScript() const { return m_initScript; }
|
2016-06-10 18:05:18 +03:00
|
|
|
|
|
|
|
void ScriptEngineContext::setInitScript(const QString& initScript)
|
|
|
|
{
|
2024-09-04 17:31:16 +03:00
|
|
|
if (m_initScript != initScript) {
|
2019-02-05 21:51:46 +03:00
|
|
|
m_initScript = initScript;
|
|
|
|
m_hasChanges = true;
|
|
|
|
}
|
2016-06-10 18:05:18 +03:00
|
|
|
}
|
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
DialogDescriber::Ptr DialogDescriber::create(const QString& name, const QByteArray& desc)
|
|
|
|
{
|
2016-06-10 18:05:18 +03:00
|
|
|
Ptr res(new DialogDescriber());
|
|
|
|
res->setName(name);
|
|
|
|
res->setDescription(desc);
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
QString JSFunctionDesc::name() const { return m_name; }
|
2016-11-01 20:42:45 +03:00
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
void JSFunctionDesc::setName(const QString& name) { m_name = name; }
|
2016-11-01 20:42:45 +03:00
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
QString JSFunctionDesc::category() const { return m_category; }
|
2016-11-01 20:42:45 +03:00
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
void JSFunctionDesc::setCategory(const QString& category) { m_category = category; }
|
2016-11-01 20:42:45 +03:00
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
QString JSFunctionDesc::description() const { return m_description; }
|
2016-11-01 20:42:45 +03:00
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
void JSFunctionDesc::setDescription(const QString& description) { m_description = description; }
|
2016-11-01 20:42:45 +03:00
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
QString JSFunctionDesc::managerName() const { return m_managerName; }
|
2016-11-01 20:42:45 +03:00
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
void JSFunctionDesc::setManagerName(const QString& managerName) { m_managerName = managerName; }
|
2016-11-01 20:42:45 +03:00
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
QObject* JSFunctionDesc::manager() const { return m_manager; }
|
2016-11-01 20:42:45 +03:00
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
void JSFunctionDesc::setManager(QObject* manager) { m_manager = manager; }
|
2016-11-01 20:42:45 +03:00
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
QString JSFunctionDesc::scriptWrapper() const { return m_scriptWrapper; }
|
2016-11-01 20:42:45 +03:00
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
void JSFunctionDesc::setScriptWrapper(const QString& scriptWrapper)
|
2016-11-01 20:42:45 +03:00
|
|
|
{
|
|
|
|
m_scriptWrapper = scriptWrapper;
|
|
|
|
}
|
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
QVariant ScriptFunctionsManager::calcGroupFunction(const QString& name, const QString& expressionID,
|
|
|
|
const QString& bandName, QObject* currentPage)
|
2016-11-01 20:42:45 +03:00
|
|
|
{
|
2024-09-04 17:31:16 +03:00
|
|
|
if (m_scriptEngineManager->dataManager()) {
|
2018-03-14 11:22:03 +03:00
|
|
|
PageItemDesignIntf* pageItem = dynamic_cast<PageItemDesignIntf*>(currentPage);
|
2017-03-08 04:59:40 +03:00
|
|
|
QString expression = m_scriptEngineManager->dataManager()->getExpression(expressionID);
|
2024-09-04 17:31:16 +03:00
|
|
|
GroupFunction* gf
|
|
|
|
= m_scriptEngineManager->dataManager()->groupFunction(name, expression, bandName);
|
|
|
|
if (gf) {
|
|
|
|
if (gf->isValid()) {
|
2018-03-14 11:22:03 +03:00
|
|
|
return gf->calculate(pageItem);
|
2024-09-04 17:31:16 +03:00
|
|
|
} else {
|
2016-11-01 20:42:45 +03:00
|
|
|
return gf->error();
|
|
|
|
}
|
2022-07-16 02:33:39 +03:00
|
|
|
} else {
|
2016-11-01 20:42:45 +03:00
|
|
|
return QString(QObject::tr("Function %1 not found or have wrong arguments").arg(name));
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
return QString(QObject::tr("Datasource manager not found"));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
QVariant ScriptFunctionsManager::calcGroupFunction(const QString& name, const QString& expressionID,
|
|
|
|
const QString& bandName)
|
2018-04-12 22:41:34 +03:00
|
|
|
{
|
|
|
|
return calcGroupFunction(name, expressionID, bandName, 0);
|
|
|
|
}
|
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
QVariant ScriptFunctionsManager::line(const QString& bandName)
|
2016-11-01 20:42:45 +03:00
|
|
|
{
|
2024-09-04 17:31:16 +03:00
|
|
|
QString varName = QLatin1String("line_") + bandName.toLower();
|
2016-11-01 20:42:45 +03:00
|
|
|
QVariant res;
|
2024-09-04 17:31:16 +03:00
|
|
|
if (scriptEngineManager()->dataManager()->variable(varName).isValid()) {
|
|
|
|
res = scriptEngineManager()->dataManager()->variable(varName);
|
|
|
|
} else
|
|
|
|
res = QString("Variable line for band %1 not found").arg(bandName);
|
2016-11-01 20:42:45 +03:00
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
QVariant ScriptFunctionsManager::numberFormat(QVariant value, const char& format, int precision,
|
|
|
|
const QString& locale)
|
2016-11-01 20:42:45 +03:00
|
|
|
{
|
2024-09-04 17:31:16 +03:00
|
|
|
return (locale.isEmpty()) ? QString::number(value.toDouble(), format, precision)
|
|
|
|
: QLocale(locale).toString(value.toDouble(), format, precision);
|
2016-11-01 20:42:45 +03:00
|
|
|
}
|
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
QVariant ScriptFunctionsManager::dateFormat(QVariant value, const QString& format,
|
|
|
|
const QString& locale)
|
2016-11-01 20:42:45 +03:00
|
|
|
{
|
2024-09-04 17:31:16 +03:00
|
|
|
return (locale.isEmpty()) ? QLocale().toString(value.toDate(), format)
|
|
|
|
: QLocale(locale).toString(value.toDate(), format);
|
2016-11-01 20:42:45 +03:00
|
|
|
}
|
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
QVariant ScriptFunctionsManager::timeFormat(QVariant value, const QString& format)
|
2016-11-01 20:42:45 +03:00
|
|
|
{
|
2024-09-04 17:31:16 +03:00
|
|
|
return QLocale().toString(value.toTime(), format);
|
2016-11-01 20:42:45 +03:00
|
|
|
}
|
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
QVariant ScriptFunctionsManager::dateTimeFormat(QVariant value, const QString& format,
|
|
|
|
const QString& locale)
|
2016-11-01 20:42:45 +03:00
|
|
|
{
|
2024-09-04 17:31:16 +03:00
|
|
|
return (locale.isEmpty()) ? QLocale().toString(value.toDateTime(), format)
|
|
|
|
: QLocale(locale).toString(value.toDateTime(), format);
|
2016-11-01 20:42:45 +03:00
|
|
|
}
|
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
QVariant ScriptFunctionsManager::sectotimeFormat(QVariant value, const QString& format)
|
2017-12-22 12:36:46 +03:00
|
|
|
{
|
|
|
|
int seconds = value.toInt();
|
|
|
|
int minutes = seconds / 60;
|
|
|
|
int hours = minutes / 60;
|
|
|
|
|
|
|
|
QString result = format;
|
|
|
|
bool hasHour = format.contains("h");
|
|
|
|
bool hasMinute = format.contains("m");
|
2024-09-04 17:31:16 +03:00
|
|
|
for (int len = 2; len; len--) {
|
|
|
|
if (hasHour)
|
|
|
|
result.replace(QString('h').repeated(len),
|
|
|
|
QString::number(hours).rightJustified(len, '0'));
|
|
|
|
if (hasMinute)
|
|
|
|
result.replace(
|
|
|
|
QString('m').repeated(len),
|
|
|
|
QString::number(hasHour ? minutes % 60 : minutes).rightJustified(len, '0'));
|
|
|
|
result.replace(
|
|
|
|
QString('s').repeated(len),
|
|
|
|
QString::number(hasMinute ? seconds % 60 : seconds).rightJustified(len, '0'));
|
2017-12-22 12:36:46 +03:00
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
QVariant ScriptFunctionsManager::date() { return QDate::currentDate(); }
|
2016-11-01 20:42:45 +03:00
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
QVariant ScriptFunctionsManager::now() { return QDateTime::currentDateTime(); }
|
2016-11-01 20:42:45 +03:00
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
QVariant ScriptFunctionsManager::currencyFormat(QVariant value, const QString& locale)
|
2016-11-01 20:42:45 +03:00
|
|
|
{
|
2024-09-04 17:31:16 +03:00
|
|
|
QString l = (!locale.isEmpty()) ? locale : QLocale::system().name();
|
2016-11-01 20:42:45 +03:00
|
|
|
return QLocale(l).toCurrencyString(value.toDouble());
|
|
|
|
}
|
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
QVariant ScriptFunctionsManager::currencyUSBasedFormat(QVariant value,
|
|
|
|
const QString& currencySymbol)
|
2016-11-01 20:42:45 +03:00
|
|
|
{
|
2024-09-04 17:31:16 +03:00
|
|
|
QString CurrencySymbol
|
|
|
|
= (!currencySymbol.isEmpty()) ? currencySymbol : QLocale::system().currencySymbol();
|
2016-11-01 20:42:45 +03:00
|
|
|
// Format it using USA locale
|
2024-09-04 17:31:16 +03:00
|
|
|
QString vTempStr
|
|
|
|
= QLocale(QLocale::English, QLocale::UnitedStates).toCurrencyString(value.toDouble());
|
2016-11-01 20:42:45 +03:00
|
|
|
// Replace currency symbol if necesarry
|
2024-09-04 17:31:16 +03:00
|
|
|
if (CurrencySymbol != "")
|
|
|
|
vTempStr.replace("$", CurrencySymbol);
|
2016-11-01 20:42:45 +03:00
|
|
|
return vTempStr;
|
|
|
|
}
|
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
void ScriptFunctionsManager::setVariable(const QString& name, QVariant value)
|
2016-11-01 20:42:45 +03:00
|
|
|
{
|
|
|
|
DataSourceManager* dm = scriptEngineManager()->dataManager();
|
2024-09-04 17:31:16 +03:00
|
|
|
if (dm->containsVariable(name)) {
|
|
|
|
dm->changeVariable(name, value);
|
2017-09-11 21:31:54 +03:00
|
|
|
} else {
|
|
|
|
dm->addVariable(name, value, VarDesc::User);
|
|
|
|
}
|
2016-11-01 20:42:45 +03:00
|
|
|
}
|
2017-02-11 00:21:03 +03:00
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
QVariant ScriptFunctionsManager::getVariable(const QString& name)
|
2017-02-11 00:21:03 +03:00
|
|
|
{
|
|
|
|
DataSourceManager* dm = scriptEngineManager()->dataManager();
|
|
|
|
return dm->variable(name);
|
|
|
|
}
|
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
QVariant ScriptFunctionsManager::getField(const QString& field)
|
2017-02-11 00:21:03 +03:00
|
|
|
{
|
|
|
|
DataSourceManager* dm = scriptEngineManager()->dataManager();
|
|
|
|
return dm->fieldData(field);
|
|
|
|
}
|
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
QVariant ScriptFunctionsManager::getFieldByKeyField(const QString& datasourceName,
|
|
|
|
const QString& valueFieldName,
|
|
|
|
const QString& keyFieldName, QVariant keyValue)
|
2017-08-18 22:55:29 +03:00
|
|
|
{
|
2017-08-31 02:53:34 +03:00
|
|
|
DataSourceManager* dm = scriptEngineManager()->dataManager();
|
|
|
|
return dm->fieldDataByKey(datasourceName, valueFieldName, keyFieldName, keyValue);
|
|
|
|
}
|
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
QVariant ScriptFunctionsManager::getFieldByRowIndex(const QString& fieldName, int rowIndex)
|
2019-02-19 02:23:53 +03:00
|
|
|
{
|
|
|
|
DataSourceManager* dm = scriptEngineManager()->dataManager();
|
|
|
|
return dm->fieldDataByRowIndex(fieldName, rowIndex);
|
|
|
|
}
|
|
|
|
|
2017-09-19 21:02:55 +03:00
|
|
|
void ScriptFunctionsManager::reopenDatasource(const QString& datasourceName)
|
|
|
|
{
|
|
|
|
DataSourceManager* dm = scriptEngineManager()->dataManager();
|
|
|
|
return dm->reopenDatasource(datasourceName);
|
|
|
|
}
|
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
void ScriptFunctionsManager::addBookmark(const QString& uniqKey, const QString& content)
|
2019-03-06 22:16:30 +03:00
|
|
|
{
|
|
|
|
scriptEngineManager()->addBookMark(uniqKey, content);
|
|
|
|
}
|
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
int ScriptFunctionsManager::findPageIndexByBookmark(const QString& uniqKey)
|
2019-03-06 22:16:30 +03:00
|
|
|
{
|
|
|
|
return scriptEngineManager()->findPageIndexByBookmark(uniqKey);
|
|
|
|
}
|
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
int ScriptFunctionsManager::getPageFreeSpace(QObject* page)
|
|
|
|
{
|
2021-04-12 20:22:34 +03:00
|
|
|
return scriptEngineManager()->getPageFreeSpace(dynamic_cast<PageItemDesignIntf*>(page));
|
|
|
|
}
|
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
void ScriptFunctionsManager::addTableOfContentsItem(const QString& uniqKey, const QString& content,
|
|
|
|
int indent)
|
2017-08-31 02:53:34 +03:00
|
|
|
{
|
2017-11-04 21:17:49 +03:00
|
|
|
scriptEngineManager()->addTableOfContentsItem(uniqKey, content, indent);
|
2017-08-18 22:55:29 +03:00
|
|
|
}
|
|
|
|
|
2017-11-04 21:17:49 +03:00
|
|
|
void ScriptFunctionsManager::clearTableOfContents()
|
2017-08-18 22:55:29 +03:00
|
|
|
{
|
2017-11-04 21:17:49 +03:00
|
|
|
scriptEngineManager()->clearTableOfContents();
|
2017-08-18 22:55:29 +03:00
|
|
|
}
|
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
QFont ScriptFunctionsManager::font(const QString& family, int pointSize, bool italic, bool bold,
|
|
|
|
bool underLine)
|
2016-11-01 20:42:45 +03:00
|
|
|
{
|
2024-09-04 17:31:16 +03:00
|
|
|
QFont result(family, pointSize);
|
2016-11-01 20:42:45 +03:00
|
|
|
result.setBold(bold);
|
|
|
|
result.setItalic(italic);
|
|
|
|
result.setUnderline(underLine);
|
|
|
|
return result;
|
|
|
|
}
|
2017-09-01 02:02:51 +03:00
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
QVariant ScriptFunctionsManager::getFieldByRowIndexEx(const QString& fieldName, int rowIndex,
|
|
|
|
const int role)
|
Add: added a function to get an arbitrary role of a model item
Example:
$D{appdata.Column_1}
$S{
var vRow = line('DataBand1') - 1;
// 8 - Qt::BackgroundRole
var vColor = getFieldByRowIndexEx('appdata.Column_1', vRow, 8);
THIS.backgroundColor = LimeReport.color('lightgray');
if(vColor > '')
{
THIS.backgroundColor = vColor;
}
''
}
Added several functions to get extended information from the model
- getFieldByRowIndexEx2(fieldName, rowIndex, roleName), default:
Qt::DisplayRole
- getHeaderData(fieldName, roleName), default: Qt::DisplayRole
- getHeaderColumnNameByIndex(datasourceName, columnIndex), default:
Qt::UserRole or Qt::DisplayRole
- getColumnCount(datasourceName), default: -1
2024-03-26 11:43:58 +03:00
|
|
|
{
|
2024-09-04 17:31:16 +03:00
|
|
|
DataSourceManager* dm = scriptEngineManager()->dataManager();
|
Add: added a function to get an arbitrary role of a model item
Example:
$D{appdata.Column_1}
$S{
var vRow = line('DataBand1') - 1;
// 8 - Qt::BackgroundRole
var vColor = getFieldByRowIndexEx('appdata.Column_1', vRow, 8);
THIS.backgroundColor = LimeReport.color('lightgray');
if(vColor > '')
{
THIS.backgroundColor = vColor;
}
''
}
Added several functions to get extended information from the model
- getFieldByRowIndexEx2(fieldName, rowIndex, roleName), default:
Qt::DisplayRole
- getHeaderData(fieldName, roleName), default: Qt::DisplayRole
- getHeaderColumnNameByIndex(datasourceName, columnIndex), default:
Qt::UserRole or Qt::DisplayRole
- getColumnCount(datasourceName), default: -1
2024-03-26 11:43:58 +03:00
|
|
|
return dm->fieldDataByRowIndex(fieldName, rowIndex, role);
|
|
|
|
}
|
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
QVariant ScriptFunctionsManager::getFieldByRowIndexEx2(const QString& fieldName, int rowIndex,
|
|
|
|
const QString& roleName)
|
Add: added a function to get an arbitrary role of a model item
Example:
$D{appdata.Column_1}
$S{
var vRow = line('DataBand1') - 1;
// 8 - Qt::BackgroundRole
var vColor = getFieldByRowIndexEx('appdata.Column_1', vRow, 8);
THIS.backgroundColor = LimeReport.color('lightgray');
if(vColor > '')
{
THIS.backgroundColor = vColor;
}
''
}
Added several functions to get extended information from the model
- getFieldByRowIndexEx2(fieldName, rowIndex, roleName), default:
Qt::DisplayRole
- getHeaderData(fieldName, roleName), default: Qt::DisplayRole
- getHeaderColumnNameByIndex(datasourceName, columnIndex), default:
Qt::UserRole or Qt::DisplayRole
- getColumnCount(datasourceName), default: -1
2024-03-26 11:43:58 +03:00
|
|
|
{
|
2024-09-04 17:31:16 +03:00
|
|
|
DataSourceManager* dm = scriptEngineManager()->dataManager();
|
Add: added a function to get an arbitrary role of a model item
Example:
$D{appdata.Column_1}
$S{
var vRow = line('DataBand1') - 1;
// 8 - Qt::BackgroundRole
var vColor = getFieldByRowIndexEx('appdata.Column_1', vRow, 8);
THIS.backgroundColor = LimeReport.color('lightgray');
if(vColor > '')
{
THIS.backgroundColor = vColor;
}
''
}
Added several functions to get extended information from the model
- getFieldByRowIndexEx2(fieldName, rowIndex, roleName), default:
Qt::DisplayRole
- getHeaderData(fieldName, roleName), default: Qt::DisplayRole
- getHeaderColumnNameByIndex(datasourceName, columnIndex), default:
Qt::UserRole or Qt::DisplayRole
- getColumnCount(datasourceName), default: -1
2024-03-26 11:43:58 +03:00
|
|
|
return dm->fieldDataByRowIndex(fieldName, rowIndex, roleName);
|
|
|
|
}
|
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
QVariant ScriptFunctionsManager::getHeaderData(const QString& fieldName, const QString& roleName)
|
Add: added a function to get an arbitrary role of a model item
Example:
$D{appdata.Column_1}
$S{
var vRow = line('DataBand1') - 1;
// 8 - Qt::BackgroundRole
var vColor = getFieldByRowIndexEx('appdata.Column_1', vRow, 8);
THIS.backgroundColor = LimeReport.color('lightgray');
if(vColor > '')
{
THIS.backgroundColor = vColor;
}
''
}
Added several functions to get extended information from the model
- getFieldByRowIndexEx2(fieldName, rowIndex, roleName), default:
Qt::DisplayRole
- getHeaderData(fieldName, roleName), default: Qt::DisplayRole
- getHeaderColumnNameByIndex(datasourceName, columnIndex), default:
Qt::UserRole or Qt::DisplayRole
- getColumnCount(datasourceName), default: -1
2024-03-26 11:43:58 +03:00
|
|
|
{
|
2024-09-04 17:31:16 +03:00
|
|
|
DataSourceManager* dm = scriptEngineManager()->dataManager();
|
Add: added a function to get an arbitrary role of a model item
Example:
$D{appdata.Column_1}
$S{
var vRow = line('DataBand1') - 1;
// 8 - Qt::BackgroundRole
var vColor = getFieldByRowIndexEx('appdata.Column_1', vRow, 8);
THIS.backgroundColor = LimeReport.color('lightgray');
if(vColor > '')
{
THIS.backgroundColor = vColor;
}
''
}
Added several functions to get extended information from the model
- getFieldByRowIndexEx2(fieldName, rowIndex, roleName), default:
Qt::DisplayRole
- getHeaderData(fieldName, roleName), default: Qt::DisplayRole
- getHeaderColumnNameByIndex(datasourceName, columnIndex), default:
Qt::UserRole or Qt::DisplayRole
- getColumnCount(datasourceName), default: -1
2024-03-26 11:43:58 +03:00
|
|
|
return dm->headerData(fieldName, roleName);
|
|
|
|
}
|
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
QVariant ScriptFunctionsManager::getHeaderColumnNameByIndex(const QString& datasourceName,
|
|
|
|
const int columnIndex)
|
Add: added a function to get an arbitrary role of a model item
Example:
$D{appdata.Column_1}
$S{
var vRow = line('DataBand1') - 1;
// 8 - Qt::BackgroundRole
var vColor = getFieldByRowIndexEx('appdata.Column_1', vRow, 8);
THIS.backgroundColor = LimeReport.color('lightgray');
if(vColor > '')
{
THIS.backgroundColor = vColor;
}
''
}
Added several functions to get extended information from the model
- getFieldByRowIndexEx2(fieldName, rowIndex, roleName), default:
Qt::DisplayRole
- getHeaderData(fieldName, roleName), default: Qt::DisplayRole
- getHeaderColumnNameByIndex(datasourceName, columnIndex), default:
Qt::UserRole or Qt::DisplayRole
- getColumnCount(datasourceName), default: -1
2024-03-26 11:43:58 +03:00
|
|
|
{
|
2024-09-04 17:31:16 +03:00
|
|
|
DataSourceManager* dm = scriptEngineManager()->dataManager();
|
Add: added a function to get an arbitrary role of a model item
Example:
$D{appdata.Column_1}
$S{
var vRow = line('DataBand1') - 1;
// 8 - Qt::BackgroundRole
var vColor = getFieldByRowIndexEx('appdata.Column_1', vRow, 8);
THIS.backgroundColor = LimeReport.color('lightgray');
if(vColor > '')
{
THIS.backgroundColor = vColor;
}
''
}
Added several functions to get extended information from the model
- getFieldByRowIndexEx2(fieldName, rowIndex, roleName), default:
Qt::DisplayRole
- getHeaderData(fieldName, roleName), default: Qt::DisplayRole
- getHeaderColumnNameByIndex(datasourceName, columnIndex), default:
Qt::UserRole or Qt::DisplayRole
- getColumnCount(datasourceName), default: -1
2024-03-26 11:43:58 +03:00
|
|
|
return dm->columnName(datasourceName, columnIndex);
|
|
|
|
}
|
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
int ScriptFunctionsManager::getColumnCount(const QString& datasourceName)
|
Add: added a function to get an arbitrary role of a model item
Example:
$D{appdata.Column_1}
$S{
var vRow = line('DataBand1') - 1;
// 8 - Qt::BackgroundRole
var vColor = getFieldByRowIndexEx('appdata.Column_1', vRow, 8);
THIS.backgroundColor = LimeReport.color('lightgray');
if(vColor > '')
{
THIS.backgroundColor = vColor;
}
''
}
Added several functions to get extended information from the model
- getFieldByRowIndexEx2(fieldName, rowIndex, roleName), default:
Qt::DisplayRole
- getHeaderData(fieldName, roleName), default: Qt::DisplayRole
- getHeaderColumnNameByIndex(datasourceName, columnIndex), default:
Qt::UserRole or Qt::DisplayRole
- getColumnCount(datasourceName), default: -1
2024-03-26 11:43:58 +03:00
|
|
|
{
|
2024-09-04 17:31:16 +03:00
|
|
|
DataSourceManager* dm = scriptEngineManager()->dataManager();
|
Add: added a function to get an arbitrary role of a model item
Example:
$D{appdata.Column_1}
$S{
var vRow = line('DataBand1') - 1;
// 8 - Qt::BackgroundRole
var vColor = getFieldByRowIndexEx('appdata.Column_1', vRow, 8);
THIS.backgroundColor = LimeReport.color('lightgray');
if(vColor > '')
{
THIS.backgroundColor = vColor;
}
''
}
Added several functions to get extended information from the model
- getFieldByRowIndexEx2(fieldName, rowIndex, roleName), default:
Qt::DisplayRole
- getHeaderData(fieldName, roleName), default: Qt::DisplayRole
- getHeaderColumnNameByIndex(datasourceName, columnIndex), default:
Qt::UserRole or Qt::DisplayRole
- getColumnCount(datasourceName), default: -1
2024-03-26 11:43:58 +03:00
|
|
|
return dm->columnCount(datasourceName);
|
|
|
|
}
|
|
|
|
|
2017-12-14 02:28:52 +03:00
|
|
|
#ifdef USE_QJSENGINE
|
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
void ScriptFunctionsManager::addItemsToComboBox(QJSValue object, const QStringList& values)
|
2017-09-01 02:02:51 +03:00
|
|
|
{
|
|
|
|
QComboBox* comboBox = dynamic_cast<QComboBox*>(object.toQObject());
|
2024-09-04 17:31:16 +03:00
|
|
|
if (comboBox) {
|
2017-09-01 02:02:51 +03:00
|
|
|
comboBox->addItems(values);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
void ScriptFunctionsManager::addItemToComboBox(QJSValue object, const QString& value)
|
2017-09-01 02:02:51 +03:00
|
|
|
{
|
|
|
|
QComboBox* comboBox = dynamic_cast<QComboBox*>(object.toQObject());
|
2024-09-04 17:31:16 +03:00
|
|
|
if (comboBox) {
|
2017-09-01 02:02:51 +03:00
|
|
|
comboBox->addItem(value);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
QJSValue ScriptFunctionsManager::createComboBoxWrapper(QJSValue comboBox)
|
|
|
|
{
|
|
|
|
QComboBox* item = dynamic_cast<QComboBox*>(comboBox.toQObject());
|
2024-09-04 17:31:16 +03:00
|
|
|
if (item) {
|
2017-09-01 02:02:51 +03:00
|
|
|
ComboBoxWrapper* wrapper = new ComboBoxWrapper(item);
|
|
|
|
return m_scriptEngineManager->scriptEngine()->newQObject(wrapper);
|
|
|
|
}
|
|
|
|
return QJSValue();
|
|
|
|
}
|
|
|
|
|
|
|
|
QJSValue ScriptFunctionsManager::createWrapper(QJSValue item)
|
|
|
|
{
|
|
|
|
QObject* object = item.toQObject();
|
2024-09-04 17:31:16 +03:00
|
|
|
if (object) {
|
2017-09-01 02:02:51 +03:00
|
|
|
IWrapperCreator* wrapper = m_wrappersFactory.value(object->metaObject()->className());
|
2024-09-04 17:31:16 +03:00
|
|
|
if (wrapper) {
|
|
|
|
return m_scriptEngineManager->scriptEngine()->newQObject(
|
|
|
|
wrapper->createWrapper(item.toQObject()));
|
2017-09-01 02:02:51 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return QJSValue();
|
|
|
|
}
|
|
|
|
|
2017-12-14 02:28:52 +03:00
|
|
|
#else
|
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
void ScriptFunctionsManager::addItemsToComboBox(QScriptValue object, const QStringList& values)
|
2017-12-14 02:28:52 +03:00
|
|
|
{
|
|
|
|
QComboBox* comboBox = dynamic_cast<QComboBox*>(object.toQObject());
|
2024-09-04 17:31:16 +03:00
|
|
|
if (comboBox) {
|
2017-12-14 02:28:52 +03:00
|
|
|
comboBox->addItems(values);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
void ScriptFunctionsManager::addItemToComboBox(QScriptValue object, const QString& value)
|
2017-12-14 02:28:52 +03:00
|
|
|
{
|
|
|
|
QComboBox* comboBox = dynamic_cast<QComboBox*>(object.toQObject());
|
2024-09-04 17:31:16 +03:00
|
|
|
if (comboBox) {
|
2017-12-14 02:28:52 +03:00
|
|
|
comboBox->addItem(value);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
QScriptValue ScriptFunctionsManager::createComboBoxWrapper(QScriptValue comboBox)
|
|
|
|
{
|
|
|
|
QComboBox* item = dynamic_cast<QComboBox*>(comboBox.toQObject());
|
2024-09-04 17:31:16 +03:00
|
|
|
if (item) {
|
2017-12-14 02:28:52 +03:00
|
|
|
ComboBoxWrapper* wrapper = new ComboBoxWrapper(item);
|
|
|
|
return m_scriptEngineManager->scriptEngine()->newQObject(wrapper);
|
|
|
|
}
|
|
|
|
return QScriptValue();
|
|
|
|
}
|
|
|
|
|
|
|
|
QScriptValue ScriptFunctionsManager::createWrapper(QScriptValue item)
|
|
|
|
{
|
|
|
|
QObject* object = item.toQObject();
|
2024-09-04 17:31:16 +03:00
|
|
|
if (object) {
|
2017-12-14 02:28:52 +03:00
|
|
|
IWrapperCreator* wrapper = m_wrappersFactory.value(object->metaObject()->className());
|
2024-09-04 17:31:16 +03:00
|
|
|
if (wrapper) {
|
|
|
|
return m_scriptEngineManager->scriptEngine()->newQObject(
|
|
|
|
wrapper->createWrapper(item.toQObject()));
|
2017-12-14 02:28:52 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return QScriptValue();
|
|
|
|
}
|
|
|
|
|
2016-11-01 20:42:45 +03:00
|
|
|
#endif
|
2017-12-14 02:28:52 +03:00
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
QFont ScriptFunctionsManager::font(QVariantMap params)
|
|
|
|
{
|
|
|
|
if (!params.contains("family")) {
|
2016-11-01 20:42:45 +03:00
|
|
|
return QFont();
|
|
|
|
} else {
|
|
|
|
QFont result(params.value("family").toString());
|
|
|
|
if (params.contains("pointSize"))
|
|
|
|
result.setPointSize(params.value("pointSize").toInt());
|
|
|
|
if (params.contains("bold"))
|
|
|
|
result.setBold(params.value("bold").toBool());
|
|
|
|
if (params.contains("italic"))
|
|
|
|
result.setItalic(params.value("italic").toBool());
|
|
|
|
if (params.contains("underline"))
|
|
|
|
result.setUnderline(params.value("underline").toBool());
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
ScriptEngineManager* ScriptFunctionsManager::scriptEngineManager() const
|
2016-11-01 20:42:45 +03:00
|
|
|
{
|
|
|
|
return m_scriptEngineManager;
|
|
|
|
}
|
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
void ScriptFunctionsManager::setScriptEngineManager(ScriptEngineManager* scriptEngineManager)
|
2016-11-01 20:42:45 +03:00
|
|
|
{
|
|
|
|
m_scriptEngineManager = scriptEngineManager;
|
|
|
|
}
|
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
TableOfContents::~TableOfContents() { clear(); }
|
2017-08-18 22:55:29 +03:00
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
void TableOfContents::setItem(const QString& uniqKey, const QString& content, int pageNumber,
|
|
|
|
int indent)
|
2017-08-18 22:55:29 +03:00
|
|
|
{
|
2024-09-04 17:31:16 +03:00
|
|
|
ContentItem* item = 0;
|
|
|
|
if (m_hash.contains(uniqKey)) {
|
2017-08-19 01:16:57 +03:00
|
|
|
item = m_hash.value(uniqKey);
|
|
|
|
item->content = content;
|
2017-08-18 22:55:29 +03:00
|
|
|
item->pageNumber = pageNumber;
|
2024-09-04 17:31:16 +03:00
|
|
|
if (indent > 0)
|
2017-08-25 18:01:59 +03:00
|
|
|
item->indent = indent;
|
2017-08-18 22:55:29 +03:00
|
|
|
} else {
|
2017-08-19 01:16:57 +03:00
|
|
|
item = new ContentItem;
|
2017-08-18 22:55:29 +03:00
|
|
|
item->content = content;
|
|
|
|
item->pageNumber = pageNumber;
|
|
|
|
item->indent = indent;
|
2017-08-31 02:53:34 +03:00
|
|
|
item->uniqKey = uniqKey;
|
2017-11-04 21:17:49 +03:00
|
|
|
m_tableOfContents.append(item);
|
2017-08-19 01:16:57 +03:00
|
|
|
m_hash.insert(uniqKey, item);
|
2017-08-18 22:55:29 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-11-04 21:17:49 +03:00
|
|
|
void TableOfContents::slotOneSlotDS(CallbackInfo info, QVariant& data)
|
2017-08-18 22:55:29 +03:00
|
|
|
{
|
|
|
|
QStringList columns;
|
2024-09-04 17:31:16 +03:00
|
|
|
columns << "Content"
|
|
|
|
<< "Page number"
|
|
|
|
<< "Content Key";
|
2017-08-18 22:55:29 +03:00
|
|
|
|
|
|
|
switch (info.dataType) {
|
2022-03-29 15:33:34 +03:00
|
|
|
case LimeReport::CallbackInfo::RowCount:
|
|
|
|
data = m_tableOfContents.count();
|
|
|
|
break;
|
|
|
|
case LimeReport::CallbackInfo::ColumnCount:
|
|
|
|
data = columns.size();
|
|
|
|
break;
|
|
|
|
case LimeReport::CallbackInfo::ColumnHeaderData: {
|
|
|
|
data = columns.at(info.index);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case LimeReport::CallbackInfo::ColumnData:
|
2024-09-04 17:31:16 +03:00
|
|
|
if (info.index < m_tableOfContents.count()) {
|
2022-03-29 15:33:34 +03:00
|
|
|
ContentItem* item = m_tableOfContents.at(info.index);
|
2024-09-04 17:31:16 +03:00
|
|
|
if (info.columnName.compare("Content", Qt::CaseInsensitive) == 0)
|
|
|
|
data = item->content.rightJustified(item->indent + item->content.size());
|
|
|
|
if (info.columnName.compare("Content Key", Qt::CaseInsensitive) == 0)
|
2022-03-29 15:33:34 +03:00
|
|
|
data = item->uniqKey;
|
2024-09-04 17:31:16 +03:00
|
|
|
if (info.columnName.compare("Page number", Qt::CaseInsensitive) == 0)
|
2022-03-29 15:33:34 +03:00
|
|
|
data = QString::number(item->pageNumber);
|
2017-08-18 22:55:29 +03:00
|
|
|
}
|
2022-03-29 15:33:34 +03:00
|
|
|
break;
|
2024-09-04 17:31:16 +03:00
|
|
|
default:
|
|
|
|
break;
|
2017-08-18 22:55:29 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
void LimeReport::TableOfContents::clear()
|
|
|
|
{
|
2017-08-18 22:55:29 +03:00
|
|
|
|
|
|
|
m_hash.clear();
|
2024-09-04 17:31:16 +03:00
|
|
|
foreach (ContentItem* item, m_tableOfContents) {
|
2017-08-18 22:55:29 +03:00
|
|
|
delete item;
|
|
|
|
}
|
2017-11-04 21:17:49 +03:00
|
|
|
m_tableOfContents.clear();
|
2017-08-18 22:55:29 +03:00
|
|
|
}
|
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
QObject* ComboBoxWrapperCreator::createWrapper(QObject* item)
|
2017-09-01 02:02:51 +03:00
|
|
|
{
|
|
|
|
QComboBox* comboBox = dynamic_cast<QComboBox*>(item);
|
2024-09-04 17:31:16 +03:00
|
|
|
if (comboBox) {
|
|
|
|
return new ComboBoxWrapper(comboBox);
|
2017-09-01 02:02:51 +03:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2019-01-31 22:30:41 +03:00
|
|
|
bool DatasourceFunctions::first(const QString& datasourceName)
|
|
|
|
{
|
2024-09-04 17:31:16 +03:00
|
|
|
if (m_dataManager && m_dataManager->dataSource(datasourceName)) {
|
2019-01-31 22:30:41 +03:00
|
|
|
m_dataManager->dataSource(datasourceName)->first();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
bool DatasourceFunctions::next(const QString& datasourceName)
|
|
|
|
{
|
2019-01-30 22:50:22 +03:00
|
|
|
if (m_dataManager && m_dataManager->dataSource(datasourceName))
|
|
|
|
return m_dataManager->dataSource(datasourceName)->next();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2019-01-31 22:30:41 +03:00
|
|
|
bool DatasourceFunctions::prior(const QString& datasourceName)
|
|
|
|
{
|
|
|
|
if (m_dataManager && m_dataManager->dataSource(datasourceName))
|
|
|
|
return m_dataManager->dataSource(datasourceName)->prior();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
bool DatasourceFunctions::isEOF(const QString& datasourceName)
|
2019-01-30 22:50:22 +03:00
|
|
|
{
|
|
|
|
if (m_dataManager && m_dataManager->dataSource(datasourceName))
|
|
|
|
return m_dataManager->dataSource(datasourceName)->eof();
|
2019-02-05 01:04:23 +03:00
|
|
|
return true;
|
2019-01-30 22:50:22 +03:00
|
|
|
}
|
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
int DatasourceFunctions::rowCount(const QString& datasourceName)
|
2022-03-29 15:33:34 +03:00
|
|
|
{
|
|
|
|
if (m_dataManager && m_dataManager->dataSource(datasourceName))
|
|
|
|
return m_dataManager->dataSource(datasourceName)->model()->rowCount();
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2019-01-31 22:30:41 +03:00
|
|
|
bool DatasourceFunctions::invalidate(const QString& datasourceName)
|
|
|
|
{
|
2024-09-04 17:31:16 +03:00
|
|
|
if (m_dataManager && m_dataManager->dataSource(datasourceName)) {
|
2019-08-11 00:45:27 +03:00
|
|
|
m_dataManager->dataSourceHolder(datasourceName)->invalidate(IDataSource::RENDER_MODE);
|
2019-01-31 22:30:41 +03:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
2017-09-01 02:02:51 +03:00
|
|
|
|
2020-02-16 16:47:26 +03:00
|
|
|
QObject* DatasourceFunctions::createTableBuilder(QObject* horizontalLayout)
|
2019-02-05 01:04:23 +03:00
|
|
|
{
|
2020-06-04 21:58:33 +03:00
|
|
|
LimeReport::HorizontalLayout* l = dynamic_cast<LimeReport::HorizontalLayout*>(horizontalLayout);
|
|
|
|
if (l)
|
|
|
|
return new TableBuilder(l, m_dataManager);
|
|
|
|
return 0;
|
2019-02-05 01:04:23 +03:00
|
|
|
}
|
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
TableBuilder::TableBuilder(HorizontalLayout* layout, DataSourceManager* dataManager):
|
|
|
|
m_horizontalLayout(layout),
|
|
|
|
m_baseLayout(0),
|
|
|
|
m_dataManager(dataManager)
|
2019-02-05 22:34:38 +03:00
|
|
|
{
|
|
|
|
if (m_horizontalLayout)
|
2024-09-04 17:31:16 +03:00
|
|
|
m_patternLayout = dynamic_cast<HorizontalLayout*>(
|
|
|
|
m_horizontalLayout->cloneItem(m_horizontalLayout->itemMode()));
|
2019-02-05 22:34:38 +03:00
|
|
|
}
|
|
|
|
|
2019-02-05 01:04:23 +03:00
|
|
|
QObject* TableBuilder::addRow()
|
|
|
|
{
|
|
|
|
checkBaseLayout();
|
2024-09-04 17:31:16 +03:00
|
|
|
if (m_baseLayout && m_patternLayout) {
|
2019-02-05 23:25:18 +03:00
|
|
|
HorizontalLayout* newRow = new HorizontalLayout(m_baseLayout, m_baseLayout);
|
2019-02-27 22:34:34 +03:00
|
|
|
newRow->setLayoutSpacing(m_horizontalLayout->layoutSpacing());
|
2024-09-04 17:31:16 +03:00
|
|
|
for (int i = 0; i < m_horizontalLayout->childrenCount(); ++i) {
|
2019-02-05 23:25:18 +03:00
|
|
|
BaseDesignIntf* item = dynamic_cast<BaseDesignIntf*>(m_patternLayout->at(i));
|
|
|
|
BaseDesignIntf* cloneItem = item->cloneItem(item->itemMode(), newRow, newRow);
|
|
|
|
newRow->addChild(cloneItem);
|
|
|
|
}
|
|
|
|
m_baseLayout->addChild(newRow);
|
|
|
|
return newRow;
|
2024-09-04 17:31:16 +03:00
|
|
|
} else
|
|
|
|
return 0;
|
2019-02-05 01:04:23 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
QObject* TableBuilder::currentRow()
|
|
|
|
{
|
|
|
|
checkBaseLayout();
|
2024-09-04 17:31:16 +03:00
|
|
|
if (m_baseLayout && m_baseLayout->childrenCount() > 0)
|
|
|
|
return m_baseLayout->at(m_baseLayout->childrenCount() - 1);
|
2019-02-05 01:04:23 +03:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void TableBuilder::fillInRowData(QObject* row)
|
|
|
|
{
|
|
|
|
HorizontalLayout* layout = dynamic_cast<HorizontalLayout*>(row);
|
2024-09-04 17:31:16 +03:00
|
|
|
if (layout) {
|
2019-02-05 01:04:23 +03:00
|
|
|
for (int i = 0; i < layout->childrenCount(); ++i) {
|
|
|
|
BaseDesignIntf* item = dynamic_cast<BaseDesignIntf*>(layout->at(i));
|
|
|
|
DataSourceManager* dm = dynamic_cast<DataSourceManager*>(m_dataManager);
|
|
|
|
if (item && dm)
|
|
|
|
item->updateItemSize(dm);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void TableBuilder::buildTable(const QString& datasourceName)
|
|
|
|
{
|
|
|
|
checkBaseLayout();
|
2020-05-25 13:22:02 +03:00
|
|
|
IDataSourceHolder* dh = m_dataManager->dataSourceHolder(datasourceName);
|
|
|
|
if (dh) {
|
|
|
|
dh->invalidate(IDataSource::RENDER_MODE);
|
|
|
|
IDataSource* ds = m_dataManager->dataSource(datasourceName);
|
2024-09-04 17:31:16 +03:00
|
|
|
if (ds) {
|
2020-05-25 13:22:02 +03:00
|
|
|
bool firstTime = true;
|
|
|
|
QObject* row = m_horizontalLayout;
|
2024-09-04 17:31:16 +03:00
|
|
|
while (!ds->eof()) {
|
|
|
|
if (!firstTime)
|
|
|
|
row = addRow();
|
|
|
|
else
|
|
|
|
firstTime = false;
|
2020-05-25 13:22:02 +03:00
|
|
|
fillInRowData(row);
|
|
|
|
ds->next();
|
|
|
|
}
|
2020-02-16 16:47:26 +03:00
|
|
|
}
|
2019-02-05 01:04:23 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void TableBuilder::checkBaseLayout()
|
|
|
|
{
|
2024-09-04 17:31:16 +03:00
|
|
|
if (!m_baseLayout) {
|
2019-02-05 01:04:23 +03:00
|
|
|
m_baseLayout = dynamic_cast<VerticalLayout*>(m_horizontalLayout->parentItem());
|
2024-09-04 17:31:16 +03:00
|
|
|
if (!m_baseLayout) {
|
|
|
|
m_baseLayout = new VerticalLayout(m_horizontalLayout->parent(),
|
|
|
|
m_horizontalLayout->parentItem());
|
2019-02-05 01:04:23 +03:00
|
|
|
m_baseLayout->setItemLocation(m_horizontalLayout->itemLocation());
|
|
|
|
m_baseLayout->setPos(m_horizontalLayout->pos());
|
|
|
|
m_baseLayout->setWidth(m_horizontalLayout->width());
|
|
|
|
m_baseLayout->setHeight(0);
|
|
|
|
m_baseLayout->addChild(m_horizontalLayout);
|
|
|
|
m_baseLayout->setObjectName(QUuid::createUuid().toString());
|
|
|
|
m_baseLayout->setItemTypeName("VerticalLayout");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-02-19 02:23:53 +03:00
|
|
|
#ifdef USE_QTSCRIPTENGINE
|
2024-09-04 17:31:16 +03:00
|
|
|
void ComboBoxPrototype::addItem(const QString& text)
|
2017-09-01 02:02:51 +03:00
|
|
|
{
|
|
|
|
QComboBox* comboBox = qscriptvalue_cast<QComboBox*>(thisObject());
|
2024-09-04 17:31:16 +03:00
|
|
|
if (comboBox) {
|
2017-09-01 02:02:51 +03:00
|
|
|
comboBox->addItem(text);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
void ComboBoxPrototype::addItems(const QStringList& texts)
|
2017-09-01 02:02:51 +03:00
|
|
|
{
|
|
|
|
QComboBox* comboBox = qscriptvalue_cast<QComboBox*>(thisObject());
|
2024-09-04 17:31:16 +03:00
|
|
|
if (comboBox) {
|
2017-09-01 02:02:51 +03:00
|
|
|
comboBox->addItems(texts);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
} // namespace LimeReport
|