forked from qt-creator/qt-creator
BinEditor: Some modernization
Qt 5 connects, override, style, and a few changes from int to 64 bit types. Change-Id: I7ac1879c4f46fcbc5b0ab9f5a6cefdbf2b789774 Reviewed-by: David Schulz <david.schulz@theqtcompany.com>
This commit is contained in:
@@ -927,7 +927,7 @@ void BinEditorWidget::paintEvent(QPaintEvent *e)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int BinEditorWidget::cursorPosition() const
|
qint64 BinEditorWidget::cursorPosition() const
|
||||||
{
|
{
|
||||||
return m_cursorPosition;
|
return m_cursorPosition;
|
||||||
}
|
}
|
||||||
@@ -1483,13 +1483,13 @@ void BinEditorWidget::contextMenuEvent(QContextMenuEvent *event)
|
|||||||
|
|
||||||
QPointer<QMenu> contextMenu(new QMenu(this));
|
QPointer<QMenu> contextMenu(new QMenu(this));
|
||||||
|
|
||||||
QAction *copyAsciiAction = new QAction(tr("Copy Selection as ASCII Characters"), contextMenu);
|
auto copyAsciiAction = new QAction(tr("Copy Selection as ASCII Characters"), contextMenu);
|
||||||
QAction *copyHexAction = new QAction(tr("Copy Selection as Hex Values"), contextMenu);
|
auto copyHexAction = new QAction(tr("Copy Selection as Hex Values"), contextMenu);
|
||||||
QAction *jumpToBeAddressHereAction = new QAction(contextMenu);
|
auto jumpToBeAddressHereAction = new QAction(contextMenu);
|
||||||
QAction *jumpToBeAddressNewWindowAction = new QAction(contextMenu);
|
auto jumpToBeAddressNewWindowAction = new QAction(contextMenu);
|
||||||
QAction *jumpToLeAddressHereAction = new QAction(contextMenu);
|
auto jumpToLeAddressHereAction = new QAction(contextMenu);
|
||||||
QAction *jumpToLeAddressNewWindowAction = new QAction(contextMenu);
|
auto jumpToLeAddressNewWindowAction = new QAction(contextMenu);
|
||||||
QAction *addWatchpointAction = new QAction(tr("Set Data Breakpoint on Selection"), contextMenu);
|
auto addWatchpointAction = new QAction(tr("Set Data Breakpoint on Selection"), contextMenu);
|
||||||
contextMenu->addAction(copyAsciiAction);
|
contextMenu->addAction(copyAsciiAction);
|
||||||
contextMenu->addAction(copyHexAction);
|
contextMenu->addAction(copyHexAction);
|
||||||
contextMenu->addAction(addWatchpointAction);
|
contextMenu->addAction(addWatchpointAction);
|
||||||
|
|||||||
@@ -79,7 +79,7 @@ public:
|
|||||||
KeepAnchor
|
KeepAnchor
|
||||||
};
|
};
|
||||||
|
|
||||||
int cursorPosition() const;
|
qint64 cursorPosition() const;
|
||||||
Q_INVOKABLE void setCursorPosition(qint64 pos, MoveMode moveMode = MoveAnchor);
|
Q_INVOKABLE void setCursorPosition(qint64 pos, MoveMode moveMode = MoveAnchor);
|
||||||
void jumpToAddress(quint64 address);
|
void jumpToAddress(quint64 address);
|
||||||
|
|
||||||
|
|||||||
@@ -97,27 +97,27 @@ public:
|
|||||||
m_incrementalWrappedState = false;
|
m_incrementalWrappedState = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool supportsReplace() const { return false; }
|
bool supportsReplace() const override { return false; }
|
||||||
QString currentFindString() const { return QString(); }
|
QString currentFindString() const override { return QString(); }
|
||||||
QString completedFindString() const { return QString(); }
|
QString completedFindString() const override { return QString(); }
|
||||||
|
|
||||||
FindFlags supportedFindFlags() const
|
FindFlags supportedFindFlags() const override
|
||||||
{
|
{
|
||||||
return FindBackward | FindCaseSensitively;
|
return FindBackward | FindCaseSensitively;
|
||||||
}
|
}
|
||||||
|
|
||||||
void resetIncrementalSearch()
|
void resetIncrementalSearch() override
|
||||||
{
|
{
|
||||||
m_incrementalStartPos = m_contPos = -1;
|
m_incrementalStartPos = m_contPos = -1;
|
||||||
m_incrementalWrappedState = false;
|
m_incrementalWrappedState = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void highlightAll(const QString &txt, FindFlags findFlags)
|
void highlightAll(const QString &txt, FindFlags findFlags) override
|
||||||
{
|
{
|
||||||
m_widget->highlightSearchResults(txt.toLatin1(), textDocumentFlagsForFindFlags(findFlags));
|
m_widget->highlightSearchResults(txt.toLatin1(), textDocumentFlagsForFindFlags(findFlags));
|
||||||
}
|
}
|
||||||
|
|
||||||
void clearHighlights()
|
void clearHighlights() override
|
||||||
{
|
{
|
||||||
m_widget->highlightSearchResults(QByteArray());
|
m_widget->highlightSearchResults(QByteArray());
|
||||||
}
|
}
|
||||||
@@ -143,7 +143,8 @@ public:
|
|||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
Result findIncremental(const QString &txt, FindFlags findFlags) {
|
Result findIncremental(const QString &txt, FindFlags findFlags) override
|
||||||
|
{
|
||||||
QByteArray pattern = txt.toLatin1();
|
QByteArray pattern = txt.toLatin1();
|
||||||
if (pattern != m_lastPattern)
|
if (pattern != m_lastPattern)
|
||||||
resetIncrementalSearch(); // Because we don't search for nibbles.
|
resetIncrementalSearch(); // Because we don't search for nibbles.
|
||||||
@@ -178,7 +179,8 @@ public:
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
Result findStep(const QString &txt, FindFlags findFlags) {
|
Result findStep(const QString &txt, FindFlags findFlags) override
|
||||||
|
{
|
||||||
QByteArray pattern = txt.toLatin1();
|
QByteArray pattern = txt.toLatin1();
|
||||||
bool wasReset = (m_incrementalStartPos < 0);
|
bool wasReset = (m_incrementalStartPos < 0);
|
||||||
if (m_contPos == -1) {
|
if (m_contPos == -1) {
|
||||||
@@ -211,8 +213,8 @@ public:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
BinEditorWidget *m_widget;
|
BinEditorWidget *m_widget;
|
||||||
int m_incrementalStartPos;
|
qint64 m_incrementalStartPos;
|
||||||
int m_contPos; // Only valid if last result was NotYetFound.
|
qint64 m_contPos; // Only valid if last result was NotYetFound.
|
||||||
bool m_incrementalWrappedState;
|
bool m_incrementalWrappedState;
|
||||||
QByteArray m_lastPattern;
|
QByteArray m_lastPattern;
|
||||||
};
|
};
|
||||||
@@ -228,11 +230,12 @@ public:
|
|||||||
setId(Core::Constants::K_DEFAULT_BINARY_EDITOR_ID);
|
setId(Core::Constants::K_DEFAULT_BINARY_EDITOR_ID);
|
||||||
setMimeType(QLatin1String(BinEditor::Constants::C_BINEDITOR_MIMETYPE));
|
setMimeType(QLatin1String(BinEditor::Constants::C_BINEDITOR_MIMETYPE));
|
||||||
m_widget = parent;
|
m_widget = parent;
|
||||||
connect(m_widget, SIGNAL(dataRequested(quint64)),
|
connect(m_widget, &BinEditorWidget::dataRequested,
|
||||||
this, SLOT(provideData(quint64)));
|
this, &BinEditorDocument::provideData);
|
||||||
connect(m_widget, SIGNAL(newRangeRequested(quint64)),
|
connect(m_widget, &BinEditorWidget::newRangeRequested,
|
||||||
this, SLOT(provideNewRange(quint64)));
|
this, &BinEditorDocument::provideNewRange);
|
||||||
connect(m_widget, &BinEditorWidget::dataChanged, this, &IDocument::contentsChanged);
|
connect(m_widget, &BinEditorWidget::dataChanged,
|
||||||
|
this, &IDocument::contentsChanged);
|
||||||
}
|
}
|
||||||
|
|
||||||
QByteArray contents() const override
|
QByteArray contents() const override
|
||||||
@@ -313,7 +316,6 @@ public:
|
|||||||
return OpenResult::ReadError;
|
return OpenResult::ReadError;
|
||||||
}
|
}
|
||||||
|
|
||||||
private slots:
|
|
||||||
void provideData(quint64 block)
|
void provideData(quint64 block)
|
||||||
{
|
{
|
||||||
const FileName fn = filePath();
|
const FileName fn = filePath();
|
||||||
@@ -342,7 +344,6 @@ private slots:
|
|||||||
}
|
}
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
bool isModified() const override
|
bool isModified() const override
|
||||||
{
|
{
|
||||||
return isTemporary()/*e.g. memory view*/ ? false
|
return isTemporary()/*e.g. memory view*/ ? false
|
||||||
@@ -358,7 +359,8 @@ public:
|
|||||||
|
|
||||||
bool isSaveAsAllowed() const override { return true; }
|
bool isSaveAsAllowed() const override { return true; }
|
||||||
|
|
||||||
bool reload(QString *errorString, ReloadFlag flag, ChangeType type) override {
|
bool reload(QString *errorString, ReloadFlag flag, ChangeType type) override
|
||||||
|
{
|
||||||
if (flag == FlagIgnore)
|
if (flag == FlagIgnore)
|
||||||
return true;
|
return true;
|
||||||
if (type == TypePermissions) {
|
if (type == TypePermissions) {
|
||||||
@@ -390,13 +392,12 @@ public:
|
|||||||
m_context.add(Core::Constants::K_DEFAULT_BINARY_EDITOR_ID);
|
m_context.add(Core::Constants::K_DEFAULT_BINARY_EDITOR_ID);
|
||||||
m_context.add(Constants::C_BINEDITOR);
|
m_context.add(Constants::C_BINEDITOR);
|
||||||
m_addressEdit = new QLineEdit;
|
m_addressEdit = new QLineEdit;
|
||||||
QRegExpValidator * const addressValidator
|
auto addressValidator = new QRegExpValidator(QRegExp(QLatin1String("[0-9a-fA-F]{1,16}")),
|
||||||
= new QRegExpValidator(QRegExp(QLatin1String("[0-9a-fA-F]{1,16}")),
|
|
||||||
m_addressEdit);
|
m_addressEdit);
|
||||||
m_addressEdit->setValidator(addressValidator);
|
m_addressEdit->setValidator(addressValidator);
|
||||||
|
|
||||||
QHBoxLayout *l = new QHBoxLayout;
|
auto l = new QHBoxLayout;
|
||||||
QWidget *w = new QWidget;
|
auto w = new QWidget;
|
||||||
l->setMargin(0);
|
l->setMargin(0);
|
||||||
l->setContentsMargins(0, 0, 5, 0);
|
l->setContentsMargins(0, 0, 5, 0);
|
||||||
l->addStretch(1);
|
l->addStretch(1);
|
||||||
@@ -409,9 +410,12 @@ public:
|
|||||||
|
|
||||||
widget->setEditor(this);
|
widget->setEditor(this);
|
||||||
|
|
||||||
connect(widget, SIGNAL(cursorPositionChanged(int)), SLOT(updateCursorPosition(int)));
|
connect(widget, &BinEditorWidget::cursorPositionChanged,
|
||||||
connect(m_addressEdit, SIGNAL(editingFinished()), SLOT(jumpToAddress()));
|
this, &BinEditor::updateCursorPosition);
|
||||||
connect(widget, SIGNAL(modificationChanged(bool)), m_file, SIGNAL(changed()));
|
connect(m_addressEdit, &QLineEdit::editingFinished,
|
||||||
|
this, &BinEditor::jumpToAddress);
|
||||||
|
connect(widget, &BinEditorWidget::modificationChanged,
|
||||||
|
m_file, &IDocument::changed);
|
||||||
updateCursorPosition(widget->cursorPosition());
|
updateCursorPosition(widget->cursorPosition());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -424,8 +428,8 @@ public:
|
|||||||
|
|
||||||
QWidget *toolBar() override { return m_toolBar; }
|
QWidget *toolBar() override { return m_toolBar; }
|
||||||
|
|
||||||
private slots:
|
private:
|
||||||
void updateCursorPosition(int position) {
|
void updateCursorPosition(qint64 position) {
|
||||||
m_addressEdit->setText(QString::number(editorWidget()->baseAddress() + position, 16));
|
m_addressEdit->setText(QString::number(editorWidget()->baseAddress() + position, 16));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -434,8 +438,7 @@ private slots:
|
|||||||
updateCursorPosition(editorWidget()->cursorPosition());
|
updateCursorPosition(editorWidget()->cursorPosition());
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
BinEditorWidget *editorWidget() const
|
||||||
inline BinEditorWidget *editorWidget() const
|
|
||||||
{
|
{
|
||||||
QTC_ASSERT(qobject_cast<BinEditorWidget *>(m_widget.data()), return 0);
|
QTC_ASSERT(qobject_cast<BinEditorWidget *>(m_widget.data()), return 0);
|
||||||
return static_cast<BinEditorWidget *>(m_widget.data());
|
return static_cast<BinEditorWidget *>(m_widget.data());
|
||||||
@@ -461,9 +464,8 @@ BinEditorFactory::BinEditorFactory(BinEditorPlugin *owner) :
|
|||||||
|
|
||||||
IEditor *BinEditorFactory::createEditor()
|
IEditor *BinEditorFactory::createEditor()
|
||||||
{
|
{
|
||||||
BinEditorWidget *widget = new BinEditorWidget();
|
auto widget = new BinEditorWidget();
|
||||||
BinEditor *editor = new BinEditor(widget);
|
auto editor = new BinEditor(widget);
|
||||||
|
|
||||||
m_owner->initializeEditor(widget);
|
m_owner->initializeEditor(widget);
|
||||||
return editor;
|
return editor;
|
||||||
}
|
}
|
||||||
@@ -482,39 +484,32 @@ BinEditorPlugin::~BinEditorPlugin()
|
|||||||
|
|
||||||
QAction *BinEditorPlugin::registerNewAction(Id id, const QString &title)
|
QAction *BinEditorPlugin::registerNewAction(Id id, const QString &title)
|
||||||
{
|
{
|
||||||
QAction *result = new QAction(title, this);
|
auto result = new QAction(title, this);
|
||||||
ActionManager::registerAction(result, id, m_context);
|
ActionManager::registerAction(result, id, m_context);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
QAction *BinEditorPlugin::registerNewAction(Id id,
|
|
||||||
QObject *receiver,
|
|
||||||
const char *slot,
|
|
||||||
const QString &title)
|
|
||||||
{
|
|
||||||
QAction *rc = registerNewAction(id, title);
|
|
||||||
if (!rc)
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
connect(rc, SIGNAL(triggered()), receiver, slot);
|
|
||||||
return rc;
|
|
||||||
}
|
|
||||||
|
|
||||||
void BinEditorPlugin::initializeEditor(BinEditorWidget *widget)
|
void BinEditorPlugin::initializeEditor(BinEditorWidget *widget)
|
||||||
{
|
{
|
||||||
m_context.add(Constants::C_BINEDITOR);
|
m_context.add(Constants::C_BINEDITOR);
|
||||||
if (!m_undoAction) {
|
if (!m_undoAction) {
|
||||||
m_undoAction = registerNewAction(Core::Constants::UNDO, this, SLOT(undoAction()), tr("&Undo"));
|
m_undoAction = registerNewAction(Core::Constants::UNDO, tr("&Undo"));
|
||||||
m_redoAction = registerNewAction(Core::Constants::REDO, this, SLOT(redoAction()), tr("&Redo"));
|
connect(m_undoAction, &QAction::triggered, this, &BinEditorPlugin::undoAction);
|
||||||
m_copyAction = registerNewAction(Core::Constants::COPY, this, SLOT(copyAction()));
|
m_redoAction = registerNewAction(Core::Constants::REDO, tr("&Redo"));
|
||||||
m_selectAllAction = registerNewAction(Core::Constants::SELECTALL, this, SLOT(selectAllAction()));
|
connect(m_redoAction, &QAction::triggered, this, &BinEditorPlugin::redoAction);
|
||||||
|
m_copyAction = registerNewAction(Core::Constants::COPY);
|
||||||
|
connect(m_copyAction, &QAction::triggered, this, &BinEditorPlugin::copyAction);
|
||||||
|
m_selectAllAction = registerNewAction(Core::Constants::SELECTALL);
|
||||||
|
connect(m_selectAllAction, &QAction::triggered, this, &BinEditorPlugin::selectAllAction);
|
||||||
}
|
}
|
||||||
|
|
||||||
QObject::connect(widget, SIGNAL(undoAvailable(bool)), this, SLOT(updateActions()));
|
QObject::connect(widget, &BinEditorWidget::undoAvailable,
|
||||||
QObject::connect(widget, SIGNAL(redoAvailable(bool)), this, SLOT(updateActions()));
|
this, &BinEditorPlugin::updateActions);
|
||||||
|
QObject::connect(widget, &BinEditorWidget::redoAvailable,
|
||||||
|
this, &BinEditorPlugin::updateActions);
|
||||||
|
|
||||||
Aggregation::Aggregate *aggregate = new Aggregation::Aggregate;
|
auto aggregate = new Aggregation::Aggregate;
|
||||||
BinEditorFind *binEditorFind = new BinEditorFind(widget);
|
auto binEditorFind = new BinEditorFind(widget);
|
||||||
aggregate->add(binEditorFind);
|
aggregate->add(binEditorFind);
|
||||||
aggregate->add(widget);
|
aggregate->add(widget);
|
||||||
}
|
}
|
||||||
@@ -524,8 +519,8 @@ bool BinEditorPlugin::initialize(const QStringList &arguments, QString *errorMes
|
|||||||
Q_UNUSED(arguments)
|
Q_UNUSED(arguments)
|
||||||
Q_UNUSED(errorMessage)
|
Q_UNUSED(errorMessage)
|
||||||
|
|
||||||
connect(Core::EditorManager::instance(), SIGNAL(currentEditorChanged(Core::IEditor*)),
|
connect(Core::EditorManager::instance(), &EditorManager::currentEditorChanged,
|
||||||
this, SLOT(updateCurrentEditor(Core::IEditor*)));
|
this, &BinEditorPlugin::updateCurrentEditor);
|
||||||
|
|
||||||
addAutoReleasedObject(new BinEditorFactory(this));
|
addAutoReleasedObject(new BinEditorFactory(this));
|
||||||
addAutoReleasedObject(new BinEditorWidgetFactory);
|
addAutoReleasedObject(new BinEditorWidgetFactory);
|
||||||
|
|||||||
@@ -54,7 +54,7 @@ public:
|
|||||||
// Connect editor to settings changed signals.
|
// Connect editor to settings changed signals.
|
||||||
void initializeEditor(BinEditorWidget *editor);
|
void initializeEditor(BinEditorWidget *editor);
|
||||||
|
|
||||||
private slots:
|
private:
|
||||||
void undoAction();
|
void undoAction();
|
||||||
void redoAction();
|
void redoAction();
|
||||||
void copyAction();
|
void copyAction();
|
||||||
@@ -63,11 +63,8 @@ private slots:
|
|||||||
|
|
||||||
void updateCurrentEditor(Core::IEditor *editor);
|
void updateCurrentEditor(Core::IEditor *editor);
|
||||||
|
|
||||||
private:
|
|
||||||
Core::Context m_context;
|
Core::Context m_context;
|
||||||
QAction *registerNewAction(Core::Id id, const QString &title = QString());
|
QAction *registerNewAction(Core::Id id, const QString &title = QString());
|
||||||
QAction *registerNewAction(Core::Id id, QObject *receiver, const char *slot,
|
|
||||||
const QString &title = QString());
|
|
||||||
QAction *m_undoAction;
|
QAction *m_undoAction;
|
||||||
QAction *m_redoAction;
|
QAction *m_redoAction;
|
||||||
QAction *m_copyAction;
|
QAction *m_copyAction;
|
||||||
|
|||||||
Reference in New Issue
Block a user