forked from qt-creator/qt-creator
qmlpuppet: enable the use of multilanguage database
Change-Id: I2277348ac1e6b5025e75c640da83da30294c9d10 Reviewed-by: Tim Jenssen <tim.jenssen@qt.io>
This commit is contained in:
@@ -69,6 +69,7 @@
|
|||||||
#include <changeselectioncommand.h>
|
#include <changeselectioncommand.h>
|
||||||
#include <inputeventcommand.h>
|
#include <inputeventcommand.h>
|
||||||
#include <view3dactioncommand.h>
|
#include <view3dactioncommand.h>
|
||||||
|
#include <changelanguagecommand.h>
|
||||||
|
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
#include <QQmlEngine>
|
#include <QQmlEngine>
|
||||||
@@ -1397,7 +1398,22 @@ void NodeInstanceServer::view3DAction(const View3DActionCommand &command)
|
|||||||
Q_UNUSED(command)
|
Q_UNUSED(command)
|
||||||
}
|
}
|
||||||
|
|
||||||
void NodeInstanceServer::changeLanguage(const ChangeLanguageCommand &) {}
|
void NodeInstanceServer::changeLanguage(const ChangeLanguageCommand &command)
|
||||||
|
{
|
||||||
|
static QPointer<MultiLanguage::Translator> multilanguageTranslator;
|
||||||
|
if (!MultiLanguage::databaseFilePath().isEmpty()) {
|
||||||
|
if (!multilanguageLink) {
|
||||||
|
multilanguageLink = std::make_unique<MultiLanguage::Link>();
|
||||||
|
multilanguageTranslator = multilanguageLink->translator().release();
|
||||||
|
QCoreApplication::installTranslator(multilanguageTranslator);
|
||||||
|
}
|
||||||
|
if (multilanguageTranslator)
|
||||||
|
multilanguageTranslator->setLanguage(command.language);
|
||||||
|
}
|
||||||
|
QEvent ev(QEvent::LanguageChange);
|
||||||
|
QCoreApplication::sendEvent(QCoreApplication::instance(), &ev);
|
||||||
|
engine()->retranslate();
|
||||||
|
}
|
||||||
|
|
||||||
void NodeInstanceServer::changePreviewImageSize(const ChangePreviewImageSizeCommand &command) {}
|
void NodeInstanceServer::changePreviewImageSize(const ChangePreviewImageSizeCommand &) {}
|
||||||
} // namespace QmlDesigner
|
} // namespace QmlDesigner
|
||||||
|
@@ -31,6 +31,13 @@
|
|||||||
#include <QStringList>
|
#include <QStringList>
|
||||||
#include <QPointer>
|
#include <QPointer>
|
||||||
|
|
||||||
|
#ifdef MULTILANGUAGE_TRANSLATIONPROVIDER
|
||||||
|
#include <multilanguagelink.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include <QTranslator>
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
#include <nodeinstanceserverinterface.h>
|
#include <nodeinstanceserverinterface.h>
|
||||||
#include "servernodeinstance.h"
|
#include "servernodeinstance.h"
|
||||||
#include "debugoutputcommand.h"
|
#include "debugoutputcommand.h"
|
||||||
@@ -47,6 +54,37 @@ QList<T>toList(const QSet<T> &set)
|
|||||||
}
|
}
|
||||||
} //QtHelpers
|
} //QtHelpers
|
||||||
|
|
||||||
|
#ifndef MULTILANGUAGE_TRANSLATIONPROVIDER
|
||||||
|
namespace MultiLanguage {
|
||||||
|
static QByteArray databaseFilePath()
|
||||||
|
{
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
|
class Translator : public QTranslator
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
void setLanguage(const QString&) {}
|
||||||
|
};
|
||||||
|
|
||||||
|
class Link
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
Link()
|
||||||
|
{
|
||||||
|
if (qEnvironmentVariableIsSet("QT_MULTILANGUAGE_DATABASE"))
|
||||||
|
qWarning() << "QT_MULTILANGUAGE_DATABASE is set but QQmlDebugTranslationService is without MULTILANGUAGE_TRANSLATIONPROVIDER support compiled.";
|
||||||
|
}
|
||||||
|
std::unique_ptr<MultiLanguage::Translator> translator() {
|
||||||
|
//should never be called
|
||||||
|
Q_ASSERT(false);
|
||||||
|
return std::make_unique<MultiLanguage::Translator>();
|
||||||
|
}
|
||||||
|
const bool isActivated = false;
|
||||||
|
};
|
||||||
|
} //namespace MultiLanguage
|
||||||
|
#endif
|
||||||
|
|
||||||
QT_BEGIN_NAMESPACE
|
QT_BEGIN_NAMESPACE
|
||||||
class QFileSystemWatcher;
|
class QFileSystemWatcher;
|
||||||
class QQmlView;
|
class QQmlView;
|
||||||
@@ -250,6 +288,7 @@ private:
|
|||||||
QPointer<QObject> m_dummyContextObject;
|
QPointer<QObject> m_dummyContextObject;
|
||||||
QPointer<QQmlComponent> m_importComponent;
|
QPointer<QQmlComponent> m_importComponent;
|
||||||
QPointer<QObject> m_importComponentObject;
|
QPointer<QObject> m_importComponentObject;
|
||||||
|
std::unique_ptr<MultiLanguage::Link> multilanguageLink;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -5,6 +5,13 @@ CONFIG += c++11
|
|||||||
|
|
||||||
DEFINES -= QT_CREATOR
|
DEFINES -= QT_CREATOR
|
||||||
|
|
||||||
|
# This .pri file contains classes to enable a special multilanguage translator debug service
|
||||||
|
MULTILANGUAGE_SUPPORT_PRI=$$(MULTILANGUAGE_SUPPORT_PRI)
|
||||||
|
!isEmpty(MULTILANGUAGE_SUPPORT_PRI) {
|
||||||
|
include($$(MULTILANGUAGE_SUPPORT_PRI))
|
||||||
|
DEFINES += MULTILANGUAGE_TRANSLATIONPROVIDER
|
||||||
|
}
|
||||||
|
|
||||||
include (editor3d/editor3d.pri)
|
include (editor3d/editor3d.pri)
|
||||||
include (../instances/instances.pri)
|
include (../instances/instances.pri)
|
||||||
include (instances/instances.pri)
|
include (instances/instances.pri)
|
||||||
|
@@ -162,6 +162,18 @@ QString PuppetCreator::getStyleConfigFileName() const
|
|||||||
return QString();
|
return QString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QString PuppetCreator::getMultilanguageDatabaseFilePath() const
|
||||||
|
{
|
||||||
|
#ifndef QMLDESIGNER_TEST
|
||||||
|
if (m_target) {
|
||||||
|
auto filePath = m_target->project()->projectDirectory().pathAppended("/multilanguage-experimental-v1.db");
|
||||||
|
if (filePath.exists())
|
||||||
|
return filePath.toString();
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
PuppetCreator::PuppetCreator(ProjectExplorer::Target *target, const Model *model)
|
PuppetCreator::PuppetCreator(ProjectExplorer::Target *target, const Model *model)
|
||||||
|
|
||||||
: m_target(target)
|
: m_target(target)
|
||||||
@@ -482,6 +494,11 @@ QProcessEnvironment PuppetCreator::processEnvironment() const
|
|||||||
environment.set("QMLDESIGNER_RC_PATHS", m_qrcMapping);
|
environment.set("QMLDESIGNER_RC_PATHS", m_qrcMapping);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const QString multilanguageDatabaseFilePath = getMultilanguageDatabaseFilePath();
|
||||||
|
|
||||||
|
if (!multilanguageDatabaseFilePath.isEmpty())
|
||||||
|
environment.set("QT_MULTILANGUAGE_DATABASE", multilanguageDatabaseFilePath);
|
||||||
|
|
||||||
#ifndef QMLDESIGNER_TEST
|
#ifndef QMLDESIGNER_TEST
|
||||||
auto view = QmlDesignerPlugin::instance()->viewManager().nodeInstanceView();
|
auto view = QmlDesignerPlugin::instance()->viewManager().nodeInstanceView();
|
||||||
view->emitCustomNotification("PuppetStatus", {}, {QVariant(m_qrcMapping)});
|
view->emitCustomNotification("PuppetStatus", {}, {QVariant(m_qrcMapping)});
|
||||||
|
@@ -102,6 +102,7 @@ protected:
|
|||||||
|
|
||||||
bool useOnlyFallbackPuppet() const;
|
bool useOnlyFallbackPuppet() const;
|
||||||
QString getStyleConfigFileName() const;
|
QString getStyleConfigFileName() const;
|
||||||
|
QString getMultilanguageDatabaseFilePath() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
mutable QString m_compileLog;
|
mutable QString m_compileLog;
|
||||||
|
Reference in New Issue
Block a user