Convert child item iterations to firstChild() and nextSibling().
[kdbg.git] / kdbg / exprwnd.h
blobaed6f1fd710cf8fef7282518aa80f3a75a084052
1 // $Id$
3 // Copyright by Johannes Sixt
4 // This file is under GPL, the GNU General Public Licence
6 #ifndef EXPRWND_H
7 #define EXPRWND_H
9 #include "ktreeview.h"
10 #include <qlineedit.h>
11 #include <qptrlist.h>
12 #include <qstrlist.h>
14 class ProgramTypeTable;
15 class TypeInfo;
17 /* a variable's value is the tree of sub-variables */
19 class VarTree : public KTreeViewItem
21 public:
22 enum VarKind { VKsimple, VKpointer, VKstruct, VKarray,
23 VKdummy /* used to update only children */
25 VarKind m_varKind;
26 enum NameKind { NKplain, NKstatic, NKtype,
27 NKaddress /* a dereferenced pointer */
29 NameKind m_nameKind;
30 QString m_value;
31 bool m_valueChanged;
32 TypeInfo* m_type; /* type of struct */
33 int m_exprIndex; /* used in struct value update */
34 bool m_exprIndexUseGuard; /* ditto; if guard expr should be used */
35 QString m_partialValue; /* while struct value update is in progress */
37 VarTree(const QString& name, NameKind kind);
38 virtual ~VarTree();
39 public:
40 void paintValue(QPainter* painter);
41 int valueWidth();
42 QString computeExpr() const;
43 bool isToplevelExpr() const;
44 /** is this element an ancestor of (or equal to) child? */
45 bool isAncestorEq(const VarTree* child) const;
46 /** update the value; return if repaint is necessary */
47 bool updateValue(const QString& newValue);
48 /** find out the type of this value using the child values */
49 void inferTypesOfChildren(ProgramTypeTable& typeTable);
50 /** get the type from base class part */
51 TypeInfo* inferTypeFromBaseClass();
52 /** returns whether the pointer is a wchar_t */
53 bool isWcharT() const;
55 VarTree* firstChild() const { return static_cast<VarTree*>(getChild()); }
56 VarTree* nextSibling() const { return static_cast<VarTree*>(getSibling()); }
60 class ExprWnd;
62 class ValueEdit : public QLineEdit
64 Q_OBJECT
65 public:
66 ValueEdit(ExprWnd* parent);
67 ~ValueEdit();
69 void terminate(bool commit);
70 int m_row;
71 bool m_finished;
72 protected:
73 void keyPressEvent(QKeyEvent *e);
74 void focusOutEvent(QFocusEvent* ev);
75 void paintEvent(QPaintEvent* e);
76 public slots:
77 void slotSelectionChanged();
78 signals:
79 void done(int, const QString&);
83 class ExprWnd : public KTreeView
85 Q_OBJECT
86 public:
87 ExprWnd(QWidget* parent, const char* name);
88 ~ExprWnd();
90 /** fills the list with the expressions at the topmost level */
91 void exprList(QStrList& exprs);
92 /** appends a copy of expr to the end of the tree at the topmost level;
93 * returns a pointer to the inserted top-level item */
94 VarTree* insertExpr(VarTree* expr, ProgramTypeTable& typeTable);
95 /** updates an existing expression */
96 void updateExpr(VarTree* expr, ProgramTypeTable& typeTable);
97 void updateExpr(VarTree* display, VarTree* newValues, ProgramTypeTable& typeTable);
98 /** updates the value and repaints it for a single item (not the children) */
99 void updateSingleExpr(VarTree* display, VarTree* newValues);
100 /** updates only the value of the node */
101 void updateStructValue(VarTree* display);
102 /** get a top-level expression by name */
103 VarTree* topLevelExprByName(const char* name);
104 /** return a member of the struct that pointer \a v refers to */
105 static VarTree* ptrMemberByName(VarTree* v, const QString& name);
106 /** return a member of the struct \a v */
107 static VarTree* memberByName(VarTree* v, const QString& name);
108 /** removes an expression; must be on the topmost level*/
109 void removeExpr(VarTree* item);
110 /** clears the list of pointers needing updates */
111 void clearPendingUpdates();
112 /** returns a pointer to update (or 0) and removes it from the list */
113 VarTree* nextUpdatePtr();
114 VarTree* nextUpdateType();
115 VarTree* nextUpdateStruct();
116 void editValue(int row, const QString& text);
117 /** tells whether the a value is currently edited */
118 bool isEditing() const;
120 VarTree* firstChild() const { return static_cast<VarTree*>(itemAt(0)); }
121 VarTree* selectedItem() const { return static_cast<VarTree*>(getCurrentItem()); }
123 protected:
124 bool updateExprRec(VarTree* display, VarTree* newValues, ProgramTypeTable& typeTable);
125 void replaceChildren(VarTree* display, VarTree* newValues);
126 virtual void paintCell(QPainter* painter, int row, int col);
127 virtual int cellWidth(int col) const;
128 void updateValuesWidth();
129 static bool getMaxValueWidth(KTreeViewItem* item, void* user);
130 void collectUnknownTypes(VarTree* item);
131 static bool collectUnknownTypes(KTreeViewItem* item, void* user);
132 static QString formatWCharPointer(QString value);
133 int maxValueWidth;
134 QPixmap m_pixPointer;
136 QList<VarTree> m_updatePtrs; /* dereferenced pointers that need update */
137 QList<VarTree> m_updateType; /* structs whose type must be determined */
138 QList<VarTree> m_updateStruct; /* structs whose nested value needs update */
140 ValueEdit m_edit;
142 /** remove items that are in the subTree from the list */
143 void unhookSubtree(VarTree* subTree);
144 static void unhookSubtree(QList<VarTree>& list, VarTree* subTree);
146 protected slots:
147 void slotExpandOrCollapse(int);
149 signals:
150 void removingItem(VarTree*);
151 void editValueCommitted(int, const QString&);
154 #endif // EXPRWND_H