forked from qt-creator/qt-creator
Update the node instance if a file has changed on the local drive
This commit is contained in:
@@ -148,6 +148,7 @@ private: // functions
|
|||||||
void setPropertyDynamicBinding(const QString &name, const QString &typeName, const QString &expression);
|
void setPropertyDynamicBinding(const QString &name, const QString &typeName, const QString &expression);
|
||||||
|
|
||||||
void resetProperty(const QString &name);
|
void resetProperty(const QString &name);
|
||||||
|
void refreshProperty(const QString &name);
|
||||||
|
|
||||||
void activateState();
|
void activateState();
|
||||||
void deactivateState();
|
void deactivateState();
|
||||||
|
|||||||
@@ -41,6 +41,8 @@
|
|||||||
|
|
||||||
class QDeclarativeEngine;
|
class QDeclarativeEngine;
|
||||||
class QGraphicsView;
|
class QGraphicsView;
|
||||||
|
class QFileSystemWatcher;
|
||||||
|
|
||||||
|
|
||||||
namespace QmlDesigner {
|
namespace QmlDesigner {
|
||||||
|
|
||||||
@@ -59,6 +61,7 @@ class CORESHARED_EXPORT NodeInstanceView : public AbstractView
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
typedef QWeakPointer<NodeInstanceView> Pointer;
|
typedef QWeakPointer<NodeInstanceView> Pointer;
|
||||||
|
typedef QPair<QWeakPointer<QObject>, QString> ObjectPropertyPair;
|
||||||
|
|
||||||
NodeInstanceView(QObject *parent = 0);
|
NodeInstanceView(QObject *parent = 0);
|
||||||
~NodeInstanceView();
|
~NodeInstanceView();
|
||||||
@@ -105,6 +108,7 @@ public:
|
|||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void emitParentChanged(QObject *child);
|
void emitParentChanged(QObject *child);
|
||||||
|
void refreshLocalFileProperty(const QString &path);
|
||||||
|
|
||||||
private: // functions
|
private: // functions
|
||||||
NodeInstance rootNodeInstance() const;
|
NodeInstance rootNodeInstance() const;
|
||||||
@@ -131,6 +135,11 @@ private: // functions
|
|||||||
void setStateInstance(const NodeInstance &stateInstance);
|
void setStateInstance(const NodeInstance &stateInstance);
|
||||||
void clearStateInstance();
|
void clearStateInstance();
|
||||||
|
|
||||||
|
QFileSystemWatcher *fileSystemWatcher();
|
||||||
|
|
||||||
|
void addFilePropertyToFileSystemWatcher(QObject *object, const QString &propertyName, const QString &path);
|
||||||
|
void removeFilePropertyFromFileSystemWatcher(QObject *object, const QString &propertyName, const QString &path);
|
||||||
|
|
||||||
private: //variables
|
private: //variables
|
||||||
NodeInstance m_rootNodeInstance;
|
NodeInstance m_rootNodeInstance;
|
||||||
NodeInstance m_activeStateInstance;
|
NodeInstance m_activeStateInstance;
|
||||||
@@ -138,12 +147,17 @@ private: //variables
|
|||||||
|
|
||||||
QHash<ModelNode, NodeInstance> m_nodeInstanceHash;
|
QHash<ModelNode, NodeInstance> m_nodeInstanceHash;
|
||||||
QHash<QObject*, NodeInstance> m_objectInstanceHash; // This is purely internal. Might contain dangling pointers!
|
QHash<QObject*, NodeInstance> m_objectInstanceHash; // This is purely internal. Might contain dangling pointers!
|
||||||
|
QMultiHash<QString, ObjectPropertyPair> m_fileSystemWatcherHash;
|
||||||
QWeakPointer<QDeclarativeEngine> m_engine;
|
QWeakPointer<QDeclarativeEngine> m_engine;
|
||||||
QWeakPointer<Internal::ChildrenChangeEventFilter> m_childrenChangeEventFilter;
|
QWeakPointer<Internal::ChildrenChangeEventFilter> m_childrenChangeEventFilter;
|
||||||
|
|
||||||
QWeakPointer<QmlModelView> m_qmlModelView;
|
QWeakPointer<QmlModelView> m_qmlModelView;
|
||||||
|
|
||||||
|
QWeakPointer<QFileSystemWatcher> m_fileSystemWatcher;
|
||||||
|
|
||||||
bool m_blockStatePropertyChanges;
|
bool m_blockStatePropertyChanges;
|
||||||
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace NodeInstanceView
|
} // namespace NodeInstanceView
|
||||||
|
|||||||
@@ -394,6 +394,11 @@ void NodeInstance::resetProperty(const QString &name)
|
|||||||
m_nodeInstance->resetProperty(name);
|
m_nodeInstance->resetProperty(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void NodeInstance::refreshProperty(const QString &name)
|
||||||
|
{
|
||||||
|
m_nodeInstance->refreshProperty(name);
|
||||||
|
}
|
||||||
|
|
||||||
void NodeInstance::setId(const QString &id)
|
void NodeInstance::setId(const QString &id)
|
||||||
{
|
{
|
||||||
m_nodeInstance->setId(id);
|
m_nodeInstance->setId(id);
|
||||||
|
|||||||
@@ -38,6 +38,7 @@
|
|||||||
#include <QGraphicsView>
|
#include <QGraphicsView>
|
||||||
#include <QGraphicsScene>
|
#include <QGraphicsScene>
|
||||||
#include <QGraphicsObject>
|
#include <QGraphicsObject>
|
||||||
|
#include <QFileSystemWatcher>
|
||||||
|
|
||||||
#include <model.h>
|
#include <model.h>
|
||||||
#include <modelnode.h>
|
#include <modelnode.h>
|
||||||
@@ -653,6 +654,7 @@ void NodeInstanceView::render(QPainter * painter, const QRectF &target, const QR
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
QRectF NodeInstanceView::sceneRect() const
|
QRectF NodeInstanceView::sceneRect() const
|
||||||
{
|
{
|
||||||
if (m_graphicsView)
|
if (m_graphicsView)
|
||||||
@@ -662,3 +664,41 @@ QRectF NodeInstanceView::sceneRect() const
|
|||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QFileSystemWatcher *NodeInstanceView::fileSystemWatcher()
|
||||||
|
{
|
||||||
|
if (m_fileSystemWatcher.isNull()) {
|
||||||
|
m_fileSystemWatcher = new QFileSystemWatcher(this);
|
||||||
|
connect(m_fileSystemWatcher.data(), SIGNAL(fileChanged(QString)), this, SLOT(refreshLocalFileProperty(QString)));
|
||||||
|
}
|
||||||
|
|
||||||
|
return m_fileSystemWatcher.data();
|
||||||
|
}
|
||||||
|
|
||||||
|
void NodeInstanceView::addFilePropertyToFileSystemWatcher(QObject *object, const QString &propertyName, const QString &path)
|
||||||
|
{
|
||||||
|
m_fileSystemWatcherHash.insert(path, ObjectPropertyPair(object, propertyName));
|
||||||
|
fileSystemWatcher()->addPath(path);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void NodeInstanceView::removeFilePropertyFromFileSystemWatcher(QObject *object, const QString &propertyName, const QString &path)
|
||||||
|
{
|
||||||
|
fileSystemWatcher()->removePath(path);
|
||||||
|
m_fileSystemWatcherHash.remove(path, ObjectPropertyPair(object, propertyName));
|
||||||
|
}
|
||||||
|
|
||||||
|
void NodeInstanceView::refreshLocalFileProperty(const QString &path)
|
||||||
|
{
|
||||||
|
if (m_fileSystemWatcherHash.contains(path)) {
|
||||||
|
QList<ObjectPropertyPair> objectPropertyPairList = m_fileSystemWatcherHash.values();
|
||||||
|
foreach(const ObjectPropertyPair &objectPropertyPair, objectPropertyPairList) {
|
||||||
|
QObject *object = objectPropertyPair.first.data();
|
||||||
|
QString propertyName = objectPropertyPair.second;
|
||||||
|
|
||||||
|
if (hasInstanceForObject(object)) {
|
||||||
|
instanceForObject(object).refreshProperty(propertyName);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -55,6 +55,9 @@
|
|||||||
#include <QDeclarativeEngine>
|
#include <QDeclarativeEngine>
|
||||||
#include <QDeclarativeProperty>
|
#include <QDeclarativeProperty>
|
||||||
#include <QSharedPointer>
|
#include <QSharedPointer>
|
||||||
|
#include <QFileInfo>
|
||||||
|
#include <QFileSystemWatcher>
|
||||||
|
#include <QPixmapCache>
|
||||||
|
|
||||||
#include <private/qdeclarativebinding_p.h>
|
#include <private/qdeclarativebinding_p.h>
|
||||||
#include <private/qdeclarativemetatype_p.h>
|
#include <private/qdeclarativemetatype_p.h>
|
||||||
@@ -404,7 +407,27 @@ void ObjectNodeInstance::reparent(const NodeInstance &oldParentInstance, const Q
|
|||||||
void ObjectNodeInstance::setPropertyVariant(const QString &name, const QVariant &value)
|
void ObjectNodeInstance::setPropertyVariant(const QString &name, const QVariant &value)
|
||||||
{
|
{
|
||||||
QDeclarativeProperty property(object(), name, context());
|
QDeclarativeProperty property(object(), name, context());
|
||||||
|
|
||||||
|
QVariant oldValue = property.read();
|
||||||
|
if (oldValue.type() == QVariant::Url) {
|
||||||
|
QUrl url = oldValue.toUrl();
|
||||||
|
QString path = url.toLocalFile();
|
||||||
|
if (QFileInfo(path).exists() && nodeInstanceView() && !path.isEmpty())
|
||||||
|
nodeInstanceView()->removeFilePropertyFromFileSystemWatcher(object(), name, path);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
property.write(value);
|
property.write(value);
|
||||||
|
|
||||||
|
QVariant newValue = property.read();
|
||||||
|
if (newValue.type() == QVariant::Url) {
|
||||||
|
QUrl url = newValue.toUrl();
|
||||||
|
QString path = url.toLocalFile();
|
||||||
|
if (QFileInfo(path).exists() && nodeInstanceView() && !path.isEmpty())
|
||||||
|
nodeInstanceView()->addFilePropertyToFileSystemWatcher(object(), name, path);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ObjectNodeInstance::setPropertyBinding(const QString &name, const QString &expression)
|
void ObjectNodeInstance::setPropertyBinding(const QString &name, const QString &expression)
|
||||||
@@ -460,27 +483,55 @@ NodeInstance ObjectNodeInstance::instanceForNode(const ModelNode &node, const QS
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ObjectNodeInstance::refreshProperty(const QString &name)
|
||||||
|
{
|
||||||
|
QDeclarativeProperty property(object(), name, context());
|
||||||
|
|
||||||
|
QVariant oldValue(property.read());
|
||||||
|
|
||||||
|
if (property.isResettable())
|
||||||
|
property.reset();
|
||||||
|
else
|
||||||
|
property.write(resetValue(name));
|
||||||
|
|
||||||
|
if (oldValue.type() == QVariant::Url) {
|
||||||
|
QByteArray key = oldValue.toUrl().toEncoded(QUrl::FormattingOption(0x100));
|
||||||
|
QString pixmapKey = QString::fromLatin1(key.constData(), key.count());
|
||||||
|
QPixmapCache::remove(pixmapKey);
|
||||||
|
}
|
||||||
|
|
||||||
|
property.write(oldValue);
|
||||||
|
}
|
||||||
|
|
||||||
void ObjectNodeInstance::resetProperty(QObject *object, const QString &propertyName)
|
void ObjectNodeInstance::resetProperty(QObject *object, const QString &propertyName)
|
||||||
{
|
{
|
||||||
m_modelAbstractPropertyHash.remove(propertyName);
|
m_modelAbstractPropertyHash.remove(propertyName);
|
||||||
|
|
||||||
QDeclarativeProperty qmlProperty(object, propertyName, context());
|
QDeclarativeProperty property(object, propertyName, context());
|
||||||
QMetaProperty metaProperty = qmlProperty.property();
|
|
||||||
|
|
||||||
QDeclarativeAbstractBinding *binding = QDeclarativePropertyPrivate::binding(qmlProperty);
|
QVariant oldValue = property.read();
|
||||||
|
if (oldValue.type() == QVariant::Url) {
|
||||||
|
QUrl url = oldValue.toUrl();
|
||||||
|
QString path = url.toLocalFile();
|
||||||
|
if (QFileInfo(path).exists() && nodeInstanceView())
|
||||||
|
nodeInstanceView()->removeFilePropertyFromFileSystemWatcher(object, propertyName, path);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
QDeclarativeAbstractBinding *binding = QDeclarativePropertyPrivate::binding(property);
|
||||||
if (binding) {
|
if (binding) {
|
||||||
binding->setEnabled(false, 0);
|
binding->setEnabled(false, 0);
|
||||||
binding->destroy();
|
binding->destroy();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (metaProperty.isResettable()) {
|
if (property.isResettable()) {
|
||||||
metaProperty.reset(object);
|
property.reset();
|
||||||
} else if (qmlProperty.isWritable()) {
|
} else if (property.isWritable()) {
|
||||||
if (qmlProperty.read() == resetValue(propertyName))
|
if (property.read() == resetValue(propertyName))
|
||||||
return;
|
return;
|
||||||
qmlProperty.write(resetValue(propertyName));
|
property.write(resetValue(propertyName));
|
||||||
} else if (qmlProperty.propertyTypeCategory() == QDeclarativeProperty::List) {
|
} else if (property.propertyTypeCategory() == QDeclarativeProperty::List) {
|
||||||
qvariant_cast<QDeclarativeListReference>(qmlProperty.read()).clear();
|
qvariant_cast<QDeclarativeListReference>(property.read()).clear();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -143,6 +143,7 @@ public:
|
|||||||
virtual void setPropertyBinding(const QString &name, const QString &expression);
|
virtual void setPropertyBinding(const QString &name, const QString &expression);
|
||||||
virtual QVariant property(const QString &name) const;
|
virtual QVariant property(const QString &name) const;
|
||||||
virtual void resetProperty(const QString &name);
|
virtual void resetProperty(const QString &name);
|
||||||
|
virtual void refreshProperty(const QString &name);
|
||||||
virtual bool isVisible() const;
|
virtual bool isVisible() const;
|
||||||
virtual void setVisible(bool isVisible);
|
virtual void setVisible(bool isVisible);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user