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. *
|
|
|
|
|
****************************************************************************/
|
|
|
|
|
#ifndef LRSCRIPTENGINEMANAGER_H
|
|
|
|
|
#define LRSCRIPTENGINEMANAGER_H
|
2019-02-19 02:23:53 +03:00
|
|
|
|
#ifdef USE_QTSCRIPTENGINE
|
2018-03-22 02:38:42 +03:00
|
|
|
|
#include <QScriptable>
|
2024-09-04 17:31:16 +03:00
|
|
|
|
#include <QtScript/QScriptEngine>
|
2018-03-22 02:38:42 +03:00
|
|
|
|
#endif
|
2016-02-17 10:11:00 +03:00
|
|
|
|
#include <QAbstractItemModel>
|
2024-09-04 17:31:16 +03:00
|
|
|
|
#include <QComboBox>
|
2016-02-17 10:11:00 +03:00
|
|
|
|
#include <QDebug>
|
|
|
|
|
#include <QFont>
|
2024-09-04 17:31:16 +03:00
|
|
|
|
#include <QIcon>
|
|
|
|
|
#include <QVector>
|
|
|
|
|
#include <QtGlobal>
|
2016-11-01 20:42:45 +03:00
|
|
|
|
|
|
|
|
|
//#include <QJSEngine>
|
|
|
|
|
|
2016-06-10 18:05:18 +03:00
|
|
|
|
#ifdef HAVE_UI_LOADER
|
|
|
|
|
#include <QDialog>
|
|
|
|
|
#endif
|
|
|
|
|
|
2016-02-17 10:11:00 +03:00
|
|
|
|
#include "base/lrsingleton.h"
|
2017-08-18 22:55:29 +03:00
|
|
|
|
#include "lrcallbackdatasourceintf.h"
|
2016-06-10 18:05:18 +03:00
|
|
|
|
#include "lrcollection.h"
|
2019-01-30 22:50:22 +03:00
|
|
|
|
#include "lrdatasourceintf.h"
|
|
|
|
|
#include "lrdatasourcemanagerintf.h"
|
2024-09-04 17:31:16 +03:00
|
|
|
|
#include "lrglobal.h"
|
2019-02-05 01:04:23 +03:00
|
|
|
|
#include "lrhorizontallayout.h"
|
2024-09-04 17:31:16 +03:00
|
|
|
|
#include "lrscriptenginemanagerintf.h"
|
2019-02-05 01:04:23 +03:00
|
|
|
|
#include "lrverticallayout.h"
|
2016-02-17 10:11:00 +03:00
|
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
|
namespace LimeReport {
|
2016-02-17 10:11:00 +03:00
|
|
|
|
|
2016-02-17 10:28:27 +03:00
|
|
|
|
class DataSourceManager;
|
2017-04-20 23:34:32 +03:00
|
|
|
|
class BaseDesignIntf;
|
2017-08-25 18:01:59 +03:00
|
|
|
|
class PageItemDesignIntf;
|
|
|
|
|
class BandDesignIntf;
|
2016-02-17 10:28:27 +03:00
|
|
|
|
|
2017-08-18 22:55:29 +03:00
|
|
|
|
struct ContentItem {
|
|
|
|
|
QString content;
|
2024-09-04 17:31:16 +03:00
|
|
|
|
int indent;
|
|
|
|
|
int pageNumber;
|
2017-08-31 02:53:34 +03:00
|
|
|
|
QString uniqKey;
|
2017-08-18 22:55:29 +03:00
|
|
|
|
};
|
|
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
|
class TableOfContents: public QObject {
|
2017-08-18 22:55:29 +03:00
|
|
|
|
Q_OBJECT
|
|
|
|
|
public:
|
2024-09-04 17:31:16 +03:00
|
|
|
|
TableOfContents(QObject* parent = 0): QObject(parent) { }
|
2017-11-04 21:17:49 +03:00
|
|
|
|
~TableOfContents();
|
2017-08-19 01:16:57 +03:00
|
|
|
|
void setItem(const QString& uniqKey, const QString& content, int pageNumber, int indent = 0);
|
2017-08-18 22:55:29 +03:00
|
|
|
|
void clear();
|
2024-09-04 17:31:16 +03:00
|
|
|
|
bool isEmpty() { return m_tableOfContents.isEmpty(); }
|
2017-08-18 22:55:29 +03:00
|
|
|
|
private slots:
|
2024-09-04 17:31:16 +03:00
|
|
|
|
void slotOneSlotDS(LimeReport::CallbackInfo info, QVariant& data);
|
|
|
|
|
|
2017-08-18 22:55:29 +03:00
|
|
|
|
private:
|
2024-09-04 17:31:16 +03:00
|
|
|
|
QVector<ContentItem*> m_tableOfContents;
|
|
|
|
|
QHash<QString, ContentItem*> m_hash;
|
2017-08-18 22:55:29 +03:00
|
|
|
|
};
|
|
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
|
struct ScriptFunctionDesc {
|
|
|
|
|
enum FuncType {
|
|
|
|
|
Native,
|
|
|
|
|
Script
|
|
|
|
|
};
|
2016-11-01 20:42:45 +03:00
|
|
|
|
ScriptValueType scriptValue;
|
2016-02-17 10:11:00 +03:00
|
|
|
|
QString name;
|
|
|
|
|
QString description;
|
|
|
|
|
QString category;
|
|
|
|
|
FuncType type;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class ScriptEngineNode {
|
|
|
|
|
public:
|
2024-09-04 17:31:16 +03:00
|
|
|
|
enum NodeType {
|
|
|
|
|
Root,
|
|
|
|
|
Category,
|
|
|
|
|
Function,
|
|
|
|
|
Dialog,
|
|
|
|
|
DialogElement
|
|
|
|
|
};
|
|
|
|
|
ScriptEngineNode(const QString& name = "", const QString& description = "",
|
|
|
|
|
NodeType type = Root, ScriptEngineNode* parent = 0,
|
|
|
|
|
const QIcon& icon = QIcon());
|
2016-02-17 10:11:00 +03:00
|
|
|
|
virtual ~ScriptEngineNode();
|
2024-09-04 17:31:16 +03:00
|
|
|
|
int childCount() { return m_childs.count(); }
|
|
|
|
|
ScriptEngineNode* child(int index) { return m_childs[index]; }
|
|
|
|
|
ScriptEngineNode* parent() { return m_parent; }
|
|
|
|
|
ScriptEngineNode* addChild(const QString& name = "", const QString& description = "",
|
2020-02-04 17:16:48 +03:00
|
|
|
|
NodeType type = Root, const QIcon& icon = QIcon());
|
2024-09-04 17:31:16 +03:00
|
|
|
|
int row();
|
|
|
|
|
QString name() { return m_name; }
|
|
|
|
|
QString description() { return m_description; }
|
|
|
|
|
QIcon icon() { return m_icon; }
|
|
|
|
|
void clear();
|
|
|
|
|
NodeType type() { return m_type; }
|
|
|
|
|
|
2016-02-17 10:11:00 +03:00
|
|
|
|
private:
|
2024-09-04 17:31:16 +03:00
|
|
|
|
QString m_name;
|
|
|
|
|
QString m_description;
|
|
|
|
|
QIcon m_icon;
|
|
|
|
|
NodeType m_type;
|
|
|
|
|
ScriptEngineNode* m_parent;
|
2016-02-17 10:11:00 +03:00
|
|
|
|
QVector<ScriptEngineNode*> m_childs;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class ScriptEngineManager;
|
|
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
|
class ScriptEngineModel: public QAbstractItemModel {
|
2016-02-17 10:11:00 +03:00
|
|
|
|
Q_OBJECT
|
|
|
|
|
public:
|
|
|
|
|
friend class ScriptEngineManager;
|
2024-09-04 17:31:16 +03:00
|
|
|
|
explicit ScriptEngineModel(): m_scriptManager(0), m_rootNode(new ScriptEngineNode()) { }
|
2016-02-17 10:11:00 +03:00
|
|
|
|
explicit ScriptEngineModel(ScriptEngineManager* scriptManager);
|
2016-02-20 12:16:42 +03:00
|
|
|
|
~ScriptEngineModel();
|
2024-09-04 17:31:16 +03:00
|
|
|
|
QModelIndex parent(const QModelIndex& child) const;
|
|
|
|
|
QModelIndex index(int row, int column, const QModelIndex& parent) const;
|
|
|
|
|
int rowCount(const QModelIndex& parent) const;
|
|
|
|
|
int columnCount(const QModelIndex& parent) const;
|
|
|
|
|
QVariant data(const QModelIndex& index, int role) const;
|
2016-02-17 10:11:00 +03:00
|
|
|
|
void setScriptEngineManager(ScriptEngineManager* scriptManager);
|
2024-09-04 17:31:16 +03:00
|
|
|
|
inline ScriptEngineManager* scriptEngineManager() { return m_scriptManager; }
|
2016-02-17 10:11:00 +03:00
|
|
|
|
private slots:
|
|
|
|
|
void slotScriptEngineChanged();
|
2024-09-04 17:31:16 +03:00
|
|
|
|
|
2016-02-17 10:11:00 +03:00
|
|
|
|
private:
|
2024-09-04 17:31:16 +03:00
|
|
|
|
ScriptEngineNode* nodeFromIndex(const QModelIndex& index) const;
|
2016-02-17 10:11:00 +03:00
|
|
|
|
void updateModel();
|
2024-09-04 17:31:16 +03:00
|
|
|
|
|
2016-02-17 10:11:00 +03:00
|
|
|
|
private:
|
|
|
|
|
ScriptEngineManager* m_scriptManager;
|
|
|
|
|
ScriptEngineNode* m_rootNode;
|
|
|
|
|
};
|
|
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
|
class DialogDescriber: public QObject {
|
2016-06-10 18:05:18 +03:00
|
|
|
|
Q_OBJECT
|
|
|
|
|
Q_PROPERTY(QString name READ name WRITE setName)
|
|
|
|
|
Q_PROPERTY(QByteArray description READ description WRITE setDescription)
|
|
|
|
|
public:
|
|
|
|
|
typedef QSharedPointer<DialogDescriber> Ptr;
|
2024-09-04 17:31:16 +03:00
|
|
|
|
static Ptr create(const QString& name, const QByteArray& desc);
|
|
|
|
|
static Ptr create() { return Ptr(new DialogDescriber); }
|
2016-06-10 18:05:18 +03:00
|
|
|
|
QString name() const;
|
|
|
|
|
void setName(const QString& name);
|
|
|
|
|
QByteArray description() const;
|
|
|
|
|
void setDescription(const QByteArray& description);
|
2024-09-04 17:31:16 +03:00
|
|
|
|
|
|
|
|
|
private:
|
2016-06-10 18:05:18 +03:00
|
|
|
|
QString m_name;
|
|
|
|
|
QByteArray m_description;
|
|
|
|
|
};
|
|
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
|
typedef QList<QSharedPointer<PageItemDesignIntf>> ReportPages;
|
2019-03-06 22:16:30 +03:00
|
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
|
class ScriptEngineContext: public QObject, public ICollectionContainer {
|
2016-06-10 18:05:18 +03:00
|
|
|
|
Q_OBJECT
|
|
|
|
|
Q_PROPERTY(ACollectionProperty dialogs READ fakeCollectionReader)
|
|
|
|
|
Q_PROPERTY(QString initScript READ initScript WRITE setInitScript)
|
|
|
|
|
public:
|
|
|
|
|
#ifdef HAVE_UI_LOADER
|
|
|
|
|
typedef QSharedPointer<QDialog> DialogPtr;
|
|
|
|
|
#endif
|
2024-09-04 17:31:16 +03:00
|
|
|
|
explicit ScriptEngineContext(QObject* parent = 0):
|
|
|
|
|
QObject(parent),
|
|
|
|
|
m_currentBand(0),
|
|
|
|
|
m_currentPage(0),
|
|
|
|
|
m_tableOfContents(new TableOfContents(this)),
|
|
|
|
|
m_hasChanges(false)
|
|
|
|
|
{
|
|
|
|
|
}
|
2016-06-10 18:05:18 +03:00
|
|
|
|
#ifdef HAVE_UI_LOADER
|
2024-09-04 17:31:16 +03:00
|
|
|
|
void addDialog(const QString& name, const QByteArray& description);
|
|
|
|
|
bool changeDialog(const QString& name, const QByteArray& description);
|
|
|
|
|
bool changeDialogName(const QString& oldName, const QString& newName);
|
|
|
|
|
bool previewDialog(const QString& dialogName);
|
|
|
|
|
bool containsDialog(const QString& dialogName);
|
|
|
|
|
const QVector<DialogDescriber::Ptr>& dialogDescribers() { return m_dialogs; }
|
|
|
|
|
void deleteDialog(const QString& dialogName);
|
|
|
|
|
QDialog* getDialog(const QString& dialogName);
|
2017-04-14 02:43:34 +03:00
|
|
|
|
QString getNewDialogName();
|
2024-09-04 17:31:16 +03:00
|
|
|
|
void initDialogs();
|
2016-06-10 18:05:18 +03:00
|
|
|
|
#endif
|
2024-09-04 17:31:16 +03:00
|
|
|
|
void baseDesignIntfToScript(const QString& pageName, BaseDesignIntf* item);
|
|
|
|
|
void qobjectToScript(const QString& name, QObject* item);
|
|
|
|
|
void clear();
|
2016-06-10 18:05:18 +03:00
|
|
|
|
QString initScript() const;
|
2024-09-04 17:31:16 +03:00
|
|
|
|
void setInitScript(const QString& initScript);
|
|
|
|
|
bool runInitScript();
|
2017-08-25 18:01:59 +03:00
|
|
|
|
|
2021-04-12 20:22:34 +03:00
|
|
|
|
BandDesignIntf* currentBand() const;
|
2017-08-25 18:01:59 +03:00
|
|
|
|
void setCurrentBand(BandDesignIntf* currentBand);
|
2021-04-12 20:22:34 +03:00
|
|
|
|
PageItemDesignIntf* currentPage() const;
|
2017-08-25 18:01:59 +03:00
|
|
|
|
void setCurrentPage(PageItemDesignIntf* currentPage);
|
2017-11-04 21:17:49 +03:00
|
|
|
|
TableOfContents* tableOfContents() const;
|
|
|
|
|
void setTableOfContents(TableOfContents* tableOfContents);
|
2024-09-04 17:31:16 +03:00
|
|
|
|
void dropChanges() { m_hasChanges = false; }
|
|
|
|
|
bool hasChanges() { return m_hasChanges; }
|
2019-03-06 22:16:30 +03:00
|
|
|
|
ReportPages* reportPages() const;
|
|
|
|
|
void setReportPages(ReportPages* value);
|
2022-03-29 15:33:34 +03:00
|
|
|
|
#ifdef HAVE_UI_LOADER
|
2017-04-14 02:43:34 +03:00
|
|
|
|
signals:
|
2024-09-04 17:31:16 +03:00
|
|
|
|
void dialogNameChanged(QString dialogName);
|
|
|
|
|
void dialogDeleted(QString dialogName);
|
|
|
|
|
void dialogAdded(QString dialogName);
|
2017-04-20 23:34:32 +03:00
|
|
|
|
#endif
|
2016-06-10 18:05:18 +03:00
|
|
|
|
protected:
|
2024-09-04 17:31:16 +03:00
|
|
|
|
QObject* createElement(const QString& collectionName, const QString& elementType);
|
|
|
|
|
int elementsCount(const QString& collectionName);
|
|
|
|
|
QObject* elementAt(const QString& collectionName, int index);
|
|
|
|
|
void collectionLoadFinished(const QString& collectionName);
|
2016-06-10 18:05:18 +03:00
|
|
|
|
#ifdef HAVE_UI_LOADER
|
2024-09-04 17:31:16 +03:00
|
|
|
|
QDialog* createDialog(DialogDescriber* cont);
|
|
|
|
|
QDialog* findDialog(const QString& dialogName);
|
2016-06-10 18:05:18 +03:00
|
|
|
|
DialogDescriber* findDialogContainer(const QString& dialogName);
|
|
|
|
|
#endif
|
|
|
|
|
private:
|
|
|
|
|
#ifdef HAVE_UI_LOADER
|
|
|
|
|
QVector<DialogDescriber::Ptr> m_dialogs;
|
|
|
|
|
QList<DialogPtr> m_createdDialogs;
|
|
|
|
|
#endif
|
|
|
|
|
QString m_lastError;
|
|
|
|
|
QString m_initScript;
|
2017-08-25 18:01:59 +03:00
|
|
|
|
BandDesignIntf* m_currentBand;
|
|
|
|
|
PageItemDesignIntf* m_currentPage;
|
2017-11-04 21:17:49 +03:00
|
|
|
|
TableOfContents* m_tableOfContents;
|
2019-02-05 21:51:46 +03:00
|
|
|
|
bool m_hasChanges;
|
2019-03-06 22:16:30 +03:00
|
|
|
|
ReportPages* m_reportPages;
|
2016-06-10 18:05:18 +03:00
|
|
|
|
};
|
|
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
|
class JSFunctionDesc {
|
2016-11-01 20:42:45 +03:00
|
|
|
|
public:
|
2024-09-04 17:31:16 +03:00
|
|
|
|
JSFunctionDesc() { }
|
|
|
|
|
JSFunctionDesc(const QString& functionName, const QString& functionCategory,
|
|
|
|
|
const QString& functionDescription, const QString& functionManagerName,
|
|
|
|
|
QObject* functionManager, const QString& functionScriptWrapper):
|
|
|
|
|
m_name(functionName),
|
|
|
|
|
m_category(functionCategory),
|
|
|
|
|
m_description(functionDescription),
|
|
|
|
|
m_managerName(functionManagerName),
|
|
|
|
|
m_manager(functionManager),
|
|
|
|
|
m_scriptWrapper(functionScriptWrapper)
|
|
|
|
|
{
|
|
|
|
|
}
|
2016-11-01 20:42:45 +03:00
|
|
|
|
QString name() const;
|
2024-09-04 17:31:16 +03:00
|
|
|
|
void setName(const QString& name);
|
2016-11-01 20:42:45 +03:00
|
|
|
|
|
|
|
|
|
QString category() const;
|
2024-09-04 17:31:16 +03:00
|
|
|
|
void setCategory(const QString& category);
|
2016-11-01 20:42:45 +03:00
|
|
|
|
|
|
|
|
|
QString description() const;
|
2024-09-04 17:31:16 +03:00
|
|
|
|
void setDescription(const QString& description);
|
2016-11-01 20:42:45 +03:00
|
|
|
|
|
|
|
|
|
QString managerName() const;
|
2024-09-04 17:31:16 +03:00
|
|
|
|
void setManagerName(const QString& managerName);
|
2016-11-01 20:42:45 +03:00
|
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
|
QObject* manager() const;
|
|
|
|
|
void setManager(QObject* manager);
|
2016-11-01 20:42:45 +03:00
|
|
|
|
|
|
|
|
|
QString scriptWrapper() const;
|
2024-09-04 17:31:16 +03:00
|
|
|
|
void setScriptWrapper(const QString& scriptWrapper);
|
2016-11-01 20:42:45 +03:00
|
|
|
|
|
|
|
|
|
private:
|
2024-09-04 17:31:16 +03:00
|
|
|
|
QString m_name;
|
|
|
|
|
QString m_category;
|
|
|
|
|
QString m_description;
|
|
|
|
|
QString m_managerName;
|
2016-11-01 20:42:45 +03:00
|
|
|
|
QObject* m_manager;
|
2024-09-04 17:31:16 +03:00
|
|
|
|
QString m_scriptWrapper;
|
2016-11-01 20:42:45 +03:00
|
|
|
|
};
|
|
|
|
|
|
2019-02-19 02:23:53 +03:00
|
|
|
|
#ifdef USE_QTSCRIPTENGINE
|
2024-09-04 17:31:16 +03:00
|
|
|
|
class ComboBoxPrototype: public QObject, public QScriptable {
|
2017-09-01 02:02:51 +03:00
|
|
|
|
Q_OBJECT
|
|
|
|
|
public:
|
2024-09-04 17:31:16 +03:00
|
|
|
|
ComboBoxPrototype(QObject* parent = 0): QObject(parent) { }
|
2017-09-01 02:02:51 +03:00
|
|
|
|
public slots:
|
2024-09-04 17:31:16 +03:00
|
|
|
|
void addItem(const QString& text);
|
2017-09-01 02:02:51 +03:00
|
|
|
|
void addItems(const QStringList& texts);
|
|
|
|
|
};
|
|
|
|
|
#endif
|
|
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
|
class IWrapperCreator {
|
2017-09-01 02:02:51 +03:00
|
|
|
|
public:
|
|
|
|
|
virtual QObject* createWrapper(QObject* item) = 0;
|
2024-09-04 17:31:16 +03:00
|
|
|
|
virtual ~IWrapperCreator() { }
|
2017-09-01 02:02:51 +03:00
|
|
|
|
};
|
|
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
|
class ComboBoxWrapper: public QObject {
|
2017-09-01 02:02:51 +03:00
|
|
|
|
Q_OBJECT
|
|
|
|
|
public:
|
2024-09-04 17:31:16 +03:00
|
|
|
|
ComboBoxWrapper(QComboBox* comboBox, QObject* parent = 0): QObject(parent), m_comboBox(comboBox)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
Q_INVOKABLE void addItems(const QStringList& texts) { m_comboBox->addItems(texts); }
|
|
|
|
|
Q_INVOKABLE void addItem(const QString& text) { m_comboBox->addItem(text); }
|
|
|
|
|
|
2017-09-01 02:02:51 +03:00
|
|
|
|
private:
|
|
|
|
|
QComboBox* m_comboBox;
|
|
|
|
|
};
|
|
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
|
class ComboBoxWrapperCreator: public IWrapperCreator {
|
2017-09-01 02:02:51 +03:00
|
|
|
|
private:
|
|
|
|
|
QObject* createWrapper(QObject* item);
|
|
|
|
|
};
|
|
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
|
class TableBuilder: public QObject {
|
2019-02-05 01:04:23 +03:00
|
|
|
|
Q_OBJECT
|
|
|
|
|
public:
|
2019-02-05 22:34:38 +03:00
|
|
|
|
TableBuilder(LimeReport::HorizontalLayout* layout, DataSourceManager* dataManager);
|
2024-09-04 17:31:16 +03:00
|
|
|
|
~TableBuilder() { delete m_patternLayout; }
|
2019-02-05 01:04:23 +03:00
|
|
|
|
Q_INVOKABLE QObject* addRow();
|
|
|
|
|
Q_INVOKABLE QObject* currentRow();
|
|
|
|
|
Q_INVOKABLE void fillInRowData(QObject* row);
|
|
|
|
|
Q_INVOKABLE void buildTable(const QString& datasourceName);
|
2024-09-04 17:31:16 +03:00
|
|
|
|
|
2019-02-05 01:04:23 +03:00
|
|
|
|
private:
|
|
|
|
|
void checkBaseLayout();
|
2024-09-04 17:31:16 +03:00
|
|
|
|
|
2019-02-05 01:04:23 +03:00
|
|
|
|
private:
|
|
|
|
|
LimeReport::HorizontalLayout* m_horizontalLayout;
|
2019-02-05 22:34:38 +03:00
|
|
|
|
LimeReport::HorizontalLayout* m_patternLayout;
|
2019-02-05 01:04:23 +03:00
|
|
|
|
LimeReport::VerticalLayout* m_baseLayout;
|
|
|
|
|
DataSourceManager* m_dataManager;
|
|
|
|
|
};
|
|
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
|
class DatasourceFunctions: public QObject {
|
2019-01-30 22:50:22 +03:00
|
|
|
|
Q_OBJECT
|
|
|
|
|
public:
|
2024-09-04 17:31:16 +03:00
|
|
|
|
explicit DatasourceFunctions(IDataSourceManager* dataManager):
|
|
|
|
|
m_dataManager(dynamic_cast<DataSourceManager*>(dataManager))
|
|
|
|
|
{
|
|
|
|
|
}
|
2019-01-31 22:30:41 +03:00
|
|
|
|
Q_INVOKABLE bool first(const QString& datasourceName);
|
2019-01-30 22:50:22 +03:00
|
|
|
|
Q_INVOKABLE bool next(const QString& datasourceName);
|
2019-01-31 22:30:41 +03:00
|
|
|
|
Q_INVOKABLE bool prior(const QString& datasourceName);
|
2019-01-30 22:50:22 +03:00
|
|
|
|
Q_INVOKABLE bool isEOF(const QString& datasourceName);
|
2022-03-29 15:33:34 +03:00
|
|
|
|
Q_INVOKABLE int rowCount(const QString& datasourceName);
|
2019-01-31 22:30:41 +03:00
|
|
|
|
Q_INVOKABLE bool invalidate(const QString& datasourceName);
|
2024-09-04 17:31:16 +03:00
|
|
|
|
Q_INVOKABLE QObject* createTableBuilder(QObject* horizontalLayout);
|
|
|
|
|
|
2019-01-30 22:50:22 +03:00
|
|
|
|
private:
|
2020-06-04 21:58:33 +03:00
|
|
|
|
DataSourceManager* m_dataManager;
|
2019-01-30 22:50:22 +03:00
|
|
|
|
};
|
|
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
|
class ScriptFunctionsManager: public QObject {
|
2016-11-01 20:42:45 +03:00
|
|
|
|
Q_OBJECT
|
|
|
|
|
public:
|
2024-09-04 17:31:16 +03:00
|
|
|
|
explicit ScriptFunctionsManager(QObject* parent = 0): QObject(parent)
|
|
|
|
|
{
|
|
|
|
|
m_wrappersFactory.insert("QComboBox", new ComboBoxWrapperCreator());
|
2017-10-26 12:24:06 +03:00
|
|
|
|
}
|
2024-09-04 17:31:16 +03:00
|
|
|
|
~ScriptFunctionsManager()
|
|
|
|
|
{
|
|
|
|
|
foreach (IWrapperCreator* wrapper, m_wrappersFactory.values()) {
|
|
|
|
|
delete wrapper;
|
|
|
|
|
}
|
|
|
|
|
m_wrappersFactory.clear();
|
2017-10-26 12:24:06 +03:00
|
|
|
|
}
|
2024-09-04 17:31:16 +03:00
|
|
|
|
Q_INVOKABLE QVariant calcGroupFunction(const QString& name, const QString& expressionID,
|
|
|
|
|
const QString& bandName, QObject* currentPage);
|
|
|
|
|
Q_INVOKABLE QVariant calcGroupFunction(const QString& name, const QString& expressionID,
|
|
|
|
|
const QString& bandName);
|
2016-11-01 20:42:45 +03:00
|
|
|
|
Q_INVOKABLE QVariant line(const QString& bandName);
|
2024-09-04 17:31:16 +03:00
|
|
|
|
Q_INVOKABLE QVariant numberFormat(QVariant value, const char& format, int precision,
|
|
|
|
|
const QString& locale);
|
2019-07-01 17:01:55 +03:00
|
|
|
|
Q_INVOKABLE QVariant dateFormat(QVariant value, const QString& format, const QString& locale);
|
2016-11-01 20:42:45 +03:00
|
|
|
|
Q_INVOKABLE QVariant timeFormat(QVariant value, const QString& format);
|
2024-09-04 17:31:16 +03:00
|
|
|
|
Q_INVOKABLE QVariant dateTimeFormat(QVariant value, const QString& format,
|
|
|
|
|
const QString& locale);
|
2017-12-22 12:36:46 +03:00
|
|
|
|
Q_INVOKABLE QVariant sectotimeFormat(QVariant value, const QString& format);
|
2016-11-01 20:42:45 +03:00
|
|
|
|
Q_INVOKABLE QVariant date();
|
|
|
|
|
Q_INVOKABLE QVariant now();
|
|
|
|
|
Q_INVOKABLE QVariant currencyFormat(QVariant value, const QString& locale);
|
|
|
|
|
Q_INVOKABLE QVariant currencyUSBasedFormat(QVariant value, const QString& currencySymbol);
|
2024-09-04 17:31:16 +03:00
|
|
|
|
Q_INVOKABLE void setVariable(const QString& name, QVariant value);
|
2017-02-11 00:21:03 +03:00
|
|
|
|
Q_INVOKABLE QVariant getVariable(const QString& name);
|
|
|
|
|
Q_INVOKABLE QVariant getField(const QString& field);
|
2024-09-04 17:31:16 +03:00
|
|
|
|
Q_INVOKABLE QVariant getFieldByKeyField(const QString& datasourceName,
|
|
|
|
|
const QString& valueFieldName,
|
|
|
|
|
const QString& keyFieldName, QVariant keyValue);
|
2019-02-19 02:23:53 +03:00
|
|
|
|
Q_INVOKABLE QVariant getFieldByRowIndex(const QString& fieldName, int rowIndex);
|
2024-09-04 17:31:16 +03:00
|
|
|
|
Q_INVOKABLE void reopenDatasource(const QString& datasourceName);
|
|
|
|
|
Q_INVOKABLE QVariant color(const QString& color) { return QColor(color); }
|
|
|
|
|
Q_INVOKABLE void addBookmark(const QString& uniqKey, const QString& content);
|
|
|
|
|
Q_INVOKABLE int findPageIndexByBookmark(const QString& uniqKey);
|
|
|
|
|
Q_INVOKABLE void addTableOfContentsItem(const QString& uniqKey, const QString& content,
|
|
|
|
|
int indent = 0);
|
|
|
|
|
Q_INVOKABLE void clearTableOfContents();
|
|
|
|
|
Q_INVOKABLE QFont font(const QString& family, int pointSize = -1, bool bold = false,
|
|
|
|
|
bool italic = false, bool underLine = false);
|
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
|
|
|
|
/*!
|
|
|
|
|
* \brief getFieldByRowIndexEx Выдает для поля значение заданной роли
|
|
|
|
|
* \param fieldName имя источника данных + имя поля
|
|
|
|
|
* \param rowIndex индекс строки
|
|
|
|
|
* \param role код роли
|
|
|
|
|
* \return
|
2024-09-04 17:31:16 +03:00
|
|
|
|
*/
|
|
|
|
|
Q_INVOKABLE QVariant 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
|
|
|
|
/*!
|
|
|
|
|
* \brief getFieldByRowIndexEx2 Выдает для поля значение заданной роли
|
|
|
|
|
* \param fieldName имя источника данных + имя поля
|
|
|
|
|
* \param rowIndex индекс строки
|
|
|
|
|
* \param roleName имя роли из roleNames()
|
|
|
|
|
* \return
|
2024-09-04 17:31:16 +03:00
|
|
|
|
*/
|
|
|
|
|
Q_INVOKABLE QVariant 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
|
|
|
|
/*!
|
|
|
|
|
* \brief getHeaderData Выдает для поля заголовка значение заданной роли
|
|
|
|
|
* \param fieldName имя источника данных + имя поля
|
|
|
|
|
* \param role имя роли из roleNames()
|
|
|
|
|
* \return
|
2024-09-04 17:31:16 +03:00
|
|
|
|
*/
|
|
|
|
|
Q_INVOKABLE QVariant 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
|
|
|
|
/*!
|
|
|
|
|
* \brief getHeaderColumnNameByIndex Выдает имя колонки по ее индексу (имя используемое LR)
|
|
|
|
|
* \param datasourceName имя источника данных
|
|
|
|
|
* \param columnIndex индекс колонки
|
|
|
|
|
* \return
|
2024-09-04 17:31:16 +03:00
|
|
|
|
*/
|
|
|
|
|
Q_INVOKABLE QVariant 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
|
|
|
|
/*!
|
|
|
|
|
* \brief getColumnCount Выдает число столбцов в источнике данных
|
|
|
|
|
* \param datasourceName имя источника данных
|
|
|
|
|
* \return возможно -1 при ошибке
|
2024-09-04 17:31:16 +03:00
|
|
|
|
*/
|
|
|
|
|
Q_INVOKABLE int 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
|
|
|
|
|
2016-11-01 20:42:45 +03:00
|
|
|
|
#ifdef USE_QJSENGINE
|
2017-09-01 02:02:51 +03:00
|
|
|
|
Q_INVOKABLE void addItemsToComboBox(QJSValue object, const QStringList& values);
|
|
|
|
|
Q_INVOKABLE void addItemToComboBox(QJSValue object, const QString& value);
|
|
|
|
|
Q_INVOKABLE QJSValue createComboBoxWrapper(QJSValue comboBox);
|
|
|
|
|
Q_INVOKABLE QJSValue createWrapper(QJSValue item);
|
2017-12-14 02:28:52 +03:00
|
|
|
|
#else
|
|
|
|
|
Q_INVOKABLE void addItemsToComboBox(QScriptValue object, const QStringList& values);
|
|
|
|
|
Q_INVOKABLE void addItemToComboBox(QScriptValue object, const QString& value);
|
|
|
|
|
Q_INVOKABLE QScriptValue createComboBoxWrapper(QScriptValue comboBox);
|
|
|
|
|
Q_INVOKABLE QScriptValue createWrapper(QScriptValue item);
|
2016-11-01 20:42:45 +03:00
|
|
|
|
#endif
|
|
|
|
|
Q_INVOKABLE QFont font(QVariantMap params);
|
2024-09-04 17:31:16 +03:00
|
|
|
|
Q_INVOKABLE int getPageFreeSpace(QObject* page);
|
|
|
|
|
ScriptEngineManager* scriptEngineManager() const;
|
|
|
|
|
void setScriptEngineManager(ScriptEngineManager* scriptEngineManager);
|
|
|
|
|
static QColor createQColor(const QString& color) { return QColor(color); }
|
|
|
|
|
|
2016-11-01 20:42:45 +03:00
|
|
|
|
private:
|
|
|
|
|
ScriptEngineManager* m_scriptEngineManager;
|
2017-09-01 02:02:51 +03:00
|
|
|
|
QMap<QString, IWrapperCreator*> m_wrappersFactory;
|
2016-11-01 20:42:45 +03:00
|
|
|
|
};
|
|
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
|
class ScriptNode {
|
2019-09-09 21:25:08 +03:00
|
|
|
|
public:
|
2021-05-24 22:14:24 +03:00
|
|
|
|
typedef QSharedPointer<ScriptNode> Ptr;
|
2024-09-04 17:31:16 +03:00
|
|
|
|
QString body()
|
|
|
|
|
{
|
2022-07-16 02:33:39 +03:00
|
|
|
|
if (m_body.isEmpty() && m_children.count() > 0)
|
2024-09-04 17:31:16 +03:00
|
|
|
|
return m_children.at(0)->body();
|
2022-07-16 02:33:39 +03:00
|
|
|
|
return m_body;
|
|
|
|
|
}
|
2024-09-04 17:31:16 +03:00
|
|
|
|
void setBody(const QString& body) { m_body = body; }
|
|
|
|
|
void setStartLex(const QString startLex) { m_startLex = startLex; }
|
|
|
|
|
QString script() { return m_startLex + m_body + '}'; }
|
|
|
|
|
Ptr createChildNode()
|
|
|
|
|
{
|
2021-05-24 22:14:24 +03:00
|
|
|
|
Ptr result = Ptr(new ScriptNode());
|
2019-09-09 21:25:08 +03:00
|
|
|
|
m_children.append(result);
|
|
|
|
|
return result;
|
|
|
|
|
}
|
2024-09-04 17:31:16 +03:00
|
|
|
|
QVector<Ptr> children() const { return m_children; }
|
|
|
|
|
|
2019-09-09 21:25:08 +03:00
|
|
|
|
private:
|
2021-05-24 22:14:24 +03:00
|
|
|
|
QVector<Ptr> m_children;
|
2019-09-09 21:25:08 +03:00
|
|
|
|
QString m_body;
|
|
|
|
|
QString m_startLex;
|
|
|
|
|
};
|
|
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
|
class ScriptExtractor {
|
2019-09-09 21:25:08 +03:00
|
|
|
|
public:
|
2024-09-04 17:31:16 +03:00
|
|
|
|
enum State {
|
|
|
|
|
None,
|
|
|
|
|
BuksFound,
|
|
|
|
|
SFound,
|
|
|
|
|
StartScriptFound,
|
|
|
|
|
OpenBracketFound,
|
|
|
|
|
CloseBracketFound,
|
|
|
|
|
DFound,
|
|
|
|
|
VFound,
|
|
|
|
|
SignFound
|
|
|
|
|
};
|
2019-09-09 21:25:08 +03:00
|
|
|
|
explicit ScriptExtractor(const QString& value):
|
2024-09-04 17:31:16 +03:00
|
|
|
|
m_context(value),
|
|
|
|
|
m_scriptTree(ScriptNode::Ptr(new ScriptNode()))
|
|
|
|
|
{
|
|
|
|
|
}
|
2019-09-09 21:25:08 +03:00
|
|
|
|
bool parse();
|
2024-09-04 17:31:16 +03:00
|
|
|
|
ScriptNode::Ptr scriptTree() { return m_scriptTree; }
|
|
|
|
|
|
2019-09-09 21:25:08 +03:00
|
|
|
|
private:
|
2024-09-04 17:31:16 +03:00
|
|
|
|
bool isStartLexem(int& curPos, QChar value);
|
|
|
|
|
bool parse(int& curPos, const State& state, ScriptNode::Ptr scriptNode);
|
|
|
|
|
void skipField(int& curPos);
|
|
|
|
|
void extractScript(int& curPos, const QString& startStr, ScriptNode::Ptr scriptNode);
|
2021-05-24 22:14:24 +03:00
|
|
|
|
bool extractBracket(int& curPos, ScriptNode::Ptr scriptNode);
|
2024-09-04 17:31:16 +03:00
|
|
|
|
bool isStartScriptLexem(int& curPos);
|
|
|
|
|
bool isStartFieldLexem(int& curPos);
|
|
|
|
|
bool isStartVariableLexem(int& curPos);
|
2019-09-09 21:25:08 +03:00
|
|
|
|
QString substring(const QString& value, int start, int end);
|
2024-09-04 17:31:16 +03:00
|
|
|
|
|
2019-09-09 21:25:08 +03:00
|
|
|
|
private:
|
|
|
|
|
QString m_context;
|
2021-05-24 22:14:24 +03:00
|
|
|
|
ScriptNode::Ptr m_scriptTree;
|
2019-09-09 21:25:08 +03:00
|
|
|
|
};
|
|
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
|
class ScriptEngineManager:
|
|
|
|
|
public QObject,
|
|
|
|
|
public Singleton<ScriptEngineManager>,
|
|
|
|
|
public IScriptEngineManager {
|
2016-02-17 10:11:00 +03:00
|
|
|
|
Q_OBJECT
|
|
|
|
|
public:
|
|
|
|
|
friend class Singleton<ScriptEngineManager>;
|
2024-09-04 17:31:16 +03:00
|
|
|
|
ScriptEngineType* scriptEngine() { return m_scriptEngine; }
|
2016-11-01 20:42:45 +03:00
|
|
|
|
~ScriptEngineManager();
|
2016-02-17 10:28:27 +03:00
|
|
|
|
bool isFunctionExists(const QString& functionName) const;
|
|
|
|
|
void deleteFunction(const QString& functionsName);
|
2016-11-01 20:42:45 +03:00
|
|
|
|
|
|
|
|
|
bool addFunction(const JSFunctionDesc& functionsDescriber);
|
2019-02-19 02:23:53 +03:00
|
|
|
|
#ifdef USE_QTSCRIPTENGINE
|
2024-09-04 17:31:16 +03:00
|
|
|
|
bool addFunction(const QString& name, QScriptEngine::FunctionSignature function,
|
|
|
|
|
const QString& category, const QString& description);
|
2016-11-01 20:42:45 +03:00
|
|
|
|
#endif
|
2024-09-04 17:31:16 +03:00
|
|
|
|
bool addFunction(const QString& name, const QString& script, const QString& category = "",
|
|
|
|
|
const QString& description = "");
|
|
|
|
|
const QString& lastError() const { return m_lastError; }
|
2016-02-17 10:11:00 +03:00
|
|
|
|
QStringList functionsNames();
|
2024-09-04 17:31:16 +03:00
|
|
|
|
const QHash<QString, ScriptFunctionDesc>& functionsDescribers() { return m_functions; }
|
|
|
|
|
ScriptEngineModel* model() { return m_model; }
|
|
|
|
|
void setContext(ScriptEngineContext* context) { m_context = context; }
|
|
|
|
|
DataSourceManager* dataManager() const { return m_dataManager; }
|
2016-02-17 10:28:27 +03:00
|
|
|
|
void setDataManager(DataSourceManager* dataManager);
|
2016-08-12 21:15:50 +03:00
|
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
|
QString expandUserVariables(QString context, RenderPass pass, ExpandType expandType,
|
|
|
|
|
QVariant& varValue);
|
|
|
|
|
QString expandDataFields(QString context, ExpandType expandType, QVariant& varValue,
|
|
|
|
|
QObject* reportItem);
|
|
|
|
|
QString expandScripts(QString context, QVariant& varValue, QObject* reportItem);
|
|
|
|
|
|
|
|
|
|
QString replaceScripts(QString context, QVariant& varValue, QObject* reportItem,
|
|
|
|
|
ScriptEngineType* se, ScriptNode::Ptr scriptTree);
|
|
|
|
|
|
|
|
|
|
QVariant evaluateScript(const QString& script);
|
|
|
|
|
void addBookMark(const QString& uniqKey, const QString& content);
|
|
|
|
|
int findPageIndexByBookmark(const QString& uniqKey);
|
|
|
|
|
void addTableOfContentsItem(const QString& uniqKey, const QString& content, int indent);
|
|
|
|
|
void clearTableOfContents();
|
|
|
|
|
int getPageFreeSpace(PageItemDesignIntf* page);
|
2019-01-30 01:53:21 +03:00
|
|
|
|
ScriptValueType moveQObjectToScript(QObject* object, const QString objectName);
|
2024-09-04 17:31:16 +03:00
|
|
|
|
|
2016-06-10 18:05:18 +03:00
|
|
|
|
protected:
|
|
|
|
|
void updateModel();
|
2024-09-04 17:31:16 +03:00
|
|
|
|
|
2016-02-17 10:11:00 +03:00
|
|
|
|
private:
|
|
|
|
|
Q_DISABLE_COPY(ScriptEngineManager)
|
2016-11-01 20:42:45 +03:00
|
|
|
|
bool createLineFunction();
|
|
|
|
|
bool createNumberFomatFunction();
|
|
|
|
|
bool createDateFormatFunction();
|
|
|
|
|
bool createTimeFormatFunction();
|
|
|
|
|
bool createDateTimeFormatFunction();
|
2017-12-22 12:36:46 +03:00
|
|
|
|
bool createSectotimeFormatFunction();
|
2016-11-01 20:42:45 +03:00
|
|
|
|
bool createDateFunction();
|
|
|
|
|
bool createNowFunction();
|
|
|
|
|
bool createCurrencyFormatFunction();
|
|
|
|
|
bool createCurrencyUSBasedFormatFunction();
|
|
|
|
|
bool createSetVariableFunction();
|
2017-02-11 00:21:03 +03:00
|
|
|
|
bool createGetVariableFunction();
|
|
|
|
|
bool createGetFieldFunction();
|
2017-08-31 02:53:34 +03:00
|
|
|
|
bool createGetFieldByKeyFunction();
|
2019-02-19 02:23:53 +03:00
|
|
|
|
bool createGetFieldByRowIndex();
|
2019-03-06 22:16:30 +03:00
|
|
|
|
bool createAddBookmarkFunction();
|
|
|
|
|
bool createFindPageIndexByBookmark();
|
2017-11-04 21:17:49 +03:00
|
|
|
|
bool createAddTableOfContentsItemFunction();
|
|
|
|
|
bool createClearTableOfContentsFunction();
|
2017-09-19 21:02:55 +03:00
|
|
|
|
bool 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
|
|
|
|
bool createGetFieldByRowIndexEx();
|
|
|
|
|
bool createGetFieldByRowIndexEx2();
|
|
|
|
|
bool createHeaderData();
|
|
|
|
|
bool createHeaderColumnNameByIndex();
|
|
|
|
|
bool createColumnCount();
|
|
|
|
|
|
2016-02-17 10:11:00 +03:00
|
|
|
|
private:
|
|
|
|
|
ScriptEngineManager();
|
2024-09-04 17:31:16 +03:00
|
|
|
|
ScriptEngineType* m_scriptEngine;
|
2016-02-17 10:11:00 +03:00
|
|
|
|
QString m_lastError;
|
2024-09-04 17:31:16 +03:00
|
|
|
|
QHash<QString, ScriptFunctionDesc> m_functions;
|
2016-02-17 10:11:00 +03:00
|
|
|
|
ScriptEngineModel* m_model;
|
2016-06-10 18:05:18 +03:00
|
|
|
|
ScriptEngineContext* m_context;
|
2016-02-17 10:28:27 +03:00
|
|
|
|
DataSourceManager* m_dataManager;
|
2016-11-01 20:42:45 +03:00
|
|
|
|
ScriptFunctionsManager* m_functionManager;
|
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
|
|
|
|
class QFontPrototype: public QObject, public QScriptable {
|
2016-02-17 10:11:00 +03:00
|
|
|
|
Q_OBJECT
|
|
|
|
|
Q_PROPERTY(QString family READ family)
|
|
|
|
|
Q_PROPERTY(int size READ size)
|
|
|
|
|
Q_PROPERTY(bool bold READ bold)
|
|
|
|
|
Q_PROPERTY(bool italic READ italic)
|
|
|
|
|
Q_PROPERTY(bool underline READ underline)
|
|
|
|
|
public:
|
2024-09-04 17:31:16 +03:00
|
|
|
|
QFontPrototype(QObject* parent = NULL): QObject(parent), QScriptable()
|
|
|
|
|
{
|
2016-02-17 10:11:00 +03:00
|
|
|
|
this->setObjectName("QFontPrototype");
|
|
|
|
|
}
|
2024-09-04 17:31:16 +03:00
|
|
|
|
QString family() const
|
|
|
|
|
{
|
2016-02-17 10:11:00 +03:00
|
|
|
|
QFont font(qScriptValueToValue<QFont>(this->thisObject()));
|
|
|
|
|
return font.family();
|
|
|
|
|
}
|
2024-09-04 17:31:16 +03:00
|
|
|
|
int size()
|
|
|
|
|
{
|
2016-02-17 10:11:00 +03:00
|
|
|
|
QFont font = qScriptValueToValue<QFont>(thisObject());
|
|
|
|
|
return font.pointSize();
|
|
|
|
|
}
|
2024-09-04 17:31:16 +03:00
|
|
|
|
bool bold()
|
|
|
|
|
{
|
2016-02-17 10:11:00 +03:00
|
|
|
|
QFont font = qScriptValueToValue<QFont>(thisObject());
|
|
|
|
|
return font.bold();
|
|
|
|
|
}
|
2024-09-04 17:31:16 +03:00
|
|
|
|
bool italic()
|
|
|
|
|
{
|
2016-02-17 10:11:00 +03:00
|
|
|
|
QFont font = qScriptValueToValue<QFont>(thisObject());
|
|
|
|
|
return font.italic();
|
|
|
|
|
}
|
2024-09-04 17:31:16 +03:00
|
|
|
|
bool underline()
|
|
|
|
|
{
|
2016-02-17 10:11:00 +03:00
|
|
|
|
QFont font = qScriptValueToValue<QFont>(thisObject());
|
|
|
|
|
return font.underline();
|
|
|
|
|
}
|
2024-09-04 17:31:16 +03:00
|
|
|
|
static QScriptValue constructorQFont(QScriptContext* context, QScriptEngine* engine)
|
|
|
|
|
{
|
2016-02-17 10:11:00 +03:00
|
|
|
|
QFont font;
|
|
|
|
|
switch (context->argumentCount()) {
|
2024-09-04 17:31:16 +03:00
|
|
|
|
case 5:
|
|
|
|
|
font.setUnderline(qScriptValueToValue<bool>(context->argument(4)));
|
|
|
|
|
case 4:
|
|
|
|
|
font.setBold(qScriptValueToValue<bool>(context->argument(3)));
|
|
|
|
|
case 3:
|
|
|
|
|
font.setItalic(qScriptValueToValue<bool>(context->argument(2)));
|
|
|
|
|
case 2:
|
|
|
|
|
font.setPointSize(qScriptValueToValue<int>(context->argument(1)));
|
|
|
|
|
case 1:
|
|
|
|
|
font.setFamily(qScriptValueToValue<QString>(context->argument(0)));
|
|
|
|
|
case 0:
|
|
|
|
|
break;
|
2016-02-17 10:11:00 +03:00
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
return qScriptValueFromValue<QFont>(engine, font);
|
|
|
|
|
}
|
|
|
|
|
};
|
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
|
2019-02-19 02:23:53 +03:00
|
|
|
|
#ifdef USE_QTSCRIPTENGINE
|
2017-10-26 12:24:06 +03:00
|
|
|
|
Q_DECLARE_METATYPE(LimeReport::ComboBoxPrototype*)
|
|
|
|
|
Q_DECLARE_METATYPE(QComboBox*)
|
2017-09-01 02:02:51 +03:00
|
|
|
|
#endif
|
|
|
|
|
|
2016-02-17 10:11:00 +03:00
|
|
|
|
#endif // LRSCRIPTENGINEMANAGER_H
|