2 * Copyright Johannes Sixt
3 * This file is licensed under the GNU General Public License Version 2.
4 * See the file COPYING in the toplevel directory of the source directory.
10 #include "qlistview.h"
11 #include <qlineedit.h>
16 class ProgramTypeTable
;
21 /* a variable's value is the tree of sub-variables */
23 class VarTree
: public QListViewItem
26 enum VarKind
{ VKsimple
, VKpointer
, VKstruct
, VKarray
,
27 VKdummy
/* used to update only children */
30 enum NameKind
{ NKplain
, NKstatic
, NKtype
,
31 NKanonymous
, /* an anonymous struct or union */
32 NKaddress
/* a dereferenced pointer */
35 TypeInfo
* m_type
; /* type of struct */
36 int m_exprIndex
; /* used in struct value update */
37 bool m_exprIndexUseGuard
; /* ditto; if guard expr should be used */
38 QString m_partialValue
; /* while struct value update is in progress */
40 VarTree(VarTree
* parent
, QListViewItem
* after
, ExprValue
* v
);
41 VarTree(ExprWnd
* parent
, QListViewItem
* after
, const QString
& name
);
44 virtual void paintCell(QPainter
* p
, const QColorGroup
& cg
, int column
, int width
, int align
);
45 QString
computeExpr() const;
46 bool isToplevelExpr() const;
47 /** is this element an ancestor of (or equal to) child? */
48 bool isAncestorEq(const VarTree
* child
) const;
49 /** update the regular value; returns whether a repaint is necessary */
50 bool updateValue(const QString
& newValue
);
51 /** update the "quick member" value; returns whether repaint is necessary */
52 bool updateStructValue(const QString
& newValue
);
53 /** find out the type of this value using the child values */
54 void inferTypesOfChildren(ProgramTypeTable
& typeTable
);
55 /** get the type from base class part */
56 TypeInfo
* inferTypeFromBaseClass();
57 /** returns whether the pointer is a wchar_t */
58 bool isWcharT() const;
60 QString
getText() const { return text(0); }
61 void setText(const QString
& t
) { QListViewItem::setText(0, t
); }
62 void setPixmap(const QPixmap
& p
) { QListViewItem::setPixmap(0, p
); }
63 QString
value() const { return m_baseValue
; }
64 VarTree
* firstChild() const { return static_cast<VarTree
*>(QListViewItem::firstChild()); }
65 VarTree
* nextSibling() const { return static_cast<VarTree
*>(QListViewItem::nextSibling()); }
68 void updateValueText();
69 QString m_baseValue
; //!< The "normal value" that the driver reported
70 QString m_structValue
; //!< The "quick member" value
71 bool m_baseChanged
: 1;
72 bool m_structChanged
: 1;
76 * Represents the value tree that is parsed by the debugger drivers.
82 VarTree::VarKind m_varKind
;
83 VarTree::NameKind m_nameKind
;
84 ExprValue
* m_child
; /* the first child expression */
85 ExprValue
* m_next
; /* the next sibling expression */
86 bool m_initiallyExpanded
;
88 ExprValue(const QString
& name
, VarTree::NameKind kind
);
91 void appendChild(ExprValue
* newChild
);
92 int childCount() const;
96 class ValueEdit
: public QLineEdit
100 ValueEdit(ExprWnd
* parent
);
103 void terminate(bool commit
);
107 void keyPressEvent(QKeyEvent
*e
);
108 void focusOutEvent(QFocusEvent
* ev
);
109 void paintEvent(QPaintEvent
* e
);
111 void slotSelectionChanged();
113 void done(VarTree
*, const QString
&);
117 class ExprWnd
: public QListView
121 ExprWnd(QWidget
* parent
, const QString
& colHeader
, const char* name
);
124 /** fills the list with the expressions at the topmost level */
125 void exprList(QStrList
& exprs
);
126 /** appends a copy of expr to the end of the tree at the topmost level;
127 * returns a pointer to the inserted top-level item */
128 VarTree
* insertExpr(ExprValue
* expr
, ProgramTypeTable
& typeTable
);
129 /** updates an existing expression */
130 void updateExpr(ExprValue
* expr
, ProgramTypeTable
& typeTable
);
131 void updateExpr(VarTree
* display
, ExprValue
* newValues
, ProgramTypeTable
& typeTable
);
132 /** updates the value and repaints it for a single item (not the children) */
133 void updateSingleExpr(VarTree
* display
, ExprValue
* newValues
);
134 /** updates only the value of the node */
135 void updateStructValue(VarTree
* display
);
136 /** get a top-level expression by name */
137 VarTree
* topLevelExprByName(const char* name
);
138 /** return a member of the struct that pointer \a v refers to */
139 static VarTree
* ptrMemberByName(VarTree
* v
, const QString
& name
);
140 /** return a member of the struct \a v */
141 static VarTree
* memberByName(VarTree
* v
, const QString
& name
);
142 /** removes an expression; must be on the topmost level*/
143 void removeExpr(VarTree
* item
);
144 /** clears the list of pointers needing updates */
145 void clearPendingUpdates();
146 /** returns a pointer to update (or 0) and removes it from the list */
147 VarTree
* nextUpdatePtr();
148 VarTree
* nextUpdateType();
149 VarTree
* nextUpdateStruct();
150 void editValue(VarTree
* item
, const QString
& text
);
151 /** tells whether the a value is currently edited */
152 bool isEditing() const;
154 VarTree
* firstChild() const { return static_cast<VarTree
*>(QListView::firstChild()); }
155 VarTree
* currentItem() const { return static_cast<VarTree
*>(QListView::currentItem()); }
156 VarTree
* selectedItem() const { return static_cast<VarTree
*>(QListView::selectedItem()); }
159 void updateExprRec(VarTree
* display
, ExprValue
* newValues
, ProgramTypeTable
& typeTable
);
160 void replaceChildren(VarTree
* display
, ExprValue
* newValues
);
161 void collectUnknownTypes(VarTree
* item
);
162 void checkUnknownType(VarTree
* item
);
163 static QString
formatWCharPointer(QString value
);
164 QPixmap m_pixPointer
;
166 QList
<VarTree
> m_updatePtrs
; /* dereferenced pointers that need update */
167 QList
<VarTree
> m_updateType
; /* structs whose type must be determined */
168 QList
<VarTree
> m_updateStruct
; /* structs whose nested value needs update */
172 /** remove items that are in the subTree from the list */
173 void unhookSubtree(VarTree
* subTree
);
174 static void unhookSubtree(QList
<VarTree
>& list
, VarTree
* subTree
);
177 void removingItem(VarTree
*);
178 void editValueCommitted(VarTree
*, const QString
&);