MythTV master
mythgenerictree.h
Go to the documentation of this file.
1#ifndef MYTHGENERICTREE_H_
2#define MYTHGENERICTREE_H_
3
4#include <utility>
5
6#include <QHash>
7#include <QList>
8#include <QMap>
9#include <QMetaType>
10#include <QString>
11#include <QStringList>
12#include <QVariant>
13#include <QVector>
14
15#include "mythuiexp.h"
16#include "mythuibuttonlist.h"
17
19
20using mgtCbFn = QString (*)(const QString &name, void *data);
22{
23 mgtCbFn fn {nullptr};
24 void* data {nullptr};
25};
26
28{
29 using IntVector = QVector<int>;
30
31 public:
32 explicit MythGenericTree(QString a_string = "", int an_int = 0,
33 bool selectable_flag = false);
34 virtual ~MythGenericTree();
35
36 void ensureSortFields(void);
37
38 MythGenericTree *addNode(const QString &a_string, int an_int = 0,
39 bool selectable_flag = false, bool visible = true);
40 MythGenericTree *addNode(const QString &a_string, const QString &sortText = "",
41 int an_int = 0, bool selectable_flag = false, bool visible = true);
42 MythGenericTree *addNode(MythGenericTree *child);
43
46 void DetachParent(void);
47
48 void removeNode(MythGenericTree *child);
49 void deleteNode(MythGenericTree *child);
50
51 MythGenericTree *findLeaf();
52 MythGenericTree* findNode(QList<int> route_of_branches);
53
54 MythGenericTree *nextSibling(int number_down);
55 MythGenericTree *prevSibling(int number_up);
56
57 MythGenericTree *getSelectedChild(bool onlyVisible = false) const;
58 MythGenericTree *getVisibleChildAt(uint reference) const;
59 MythGenericTree *getChildAt(uint reference) const;
60 MythGenericTree *getChildByName(const QString &a_name) const;
61 MythGenericTree *getChildById(int an_int) const;
62
63 QList<MythGenericTree*> *getAllChildren() const;
64
65 int getChildPosition(MythGenericTree *child) const;
66 int getPosition(void);
67
68 QList<int> getRouteById(void);
69 QStringList getRouteByString(void);
70 QList<MythGenericTree*> getRoute(void);
71
72 void setInt(int an_int) { m_int = an_int; }
73 int getInt() const { return m_int; }
74
75 void setParent(MythGenericTree* a_parent) { m_parent = a_parent; }
76 MythGenericTree *getParent(void) const;
77
78 void SetText(const QString &text, const QString &name="",
79 const QString &state="");
80 void SetTextFromMap(const InfoMap &infoMap, const QString &state="");
81 void SetTextCb(mgtCbFn fn, void *data);
82 QString GetText(const QString &name="") const;
83
84 QString GetSortText() const { return m_sortText; }
85 void SetSortText(const QString &text) { m_sortText = text; }
86
87 void SetImage(const QString &filename, const QString &name="");
88 void SetImageFromMap(const InfoMap &infoMap);
89 void SetImageCb(mgtCbFn fn, void *data);
90 QString GetImage(const QString &name="") const;
91
92 void DisplayState(const QString &state, const QString &name="");
93 void DisplayStateFromMap(const InfoMap &infoMap);
94 void SetStateCb(mgtCbFn fn, void *data);
95 QString GetState(const QString &name="") const;
96
97 void SetData(QVariant data) { m_data = std::move(data); }
98 QVariant GetData(void) const { return m_data; }
99
100 int childCount(void) const;
101 uint visibleChildCount() const { return m_visibleCount; }
102 int siblingCount(void) const;
103
104 int currentDepth(void);
105
106 void setSelectable(bool flag) { m_selectable = flag; }
107 bool isSelectable() const { return m_selectable; }
108
109 void SetVisible(bool visible);
110 bool IsVisible() const { return m_visible; }
111
112 void IncVisibleCount() { m_visibleCount++; }
113 void DecVisibleCount() { m_visibleCount--; }
114
115 void becomeSelectedChild(void);
116 void setSelectedChild(MythGenericTree* a_node) { m_selectedSubnode = a_node; }
117
118 void sortByString();
119 void sortBySelectable();
120 void deleteAllChildren();
121
122 // only changes m_subnodes. resort it if you want the others to change
123 void MoveItemUpDown(MythGenericTree *item, bool flag);
124
125 virtual MythUIButtonListItem *CreateListButton(MythUIButtonList *list);
126
127 private:
128 void reorderSubnodes(void);
129
130 QString m_text;
131 QString m_sortText;
132 QMap<QString, TextProperties> m_strings;
138 int m_int {0};
139 QVariant m_data {0};
140 uint m_visibleCount {0};
141
142 SortableMythGenericTreeList *m_subnodes {nullptr};
143
144 MythGenericTree *m_selectedSubnode {nullptr};
145 MythGenericTree *m_parent {nullptr};
146
147 bool m_selectable {false};
148 bool m_visible {true};
149};
150
152
153#endif
#define GetState(a, b)
int getInt() const
bool isSelectable() const
QVariant GetData(void) const
void setInt(int an_int)
void setParent(MythGenericTree *a_parent)
void setSelectedChild(MythGenericTree *a_node)
void SetSortText(const QString &text)
QVector< int > IntVector
QMap< QString, TextProperties > m_strings
bool IsVisible() const
InfoMap m_imageFilenames
uint visibleChildCount() const
void setSelectable(bool flag)
void SetData(QVariant data)
void reorderSubnodes(void)
QString GetSortText() const
List widget, displays list items in a variety of themeable arrangements and can trigger signals when ...
unsigned int uint
Definition: freesurround.h:24
Q_DECLARE_METATYPE(std::chrono::seconds)
QString(*)(const QString &name, void *data) mgtCbFn
QHash< QString, QString > InfoMap
Definition: mythtypes.h:15
#define MUI_PUBLIC
Definition: mythuiexp.h:9
mgtCbFn fn