diff options
author | Alessandro Portale <alessandro.portale@qt.io> | 2018-11-07 23:45:39 +0100 |
---|---|---|
committer | Alessandro Portale <alessandro.portale@qt.io> | 2018-11-08 21:32:29 +0000 |
commit | df1f9752529b92fc8ffa114f58c43adf52132189 (patch) | |
tree | 79e9def310994802b7c64630a88a9c8c647af207 /src/plugins/fakevim | |
parent | f05f4d304f89a625506f9205126c82b3e1899121 (diff) |
FakeVim: Modernize
modernize-use-auto
modernize-use-nullptr
modernize-use-override
modernize-use-using
modernize-use-equals-default
Change-Id: I320a08a99a1d18ab87aec207ec1e03190009b592
Reviewed-by: Orgad Shaneh <orgads@gmail.com>
Diffstat (limited to 'src/plugins/fakevim')
-rw-r--r-- | src/plugins/fakevim/fakevim_test.cpp | 2 | ||||
-rw-r--r-- | src/plugins/fakevim/fakevimactions.cpp | 4 | ||||
-rw-r--r-- | src/plugins/fakevim/fakevimactions.h | 4 | ||||
-rw-r--r-- | src/plugins/fakevim/fakevimhandler.cpp | 48 | ||||
-rw-r--r-- | src/plugins/fakevim/fakevimhandler.h | 10 | ||||
-rw-r--r-- | src/plugins/fakevim/fakevimplugin.cpp | 69 | ||||
-rw-r--r-- | src/plugins/fakevim/fakevimplugin.h | 8 |
7 files changed, 72 insertions, 73 deletions
diff --git a/src/plugins/fakevim/fakevim_test.cpp b/src/plugins/fakevim/fakevim_test.cpp index a5dca213fb..88973a5200 100644 --- a/src/plugins/fakevim/fakevim_test.cpp +++ b/src/plugins/fakevim/fakevim_test.cpp @@ -255,7 +255,7 @@ struct FakeVimPlugin::TestData int lines() const { QTextDocument *doc = editor()->document(); - Q_ASSERT(doc != 0); + Q_ASSERT(doc != nullptr); return doc->lineCount(); } diff --git a/src/plugins/fakevim/fakevimactions.cpp b/src/plugins/fakevim/fakevimactions.cpp index db8b82c1bf..0c6dcc01ec 100644 --- a/src/plugins/fakevim/fakevimactions.cpp +++ b/src/plugins/fakevim/fakevimactions.cpp @@ -146,7 +146,7 @@ void FakeVimSettings::writeSettings(QSettings *settings) FakeVimAction *FakeVimSettings::item(int code) { - QTC_ASSERT(m_items.value(code, 0), qDebug() << "CODE: " << code; return 0); + QTC_ASSERT(m_items.value(code, 0), qDebug() << "CODE: " << code; return nullptr); return m_items.value(code, 0); } @@ -176,7 +176,7 @@ void FakeVimSettings::createAction(int code, const QVariant &value, const QString &settingsKey, const QString &shortKey) { - FakeVimAction *item = new FakeVimAction(0); + auto item = new FakeVimAction(nullptr); item->setValue(value); item->setSettingsKey("FakeVim", settingsKey); item->setDefaultValue(value); diff --git a/src/plugins/fakevim/fakevimactions.h b/src/plugins/fakevim/fakevimactions.h index e1c230ba51..f0607f33d8 100644 --- a/src/plugins/fakevim/fakevimactions.h +++ b/src/plugins/fakevim/fakevimactions.h @@ -61,9 +61,9 @@ public: }; #ifdef FAKEVIM_STANDALONE -typedef DummyAction FakeVimAction; +using FakeVimAction = DummyAction; #else -typedef Utils::SavedAction FakeVimAction; +using FakeVimAction = Utils::SavedAction; #endif enum FakeVimSettingsCode diff --git a/src/plugins/fakevim/fakevimhandler.cpp b/src/plugins/fakevim/fakevimhandler.cpp index 2b0e7ab10c..e90393c9cf 100644 --- a/src/plugins/fakevim/fakevimhandler.cpp +++ b/src/plugins/fakevim/fakevimhandler.cpp @@ -252,7 +252,7 @@ enum EventResult struct CursorPosition { - CursorPosition() {} + CursorPosition() = default; CursorPosition(int block, int column) : line(block), column(column) {} explicit CursorPosition(const QTextCursor &tc) : line(tc.block().blockNumber()), column(tc.positionInBlock()) {} @@ -320,12 +320,12 @@ private: CursorPosition m_position; QString m_fileName; }; -typedef QHash<QChar, Mark> Marks; -typedef QHashIterator<QChar, Mark> MarksIterator; +using Marks = QHash<QChar, Mark>; +using MarksIterator = QHashIterator<QChar, Mark>; struct State { - State() {} + State() = default; State(int revision, const CursorPosition &position, const Marks &marks, VisualMode lastVisualMode, bool lastVisualModeInverted) : revision(revision), position(position), marks(marks), lastVisualMode(lastVisualMode), @@ -354,7 +354,7 @@ QDebug operator<<(QDebug ts, const Column &col) struct Register { - Register() {} + Register() = default; Register(const QString &c) : contents(c) {} Register(const QString &c, RangeMode m) : contents(c), rangemode(m) {} QString contents; @@ -982,7 +982,7 @@ public: return m & ~Qt::KeypadModifier; } - Input() {} + Input() = default; explicit Input(QChar x) : m_key(x.unicode()), m_xkey(x.unicode()), m_text(x) { @@ -1252,7 +1252,7 @@ QDebug operator<<(QDebug ts, const Input &input) { return input.dump(ts); } class Inputs : public QVector<Input> { public: - Inputs() {} + Inputs() = default; explicit Inputs(const QString &str, bool noremap = true, bool silent = false) : m_noremap(noremap), m_silent(silent) @@ -1521,7 +1521,7 @@ private: }; // Mappings for all modes -typedef QHash<char, ModeMapping> Mappings; +using Mappings = QHash<char, ModeMapping>; // Iterator for mappings class MappingsIterator : public QVector<ModeMapping::Iterator> @@ -1641,7 +1641,7 @@ private: // state of current mapping struct MappingState { - MappingState() {} + MappingState() = default; MappingState(bool noremap, bool silent, bool editBlock) : noremap(noremap), silent(silent), editBlock(editBlock) {} bool noremap = false; @@ -2037,7 +2037,7 @@ public: int position() const { return m_cursor.position(); } // Transform text selected by cursor in current visual mode. - typedef std::function<QString(const QString &)> Transformation; + using Transformation = std::function<QString(const QString &)>; void transformText(const Range &range, QTextCursor &tc, const std::function<void()> &transform) const; void transformText(const Range &range, const Transformation &transform); @@ -2119,7 +2119,7 @@ public: QString registerContents(int reg) const; void setRegister(int reg, const QString &contents, RangeMode mode); RangeMode registerRangeMode(int reg) const; - void getRegisterType(int *reg, bool *isClipboard, bool *isSelection, bool *append = 0) const; + void getRegisterType(int *reg, bool *isClipboard, bool *isSelection, bool *append = nullptr) const; void recordJump(int position = -1); void jump(int distance); @@ -2207,7 +2207,7 @@ public: QPointer<FakeVimHandler::Private> currentHandler; }; - typedef QSharedPointer<BufferData> BufferDataPtr; + using BufferDataPtr = QSharedPointer<BufferData>; void pullOrCreateBufferData(); BufferDataPtr m_buffer; @@ -5899,7 +5899,7 @@ bool FakeVimHandler::Private::handleExMoveCommand(const ExCommand &cmd) setMark('>', lastPosition); if (lines > 2) - showMessage(MessageInfo, Tr::tr("%n lines moved.", 0, lines)); + showMessage(MessageInfo, Tr::tr("%n lines moved.", nullptr, lines)); return true; } @@ -6044,7 +6044,7 @@ bool FakeVimHandler::Private::handleExBangCommand(const ExCommand &cmd) // :! endEditBlock(); leaveVisualMode(); //qDebug() << "FILTER: " << command; - showMessage(MessageInfo, Tr::tr("%n lines filtered.", 0, + showMessage(MessageInfo, Tr::tr("%n lines filtered.", nullptr, input.count('\n'))); } else if (!result.isEmpty()) { q->extraInformationChanged(result); @@ -6489,7 +6489,7 @@ void FakeVimHandler::Private::indentSelectedText(QChar typedChar) const int lines = endLine - beginLine + 1; if (lines > 2) - showMessage(MessageInfo, Tr::tr("%n lines indented.", 0, lines)); + showMessage(MessageInfo, Tr::tr("%n lines indented.", nullptr, lines)); } void FakeVimHandler::Private::indentText(const Range &range, QChar typedChar) @@ -6545,7 +6545,7 @@ void FakeVimHandler::Private::shiftRegionRight(int repeat) const int lines = endLine - beginLine + 1; if (lines > 2) { showMessage(MessageInfo, - Tr::tr("%n lines %1ed %2 time.", 0, lines) + Tr::tr("%n lines %1ed %2 time.", nullptr, lines) .arg(repeat > 0 ? '>' : '<').arg(qAbs(repeat))); } } @@ -7083,7 +7083,7 @@ void FakeVimHandler::Private::yankText(const Range &range, int reg) const int lines = blockAt(range.endPos).blockNumber() - blockAt(range.beginPos).blockNumber() + 1; if (lines > 2) - showMessage(MessageInfo, Tr::tr("%n lines yanked.", 0, lines)); + showMessage(MessageInfo, Tr::tr("%n lines yanked.", nullptr, lines)); } void FakeVimHandler::Private::transformText( @@ -8610,7 +8610,7 @@ void FakeVimHandler::Private::getRegisterType(int *reg, bool *isClipboard, bool // If register is uppercase, append content to lower case register on yank/delete. const QChar c(*reg); - if (append != 0) + if (append != nullptr) *append = c.isUpper(); if (c.isUpper()) *reg = c.toLower().unicode(); @@ -8631,9 +8631,9 @@ void FakeVimHandler::Private::getRegisterType(int *reg, bool *isClipboard, bool selection = false; } - if (isClipboard != 0) + if (isClipboard != nullptr) *isClipboard = clipboard; - if (isSelection != 0) + if (isSelection != nullptr) *isSelection = selection; } @@ -8655,8 +8655,8 @@ FakeVimHandler::~FakeVimHandler() // gracefully handle that the parent editor is deleted void FakeVimHandler::disconnectFromEditor() { - d->m_textedit = 0; - d->m_plaintextedit = 0; + d->m_textedit = nullptr; + d->m_plaintextedit = nullptr; } void FakeVimHandler::updateGlobalMarksFilenames(const QString &oldFileName, const QString &newFileName) @@ -8683,7 +8683,7 @@ bool FakeVimHandler::eventFilter(QObject *ob, QEvent *ev) if (ev->type() == QEvent::KeyPress && (ob == d->editor() || (Private::g.mode == ExMode || Private::g.subsubmode == SearchSubSubMode))) { - QKeyEvent *kev = static_cast<QKeyEvent *>(ev); + auto kev = static_cast<QKeyEvent *>(ev); KEY_DEBUG("KEYPRESS" << kev->key() << kev->text() << QChar(kev->key())); EventResult res = d->handleEvent(kev); //if (Private::g.mode == InsertMode) @@ -8697,7 +8697,7 @@ bool FakeVimHandler::eventFilter(QObject *ob, QEvent *ev) if (ev->type() == QEvent::ShortcutOverride && (ob == d->editor() || (Private::g.mode == ExMode || Private::g.subsubmode == SearchSubSubMode))) { - QKeyEvent *kev = static_cast<QKeyEvent *>(ev); + auto kev = static_cast<QKeyEvent *>(ev); if (d->wantsOverride(kev)) { KEY_DEBUG("OVERRIDING SHORTCUT" << kev->key()); ev->accept(); // accepting means "don't run the shortcuts" diff --git a/src/plugins/fakevim/fakevimhandler.h b/src/plugins/fakevim/fakevimhandler.h index 25ce463554..9ba321fca9 100644 --- a/src/plugins/fakevim/fakevimhandler.h +++ b/src/plugins/fakevim/fakevimhandler.h @@ -47,7 +47,7 @@ enum RangeMode struct Range { - Range() {} + Range() = default; Range(int b, int e, RangeMode m = RangeCharMode); QString toString() const; bool isValid() const; @@ -59,7 +59,7 @@ struct Range struct ExCommand { - ExCommand() {} + ExCommand() = default; ExCommand(const QString &cmd, const QString &args = QString(), const Range &range = Range()); @@ -107,8 +107,8 @@ class FakeVimHandler : public QObject Q_OBJECT public: - explicit FakeVimHandler(QWidget *widget, QObject *parent = 0); - ~FakeVimHandler(); + explicit FakeVimHandler(QWidget *widget, QObject *parent = nullptr); + ~FakeVimHandler() override; QWidget *widget(); @@ -151,7 +151,7 @@ public: bool jumpToLocalMark(QChar mark, bool backTickMode); - bool eventFilter(QObject *ob, QEvent *ev); + bool eventFilter(QObject *ob, QEvent *ev) override; Signal<void(const QString &msg, int cursorPos, int anchorPos, int messageLevel)> commandBufferChanged; Signal<void(const QString &msg)> statusDataChanged; diff --git a/src/plugins/fakevim/fakevimplugin.cpp b/src/plugins/fakevim/fakevimplugin.cpp index 443b36f4d9..0cf2311269 100644 --- a/src/plugins/fakevim/fakevimplugin.cpp +++ b/src/plugins/fakevim/fakevimplugin.cpp @@ -200,7 +200,7 @@ public: m_lastMessageLevel = messageLevel; } - QSize sizeHint() const + QSize sizeHint() const override { QSize size = QWidget::sizeHint(); // reserve maximal width for line edit widget @@ -259,7 +259,7 @@ public: } protected: - void paintEvent(QPaintEvent *event) + void paintEvent(QPaintEvent *event) override { QTextCursor firstVisibleCursor = m_editor->cursorForPosition(QPoint(0, 0)); QTextBlock firstVisibleBlock = firstVisibleCursor.block(); @@ -310,7 +310,7 @@ protected: } } - bool eventFilter(QObject *, QEvent *event) + bool eventFilter(QObject *, QEvent *event) override { if (event->type() == QEvent::Resize || event->type() == QEvent::Move) m_timerUpdate.start(); @@ -352,8 +352,8 @@ private: // /////////////////////////////////////////////////////////////////////// -typedef QMap<QString, QRegExp> ExCommandMap; -typedef QMap<int, QString> UserCommandMap; +using ExCommandMap = QMap<QString, QRegExp>; +using UserCommandMap = QMap<int, QString>; class FakeVimOptionPage : public IOptionsPage { @@ -368,9 +368,9 @@ public: Utils::Theme::PanelTextColorDark}}, Utils::Icon::Tint)); } - QWidget *widget(); - void apply(); - void finish(); + QWidget *widget() override; + void apply() override; + void finish() override; private: void copyTextEditorSettings(); @@ -556,7 +556,7 @@ public: void setActionChecked(Id id, bool check); - typedef int (*DistFunction)(const QRect &cursor, const QRect &other); + using DistFunction = int (*)(const QRect &, const QRect &); void moveSomewhere(FakeVimHandler *handler, DistFunction f, int count); void keepOnlyWindow(); // :only @@ -676,7 +676,7 @@ void FakeVimExCommandsPage::apply() QSettings *settings = ICore::settings(); settings->beginWriteArray(exCommandMapGroup); int count = 0; - typedef ExCommandMap::const_iterator Iterator; + using Iterator = ExCommandMap::const_iterator; const Iterator end = newMapping.constEnd(); for (Iterator it = newMapping.constBegin(); it != end; ++it) { const QString id = it.key(); @@ -807,12 +807,12 @@ public: FakeVimUserCommandsModel() { m_commandMap = dd->m_userCommandMap; } UserCommandMap commandMap() const { return m_commandMap; } - int rowCount(const QModelIndex &parent) const; - int columnCount(const QModelIndex &parent) const; - QVariant data(const QModelIndex &index, int role) const; - bool setData(const QModelIndex &index, const QVariant &data, int role); - QVariant headerData(int section, Qt::Orientation orientation, int role) const; - Qt::ItemFlags flags(const QModelIndex &index) const; + int rowCount(const QModelIndex &parent) const override; + int columnCount(const QModelIndex &parent) const override; + QVariant data(const QModelIndex &index, int role) const override; + bool setData(const QModelIndex &index, const QVariant &data, int role) override; + QVariant headerData(int section, Qt::Orientation orientation, int role) const override; + Qt::ItemFlags flags(const QModelIndex &index) const override; private: UserCommandMap m_commandMap; @@ -856,7 +856,7 @@ public: {} QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &, - const QModelIndex &) const + const QModelIndex &) const override { auto lineEdit = new QLineEdit(parent); lineEdit->setFrame(false); @@ -864,9 +864,9 @@ public: } void setModelData(QWidget *editor, QAbstractItemModel *model, - const QModelIndex &index) const + const QModelIndex &index) const override { - QLineEdit *lineEdit = qobject_cast<QLineEdit *>(editor); + auto lineEdit = qobject_cast<QLineEdit *>(editor); QTC_ASSERT(lineEdit, return); model->setData(index, lineEdit->text(), Qt::EditRole); } @@ -891,7 +891,7 @@ public: private: QPointer<QWidget> m_widget; - FakeVimUserCommandsModel *m_model; + FakeVimUserCommandsModel *m_model = nullptr; }; QWidget *FakeVimUserCommandsPage::widget() @@ -928,7 +928,7 @@ void FakeVimUserCommandsPage::apply() QSettings *settings = ICore::settings(); settings->beginWriteArray(userCommandMapGroup); int count = 0; - typedef UserCommandMap::const_iterator Iterator; + using Iterator = UserCommandMap::const_iterator; const Iterator end = current.constEnd(); for (Iterator it = current.constBegin(); it != end; ++it) { const int key = it.key(); @@ -960,7 +960,7 @@ void FakeVimUserCommandsPage::apply() class FakeVimCompletionAssistProvider : public CompletionAssistProvider { public: - IAssistProcessor *createProcessor() const; + IAssistProcessor *createProcessor() const override; void setActive(const QString &needle, bool forward, FakeVimHandler *handler) { @@ -969,7 +969,7 @@ public: if (!m_handler) return; - TextEditorWidget *editor = qobject_cast<TextEditorWidget *>(handler->widget()); + auto editor = qobject_cast<TextEditorWidget *>(handler->widget()); if (!editor) return; @@ -1258,7 +1258,7 @@ void FakeVimPluginPrivate::userActionTriggered(int key) void FakeVimPluginPrivate::createRelativeNumberWidget(IEditor *editor) { - if (TextEditorWidget *textEditor = qobject_cast<TextEditorWidget *>(editor->widget())) { + if (auto textEditor = qobject_cast<TextEditorWidget *>(editor->widget())) { auto relativeNumbers = new RelativeNumbersColumn(textEditor); connect(theFakeVimSetting(ConfigRelativeNumber), &SavedAction::valueChanged, relativeNumbers, &QObject::deleteLater); @@ -1386,13 +1386,13 @@ void FakeVimPluginPrivate::moveSomewhere(FakeVimHandler *handler, DistFunction f { QTC_ASSERT(handler, return); QWidget *w = handler->widget(); - QPlainTextEdit *pe = qobject_cast<QPlainTextEdit *>(w); + auto pe = qobject_cast<QPlainTextEdit *>(w); QTC_ASSERT(pe, return); QRect rc = pe->cursorRect(); QRect cursorRect(w->mapToGlobal(rc.topLeft()), w->mapToGlobal(rc.bottomRight())); //qDebug() << "\nCURSOR: " << cursorRect; - IEditor *bestEditor = 0; + IEditor *bestEditor = nullptr; int repeat = count; IEditor *currentEditor = EditorManager::currentEditor(); @@ -1503,12 +1503,12 @@ public: : QObject(parent), m_handler(handler) {} - ~DeferredDeleter() + ~DeferredDeleter() override { if (m_handler) { m_handler->disconnectFromEditor(); m_handler->deleteLater(); - m_handler = 0; + m_handler = nullptr; } } }; @@ -1526,12 +1526,12 @@ void FakeVimPluginPrivate::editorOpened(IEditor *editor) if (!qobject_cast<QTextEdit *>(widget) && !qobject_cast<QPlainTextEdit *>(widget)) return; - TextEditorWidget *tew = qobject_cast<TextEditorWidget *>(widget); + auto tew = qobject_cast<TextEditorWidget *>(widget); //qDebug() << "OPENING: " << editor << editor->widget() // << "MODE: " << theFakeVimSetting(ConfigUseFakeVim)->value(); - auto handler = new FakeVimHandler(widget, 0); + auto handler = new FakeVimHandler(widget, nullptr); // the handler might have triggered the deletion of the editor: // make sure that it can return before being deleted itself new DeferredDeleter(widget, handler); @@ -1560,8 +1560,7 @@ void FakeVimPluginPrivate::editorOpened(IEditor *editor) handler->highlightMatches.connect([](const QString &needle) { for (IEditor *editor : EditorManager::visibleEditors()) { QWidget *w = editor->widget(); - IFindSupport *find = Aggregation::query<IFindSupport>(w); - if (find != 0) + if (auto find = Aggregation::query<IFindSupport>(w)) find->highlightAll(needle, FindRegularExpression | FindCaseSensitively); } }); @@ -1707,7 +1706,7 @@ void FakeVimPluginPrivate::editorOpened(IEditor *editor) handler->foldAll.connect([handler](bool fold) { QTextDocument *document = handler->textCursor().document(); auto documentLayout = qobject_cast<TextDocumentLayout*>(document->documentLayout()); - QTC_ASSERT(documentLayout != 0, return); + QTC_ASSERT(documentLayout, return); QTextBlock block = document->firstBlock(); while (block.isValid()) { @@ -1871,7 +1870,7 @@ void FakeVimPluginPrivate::setUseFakeVimInternal(bool on) // Context(FAKEVIM_CONTEXT)); resetCommandBuffer(); foreach (IEditor *editor, m_editorToHandler.keys()) { - if (TextDocument *textDocument = qobject_cast<TextDocument *>(editor->document())) + if (auto textDocument = qobject_cast<const TextDocument *>(editor->document())) m_editorToHandler[editor]->restoreWidget(textDocument->tabSettings().m_tabSize); } } @@ -1928,7 +1927,7 @@ void FakeVimPluginPrivate::handleExCommand(FakeVimHandler *handler, bool *handle if (failed.isEmpty()) handler->showMessage(MessageInfo, Tr::tr("Saving succeeded")); else - handler->showMessage(MessageError, Tr::tr("%n files not saved", 0, failed.size())); + handler->showMessage(MessageError, Tr::tr("%n files not saved", nullptr, failed.size())); if (cmd.matches("wqa", "wqall")) emit delayedQuitAllRequested(cmd.hasBang); } else if (cmd.matches("q", "quit")) { diff --git a/src/plugins/fakevim/fakevimplugin.h b/src/plugins/fakevim/fakevimplugin.h index 98f526ce44..2dbcbfcb8a 100644 --- a/src/plugins/fakevim/fakevimplugin.h +++ b/src/plugins/fakevim/fakevimplugin.h @@ -39,13 +39,13 @@ class FakeVimPlugin : public ExtensionSystem::IPlugin public: FakeVimPlugin(); - ~FakeVimPlugin(); + ~FakeVimPlugin() override; private: // implementation of ExtensionSystem::IPlugin - bool initialize(const QStringList &arguments, QString *errorMessage); - ShutdownFlag aboutToShutdown(); - void extensionsInitialized(); + bool initialize(const QStringList &arguments, QString *errorMessage) override; + ShutdownFlag aboutToShutdown() override; + void extensionsInitialized() override; private: friend class FakeVimPluginPrivate; |