Try to find values for value popups in members of 'this'.
[kdbg.git] / kdbg / exprwnd.h
blobb418c1aaf62248712f21756cf0fa65abf8ec002f
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;
17 /* a variable's value is the tree of sub-variables */
19 class VarTree : public KTreeViewItem
21 public:
22 enum VarKind { VKsimple, VKpointer, VKstruct, VKarray,
23 VKdummy /* used to update only children */
25 VarKind m_varKind;
26 enum NameKind { NKplain, NKstatic, NKtype,
27 NKaddress /* a dereferenced pointer */
29 NameKind m_nameKind;
30 QString m_value;
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(const QString& name, NameKind kind);
38 virtual ~VarTree();
39 public:
40 void paintValue(QPainter* painter);
41 int valueWidth();
42 QString computeExpr() const;
43 bool isToplevelExpr() const;
44 /** is this element an ancestor of (or equal to) child? */
45 bool isAncestorEq(const VarTree* child) const;
46 /** update the value; return if repaint is necessary */
47 bool updateValue(const QString& newValue);
48 /** find out the type of this value using the child values */
49 void inferTypesOfChildren(ProgramTypeTable& typeTable);
50 /** get the type from base class part */
51 TypeInfo* inferTypeFromBaseClass();
55 class ExprWnd;
57 class ValueEdit : public QLineEdit
59 Q_OBJECT
60 public:
61 ValueEdit(ExprWnd* parent);
62 ~ValueEdit();
64 void terminate(bool commit);
65 int m_row;
66 bool m_finished;
67 protected:
68 void keyPressEvent(QKeyEvent *e);
69 void focusOutEvent(QFocusEvent* ev);
70 void paintEvent(QPaintEvent* e);
71 public slots:
72 void slotSelectionChanged();
73 signals:
74 void done(int, const QString&);
78 class ExprWnd : public KTreeView
80 Q_OBJECT
81 public:
82 ExprWnd(QWidget* parent, const char* name);
83 ~ExprWnd();
85 /** fills the list with the expressions at the topmost level */
86 void exprList(QStrList& exprs);
87 /** appends var the the end of the tree at the topmost level */
88 void insertExpr(VarTree* expr);
89 /** updates an existing expression */
90 void updateExpr(VarTree* expr);
91 void updateExpr(VarTree* display, VarTree* newValues);
92 /** updates the value and repaints it for a single item (not the children) */
93 void updateSingleExpr(VarTree* display, VarTree* newValues);
94 /** updates only the value of the node */
95 void updateStructValue(VarTree* display);
96 /** get a top-level expression by name */
97 VarTree* topLevelExprByName(const char* name);
98 /** return a member of the struct that pointer \a v refers to */
99 static VarTree* ptrMemberByName(VarTree* v, const QString& name);
100 /** removes an expression; must be on the topmost level*/
101 void removeExpr(VarTree* item);
102 /** retrieves the expression string at the specified line */
103 QString exprStringAt(int index);
104 /** clears the list of pointers needing updates */
105 void clearPendingUpdates();
106 /** returns a pointer to update (or 0) and removes it from the list */
107 VarTree* nextUpdatePtr();
108 VarTree* nextUpdateType();
109 VarTree* nextUpdateStruct();
110 void editValue(int row, const QString& text);
111 /** tells whether the a value is currently edited */
112 bool isEditing() const;
114 protected:
115 bool updateExprRec(VarTree* display, VarTree* newValues);
116 void replaceChildren(VarTree* display, VarTree* newValues);
117 virtual void paintCell(QPainter* painter, int row, int col);
118 virtual int cellWidth(int col) const;
119 void updateValuesWidth();
120 static bool getMaxValueWidth(KTreeViewItem* item, void* user);
121 void collectUnknownTypes(VarTree* item);
122 static bool collectUnknownTypes(KTreeViewItem* item, void* user);
123 int maxValueWidth;
124 QPixmap m_pixPointer;
126 QList<VarTree> m_updatePtrs; /* dereferenced pointers that need update */
127 QList<VarTree> m_updateType; /* structs whose type must be determined */
128 QList<VarTree> m_updateStruct; /* structs whose nested value needs update */
130 ValueEdit m_edit;
132 /** remove items that are in the subTree from the list */
133 static void sweepList(QList<VarTree>& list, VarTree* subTree);
135 protected slots:
136 void slotExpandOrCollapse(int);
138 signals:
139 void editValueCommitted(int, const QString&);
142 #endif // EXPRWND_H