00001 #ifndef MYTHGENERICTREE_H_
00002 #define MYTHGENERICTREE_H_
00003
00004 #include <QString>
00005 #include <QStringList>
00006 #include <QList>
00007 #include <QVector>
00008 #include <QMetaType>
00009 #include <QVariant>
00010 #include <QMap>
00011 #include <QHash>
00012
00013 #include "mythuiexp.h"
00014
00015 #include "mythuibuttonlist.h"
00016
00017 class SortableMythGenericTreeList;
00018
00019 class MUI_PUBLIC MythGenericTree
00020 {
00021 typedef QVector<int> IntVector;
00022
00023 public:
00024 MythGenericTree(const QString &a_string = "", int an_int = 0,
00025 bool selectable_flag = false);
00026 virtual ~MythGenericTree();
00027
00028 MythGenericTree *addNode(const QString &a_string, int an_int = 0,
00029 bool selectable_flag = false, bool visible = true);
00030 MythGenericTree *addNode(MythGenericTree *child);
00031
00034 void DetachParent(void);
00035
00036 void removeNode(MythGenericTree *child);
00037 void deleteNode(MythGenericTree *child);
00038
00039 MythGenericTree *findLeaf();
00040 MythGenericTree* findNode(QList<int> route_of_branches, int depth=-1);
00041
00042 MythGenericTree *nextSibling(int number_down);
00043 MythGenericTree *prevSibling(int number_up);
00044
00045 QList<MythGenericTree*>::iterator getFirstChildIterator() const;
00046
00047 MythGenericTree *getSelectedChild(bool onlyVisible = false) const;
00048 MythGenericTree *getVisibleChildAt(uint reference) const;
00049 MythGenericTree *getChildAt(uint reference) const;
00050 MythGenericTree *getChildByName(const QString &a_name) const;
00051 MythGenericTree *getChildById(int an_int) const;
00052
00053 QList<MythGenericTree*> *getAllChildren() const;
00054
00055 int getChildPosition(MythGenericTree *child) const;
00056 int getPosition(void);
00057
00058 QList<int> getRouteById(void);
00059 QStringList getRouteByString(void);
00060 QList<MythGenericTree*> getRoute(void);
00061
00062 void setInt(int an_int) { m_int = an_int; }
00063 int getInt() const { return m_int; }
00064
00065 void setParent(MythGenericTree* a_parent) { m_parent = a_parent; }
00066 MythGenericTree *getParent(void) const;
00067
00068
00069 const QString getString(void) const { return m_text; }
00070 void setString(const QString &str) { m_text = str; }
00071
00072
00073 void SetText(const QString &text, const QString &name="",
00074 const QString &state="");
00075 void SetTextFromMap(InfoMap &infoMap, const QString &state="");
00076 QString GetText(const QString &name="") const;
00077
00078 void SetImage(const QString &filename, const QString &name="");
00079 void SetImageFromMap(InfoMap &infoMap);
00080 QString GetImage(const QString &name="") const;
00081
00082 void DisplayState(const QString &state, const QString &name="");
00083 void DisplayStateFromMap(InfoMap &infoMap);
00084 QString GetState(const QString &name="") const;
00085
00086 void SetData(QVariant data) { m_data = data; }
00087 const QVariant GetData(void) const { return m_data; }
00088
00089 int childCount(void) const;
00090 uint visibleChildCount() const { return m_visibleCount; }
00091 int siblingCount(void) const;
00092
00093 int currentDepth(void);
00094
00095 void setSelectable(bool flag) { m_selectable = flag; }
00096 bool isSelectable() const { return m_selectable; }
00097
00098 void SetVisible(bool visible);
00099 bool IsVisible() const { return m_visible; }
00100
00101 void IncVisibleCount() { m_visibleCount++; }
00102 void DecVisibleCount() { m_visibleCount--; }
00103
00104 void setAttribute(uint attribute_position, int value_of_attribute);
00105 int getAttribute(uint which_one) const;
00106 IntVector *getAttributes(void) const { return m_attributes; }
00107
00108 void setOrderingIndex(int ordering_index);
00109 int getOrderingIndex(void) const { return m_currentOrderingIndex; }
00110
00111 void becomeSelectedChild(void);
00112 void setSelectedChild(MythGenericTree* a_node) { m_selected_subnode = a_node; }
00113
00114 void addYourselfIfSelectable(QList<MythGenericTree*> *flat_list);
00115 void buildFlatListOfSubnodes(bool scrambled_parents);
00116
00117 MythGenericTree *nextPrevFromFlatList(bool forward_or_back, bool wrap_around,
00118 MythGenericTree *active) const;
00119
00120 void sortByString();
00121 void sortByAttributeThenByString(int which_attribute);
00122 void sortBySelectable();
00123 void deleteAllChildren();
00124 void reOrderAsSorted();
00125
00126
00127 void MoveItemUpDown(MythGenericTree *item, bool flag);
00128
00129 virtual MythUIButtonListItem *CreateListButton(MythUIButtonList *list);
00130
00131 private:
00132 void reorderSubnodes(void);
00133
00134 QString m_text;
00135 QMap<QString, TextProperties> m_strings;
00136 InfoMap m_imageFilenames;
00137 InfoMap m_states;
00138 int m_int;
00139 QVariant m_data;
00140 uint m_visibleCount;
00141
00142 SortableMythGenericTreeList *m_subnodes;
00143 SortableMythGenericTreeList *m_ordered_subnodes;
00144 SortableMythGenericTreeList *m_flatenedSubnodes;
00145
00146 MythGenericTree *m_selected_subnode;
00147 IntVector *m_attributes;
00148 MythGenericTree *m_parent;
00149
00150 bool m_selectable;
00151 bool m_visible;
00152 int m_currentOrderingIndex;
00153 };
00154
00155 Q_DECLARE_METATYPE(MythGenericTree*)
00156
00157 #endif