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 NKanonymous
, /* an anonymous struct or union */
31 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
, QListViewItem
* after
, ExprValue
* v
);
40 VarTree(ExprWnd
* parent
, QListViewItem
* after
, 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 regular value; returns whether a repaint is necessary */
49 bool updateValue(const QString
& newValue
);
50 /** update the "quick member" value; returns whether repaint is necessary */
51 bool updateStructValue(const QString
& newValue
);
52 /** find out the type of this value using the child values */
53 void inferTypesOfChildren(ProgramTypeTable
& typeTable
);
54 /** get the type from base class part */
55 TypeInfo
* inferTypeFromBaseClass();
56 /** returns whether the pointer is a wchar_t */
57 bool isWcharT() const;
59 QString
getText() const { return text(0); }
60 void setText(const QString
& t
) { QListViewItem::setText(0, t
); }
61 void setPixmap(const QPixmap
& p
) { QListViewItem::setPixmap(0, p
); }
62 QString
value() const { return m_baseValue
; }
63 VarTree
* firstChild() const { return static_cast<VarTree
*>(QListViewItem::firstChild()); }
64 VarTree
* nextSibling() const { return static_cast<VarTree
*>(QListViewItem::nextSibling()); }
67 void updateValueText();
68 QString m_baseValue
; //!< The "normal value" that the driver reported
69 QString m_structValue
; //!< The "quick member" value
70 bool m_baseChanged
: 1;
71 bool m_structChanged
: 1;
75 * Represents the value tree that is parsed by the debugger drivers.
81 VarTree::VarKind m_varKind
;
82 VarTree::NameKind m_nameKind
;
83 ExprValue
* m_child
; /* the first child expression */
84 ExprValue
* m_next
; /* the next sibling expression */
85 bool m_initiallyExpanded
;
87 ExprValue(const QString
& name
, VarTree::NameKind kind
);
90 void appendChild(ExprValue
* newChild
);
91 int childCount() const;
95 class ValueEdit
: public QLineEdit
99 ValueEdit(ExprWnd
* parent
);
102 void terminate(bool commit
);
106 void keyPressEvent(QKeyEvent
*e
);
107 void focusOutEvent(QFocusEvent
* ev
);
108 void paintEvent(QPaintEvent
* e
);
110 void slotSelectionChanged();
112 void done(VarTree
*, const QString
&);
116 class ExprWnd
: public QListView
120 ExprWnd(QWidget
* parent
, const QString
& colHeader
, const char* name
);
123 /** fills the list with the expressions at the topmost level */
124 void exprList(QStrList
& exprs
);
125 /** appends a copy of expr to the end of the tree at the topmost level;
126 * returns a pointer to the inserted top-level item */
127 VarTree
* insertExpr(ExprValue
* expr
, ProgramTypeTable
& typeTable
);
128 /** updates an existing expression */
129 void updateExpr(ExprValue
* expr
, ProgramTypeTable
& typeTable
);
130 void updateExpr(VarTree
* display
, ExprValue
* newValues
, ProgramTypeTable
& typeTable
);
131 /** updates the value and repaints it for a single item (not the children) */
132 void updateSingleExpr(VarTree
* display
, ExprValue
* newValues
);
133 /** updates only the value of the node */
134 void updateStructValue(VarTree
* display
);
135 /** get a top-level expression by name */
136 VarTree
* topLevelExprByName(const char* name
);
137 /** return a member of the struct that pointer \a v refers to */
138 static VarTree
* ptrMemberByName(VarTree
* v
, const QString
& name
);
139 /** return a member of the struct \a v */
140 static VarTree
* memberByName(VarTree
* v
, const QString
& name
);
141 /** removes an expression; must be on the topmost level*/
142 void removeExpr(VarTree
* item
);
143 /** clears the list of pointers needing updates */
144 void clearPendingUpdates();
145 /** returns a pointer to update (or 0) and removes it from the list */
146 VarTree
* nextUpdatePtr();
147 VarTree
* nextUpdateType();
148 VarTree
* nextUpdateStruct();
149 void editValue(VarTree
* item
, const QString
& text
);
150 /** tells whether the a value is currently edited */
151 bool isEditing() const;
153 VarTree
* firstChild() const { return static_cast<VarTree
*>(QListView::firstChild()); }
154 VarTree
* currentItem() const { return static_cast<VarTree
*>(QListView::currentItem()); }
155 VarTree
* selectedItem() const { return static_cast<VarTree
*>(QListView::selectedItem()); }
158 void updateExprRec(VarTree
* display
, ExprValue
* newValues
, ProgramTypeTable
& typeTable
);
159 void replaceChildren(VarTree
* display
, ExprValue
* newValues
);
160 void collectUnknownTypes(VarTree
* item
);
161 void checkUnknownType(VarTree
* item
);
162 static QString
formatWCharPointer(QString value
);
163 QPixmap m_pixPointer
;
165 QList
<VarTree
> m_updatePtrs
; /* dereferenced pointers that need update */
166 QList
<VarTree
> m_updateType
; /* structs whose type must be determined */
167 QList
<VarTree
> m_updateStruct
; /* structs whose nested value needs update */
171 /** remove items that are in the subTree from the list */
172 void unhookSubtree(VarTree
* subTree
);
173 static void unhookSubtree(QList
<VarTree
>& list
, VarTree
* subTree
);
176 void removingItem(VarTree
*);
177 void editValueCommitted(VarTree
*, const QString
&);