~ubuntu-sdk-team/ubuntu-ui-toolkit/trunk

« back to all changes in this revision

Viewing changes to src/Ubuntu/Components/plugin/ucpagetreenode.cpp

  • Committer: CI Train Bot
  • Author(s): Christian Dywan, Zsombor Egri, Zoltán Balogh, Tim Peeters, Albert Astals Cid, Michael Sheldon, Benjamin Zeller
  • Date: 2015-12-17 17:13:49 UTC
  • mfrom: (1000.739.27 OTA9-landing-2015-12-16)
  • Revision ID: ci-train-bot@canonical.com-20151217171349-8xwclnhnx8v9oz4m
OTA9-landing-2015-12-16
Approved by: Zoltan Balogh

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright 2015 Canonical Ltd.
 
3
 *
 
4
 * This program is free software; you can redistribute it and/or modify
 
5
 * it under the terms of the GNU Lesser General Public License as published by
 
6
 * the Free Software Foundation; version 3.
 
7
 *
 
8
 * This program is distributed in the hope that it will be useful,
 
9
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
10
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
11
 * GNU Lesser General Public License for more details.
 
12
 *
 
13
 * You should have received a copy of the GNU Lesser General Public License
 
14
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
15
 */
 
16
 
 
17
#include "ucpagetreenode.h"
 
18
#include "ucpagetreenode_p.h"
 
19
 
 
20
#include <QQmlEngine>
 
21
 
 
22
Q_LOGGING_CATEGORY(ucPageTreeNode, "ubuntu.components.PageTreeNode", QtMsgType::QtWarningMsg)
 
23
 
 
24
#define PT_TRACE(params) qCDebug(ucPageTreeNode).noquote().nospace()<< params
 
25
 
 
26
UCPageTreeNodePrivate::UCPageTreeNodePrivate()
 
27
    : m_parentNode(nullptr),
 
28
      m_activeLeafNode(nullptr),
 
29
      m_pageStack(nullptr),
 
30
      m_propagated(nullptr),
 
31
      m_toolbar(nullptr),
 
32
      m_flags(0),
 
33
      m_isLeaf(false),
 
34
      m_active(false)
 
35
 
 
36
{}
 
37
 
 
38
/*!
 
39
 * \internal
 
40
 * \brief UCPageTreeNodePrivate::init
 
41
 * Initialize the UCPageTreeNode and setup the bindings
 
42
 */
 
43
void UCPageTreeNodePrivate::init()
 
44
{
 
45
    Q_Q(UCPageTreeNode);
 
46
    q->setActiveFocusOnPress(true);
 
47
 
 
48
    auto slotUpdateParentLeafNode = [this] () {
 
49
        updateParentLeafNode();
 
50
    };
 
51
 
 
52
    //connect all signals that are required to keep the "activeLeafNode" in the
 
53
    //parents valid. The activeLeadNode property in the parent is set if the current
 
54
    //PTN is a leaf itself (isLeaf = true) or one of its children is a leaf
 
55
    QObject::connect(q, &UCPageTreeNode::activeChanged, slotUpdateParentLeafNode);
 
56
    QObject::connect(q, &UCPageTreeNode::activeLeafNodeChanged, slotUpdateParentLeafNode);
 
57
    QObject::connect(q, &UCPageTreeNode::parentNodeChanged, slotUpdateParentLeafNode);
 
58
 
 
59
    //make sure all bindings are in tact
 
60
    initActive();
 
61
    initPageStack();
 
62
    initPropagated();
 
63
}
 
64
 
 
65
/*!
 
66
 * \internal
 
67
 * \brief UCPageTreeNodePrivate::initActive
 
68
 * Initialize active property and setup the propagating binding.
 
69
 * By default the parents active property is propagated to the children.
 
70
 */
 
71
void UCPageTreeNodePrivate::initActive()
 
72
{
 
73
    Q_Q(UCPageTreeNode);
 
74
    bool intialActive = false;
 
75
    if (m_parentNode) {
 
76
        intialActive = m_parentNode->active();
 
77
        QObject::connect(m_parentNode, SIGNAL(activeChanged(bool)),
 
78
                         q, SLOT(_q_activeBinding(bool)));
 
79
    }
 
80
    _q_activeBinding(intialActive);
 
81
}
 
