summaryrefslogtreecommitdiff
path: root/src/plugins/qmldesigner/designercore/instances/nodeinstanceview.cpp
blob: fcef236ab70ebdc57daad67e9bda6f1303ae0da0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
/**************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** No Commercial Usage
**
** This file contains pre-release code and may not be distributed.
** You may use this file in accordance with the terms and conditions
** contained in the Technology Preview License Agreement accompanying
** this package.
**
** GNU Lesser General Public License Usage
**
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file.  Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Nokia gives you certain additional
** rights.  These rights are described in the Nokia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** If you have questions regarding the use of this file, please contact
** Nokia at qt-info@nokia.com.
**
**************************************************************************/

#include "nodeinstanceview.h"

#include <QDeclarativeEngine>
#include <QDeclarativeContext>
#include <private/qdeclarativeengine_p.h>

#include <QtDebug>
#include <QUrl>
#include <QGraphicsView>
#include <QGraphicsScene>
#include <QGraphicsObject>
#include <QFileSystemWatcher>

#include <model.h>
#include <modelnode.h>
#include <propertymetainfo.h>
#include <metainfo.h>
#include <nodeinstance.h>

#include <typeinfo>
#include <iwidgetplugin.h>

#include "abstractproperty.h"
#include "variantproperty.h"
#include "bindingproperty.h"
#include "nodeabstractproperty.h"
#include "nodelistproperty.h"

#include "objectnodeinstance.h"

#include "qmlmodelview.h"

enum {
    debug = false
};

/*!
\defgroup CoreInstance
*/
/*!
\class QmlDesigner::NodeInstanceView
\ingroup CoreInstance
\brief Central class to create and manage instances of a ModelNode.

This view is used to instance the ModelNodes. Many AbstractViews hold a
NodeInstanceView to get values from tghe NodeInstances back.
For this purpose this view can be rendered offscreen.

\see NodeInstance ModelNode
*/

