1 | /* |
---|---|
2 | This file is part of the KDE project |
3 | SPDX-FileCopyrightText: 2007 Matthias Kretz <kretz@kde.org> |
4 | |
5 | SPDX-License-Identifier: LGPL-2.0-only |
6 | */ |
7 | |
8 | #ifndef KPAGEWIDGETMODEL_P_H |
9 | #define KPAGEWIDGETMODEL_P_H |
10 | |
11 | #include "kpagemodel_p.h" |
12 | #include "kpagewidgetmodel.h" |
13 | |
14 | class PageItem |
15 | { |
16 | public: |
17 | explicit PageItem(KPageWidgetItem *pageItem, PageItem *parent = nullptr); |
18 | ~PageItem(); |
19 | |
20 | PageItem(const PageItem &) = delete; |
21 | PageItem &operator=(const PageItem &) = delete; |
22 | |
23 | void appendChild(PageItem *child); |
24 | void insertChild(int row, PageItem *child); |
25 | void removeChild(int row); |
26 | |
27 | PageItem *child(int row); |
28 | int childCount() const; |
29 | int columnCount() const; |
30 | int row() const; |
31 | PageItem *parent(); |
32 | |
33 | KPageWidgetItem *pageWidgetItem() const; |
34 | |
35 | PageItem *findChild(const KPageWidgetItem *item); |
36 | |
37 | void dump(int indent = 0); |
38 | |
39 | private: |
40 | KPageWidgetItem *mPageWidgetItem; |
41 | |
42 | QList<PageItem *> mChildItems; |
43 | PageItem *mParentItem; |
44 | }; |
45 | |
46 | class KPageWidgetModelPrivate : public KPageModelPrivate |
47 | { |
48 | Q_DECLARE_PUBLIC(KPageWidgetModel) |
49 | protected: |
50 | KPageWidgetModelPrivate() |
51 | : rootItem(new PageItem(nullptr, nullptr)) |
52 | { |
53 | } |
54 | |
55 | ~KPageWidgetModelPrivate() override |
56 | { |
57 | delete rootItem; |
58 | rootItem = nullptr; |
59 | } |
60 | |
61 | PageItem *rootItem; |
62 | |
63 | void _k_itemChanged() |
64 | { |
65 | Q_Q(KPageWidgetModel); |
66 | KPageWidgetItem *item = qobject_cast<KPageWidgetItem *>(object: q->sender()); |
67 | if (!item) { |
68 | return; |
69 | } |
70 | |
71 | const QModelIndex index = q->index(item); |
72 | if (!index.isValid()) { |
73 | return; |
74 | } |
75 | |
76 | Q_EMIT q->dataChanged(topLeft: index, bottomRight: index); |
77 | } |
78 | |
79 | void _k_itemToggled(bool checked) |
80 | { |
81 | Q_Q(KPageWidgetModel); |
82 | KPageWidgetItem *item = qobject_cast<KPageWidgetItem *>(object: q->sender()); |
83 | if (!item) { |
84 | return; |
85 | } |
86 | |
87 | Q_EMIT q->toggled(page: item, checked); |
88 | } |
89 | }; |
90 | |
91 | #endif // KPAGEWIDGETMODEL_P_H |
92 |