82
 
 
83
/*!
 
84
 * \internal
 
85
 * \brief UCPageTreeNodePrivate::initPageStack
 
86
 * Initialize pageStack property and setup the propagating binding.
 
87
 * By default the parents pageStack property is propagated to the children.
 
88
 */
 
89
void UCPageTreeNodePrivate::initPageStack()
 
90
{
 
91
    Q_Q(UCPageTreeNode);
 
92
    QQuickItem *initialPageStack = nullptr;
 
93
    if (m_parentNode) {
 
94
        initialPageStack = m_parentNode->pageStack();
 
95
        QObject::connect(m_parentNode,SIGNAL(pageStackChanged(QQuickItem*)),
 
96
                         q, SLOT(_q_pageStackBinding (QQuickItem *)));
 
97
    }
 
98
    _q_pageStackBinding(initialPageStack);
 
99
}
 
100
 
 
101
/*!
 
102
 * \internal
 
103
 * \brief UCPageTreeNodePrivate::initPropagated
 
104
 * Initialize __propagated property and setup the propagating binding.
 
105
 * By default the parents __propagated property is propagated to the children.
 
106
 */
 
107
void UCPageTreeNodePrivate::initPropagated()
 
108
{
 
109
    Q_Q(UCPageTreeNode);
 
110
    QObject *initialPropagated = nullptr;
 
111
    if (m_parentNode) {
 
112
        initialPropagated = m_parentNode->propagated();
 
113
        QObject::connect(m_parentNode,SIGNAL(propagatedChanged(QObject*)),
 
114
                         q, SLOT(_q_propagatedBinding (QObject *)));
 
115
    }
 
116
    _q_propagatedBinding(initialPropagated);
 
117
}
 
118
 
 
119
/*!
 
120
  \internal
 
121
  Find the parent node and update the parentNode property
 
122
 */
 
123
void UCPageTreeNodePrivate::updatePageTree()
 
124
{
 
125
    Q_Q(UCPageTreeNode);
 
126
    q->setParentNode(getParentPageTreeNode());
 
127
}
 
128
 
 
129
 
 
130
/*!
 
131
   \internal
 
132
   \brief UCPageTreeNodePrivate::getParentPageTreeNode
 
133
   Returns the parent node in the page tree, or null if the item is the root node or invalid.
 
134
 */
 
135
UCPageTreeNode *UCPageTreeNodePrivate::getParentPageTreeNode()
 
136
{
 
137
    Q_Q(UCPageTreeNode);
 
138
    UCPageTreeNode *node = nullptr;
 
139
 
 
140
    //search the current tree for the next parent item that
 
141
    //is a UCPageTreeNode
 
142
    QQuickItem *currItem = q->parentItem();
 
143
    while (currItem) {
 
144
        UCPageTreeNode *currPageTreeNode = qobject_cast<UCPageTreeNode *>(currItem);
 
145
        if (currPageTreeNode) {
 
146
            if (currPageTreeNode->isLeaf()) {
 
147
                // children of a leaf are not part of the tree
 
148
                node = nullptr;
 
149
            } else {
 
150
                // current node is part of the tree with currPageTreeNode as its parent.
 
151
                node = currPageTreeNode;
 
152
            }
 
153
            break;
 
154
        }
 
155
        currItem = currItem->parentItem();
 
156
    }
 
157
 
 
158
    return node;
 
159
}
 
160
 
 
161
/*!
 
162
 * \internal
 
163
 * \brief UCPageTreeNodePrivate::_q_activeBinding
 
164
 * Directly updates the activeBinding property. Is used as
 
165
 * callback to support qml style bindings that can be overriden
 
166
 */
 
167
void UCPageTreeNodePrivate::_q_activeBinding(bool active)
 
168
{
 
169
    if (m_active == active)
 
170
        return;
 
171
 
 
172
    Q_Q(UCPageTreeNode);
 
173
    m_active = active;
 
174
    Q_EMIT q->activeChanged(active);
 
175
}
 
176
 
 
177
 
 
178
/*!
 
179
 * \internal
 
180
 * \brief UCPageTreeNodePrivate::_q_pageStackBinding
 
181
 * Directly updates the pageStack property. Is used as
 
182
 * callback to support qml style bindings that can be overriden
 
183
 */
 
