diff options
author | hjk <qtc-committer@nokia.com> | 2011-02-17 19:00:33 +0100 |
---|---|---|
committer | hjk <qtc-committer@nokia.com> | 2011-02-17 19:01:07 +0100 |
commit | 98c4b82c2d9046f635c9991ef2fcce9c42910893 (patch) | |
tree | 4016faab1f45317ab0f8f6db3c89f890824fe17f /src/plugins/debugger | |
parent | 8c3e61e083b801f151c6b05aa26264fcad4b7cf9 (diff) | |
download | qt-creator-98c4b82c2d9046f635c9991ef2fcce9c42910893.tar.gz |
debugger: make output format of non-printable characters customizable
Diffstat (limited to 'src/plugins/debugger')
-rw-r--r-- | src/plugins/debugger/watchhandler.cpp | 39 | ||||
-rw-r--r-- | src/plugins/debugger/watchhandler.h | 4 | ||||
-rw-r--r-- | src/plugins/debugger/watchwindow.cpp | 25 |
3 files changed, 58 insertions, 10 deletions
diff --git a/src/plugins/debugger/watchhandler.cpp b/src/plugins/debugger/watchhandler.cpp index 05e6c834cb..63b02127b0 100644 --- a/src/plugins/debugger/watchhandler.cpp +++ b/src/plugins/debugger/watchhandler.cpp @@ -79,6 +79,7 @@ static int generationCounter = 0; QHash<QByteArray, int> WatchHandler::m_watcherNames; QHash<QByteArray, int> WatchHandler::m_typeFormats; +int WatchHandler::m_unprintableBase = 0; //////////////////////////////////////////////////////////////////// // @@ -627,21 +628,41 @@ QVariant WatchModel::data(const QModelIndex &idx, int role) const case Qt::DisplayRole: { const QByteArray ns = engine()->qtNamespace(); + QString result; switch (idx.column()) { case 0: if (data.name.isEmpty()) - return tr("<Edit>"); - if (data.name == QLatin1String("*") && item->parent) - return QVariant(QLatin1Char('*') + item->parent->name); - return removeInitialNamespace(data.name, ns); + result = tr("<Edit>"); + else if (data.name == QLatin1String("*") && item->parent) + result = QLatin1Char('*') + item->parent->name; + else + result = removeInitialNamespace(data.name, ns); + break; case 1: - return removeInitialNamespace(truncateValue( + result = removeInitialNamespace(truncateValue( formattedValue(data, itemFormat(data))), ns); + break; case 2: - return removeNamespaces(displayType(data), ns); + result = removeNamespaces(displayType(data), ns); + break; default: break; } + if (WatchHandler::m_unprintableBase == 0) + return result; + QString encoded; + foreach (const QChar c, result) { + if (c.isPrint()) { + encoded += c; + } else if (WatchHandler::m_unprintableBase == 8) { + encoded += QString("\\%1") + .arg(c.unicode(), 3, 8, QLatin1Char('0')); + } else { + encoded += QString("\\u%1") + .arg(c.unicode(), 4, 16, QLatin1Char('0')); + } + } + return encoded; } case Qt::ToolTipRole: @@ -1092,11 +1113,11 @@ WatchHandler::WatchHandler(DebuggerEngine *engine) m_tooltips = new WatchModel(this, TooltipsWatch); connect(debuggerCore()->action(ShowStdNamespace), - SIGNAL(triggered()), this, SLOT(emitAllChanged())); + SIGNAL(triggered()), SLOT(emitAllChanged())); connect(debuggerCore()->action(ShowQtNamespace), - SIGNAL(triggered()), this, SLOT(emitAllChanged())); + SIGNAL(triggered()), SLOT(emitAllChanged())); connect(debuggerCore()->action(SortStructMembers), - SIGNAL(triggered()), this, SLOT(emitAllChanged())); + SIGNAL(triggered()), SLOT(emitAllChanged())); } void WatchHandler::beginCycle(bool fullCycle) diff --git a/src/plugins/debugger/watchhandler.h b/src/plugins/debugger/watchhandler.h index 10d96826ec..950bf4fdaa 100644 --- a/src/plugins/debugger/watchhandler.h +++ b/src/plugins/debugger/watchhandler.h @@ -180,6 +180,9 @@ public: void addTypeFormats(const QByteArray &type, const QStringList &formats); + void setUnprintableBase(int base) { m_unprintableBase = base; } + int unprintableBase() const { return m_unprintableBase; } + QByteArray watcherName(const QByteArray &exp); void synchronizeWatchers(); QString editorContents(); @@ -214,6 +217,7 @@ private: WatchModel *m_watchers; WatchModel *m_tooltips; DebuggerEngine *m_engine; + static int m_unprintableBase; }; } // namespace Internal diff --git a/src/plugins/debugger/watchwindow.cpp b/src/plugins/debugger/watchwindow.cpp index b6708b3067..f4c554752a 100644 --- a/src/plugins/debugger/watchwindow.cpp +++ b/src/plugins/debugger/watchwindow.cpp @@ -286,14 +286,31 @@ void WatchWindow::contextMenuEvent(QContextMenuEvent *ev) mi0.data(LocalsIndividualFormatRole).toInt(); const int effectiveIndividualFormat = individualFormat == -1 ? typeFormat : individualFormat; + const int unprintableBase = handler->unprintableBase(); QMenu formatMenu; QList<QAction *> typeFormatActions; QList<QAction *> individualFormatActions; QAction *clearTypeFormatAction = 0; QAction *clearIndividualFormatAction = 0; + QAction *showUnprintableUnicode = 0; + QAction *showUnprintableOctal = 0; + QAction *showUnprintableHexadecimal = 0; formatMenu.setTitle(tr("Change Display Format...")); - if (idx.isValid() && !alternativeFormats.isEmpty()) { + if (true /*idx.isValid() && !alternativeFormats.isEmpty() */) { + showUnprintableUnicode = + formatMenu.addAction(tr("Treat All Characters as Printable")); + showUnprintableUnicode->setCheckable(true); + showUnprintableUnicode->setChecked(unprintableBase == 0); + showUnprintableOctal = + formatMenu.addAction(tr("Show Unprintable Characters as Octal")); + showUnprintableOctal->setCheckable(true); + showUnprintableOctal->setChecked(unprintableBase == 8); + showUnprintableHexadecimal = + formatMenu.addAction(tr("Show Unprintable Characters as Hexadecimal")); + showUnprintableHexadecimal->setCheckable(true); + showUnprintableHexadecimal->setChecked(unprintableBase == 16); + formatMenu.addSeparator(); QAction *dummy = formatMenu.addAction( tr("Change Display for Type \"%1\"").arg(type)); dummy->setEnabled(false); @@ -515,6 +532,12 @@ void WatchWindow::contextMenuEvent(QContextMenuEvent *ev) } else if (act == actShowInEditor) { QString contents = handler->editorContents(); debuggerCore()->openTextEditor(tr("Locals & Watchers"), contents); + } else if (act == showUnprintableUnicode) { + handler->setUnprintableBase(0); + } else if (act == showUnprintableOctal) { + handler->setUnprintableBase(8); + } else if (act == showUnprintableHexadecimal) { + handler->setUnprintableBase(16); } else { for (int i = 0; i != typeFormatActions.size(); ++i) { if (act == typeFormatActions.at(i)) |