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 "q3listview.h"
11 #include <qlineedit.h>
13 #include <QPaintEvent>
14 #include <QFocusEvent>
18 class ProgramTypeTable
;
24 /*! \brief a variable's value is the tree of sub-variables */
25 class VarTree
: public Q3ListViewItem
28 enum VarKind
{ VKsimple
, VKpointer
, VKstruct
, VKarray
,
29 VKdummy
//!< used to update only children
32 enum NameKind
{ NKplain
, NKstatic
, NKtype
,
33 NKanonymous
, //!< an anonymous struct or union
34 NKaddress
//!< a dereferenced pointer
37 TypeInfo
* m_type
; //!< the type of struct if it could be derived
38 int m_exprIndex
; //!< used in struct value update
39 bool m_exprIndexUseGuard
; //!< ditto; if guard expr should be used
40 QString m_partialValue
; //!< while struct value update is in progress
42 VarTree(VarTree
* parent
, Q3ListViewItem
* after
, ExprValue
* v
);
43 VarTree(ExprWnd
* parent
, Q3ListViewItem
* after
, const QString
& name
);
46 virtual void paintCell(QPainter
* p
, const QColorGroup
& cg
, int column
, int width
, int align
);
47 QString
computeExpr() const;
48 bool isToplevelExpr() const;
49 /** is this element an ancestor of (or equal to) child? */
50 bool isAncestorEq(const VarTree
* child
) const;
51 /** update the regular value; returns whether a repaint is necessary */
52 bool updateValue(const QString
& newValue
);
53 /** update the "quick member" value; returns whether repaint is necessary */
54 bool updateStructValue(const QString
& newValue
);
55 /** find out the type of this value using the child values */
56 void inferTypesOfChildren(ProgramTypeTable
& typeTable
);
57 /** get the type from base class part */
58 TypeInfo
* inferTypeFromBaseClass();
59 /** returns whether the pointer is a wchar_t */
60 bool isWcharT() const;
62 QString
getText() const { return text(0); }
63 void setText(const QString
& t
) { Q3ListViewItem::setText(0, t
); }
64 void setPixmap(const QPixmap
& p
) { Q3ListViewItem::setPixmap(0, p
); }
65 QString
value() const { return m_baseValue
; }
66 VarTree
* firstChild() const { return static_cast<VarTree
*>(Q3ListViewItem::firstChild()); }
67 VarTree
* nextSibling() const { return static_cast<VarTree
*>(Q3ListViewItem::nextSibling()); }
70 void updateValueText();
71 QString m_baseValue
; //!< The "normal value" that the driver reported
72 QString m_structValue
; //!< The "quick member" value
73 bool m_baseChanged
: 1;
74 bool m_structChanged
: 1;
78 * Represents the value tree that is parsed by the debugger drivers.
84 VarTree::VarKind m_varKind
;
85 VarTree::NameKind m_nameKind
;
86 ExprValue
* m_child
; /* the first child expression */
87 ExprValue
* m_next
; /* the next sibling expression */
88 bool m_initiallyExpanded
;
90 ExprValue(const QString
& name
, VarTree::NameKind kind
);
93 void appendChild(ExprValue
* newChild
);
94 int childCount() const;
98 class ValueEdit
: public QLineEdit
102 ValueEdit(ExprWnd
* parent
);
105 void terminate(bool commit
);
109 void keyPressEvent(QKeyEvent
*e
);
110 void focusOutEvent(QFocusEvent
* ev
);
111 void paintEvent(QPaintEvent
* e
);
113 void slotSelectionChanged();
115 void done(VarTree
*, const QString
&);
119 class ExprWnd
: public Q3ListView
123 ExprWnd(QWidget
* parent
, const QString
& colHeader
);
126 /** returns the list with the expressions at the topmost level */
127 QStringList
exprList() const;
128 /** appends a copy of expr to the end of the tree at the topmost level;
129 * returns a pointer to the inserted top-level item */
130 VarTree
* insertExpr(ExprValue
* expr
, ProgramTypeTable
& typeTable
);
131 /** updates an existing expression */
132 void updateExpr(ExprValue
* expr
, ProgramTypeTable
& typeTable
);
133 void updateExpr(VarTree
* display
, ExprValue
* newValues
, ProgramTypeTable
& typeTable
);
134 /** updates the value and repaints it for a single item (not the children) */
135 void updateSingleExpr(VarTree
* display
, ExprValue
* newValues
);
136 /** updates only the value of the node */
137 void updateStructValue(VarTree
* display
);
138 /** get a top-level expression by name */
139 VarTree
* topLevelExprByName(const QString
& name
) const;
140 /** return a member of the struct that pointer \a v refers to */
141 static VarTree
* ptrMemberByName(VarTree
* v
, const QString
& name
);
142 /** return a member of the struct \a v */
143 static VarTree
* memberByName(VarTree
* v
, const QString
& name
);
144 /** removes an expression; must be on the topmost level*/
145 void removeExpr(VarTree
* item
);
146 /** clears the list of pointers needing updates */
147 void clearPendingUpdates();
148 /** returns a pointer to update (or 0) and removes it from the list */
149 VarTree
* nextUpdatePtr();
150 VarTree
* nextUpdateType();
151 VarTree
* nextUpdateStruct();
152 void editValue(VarTree
* item
, const QString
& text
);
153 /** tells whether the a value is currently edited */
154 bool isEditing() const;
156 VarTree
* firstChild() const { return static_cast<VarTree
*>(Q3ListView::firstChild()); }
157 VarTree
* currentItem() const { return static_cast<VarTree
*>(Q3ListView::currentItem()); }
158 VarTree
* selectedItem() const { return static_cast<VarTree
*>(Q3ListView::selectedItem()); }
161 void updateExprRec(VarTree
* display
, ExprValue
* newValues
, ProgramTypeTable
& typeTable
);
162 void replaceChildren(VarTree
* display
, ExprValue
* newValues
);
163 void collectUnknownTypes(VarTree
* item
);
164 void checkUnknownType(VarTree
* item
);
165 static QString
formatWCharPointer(QString value
);
166 QPixmap m_pixPointer
;
168 std::list
<VarTree
*> m_updatePtrs
; //!< dereferenced pointers that need update
169 std::list
<VarTree
*> m_updateType
; //!< structs whose type must be determined
170 std::list
<VarTree
*> m_updateStruct
; //!< structs whose nested value needs update
174 /** remove items that are in the subTree from the list */
175 void unhookSubtree(VarTree
* subTree
);
176 static void unhookSubtree(std::list
<VarTree
*>& list
, VarTree
* subTree
);
179 void removingItem(VarTree
*);
180 void editValueCommitted(VarTree
*, const QString
&);