184
void UCPageTreeNodePrivate::_q_pageStackBinding(QQuickItem *pageStack)
 
185
{
 
186
    if (m_pageStack == pageStack)
 
187
        return;
 
188
 
 
189
    Q_Q(UCPageTreeNode);
 
190
    m_pageStack = pageStack;
 
191
    Q_EMIT q->pageStackChanged(pageStack);
 
192
}
 
193
 
 
194
 
 
195
/*!
 
196
 * \internal
 
197
 * \brief UCPageTreeNodePrivate::_q_propagatedBinding
 
198
 * Directly updates the __propagated property. Is used as
 
199
 * callback to support qml style bindings that can be overriden
 
200
 */
 
201
void UCPageTreeNodePrivate::_q_propagatedBinding(QObject *propagated)
 
202
{
 
203
    if (m_propagated == propagated)
 
204
        return;
 
205
    Q_Q(UCPageTreeNode);
 
206
    m_propagated = propagated;
 
207
    Q_EMIT q->propagatedChanged(propagated);
 
208
}
 
209
 
 
210
/*!
 
211
 * \internal
 
212
 * \brief UCPageTreeNodePrivate::updateParentLeafNode
 
213
 * Update the activeLeafNode of the parent. The activeLeadNode property
 
214
 * in the parent is set if the current PTN is a leaf itself (isLeaf = true)
 
215
 * or one of its children is a leaf
 
216
 */
 
217
void UCPageTreeNodePrivate::updateParentLeafNode()
 
218
{
 
219
    Q_Q(UCPageTreeNode);
 
220
    if (q->active() && q->parentNode()) {
 
221
        if (q->isLeaf())
 
222
            q->parentNode()->setActiveLeafNode(q);
 
223
        else
 
224
            q->parentNode()->setActiveLeafNode(q->activeLeafNode());
 
225
    }
 
226
}
 
227
 
 
228
/*!
 
229
 * \brief findPTNChild
 
230
 * Returns only the next level of UCPageTreeNode children of \l rootNode.
 
231
 * Just used for debugging output.
 
232
 */
 
233
static QList<UCPageTreeNode *> findPTNChild (QQuickItem *rootNode)
 
234
{
 
235
    QList<UCPageTreeNode *> nodes;
 
236
    UCPageTreeNode *thisNode = qobject_cast<UCPageTreeNode *>(rootNode);
 
237
    if(thisNode)
 
238
        nodes << thisNode;
 
239
    else {
 
240
        Q_FOREACH(QQuickItem *curr, rootNode->childItems()) {
 
241
            nodes.append(findPTNChild(curr));
 
242
        }
 
243
    }
 
244
    return nodes;
 
245
}
 
246
 
 
247
/*!
 
248
 * \brief collectNodes
 
249
 * Recursively collects all UCPageTreeNodes in a node tree and builds up
 
250
 * a representation of the Tree. Just used for debugging output.
 
251
 */
 
252
static QList<UCPageTreeNodePrivate::Node> collectNodes (UCPageTreeNode *root)
 
253
{
 
254
    if (!root)
 
255
        return QList<UCPageTreeNodePrivate::Node>();
 
256
 
 
257
    QList<UCPageTreeNodePrivate::Node> nodes;
 
258
 
 
259
    QList<QQuickItem *> items = root->childItems();
 
260
    Q_FOREACH(QQuickItem *item, items) {
 
261
        QList<UCPageTreeNode *>subNodes = findPTNChild(item);
 
262
 
 
263
        if (subNodes.isEmpty()) continue;
 
264
 
 
265
        Q_FOREACH(UCPageTreeNode *currPTN, subNodes) {
 
266
            UCPageTreeNodePrivate::Node n;
 
267
            n.m_node = currPTN;
 
268
            n.m_children = collectNodes(currPTN);
 
269
            nodes.append(n);
 
270
        }
 
271
    }
 
272
 
 
273
    return nodes;
 
274
}
 
275
 
 
276
/*!
 
277
 * \brief UCPageTreeNodePrivate::dumpNode
 
278
 * Pretty prints the node \l n using the \l oldDepth of the parentNode and
 
279
 * \l depth as the current Nodes prefix. The \l isRoot parameter
 
280
 * specifies if the current Node \l n is the root Node.
 
281
 */
 
