diff options
author | hjk <hjk@theqtcompany.com> | 2016-06-01 10:54:41 +0200 |
---|---|---|
committer | hjk <hjk@theqtcompany.com> | 2016-06-03 06:19:20 +0000 |
commit | 8fd12818c9fce12e30771d833beff913aeaf2f50 (patch) | |
tree | c6a17a39a16bc676f472dbeaada46d6bc6a1e7ec /src/plugins/bineditor | |
parent | 2fbf126e4e684bde49e6f59ebf49b9f26147791a (diff) | |
download | qt-creator-8fd12818c9fce12e30771d833beff913aeaf2f50.tar.gz |
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>
Diffstat (limited to 'src/plugins/bineditor')
-rw-r--r-- | src/plugins/bineditor/bineditor.cpp | 16 | ||||
-rw-r--r-- | src/plugins/bineditor/bineditor.h | 2 | ||||
-rw-r--r-- | src/plugins/bineditor/bineditorplugin.cpp | 111 | ||||
-rw-r--r-- | src/plugins/bineditor/bineditorplugin.h | 5 |
4 files changed, 63 insertions, 71 deletions
diff --git a/src/plugins/bineditor/bineditor.cpp b/src/plugins/bineditor/bineditor.cpp index f20af207fb..5fe5745dab 100644 --- a/src/plugins/bineditor/bineditor.cpp +++ b/src/plugins/bineditor/bineditor.cpp @@ -927,7 +927,7 @@ void BinEditorWidget::paintEvent(QPaintEvent *e) } -int BinEditorWidget::cursorPosition() const +qint64 BinEditorWidget::cursorPosition() const { return m_cursorPosition; } @@ -1483,13 +1483,13 @@ void BinEditorWidget::contextMenuEvent(QContextMenuEvent *event) QPointer<QMenu> contextMenu(new QMenu(this)); - QAction *copyAsciiAction = new QAction(tr("Copy Selection as ASCII Characters"), contextMenu); - QAction *copyHexAction = new QAction(tr("Copy Selection as Hex Values"), contextMenu); - QAction *jumpToBeAddressHereAction = new QAction(contextMenu); - QAction *jumpToBeAddressNewWindowAction = new QAction(contextMenu); - QAction *jumpToLeAddressHereAction = new QAction(contextMenu); - QAction *jumpToLeAddressNewWindowAction = new QAction(contextMenu); - QAction *addWatchpointAction = new QAction(tr("Set Data Breakpoint on Selection"), contextMenu); + auto copyAsciiAction = new QAction(tr("Copy Selection as ASCII Characters"), contextMenu); + auto copyHexAction = new QAction(tr("Copy Selection as Hex Values"), contextMenu); + auto jumpToBeAddressHereAction = new QAction(contextMenu); + auto jumpToBeAddressNewWindowAction = new QAction(contextMenu); + auto jumpToLeAddressHereAction = new QAction(contextMenu); + auto jumpToLeAddressNewWindowAction = new QAction(contextMenu); + auto addWatchpointAction = new QAction(tr("Set Data Breakpoint on Selection"), contextMenu); contextMenu->addAction(copyAsciiAction); contextMenu->addAction(copyHexAction); contextMenu->addAction(addWatchpointAction); diff --git a/src/plugins/bineditor/bineditor.h b/src/plugins/bineditor/bineditor.h index 007de40871..86979722f0 100644 --- a/src/plugins/bineditor/bineditor.h +++ b/src/plugins/bineditor/bineditor.h @@ -79,7 +79,7 @@ public: KeepAnchor }; - int cursorPosition() const; + qint64 cursorPosition() const; Q_INVOKABLE void setCursorPosition(qint64 pos, MoveMode moveMode = MoveAnchor); void jumpToAddress(quint64 address); diff --git a/src/plugins/bineditor/bineditorplugin.cpp b/src/plugins/bineditor/bineditorplugin.cpp index 9d27db2dde..f3592851f3 100644 --- a/src/plugins/bineditor/bineditorplugin.cpp +++ b/src/plugins/bineditor/bineditorplugin.cpp @@ -97,27 +97,27 @@ public: m_incrementalWrappedState = false; } - bool supportsReplace() const { return false; } - QString currentFindString() const { return QString(); } - QString completedFindString() const { return QString(); } + bool supportsReplace() const override { return false; } + QString currentFindString() const override { return QString(); } + QString completedFindString() const override { return QString(); } - FindFlags supportedFindFlags() const + FindFlags supportedFindFlags() const override { return FindBackward | FindCaseSensitively; } - void resetIncrementalSearch() + void resetIncrementalSearch() override { m_incrementalStartPos = m_contPos = -1; 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)); } - void clearHighlights() + void clearHighlights() override { m_widget->highlightSearchResults(QByteArray()); } @@ -143,7 +143,8 @@ public: return res; } - Result findIncremental(const QString &txt, FindFlags findFlags) { + Result findIncremental(const QString &txt, FindFlags findFlags) override + { QByteArray pattern = txt.toLatin1(); if (pattern != m_lastPattern) resetIncrementalSearch(); // Because we don't search for nibbles. @@ -178,7 +179,8 @@ public: return result; } - Result findStep(const QString &txt, FindFlags findFlags) { + Result findStep(const QString &txt, FindFlags findFlags) override + { QByteArray pattern = txt.toLatin1(); bool wasReset = (m_incrementalStartPos < 0); if (m_contPos == -1) { @@ -211,8 +213,8 @@ public: private: BinEditorWidget *m_widget; - int m_incrementalStartPos; - int m_contPos; // Only valid if last result was NotYetFound. + qint64 m_incrementalStartPos; + qint64 m_contPos; // Only valid if last result was NotYetFound. bool m_incrementalWrappedState; QByteArray m_lastPattern; }; @@ -228,11 +230,12 @@ public: setId(Core::Constants::K_DEFAULT_BINARY_EDITOR_ID); setMimeType(QLatin1String(BinEditor::Constants::C_BINEDITOR_MIMETYPE)); m_widget = parent; - connect(m_widget, SIGNAL(dataRequested(quint64)), - this, SLOT(provideData(quint64))); - connect(m_widget, SIGNAL(newRangeRequested(quint64)), - this, SLOT(provideNewRange(quint64))); - connect(m_widget, &BinEditorWidget::dataChanged, this, &IDocument::contentsChanged); + connect(m_widget, &BinEditorWidget::dataRequested, + this, &BinEditorDocument::provideData); + connect(m_widget, &BinEditorWidget::newRangeRequested, + this, &BinEditorDocument::provideNewRange); + connect(m_widget, &BinEditorWidget::dataChanged, + this, &IDocument::contentsChanged); } QByteArray contents() const override @@ -313,7 +316,6 @@ public: return OpenResult::ReadError; } -private slots: void provideData(quint64 block) { const FileName fn = filePath(); @@ -342,7 +344,6 @@ private slots: } public: - bool isModified() const override { return isTemporary()/*e.g. memory view*/ ? false @@ -358,7 +359,8 @@ public: 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) return true; if (type == TypePermissions) { @@ -390,13 +392,12 @@ public: m_context.add(Core::Constants::K_DEFAULT_BINARY_EDITOR_ID); m_context.add(Constants::C_BINEDITOR); m_addressEdit = new QLineEdit; - QRegExpValidator * const addressValidator - = new QRegExpValidator(QRegExp(QLatin1String("[0-9a-fA-F]{1,16}")), - m_addressEdit); + auto addressValidator = new QRegExpValidator(QRegExp(QLatin1String("[0-9a-fA-F]{1,16}")), + m_addressEdit); m_addressEdit->setValidator(addressValidator); - QHBoxLayout *l = new QHBoxLayout; - QWidget *w = new QWidget; + auto l = new QHBoxLayout; + auto w = new QWidget; l->setMargin(0); l->setContentsMargins(0, 0, 5, 0); l->addStretch(1); @@ -409,9 +410,12 @@ public: widget->setEditor(this); - connect(widget, SIGNAL(cursorPositionChanged(int)), SLOT(updateCursorPosition(int))); - connect(m_addressEdit, SIGNAL(editingFinished()), SLOT(jumpToAddress())); - connect(widget, SIGNAL(modificationChanged(bool)), m_file, SIGNAL(changed())); + connect(widget, &BinEditorWidget::cursorPositionChanged, + this, &BinEditor::updateCursorPosition); + connect(m_addressEdit, &QLineEdit::editingFinished, + this, &BinEditor::jumpToAddress); + connect(widget, &BinEditorWidget::modificationChanged, + m_file, &IDocument::changed); updateCursorPosition(widget->cursorPosition()); } @@ -424,8 +428,8 @@ public: QWidget *toolBar() override { return m_toolBar; } -private slots: - void updateCursorPosition(int position) { +private: + void updateCursorPosition(qint64 position) { m_addressEdit->setText(QString::number(editorWidget()->baseAddress() + position, 16)); } @@ -434,8 +438,7 @@ private slots: updateCursorPosition(editorWidget()->cursorPosition()); } -private: - inline BinEditorWidget *editorWidget() const + BinEditorWidget *editorWidget() const { QTC_ASSERT(qobject_cast<BinEditorWidget *>(m_widget.data()), return 0); return static_cast<BinEditorWidget *>(m_widget.data()); @@ -461,9 +464,8 @@ BinEditorFactory::BinEditorFactory(BinEditorPlugin *owner) : IEditor *BinEditorFactory::createEditor() { - BinEditorWidget *widget = new BinEditorWidget(); - BinEditor *editor = new BinEditor(widget); - + auto widget = new BinEditorWidget(); + auto editor = new BinEditor(widget); m_owner->initializeEditor(widget); return editor; } @@ -482,39 +484,32 @@ BinEditorPlugin::~BinEditorPlugin() 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); 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) { m_context.add(Constants::C_BINEDITOR); if (!m_undoAction) { - m_undoAction = registerNewAction(Core::Constants::UNDO, this, SLOT(undoAction()), tr("&Undo")); - m_redoAction = registerNewAction(Core::Constants::REDO, this, SLOT(redoAction()), tr("&Redo")); - m_copyAction = registerNewAction(Core::Constants::COPY, this, SLOT(copyAction())); - m_selectAllAction = registerNewAction(Core::Constants::SELECTALL, this, SLOT(selectAllAction())); + m_undoAction = registerNewAction(Core::Constants::UNDO, tr("&Undo")); + connect(m_undoAction, &QAction::triggered, this, &BinEditorPlugin::undoAction); + m_redoAction = registerNewAction(Core::Constants::REDO, tr("&Redo")); + 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, SIGNAL(redoAvailable(bool)), this, SLOT(updateActions())); + QObject::connect(widget, &BinEditorWidget::undoAvailable, + this, &BinEditorPlugin::updateActions); + QObject::connect(widget, &BinEditorWidget::redoAvailable, + this, &BinEditorPlugin::updateActions); - Aggregation::Aggregate *aggregate = new Aggregation::Aggregate; - BinEditorFind *binEditorFind = new BinEditorFind(widget); + auto aggregate = new Aggregation::Aggregate; + auto binEditorFind = new BinEditorFind(widget); aggregate->add(binEditorFind); aggregate->add(widget); } @@ -524,8 +519,8 @@ bool BinEditorPlugin::initialize(const QStringList &arguments, QString *errorMes Q_UNUSED(arguments) Q_UNUSED(errorMessage) - connect(Core::EditorManager::instance(), SIGNAL(currentEditorChanged(Core::IEditor*)), - this, SLOT(updateCurrentEditor(Core::IEditor*))); + connect(Core::EditorManager::instance(), &EditorManager::currentEditorChanged, + this, &BinEditorPlugin::updateCurrentEditor); addAutoReleasedObject(new BinEditorFactory(this)); addAutoReleasedObject(new BinEditorWidgetFactory); diff --git a/src/plugins/bineditor/bineditorplugin.h b/src/plugins/bineditor/bineditorplugin.h index 2dba62e5e9..4fd3c743f8 100644 --- a/src/plugins/bineditor/bineditorplugin.h +++ b/src/plugins/bineditor/bineditorplugin.h @@ -54,7 +54,7 @@ public: // Connect editor to settings changed signals. void initializeEditor(BinEditorWidget *editor); -private slots: +private: void undoAction(); void redoAction(); void copyAction(); @@ -63,11 +63,8 @@ private slots: void updateCurrentEditor(Core::IEditor *editor); -private: Core::Context m_context; 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_redoAction; QAction *m_copyAction; |