qmlpropertychangesnodeinstance.cpp 24.3 KB
Newer Older
1
2
3
4
/**************************************************************************
**
** This file is part of Qt Creator
**
hjk's avatar
hjk committed
5
** Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
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
**
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** Commercial Usage
**
** Licensees holding valid Qt Commercial licenses may use this file in
** accordance with the Qt Commercial License Agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Nokia.
**
** 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.
**
** If you are unsure which license is appropriate for your use, please
** contact the sales department at http://qt.nokia.com/contact.
**
**************************************************************************/

#include "qmlpropertychangesnodeinstance.h"
#include "qmlstatenodeinstance.h"
32
33
34
35
#include <QDeclarativeEngine>
#include <QDeclarativeContext>
#include <QDeclarativeExpression>
#include <private/qdeclarativebinding_p.h>
36
#include <metainfo.h>
37
38
39
40
41
#include <QMutableListIterator>

#include <private/qdeclarativestate_p_p.h>
#include <private/qdeclarativestategroup_p.h>
#include <private/qdeclarativeproperty_p.h>
42
43
44
45
46

namespace QmlDesigner {
namespace Internal {

QmlPropertyChangesObject::QmlPropertyChangesObject() :
47
        QDeclarativeStateOperation(),
48
49
50
51
52
        m_restoreEntryValues(true),
        m_isExplicit(false)
{
}

53
QDeclarativeStateOperation::ActionList QmlPropertyChangesObject::actions()
54
{
55
56
57
58
59
60
61
62
    QMutableListIterator<QDeclarativeAction> actionIterator(m_qmlActionList);

    while (actionIterator.hasNext()) {
        QDeclarativeAction &action = actionIterator.next();
        action.fromBinding = QDeclarativePropertyPrivate::binding(action.property);
        action.fromValue = action.property.read();
        if (m_expressionHash.contains(action.specifiedProperty)) {
            if(m_expressionHash[action.specifiedProperty].second.isNull()) {
63
64
65
66
67
68
69
70
71
72
                if (targetObject()) {
                    QDeclarativeBinding *binding = new QDeclarativeBinding(m_expressionHash[action.specifiedProperty].first, targetObject(), QDeclarativeEngine::contextForObject(targetObject()), this);
                    binding->setTarget(action.property);
                    binding->setNotifyOnValueChanged(true);
                    action.toBinding = binding;
                    action.toValue = binding->evaluate();
                    m_expressionHash.insert(action.specifiedProperty, ExpressionPair(m_expressionHash[action.specifiedProperty].first, binding));
                } else {
                    action.toBinding = 0;
                }
73
74
            } else {
                action.toBinding = m_expressionHash[action.specifiedProperty].second.data();
75
                action.toValue = m_expressionHash[action.specifiedProperty].second->evaluate();
76
77
78
79
80
            }
        } else {
            action.toBinding = 0;
        }
    }
81

82
83
    return m_qmlActionList;
}
84

85
86
87
88
QObject *QmlPropertyChangesObject::targetObject() const
{
    return m_targetObject.data();
}
89

90
91
void QmlPropertyChangesObject::setTargetObject(QObject *object)
{
92
93
94
    if (m_targetObject.data() == object)
        return;

95
96
97
98
99
100
101
    QMutableListIterator<QDeclarativeAction> actionIterator(m_qmlActionList);
    while (actionIterator.hasNext()) {
         QDeclarativeAction &qmlAction = actionIterator.next();
         if (m_expressionHash.contains(qmlAction.specifiedProperty) && m_expressionHash[qmlAction.specifiedProperty].second) {
             if (isActive()) {
                 QDeclarativePropertyPrivate::setBinding(qmlAction.property, 0, QDeclarativePropertyPrivate::DontRemoveBinding| QDeclarativePropertyPrivate::BypassInterceptor);
                 qmlAction.property.write(qmlAction.fromValue);
102
                 m_expressionHash[qmlAction.specifiedProperty].second.data()->destroy();
103
104
             }

105

106
107
108
109
110
111
112
113
             qmlAction.toBinding = 0;
         }

         if (isActive() && targetObject()) {
             updateRevertValueAndBinding(qmlAction.specifiedProperty);
         }
    }

114
115
    m_targetObject = object;

116
    actionIterator.toFront();
117
118
119
120
121
122
    while (actionIterator.hasNext()) {
        QDeclarativeAction &qmlAction = actionIterator.next();
        qmlAction.specifiedObject = object;
        qmlAction.property = createMetaProperty(qmlAction.specifiedProperty);
        qmlAction.fromValue = qmlAction.property.read();
        qmlAction.fromBinding = QDeclarativePropertyPrivate::binding(qmlAction.property);
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137

        if (m_expressionHash.contains(qmlAction.specifiedProperty) && targetObject()) {
            QDeclarativeBinding *binding = new QDeclarativeBinding(m_expressionHash[qmlAction.specifiedProperty].first ,targetObject(), QDeclarativeEngine::contextForObject(targetObject()));
            binding->setTarget(qmlAction.property);
            binding->setNotifyOnValueChanged(true);
            qmlAction.toBinding = binding;
            m_expressionHash.insert(qmlAction.specifiedProperty, ExpressionPair(m_expressionHash[qmlAction.specifiedProperty].first, binding));
            if (isActive()) {
                QDeclarativePropertyPrivate::setBinding(qmlAction.property, qmlAction.toBinding, QDeclarativePropertyPrivate::DontRemoveBinding| QDeclarativePropertyPrivate::BypassInterceptor);
            }
        }

        if (isActive() && targetObject()) {
            updateRevertValueAndBinding(qmlAction.specifiedProperty);
        }
138
    }
139
}
140

141
142
143
144
bool QmlPropertyChangesObject::restoreEntryValues() const
{
    return m_restoreEntryValues;
}
145

146
147
148
149
void QmlPropertyChangesObject::setRestoreEntryValues(bool restore)
{
    m_restoreEntryValues = restore;
}
150

151
152
153
bool QmlPropertyChangesObject::isExplicit() const
{
    return m_isExplicit;
154
155
}

156
157
158
159
160
161
void QmlPropertyChangesObject::setIsExplicit(bool isExplicit)
{
    m_isExplicit = isExplicit;
}

QDeclarativeProperty QmlPropertyChangesObject::createMetaProperty(const QString &property)
162
{
163
    QDeclarativeProperty prop(m_targetObject.data(), property, QDeclarativeEngine::contextForObject(m_targetObject.data()));
164
    if (!prop.isValid()) {
Tobias Hunger's avatar
Tobias Hunger committed
165
        qWarning() << "Cannot assign to non-existent property" << property;
166
        return QDeclarativeProperty();
167
168
    } else if (!prop.isWritable()) {
        qWarning() << "Cannot assign to read-only property" << property;
169
        return QDeclarativeProperty();
170
171
172
173
174
175
176
177
178
179
180
    }
    return prop;
}

QmlPropertyChangesNodeInstance::QmlPropertyChangesNodeInstance(QmlPropertyChangesObject *propertyChangesObject) :
        ObjectNodeInstance(propertyChangesObject)
{
}

QmlPropertyChangesNodeInstance::Pointer
        QmlPropertyChangesNodeInstance::create(const NodeMetaInfo & /*metaInfo*/,
181
                                               QDeclarativeContext *context,
182
183
184
185
186
                                               QObject *objectToBeWrapped)
{
    Q_ASSERT(!objectToBeWrapped);

    QmlPropertyChangesObject *object = new QmlPropertyChangesObject;
187
    QDeclarativeEngine::setContextForObject(object, context);
188
189
190
191
192
193
    Pointer instance(new QmlPropertyChangesNodeInstance(object));
    return instance;
}

void QmlPropertyChangesNodeInstance::setPropertyVariant(const QString &name, const QVariant &value)
{
194
195
196
    QMetaObject metaObject = QmlPropertyChangesObject::staticMetaObject;

    if (metaObject.indexOfProperty(name.toLatin1()) > 0) { // 'restoreEntryValues', 'explicit'
197
        ObjectNodeInstance::setPropertyVariant(name, value);
198
    } else {
199
200
201
202
203
204
205
        changesObject()->setVariantValue(name, value);
        QObject *targetObject = changesObject()->targetObject();
        if (targetObject && nodeInstanceView()->activeStateInstance().isWrappingThisObject(changesObject()->state())) {
            changesObject()->updateRevertValueAndBinding(name);
            NodeInstance targetInstance = nodeInstanceView()->instanceForObject(targetObject);
            targetInstance.setPropertyVariant(name, value);
        }
206
207
208
209
210
    }
}

void QmlPropertyChangesNodeInstance::setPropertyBinding(const QString &name, const QString &expression)
{
211
212
213
    QMetaObject metaObject = QmlPropertyChangesObject::staticMetaObject;

    if (metaObject.indexOfProperty(name.toLatin1()) > 0) { // 'restoreEntryValues', 'explicit'
214
        ObjectNodeInstance::setPropertyBinding(name, expression);
215
    } else {
216
        changesObject()->setExpression(name, expression);
217
218
219
220
221
    }
}

QVariant QmlPropertyChangesNodeInstance::property(const QString &name) const
{
222
223
224
225
    if (changesObject()->hasVariantValue(name))
        return changesObject()->variantValue(name);
    if (changesObject()->hasExpression(name))
        return QVariant(changesObject()->expression(name));
226
227
228
229
230
231

    return QVariant();
}

void QmlPropertyChangesNodeInstance::resetProperty(const QString &name)
{
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
    changesObject()->resetProperty(name);
}


void QmlPropertyChangesNodeInstance::reparent(const NodeInstance &oldParentInstance, const QString &oldParentProperty, const NodeInstance &newParentInstance, const QString &newParentProperty)
{
    if (oldParentProperty == "changes") {
        if (changesObject()) {
            changesObject()->removeFromStateRevertList();
        }
    }

    ObjectNodeInstance::reparent(oldParentInstance, oldParentProperty, newParentInstance, newParentProperty);

    if (newParentProperty == "changes") {
        if (changesObject()) {
            changesObject()->addToStateRevertList();
        }
    }
}

QDeclarativeState *QmlPropertyChangesObject::state() const
{
    if (!parent())
        return 0;

    Q_ASSERT(qobject_cast<QDeclarativeState*>(parent()));
    return static_cast<QDeclarativeState*>(parent());
}

QDeclarativeStateGroup *QmlPropertyChangesObject::stateGroup() const
{
    if (!state())
        return 0;

    return state()->stateGroup();
}

QDeclarativeStatePrivate *QmlPropertyChangesObject::statePrivate() const
{
272
    if (!parent() || QObjectPrivate::get(parent())->wasDeleted)
273
        return 0;
274

275
276
    Q_ASSERT(qobject_cast<QDeclarativeState*>(parent()));
    return static_cast<QDeclarativeStatePrivate*>(QObjectPrivate::get(parent()));
277
278
279
280
281
282
283
284
}

QmlPropertyChangesObject *QmlPropertyChangesNodeInstance::changesObject() const
{
    Q_ASSERT(qobject_cast<QmlPropertyChangesObject*>(object()));
    return static_cast<QmlPropertyChangesObject*>(object());
}

285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307

QDeclarativeAction QmlPropertyChangesObject::createQDeclarativeAction(const QString &propertyName)
{
    QDeclarativeProperty qmlMetaProperty = createMetaProperty(propertyName);

    QDeclarativeAction qmlAction;
    qmlAction.restore = true;
    qmlAction.property = qmlMetaProperty;
    qmlAction.fromValue = qmlMetaProperty.read();
    qmlAction.fromBinding = QDeclarativePropertyPrivate::binding(qmlMetaProperty);
    qmlAction.specifiedObject = m_targetObject.data();
    qmlAction.specifiedProperty = propertyName;
    qmlAction.event = 0;

    return qmlAction;
}

bool QmlPropertyChangesObject::hasActionForProperty(const QString &propertyName) const
{
    for(ActionList::iterator actionIterator = m_qmlActionList.begin();
        actionIterator != m_qmlActionList.end();
        ++actionIterator) {
            QDeclarativeAction &qmlAction = *actionIterator;
Marco Bubke's avatar
Marco Bubke committed
308
309
310
            if (qmlAction.specifiedProperty == propertyName) {
                return true;
            }
311
312
        }

Marco Bubke's avatar
Marco Bubke committed
313
    return false;
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
}

QDeclarativeAction &QmlPropertyChangesObject::qmlActionForProperty(const QString &propertyName) const
{
    for(ActionList::iterator actionIterator = m_qmlActionList.begin();
        actionIterator != m_qmlActionList.end();
        ++actionIterator) {
            QDeclarativeAction &qmlAction = *actionIterator;
            if (qmlAction.specifiedProperty == propertyName)
                return qmlAction;
    }

    Q_ASSERT(false);

    return m_qmlActionList[0];
}

void QmlPropertyChangesObject::removeActionForProperty(const QString &propertyName)
{
    QMutableListIterator<QDeclarativeAction> actionIterator(m_qmlActionList);
    while (actionIterator.hasNext()) {
        QDeclarativeAction &qmlAction = actionIterator.next();
        if (qmlAction.specifiedProperty == propertyName)
            actionIterator.remove();
    }

340
341
342
343
344
345
346
    if (statePrivate()) {
        QMutableListIterator<QDeclarativeSimpleAction> simpleActionIterator(statePrivate()->revertList);
        while (simpleActionIterator.hasNext()) {
            QDeclarativeSimpleAction &qmlSimpleAction = simpleActionIterator.next();
            if (qmlSimpleAction.specifiedProperty == propertyName && qmlSimpleAction.specifiedObject == targetObject()) {
                simpleActionIterator.remove();
            }
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
        }
    }
}

bool QmlPropertyChangesObject::isActive() const
{
    if (state() && stateGroup())
        return  state()->name() == stateGroup()->state();

    return false;
}
QmlPropertyChangesObject::~QmlPropertyChangesObject()
{
    removeFromStateRevertList();
}

void QmlPropertyChangesObject::removeFromStateRevertList()
{
    if (statePrivate()) {
        QMutableListIterator<QDeclarativeSimpleAction> simpleActionIterator(statePrivate()->revertList);
        while(simpleActionIterator.hasNext()) {
            QDeclarativeSimpleAction &simpleAction = simpleActionIterator.next();
            if (simpleAction.specifiedObject == targetObject()) {
370
371
372
373
374
375
376
                if (simpleAction.property.isValid()) {
                    if (simpleAction.binding) {
                        QDeclarativePropertyPrivate::setBinding(simpleAction.property, simpleAction.binding);
                    } else if (simpleAction.value.isValid()) {
                        QDeclarativePropertyPrivate::setBinding(simpleAction.property, 0);
                        simpleAction.property.write(simpleAction.value);
                    }
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
                }
                simpleActionIterator.remove();
            }
        }
    }
}

void QmlPropertyChangesObject::addToStateRevertList()
{
    if (isActive() && statePrivate()) {
        QListIterator<QDeclarativeAction> actionIterator(m_qmlActionList);
        while (actionIterator.hasNext()) {
            const QDeclarativeAction &qmlAction = actionIterator.next();
            QDeclarativeSimpleAction simpleAction(qmlAction);
            simpleAction.binding = qmlAction.fromBinding;
            simpleAction.value = qmlAction.fromValue;
            statePrivate()->revertList.append(simpleAction);
            if (qmlAction.toBinding)
                QDeclarativePropertyPrivate::setBinding(qmlAction.property, qmlAction.toBinding);
            else
                qmlAction.property.write(qmlAction.toValue);
        }
    }
}

void QmlPropertyChangesObject::updateRevertValueAndBinding(const QString &name)
403
{
404
405
406
407
408
409
410
411
412
413
414
415
416
    if (isActive() && statePrivate()) {
        typedef QList<QDeclarativeSimpleAction> SimpleActionList;
        if (!statePrivate()->revertList.isEmpty()) {
            for(SimpleActionList::iterator actionIterator = statePrivate()->revertList.begin();
            actionIterator != statePrivate()->revertList.end();
            ++actionIterator) {
                //simple action defines values and bindings to revert current state
                QDeclarativeSimpleAction &simpleAction = *actionIterator;
                if (simpleAction.specifiedObject == targetObject()
                    && simpleAction.specifiedProperty == name) {
                    const QDeclarativeAction &qmlAction = qmlActionForProperty(name);
                    simpleAction.value = qmlAction.fromValue;
                    simpleAction.binding = qmlAction.fromBinding;
417
418
419
                    simpleAction.specifiedObject = qmlAction.specifiedObject;
                    simpleAction.specifiedProperty = qmlAction.specifiedProperty;
                    simpleAction.property = qmlAction.property;
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
                    return; //return since we just had to update exisisting simple action
                }
            }
        }

        //simple action does not exist, yet

        const QDeclarativeAction &qmlAction = qmlActionForProperty(name);
        QDeclarativeSimpleAction simpleAction(qmlAction);
        simpleAction.binding = qmlAction.fromBinding;
        simpleAction.value = qmlAction.fromValue;
        statePrivate()->revertList.append(simpleAction);
    }
}

void QmlPropertyChangesObject::setVariantValue(const QString &name, const QVariant & value)
{
    if (!hasActionForProperty(name)) {
        m_qmlActionList.append(createQDeclarativeAction(name));
    }

    QDeclarativeAction &qmlAction = qmlActionForProperty(name);
442
443
444
    if (qmlAction.fromBinding)
        qmlAction.fromBinding->setEnabled(false, QDeclarativePropertyPrivate::BypassInterceptor | QDeclarativePropertyPrivate::DontRemoveBinding);

445
446
447
448
449
450
451
452
453
    qmlAction.toValue = value;
}

void QmlPropertyChangesObject::setExpression(const QString &name, const QString &expression)
{
    if (!hasActionForProperty(name)) {
        m_qmlActionList.append(createQDeclarativeAction(name));
    }

454
455
456
457
    QDeclarativeContext *context = QDeclarativeEngine::contextForObject(targetObject());
    QDeclarativeBinding *binding = 0;
    QDeclarativeProperty metaProperty(targetObject(), name, context);

458
459
    QDeclarativeAction &qmlAction = qmlActionForProperty(name);
    if (m_expressionHash.contains(name) && m_expressionHash[name].second) {
460
461
462
        if (QDeclarativePropertyPrivate::binding(metaProperty) == m_expressionHash[name].second.data())
            QDeclarativePropertyPrivate::setBinding(metaProperty, 0,  QDeclarativePropertyPrivate::BypassInterceptor | QDeclarativePropertyPrivate::DontRemoveBinding);
        m_expressionHash.take(name).second->destroy();
463
        qmlAction.toBinding = 0;
464
465
    }

466

467
468
469
470
471
472
473
    if (metaProperty.isValid() && metaProperty.isProperty()) {
        binding = new QDeclarativeBinding(expression, targetObject(), context, this);
        binding->setTarget(metaProperty);
        binding->setNotifyOnValueChanged(true);
        qmlAction.toBinding = binding;
        m_expressionHash.insert(name, ExpressionPair(expression, binding));
    } else {
474
         m_expressionHash.insert(name, ExpressionPair(expression, static_cast<QDeclarativeBinding*>(0)));
475
476
477
    }

    updateRevertValueAndBinding(name);
478
    if (isActive() && binding)
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
        QDeclarativePropertyPrivate::setBinding(metaProperty, binding,  QDeclarativePropertyPrivate::BypassInterceptor | QDeclarativePropertyPrivate::DontRemoveBinding);
}

void QmlPropertyChangesObject::removeVariantValue(const QString &name)
{
    if (hasActionForProperty(name)) {
        QDeclarativeAction &qmlAction = qmlActionForProperty(name);
        if (hasExpression(name)) {
            qmlAction.toValue = QVariant();
            updateRevertValueAndBinding(name);
        } else {
            if (qmlAction.fromBinding)
                QDeclarativePropertyPrivate::setBinding(qmlAction.property, qmlAction.fromBinding);
            else
                qmlAction.property.write(qmlAction.fromValue);
            removeActionForProperty(name);
        }
    }
}

void QmlPropertyChangesObject::removeExpression(const QString &name)
{
    if (hasActionForProperty(name)) {
        QDeclarativeAction &qmlAction = qmlActionForProperty(name);
        if (hasVariantValue(name)) {
            ExpressionPair expr = m_expressionHash.take(name);
            if (expr.second)
                expr.second.data()->destroy();
            qmlAction.toBinding = 0;
            updateRevertValueAndBinding(name);
            qmlAction.property.write(qmlAction.toValue);
        } else {
            if (qmlAction.fromBinding)
                QDeclarativePropertyPrivate::setBinding(qmlAction.property, qmlAction.fromBinding);
            else
                qmlAction.property.write(qmlAction.fromValue);
            removeActionForProperty(name);
        }
    }
}

void QmlPropertyChangesObject::resetProperty(const QString &name)
{
    if (statePrivate()) {
        QMutableListIterator<QDeclarativeSimpleAction> simpleActionIterator(statePrivate()->revertList);
        while (simpleActionIterator.hasNext()) {
            QDeclarativeSimpleAction &qmlSimpleAction = simpleActionIterator.next();
            if (qmlSimpleAction.specifiedProperty == name && qmlSimpleAction.specifiedObject == targetObject()) {
                if (qmlSimpleAction.binding) {
                    qDebug() << qmlSimpleAction.binding->expression();
                    QDeclarativePropertyPrivate::setBinding(qmlSimpleAction.property, qmlSimpleAction.binding);
                } else {
                    QDeclarativePropertyPrivate::setBinding(qmlSimpleAction.property, 0);
                    qmlSimpleAction.property.write(qmlSimpleAction.value);
                }
            }
        }
    }

    if (m_expressionHash.contains(name)) {
539
540
541
542
        if (m_expressionHash[name].second) {
            QDeclarativeProperty metaProperty(targetObject(), name, QDeclarativeEngine::contextForObject(targetObject()));
            if (metaProperty.isValid() && QDeclarativePropertyPrivate::binding(metaProperty) == m_expressionHash[name].second.data())
                QDeclarativePropertyPrivate::setBinding(metaProperty, 0,  QDeclarativePropertyPrivate::BypassInterceptor | QDeclarativePropertyPrivate::DontRemoveBinding);
543
            m_expressionHash[name].second.data()->destroy();
544
        }
545
546
547
548
549
550
551
552
553
        m_expressionHash.remove(name);
    }

    if (hasActionForProperty(name)) {
        removeActionForProperty(name);
    }


}
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
QVariant QmlPropertyChangesObject::variantValue(const QString &name) const
{
    if (hasActionForProperty(name)) {
        QDeclarativeAction &qmlAction = qmlActionForProperty(name);
        return qmlAction.toValue;
    }

    return QVariant();
}

QString QmlPropertyChangesObject::expression(const QString &name) const
{
    if (hasActionForProperty(name)) {
        QDeclarativeAction &qmlAction = qmlActionForProperty(name);
        if (qmlAction.toBinding)
            return qmlAction.toBinding->expression();
    }

    return QString();
}

bool QmlPropertyChangesObject::hasVariantValue(const QString &name) const
{
    if (hasActionForProperty(name))
        return qmlActionForProperty(name).toValue.isValid();

    return false;
}

bool QmlPropertyChangesObject::hasExpression(const QString &name) const
{
    return m_expressionHash.contains(name);
}

bool QmlPropertyChangesObject::updateStateVariant(const QString &name, const QVariant &value)
{
    if (hasActionForProperty(name)) {
        QDeclarativeAction &qmlAction = qmlActionForProperty(name);
        if (qmlAction.fromValue.isValid()) {
            qmlAction.fromValue = value;
            updateRevertValueAndBinding(name);

            return true;
        }
    }
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
    return false;
}

bool QmlPropertyChangesObject::updateStateBinding(const QString &name, const QString &expression)
{
    if (hasActionForProperty(name)) {
        QDeclarativeContext *context = QDeclarativeEngine::contextForObject(targetObject());
        QDeclarativeProperty metaProperty(targetObject(), name, context);
        QDeclarativeAction &qmlAction = qmlActionForProperty(name);

        if (qmlAction.fromBinding) {
            if (QDeclarativePropertyPrivate::binding(qmlAction.property) == qmlAction.fromBinding)
                QDeclarativePropertyPrivate::setBinding(qmlAction.property, 0);
            qmlAction.fromBinding->destroy();

        }

        QDeclarativeBinding *binding = new QDeclarativeBinding(expression, targetObject(), context, this);
        binding->setTarget(metaProperty);
        binding->setNotifyOnValueChanged(true);
        qmlAction.fromBinding = binding;

        if (m_expressionHash.contains(name))
            QDeclarativePropertyPrivate::setBinding(qmlAction.property, binding);

        updateRevertValueAndBinding(name);

        return true;
    }

    return false;
}

bool QmlPropertyChangesObject::resetStateProperty(const QString &name, const QVariant &resetValue)
{
    if (hasActionForProperty(name)) {
        QDeclarativeContext *context = QDeclarativeEngine::contextForObject(targetObject());
        QDeclarativeProperty metaProperty(targetObject(), name, context);
        QDeclarativeAction &qmlAction = qmlActionForProperty(name);
        if (m_expressionHash.contains(name) && m_expressionHash[name].second) {
            m_expressionHash[name].second.data()->destroy();
            qmlAction.toBinding = 0;
        }

        qmlAction.fromValue = resetValue;

        updateRevertValueAndBinding(name);

        removeActionForProperty(name);

        return true;
    }
653

654
    return false;
655
656
657
658
}

} // namespace Internal
} // namespace QmlDesigner