282
void UCPageTreeNodePrivate::dumpNode (const Node &n, const QString &oldDepth,const QString &depth, bool isRoot)
 
283
{
 
284
    UCPageTreeNode *currNode = n.m_node;
 
285
 
 
286
    //print the current node name and info
 
287
    if (!isRoot)
 
288
        PT_TRACE(oldDepth<<"+--"<<currNode);
 
289
    else
 
290
        PT_TRACE(currNode);
 
291
 
 
292
    //print the current nodes properties we are interested in
 
293
    switch(QQmlEngine::objectOwnership(currNode)) {
 
294
        case QQmlEngine::CppOwnership:
 
295
            PT_TRACE(QString("%1|  ->ownership: ").arg(depth)<<"C++");
 
296
        break;
 
297
        case QQmlEngine::JavaScriptOwnership:
 
298
            PT_TRACE(QString("%1|  ->ownership: ").arg(depth)<<"JS");
 
299
        break;
 
300
    }
 
301
 
 
302
    PT_TRACE(QString("%1|  ->parentNode: ").arg(depth)<<currNode->parentNode());
 
303
    PT_TRACE(QString("%1|  ->parent: ").arg(depth)<<currNode->parent());
 
304
    PT_TRACE(QString("%1|  ->pageStack: ").arg(depth)<<currNode->pageStack()
 
305
                               <<" custom:"<<((currNode->d_func()->m_flags & UCPageTreeNodePrivate::CustomPageStack) ? true : false));
 
306
    PT_TRACE(QString("%1|  ->propagated: ").arg(depth)<<currNode->propagated()
 
307
                               <<" custom:"<<((currNode->d_func()->m_flags & UCPageTreeNodePrivate::CustomPropagated) ? true : false));
 
308
    PT_TRACE(QString("%1|  ->active: ").arg(depth)<<currNode->active()
 
309
                               <<" custom:"<<((currNode->d_func()->m_flags & UCPageTreeNodePrivate::CustomActive) ? true : false));
 
310
    PT_TRACE(QString("%1|  ->activeLeaf: ").arg(depth)<<currNode->activeLeafNode());
 
311
 
 
312
    if (n.m_children.length())
 
313
        PT_TRACE(QString("%1|  ->isLeaf: ").arg(depth)<<currNode->isLeaf());
 
314
    else
 
315
        PT_TRACE(QString("%1└  ->isLeaf: ").arg(depth)<<currNode->isLeaf());
 
316
 
 
317
    //print the current nodes children
 
318
    for (int i = 0; i < n.m_children.length(); i++) {
 
319
        QString subDepth = depth;
 
320
 
 
321
        if (i == n.m_children.length() - 1 ) //last
 
322
            subDepth.append("   ");
 
323
        else
 
324
            subDepth.append("|  ");
 
325
 
 
326
        dumpNode(n.m_children.at(i), depth, subDepth, false);
 
327
    }
 
328
}
 
329
 
 
330
/*!
 
331
 * \brief UCPageTreeNodePrivate::dumpNodeTree
 
332
 * Prints the complete node tree this node is part of.
 
333
 * This recursively searches and prints the whole tree, so
 
334
 * its pretty expensive. Do not leaf the calls to it after
 
335
 * finishing the debugging.
 
336
 */
 
337
void UCPageTreeNodePrivate::dumpNodeTree()
 
338
{
 
339
    Q_Q(UCPageTreeNode);
 
340
 
 
341
    UCPageTreeNode *node = q;
 
342
    UCPageTreeNode *rootNode = nullptr;
 
343
    while(node) {
 
344
        rootNode = node;
 
345
        node = node->d_func()->getParentPageTreeNode();
 
346
    }
 
347
 
 
348
    PT_TRACE("Begin Node List for"<<q);
 
349
    if (Q_UNLIKELY(!rootNode)) {
 
350
        PT_TRACE("Empty tree");
 
351
    } else {
 
352
        Node root;
 
353
        root.m_node = rootNode;
 
354
        root.m_children = collectNodes(rootNode);
 
355
        dumpNode(root);
 
356
    }
 
357
    PT_TRACE("End Node List\n");
 
358
}
 
359
 
 
360
/*!
 
361
    \internal
 
362
    \qmltype PageTreeNode
 
363
    \inqmlmodule Ubuntu.Components 1.1
 
364
    \ingroup ubuntu
 
365
    \brief The common parent of \l Page, \l MainView, \l PageStack and \l Tabs.
 
366
 
 
367
    It is used to propagate properties such as \l header and \l toolbar from a
 
368
    \l MainView (the root node) to each \l Page (leaf node) in the tree.
 
369
*/
 
370
UCPageTreeNode::UCPageTreeNode(QQuickItem *parent)
 
371
    : UCStyledItemBase(*(new UCPageTreeNodePrivate), parent)
 
372
{
 
373
    d_func()->init();
 
374
}
 
375
 
 
376
UCPageTreeNode::UCPageTreeNode(UCPageTreeNodePrivate &dd, QQuickItem *parent)
 
377
    : UCStyledItemBase(dd, parent)
 
378
{
 
379
    d_func()->init();
 
380
}
 
381
 
 
382
void UCPageTreeNode::itemChange(QQuickItem::ItemChange change, const QQuickItem::ItemChangeData &value)
 
383
{
 
384
    Q_D(UCPageTreeNode);
 
385
 
 
386
    //update the parentNode property.
 
387
    //Likely it changes together with the Items parent
 
388
    UCStyledItemBase::itemChange(change, value);
 
389
    if (change == QQuickItem::ItemParentHasChanged) {
 
390
        d->updatePageTree();
 
391
    }
 
392
}
 
393
 
 
394
/*!
 
395
  \qmlproperty Item PageTreeNode::isLeaf
 
396
  Whether or not this node is a leaf, that is if it has no descendant that are nodes.
 
397
  Pages are leafs, and they don't have descendants in the PageTree.
 
398
 */
 
399
bool UCPageTreeNode::isLeaf() const
 
400
{
 
401
    return d_func()->m_isLeaf;
 
402
}
 
403
 
 
404
void UCPageTreeNode::setIsLeaf(bool isLeaf)
 
405
{
 
406
    Q_D(UCPageTreeNode);
 
407
 
 
408
    if (d->m_isLeaf == isLeaf)
 
409
        return;
 
410
 
 
411
    d->m_isLeaf = isLeaf;
 
412
    Q_EMIT isLeafChanged(isLeaf);
 
413
 
 
414
    //notify all our parent nodes that we are the leaf
 
415
    d->updateParentLeafNode();
 
416
}
 
417
 
 
418
/*!
 
419
  \qmlproperty Item PageTreeNode::parentNode
 
420
  The parent node of the current node in the page tree.
 
421
 */
 
422
void UCPageTreeNode::setParentNode(UCPageTreeNode *parentNode)
 
423
{
 
424
    Q_D(UCPageTreeNode);
 
425
 
 
426
    if (d->m_parentNode == parentNode)
 
427
        return;
 
428
 
 
429
    //disconnect from the old parent, we do not want to get
 
430
    //false property updates
 
431
    if (d->m_parentNode) {
 
432
        if (!(d->m_flags & UCPageTreeNodePrivate::CustomActive)) {
 
433
            disconnect(d->m_parentNode, SIGNAL(activeChanged(bool)),
 
434
                       this, SLOT(_q_activeBinding(bool)));
 
435
        }
 
436
        if (!(d->m_flags & UCPageTreeNodePrivate::CustomPageStack)) {
 
437
            disconnect(d->m_parentNode,SIGNAL(pageStackChanged(QQuickItem*)),
 
438
                       this, SLOT(_q_pageStackBinding (QQuickItem *)));
 
439
        }
 
440
        if (!(d->m_flags & UCPageTreeNodePrivate::CustomPropagated)) {
 
441
            disconnect(d->m_parentNode,SIGNAL(propagatedChanged(QObject*)),
 
442
                       this, SLOT(_q_propagatedBinding (QObject *)));
 
443
        }
 
444
 
 
445
        //the parent has changed, in case we or one of our children
 
446
        //were the active leaf node
 
447
        //make sure we are not anymore, since we are not part of that
 
448
        //tree
 
449
        if (d->m_parentNode->activeLeafNode() == this
 
450
                || d->m_parentNode->activeLeafNode() == activeLeafNode()) {
 
451
            d->m_parentNode->setActiveLeafNode(nullptr);
 
452
        }
 
453
    }
 
454
 
 
455
    d->m_parentNode = parentNode;
 
456
 
 
457
    //connect to the property changes of the parent node so they
 
458
    //can be propagated
 
459
    if (d->m_parentNode ) {
 
460
        if (!(d->m_flags & UCPageTreeNodePrivate::CustomActive)) {
 
461
            connect(d->m_parentNode, SIGNAL(activeChanged(bool)),
 
462
                   this, SLOT(_q_activeBinding(bool)));
 
463
        }
 
464
        if (!(d->m_flags & UCPageTreeNodePrivate::CustomPageStack)) {
 
465
            connect(d->m_parentNode,SIGNAL(pageStackChanged(QQuickItem*)),
 
466
                   this, SLOT(_q_pageStackBinding (QQuickItem *)));
 
467
        }
 
468
        if (!(d->m_flags & UCPageTreeNodePrivate::CustomPropagated)) {
 
469
            connect(d->m_parentNode,SIGNAL(propagatedChanged(QObject*)),
 
470
                    this, SLOT(_q_propagatedBinding (QObject *)));
 
471
        }
 
472
    }
 
473
 
 
474
    //update properties if they are not set manually
 
475
    if (!(d->m_flags & UCPageTreeNodePrivate::CustomActive))
 
476
        d->_q_activeBinding (parentNode && parentNode->active() );
 
477
    if (!(d->m_flags & UCPageTreeNodePrivate::CustomPageStack))
 
478
        d->_q_pageStackBinding (parentNode ? parentNode->pageStack() : nullptr);
 
479
    if (!(d->m_flags & UCPageTreeNodePrivate::CustomPropagated))
 
480
        d->_q_propagatedBinding (parentNode ? parentNode->propagated() : nullptr);
 
481
 
 
482
    Q_EMIT parentNodeChanged (parentNode);
 
483
}
 
484
 
 
485
UCPageTreeNode *UCPageTreeNode::parentNode() const
 
486
{
 
487
    return d_func()->m_parentNode;
 
488
}
 
489
 
 
490
void UCPageTreeNode::componentComplete()
 
491
{
 
492
    UCStyledItemBase::componentComplete();
 
493
    d_func()->updatePageTree();
 
494
}
 
495
 
 
496
void UCPageTreeNode::dumpNodeTree()
 
497
{
 
498
    d_func()->dumpNodeTree();
 
499
}
 
500
 
 
501
/*!
 
502
  \internal
 
503
  \qmlproperty Item PageTreeNode::__propagated
 
504
  QtObject containing all the properties that are propagated from the
 
505
  root (MainView) of a page tree to its leafs (Pages).
 
506
  This object contains properties such as the header and toolbar that are
 
507
  instantiated by the MainView.
 
508
 
 
509
  This property is internal because the derived classes (MainView and Page)
 
510
  need to access it, but other components using those classes should not have
 
511
  access to it.
 
512
 */
 
513
QObject *UCPageTreeNode::propagated() const
 
514
{
 
515
    return d_func()->m_propagated;
 
516
}
 
517
 
 
518
void UCPageTreeNode::setPropagated(QObject *propagated)
 
519
{
 
520
    Q_D(UCPageTreeNode);
 
521
 
 
522
    //remove the binding to parent
 
523
    if (d->m_parentNode && !(d->m_flags & UCPageTreeNodePrivate::CustomPropagated))
 
524
        disconnect(d->m_parentNode,SIGNAL(propagatedChanged(QObject*)),
 
525
                   this, SLOT(_q_propagatedBinding (QObject *)));
 
526
 
 
527
    d->m_flags |= UCPageTreeNodePrivate::CustomPropagated;
 
528
    d->_q_propagatedBinding(propagated);
 
529
}
 
530
 
 
531
/*!
 
532
  \qmlproperty Item PageTreeNode::toolbar
 
533
  \deprecated
 
534
  The toolbar of the node. Propagates down from the root node.
 
535
  This property is DEPRECATED.
 
536
 */
 
537
QQuickItem *UCPageTreeNode::toolbar() const
 
538
{
 
539
    return d_func()->m_toolbar;
 
540
}
 
541
 
 
542
void UCPageTreeNode::setToolbar(QQuickItem *toolbar)
 
543
{
 
544
    Q_D(UCPageTreeNode);
 
545
    if (d->m_toolbar == toolbar)
 
546
        return;
 
547
 
 
548
    d->m_toolbar = toolbar;
 
549
    Q_EMIT toolbarChanged(toolbar);
 
550
}
 
551
 
 
552
/*!
 
553
  \internal
 
554
  \qmlproperty Item PageTreeNode::__isPageTreeNode
 
555
  Used to determine whether an Item is a PageTreeNode
 
556
 */
 
557
bool UCPageTreeNode::isPageTreeNode() const
 
558
{
 
559
    return true;
 
560
}
 
561
 
 
562
/*!
 
563
  \qmlproperty Item PageTreeNode::activeLeafNode
 
564
  The leaf node that is active.
 
565
 */
 
566
void UCPageTreeNode::setActiveLeafNode(QQuickItem *activeLeafNode)
 
567
{
 
568
    Q_D(UCPageTreeNode);
 
569
    if (d->m_activeLeafNode == activeLeafNode)
 
570
        return;
 
571
 
 
572
    d->m_activeLeafNode = activeLeafNode;
 
573
    Q_EMIT activeLeafNodeChanged(activeLeafNode);
 
574
}
 
575
 
 
576
QQuickItem *UCPageTreeNode::activeLeafNode() const
 
577
{
 
578
    return d_func()->m_activeLeafNode;
 
579
}
 
580
 
 
581
 
 
582
/*!
 
583
  \qmlproperty Item PageTreeNode::active
 
584
  At any time, there is exactly one path from the root node to a Page leaf node
 
585
  where all nodes are active. All other nodes are not active. This is used by
 
586
  \l Tabs and \l PageStack to determine which of multiple nodes in the Tabs or
 
587
  PageStack is the currently active one.
 
588
 */
 
589
void UCPageTreeNode::setActive(bool active)
 
590
{
 
591
    Q_D(UCPageTreeNode);
 
592
 
 
593
    //remove the binding to parent
 
594
    if (d->m_parentNode && !(d->m_flags & UCPageTreeNodePrivate::CustomActive)) {
 
595
        disconnect(d->m_parentNode, SIGNAL(activeChanged(bool)),
 
596
                   this, SLOT(_q_activeBinding(bool)));
 
597
    }
 
598
 
 
599
    d->m_flags |= UCPageTreeNodePrivate::CustomActive;
 
600
    d->_q_activeBinding(active);
 
601
}
 
602
 
 
603
bool UCPageTreeNode::active() const
 
604
{
 
605
    return d_func()->m_active;
 
606
}
 
607
 
 
608
/*!
 
609
  \qmlproperty Item PageTreeNode::pageStack
 
610
  The \l PageStack that this Page has been pushed on, or null if it is not
 
611
  part of a PageStack. This value is automatically set for pages that are pushed
 
612
  on a PageStack, and propagates to its child nodes.
 
613
 */
 
614
// Note: pageStack is not included in the propagated property because there may
 
615
//  be multiple PageStacks in a single page tree.
 
616
void UCPageTreeNode::setPageStack(QQuickItem *pageStack)
 
617
{
 
618
    Q_D(UCPageTreeNode);
 
619
 
 
620
    //remove the binding to parent
 
621
    if (d->m_parentNode && !(d->m_flags & UCPageTreeNodePrivate::CustomPageStack))
 
622
        disconnect(d->m_parentNode,SIGNAL(pageStackChanged(QQuickItem*)),
 
623
                   this, SLOT(_q_pageStackBinding (QQuickItem *)));
 
624
 
 
625
    d->m_flags |= UCPageTreeNodePrivate::CustomPageStack;
 
626
    d->_q_pageStackBinding(pageStack);
 
627
}
 
628
 
 
629
QQuickItem *UCPageTreeNode::pageStack() const
 
630
{
 
631
    return d_func()->m_pageStack;
 
632
}
 
633
 
 
634
#include "moc_ucpagetreenode.cpp"