QmlDesigner: Add ChangeLanguage command

Change-Id: If79de7d04717ad81af05411e61c262b9ff70129b
Reviewed-by: Thomas Hartmann <thomas.hartmann@qt.io>
Reviewed-by: Tim Jenssen <tim.jenssen@qt.io>
This commit is contained in:
Marco Bubke
2020-04-28 11:21:03 +02:00
parent c10914204a
commit dacea667ed
11 changed files with 189 additions and 65 deletions
@@ -0,0 +1,45 @@
/****************************************************************************
**
** Copyright (C) 2020 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of Qt Creator.
**
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3 as published by the Free Software
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
** included in the packaging of this file. Please review the following
** information to ensure the GNU General Public License requirements will
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
**
****************************************************************************/
#include "changelanguagecommand.h"
namespace QmlDesigner {
QDataStream &operator<<(QDataStream &out, const ChangeLanguageCommand &command)
{
return out << command.language;
}
QDataStream &operator>>(QDataStream &in, ChangeLanguageCommand &command)
{
return in >> command.language;
}
QDebug operator<<(QDebug debug, const ChangeLanguageCommand &command)
{
return debug.nospace() << "ChangeLanguageCommand(" << command.language << ")";
}
} // namespace QmlDesigner
@@ -0,0 +1,53 @@
/****************************************************************************
**
** Copyright (C) 2020 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of Qt Creator.
**
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3 as published by the Free Software
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
** included in the packaging of this file. Please review the following
** information to ensure the GNU General Public License requirements will
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
**
****************************************************************************/
#pragma once
#include <QString>
namespace QmlDesigner {
class ChangeLanguageCommand
{
public:
friend QDataStream &operator>>(QDataStream &in, ChangeLanguageCommand &command);
public:
ChangeLanguageCommand() = default;
ChangeLanguageCommand(const QString &language)
: language(language)
{}
friend QDataStream &operator<<(QDataStream &out, const ChangeLanguageCommand &command);
friend QDataStream &operator>>(QDataStream &in, ChangeLanguageCommand &command);
friend QDebug operator<<(QDebug debug, const ChangeLanguageCommand &command);
public:
QString language;
};
} // namespace QmlDesigner
Q_DECLARE_METATYPE(QmlDesigner::ChangeLanguageCommand)
@@ -1,6 +1,7 @@
INCLUDEPATH += $$PWD/
HEADERS += $$PWD/synchronizecommand.h
HEADERS += $$PWD/changelanguagecommand.h
HEADERS += $$PWD//debugoutputcommand.h
HEADERS += $$PWD/endpuppetcommand.h
HEADERS += $$PWD/tokencommand.h
@@ -33,6 +34,7 @@ HEADERS += $$PWD/inputeventcommand.h
HEADERS += $$PWD/view3dactioncommand.h
SOURCES += $$PWD/synchronizecommand.cpp
SOURCES += $$PWD/changelanguagecommand.cpp
SOURCES += $$PWD/debugoutputcommand.cpp
SOURCES += $$PWD/endpuppetcommand.cpp
SOURCES += $$PWD/tokencommand.cpp
@@ -35,28 +35,29 @@
#include "nodeinstanceserverinterface.h"
#include "propertyabstractcontainer.h"
#include "propertyvaluecontainer.h"
#include "propertybindingcontainer.h"
#include "instancecontainer.h"
#include "changeauxiliarycommand.h"
#include "changebindingscommand.h"
#include "changefileurlcommand.h"
#include "changeidscommand.h"
#include "changelanguagecommand.h"
#include "changestatecommand.h"
#include "changevaluescommand.h"
#include "clearscenecommand.h"
#include "completecomponentcommand.h"
#include "createinstancescommand.h"
#include "createscenecommand.h"
#include "update3dviewstatecommand.h"
#include "changevaluescommand.h"
#include "changebindingscommand.h"
#include "changeauxiliarycommand.h"
#include "changefileurlcommand.h"
#include "removeinstancescommand.h"
#include "clearscenecommand.h"
#include "removepropertiescommand.h"
#include "reparentinstancescommand.h"
#include "changeidscommand.h"
#include "changestatecommand.h"
#include "completecomponentcommand.h"
#include "synchronizecommand.h"
#include "removesharedmemorycommand.h"
#include "tokencommand.h"
#include "inputeventcommand.h"
#include "instancecontainer.h"
#include "propertyabstractcontainer.h"
#include "propertybindingcontainer.h"
#include "propertyvaluecontainer.h"
#include "removeinstancescommand.h"
#include "removepropertiescommand.h"
#include "removesharedmemorycommand.h"
#include "reparentinstancescommand.h"
#include "synchronizecommand.h"
#include "tokencommand.h"
#include "update3dviewstatecommand.h"
#include "view3dactioncommand.h"
#include "informationchangedcommand.h"
@@ -324,6 +325,11 @@ void NodeInstanceClientProxy::view3DAction(const View3DActionCommand &command)
nodeInstanceServer()->view3DAction(command);
}
void NodeInstanceClientProxy::changeLanguage(const ChangeLanguageCommand &command)
{
nodeInstanceServer()->changeLanguage(command);
}
void NodeInstanceClientProxy::readDataStream()
{
QList<QVariant> commandList;
@@ -490,6 +496,7 @@ void NodeInstanceClientProxy::dispatchCommand(const QVariant &command)
static const int changeSelectionCommandType = QMetaType::type("ChangeSelectionCommand");
static const int inputEventCommandType = QMetaType::type("InputEventCommand");
static const int view3DActionCommandType = QMetaType::type("View3DActionCommand");
static const int changeLanguageCommand = QMetaType::type("ChangeLanguageCommand");
const int commandType = command.userType();
@@ -539,6 +546,8 @@ void NodeInstanceClientProxy::dispatchCommand(const QVariant &command)
} else if (commandType == changeSelectionCommandType) {
ChangeSelectionCommand changeSelectionCommand = command.value<ChangeSelectionCommand>();
changeSelection(changeSelectionCommand);
} else if (command.userType() == changeLanguageCommand) {
changeLanguage(command.value<ChangeLanguageCommand>());
} else {
Q_ASSERT(false);
}
@@ -61,6 +61,7 @@ class ChangeSelectionCommand;
class PuppetToCreatorCommand;
class InputEventCommand;
class View3DActionCommand;
class ChangeLanguageCommand;
class NodeInstanceClientProxy : public QObject, public NodeInstanceClientInterface
{
@@ -116,6 +117,7 @@ protected:
static QVariant readCommandFromIOStream(QIODevice *ioDevice, quint32 *readCommandCounter, quint32 *blockSize);
void inputEvent(const InputEventCommand &command);
void view3DAction(const View3DActionCommand &command);
void changeLanguage(const ChangeLanguageCommand &command);
protected slots:
void readDataStream();
@@ -53,6 +53,7 @@ class RemoveSharedMemoryCommand;
class ChangeSelectionCommand;
class InputEventCommand;
class View3DActionCommand;
class ChangeLanguageCommand;
class NodeInstanceServerInterface : public QObject
{
@@ -85,9 +86,9 @@ public:
virtual void changeSelection(const ChangeSelectionCommand &command) = 0;
virtual void inputEvent(const InputEventCommand &command) = 0;
virtual void view3DAction(const View3DActionCommand &command) = 0;
virtual void changeLanguage(const ChangeLanguageCommand &command) = 0;
virtual void benchmark(const QString &)
{}
virtual void benchmark(const QString &) {}
static void registerCommands();
};
@@ -1397,6 +1397,7 @@ void NodeInstanceServer::view3DAction(const View3DActionCommand &command)
Q_UNUSED(command)
}
void NodeInstanceServer::changeLanguage(const ChangeLanguageCommand &command) {}
}
@@ -112,6 +112,7 @@ public:
void changeSelection(const ChangeSelectionCommand &command) override;
void inputEvent(const InputEventCommand &command) override;
void view3DAction(const View3DActionCommand &command) override;
void changeLanguage(const ChangeLanguageCommand &command) override;
ServerNodeInstance instanceForId(qint32 id) const;
bool hasInstanceForId(qint32 id) const;
@@ -27,24 +27,25 @@
#include "puppetcreator.h"
#include <createinstancescommand.h>
#include <createscenecommand.h>
#include <update3dviewstatecommand.h>
#include <changevaluescommand.h>
#include <changebindingscommand.h>
#include <changeauxiliarycommand.h>
#include <changebindingscommand.h>
#include <changefileurlcommand.h>
#include <removeinstancescommand.h>
#include <clearscenecommand.h>
#include <removepropertiescommand.h>
#include <reparentinstancescommand.h>
#include <changeidscommand.h>
#include <changestatecommand.h>
#include <completecomponentcommand.h>
#include <changelanguagecommand.h>
#include <changenodesourcecommand.h>
#include <changeselectioncommand.h>
#include <puppettocreatorcommand.h>
#include <changestatecommand.h>
#include <changevaluescommand.h>
#include <clearscenecommand.h>
#include <completecomponentcommand.h>
#include <createinstancescommand.h>
#include <createscenecommand.h>
#include <inputeventcommand.h>
#include <puppettocreatorcommand.h>
#include <removeinstancescommand.h>
#include <removepropertiescommand.h>
#include <reparentinstancescommand.h>
#include <update3dviewstatecommand.h>
#include <view3dactioncommand.h>
#include <informationchangedcommand.h>
@@ -740,4 +741,9 @@ void NodeInstanceServerProxy::view3DAction(const View3DActionCommand &command)
writeCommand(QVariant::fromValue(command));
}
void NodeInstanceServerProxy::changeLanguage(const ChangeLanguageCommand &command)
{
writeCommand(QVariant::fromValue(command));
}
} // namespace QmlDesigner
@@ -85,6 +85,7 @@ public:
void benchmark(const QString &message) override;
void inputEvent(const InputEventCommand &command) override;
void view3DAction(const View3DActionCommand &command) override;
void changeLanguage(const ChangeLanguageCommand &command) override;
protected:
void writeCommand(const QVariant &command);
@@ -25,52 +25,53 @@
#include "nodeinstanceview.h"
#include <model.h>
#include <modelnode.h>
#include <metainfo.h>
#include <nodehints.h>
#include <rewriterview.h>
#include "abstractproperty.h"
#include "variantproperty.h"
#include "bindingproperty.h"
#include "changeauxiliarycommand.h"
#include "changebindingscommand.h"
#include "changefileurlcommand.h"
#include "changeidscommand.h"
#include "changelanguagecommand.h"
#include "changenodesourcecommand.h"
#include "changeselectioncommand.h"
#include "changestatecommand.h"
#include "changevaluescommand.h"
#include "childrenchangedcommand.h"
#include "clearscenecommand.h"
#include "completecomponentcommand.h"
#include "componentcompletedcommand.h"
#include "createinstancescommand.h"
#include "createscenecommand.h"
#include "debugoutputcommand.h"
#include "informationchangedcommand.h"
#include "inputeventcommand.h"
#include "nodeabstractproperty.h"
#include "nodeinstanceserverproxy.h"
#include "nodelistproperty.h"
#include "nodeproperty.h"
#include "pixmapchangedcommand.h"
#include "puppettocreatorcommand.h"
#include "qmlchangeset.h"
#include "qmldesignerconstants.h"
#include "qmlstate.h"
#include "qmltimeline.h"
#include "qmltimelinekeyframegroup.h"
#include "qmlvisualnode.h"
#include "qmldesignerconstants.h"
#include "createscenecommand.h"
#include "createinstancescommand.h"
#include "clearscenecommand.h"
#include "changefileurlcommand.h"
#include "reparentinstancescommand.h"
#include "update3dviewstatecommand.h"
#include "changevaluescommand.h"
#include "changeauxiliarycommand.h"
#include "changebindingscommand.h"
#include "changeidscommand.h"
#include "changeselectioncommand.h"
#include "changenodesourcecommand.h"
#include "removeinstancescommand.h"
#include "removepropertiescommand.h"
#include "valueschangedcommand.h"
#include "pixmapchangedcommand.h"
#include "informationchangedcommand.h"
#include "changestatecommand.h"
#include "childrenchangedcommand.h"
#include "statepreviewimagechangedcommand.h"
#include "completecomponentcommand.h"
#include "componentcompletedcommand.h"
#include "tokencommand.h"
#include "removesharedmemorycommand.h"
#include "debugoutputcommand.h"
#include "nodeinstanceserverproxy.h"
#include "puppettocreatorcommand.h"
#include "inputeventcommand.h"
#include "reparentinstancescommand.h"
#include "statepreviewimagechangedcommand.h"
#include "tokencommand.h"
#include "update3dviewstatecommand.h"
#include "valueschangedcommand.h"
#include "variantproperty.h"
#include "view3dactioncommand.h"
#include <metainfo.h>
#include <model.h>
#include <modelnode.h>
#include <nodehints.h>
#include <rewriterview.h>
#ifndef QMLDESIGNER_TEST
#include <qmldesignerplugin.h>
@@ -536,6 +537,8 @@ void NodeInstanceView::auxiliaryDataChanged(const ModelNode &node,
}
}
}
} else if (node.isRootNode() && name == "language") {
nodeInstanceServer()->changeLanguage({value.toString()});
}
}