1 /**************************************************************************
3 ** This file is part of Qt Creator
5 ** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
7 ** Contact: Nokia Corporation (info@qt.nokia.com)
10 ** GNU Lesser General Public License Usage
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.
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.
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.
28 ** If you have questions regarding the use of this file, please contact
29 ** Nokia at qt-info@nokia.com.
31 **************************************************************************/
33 #ifndef DEBUGGER_WATCHHANDLER_H
34 #define DEBUGGER_WATCHHANDLER_H
36 #include "watchdata.h"
38 #include <QtCore/QPointer>
39 #include <QtCore/QHash>
40 #include <QtCore/QSet>
41 #include <QtCore/QStringList>
42 #include <QtCore/QAbstractItemModel>
62 DecimalFormat = 0, // Keep that at 0 as default.
68 class WatchModel : public QAbstractItemModel
73 explicit WatchModel(WatchHandler *handler, WatchType type);
74 virtual ~WatchModel();
77 virtual int rowCount(const QModelIndex &idx = QModelIndex()) const;
78 virtual int columnCount(const QModelIndex &idx) const;
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);
92 friend class WatchHandler;
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;
99 void insertData(const WatchData &data);
100 void insertBulkData(const QList<WatchData> &data);
101 WatchItem *findItem(const QByteArray &iname, WatchItem *root) const;
103 void removeOutdated();
104 void removeOutdatedHelper(WatchItem *item);
105 WatchItem *rootItem() const;
106 void destroyItem(WatchItem *item);
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.
113 friend QDebug operator<<(QDebug d, const WatchModel &m);
116 void dumpHelper(WatchItem *item);
117 void emitAllChanged();
120 void enableUpdates(bool);
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;
128 WatchHandler *m_handler;
131 QSet<QByteArray> m_fetchTriggered;
134 class WatchHandler : public QObject
139 explicit WatchHandler(DebuggerEngine *engine);
140 WatchModel *model(WatchType type) const;
141 WatchModel *modelForIName(const QByteArray &iname) const;
144 void watchExpression(const QString &exp);
145 void removeWatchExpression(const QString &exp);
146 Q_SLOT void clearWatches();
147 Q_SLOT void emitAllChanged();
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);
154 void insertData(const WatchData &data);
155 void insertBulkData(const QList<WatchData> &data);
156 void removeData(const QByteArray &iname);
158 const WatchData *watchData(WatchType type, const QModelIndex &) const;
159 const WatchData *findItem(const QByteArray &iname) const;
160 QModelIndex itemIndex(const QByteArray &iname) const;
162 void loadSessionData();
163 void saveSessionData();
164 void removeTooltip();
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; }
175 QByteArray expansionRequests() const;
176 QByteArray typeFormatRequests() const;
177 QByteArray individualFormatRequests() const;
179 int format(const QByteArray &iname) const;
181 void addTypeFormats(const QByteArray &type, const QStringList &formats);
183 void setUnprintableBase(int base) { m_unprintableBase = base; }
184 int unprintableBase() const { return m_unprintableBase; }
186 QByteArray watcherName(const QByteArray &exp);
187 void synchronizeWatchers();
188 QString editorContents();
191 friend class WatchModel;
194 static void loadTypeFormats();
195 static void saveTypeFormats();
197 void setFormat(const QByteArray &type, int format);
198 void updateWatchersWindow();
199 void showInEditorHelper(QString *contents, WatchItem *item, int level);
203 // QWidgets and QProcesses taking care of special displays.
204 typedef QMap<QString, QPointer<QObject> > EditHandlers;
205 EditHandlers m_editHandlers;
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;
212 // Items expanded in the Locals & Watchers view.
213 QSet<QByteArray> m_expandedINames;
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;
223 } // namespace Internal
224 } // namespace Debugger
226 #endif // DEBUGGER_WATCHHANDLER_H