QmlDesigner: Move implementation code in the node instances

updateDirtyNodeRecursive and renderPreviewImage belongs to quick image and
not in the node instance server.

Change-Id: I629b89c748036c0614e78bcfa0c837cb16ca6374
Reviewed-by: Thomas Hartmann <Thomas.Hartmann@digia.com>
This commit is contained in:
Marco Bubke
2013-04-15 13:28:48 +02:00
committed by Thomas Hartmann
parent f021ec50cd
commit 359ef53280
7 changed files with 61 additions and 16 deletions

View File

@@ -433,6 +433,10 @@ QVariant ObjectNodeInstance::fixResourcePaths(const QVariant &value)
return value;
}
void ObjectNodeInstance::updateDirtyNodeRecursive()
{
}
void ObjectNodeInstance::setPropertyVariant(const PropertyName &name, const QVariant &value)
{
QQmlProperty property(object(), name, context());
@@ -1108,6 +1112,11 @@ QImage ObjectNodeInstance::renderImage() const
return QImage();
}
QImage ObjectNodeInstance::renderPreviewImage(const QSize & /*previewImageSize*/) const
{
return QImage();
}
QObject *ObjectNodeInstance::parent() const
{
if (!object())

View File

@@ -85,6 +85,7 @@ public:
virtual void initialize(const Pointer &objectNodeInstance);
virtual void paint(QPainter *painter);
virtual QImage renderImage() const;
virtual QImage renderPreviewImage(const QSize &previewImageSize) const;
virtual QObject *parent() const;
@@ -179,6 +180,8 @@ public:
static QVariant fixResourcePaths(const QVariant &value);
virtual void updateDirtyNodeRecursive();
protected:
void doResetProperty(const PropertyName &propertyName);
void removeFromOldProperty(QObject *object, QObject *oldParent, const PropertyName &oldParentProperty);

View File

@@ -65,7 +65,7 @@ void Qt5PreviewNodeInstanceServer::collectItemChangesAndSendChangeCommands()
{
static bool inFunction = false;
if (rootNodeInstance().internalSGItem() == 0)
if (!rootNodeInstance().holdsQuickItem())
return;
if (!inFunction && nodeInstanceClient()->bytesToWrite() < 10000) {
@@ -106,17 +106,14 @@ static void updateDirtyNodeRecursive(QQuickItem *parentItem)
QImage Qt5PreviewNodeInstanceServer::renderPreviewImage()
{
updateDirtyNodeRecursive(rootNodeInstance().internalSGItem());
rootNodeInstance().updateDirtyNodeRecursive();
QRectF boundingRect = rootNodeInstance().boundingRect();
QSize previewImageSize = boundingRect.size().toSize();
previewImageSize.scale(QSize(100, 100), Qt::KeepAspectRatio);
QImage previewImage;
if (boundingRect.isValid() && rootNodeInstance().internalSGItem())
previewImage = designerSupport()->renderImageForItem(rootNodeInstance().internalSGItem(), boundingRect, previewImageSize);
QImage previewImage = rootNodeInstance().renderPreviewImage(previewImageSize);
previewImage = previewImage.convertToFormat(QImage::Format_ARGB32_Premultiplied);

View File

@@ -218,6 +218,14 @@ void QuickItemNodeInstance::updateDirtyNodeRecursive(QQuickItem *parentItem) con
DesignerSupport::updateDirtyNode(parentItem);
}
void QuickItemNodeInstance::updateAllDirtyNodeRecursive(QQuickItem *parentItem) const
{
foreach (QQuickItem *childItem, parentItem->childItems())
updateDirtyNodeRecursive(childItem);
DesignerSupport::updateDirtyNode(parentItem);
}
QImage QuickItemNodeInstance::renderImage() const
{
updateDirtyNodeRecursive(quickItem());
@@ -231,6 +239,16 @@ QImage QuickItemNodeInstance::renderImage() const
return renderImage;
}
QImage QuickItemNodeInstance::renderPreviewImage(const QSize &previewImageSize) const
{
QRectF previewItemBoundingRect = boundingRect();
if (previewItemBoundingRect.isValid() && quickItem())
return designerSupport()->renderImageForItem(quickItem(), previewItemBoundingRect, previewImageSize);
return QImage();
}
bool QuickItemNodeInstance::isMovable() const
{
if (isRootNodeInstance())
@@ -661,6 +679,11 @@ void QuickItemNodeInstance::createEffectItem(bool createEffectItem)
s_createEffectItem = createEffectItem;
}
void QuickItemNodeInstance::updateDirtyNodeRecursive() const
{
updateAllDirtyNodeRecursive(quickItem());
}
} // namespace Internal
} // namespace QmlDesigner

View File

@@ -102,12 +102,15 @@ public:
QList<ServerNodeInstance> stateInstances() const;
QImage renderImage() const;
QImage renderPreviewImage(const QSize &previewImageSize) const;
DesignerSupport *designerSupport() const;
Qt5NodeInstanceServer *qt5NodeInstanceServer() const;
static void createEffectItem(bool createEffectItem);
void updateDirtyNodeRecursive() const;
protected:
QuickItemNodeInstance(QQuickItem*);
QQuickItem *quickItem() const;
@@ -116,6 +119,7 @@ protected:
void refresh();
QRectF boundingRectWithStepChilds(QQuickItem *parentItem) const;
void updateDirtyNodeRecursive(QQuickItem *parentItem) const;
void updateAllDirtyNodeRecursive(QQuickItem *parentItem) const;
static bool anyItemHasContent(QQuickItem *graphicsItem);
static bool childItemsHaveContent(QQuickItem *graphicsItem);

View File

@@ -122,6 +122,11 @@ QImage ServerNodeInstance::renderImage() const
return m_nodeInstance->renderImage();
}
QImage ServerNodeInstance::renderPreviewImage(const QSize &previewImageSize) const
{
return m_nodeInstance->renderPreviewImage(previewImageSize);
}
bool ServerNodeInstance::isRootNodeInstance() const
{
return isValid() && m_nodeInstance->isRootNodeInstance();
@@ -153,6 +158,16 @@ void ServerNodeInstance::setNodeSource(const QString &source)
m_nodeInstance->setNodeSource(source);
}
bool ServerNodeInstance::holdsQuickItem() const
{
return m_nodeInstance->isQuickItem();
}
void ServerNodeInstance::updateDirtyNodeRecursive()
{
m_nodeInstance->updateDirtyNodeRecursive();
}
bool ServerNodeInstance::isSubclassOf(const QString &superTypeName) const
{
return isSubclassOf(internalObject(), superTypeName.toUtf8());
@@ -552,13 +567,6 @@ QObject *ServerNodeInstance::internalObject() const
return m_nodeInstance->object();
}
#if (QT_VERSION >= QT_VERSION_CHECK(5, 0, 0))
QQuickItem *ServerNodeInstance::internalSGItem() const
{
return qobject_cast<QQuickItem*>(internalObject());
}
#endif
void ServerNodeInstance::activateState()
{
m_nodeInstance->activateState();

View File

@@ -98,6 +98,7 @@ public:
void paint(QPainter *painter);
QImage renderImage() const;
QImage renderPreviewImage(const QSize &previewImageSize) const;
ServerNodeInstance parent() const;
bool hasParent() const;
@@ -196,11 +197,11 @@ private: // functions
void setNodeSource(const QString &source);
bool holdsQuickItem() const;
void updateDirtyNodeRecursive();
QObject *internalObject() const; // should be not used outside of the nodeinstances!!!!
#if (QT_VERSION >= QT_VERSION_CHECK(5, 0, 0))
QQuickItem *internalSGItem() const;
#endif
private: // variables
QSharedPointer<Internal::ObjectNodeInstance> m_nodeInstance;