Do not insert new values in reversed order.
[kdbg.git] / kdbg / exprwnd.h
blob34e2b3c92f2083b3425d0f280428e9b6681f16b9
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 bool m_valueChanged;
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);
41 virtual ~VarTree();
42 public:
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 value; return if repaint is necessary */
49 bool updateValue(const QString& newValue);
50 /** find out the type of this value using the child values */
51 void inferTypesOfChildren(ProgramTypeTable& typeTable);
52 /** get the type from base class part */
53 TypeInfo* inferTypeFromBaseClass();
54 /** returns whether the pointer is a wchar_t */
55 bool isWcharT() const;
57 QString getText() const { return text(0); }
58 void setText(const QString& t) { QListViewItem::setText(0, t); }
59 void setPixmap(const QPixmap& p) { QListViewItem::setPixmap(0, p); }
60 void setValue(const QString& v) { QListViewItem::setText(1, v); }
61 QString value() const { return text(1); }
62 VarTree* firstChild() const { return static_cast<VarTree*>(QListViewItem::firstChild()); }
63 VarTree* nextSibling() const { return static_cast<VarTree*>(QListViewItem::nextSibling()); }
66 /**
67 * Represents the value tree that is parsed by the debugger drivers.
69 struct ExprValue
71 QString m_name;
72 QString m_value;
73 VarTree::VarKind m_varKind;
74 VarTree::NameKind m_nameKind;
75 ExprValue* m_child; /* the first child expression */
76 ExprValue* m_next; /* the next sibling expression */
77 bool m_initiallyExpanded;
79 ExprValue(const QString& name, VarTree::NameKind kind);
80 ~ExprValue();
82 void appendChild(ExprValue* newChild);
83 int childCount() const;
87 class ValueEdit : public QLineEdit
89 Q_OBJECT
90 public:
91 ValueEdit(ExprWnd* parent);
92 ~ValueEdit();
94 void terminate(bool commit);
95 VarTree* m_item;
96 bool m_finished;
97 protected:
98 void keyPressEvent(QKeyEvent *e);
99 void focusOutEvent(QFocusEvent* ev);
100 void paintEvent(QPaintEvent* e);
101 public slots:
102 void slotSelectionChanged();
103 signals:
104 void done(VarTree*, const QString&);
108 class ExprWnd : public QListView
110 Q_OBJECT
111 public:
112 ExprWnd(QWidget* parent, const QString& colHeader, const char* name);
113 ~ExprWnd();
115 /** fills the list with the expressions at the topmost level */
116 void exprList(QStrList& exprs);
117 /** appends a copy of expr to the end of the tree at the topmost level;
118 * returns a pointer to the inserted top-level item */
119 VarTree* insertExpr(ExprValue* expr, ProgramTypeTable& typeTable);
120 /** updates an existing expression */
121 void updateExpr(ExprValue* expr, ProgramTypeTable& typeTable);
122 void updateExpr(VarTree* display, ExprValue* newValues, ProgramTypeTable& typeTable);
123 /** updates the value and repaints it for a single item (not the children) */
124 void updateSingleExpr(VarTree* display, ExprValue* newValues);
125 /** updates only the value of the node */
126 void updateStructValue(VarTree* display);
127 /** get a top-level expression by name */
128 VarTree* topLevelExprByName(const char* name);
129 /** return a member of the struct that pointer \a v refers to */
130 static VarTree* ptrMemberByName(VarTree* v, const QString& name);
131 /** return a member of the struct \a v */
132 static VarTree* memberByName(VarTree* v, const QString& name);
133 /** removes an expression; must be on the topmost level*/
134 void removeExpr(VarTree* item);
135 /** clears the list of pointers needing updates */
136 void clearPendingUpdates();
137 /** returns a pointer to update (or 0) and removes it from the list */
138 VarTree* nextUpdatePtr();
139 VarTree* nextUpdateType();
140 VarTree* nextUpdateStruct();
141 void editValue(VarTree* item, const QString& text);
142 /** tells whether the a value is currently edited */
143 bool isEditing() const;
145 VarTree* firstChild() const { return static_cast<VarTree*>(QListView::firstChild()); }
146 VarTree* currentItem() const { return static_cast<VarTree*>(QListView::currentItem()); }
147 VarTree* selectedItem() const { return static_cast<VarTree*>(QListView::selectedItem()); }
149 protected:
150 bool updateExprRec(VarTree* display, ExprValue* newValues, ProgramTypeTable& typeTable);
151 void replaceChildren(VarTree* display, ExprValue* newValues);
152 void collectUnknownTypes(VarTree* item);
153 void checkUnknownType(VarTree* item);
154 static QString formatWCharPointer(QString value);
155 QPixmap m_pixPointer;
157 QList<VarTree> m_updatePtrs; /* dereferenced pointers that need update */
158 QList<VarTree> m_updateType; /* structs whose type must be determined */
159 QList<VarTree> m_updateStruct; /* structs whose nested value needs update */
161 ValueEdit* m_edit;
163 /** remove items that are in the subTree from the list */
164 void unhookSubtree(VarTree* subTree);
165 static void unhookSubtree(QList<VarTree>& list, VarTree* subTree);
167 signals:
168 void removingItem(VarTree*);
169 void editValueCommitted(VarTree*, const QString&);
172 #endif // EXPRWND_H