Commit 1b3016c5 authored by Marco Bubke's avatar Marco Bubke

QmlDesigner.NodeInstances: Refactor image send commands

parent 66ed5367
......@@ -119,7 +119,9 @@ SOURCES += $$PWD/model/abstractview.cpp \
$$PWD/instances/nodeinstanceserverproxy.cpp \
$$PWD/instances/nodeinstanceclientproxy.cpp \
$$PWD/instances/addimportcommand.cpp \
$$PWD/instances/childrenchangedcommand.cpp
$$PWD/instances/childrenchangedcommand.cpp \
$$PWD/instances/statepreviewimagechangedcommand.cpp \
$$PWD/instances/imagecontainer.cpp
HEADERS += $$PWD/include/corelib_global.h \
$$PWD/include/abstractview.h \
$$PWD/include/nodeinstanceview.h \
......@@ -237,8 +239,9 @@ HEADERS += $$PWD/include/corelib_global.h \
$$PWD/instances/nodeinstanceserverproxy.h \
$$PWD/instances/nodeinstanceclientproxy.h \
$$PWD/instances/addimportcommand.h \
$$PWD/instances/childrenchangedcommand.h
$$PWD/instances/childrenchangedcommand.h \
$$PWD/instances/statepreviewimagechangedcommand.h \
$$PWD/instances/imagecontainer.h
contains(CONFIG, plugin) {
# If core.pri has been included in the qmldesigner plugin
SOURCES += $$PWD/model/basetexteditmodifier.cpp
......
......@@ -9,6 +9,7 @@ class ValuesChangedCommand;
class PixmapChangedCommand;
class InformationChangedCommand;
class ChildrenChangedCommand;
class StatePreviewImageChangedCommand;
class NodeInstanceClientInterface
{
......@@ -17,6 +18,7 @@ public:
virtual void valuesChanged(const ValuesChangedCommand &command) = 0;
virtual void pixmapChanged(const PixmapChangedCommand &command) = 0;
virtual void childrenChanged(const ChildrenChangedCommand &command) = 0;
virtual void statePreviewImagesChanged(const StatePreviewImageChangedCommand &command) = 0;
virtual void flush() {};
virtual qint64 bytesToWrite() const {return 0;}
......
......@@ -116,6 +116,7 @@ public:
void pixmapChanged(const PixmapChangedCommand &command);
void informationChanged(const InformationChangedCommand &command);
void childrenChanged(const ChildrenChangedCommand &command);
void statePreviewImagesChanged(const StatePreviewImageChangedCommand &command);
private: // functions
NodeInstance rootNodeInstance() const;
......
#include "imagecontainer.h"
namespace QmlDesigner {
ImageContainer::ImageContainer()
: m_instanceId(-1)
{
}
ImageContainer::ImageContainer(qint32 instanceId, const QImage &image)
: m_image(image), m_instanceId(instanceId)
{
}
qint32 ImageContainer::instanceId() const
{
return m_instanceId;
}
QImage ImageContainer::image() const
{
return m_image;
}
QDataStream &operator<<(QDataStream &out, const ImageContainer &container)
{
out << container.instanceId();
const QImage image = container.image();
const QByteArray data(reinterpret_cast<const char*>(image.constBits()), image.byteCount());
out << qint32(image.bytesPerLine());
out << image.size();
out << qint32(image.format());
out << qint32(image.byteCount());
out.writeRawData(reinterpret_cast<const char*>(image.constBits()), image.byteCount());
return out;
}
QDataStream &operator>>(QDataStream &in, ImageContainer &container)
{
qint32 byteSize;
qint32 bytesPerLine;
QSize imageSize;
qint32 format;
in >> container.m_instanceId;
in >> bytesPerLine;
in >> imageSize;
in >> format;
in >> byteSize;
container.m_image = QImage(imageSize, QImage::Format(format));
in.readRawData(reinterpret_cast<char*>(container.m_image.bits()), byteSize);
return in;
}
} // namespace QmlDesigner
#ifndef IMAGECONTAINER_H
#define IMAGECONTAINER_H
#include <QMetaType>
#include <QImage>
namespace QmlDesigner {
class ImageContainer
{
friend QDataStream &operator>>(QDataStream &in, ImageContainer &container);
public:
ImageContainer();
ImageContainer(qint32 instanceId, const QImage &image);
qint32 instanceId() const;
QImage image() const;
private:
QImage m_image;
qint32 m_instanceId;
};
QDataStream &operator<<(QDataStream &out, const ImageContainer &container);
QDataStream &operator>>(QDataStream &in, ImageContainer &container);
} // namespace QmlDesigner
Q_DECLARE_METATYPE(QmlDesigner::ImageContainer);
#endif // IMAGECONTAINER_H
......@@ -3,6 +3,8 @@ INCLUDEPATH += $$PWD/../include
HEADERS += $$PWD/behaviornodeinstance.h
HEADERS += $$PWDstatepreviewimagechangedcommand.h
HEADERS += $$PWD//imagecontainer.h
HEADERS += $$PWD/childrenchangedcommand.h
HEADERS += $$PWD/addimportcommand.h
HEADERS += $$PWD/changebindingscommand.h
......@@ -43,6 +45,8 @@ HEADERS += $$PWD/../include/nodeinstanceserverinterface.h
SOURCES += $$PWD/behaviornodeinstance.cpp
SOURCES += $$PWD/statepreviewimagechangedcommand.cpp
SOURCES += $$PWD/imagecontainer.cpp
SOURCES += $$PWD/childrenchangedcommand.cpp
SOURCES += $$PWD/addimportcommand.cpp
SOURCES += $$PWD/changebindingscommand.cpp
......
......@@ -28,6 +28,8 @@
#include "pixmapchangedcommand.h"
#include "valueschangedcommand.h"
#include "childrenchangedcommand.h"
#include "imagecontainer.h"
#include "statepreviewimagechangedcommand.h"
namespace QmlDesigner {
......@@ -76,6 +78,11 @@ void NodeInstanceClientProxy::childrenChanged(const ChildrenChangedCommand &comm
writeCommand(QVariant::fromValue(command));
}
void NodeInstanceClientProxy::statePreviewImagesChanged(const StatePreviewImageChangedCommand &command)
{
writeCommand(QVariant::fromValue(command));
}
void NodeInstanceClientProxy::flush()
{
}
......
......@@ -24,6 +24,7 @@ public:
void valuesChanged(const ValuesChangedCommand &command);
void pixmapChanged(const PixmapChangedCommand &command);
void childrenChanged(const ChildrenChangedCommand &command);
void statePreviewImagesChanged(const StatePreviewImageChangedCommand &command);
void flush();
qint64 bytesToWrite() const;
......
......@@ -82,8 +82,7 @@ void NodeInstanceServer::createInstances(const CreateInstancesCommand &command)
nodeInstanceClient()->valuesChanged(createValuesChangedCommand(instanceList));
nodeInstanceClient()->informationChanged(createAllInformationChangedCommand(instanceList, true));
foreach(const ServerNodeInstance &instance, instanceList)
nodeInstanceClient()->pixmapChanged(createPixmapChangedCommand(instance));
nodeInstanceClient()->pixmapChanged(createPixmapChangedCommand(instanceList));
startRenderTimer();
}
......@@ -682,10 +681,14 @@ void NodeInstanceServer::removeInstanceRelationsip(qint32 instanceId)
}
}
PixmapChangedCommand NodeInstanceServer::createPixmapChangedCommand(const ServerNodeInstance &instance) const
PixmapChangedCommand NodeInstanceServer::createPixmapChangedCommand(const QList<ServerNodeInstance> &instanceList) const
{
qDebug() << __FUNCTION__ << instance.internalObject();
return PixmapChangedCommand(instance.instanceId(), instance.renderImage());
QVector<ImageContainer> imageVector;
foreach (const ServerNodeInstance &instance, instanceList)
imageVector.append(ImageContainer(instance.instanceId(), instance.renderImage()));
return PixmapChangedCommand(imageVector);
}
bool NodeInstanceServer::nonInstanceChildIsDirty(QGraphicsObject *graphicsObject) const
......@@ -783,8 +786,8 @@ void NodeInstanceServer::findItemChangesAndSendChangeCommands()
if (!propertyChangedList.isEmpty())
nodeInstanceClient()->valuesChanged(createValuesChangedCommand(propertyChangedList));
foreach(const ServerNodeInstance &instance, dirtyInstanceSet)
nodeInstanceClient()->pixmapChanged(createPixmapChangedCommand(instance));
if (!dirtyInstanceSet.isEmpty())
nodeInstanceClient()->pixmapChanged(createPixmapChangedCommand(dirtyInstanceSet.toList()));
if (adjustSceneRect) {
QRectF boundingRect = m_rootNodeInstance.boundingRect();
......
......@@ -101,7 +101,7 @@ protected:
ValuesChangedCommand createValuesChangedCommand(const QList<ServerNodeInstance> &instanceList) const;
ValuesChangedCommand createValuesChangedCommand(const QVector<InstancePropertyPair> &propertyList) const;
PixmapChangedCommand createPixmapChangedCommand(const ServerNodeInstance &instance) const;
PixmapChangedCommand createPixmapChangedCommand(const QList<ServerNodeInstance> &instanceList) const;
InformationChangedCommand createAllInformationChangedCommand(const QList<ServerNodeInstance> &instanceList, bool initial = false) const;
ChildrenChangedCommand createChildrenChangedCommand(const ServerNodeInstance &parentInstance, const QList<ServerNodeInstance> &instanceList) const;
......
......@@ -22,6 +22,9 @@
#include "valueschangedcommand.h"
#include "addimportcommand.h"
#include "childrenchangedcommand.h"
#include "imagecontainer.h"
#include "statepreviewimagechangedcommand.h"
namespace QmlDesigner {
......@@ -108,6 +111,12 @@ void NodeInstanceServerInterface::registerCommands()
qRegisterMetaType<ChildrenChangedCommand>("ChildrenChangedCommand");
qRegisterMetaTypeStreamOperators<ChildrenChangedCommand>("ChildrenChangedCommand");
qRegisterMetaType<ImageContainer>("ImageContainer");
qRegisterMetaTypeStreamOperators<ImageContainer>("ImageContainer");
qRegisterMetaType<StatePreviewImageChangedCommand>("StatePreviewImageChangedCommand");
qRegisterMetaTypeStreamOperators<StatePreviewImageChangedCommand>("StatePreviewImageChangedCommand");
}
}
......@@ -27,6 +27,8 @@
#include "pixmapchangedcommand.h"
#include "valueschangedcommand.h"
#include "childrenchangedcommand.h"
#include "imagecontainer.h"
#include "statepreviewimagechangedcommand.h"
#include "nodeinstanceview.h"
#include "nodeinstanceclientproxy.h"
......@@ -75,6 +77,7 @@ void NodeInstanceServerProxy::dispatchCommand(const QVariant &command)
static const int valuesChangedCommandType = QMetaType::type("ValuesChangedCommand");
static const int pixmapChangedCommandType = QMetaType::type("PixmapChangedCommand");
static const int childrenChangedCommandType = QMetaType::type("ChildrenChangedCommand");
static const int statePreviewImageChangedCommandType = QMetaType::type("StatePreviewImageChangedCommand");
if (command.userType() == informationChangedCommandType)
nodeInstanceClient()->informationChanged(command.value<InformationChangedCommand>());
......@@ -84,6 +87,8 @@ void NodeInstanceServerProxy::dispatchCommand(const QVariant &command)
nodeInstanceClient()->pixmapChanged(command.value<PixmapChangedCommand>());
else if (command.userType() == childrenChangedCommandType)
nodeInstanceClient()->childrenChanged(command.value<ChildrenChangedCommand>());
else if (command.userType() == statePreviewImageChangedCommandType)
nodeInstanceClient()->statePreviewImagesChanged(command.value<StatePreviewImageChangedCommand>());
else
Q_ASSERT(false);
}
......
......@@ -72,6 +72,8 @@
#include "changestatecommand.h"
#include "addimportcommand.h"
#include "childrenchangedcommand.h"
#include "imagecontainer.h"
#include "statepreviewimagechangedcommand.h"
#include "nodeinstanceserverproxy.h"
......@@ -864,11 +866,13 @@ void NodeInstanceView::pixmapChanged(const PixmapChangedCommand &command)
{
QSet<ModelNode> renderImageChangeSet;
if (hasInstanceForId(command.instanceId())) {
NodeInstance instance = instanceForId(command.instanceId());
if (instance.isValid()) {
instance.setRenderImage(command.renderImage());
renderImageChangeSet.insert(instance.modelNode());
foreach (const ImageContainer &container, command.images()) {
if (hasInstanceForId(container.instanceId())) {
NodeInstance instance = instanceForId(container.instanceId());
if (instance.isValid()) {
instance.setRenderImage(container.image());
renderImageChangeSet.insert(instance.modelNode());
}
}
}
......@@ -894,6 +898,11 @@ void NodeInstanceView::informationChanged(const InformationChangedCommand &comma
emitCustomNotification("__instance information changed__", informationChangedList);
}
void NodeInstanceView::statePreviewImagesChanged(const StatePreviewImageChangedCommand &/*command*/)
{
}
void NodeInstanceView::childrenChanged(const ChildrenChangedCommand &command)
{
QList<ModelNode> childNodeList;
......
......@@ -7,58 +7,29 @@
namespace QmlDesigner {
PixmapChangedCommand::PixmapChangedCommand()
: m_instanceId(-1)
{
}
PixmapChangedCommand::PixmapChangedCommand(qint32 instanceId, const QImage &image)
: m_image(image), m_instanceId(instanceId)
PixmapChangedCommand::PixmapChangedCommand(const QVector<ImageContainer> &imageVector)
: m_imageVector(imageVector)
{
}
qint32 PixmapChangedCommand::instanceId() const
QVector<ImageContainer> PixmapChangedCommand::images() const
{
return m_instanceId;
}
QImage PixmapChangedCommand::renderImage() const
{
return m_image;
return m_imageVector;
}
QDataStream &operator<<(QDataStream &out, const PixmapChangedCommand &command)
{
out << command.instanceId();
const QImage image = command.renderImage();
const QByteArray data(reinterpret_cast<const char*>(image.constBits()), image.byteCount());
out << qint32(image.bytesPerLine());
out << image.size();
out << qint32(image.format());
out << qint32(image.byteCount());
out.writeRawData(reinterpret_cast<const char*>(image.constBits()), image.byteCount());
out << command.images();
return out;
}
QDataStream &operator>>(QDataStream &in, PixmapChangedCommand &command)
{
qint32 byteSize;
qint32 bytesPerLine;
QSize imageSize;
qint32 format;
in >> command.m_instanceId;
in >> bytesPerLine;
in >> imageSize;
in >> format;
in >> byteSize;
command.m_image = QImage(imageSize, QImage::Format(format));
in.readRawData(reinterpret_cast<char*>(command.m_image.bits()), byteSize);
in >> command.m_imageVector;
return in;
}
......
......@@ -2,7 +2,7 @@
#define PIXMAPCHANGEDCOMMAND_H
#include <QMetaType>
#include <QImage>
#include "imagecontainer.h"
namespace QmlDesigner {
......@@ -11,14 +11,12 @@ class PixmapChangedCommand
friend QDataStream &operator>>(QDataStream &in, PixmapChangedCommand &command);
public:
PixmapChangedCommand();
PixmapChangedCommand(qint32 instanceId, const QImage &image);
PixmapChangedCommand(const QVector<ImageContainer> &imageVector);
qint32 instanceId() const;
QImage renderImage() const;
QVector<ImageContainer> images() const;
private:
QImage m_image;
qint32 m_instanceId;
QVector<ImageContainer> m_imageVector;
};
QDataStream &operator<<(QDataStream &out, const PixmapChangedCommand &command);
......
#include "statepreviewimagechangedcommand.h"
namespace QmlDesigner {
StatePreviewImageChangedCommand::StatePreviewImageChangedCommand()
{
}
StatePreviewImageChangedCommand::StatePreviewImageChangedCommand(const QVector<ImageContainer> &imageVector)
: m_previewVector(imageVector)
{
}
QVector<ImageContainer> StatePreviewImageChangedCommand::previews()const
{
return m_previewVector;
}
QDataStream &operator<<(QDataStream &out, const StatePreviewImageChangedCommand &command)
{
out << command.previews();
return out;
}
QDataStream &operator>>(QDataStream &in, StatePreviewImageChangedCommand &command)
{
in >> command.m_previewVector;
return in;
}
} // namespace QmlDesigner
#ifndef STATEPREVIEWIMAGECHANGEDCOMMAND_H
#define STATEPREVIEWIMAGECHANGEDCOMMAND_H
#include <QMetaType>
#include "imagecontainer.h"
namespace QmlDesigner {
class StatePreviewImageChangedCommand
{
friend QDataStream &operator>>(QDataStream &in, StatePreviewImageChangedCommand &command);
public:
StatePreviewImageChangedCommand();
StatePreviewImageChangedCommand(const QVector<ImageContainer> &imageVector);
QVector<ImageContainer> previews() const;
private:
QVector<ImageContainer> m_previewVector;
};
QDataStream &operator<<(QDataStream &out, const StatePreviewImageChangedCommand &command);
QDataStream &operator>>(QDataStream &in, StatePreviewImageChangedCommand &command);
} // namespace QmlDesigner
Q_DECLARE_METATYPE(QmlDesigner::StatePreviewImageChangedCommand);
#endif // STATEPREVIEWIMAGECHANGEDCOMMAND_H
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment