1 /*
2     SPDX-FileCopyrightText: 2020 Marco Martin <mart@kde.org>
3 
4     SPDX-License-Identifier: LGPL-2.0-or-later
5 */
6 
7 #include "kdescendantsproxymodel_qml.h"
8 #include <QDebug>
9 
KDescendantsProxyModelQml(QObject * parent)10 KDescendantsProxyModelQml::KDescendantsProxyModelQml(QObject *parent)
11     : KDescendantsProxyModel(parent)
12 {
13 }
14 
~KDescendantsProxyModelQml()15 KDescendantsProxyModelQml::~KDescendantsProxyModelQml()
16 {
17 }
18 
expandChildren(int row)19 void KDescendantsProxyModelQml::expandChildren(int row)
20 {
21     QModelIndex idx = mapToSource(index(row, 0));
22     expandSourceIndex(idx);
23 }
24 
collapseChildren(int row)25 void KDescendantsProxyModelQml::collapseChildren(int row)
26 {
27     QModelIndex idx = mapToSource(index(row, 0));
28     collapseSourceIndex(idx);
29 }
30 
toggleChildren(int row)31 void KDescendantsProxyModelQml::toggleChildren(int row)
32 {
33     QModelIndex sourceIndex = mapToSource(index(row, 0));
34 
35     if (!sourceModel()->hasChildren(sourceIndex)) {
36         return;
37     }
38 
39     if (isSourceIndexExpanded(sourceIndex)) {
40         collapseSourceIndex(sourceIndex);
41     } else {
42         expandSourceIndex(sourceIndex);
43     }
44 }
45 
46 #include "moc_kdescendantsproxymodel_qml.cpp"
47