3 // Copyright by Johannes Sixt
4 // This file is under GPL, the GNU General Public Licence
10 #include <qlineedit.h>
14 class ProgramTypeTable
;
17 /* a variable's value is the tree of sub-variables */
19 class VarTree
: public KTreeViewItem
22 enum VarKind
{ VKsimple
, VKpointer
, VKstruct
, VKarray
,
23 VKdummy
/* used to update only children */
26 enum NameKind
{ NKplain
, NKstatic
, NKtype
,
27 NKaddress
/* a dereferenced pointer */
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
);
40 void paintValue(QPainter
* painter
);
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();
52 /** returns whether the pointer is a wchar_t */
53 bool isWcharT() const;
59 class ValueEdit
: public QLineEdit
63 ValueEdit(ExprWnd
* parent
);
66 void terminate(bool commit
);
70 void keyPressEvent(QKeyEvent
*e
);
71 void focusOutEvent(QFocusEvent
* ev
);
72 void paintEvent(QPaintEvent
* e
);
74 void slotSelectionChanged();
76 void done(int, const QString
&);
80 class ExprWnd
: public KTreeView
84 ExprWnd(QWidget
* parent
, const char* name
);
87 /** fills the list with the expressions at the topmost level */
88 void exprList(QStrList
& exprs
);
89 /** appends a copy of expr to the end of the tree at the topmost level;
90 * returns a pointer to the inserted top-level item */
91 VarTree
* insertExpr(VarTree
* expr
);
92 /** updates an existing expression */
93 void updateExpr(VarTree
* expr
);
94 void updateExpr(VarTree
* display
, VarTree
* newValues
);
95 /** updates the value and repaints it for a single item (not the children) */
96 void updateSingleExpr(VarTree
* display
, VarTree
* newValues
);
97 /** updates only the value of the node */
98 void updateStructValue(VarTree
* display
);
99 /** get a top-level expression by name */
100 VarTree
* topLevelExprByName(const char* name
);
101 /** return a member of the struct that pointer \a v refers to */
102 static VarTree
* ptrMemberByName(VarTree
* v
, const QString
& name
);
103 /** return a member of the struct \a v */
104 static VarTree
* memberByName(VarTree
* v
, const QString
& name
);
105 /** removes an expression; must be on the topmost level*/
106 void removeExpr(VarTree
* item
);
107 /** clears the list of pointers needing updates */
108 void clearPendingUpdates();
109 /** returns a pointer to update (or 0) and removes it from the list */
110 VarTree
* nextUpdatePtr();
111 VarTree
* nextUpdateType();
112 VarTree
* nextUpdateStruct();
113 void editValue(int row
, const QString
& text
);
114 /** tells whether the a value is currently edited */
115 bool isEditing() const;
117 VarTree
* selectedItem() const { return static_cast<VarTree
*>(getCurrentItem()); }
120 bool updateExprRec(VarTree
* display
, VarTree
* newValues
);
121 void replaceChildren(VarTree
* display
, VarTree
* newValues
);
122 virtual void paintCell(QPainter
* painter
, int row
, int col
);
123 virtual int cellWidth(int col
) const;
124 void updateValuesWidth();
125 static bool getMaxValueWidth(KTreeViewItem
* item
, void* user
);
126 void collectUnknownTypes(VarTree
* item
);
127 static bool collectUnknownTypes(KTreeViewItem
* item
, void* user
);
128 static QString
formatWCharPointer(QString value
);
130 QPixmap m_pixPointer
;
132 QList
<VarTree
> m_updatePtrs
; /* dereferenced pointers that need update */
133 QList
<VarTree
> m_updateType
; /* structs whose type must be determined */
134 QList
<VarTree
> m_updateStruct
; /* structs whose nested value needs update */
138 /** remove items that are in the subTree from the list */
139 void unhookSubtree(VarTree
* subTree
);
140 static void unhookSubtree(QList
<VarTree
>& list
, VarTree
* subTree
);
143 void slotExpandOrCollapse(int);
146 void removingItem(VarTree
*);
147 void editValueCommitted(int, const QString
&);