namespace QmlDesigner {

/*! \brief Constructor

  The class will be rendered offscreen if not set otherwise.

\param Parent of this object. If this parent is d this instance is
d too.

\see ~NodeInstanceView setRenderOffScreen
*/
NodeInstanceView::NodeInstanceView(QObject *parent)
        : AbstractView(parent),
    m_graphicsView(new QGraphicsView),
    m_blockStatePropertyChanges(false)
{
    m_graphicsView->setAttribute(Qt::WA_DontShowOnScreen, true);
    m_graphicsView->setOptimizationFlags(QGraphicsView::DontSavePainterState);
    m_graphicsView->setViewportUpdateMode(QGraphicsView::BoundingRectViewportUpdate);
    m_graphicsView->setScene(new QGraphicsScene(m_graphicsView.data()));
    m_graphicsView->scene()->setItemIndexMethod(QGraphicsScene::NoIndex);
}


/*! \brief Destructor

*/
NodeInstanceView::~NodeInstanceView()
{
    removeAllInstanceNodeRelationships();
}

/*!   \name Overloaded Notifiers
 *  This methodes notify the view that something has happen in the model
 */
//\{
/*! \brief Notifing the view that it was attached to a model.

  For every ModelNode in the model a NodeInstance will be created.
\param model Model to which the view is attached
*/
void NodeInstanceView::modelAttached(Model *model)
{
    AbstractView::modelAttached(model);
    engine()->setBaseUrl(model->fileUrl());
    loadModel(model);
}

void NodeInstanceView::modelAboutToBeDetached(Model * model)
{
    removeAllInstanceNodeRelationships();
    AbstractView::modelAboutToBeDetached(model);
    delete m_engine.data();
}


/*! \brief Notifing the view that a node was created.
  A NodeInstance will be created for the new created ModelNode.
\param createdNode New created ModelNode.
*/
void NodeInstanceView::nodeCreated(const ModelNode &createdNode)
{
    NodeInstance instance = loadNode(createdNode);

    if (instance.isValid())
        instance.doComponentComplete();
}

/*! \brief Notifing the view that a node was created.
\param removedNode
*/
void NodeInstanceView::nodeAboutToBeRemoved(const ModelNode &removedNode)
{
    removeInstanceAndSubInstances(removedNode);
}

void NodeInstanceView::nodeRemoved(const ModelNode &/*removedNode*/, const NodeAbstractProperty &/*parentProperty*/, PropertyChangeFlags /*propertyChange*/)
{
}

/*! \brief Notifing the view that a AbstractProperty was added to a ModelNode.

  The property will be set for the NodeInstance.

\param state ModelNode to which the Property belongs
\param property AbstractProperty which was added
\see AbstractProperty NodeInstance ModelNode
*/

void NodeInstanceView::propertiesAboutToBeRemoved(const QList<AbstractProperty>& propertyList)
{
    foreach (const AbstractProperty &property, propertyList) {
        resetInstanceProperty(property);

        if (property.isNodeAbstractProperty()) {
            foreach (const ModelNode &subNode, property.toNodeAbstractProperty().allSubNodes())
                removeInstanceNodeRelationship(subNode);
        }
    }
}

void NodeInstanceView::propertiesRemoved(const QList<AbstractProperty>& /*propertyList*/)
{
}

void NodeInstanceView::resetInstanceProperty(const AbstractProperty &property)
{
    if (hasInstanceForNode(property.parentModelNode())) { // TODO ugly workaround
        NodeInstance instance = instanceForNode(property.parentModelNode());
        Q_ASSERT(instance.isValid());
        const QString name = property.name();
        if (activeStateInstance().isValid() && !property.parentModelNode().metaInfo().isSubclassOf("PropertyChange", 4, 7)) {
            bool statePropertyWasReseted = activeStateInstance().resetStateProperty(instance, name, instance.resetVariant(name));
            if (!statePropertyWasReseted)
                instance.resetProperty(name);
        } else {
            instance.resetProperty(name);
        }
    }
}

void NodeInstanceView::setInstancePropertyBinding(const BindingProperty &property)
{
    NodeInstance instance = instanceForNode(property.parentModelNode());

    const QString name = property.name();
    const QString expression = property.expression();


    if (activeStateInstance().isValid() && !property.parentModelNode().metaInfo().isSubclassOf("PropertyChange", 4, 7)) {
        bool stateBindingWasUpdated = activeStateInstance().updateStateBinding(instance, name, expression);
        if (!stateBindingWasUpdated) {
            if (property.isDynamic())
                instance.setPropertyDynamicBinding(name, property.dynamicTypeName(), expression);
            else
                instance.setPropertyBinding(name, expression);
        }
    } else {
        if (property.isDynamic())
            instance.setPropertyDynamicBinding(name, property.dynamicTypeName(), expression);
        else
            instance.setPropertyBinding(name, expression);
    }


    if (property.parentModelNode().isRootNode()
        && (name == "width" || name == "height")) {
        QGraphicsObject *rootGraphicsObject = qobject_cast<QGraphicsObject*>(instance.internalObject());
        if (rootGraphicsObject) {
            m_graphicsView->setSceneRect(rootGraphicsObject->boundingRect());
        }
    }

    instance.paintUpdate();

}

void NodeInstanceView::setInstancePropertyVariant(const VariantProperty &property)
{
    NodeInstance instance = instanceForNode(property.parentModelNode());

    const QString name = property.name();
    const QVariant value = property.value();


    if (activeStateInstance().isValid() && !property.parentModelNode().metaInfo().isSubclassOf("PropertyChange", 4, 7)) {
        bool stateValueWasUpdated = activeStateInstance().updateStateVariant(instance, name, value);
        if (!stateValueWasUpdated) {
            if (property.isDynamic())
                instance.setPropertyDynamicVariant(name, property.dynamicTypeName(), value);
            else
                instance.setPropertyVariant(name, value);
        }
    } else { //base state
        if (property.isDynamic())
            instance.setPropertyDynamicVariant(name, property.dynamicTypeName(), value);
        else
            instance.setPropertyVariant(name, value);
    }


    if (property.parentModelNode().isRootNode()
        && (name == "width" || name == "height")) {
        QGraphicsObject *rootGraphicsObject = qobject_cast<QGraphicsObject*>(instance.internalObject());
        if (rootGraphicsObject) {
            m_graphicsView->setSceneRect(rootGraphicsObject->boundingRect());
        }
    }

    instance.paintUpdate();
}

void NodeInstanceView::removeInstanceAndSubInstances(const ModelNode &node)
{
    foreach(const ModelNode &subNode, node.allSubModelNodes()) {
        if (hasInstanceForNode(subNode))
            removeInstanceNodeRelationship(subNode);
    }

    if (hasInstanceForNode(node))
        removeInstanceNodeRelationship(node);
}

void NodeInstanceView::rootNodeTypeChanged(const QString &/*type*/, int /*majorVersion*/, int /*minorVersion*/)
{
    removeAllInstanceNodeRelationships();

    QList<ModelNode> nodeList;

    nodeList.append(allModelNodes());

    loadNodes(nodeList);
}

void NodeInstanceView::bindingPropertiesChanged(const QList<BindingProperty>& propertyList, PropertyChangeFlags /*propertyChange*/)
{
    foreach (const BindingProperty &property, propertyList)
        setInstancePropertyBinding(property);
}

/*! \brief Notifing the view that a AbstractProperty value was changed to a ModelNode.

  The property will be set for the NodeInstance.

\param state ModelNode to which the Property belongs
\param property AbstractProperty which was changed
\param newValue New Value of the property
\param oldValue Old Value of the property
\see AbstractProperty NodeInstance ModelNode
*/

void NodeInstanceView::variantPropertiesChanged(const QList<VariantProperty>& propertyList, PropertyChangeFlags /*propertyChange*/)
{
    foreach (const VariantProperty &property, propertyList)
        setInstancePropertyVariant(property);
}
/*! \brief Notifing the view that a ModelNode has a new Parent.

  Note that also the ModelNode::childNodes() list was changed. The
  NodeInstance tree will be changed to reflect the ModelNode tree change.

\param node ModelNode which parent was changed.
\param oldParent Old parent of the node.
\param newParent New parent of the node.

\see NodeInstance ModelNode
*/

void NodeInstanceView::nodeReparented(const ModelNode &node, const NodeAbstractProperty &newPropertyParent, const NodeAbstractProperty &oldPropertyParent, AbstractView::PropertyChangeFlags /*propertyChange*/)
{
    NodeInstance nodeInstance(instanceForNode(node));
    NodeInstance oldParentInstance;
    if (hasInstanceForNode(oldPropertyParent.parentModelNode()))
        oldParentInstance = instanceForNode(oldPropertyParent.parentModelNode());
    NodeInstance newParentInstance;
    if (hasInstanceForNode(newPropertyParent.parentModelNode()))
        newParentInstance = instanceForNode(newPropertyParent.parentModelNode());
    nodeInstance.reparent(oldParentInstance, oldPropertyParent.name(), newParentInstance, newPropertyParent.name());
}

void NodeInstanceView::fileUrlChanged(const QUrl &/*oldUrl*/, const QUrl &/*newUrl*/)
{
    // TODO: We have to probably reload everything, so that images etc are updated!!!
    engine()->setBaseUrl(model()->fileUrl());
}

void NodeInstanceView::nodeIdChanged(const ModelNode& node, const QString& newId, const QString& /*oldId*/)
{
    if (hasInstanceForNode(node)) {
        NodeInstance instance = instanceForNode(node);

        instance.setId(newId);
    }
}

void NodeInstanceView::nodeOrderChanged(const NodeListProperty & listProperty,
                                        const ModelNode & /*movedNode*/, int /*oldIndex*/)
{
    foreach(const ModelNode &node, listProperty.toModelNodeList()) {
        NodeInstance instance = instanceForNode(node);
        if (instance.isValid())
            instance.reparent(instance.parent(), listProperty.name(), instance.parent(), listProperty.name());
    }
}

/*! \brief Notifing the view that the selection has been changed.

  Do nothing.

\param selectedNodeList List of ModelNode which has been selected
\param lastSelectedNodeList List of ModelNode which was selected

\see ModelNode NodeInstance
*/
void NodeInstanceView::selectedNodesChanged(const QList<ModelNode> &/*selectedNodeList*/,
                                              const QList<ModelNode> &/*lastSelectedNodeList*/)
{
}

void NodeInstanceView::scriptFunctionsChanged(const ModelNode &/*node*/, const QStringList &/*scriptFunctionList*/)
{

}

void NodeInstanceView::instancePropertyChange(const QList<QPair<ModelNode, QString> > &/*propertyList*/)
{

}


//\}


void NodeInstanceView::loadNodes(const QList<ModelNode> &nodeList)
{
    foreach (const ModelNode &node, nodeList)
        loadNode(node);

    foreach (const ModelNode &node, nodeList) {
        if (node.hasParentProperty())
            instanceForNode(node).reparent(NodeInstance(), QString(), instanceForNode(node.parentProperty().parentModelNode()), node.parentProperty().name());
    }

    foreach (const ModelNode &node, nodeList) {
        foreach (const BindingProperty &property, node.bindingProperties())
            instanceForNode(node).setPropertyBinding(property.name(), property.expression());
    }

    QListIterator<ModelNode> listIterator(nodeList);
    listIterator.toBack();

    while (listIterator.hasPrevious())
        instanceForNode(listIterator.previous()).doComponentComplete();
}

// TODO: Set base state as current model state
void NodeInstanceView::loadModel(Model *model)
{
    removeAllInstanceNodeRelationships();

    engine()->rootContext()->setBaseUrl(model->fileUrl());

    loadNodes(allModelNodes());
}

void NodeInstanceView::removeAllInstanceNodeRelationships()
{
    // prevent destroyed() signals calling back

    foreach (NodeInstance instance, m_objectInstanceHash.values()) {
        if (instance.isValid())
            instance.setId(QString());
    }

    //first  the root object
    if (rootNodeInstance().internalObject())
        rootNodeInstance().internalObject()->disconnect();

    rootNodeInstance().makeInvalid();


    foreach (NodeInstance instance, m_objectInstanceHash.values()) {
        if (instance.internalObject())
            instance.internalObject()->disconnect();
        instance.makeInvalid();
    }

    m_nodeInstanceHash.clear();
    m_objectInstanceHash.clear();
}

/*! \brief Returns a List of all NodeInstances

\see NodeInstance
*/

QList<NodeInstance> NodeInstanceView::instances() const
{
    return m_nodeInstanceHash.values();
}

/*! \brief Returns the NodeInstance for this ModelNode

  Returns a invalid NodeInstance if no NodeInstance for this ModelNode exists.

\param node ModelNode must be valid.
\returns  NodeStance for ModelNode.
\see NodeInstance
*/
NodeInstance NodeInstanceView::instanceForNode(const ModelNode &node)
{
    Q_ASSERT(node.isValid());
    Q_ASSERT(m_nodeInstanceHash.contains(node));
    Q_ASSERT(m_nodeInstanceHash.value(node).modelNode() == node);
    return m_nodeInstanceHash.value(node);
}

bool NodeInstanceView::hasInstanceForNode(const ModelNode &node)
{
    return m_nodeInstanceHash.contains(node);
}

NodeInstance NodeInstanceView::instanceForObject(QObject *object)
{
    if (object == 0)
        return NodeInstance();

    return m_objectInstanceHash.value(object);
}

bool NodeInstanceView::hasInstanceForObject(QObject *object)
{
    if (object == 0)
        return false;

    return m_objectInstanceHash.contains(object);
}


/*! \brief Returns the root NodeInstance of this view.


\returns  Root NodeIntance for this view.
\see NodeInstance
*/
NodeInstance NodeInstanceView::rootNodeInstance() const
{
    return m_rootNodeInstance;
}

/*! \brief Returns the view NodeInstance of this view.

  This can be the root NodeInstance if it is specified in the qml file.
\code
    QGraphicsView {
         QGraphicsScene {
             Item {}
         }
    }
\endcode

    If there is node view in the qml file:
 \code

    Item {}

\endcode
    Than there will be a new NodeInstance for this QGraphicsView
    generated which is not the root instance of this NodeInstanceView.

    This is the way to get this QGraphicsView NodeInstance.

\returns  Root NodeIntance for this view.
\see NodeInstance
*/



void NodeInstanceView::insertInstanceNodeRelationship(const ModelNode &node, const NodeInstance &instance)
{
    instance.internalObject()->installEventFilter(childrenChangeEventFilter());


    Q_ASSERT(!m_nodeInstanceHash.contains(node));
    m_nodeInstanceHash.insert(node, instance);
    m_objectInstanceHash.insert(instance.internalObject(), instance);
}

QDeclarativeEngine *NodeInstanceView::engine()
{
    if (m_engine.isNull())
        m_engine = new QDeclarativeEngine(this);
    return m_engine.data();
}

Internal::ChildrenChangeEventFilter *NodeInstanceView::childrenChangeEventFilter()
{
    if (m_childrenChangeEventFilter.isNull()) {
        m_childrenChangeEventFilter = new Internal::ChildrenChangeEventFilter(this);
        connect(m_childrenChangeEventFilter.data(), SIGNAL(childrenChanged(QObject*)), this, SLOT(emitParentChanged(QObject*)));
    }

    return m_childrenChangeEventFilter.data();
}

void NodeInstanceView::removeInstanceNodeRelationship(const ModelNode &node)
{
    Q_ASSERT(m_nodeInstanceHash.contains(node));
    NodeInstance instance = instanceForNode(node);
    if (instance.isValid())
        instance.setId(QString());
    m_objectInstanceHash.remove(instanceForNode(node).internalObject());
    m_nodeInstanceHash.remove(node);
    instance.makeInvalid();
}

void NodeInstanceView::notifyPropertyChange(const ModelNode &node, const QString &propertyName)
{
    if (m_blockStatePropertyChanges)
        return;
    if (!node.isValid())
        return;

    emitInstancePropertyChange(QList<QPair<ModelNode, QString> >() << qMakePair(node, propertyName));
}


void NodeInstanceView::setBlockStatePropertyChanges(bool block)
{
    m_blockStatePropertyChanges = block;
}

void NodeInstanceView::setStateInstance(const NodeInstance &stateInstance)
{
    m_activeStateInstance = stateInstance;
}

void NodeInstanceView::clearStateInstance()
{
    m_activeStateInstance = NodeInstance();
}

NodeInstance NodeInstanceView::activeStateInstance() const
{
    return m_activeStateInstance;
}

void NodeInstanceView::emitParentChanged(QObject *child)
{
    if (hasInstanceForObject(child)) {
        notifyPropertyChange(instanceForObject(child).modelNode(), "parent");
    }
}

NodeInstance NodeInstanceView::loadNode(const ModelNode &node, QObject *objectToBeWrapped)
{
    NodeInstance instance(NodeInstance::create(this, node, objectToBeWrapped));

    insertInstanceNodeRelationship(node, instance);

    if (node.isRootNode()) {
        m_rootNodeInstance = instance;
        QGraphicsObject *rootGraphicsObject = qobject_cast<QGraphicsObject*>(instance.internalObject());
        if (rootGraphicsObject) {
            m_graphicsView->scene()->addItem(rootGraphicsObject);
            m_graphicsView->setSceneRect(rootGraphicsObject->boundingRect());
        }
    }

    return instance;
}

void NodeInstanceView::activateState(const NodeInstance &instance)
{
    activateBaseState();
    NodeInstance stateInstance(instance);
    stateInstance.activateState();
}

void NodeInstanceView::activateBaseState()
{
    if (activeStateInstance().isValid())
        activeStateInstance().deactivateState();
}

void NodeInstanceView::removeRecursiveChildRelationship(const ModelNode &removedNode)
{
    if (hasInstanceForNode(removedNode)) {
        instanceForNode(removedNode).setId(QString());
    }

    foreach (const ModelNode &childNode, removedNode.allDirectSubModelNodes())
        removeRecursiveChildRelationship(childNode);

    removeInstanceNodeRelationship(removedNode);
}

void NodeInstanceView::render(QPainter * painter, const QRectF &target, const QRectF &source, Qt::AspectRatioMode aspectRatioMode)
{
    if (m_graphicsView) {
        painter->save();
        painter->setRenderHint(QPainter::Antialiasing, true);
        painter->setRenderHint(QPainter::TextAntialiasing, true);
        painter->setRenderHint(QPainter::SmoothPixmapTransform, true);
        painter->setRenderHint(QPainter::HighQualityAntialiasing, true);
        painter->setRenderHint(QPainter::NonCosmeticDefaultPen, true);
        m_graphicsView->scene()->render(painter, target, source, aspectRatioMode);
        painter->restore();
    }
}


QRectF NodeInstanceView::sceneRect() const
{
    if (m_graphicsView)
       return rootNodeInstance().boundingRect();

    return QRectF();
}


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);
            }
        }
    }
}

}