mirror of
https://github.com/fralx/LimeReport.git
synced 2024-12-24 16:44:39 +03:00
Changing the language from the script has been added
This commit is contained in:
parent
992c53e19a
commit
5c3c032ea3
127
demo_r1/demo_reports/change_lang_from_script.lrxml
Normal file
127
demo_r1/demo_reports/change_lang_from_script.lrxml
Normal file
@ -0,0 +1,127 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF8"?>
|
||||||
|
<Report>
|
||||||
|
<object ClassName="LimeReport::ReportEnginePrivate" Type="Object">
|
||||||
|
<objectName Type="QString"></objectName>
|
||||||
|
<pages Type="Collection">
|
||||||
|
<item ClassName="LimeReport::PageDesignIntf" Type="Object">
|
||||||
|
<objectName Type="QString">page1</objectName>
|
||||||
|
<sceneRect width="2200" y="-50" height="3070" Type="QRect" x="-50"/>
|
||||||
|
<bspTreeDepth Type="int" Value="5"/>
|
||||||
|
<font italic="0" Type="QFont" underline="0" pointSize="8" family="MS Shell Dlg 2" weight="50" stylename=""/>
|
||||||
|
<sortCacheEnabled Type="bool" Value="0"/>
|
||||||
|
<stickyFocus Type="bool" Value="0"/>
|
||||||
|
<minimumRenderSize Type="qreal" Value="0"/>
|
||||||
|
<pageItem ClassName="PageItem" Type="Object">
|
||||||
|
<objectName Type="QString">Reportpage1</objectName>
|
||||||
|
<geometry width="2100" y="0" height="2970" Type="QRect" x="0"/>
|
||||||
|
<children Type="Collection">
|
||||||
|
<item ClassName="TextItem" Type="Object">
|
||||||
|
<objectName Type="QString">TextItem1</objectName>
|
||||||
|
<geometry width="200" y="124" height="50" Type="QRect" x="138"/>
|
||||||
|
<children Type="Collection"/>
|
||||||
|
<zOrder Type="qreal" Value="0"/>
|
||||||
|
<borders Type="enumAndFlags" Value="0"/>
|
||||||
|
<parentName Type="QString">Reportpage1</parentName>
|
||||||
|
<borderLineSize Type="int" Value="1"/>
|
||||||
|
<isVisible Type="bool" Value="1"/>
|
||||||
|
<borderColor Type="QColor" Value="#000000"/>
|
||||||
|
<itemLocation Type="enumAndFlags" Value="1"/>
|
||||||
|
<stretchToMaxHeight Type="bool" Value="0"/>
|
||||||
|
<itemAlign Type="enumAndFlags" Value="4"/>
|
||||||
|
<content Type="QString">Test</content>
|
||||||
|
<margin Type="int" Value="4"/>
|
||||||
|
<alignment Type="enumAndFlags" Value="33"/>
|
||||||
|
<autoWidth Type="enumAndFlags" Value="0"/>
|
||||||
|
<autoHeight Type="bool" Value="0"/>
|
||||||
|
<font italic="0" Type="QFont" underline="0" pointSize="10" family="Arial" weight="50" stylename=""/>
|
||||||
|
<backgroundOpacity Type="int" Value="100"/>
|
||||||
|
<backgroundMode Type="enumAndFlags" Value="1"/>
|
||||||
|
<backgroundColor Type="QColor" Value="#ffffff"/>
|
||||||
|
<fontColor Type="QColor" Value="#000000"/>
|
||||||
|
<angle Type="enumAndFlags" Value="0"/>
|
||||||
|
<foregroundOpacity Type="int" Value="100"/>
|
||||||
|
<underlines Type="bool" Value="0"/>
|
||||||
|
<adaptFontToSize Type="bool" Value="0"/>
|
||||||
|
<trimValue Type="bool" Value="1"/>
|
||||||
|
<lineSpacing Type="int" Value="1"/>
|
||||||
|
<underlineLineSize Type="int" Value="1"/>
|
||||||
|
<allowHTML Type="bool" Value="0"/>
|
||||||
|
<allowHTMLInFields Type="bool" Value="0"/>
|
||||||
|
<format Type="QString"></format>
|
||||||
|
<valueType Type="enumAndFlags" Value="0"/>
|
||||||
|
<followTo Type="QString"></followTo>
|
||||||
|
<backgroundBrushStyle Type="enumAndFlags" Value="1"/>
|
||||||
|
<textIndent Type="qreal" Value="0"/>
|
||||||
|
<textLayoutDirection Type="enumAndFlags" Value="2"/>
|
||||||
|
<fillInSecondPass Type="bool" Value="0"/>
|
||||||
|
</item>
|
||||||
|
</children>
|
||||||
|
<zOrder Type="qreal" Value="0"/>
|
||||||
|
<borders Type="enumAndFlags" Value="0"/>
|
||||||
|
<parentName Type="QString"></parentName>
|
||||||
|
<borderLineSize Type="int" Value="1"/>
|
||||||
|
<isVisible Type="bool" Value="1"/>
|
||||||
|
<borderColor Type="QColor" Value="#000000"/>
|
||||||
|
<topMargin Type="int" Value="5"/>
|
||||||
|
<bottomMargin Type="int" Value="5"/>
|
||||||
|
<rightMargin Type="int" Value="5"/>
|
||||||
|
<leftMargin Type="int" Value="5"/>
|
||||||
|
<pageOrientation Type="enumAndFlags" Value="0"/>
|
||||||
|
<pageSize Type="enumAndFlags" Value="0"/>
|
||||||
|
<gridStep Type="int" Value="2"/>
|
||||||
|
<fullPage Type="bool" Value="0"/>
|
||||||
|
<oldPrintMode Type="bool" Value="0"/>
|
||||||
|
<resetPageNumber Type="bool" Value="0"/>
|
||||||
|
<isExtendedInDesignMode Type="bool" Value="0"/>
|
||||||
|
<extendedHeight Type="int" Value="1000"/>
|
||||||
|
<pageIsTOC Type="bool" Value="0"/>
|
||||||
|
</pageItem>
|
||||||
|
</item>
|
||||||
|
</pages>
|
||||||
|
<datasourcesManager ClassName="LimeReport::DataSourceManager" Type="Object">
|
||||||
|
<objectName Type="QString">datasources</objectName>
|
||||||
|
<connections Type="Collection"/>
|
||||||
|
<queries Type="Collection"/>
|
||||||
|
<subqueries Type="Collection"/>
|
||||||
|
<subproxies Type="Collection"/>
|
||||||
|
<variables Type="Collection"/>
|
||||||
|
</datasourcesManager>
|
||||||
|
<scriptContext ClassName="LimeReport::ScriptEngineContext" Type="Object">
|
||||||
|
<objectName Type="QString"></objectName>
|
||||||
|
<dialogs Type="Collection">
|
||||||
|
<item ClassName="LimeReport::DialogDescriber" Type="Object">
|
||||||
|
<objectName Type="QString"></objectName>
|
||||||
|
<name Type="QString">Dialog</name>
|
||||||
|
<description Type="QByteArray" Value="PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iVVRGLTgiPz4KPHVpIHZlcnNpb249IjQuMCI+CiA8Y2xhc3M+RGlhbG9nPC9jbGFzcz4KIDx3aWRnZXQgY2xhc3M9IlFEaWFsb2ciIG5hbWU9IkRpYWxvZyI+CiAgPHByb3BlcnR5IG5hbWU9Imdlb21ldHJ5Ij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AgIDx5PjE1ODwveT4KICAgIDwvaGludD4KICAgPC9oaW50cz4KICA8L2Nvbm5lY3Rpb24+CiAgPGNvbm5lY3Rpb24+CiAgIDxzZW5kZXI+cHVzaEJ1dHRvbl8yPC9zZW5kZXI+CiAgIDxzaWduYWw+Y2xpY2tlZCgpPC9zaWduYWw+CiAgIDxyZWNlaXZlcj5EaWFsb2c8L3JlY2VpdmVyPgogICA8c2xvdD5yZWplY3QoKTwvc2xvdD4KICAgPGhpbnRzPgogICAgPGhpbnQgdHlwZT0ic291cmNlbGFiZWwiPgogICAgIDx4PjI2MTwveD4KICAgICA8eT4yMzU8L3k+CiAgICA8L2hpbnQ+CiAgICA8aGludCB0eXBlPSJkZXN0aW5hdGlvbmxhYmVsIj4KICAgICA8eD4yODE8L3g+CiAgICAgPHk+MTYxPC95PgogICAgPC9oaW50PgogICA8L2hpbnRzPgogIDwvY29ubmVjdGlvbj4KIDwvY29ubmVjdGlvbnM+CjwvdWk+Cg=="/>
|
||||||
|
</item>
|
||||||
|
</dialogs>
|
||||||
|
<initScript Type="QString">function OnAccept(){
|
||||||
|
engine.setReportTranslation(Dialog.comboBox.currentText);
|
||||||
|
}
|
||||||
|
Dialog.accepted.connect(OnAccept);
|
||||||
|
|
||||||
|
var comboBox = LimeReport.createWrapper(Dialog.comboBox);
|
||||||
|
comboBox.addItems(engine.aviableReportTranslations());
|
||||||
|
|
||||||
|
Dialog.exec() == 1;
|
||||||
|
</initScript>
|
||||||
|
</scriptContext>
|
||||||
|
<suppressFieldAndVarError Type="bool" Value="0"/>
|
||||||
|
<translation Type="Translation">
|
||||||
|
<Default Value="0">
|
||||||
|
<page1>
|
||||||
|
<TextItem1>
|
||||||
|
<content Checked="N" SourceValue="Test" Value="Test"/>
|
||||||
|
</TextItem1>
|
||||||
|
</page1>
|
||||||
|
</Default>
|
||||||
|
<Russian Value="96">
|
||||||
|
<page1>
|
||||||
|
<TextItem1>
|
||||||
|
<content Checked="Y" SourceValue="Test" Value="Проверка"/>
|
||||||
|
</TextItem1>
|
||||||
|
</page1>
|
||||||
|
</Russian>
|
||||||
|
</translation>
|
||||||
|
</object>
|
||||||
|
</Report>
|
@ -268,6 +268,7 @@ void ReportDesignWidget::createNewDialogTab(const QString& dialogName, const QBy
|
|||||||
int pageIndex = m_tabWidget->addTab(dialogDesigner,QIcon(),dialogName);
|
int pageIndex = m_tabWidget->addTab(dialogDesigner,QIcon(),dialogName);
|
||||||
m_tabWidget->setTabWhatsThis(pageIndex,"dialog");
|
m_tabWidget->setTabWhatsThis(pageIndex,"dialog");
|
||||||
m_tabWidget->setCurrentIndex(pageIndex);
|
m_tabWidget->setCurrentIndex(pageIndex);
|
||||||
|
m_dialogDesignerManager->setActiveEditor(dialogDesigner);
|
||||||
}
|
}
|
||||||
|
|
||||||
DialogDesigner*ReportDesignWidget::activeDialogPage()
|
DialogDesigner*ReportDesignWidget::activeDialogPage()
|
||||||
|
@ -304,6 +304,24 @@ void ReportEnginePrivate::printReport(ReportPages pages, QPrinter &printer)
|
|||||||
delete painter;
|
delete painter;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QStringList ReportEnginePrivate::aviableReportTranslations()
|
||||||
|
{
|
||||||
|
QStringList result;
|
||||||
|
foreach (QLocale::Language language, aviableLanguages()){
|
||||||
|
result << QLocale::languageToString(language);
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ReportEnginePrivate::setReportTranslation(const QString &languageName)
|
||||||
|
{
|
||||||
|
foreach(QLocale::Language language, aviableLanguages()){
|
||||||
|
if (QLocale::languageToString(language).compare(languageName) == 0){
|
||||||
|
setReportLanguage(language);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
bool ReportEnginePrivate::printReport(QPrinter* printer)
|
bool ReportEnginePrivate::printReport(QPrinter* printer)
|
||||||
{
|
{
|
||||||
if (!printer&&!m_printerSelected){
|
if (!printer&&!m_printerSelected){
|
||||||
@ -892,7 +910,7 @@ ReportPages ReportEnginePrivate::renderToPages()
|
|||||||
dataManager()->connectAllDatabases();
|
dataManager()->connectAllDatabases();
|
||||||
dataManager()->setDesignTime(false);
|
dataManager()->setDesignTime(false);
|
||||||
dataManager()->updateDatasourceModel();
|
dataManager()->updateDatasourceModel();
|
||||||
activateLanguage(m_reportLanguage);
|
|
||||||
connect(m_reportRender.data(),SIGNAL(pageRendered(int)),
|
connect(m_reportRender.data(),SIGNAL(pageRendered(int)),
|
||||||
this, SIGNAL(renderPageFinished(int)));
|
this, SIGNAL(renderPageFinished(int)));
|
||||||
|
|
||||||
@ -910,7 +928,11 @@ ReportPages ReportEnginePrivate::renderToPages()
|
|||||||
scriptContext()->baseDesignIntfToScript(page->pageItem()->objectName(), page->pageItem());
|
scriptContext()->baseDesignIntfToScript(page->pageItem()->objectName(), page->pageItem());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
scriptContext()->qobjectToScript("engine",this);
|
||||||
|
|
||||||
if (m_scriptEngineContext->runInitScript()){
|
if (m_scriptEngineContext->runInitScript()){
|
||||||
|
|
||||||
|
activateLanguage(m_reportLanguage);
|
||||||
emit renderStarted();
|
emit renderStarted();
|
||||||
|
|
||||||
foreach(PageDesignIntf* page , m_pages){
|
foreach(PageDesignIntf* page , m_pages){
|
||||||
|
@ -67,6 +67,8 @@ class ReportEnginePrivate : public QObject, public ICollectionContainer, public
|
|||||||
public:
|
public:
|
||||||
static void printReport(ItemsReaderIntf::Ptr reader, QPrinter &printer);
|
static void printReport(ItemsReaderIntf::Ptr reader, QPrinter &printer);
|
||||||
static void printReport(ReportPages pages, QPrinter &printer);
|
static void printReport(ReportPages pages, QPrinter &printer);
|
||||||
|
Q_INVOKABLE QStringList aviableReportTranslations();
|
||||||
|
Q_INVOKABLE void setReportTranslation(const QString& languageName);
|
||||||
public:
|
public:
|
||||||
explicit ReportEnginePrivate(QObject *parent = 0);
|
explicit ReportEnginePrivate(QObject *parent = 0);
|
||||||
virtual ~ReportEnginePrivate();
|
virtual ~ReportEnginePrivate();
|
||||||
|
@ -819,6 +819,10 @@ ScriptEngineManager::ScriptEngineManager()
|
|||||||
m_scriptEngine = new ScriptEngineType;
|
m_scriptEngine = new ScriptEngineType;
|
||||||
m_functionManager = new ScriptFunctionsManager(this);
|
m_functionManager = new ScriptFunctionsManager(this);
|
||||||
m_functionManager->setScriptEngineManager(this);
|
m_functionManager->setScriptEngineManager(this);
|
||||||
|
#ifndef USE_QJSENGINE
|
||||||
|
m_scriptEngine->setDefaultPrototype(qMetaTypeId<QComboBox*>(),
|
||||||
|
m_scriptEngine->newQObject(new ComboBoxPrototype()));
|
||||||
|
#endif
|
||||||
|
|
||||||
createLineFunction();
|
createLineFunction();
|
||||||
createNumberFomatFunction();
|
createNumberFomatFunction();
|
||||||
@ -1238,7 +1242,6 @@ void ScriptEngineContext::baseDesignIntfToScript(const QString& pageName, BaseDe
|
|||||||
ScriptEngineType* engine = ScriptEngineManager::instance().scriptEngine();
|
ScriptEngineType* engine = ScriptEngineManager::instance().scriptEngine();
|
||||||
|
|
||||||
#ifdef USE_QJSENGINE
|
#ifdef USE_QJSENGINE
|
||||||
//sItem = engine->newQObject(item);
|
|
||||||
ScriptValueType sItem = getCppOwnedJSValue(*engine, item);
|
ScriptValueType sItem = getCppOwnedJSValue(*engine, item);
|
||||||
engine->globalObject().setProperty(pageName+"_"+item->patternName(), sItem);
|
engine->globalObject().setProperty(pageName+"_"+item->patternName(), sItem);
|
||||||
#else
|
#else
|
||||||
@ -1247,7 +1250,7 @@ void ScriptEngineContext::baseDesignIntfToScript(const QString& pageName, BaseDe
|
|||||||
engine->newQObject(sItem, item);
|
engine->newQObject(sItem, item);
|
||||||
} else {
|
} else {
|
||||||
sItem = engine->newQObject(item);
|
sItem = engine->newQObject(item);
|
||||||
engine->globalObject().setProperty(item->patternName(),sItem);
|
engine->globalObject().setProperty(pageName+"_"+item->patternName(),sItem);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
foreach(BaseDesignIntf* child, item->childBaseItems()){
|
foreach(BaseDesignIntf* child, item->childBaseItems()){
|
||||||
@ -1256,6 +1259,23 @@ void ScriptEngineContext::baseDesignIntfToScript(const QString& pageName, BaseDe
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ScriptEngineContext::qobjectToScript(const QString& name, QObject *item)
|
||||||
|
{
|
||||||
|
ScriptEngineType* engine = ScriptEngineManager::instance().scriptEngine();
|
||||||
|
#ifdef USE_QJSENGINE
|
||||||
|
ScriptValueType sItem = getCppOwnedJSValue(*engine, item);
|
||||||
|
engine->globalObject().setProperty(name, sItem);
|
||||||
|
#else
|
||||||
|
ScriptValueType sItem = engine->globalObject().property(name);
|
||||||
|
if (sItem.isValid()){
|
||||||
|
engine->newQObject(sItem, item);
|
||||||
|
} else {
|
||||||
|
sItem = engine->newQObject(item);
|
||||||
|
engine->globalObject().setProperty(name,sItem);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
#ifdef HAVE_UI_LOADER
|
#ifdef HAVE_UI_LOADER
|
||||||
|
|
||||||
#ifdef USE_QJSENGINE
|
#ifdef USE_QJSENGINE
|
||||||
@ -1502,7 +1522,10 @@ void ScriptFunctionsManager::clearTableOfContens()
|
|||||||
scriptEngineManager()->clearTableOfContens();
|
scriptEngineManager()->clearTableOfContens();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#ifdef USE_QJSENGINE
|
#ifdef USE_QJSENGINE
|
||||||
|
|
||||||
QFont ScriptFunctionsManager::font(const QString &family, int pointSize, bool bold, bool italic, bool underLine)
|
QFont ScriptFunctionsManager::font(const QString &family, int pointSize, bool bold, bool italic, bool underLine)
|
||||||
{
|
{
|
||||||
QFont result (family, pointSize);
|
QFont result (family, pointSize);
|
||||||
@ -1511,6 +1534,45 @@ QFont ScriptFunctionsManager::font(const QString &family, int pointSize, bool bo
|
|||||||
result.setUnderline(underLine);
|
result.setUnderline(underLine);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ScriptFunctionsManager::addItemsToComboBox(QJSValue object, const QStringList &values)
|
||||||
|
{
|
||||||
|
QComboBox* comboBox = dynamic_cast<QComboBox*>(object.toQObject());
|
||||||
|
if (comboBox){
|
||||||
|
comboBox->addItems(values);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void ScriptFunctionsManager::addItemToComboBox(QJSValue object, const QString &value)
|
||||||
|
{
|
||||||
|
QComboBox* comboBox = dynamic_cast<QComboBox*>(object.toQObject());
|
||||||
|
if (comboBox){
|
||||||
|
comboBox->addItem(value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
QJSValue ScriptFunctionsManager::createComboBoxWrapper(QJSValue comboBox)
|
||||||
|
{
|
||||||
|
QComboBox* item = dynamic_cast<QComboBox*>(comboBox.toQObject());
|
||||||
|
if (item){
|
||||||
|
ComboBoxWrapper* wrapper = new ComboBoxWrapper(item);
|
||||||
|
return m_scriptEngineManager->scriptEngine()->newQObject(wrapper);
|
||||||
|
}
|
||||||
|
return QJSValue();
|
||||||
|
}
|
||||||
|
|
||||||
|
QJSValue ScriptFunctionsManager::createWrapper(QJSValue item)
|
||||||
|
{
|
||||||
|
QObject* object = item.toQObject();
|
||||||
|
if (object){
|
||||||
|
IWrapperCreator* wrapper = m_wrappersFactory.value(object->metaObject()->className());
|
||||||
|
if (wrapper){
|
||||||
|
return m_scriptEngineManager->scriptEngine()->newQObject(wrapper->createWrapper(item.toQObject()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return QJSValue();
|
||||||
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
QFont ScriptFunctionsManager::font(QVariantMap params){
|
QFont ScriptFunctionsManager::font(QVariantMap params){
|
||||||
if (!params.contains("family")){
|
if (!params.contains("family")){
|
||||||
@ -1606,5 +1668,36 @@ void LimeReport::TableOfContens::clear(){
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef USE_QJSENGINE
|
||||||
|
|
||||||
|
QObject* ComboBoxWrapperCreator::createWrapper(QObject *item)
|
||||||
|
{
|
||||||
|
QComboBox* comboBox = dynamic_cast<QComboBox*>(item);
|
||||||
|
if (comboBox){
|
||||||
|
return new ComboBoxWrapper(comboBox);
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef USE_QJSENGINE
|
||||||
|
void ComboBoxPrototype::addItem(const QString &text)
|
||||||
|
{
|
||||||
|
QComboBox* comboBox = qscriptvalue_cast<QComboBox*>(thisObject());
|
||||||
|
if (comboBox){
|
||||||
|
comboBox->addItem(text);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void ComboBoxPrototype::addItems(const QStringList &texts)
|
||||||
|
{
|
||||||
|
QComboBox* comboBox = qscriptvalue_cast<QComboBox*>(thisObject());
|
||||||
|
if (comboBox){
|
||||||
|
comboBox->addItems(texts);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
} //namespace LimeReport
|
} //namespace LimeReport
|
||||||
|
|
||||||
|
@ -38,7 +38,7 @@
|
|||||||
#include <QtGlobal>
|
#include <QtGlobal>
|
||||||
#include <QScriptable>
|
#include <QScriptable>
|
||||||
#include <QFont>
|
#include <QFont>
|
||||||
|
#include <QComboBox>
|
||||||
|
|
||||||
//#include <QJSEngine>
|
//#include <QJSEngine>
|
||||||
|
|
||||||
@ -183,6 +183,7 @@ public:
|
|||||||
void initDialogs();
|
void initDialogs();
|
||||||
#endif
|
#endif
|
||||||
void baseDesignIntfToScript(const QString& pageName, BaseDesignIntf *item);
|
void baseDesignIntfToScript(const QString& pageName, BaseDesignIntf *item);
|
||||||
|
void qobjectToScript(const QString &name, QObject* item);
|
||||||
void clear();
|
void clear();
|
||||||
QString initScript() const;
|
QString initScript() const;
|
||||||
void setInitScript(const QString& initScript);
|
void setInitScript(const QString& initScript);
|
||||||
@ -262,10 +263,48 @@ private:
|
|||||||
QString m_scriptWrapper;
|
QString m_scriptWrapper;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
#ifndef USE_QJSENGINE
|
||||||
|
class ComboBoxPrototype : public QObject, public QScriptable{
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
ComboBoxPrototype(QObject* parent = 0):QObject(parent){}
|
||||||
|
public slots:
|
||||||
|
void addItem( const QString& text);
|
||||||
|
void addItems(const QStringList& texts);
|
||||||
|
};
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef USE_QJSENGINE
|
||||||
|
|
||||||
|
class IWrapperCreator{
|
||||||
|
public:
|
||||||
|
virtual QObject* createWrapper(QObject* item) = 0;
|
||||||
|
virtual ~IWrapperCreator(){}
|
||||||
|
};
|
||||||
|
|
||||||
|
class ComboBoxWrapper : public QObject{
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
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);}
|
||||||
|
private:
|
||||||
|
QComboBox* m_comboBox;
|
||||||
|
};
|
||||||
|
|
||||||
|
class ComboBoxWrapperCreator: public IWrapperCreator{
|
||||||
|
private:
|
||||||
|
QObject* createWrapper(QObject* item);
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
class ScriptFunctionsManager : public QObject{
|
class ScriptFunctionsManager : public QObject{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
explicit ScriptFunctionsManager(QObject* parent = 0):QObject(parent){}
|
explicit ScriptFunctionsManager(QObject* parent = 0):QObject(parent){ m_wrappersFactory.insert("QComboBox",new ComboBoxWrapperCreator());}
|
||||||
|
~ScriptFunctionsManager(){ foreach(IWrapperCreator* wrapper, m_wrappersFactory.values()){ delete wrapper;} m_wrappersFactory.clear();}
|
||||||
Q_INVOKABLE QVariant calcGroupFunction(const QString& name, const QString& expressionID, const QString& bandName);
|
Q_INVOKABLE QVariant calcGroupFunction(const QString& name, const QString& expressionID, const QString& bandName);
|
||||||
Q_INVOKABLE QVariant line(const QString& bandName);
|
Q_INVOKABLE QVariant line(const QString& bandName);
|
||||||
Q_INVOKABLE QVariant numberFormat(QVariant value, const char &format, int precision, const QString &locale);
|
Q_INVOKABLE QVariant numberFormat(QVariant value, const char &format, int precision, const QString &locale);
|
||||||
@ -283,8 +322,13 @@ public:
|
|||||||
Q_INVOKABLE QVariant color(const QString& color){ return QColor(color);}
|
Q_INVOKABLE QVariant color(const QString& color){ return QColor(color);}
|
||||||
Q_INVOKABLE void addTableOfContensItem(const QString& uniqKey, const QString& content, int indent = 0);
|
Q_INVOKABLE void addTableOfContensItem(const QString& uniqKey, const QString& content, int indent = 0);
|
||||||
Q_INVOKABLE void clearTableOfContens();
|
Q_INVOKABLE void clearTableOfContens();
|
||||||
|
|
||||||
#ifdef USE_QJSENGINE
|
#ifdef USE_QJSENGINE
|
||||||
Q_INVOKABLE QFont font(const QString& family, int pointSize = -1, bool bold = false, bool italic = false, bool underLine = false);
|
Q_INVOKABLE QFont font(const QString& family, int pointSize = -1, bool bold = false, bool italic = false, bool underLine = false);
|
||||||
|
Q_INVOKABLE void addItemsToComboBox(QJSValue object, const QStringList& values);
|
||||||
|
Q_INVOKABLE void addItemToComboBox(QJSValue object, const QString& value);
|
||||||
|
Q_INVOKABLE QJSValue createComboBoxWrapper(QJSValue comboBox);
|
||||||
|
Q_INVOKABLE QJSValue createWrapper(QJSValue item);
|
||||||
#endif
|
#endif
|
||||||
Q_INVOKABLE QFont font(QVariantMap params);
|
Q_INVOKABLE QFont font(QVariantMap params);
|
||||||
ScriptEngineManager *scriptEngineManager() const;
|
ScriptEngineManager *scriptEngineManager() const;
|
||||||
@ -292,6 +336,7 @@ public:
|
|||||||
static QColor createQColor(const QString& color){ return QColor(color);}
|
static QColor createQColor(const QString& color){ return QColor(color);}
|
||||||
private:
|
private:
|
||||||
ScriptEngineManager* m_scriptEngineManager;
|
ScriptEngineManager* m_scriptEngineManager;
|
||||||
|
QMap<QString, IWrapperCreator*> m_wrappersFactory;
|
||||||
};
|
};
|
||||||
|
|
||||||
class ScriptEngineManager : public QObject, public Singleton<ScriptEngineManager>, public IScriptEngineManager
|
class ScriptEngineManager : public QObject, public Singleton<ScriptEngineManager>, public IScriptEngineManager
|
||||||
@ -435,4 +480,9 @@ public:
|
|||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifndef USE_QJSENGINE
|
||||||
|
Q_DECLARE_METATYPE(LimeReport::ComboBoxPrototype*);
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif // LRSCRIPTENGINEMANAGER_H
|
#endif // LRSCRIPTENGINEMANAGER_H
|
||||||
|
Loading…
Reference in New Issue
Block a user