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 <QTreeWidget>
15 class ProgramTypeTable
;
21 /*! \brief a variable's value is the tree of sub-variables */
22 class VarTree
: public QTreeWidgetItem
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 const TypeInfo
* m_type
; //!< the type of struct if it could be derived
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
, ExprValue
* v
);
43 QString
computeExpr() const;
44 bool isToplevelExpr() const;
45 /** is this element an ancestor of (or equal to) child? */
46 bool isAncestorEq(const VarTree
* child
) const;
47 /** update the regular value; returns whether a repaint is necessary */
48 bool updateValue(const QString
& newValue
);
49 /** update the "quick member" value; returns whether repaint is necessary */
50 bool updateStructValue(const QString
& newValue
);
51 /** find out the type of this value using the child values */
52 void inferTypesOfChildren(ProgramTypeTable
& typeTable
);
53 /** get the type from base class part */
54 const TypeInfo
* inferTypeFromBaseClass();
55 /** returns whether the pointer is a wchar_t */
56 bool isWcharT() const;
58 QString
getText() const { return text(0); }
59 using QTreeWidgetItem::setText
;
60 void setText(const QString
& t
) { QTreeWidgetItem::setText(0, t
); }
61 void setPixmap(const QPixmap
& p
) { QTreeWidgetItem::setIcon(0, QIcon(p
)); }
62 QString
value() const { return m_baseValue
; }
63 VarTree
* child(int i
) const { return static_cast<VarTree
*>(QTreeWidgetItem::child(i
)); }
65 virtual QVariant
data(int column
, int role
) const;
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 QTreeWidget
121 ExprWnd(QWidget
* parent
, const QString
& colHeader
);
124 /** returns the list with the expressions at the topmost level */
125 QStringList
exprList() const;
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 QString
& name
) const;
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
* selectedItem() const { return static_cast<VarTree
*>(QTreeWidget::currentItem()); }
155 VarTree
* topLevelItem(int i
) const { return static_cast<VarTree
*>(QTreeWidget::topLevelItem(i
)); }
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 std::list
<VarTree
*> m_updatePtrs
; //!< dereferenced pointers that need update
166 std::list
<VarTree
*> m_updateType
; //!< structs whose type must be determined
167 std::list
<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(std::list
<VarTree
*>& list
, VarTree
* subTree
);
176 void removingItem(VarTree
*);
177 void editValueCommitted(VarTree
*, const QString
&);