3 // Copyright by Johannes Sixt
4 // This file is under GPL, the GNU General Public Licence
10 #include <qlineedit.h>
15 class ProgramTypeTable
;
20 /* a variable's value is the tree of sub-variables */
22 class VarTree
: public QListViewItem
25 enum VarKind
{ VKsimple
, VKpointer
, VKstruct
, VKarray
,
26 VKdummy
/* used to update only children */
29 enum NameKind
{ NKplain
, NKstatic
, NKtype
,
30 NKaddress
/* a dereferenced pointer */
34 TypeInfo
* m_type
; /* type of struct */
35 int m_exprIndex
; /* used in struct value update */
36 bool m_exprIndexUseGuard
; /* ditto; if guard expr should be used */
37 QString m_partialValue
; /* while struct value update is in progress */
39 VarTree(VarTree
* parent
, ExprValue
* v
);
40 VarTree(ExprWnd
* parent
, const QString
& name
);
43 virtual void paintCell(QPainter
* p
, const QColorGroup
& cg
, int column
, int width
, int align
);
44 QString
computeExpr() const;
45 bool isToplevelExpr() const;
46 /** is this element an ancestor of (or equal to) child? */
47 bool isAncestorEq(const VarTree
* child
) const;
48 /** update the value; return if repaint is necessary */
49 bool updateValue(const QString
& newValue
);
50 /** find out the type of this value using the child values */
51 void inferTypesOfChildren(ProgramTypeTable
& typeTable
);
52 /** get the type from base class part */
53 TypeInfo
* inferTypeFromBaseClass();
54 /** returns whether the pointer is a wchar_t */
55 bool isWcharT() const;
57 QString
getText() const { return text(0); }
58 void setText(const QString
& t
) { QListViewItem::setText(0, t
); }
59 void setPixmap(const QPixmap
& p
) { QListViewItem::setPixmap(0, p
); }
60 void setValue(const QString
& v
) { QListViewItem::setText(1, v
); }
61 QString
value() const { return text(1); }
62 VarTree
* firstChild() const { return static_cast<VarTree
*>(QListViewItem::firstChild()); }
63 VarTree
* nextSibling() const { return static_cast<VarTree
*>(QListViewItem::nextSibling()); }
67 * Represents the value tree that is parsed by the debugger drivers.
73 VarTree::VarKind m_varKind
;
74 VarTree::NameKind m_nameKind
;
75 ExprValue
* m_child
; /* the first child expression */
76 ExprValue
* m_next
; /* the next sibling expression */
77 bool m_initiallyExpanded
;
79 ExprValue(const QString
& name
, VarTree::NameKind kind
);
82 void appendChild(ExprValue
* newChild
);
83 int childCount() const;
87 class ValueEdit
: public QLineEdit
91 ValueEdit(ExprWnd
* parent
);
94 void terminate(bool commit
);
98 void keyPressEvent(QKeyEvent
*e
);
99 void focusOutEvent(QFocusEvent
* ev
);
100 void paintEvent(QPaintEvent
* e
);
102 void slotSelectionChanged();
104 void done(VarTree
*, const QString
&);
108 class ExprWnd
: public QListView
112 ExprWnd(QWidget
* parent
, const char* name
);
115 /** fills the list with the expressions at the topmost level */
116 void exprList(QStrList
& exprs
);
117 /** appends a copy of expr to the end of the tree at the topmost level;
118 * returns a pointer to the inserted top-level item */
119 VarTree
* insertExpr(ExprValue
* expr
, ProgramTypeTable
& typeTable
);
120 /** updates an existing expression */
121 void updateExpr(ExprValue
* expr
, ProgramTypeTable
& typeTable
);
122 void updateExpr(VarTree
* display
, ExprValue
* newValues
, ProgramTypeTable
& typeTable
);
123 /** updates the value and repaints it for a single item (not the children) */
124 void updateSingleExpr(VarTree
* display
, ExprValue
* newValues
);
125 /** updates only the value of the node */
126 void updateStructValue(VarTree
* display
);
127 /** get a top-level expression by name */
128 VarTree
* topLevelExprByName(const char* name
);
129 /** return a member of the struct that pointer \a v refers to */
130 static VarTree
* ptrMemberByName(VarTree
* v
, const QString
& name
);
131 /** return a member of the struct \a v */
132 static VarTree
* memberByName(VarTree
* v
, const QString
& name
);
133 /** removes an expression; must be on the topmost level*/
134 void removeExpr(VarTree
* item
);
135 /** clears the list of pointers needing updates */
136 void clearPendingUpdates();
137 /** returns a pointer to update (or 0) and removes it from the list */
138 VarTree
* nextUpdatePtr();
139 VarTree
* nextUpdateType();
140 VarTree
* nextUpdateStruct();
141 void editValue(VarTree
* item
, const QString
& text
);
142 /** tells whether the a value is currently edited */
143 bool isEditing() const;
145 VarTree
* firstChild() const { return static_cast<VarTree
*>(QListView::firstChild()); }
146 VarTree
* currentItem() const { return static_cast<VarTree
*>(QListView::currentItem()); }
147 VarTree
* selectedItem() const { return static_cast<VarTree
*>(QListView::selectedItem()); }
150 bool updateExprRec(VarTree
* display
, ExprValue
* newValues
, ProgramTypeTable
& typeTable
);
151 void replaceChildren(VarTree
* display
, ExprValue
* newValues
);
152 void collectUnknownTypes(VarTree
* item
);
153 void checkUnknownType(VarTree
* item
);
154 static QString
formatWCharPointer(QString value
);
155 QPixmap m_pixPointer
;
157 QList
<VarTree
> m_updatePtrs
; /* dereferenced pointers that need update */
158 QList
<VarTree
> m_updateType
; /* structs whose type must be determined */
159 QList
<VarTree
> m_updateStruct
; /* structs whose nested value needs update */
163 /** remove items that are in the subTree from the list */
164 void unhookSubtree(VarTree
* subTree
);
165 static void unhookSubtree(QList
<VarTree
>& list
, VarTree
* subTree
);
168 void removingItem(VarTree
*);
169 void editValueCommitted(VarTree
*, const QString
&);