3 // Copyright by Johannes Sixt
4 // This file is under GPL, the GNU General Public Licence
10 #include <qlineedit.h>
14 class ProgramTypeTable
;
18 /* a variable's value is the tree of sub-variables */
20 class VarTree
: public KTreeViewItem
23 enum VarKind
{ VKsimple
, VKpointer
, VKstruct
, VKarray
,
24 VKdummy
/* used to update only children */
27 enum NameKind
{ NKplain
, NKstatic
, NKtype
,
28 NKaddress
/* a dereferenced pointer */
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(ExprValue
* v
);
38 VarTree(const QString
& name
);
41 void paintValue(QPainter
* painter
);
43 QString
computeExpr() const;
44 bool isToplevelExpr() const;
45 /** is this element an ancestor of (or equal to) child? */
46 bool isAncestorEq(const VarTree
* child
) const;
47 /** update the value; return if repaint is necessary */
48 bool updateValue(const QString
& newValue
);
49 /** find out the type of this value using the child values */
50 void inferTypesOfChildren(ProgramTypeTable
& typeTable
);
51 /** get the type from base class part */
52 TypeInfo
* inferTypeFromBaseClass();
53 /** returns whether the pointer is a wchar_t */
54 bool isWcharT() const;
56 void setValue(const QString
& v
) { m_value
= v
; }
57 QString
value() const { return m_value
; }
58 VarTree
* firstChild() const { return static_cast<VarTree
*>(getChild()); }
59 VarTree
* nextSibling() const { return static_cast<VarTree
*>(getSibling()); }
66 * Represents the value tree that is parsed by the debugger drivers.
72 VarTree::VarKind m_varKind
;
73 VarTree::NameKind m_nameKind
;
74 ExprValue
* m_child
; /* the first child expression */
75 ExprValue
* m_next
; /* the next sibling expression */
76 bool m_initiallyExpanded
;
78 ExprValue(const QString
& name
, VarTree::NameKind kind
);
81 void appendChild(ExprValue
* newChild
);
82 uint
childCount() const;
88 class ValueEdit
: public QLineEdit
92 ValueEdit(ExprWnd
* parent
);
95 void terminate(bool commit
);
99 void keyPressEvent(QKeyEvent
*e
);
100 void focusOutEvent(QFocusEvent
* ev
);
101 void paintEvent(QPaintEvent
* e
);
103 void slotSelectionChanged();
105 void done(int, const QString
&);
109 class ExprWnd
: public KTreeView
113 ExprWnd(QWidget
* parent
, const char* name
);
116 /** fills the list with the expressions at the topmost level */
117 void exprList(QStrList
& exprs
);
118 /** appends a copy of expr to the end of the tree at the topmost level;
119 * returns a pointer to the inserted top-level item */
120 VarTree
* insertExpr(ExprValue
* expr
, ProgramTypeTable
& typeTable
);
121 /** updates an existing expression */
122 void updateExpr(ExprValue
* expr
, ProgramTypeTable
& typeTable
);
123 void updateExpr(VarTree
* display
, ExprValue
* newValues
, ProgramTypeTable
& typeTable
);
124 /** updates the value and repaints it for a single item (not the children) */
125 void updateSingleExpr(VarTree
* display
, ExprValue
* newValues
);
126 /** updates only the value of the node */
127 void updateStructValue(VarTree
* display
);
128 /** get a top-level expression by name */
129 VarTree
* topLevelExprByName(const char* name
);
130 /** return a member of the struct that pointer \a v refers to */
131 static VarTree
* ptrMemberByName(VarTree
* v
, const QString
& name
);
132 /** return a member of the struct \a v */
133 static VarTree
* memberByName(VarTree
* v
, const QString
& name
);
134 /** removes an expression; must be on the topmost level*/
135 void removeExpr(VarTree
* item
);
136 /** clears the list of pointers needing updates */
137 void clearPendingUpdates();
138 /** returns a pointer to update (or 0) and removes it from the list */
139 VarTree
* nextUpdatePtr();
140 VarTree
* nextUpdateType();
141 VarTree
* nextUpdateStruct();
142 void editValue(int row
, const QString
& text
);
143 /** tells whether the a value is currently edited */
144 bool isEditing() const;
146 VarTree
* firstChild() const { return static_cast<VarTree
*>(itemAt(0)); }
147 VarTree
* selectedItem() const { return static_cast<VarTree
*>(getCurrentItem()); }
150 bool updateExprRec(VarTree
* display
, ExprValue
* newValues
, ProgramTypeTable
& typeTable
);
151 void replaceChildren(VarTree
* display
, ExprValue
* newValues
);
152 virtual void paintCell(QPainter
* painter
, int row
, int col
);
153 virtual int cellWidth(int col
) const;
154 void updateValuesWidth();
155 static bool getMaxValueWidth(KTreeViewItem
* item
, void* user
);
156 void collectUnknownTypes(VarTree
* item
);
157 static bool collectUnknownTypes(KTreeViewItem
* item
, void* user
);
158 static QString
formatWCharPointer(QString value
);
160 QPixmap m_pixPointer
;
162 QList
<VarTree
> m_updatePtrs
; /* dereferenced pointers that need update */
163 QList
<VarTree
> m_updateType
; /* structs whose type must be determined */
164 QList
<VarTree
> m_updateStruct
; /* structs whose nested value needs update */
168 /** remove items that are in the subTree from the list */
169 void unhookSubtree(VarTree
* subTree
);
170 static void unhookSubtree(QList
<VarTree
>& list
, VarTree
* subTree
);
173 void slotExpandOrCollapse(int);
176 void removingItem(VarTree
*);
177 void editValueCommitted(int, const QString
&);