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