3 // Copyright by Johannes Sixt
4 // This file is under GPL, the GNU General Public Licence
10 #include <qlineedit.h>
14 class ProgramTypeTable
;
17 /* a variable's value is the tree of sub-variables */
19 class VarTree
: public KTreeViewItem
22 enum VarKind
{ VKsimple
, VKpointer
, VKstruct
, VKarray
,
23 VKdummy
/* used to update only children */
26 enum NameKind
{ NKplain
, NKstatic
, NKtype
,
27 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(const QString
& name
, NameKind kind
);
40 void paintValue(QPainter
* painter
);
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 * Represents the value tree that is parsed by the debugger drivers.
66 VarTree::VarKind m_varKind
;
67 VarTree::NameKind m_nameKind
;
68 ExprValue
* m_child
; /* the first child expression */
69 ExprValue
* m_next
; /* the next sibling expression */
70 bool m_initiallyExpanded
;
72 ExprValue(const QString
& name
, VarTree::NameKind kind
);
75 void appendChild(ExprValue
* newChild
);
76 uint
childCount() const;
82 class ValueEdit
: public QLineEdit
86 ValueEdit(ExprWnd
* parent
);
89 void terminate(bool commit
);
93 void keyPressEvent(QKeyEvent
*e
);
94 void focusOutEvent(QFocusEvent
* ev
);
95 void paintEvent(QPaintEvent
* e
);
97 void slotSelectionChanged();
99 void done(int, const QString
&);
103 class ExprWnd
: public KTreeView
107 ExprWnd(QWidget
* parent
, const char* name
);
110 /** fills the list with the expressions at the topmost level */
111 void exprList(QStrList
& exprs
);
112 /** appends a copy of expr to the end of the tree at the topmost level;
113 * returns a pointer to the inserted top-level item */
114 VarTree
* insertExpr(ExprValue
* expr
, ProgramTypeTable
& typeTable
);
115 /** updates an existing expression */
116 void updateExpr(ExprValue
* expr
, ProgramTypeTable
& typeTable
);
117 void updateExpr(VarTree
* display
, ExprValue
* newValues
, ProgramTypeTable
& typeTable
);
118 /** updates the value and repaints it for a single item (not the children) */
119 void updateSingleExpr(VarTree
* display
, ExprValue
* newValues
);
120 /** updates only the value of the node */
121 void updateStructValue(VarTree
* display
);
122 /** get a top-level expression by name */
123 VarTree
* topLevelExprByName(const char* name
);
124 /** return a member of the struct that pointer \a v refers to */
125 static VarTree
* ptrMemberByName(VarTree
* v
, const QString
& name
);
126 /** return a member of the struct \a v */
127 static VarTree
* memberByName(VarTree
* v
, const QString
& name
);
128 /** removes an expression; must be on the topmost level*/
129 void removeExpr(VarTree
* item
);
130 /** clears the list of pointers needing updates */
131 void clearPendingUpdates();
132 /** returns a pointer to update (or 0) and removes it from the list */
133 VarTree
* nextUpdatePtr();
134 VarTree
* nextUpdateType();
135 VarTree
* nextUpdateStruct();
136 void editValue(int row
, const QString
& text
);
137 /** tells whether the a value is currently edited */
138 bool isEditing() const;
140 VarTree
* firstChild() const { return static_cast<VarTree
*>(itemAt(0)); }
141 VarTree
* selectedItem() const { return static_cast<VarTree
*>(getCurrentItem()); }
144 bool updateExprRec(VarTree
* display
, ExprValue
* newValues
, ProgramTypeTable
& typeTable
);
145 void replaceChildren(VarTree
* display
, ExprValue
* newValues
);
146 virtual void paintCell(QPainter
* painter
, int row
, int col
);
147 virtual int cellWidth(int col
) const;
148 void updateValuesWidth();
149 static bool getMaxValueWidth(KTreeViewItem
* item
, void* user
);
150 void collectUnknownTypes(VarTree
* item
);
151 static bool collectUnknownTypes(KTreeViewItem
* item
, void* user
);
152 static QString
formatWCharPointer(QString value
);
154 QPixmap m_pixPointer
;
156 QList
<VarTree
> m_updatePtrs
; /* dereferenced pointers that need update */
157 QList
<VarTree
> m_updateType
; /* structs whose type must be determined */
158 QList
<VarTree
> m_updateStruct
; /* structs whose nested value needs update */
162 /** remove items that are in the subTree from the list */
163 void unhookSubtree(VarTree
* subTree
);
164 static void unhookSubtree(QList
<VarTree
>& list
, VarTree
* subTree
);
167 void slotExpandOrCollapse(int);
170 void removingItem(VarTree
*);
171 void editValueCommitted(int, const QString
&);