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 
20 using mgtCbFn = QString (*)(const QString &name, void *data);
21 struct mgtCbInfo
22 {
23  mgtCbFn fn {nullptr};
24  void* data {nullptr};
25 };
26 
28 {
29  using IntVector = QVector<int>;
30 
31  public:
32  explicit MythGenericTree(const 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
MythGenericTree::GetSortText
QString GetSortText() const
Definition: mythgenerictree.h:84
Q_DECLARE_METATYPE
Q_DECLARE_METATYPE(GrabberScript *)
MythGenericTree::SetData
void SetData(QVariant data)
Definition: mythgenerictree.h:97
MUI_PUBLIC
#define MUI_PUBLIC
Definition: mythuiexp.h:9
MythGenericTree::m_text
QString m_text
Definition: mythgenerictree.h:130
MythGenericTree::setInt
void setInt(int an_int)
Definition: mythgenerictree.h:72
MythGenericTree::setParent
void setParent(MythGenericTree *a_parent)
Definition: mythgenerictree.h:75
MythGenericTree::m_textCb
mgtCbInfo m_textCb
Definition: mythgenerictree.h:135
MythGenericTree::setSelectedChild
void setSelectedChild(MythGenericTree *a_node)
Definition: mythgenerictree.h:116
MythGenericTree::m_states
InfoMap m_states
Definition: mythgenerictree.h:134
MythGenericTree::visibleChildCount
uint visibleChildCount() const
Definition: mythgenerictree.h:101
MythGenericTree::getInt
int getInt() const
Definition: mythgenerictree.h:73
MythGenericTree::m_sortText
QString m_sortText
Definition: mythgenerictree.h:131
MythGenericTree::GetData
QVariant GetData(void) const
Definition: mythgenerictree.h:98
mgtCbInfo::data
void * data
Definition: mythgenerictree.h:24
MythGenericTree::IntVector
QVector< int > IntVector
Definition: mythgenerictree.h:29
MythGenericTree::isSelectable
bool isSelectable() const
Definition: mythgenerictree.h:107
mythuibuttonlist.h
mgtCbInfo
Definition: mythgenerictree.h:21
mgtCbFn
QString(*)(const QString &name, void *data) mgtCbFn
Definition: mythgenerictree.h:20
InfoMap
QHash< QString, QString > InfoMap
Definition: mythtypes.h:15
MythUIButtonListItem
Definition: mythuibuttonlist.h:34
MythGenericTree::IsVisible
bool IsVisible() const
Definition: mythgenerictree.h:110
GetState
#define GetState(a, b)
Definition: audiooutputopensles.cpp:48
MythGenericTree::setSelectable
void setSelectable(bool flag)
Definition: mythgenerictree.h:106
uint
unsigned int uint
Definition: compat.h:144
MythGenericTree::m_imageFilenames
InfoMap m_imageFilenames
Definition: mythgenerictree.h:133
MythGenericTree::m_stateCb
mgtCbInfo m_stateCb
Definition: mythgenerictree.h:137
MythGenericTree::DecVisibleCount
void DecVisibleCount()
Definition: mythgenerictree.h:113
MythGenericTree
Definition: mythgenerictree.h:27
mgtCbInfo::fn
mgtCbFn fn
Definition: mythgenerictree.h:23
MythGenericTree::m_imageCb
mgtCbInfo m_imageCb
Definition: mythgenerictree.h:136
MythGenericTree::SetSortText
void SetSortText(const QString &text)
Definition: mythgenerictree.h:85
MythUIButtonList
List widget, displays list items in a variety of themeable arrangements and can trigger signals when ...
Definition: mythuibuttonlist.h:177
build_compdb.filename
filename
Definition: build_compdb.py:21
MythGenericTree::IncVisibleCount
void IncVisibleCount()
Definition: mythgenerictree.h:112
SortableMythGenericTreeList
Definition: mythgenerictree.cpp:13
mythuiexp.h
MythGenericTree::m_strings
QMap< QString, TextProperties > m_strings
Definition: mythgenerictree.h:132