mirror of
https://github.com/python-LimeReport/LimeReport.git
synced 2025-09-23 08:39:07 +03:00
Changing the language from the script has been added
This commit is contained in:
@@ -268,6 +268,7 @@ void ReportDesignWidget::createNewDialogTab(const QString& dialogName, const QBy
|
||||
int pageIndex = m_tabWidget->addTab(dialogDesigner,QIcon(),dialogName);
|
||||
m_tabWidget->setTabWhatsThis(pageIndex,"dialog");
|
||||
m_tabWidget->setCurrentIndex(pageIndex);
|
||||
m_dialogDesignerManager->setActiveEditor(dialogDesigner);
|
||||
}
|
||||
|
||||
DialogDesigner*ReportDesignWidget::activeDialogPage()
|
||||
|
@@ -304,6 +304,24 @@ void ReportEnginePrivate::printReport(ReportPages pages, QPrinter &printer)
|
||||
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)
|
||||
{
|
||||
if (!printer&&!m_printerSelected){
|
||||
@@ -892,7 +910,7 @@ ReportPages ReportEnginePrivate::renderToPages()
|
||||
dataManager()->connectAllDatabases();
|
||||
dataManager()->setDesignTime(false);
|
||||
dataManager()->updateDatasourceModel();
|
||||
activateLanguage(m_reportLanguage);
|
||||
|
||||
connect(m_reportRender.data(),SIGNAL(pageRendered(int)),
|
||||
this, SIGNAL(renderPageFinished(int)));
|
||||
|
||||
@@ -910,7 +928,11 @@ ReportPages ReportEnginePrivate::renderToPages()
|
||||
scriptContext()->baseDesignIntfToScript(page->pageItem()->objectName(), page->pageItem());
|
||||
}
|
||||
|
||||
scriptContext()->qobjectToScript("engine",this);
|
||||
|
||||
if (m_scriptEngineContext->runInitScript()){
|
||||
|
||||
activateLanguage(m_reportLanguage);
|
||||
emit renderStarted();
|
||||
|
||||
foreach(PageDesignIntf* page , m_pages){
|
||||
|
@@ -67,6 +67,8 @@ class ReportEnginePrivate : public QObject, public ICollectionContainer, public
|
||||
public:
|
||||
static void printReport(ItemsReaderIntf::Ptr reader, QPrinter &printer);
|
||||
static void printReport(ReportPages pages, QPrinter &printer);
|
||||
Q_INVOKABLE QStringList aviableReportTranslations();
|
||||
Q_INVOKABLE void setReportTranslation(const QString& languageName);
|
||||
public:
|
||||
explicit ReportEnginePrivate(QObject *parent = 0);
|
||||
virtual ~ReportEnginePrivate();
|
||||
|
@@ -819,6 +819,10 @@ ScriptEngineManager::ScriptEngineManager()
|
||||
m_scriptEngine = new ScriptEngineType;
|
||||
m_functionManager = new ScriptFunctionsManager(this);
|
||||
m_functionManager->setScriptEngineManager(this);
|
||||
#ifndef USE_QJSENGINE
|
||||
m_scriptEngine->setDefaultPrototype(qMetaTypeId<QComboBox*>(),
|
||||
m_scriptEngine->newQObject(new ComboBoxPrototype()));
|
||||
#endif
|
||||
|
||||
createLineFunction();
|
||||
createNumberFomatFunction();
|
||||
@@ -1238,7 +1242,6 @@ void ScriptEngineContext::baseDesignIntfToScript(const QString& pageName, BaseDe
|
||||
ScriptEngineType* engine = ScriptEngineManager::instance().scriptEngine();
|
||||
|
||||
#ifdef USE_QJSENGINE
|
||||
//sItem = engine->newQObject(item);
|
||||
ScriptValueType sItem = getCppOwnedJSValue(*engine, item);
|
||||
engine->globalObject().setProperty(pageName+"_"+item->patternName(), sItem);
|
||||
#else
|
||||
@@ -1247,7 +1250,7 @@ void ScriptEngineContext::baseDesignIntfToScript(const QString& pageName, BaseDe
|
||||
engine->newQObject(sItem, item);
|
||||
} else {
|
||||
sItem = engine->newQObject(item);
|
||||
engine->globalObject().setProperty(item->patternName(),sItem);
|
||||
engine->globalObject().setProperty(pageName+"_"+item->patternName(),sItem);
|
||||
}
|
||||
#endif
|
||||
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 USE_QJSENGINE
|
||||
@@ -1502,7 +1522,10 @@ void ScriptFunctionsManager::clearTableOfContens()
|
||||
scriptEngineManager()->clearTableOfContens();
|
||||
}
|
||||
|
||||
|
||||
|
||||
#ifdef USE_QJSENGINE
|
||||
|
||||
QFont ScriptFunctionsManager::font(const QString &family, int pointSize, bool bold, bool italic, bool underLine)
|
||||
{
|
||||
QFont result (family, pointSize);
|
||||
@@ -1511,6 +1534,45 @@ QFont ScriptFunctionsManager::font(const QString &family, int pointSize, bool bo
|
||||
result.setUnderline(underLine);
|
||||
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
|
||||
QFont ScriptFunctionsManager::font(QVariantMap params){
|
||||
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
|
||||
|
||||
|
@@ -38,7 +38,7 @@
|
||||
#include <QtGlobal>
|
||||
#include <QScriptable>
|
||||
#include <QFont>
|
||||
|
||||
#include <QComboBox>
|
||||
|
||||
//#include <QJSEngine>
|
||||
|
||||
@@ -183,6 +183,7 @@ public:
|
||||
void initDialogs();
|
||||
#endif
|
||||
void baseDesignIntfToScript(const QString& pageName, BaseDesignIntf *item);
|
||||
void qobjectToScript(const QString &name, QObject* item);
|
||||
void clear();
|
||||
QString initScript() const;
|
||||
void setInitScript(const QString& initScript);
|
||||
@@ -262,10 +263,48 @@ private:
|
||||
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{
|
||||
Q_OBJECT
|
||||
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 line(const QString& bandName);
|
||||
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 void addTableOfContensItem(const QString& uniqKey, const QString& content, int indent = 0);
|
||||
Q_INVOKABLE void clearTableOfContens();
|
||||
|
||||
#ifdef USE_QJSENGINE
|
||||
Q_INVOKABLE QFont font(const QString& family, int pointSize = -1, bool bold = false, bool italic = false, bool underLine = false);
|
||||
Q_INVOKABLE void addItemsToComboBox(QJSValue object, const QStringList& values);
|
||||
Q_INVOKABLE void addItemToComboBox(QJSValue object, const QString& value);
|
||||
Q_INVOKABLE QJSValue createComboBoxWrapper(QJSValue comboBox);
|
||||
Q_INVOKABLE QJSValue createWrapper(QJSValue item);
|
||||
#endif
|
||||
Q_INVOKABLE QFont font(QVariantMap params);
|
||||
ScriptEngineManager *scriptEngineManager() const;
|
||||
@@ -292,6 +336,7 @@ public:
|
||||
static QColor createQColor(const QString& color){ return QColor(color);}
|
||||
private:
|
||||
ScriptEngineManager* m_scriptEngineManager;
|
||||
QMap<QString, IWrapperCreator*> m_wrappersFactory;
|
||||
};
|
||||
|
||||
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
|
||||
|
Reference in New Issue
Block a user