Make the value edit window a pointer rather then a member object.
[kdbg.git] / kdbg / exprwnd.h
blob97d77391fac9667d0835835fd3c8258c2e776a16
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 "ktreeview.h"
10 #include <qlineedit.h>
11 #include <qptrlist.h>
12 #include <qstrlist.h>
14 class ProgramTypeTable;
15 class TypeInfo;
16 struct ExprValue;
18 /* a variable's value is the tree of sub-variables */
20 class VarTree : public KTreeViewItem
22 public:
23 enum VarKind { VKsimple, VKpointer, VKstruct, VKarray,
24 VKdummy /* used to update only children */
26 VarKind m_varKind;
27 enum NameKind { NKplain, NKstatic, NKtype,
28 NKaddress /* a dereferenced pointer */
30 NameKind m_nameKind;
31 bool m_valueChanged;
32 TypeInfo* m_type; /* type of struct */
33 int m_exprIndex; /* used in struct value update */
34 bool m_exprIndexUseGuard; /* ditto; if guard expr should be used */
35 QString m_partialValue; /* while struct value update is in progress */
37 VarTree(ExprValue* v);
38 VarTree(const QString& name);
39 virtual ~VarTree();
40 public:
41 void paintValue(QPainter* painter);
42 int valueWidth();
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 value; return if repaint is necessary */
48 bool updateValue(const QString& newValue);
49 /** find out the type of this value using the child values */
50 void inferTypesOfChildren(ProgramTypeTable& typeTable);
51 /** get the type from base class part */
52 TypeInfo* inferTypeFromBaseClass();
53 /** returns whether the pointer is a wchar_t */
54 bool isWcharT() const;
56 void setValue(const QString& v) { m_value = v; }
57 QString value() const { return m_value; }
58 VarTree* firstChild() const { return static_cast<VarTree*>(getChild()); }
59 VarTree* nextSibling() const { return static_cast<VarTree*>(getSibling()); }
61 private:
62 QString m_value;
65 /**
66 * Represents the value tree that is parsed by the debugger drivers.
68 struct ExprValue
70 QString m_name;
71 QString m_value;
72 VarTree::VarKind m_varKind;
73 VarTree::NameKind m_nameKind;
74 ExprValue* m_child; /* the first child expression */
75 ExprValue* m_next; /* the next sibling expression */
76 bool m_initiallyExpanded;
78 ExprValue(const QString& name, VarTree::NameKind kind);
79 ~ExprValue();
81 void appendChild(ExprValue* newChild);
82 uint childCount() const;
86 class ExprWnd;
88 class ValueEdit : public QLineEdit
90 Q_OBJECT
91 public:
92 ValueEdit(ExprWnd* parent);
93 ~ValueEdit();
95 void terminate(bool commit);
96 int m_row;
97 bool m_finished;
98 protected:
99 void keyPressEvent(QKeyEvent *e);
100 void focusOutEvent(QFocusEvent* ev);
101 void paintEvent(QPaintEvent* e);
102 public slots:
103 void slotSelectionChanged();
104 signals:
105 void done(int, const QString&);
109 class ExprWnd : public KTreeView
111 Q_OBJECT
112 public:
113 ExprWnd(QWidget* parent, const char* name);
114 ~ExprWnd();
116 /** fills the list with the expressions at the topmost level */
117 void exprList(QStrList& exprs);
118 /** appends a copy of expr to the end of the tree at the topmost level;
119 * returns a pointer to the inserted top-level item */
120 VarTree* insertExpr(ExprValue* expr, ProgramTypeTable& typeTable);
121 /** updates an existing expression */
122 void updateExpr(ExprValue* expr, ProgramTypeTable& typeTable);
123 void updateExpr(VarTree* display, ExprValue* newValues, ProgramTypeTable& typeTable);
124 /** updates the value and repaints it for a single item (not the children) */
125 void updateSingleExpr(VarTree* display, ExprValue* newValues);
126 /** updates only the value of the node */
127 void updateStructValue(VarTree* display);
128 /** get a top-level expression by name */
129 VarTree* topLevelExprByName(const char* name);
130 /** return a member of the struct that pointer \a v refers to */
131 static VarTree* ptrMemberByName(VarTree* v, const QString& name);
132 /** return a member of the struct \a v */
133 static VarTree* memberByName(VarTree* v, const QString& name);
134 /** removes an expression; must be on the topmost level*/
135 void removeExpr(VarTree* item);
136 /** clears the list of pointers needing updates */
137 void clearPendingUpdates();
138 /** returns a pointer to update (or 0) and removes it from the list */
139 VarTree* nextUpdatePtr();
140 VarTree* nextUpdateType();
141 VarTree* nextUpdateStruct();
142 void editValue(int row, const QString& text);
143 /** tells whether the a value is currently edited */
144 bool isEditing() const;
146 VarTree* firstChild() const { return static_cast<VarTree*>(itemAt(0)); }
147 VarTree* selectedItem() const { return static_cast<VarTree*>(getCurrentItem()); }
149 protected:
150 bool updateExprRec(VarTree* display, ExprValue* newValues, ProgramTypeTable& typeTable);
151 void replaceChildren(VarTree* display, ExprValue* newValues);
152 virtual void paintCell(QPainter* painter, int row, int col);
153 virtual int cellWidth(int col) const;
154 void updateValuesWidth();
155 static bool getMaxValueWidth(KTreeViewItem* item, void* user);
156 void collectUnknownTypes(VarTree* item);
157 static bool collectUnknownTypes(KTreeViewItem* item, void* user);
158 static QString formatWCharPointer(QString value);
159 int maxValueWidth;
160 QPixmap m_pixPointer;
162 QList<VarTree> m_updatePtrs; /* dereferenced pointers that need update */
163 QList<VarTree> m_updateType; /* structs whose type must be determined */
164 QList<VarTree> m_updateStruct; /* structs whose nested value needs update */
166 ValueEdit* m_edit;
168 /** remove items that are in the subTree from the list */
169 void unhookSubtree(VarTree* subTree);
170 static void unhookSubtree(QList<VarTree>& list, VarTree* subTree);
172 protected slots:
173 void slotExpandOrCollapse(int);
175 signals:
176 void removingItem(VarTree*);
177 void editValueCommitted(int, const QString&);
180 #endif // EXPRWND_H