Keep the regular values and the "quick member" values separated.
[kdbg.git] / kdbg / exprwnd.h
blobd9d83ffba62a53814366a4c44cfda8edbec698ef
1 // $Id$
3 // Copyright by Johannes Sixt
4 // This file is under GPL, the GNU General Public Licence
6 #ifndef EXPRWND_H
7 #define EXPRWND_H
9 #include "qlistview.h"
10 #include <qlineedit.h>
11 #include <qpixmap.h>
12 #include <qptrlist.h>
13 #include <qstrlist.h>
15 class ProgramTypeTable;
16 class TypeInfo;
17 struct ExprValue;
18 class ExprWnd;
20 /* a variable's value is the tree of sub-variables */
22 class VarTree : public QListViewItem
24 public:
25 enum VarKind { VKsimple, VKpointer, VKstruct, VKarray,
26 VKdummy /* used to update only children */
28 VarKind m_varKind;
29 enum NameKind { NKplain, NKstatic, NKtype,
30 NKaddress /* a dereferenced pointer */
32 NameKind m_nameKind;
33 TypeInfo* m_type; /* type of struct */
34 int m_exprIndex; /* used in struct value update */
35 bool m_exprIndexUseGuard; /* ditto; if guard expr should be used */
36 QString m_partialValue; /* while struct value update is in progress */
38 VarTree(VarTree* parent, QListViewItem* after, ExprValue* v);
39 VarTree(ExprWnd* parent, QListViewItem* after, const QString& name);
40 virtual ~VarTree();
41 public:
42 virtual void paintCell(QPainter* p, const QColorGroup& cg, int column, int width, int align);
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 TypeInfo* inferTypeFromBaseClass();
55 /** returns whether the pointer is a wchar_t */
56 bool isWcharT() const;
58 QString getText() const { return text(0); }
59 void setText(const QString& t) { QListViewItem::setText(0, t); }
60 void setPixmap(const QPixmap& p) { QListViewItem::setPixmap(0, p); }
61 QString value() const { return m_baseValue; }
62 VarTree* firstChild() const { return static_cast<VarTree*>(QListViewItem::firstChild()); }
63 VarTree* nextSibling() const { return static_cast<VarTree*>(QListViewItem::nextSibling()); }
65 private:
66 void updateValueText();
67 QString m_baseValue; //!< The "normal value" that the driver reported
68 QString m_structValue; //!< The "quick member" value
69 bool m_baseChanged : 1;
70 bool m_structChanged : 1;
73 /**
74 * Represents the value tree that is parsed by the debugger drivers.
76 struct ExprValue
78 QString m_name;
79 QString m_value;
80 VarTree::VarKind m_varKind;
81 VarTree::NameKind m_nameKind;
82 ExprValue* m_child; /* the first child expression */
83 ExprValue* m_next; /* the next sibling expression */
84 bool m_initiallyExpanded;
86 ExprValue(const QString& name, VarTree::NameKind kind);
87 ~ExprValue();
89 void appendChild(ExprValue* newChild);
90 int childCount() const;
94 class ValueEdit : public QLineEdit
96 Q_OBJECT
97 public:
98 ValueEdit(ExprWnd* parent);
99 ~ValueEdit();
101 void terminate(bool commit);
102 VarTree* m_item;
103 bool m_finished;
104 protected:
105 void keyPressEvent(QKeyEvent *e);
106 void focusOutEvent(QFocusEvent* ev);
107 void paintEvent(QPaintEvent* e);
108 public slots:
109 void slotSelectionChanged();
110 signals:
111 void done(VarTree*, const QString&);
115 class ExprWnd : public QListView
117 Q_OBJECT
118 public:
119 ExprWnd(QWidget* parent, const QString& colHeader, const char* name);
120 ~ExprWnd();
122 /** fills the list with the expressions at the topmost level */
123 void exprList(QStrList& exprs);
124 /** appends a copy of expr to the end of the tree at the topmost level;
125 * returns a pointer to the inserted top-level item */
126 VarTree* insertExpr(ExprValue* expr, ProgramTypeTable& typeTable);
127 /** updates an existing expression */
128 void updateExpr(ExprValue* expr, ProgramTypeTable& typeTable);
129 void updateExpr(VarTree* display, ExprValue* newValues, ProgramTypeTable& typeTable);
130 /** updates the value and repaints it for a single item (not the children) */
131 void updateSingleExpr(VarTree* display, ExprValue* newValues);
132 /** updates only the value of the node */
133 void updateStructValue(VarTree* display);
134 /** get a top-level expression by name */
135 VarTree* topLevelExprByName(const char* name);
136 /** return a member of the struct that pointer \a v refers to */
137 static VarTree* ptrMemberByName(VarTree* v, const QString& name);
138 /** return a member of the struct \a v */
139 static VarTree* memberByName(VarTree* v, const QString& name);
140 /** removes an expression; must be on the topmost level*/
141 void removeExpr(VarTree* item);
142 /** clears the list of pointers needing updates */
143 void clearPendingUpdates();
144 /** returns a pointer to update (or 0) and removes it from the list */
145 VarTree* nextUpdatePtr();
146 VarTree* nextUpdateType();
147 VarTree* nextUpdateStruct();
148 void editValue(VarTree* item, const QString& text);
149 /** tells whether the a value is currently edited */
150 bool isEditing() const;
152 VarTree* firstChild() const { return static_cast<VarTree*>(QListView::firstChild()); }
153 VarTree* currentItem() const { return static_cast<VarTree*>(QListView::currentItem()); }
154 VarTree* selectedItem() const { return static_cast<VarTree*>(QListView::selectedItem()); }
156 protected:
157 bool updateExprRec(VarTree* display, ExprValue* newValues, ProgramTypeTable& typeTable);
158 void replaceChildren(VarTree* display, ExprValue* newValues);
159 void collectUnknownTypes(VarTree* item);
160 void checkUnknownType(VarTree* item);
161 static QString formatWCharPointer(QString value);
162 QPixmap m_pixPointer;
164 QList<VarTree> m_updatePtrs; /* dereferenced pointers that need update */
165 QList<VarTree> m_updateType; /* structs whose type must be determined */
166 QList<VarTree> m_updateStruct; /* structs whose nested value needs update */
168 ValueEdit* m_edit;
170 /** remove items that are in the subTree from the list */
171 void unhookSubtree(VarTree* subTree);
172 static void unhookSubtree(QList<VarTree>& list, VarTree* subTree);
174 signals:
175 void removingItem(VarTree*);
176 void editValueCommitted(VarTree*, const QString&);
179 #endif // EXPRWND_H