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