Commit ce67924b authored by Friedemann Kleint's avatar Friedemann Kleint
Browse files

Bin-Editor: Markup/Make widget usable as standalone-view.

Add markup for displaying class layouts in the debugger.
Add a factory registered with the plugin manager
for creation of widgets by soft-dependent plugins.
parent bd149059
......@@ -697,7 +697,6 @@ void BinEditor::paintEvent(QPaintEvent *e)
int viewport_height = viewport()->height();
QBrush alternate_base = palette().alternateBase();
for (int i = 0; i < 8; ++i) {
int bg_x = -xoffset + m_margin + (2 * i + 1) * m_columnWidth + m_labelWidth;
QRect r(bg_x - m_charWidth/2, 0, m_columnWidth, viewport_height);
......@@ -715,7 +714,6 @@ void BinEditor::paintEvent(QPaintEvent *e)
::lower(patternData);
}
int foundPatternAt = findPattern(patternData, patternDataHex, patternOffset, patternOffset, &matchLength);
int selStart, selEnd;
......@@ -739,15 +737,15 @@ void BinEditor::paintEvent(QPaintEvent *e)
if (line >= m_numLines)
break;
const quint64 lineAddress = m_baseAddr + uint(line) * 16;
int y = i * m_lineHeight + m_ascent;
if (y - m_ascent > e->rect().bottom())
break;
if (y + m_descent < e->rect().top())
continue;
painter.drawText(-xoffset, i * m_lineHeight + m_ascent,
addressString(m_baseAddr + uint(line) * 16));
addressString(lineAddress));
int cursor = -1;
if (line * 16 <= m_cursorPosition && m_cursorPosition < line * 16 + 16)
......@@ -789,7 +787,6 @@ void BinEditor::paintEvent(QPaintEvent *e)
}
break;
}
if (foundPatternAt >= 0 && pos >= foundPatternAt + matchLength)
foundPatternAt = findPattern(patternData, patternDataHex, foundPatternAt + matchLength, patternOffset, &matchLength);
......@@ -804,13 +801,23 @@ void BinEditor::paintEvent(QPaintEvent *e)
int item_x = -xoffset + m_margin + c * m_columnWidth + m_labelWidth;
if (foundPatternAt >= 0 && pos >= foundPatternAt && pos < foundPatternAt + matchLength) {
painter.fillRect(item_x, y-m_ascent, m_columnWidth, m_lineHeight, QColor(0xffef0b));
QColor color;
foreach (const Markup &m, m_markup) {
if (m.covers(lineAddress + c)) {
color = m.color;
break;
}
}
if (foundPatternAt >= 0 && pos >= foundPatternAt && pos < foundPatternAt + matchLength)
color = QColor(0xffef0b);
if (color.isValid()) {
painter.fillRect(item_x, y-m_ascent, m_columnWidth, m_lineHeight, color);
int printable_item_x = -xoffset + m_margin + m_labelWidth + 16 * m_columnWidth + m_charWidth
+ fm.width(printable.left(c));
painter.fillRect(printable_item_x, y-m_ascent,
fm.width(printable.at(c)),
m_lineHeight, QColor(0xffef0b));
m_lineHeight, color);
}
if (selStart < selEnd && !isFullySelected && pos >= selStart && pos < selEnd) {
......@@ -1095,7 +1102,17 @@ bool BinEditor::event(QEvent *e)
//uchar old = dataAt(pos, true);
//uchar current = dataAt(pos, false);
QString msg =
QString msg;
const quint64 address = m_baseAddr + selStart;
foreach (const Markup &m, m_markup) {
if (m.covers(address) && !m.toolTip.isEmpty()) {
msg += m.toolTip;
msg += QLatin1String("\n\n");
break;
}
}
msg +=
tr("Decimal unsigned value (little endian): %1\n"
"Decimal unsigned value (big endian): %2\n"
"Decimal signed value (little endian): %3\n"
......@@ -1427,9 +1444,9 @@ void BinEditor::jumpToAddress(quint64 address)
emit newRangeRequested(editor(), address);
}
void BinEditor::setNewWindowRequestAllowed()
void BinEditor::setNewWindowRequestAllowed(bool c)
{
m_canRequestNewWindow = true;
m_canRequestNewWindow = c;
}
void BinEditor::updateContents()
......@@ -1463,4 +1480,10 @@ bool BinEditor::isMemoryView() const
return editor()->property("MemoryView").toBool();
}
void BinEditor::setMarkup(const QList<Markup> &markup)
{
m_markup = markup;
viewport()->update();
}
} // namespace BINEditor
......@@ -33,6 +33,8 @@
#ifndef BINEDITOR_H
#define BINEDITOR_H
#include "markup.h"
#include <QtCore/QBasicTimer>
#include <QtCore/QMap>
#include <QtCore/QSet>
......@@ -60,7 +62,8 @@ class BinEditor : public QAbstractScrollArea
Q_OBJECT
Q_PROPERTY(bool modified READ isModified WRITE setModified DESIGNABLE false)
Q_PROPERTY(bool readOnly READ isReadOnly WRITE setReadOnly DESIGNABLE false)
Q_PROPERTY(QList<BINEditor::Markup> markup READ markup WRITE setMarkup DESIGNABLE false)
Q_PROPERTY(bool newWindowRequestAllowed READ newWindowRequestAllowed WRITE setNewWindowRequestAllowed DESIGNABLE false)
public:
BinEditor(QWidget *parent = 0);
~BinEditor();
......@@ -70,7 +73,9 @@ public:
Q_INVOKABLE void setSizes(quint64 startAddr, int range, int blockSize = 4096);
int dataBlockSize() const { return m_blockSize; }
Q_INVOKABLE void addData(quint64 block, const QByteArray &data);
Q_INVOKABLE void setNewWindowRequestAllowed();
bool newWindowRequestAllowed() const { return m_canRequestNewWindow; }
Q_INVOKABLE void updateContents();
bool save(QString *errorString, const QString &oldFileName, const QString &newFileName);
......@@ -119,11 +124,15 @@ public:
static const int SearchStride = 1024 * 1024;
QList<Markup> markup() const { return m_markup; }
public Q_SLOTS:
void setFontSettings(const TextEditor::FontSettings &fs);
void highlightSearchResults(const QByteArray &pattern,
QTextDocument::FindFlags findFlags = 0);
void copy(bool raw = false);
void setMarkup(const QList<Markup> &markup);
void setNewWindowRequestAllowed(bool c);
Q_SIGNALS:
void modificationChanged(bool modified);
......@@ -239,6 +248,7 @@ private:
QString m_addressString;
int m_addressBytes;
bool m_canRequestNewWindow;
QList<Markup> m_markup;
};
} // namespace BINEditor
......
......@@ -5,7 +5,8 @@ include(bineditor_dependencies.pri)
HEADERS += bineditorplugin.h \
bineditor.h \
bineditorconstants.h
bineditorconstants.h \
markup.h
SOURCES += bineditorplugin.cpp \
bineditor.cpp
......
......@@ -438,6 +438,24 @@ QStringList BinEditorFactory::mimeTypes() const
return m_mimeTypes;
}
/*!
\class BINEditor::BinEditorWidgetFactory
\brief Service registered with PluginManager to create bin editor widgets for plugins
without direct linkage.
\sa ExtensionSystem::PluginManager::getObjectByClassName, ExtensionSystem::invoke
*/
BinEditorWidgetFactory::BinEditorWidgetFactory(QObject *parent) :
QObject(parent)
{
}
QWidget *BinEditorWidgetFactory::createWidget(QWidget *parent)
{
return new BinEditor(parent);
}
///////////////////////////////// BinEditorPlugin //////////////////////////////////
BinEditorPlugin::BinEditorPlugin()
......@@ -515,6 +533,7 @@ bool BinEditorPlugin::initialize(const QStringList &arguments, QString *errorMes
this, SLOT(updateCurrentEditor(Core::IContext *)));
addAutoReleasedObject(new BinEditorFactory(this));
addAutoReleasedObject(new BinEditorWidgetFactory);
return true;
}
......
......@@ -44,6 +44,16 @@
namespace BINEditor {
class BinEditor;
class BinEditorWidgetFactory : public QObject
{
Q_OBJECT
public:
explicit BinEditorWidgetFactory(QObject *parent = 0);
Q_INVOKABLE QWidget *createWidget(QWidget *parent);
};
namespace Internal {
class BinEditorFactory;
......
/**************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact: Nokia Corporation (info@qt.nokia.com)
**
**
** GNU Lesser General Public License Usage
**
** This file may be used under the terms of the GNU Lesser General Public
** License version 2.1 as published by the Free Software Foundation and
** appearing in the file LICENSE.LGPL included in the packaging of this file.
** Please review the following information to ensure the GNU Lesser General
** Public License version 2.1 requirements will be met:
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Nokia gives you certain additional
** rights. These rights are described in the Nokia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** Other Usage
**
** Alternatively, this file may be used in accordance with the terms and
** conditions contained in a signed written agreement between you and Nokia.
**
** If you have questions regarding the use of this file, please contact
** Nokia at qt-info@nokia.com.
**
**************************************************************************/
#ifndef MARKUP_H
#define MARKUP_H
#include <QtGui/QColor>
#include <QtCore/QString>
#include <QtCore/QList>
#include <QtCore/QMetaType>
namespace BINEditor {
/*!
\class BINEditor::Markup
\brief Markup range of the binary editor.
Used for displaying class layouts by the debugger.
\note Must not have linkage - used for soft dependencies.
\sa Debugger::Internal::MemoryAgent
*/
class Markup
{
public:
Markup(quint64 a = 0, quint64 l = 0, QColor c = Qt::yellow, const QString &tt = QString()) :
address(a), length(l), color(c), toolTip(tt) {}
bool covers(quint64 a) const { return a >= address && a < (address + length); }
quint64 address;
quint64 length;
QColor color;
QString toolTip;
};
} // namespace BINEditor
Q_DECLARE_METATYPE(QList<BINEditor::Markup>)
#endif // MARKUP_H
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment