Update the admin/ directory.
[kdbg.git] / kdbg / exprwnd.h
blobf6f78a1c3c54111743b145dc827bb3578e472439
1 /*
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.
5 */
7 #ifndef EXPRWND_H
8 #define EXPRWND_H
10 #include "qlistview.h"
11 #include <qlineedit.h>
12 #include <qpixmap.h>
13 #include <qptrlist.h>
14 #include <qstrlist.h>
16 class ProgramTypeTable;
17 class TypeInfo;
18 struct ExprValue;
19 class ExprWnd;
21 /* a variable's value is the tree of sub-variables */
23 class VarTree : public QListViewItem
25 public:
26 enum VarKind { VKsimple, VKpointer, VKstruct, VKarray,
27 VKdummy /* used to update only children */
29 VarKind m_varKind;
30 enum NameKind { NKplain, NKstatic, NKtype,
31 NKanonymous, /* an anonymous struct or union */
32 NKaddress /* a dereferenced pointer */
34 NameKind m_nameKind;
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);
42 virtual ~VarTree();
43 public:
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()); }
67 private:
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;
75 /**
76 * Represents the value tree that is parsed by the debugger drivers.
78 struct ExprValue
80 QString m_name;
81 QString m_value;
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);
89 ~ExprValue();
91 void appendChild(ExprValue* newChild);
92 int childCount() const;
96 class ValueEdit : public QLineEdit
98 Q_OBJECT
99 public:
100 ValueEdit(ExprWnd* parent);
101 ~ValueEdit();
103 void terminate(bool commit);
104 VarTree* m_item;
105 bool m_finished;
106 protected:
107 void keyPressEvent(QKeyEvent *e);
108 void focusOutEvent(QFocusEvent* ev);
109 void paintEvent(QPaintEvent* e);
110 public slots:
111 void slotSelectionChanged();
112 signals:
113 void done(VarTree*, const QString&);
117 class ExprWnd : public QListView
119 Q_OBJECT
120 public:
121 ExprWnd(QWidget* parent, const QString& colHeader, const char* name);
122 ~ExprWnd();
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()); }
158 protected:
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 */
170 ValueEdit* m_edit;
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);
176 signals:
177 void removingItem(VarTree*);
178 void editValueCommitted(VarTree*, const QString&);
181 #endif // EXPRWND_H