OSDN Git Service

Update license.
[qt-creator-jp/qt-creator-jp.git] / src / plugins / debugger / watchhandler.h
1 /**************************************************************************
2 **
3 ** This file is part of Qt Creator
4 **
5 ** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
6 **
7 ** Contact: Nokia Corporation (info@qt.nokia.com)
8 **
9 **
10 ** GNU Lesser General Public License Usage
11 **
12 ** This file may be used under the terms of the GNU Lesser General Public
13 ** License version 2.1 as published by the Free Software Foundation and
14 ** appearing in the file LICENSE.LGPL included in the packaging of this file.
15 ** Please review the following information to ensure the GNU Lesser General
16 ** Public License version 2.1 requirements will be met:
17 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
18 **
19 ** In addition, as a special exception, Nokia gives you certain additional
20 ** rights. These rights are described in the Nokia Qt LGPL Exception
21 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
22 **
23 ** Other Usage
24 **
25 ** Alternatively, this file may be used in accordance with the terms and
26 ** conditions contained in a signed written agreement between you and Nokia.
27 **
28 ** If you have questions regarding the use of this file, please contact
29 ** Nokia at qt-info@nokia.com.
30 **
31 **************************************************************************/
32
33 #ifndef DEBUGGER_WATCHHANDLER_H
34 #define DEBUGGER_WATCHHANDLER_H
35
36 #include "watchdata.h"
37
38 #include <QtCore/QPointer>
39 #include <QtCore/QHash>
40 #include <QtCore/QSet>
41 #include <QtCore/QStringList>
42 #include <QtCore/QAbstractItemModel>
43
44 namespace Debugger {
45 class DebuggerEngine;
46
47 namespace Internal {
48
49 class WatchItem;
50 class WatchHandler;
51
52 enum WatchType
53 {
54     ReturnWatch,
55     LocalsWatch,
56     WatchersWatch,
57     TooltipsWatch
58 };
59
60 enum IntegerFormat
61 {
62     DecimalFormat = 0, // Keep that at 0 as default.
63     HexadecimalFormat,
64     BinaryFormat,
65     OctalFormat
66 };
67
68 class WatchModel : public QAbstractItemModel
69 {
70     Q_OBJECT
71
72 private:
73     explicit WatchModel(WatchHandler *handler, WatchType type);
74     virtual ~WatchModel();
75
76 public:
77     virtual int rowCount(const QModelIndex &idx = QModelIndex()) const;
78     virtual int columnCount(const QModelIndex &idx) const;
79
80 private:
81     QVariant data(const QModelIndex &index, int role) const;
82     bool setData(const QModelIndex &index, const QVariant &value, int role);
83     QModelIndex index(int, int, const QModelIndex &idx) const;
84     QModelIndex parent(const QModelIndex &idx) const;
85     bool hasChildren(const QModelIndex &idx) const;
86     Qt::ItemFlags flags(const QModelIndex &idx) const;
87     QVariant headerData(int section, Qt::Orientation orientation,
88         int role = Qt::DisplayRole) const;
89     bool canFetchMore(const QModelIndex &parent) const;
90     void fetchMore(const QModelIndex &parent);
91
92     friend class WatchHandler;
93
94     WatchItem *watchItem(const QModelIndex &) const;
95     QModelIndex watchIndex(const WatchItem *needle) const;
96     QModelIndex watchIndexHelper(const WatchItem *needle,
97         const WatchItem *parentItem, const QModelIndex &parentIndex) const;
98
99     void insertData(const WatchData &data);
100     void insertBulkData(const QList<WatchData> &data);
101     WatchItem *findItem(const QByteArray &iname, WatchItem *root) const;
102     void reinitialize();
103     void removeOutdated();
104     void removeOutdatedHelper(WatchItem *item);
105     WatchItem *rootItem() const;
106     void destroyItem(WatchItem *item);
107
108     void emitDataChanged(int column,
109         const QModelIndex &parentIndex = QModelIndex());
110     void beginCycle(); // Called at begin of updateLocals() cycle.
111     void endCycle(); // Called after all results have been received.
112
113     friend QDebug operator<<(QDebug d, const WatchModel &m);
114
115     void dump();
116     void dumpHelper(WatchItem *item);
117     void emitAllChanged();
118
119 signals:
120     void enableUpdates(bool);
121
122 private:
123     QString displayType(const WatchData &typeIn) const;
124     void formatRequests(QByteArray *out, const WatchItem *item) const;
125     DebuggerEngine *engine() const;
126     int itemFormat(const WatchData &data) const;
127
128     WatchHandler *m_handler;
129     WatchType m_type;
130     WatchItem *m_root;
131     QSet<QByteArray> m_fetchTriggered;
132 };
133
134 class WatchHandler : public QObject
135 {
136     Q_OBJECT
137
138 public:
139     explicit WatchHandler(DebuggerEngine *engine);
140     WatchModel *model(WatchType type) const;
141     WatchModel *modelForIName(const QByteArray &iname) const;
142
143     void cleanup();
144     void watchExpression(const QString &exp);
145     void removeWatchExpression(const QString &exp);
146     Q_SLOT void clearWatches();
147     Q_SLOT void emitAllChanged();
148
149     void beginCycle(bool fullCycle = true); // Called at begin of updateLocals() cycle
150     void updateWatchers(); // Called after locals are fetched
151     void endCycle(bool fullCycle = true); // Called after all results have been received
152     void showEditValue(const WatchData &data);
153
154     void insertData(const WatchData &data);
155     void insertBulkData(const QList<WatchData> &data);
156     void removeData(const QByteArray &iname);
157
158     const WatchData *watchData(WatchType type, const QModelIndex &) const;
159     const WatchData *findItem(const QByteArray &iname) const;
160     QModelIndex itemIndex(const QByteArray &iname) const;
161
162     void loadSessionData();
163     void saveSessionData();
164     void removeTooltip();
165     void rebuildModel();
166
167     bool isExpandedIName(const QByteArray &iname) const
168         { return m_expandedINames.contains(iname); }
169     QSet<QByteArray> expandedINames() const
170         { return m_expandedINames; }
171     static QStringList watchedExpressions();
172     static QHash<QByteArray, int> watcherNames()
173         { return m_watcherNames; }
174
175     QByteArray expansionRequests() const;
176     QByteArray typeFormatRequests() const;
177     QByteArray individualFormatRequests() const;
178
179     int format(const QByteArray &iname) const;
180
181     void addTypeFormats(const QByteArray &type, const QStringList &formats);
182
183     void setUnprintableBase(int base) { m_unprintableBase = base; }
184     int unprintableBase() const { return m_unprintableBase; }
185
186     QByteArray watcherName(const QByteArray &exp);
187     void synchronizeWatchers();
188     QString editorContents();
189
190 private:
191     friend class WatchModel;
192
193     void saveWatchers();
194     static void loadTypeFormats();
195     static void saveTypeFormats();
196
197     void setFormat(const QByteArray &type, int format);
198     void updateWatchersWindow();
199     void showInEditorHelper(QString *contents, WatchItem *item, int level);
200
201     bool m_inChange;
202
203     // QWidgets and QProcesses taking care of special displays.
204     typedef QMap<QString, QPointer<QObject> > EditHandlers;
205     EditHandlers m_editHandlers;
206
207     static QHash<QByteArray, int> m_watcherNames;
208     static QHash<QByteArray, int> m_typeFormats;
209     QHash<QByteArray, int> m_individualFormats; // Indexed by iname.
210     QHash<QString, QStringList> m_reportedTypeFormats;
211
212     // Items expanded in the Locals & Watchers view.
213     QSet<QByteArray> m_expandedINames;
214
215     WatchModel *m_return;
216     WatchModel *m_locals;
217     WatchModel *m_watchers;
218     WatchModel *m_tooltips;
219     DebuggerEngine *m_engine;
220     static int m_unprintableBase;
221 };
222
223 } // namespace Internal
224 } // namespace Debugger
225
226 #endif // DEBUGGER_WATCHHANDLER_H