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
MythGenericTree::GetSortText
QString GetSortText() const
Definition: mythgenerictree.h:76
Q_DECLARE_METATYPE
Q_DECLARE_METATYPE(GrabberScript *)
MythGenericTree::SetData
void SetData(QVariant data)
Definition: mythgenerictree.h:87
MUI_PUBLIC
#define MUI_PUBLIC
Definition: mythuiexp.h:9
MythGenericTree::m_text
QString m_text
Definition: mythgenerictree.h:120
MythGenericTree::setInt
void setInt(int an_int)
Definition: mythgenerictree.h:65
MythGenericTree::setParent
void setParent(MythGenericTree *a_parent)
Definition: mythgenerictree.h:68
MythGenericTree::setSelectedChild
void setSelectedChild(MythGenericTree *a_node)
Definition: mythgenerictree.h:106
MythGenericTree::m_states
InfoMap m_states
Definition: mythgenerictree.h:124
MythGenericTree::visibleChildCount
uint visibleChildCount() const
Definition: mythgenerictree.h:91
MythGenericTree::getInt
int getInt() const
Definition: mythgenerictree.h:66
MythGenericTree::m_sortText
QString m_sortText
Definition: mythgenerictree.h:121
MythGenericTree::GetData
QVariant GetData(void) const
Definition: mythgenerictree.h:88
MythGenericTree::IntVector
QVector< int > IntVector
Definition: mythgenerictree.h:22
MythGenericTree::isSelectable
bool isSelectable() const
Definition: mythgenerictree.h:97
mythuibuttonlist.h
InfoMap
QHash< QString, QString > InfoMap
Definition: mythtypes.h:15
MythUIButtonListItem
Definition: mythuibuttonlist.h:27
MythGenericTree::IsVisible
bool IsVisible() const
Definition: mythgenerictree.h:100
filename
QString filename
Definition: mythplugins/mytharchive/mytharchivehelper/main.cpp:634
GetState
#define GetState(a, b)
Definition: audiooutputopensles.cpp:50
MythGenericTree::setSelectable
void setSelectable(bool flag)
Definition: mythgenerictree.h:96
uint
unsigned int uint
Definition: compat.h:140
MythGenericTree::m_imageFilenames
InfoMap m_imageFilenames
Definition: mythgenerictree.h:123
MythGenericTree::DecVisibleCount
void DecVisibleCount()
Definition: mythgenerictree.h:103
MythGenericTree
Definition: mythgenerictree.h:20
MythGenericTree::SetSortText
void SetSortText(const QString &text)
Definition: mythgenerictree.h:77
MythUIButtonList
List widget, displays list items in a variety of themeable arrangements and can trigger signals when ...
Definition: mythuibuttonlist.h:143
MythGenericTree::IncVisibleCount
void IncVisibleCount()
Definition: mythgenerictree.h:102
SortableMythGenericTreeList
Definition: mythgenerictree.cpp:13
mythuiexp.h
MythGenericTree::m_strings
QMap< QString, TextProperties > m_strings
Definition: mythgenerictree.h:122