EmacsKeys: Use Qt5-style connects

The heavy lifting was done by clazy.

Change-Id: Ib5fda624ef6d776fd238e15b562c9fc0dd6cab58
Reviewed-by: hjk <hjk@theqtcompany.com>
This commit is contained in:
Orgad Shaneh
2016-06-04 22:49:38 +03:00
committed by Orgad Shaneh
parent a9f73d079a
commit 38a13f09c2
4 changed files with 53 additions and 55 deletions

View File

@@ -46,12 +46,13 @@
#include <QtPlugin> #include <QtPlugin>
QT_BEGIN_NAMESPACE QT_BEGIN_NAMESPACE
extern void qt_set_sequence_auto_mnemonic(bool enable); extern void qt_set_sequence_auto_mnemonic(bool enable);
QT_END_NAMESPACE QT_END_NAMESPACE
using namespace EmacsKeys::Internal; using namespace Core;
namespace EmacsKeys {
namespace Internal {
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
// EmacsKeysPlugin // EmacsKeysPlugin
@@ -76,60 +77,56 @@ bool EmacsKeysPlugin::initialize(const QStringList &arguments, QString *errorStr
// Alt+W (Window). // Alt+W (Window).
qt_set_sequence_auto_mnemonic(false); qt_set_sequence_auto_mnemonic(false);
connect(Core::EditorManager::instance(), connect(EditorManager::instance(), &EditorManager::editorAboutToClose,
SIGNAL(editorAboutToClose(Core::IEditor*)), this, &EmacsKeysPlugin::editorAboutToClose);
this, connect(EditorManager::instance(), &EditorManager::currentEditorChanged,
SLOT(editorAboutToClose(Core::IEditor*))); this, &EmacsKeysPlugin::currentEditorChanged);
connect(Core::EditorManager::instance(),
SIGNAL(currentEditorChanged(Core::IEditor*)),
this,
SLOT(currentEditorChanged(Core::IEditor*)));
registerAction(Constants::DELETE_CHARACTER, registerAction(Constants::DELETE_CHARACTER,
SLOT(deleteCharacter()), tr("Delete Character")); &EmacsKeysPlugin::deleteCharacter, tr("Delete Character"));
registerAction(Constants::KILL_WORD, registerAction(Constants::KILL_WORD,
SLOT(killWord()), tr("Kill Word")); &EmacsKeysPlugin::killWord, tr("Kill Word"));
registerAction(Constants::KILL_LINE, registerAction(Constants::KILL_LINE,
SLOT(killLine()), tr("Kill Line")); &EmacsKeysPlugin::killLine, tr("Kill Line"));
registerAction(Constants::INSERT_LINE_AND_INDENT, registerAction(Constants::INSERT_LINE_AND_INDENT,
SLOT(insertLineAndIndent()), tr("Insert New Line and Indent")); &EmacsKeysPlugin::insertLineAndIndent, tr("Insert New Line and Indent"));
registerAction(Constants::GOTO_FILE_START, registerAction(Constants::GOTO_FILE_START,
SLOT(gotoFileStart()), tr("Go to File Start")); &EmacsKeysPlugin::gotoFileStart, tr("Go to File Start"));
registerAction(Constants::GOTO_FILE_END, registerAction(Constants::GOTO_FILE_END,
SLOT(gotoFileEnd()), tr("Go to File End")); &EmacsKeysPlugin::gotoFileEnd, tr("Go to File End"));
registerAction(Constants::GOTO_LINE_START, registerAction(Constants::GOTO_LINE_START,
SLOT(gotoLineStart()), tr("Go to Line Start")); &EmacsKeysPlugin::gotoLineStart, tr("Go to Line Start"));
registerAction(Constants::GOTO_LINE_END, registerAction(Constants::GOTO_LINE_END,
SLOT(gotoLineEnd()), tr("Go to Line End")); &EmacsKeysPlugin::gotoLineEnd, tr("Go to Line End"));
registerAction(Constants::GOTO_NEXT_LINE, registerAction(Constants::GOTO_NEXT_LINE,
SLOT(gotoNextLine()), tr("Go to Next Line")); &EmacsKeysPlugin::gotoNextLine, tr("Go to Next Line"));
registerAction(Constants::GOTO_PREVIOUS_LINE, registerAction(Constants::GOTO_PREVIOUS_LINE,
SLOT(gotoPreviousLine()), tr("Go to Previous Line")); &EmacsKeysPlugin::gotoPreviousLine, tr("Go to Previous Line"));
registerAction(Constants::GOTO_NEXT_CHARACTER, registerAction(Constants::GOTO_NEXT_CHARACTER,
SLOT(gotoNextCharacter()), tr("Go to Next Character")); &EmacsKeysPlugin::gotoNextCharacter, tr("Go to Next Character"));
registerAction(Constants::GOTO_PREVIOUS_CHARACTER, registerAction(Constants::GOTO_PREVIOUS_CHARACTER,
SLOT(gotoPreviousCharacter()), tr("Go to Previous Character")); &EmacsKeysPlugin::gotoPreviousCharacter, tr("Go to Previous Character"));
registerAction(Constants::GOTO_NEXT_WORD, registerAction(Constants::GOTO_NEXT_WORD,
SLOT(gotoNextWord()), tr("Go to Next Word")); &EmacsKeysPlugin::gotoNextWord, tr("Go to Next Word"));
registerAction(Constants::GOTO_PREVIOUS_WORD, registerAction(Constants::GOTO_PREVIOUS_WORD,
SLOT(gotoPreviousWord()), tr("Go to Previous Word")); &EmacsKeysPlugin::gotoPreviousWord, tr("Go to Previous Word"));
registerAction(Constants::MARK, registerAction(Constants::MARK,
SLOT(mark()), tr("Mark")); &EmacsKeysPlugin::mark, tr("Mark"));
registerAction(Constants::EXCHANGE_CURSOR_AND_MARK, registerAction(Constants::EXCHANGE_CURSOR_AND_MARK,
SLOT(exchangeCursorAndMark()), tr("Exchange Cursor and Mark")); &EmacsKeysPlugin::exchangeCursorAndMark, tr("Exchange Cursor and Mark"));
registerAction(Constants::COPY, registerAction(Constants::COPY,
SLOT(copy()), tr("Copy")); &EmacsKeysPlugin::copy, tr("Copy"));
registerAction(Constants::CUT, registerAction(Constants::CUT,
SLOT(cut()), tr("Cut")); &EmacsKeysPlugin::cut, tr("Cut"));
registerAction(Constants::YANK, registerAction(Constants::YANK,
SLOT(yank()), tr("Yank")); &EmacsKeysPlugin::yank, tr("Yank"));
registerAction(Constants::SCROLL_HALF_DOWN, registerAction(Constants::SCROLL_HALF_DOWN,
SLOT(scrollHalfDown()), tr("Scroll Half Screen Down")); &EmacsKeysPlugin::scrollHalfDown, tr("Scroll Half Screen Down"));
registerAction(Constants::SCROLL_HALF_UP, registerAction(Constants::SCROLL_HALF_UP,
SLOT(scrollHalfUp()), tr("Scroll Half Screen Up")); &EmacsKeysPlugin::scrollHalfUp, tr("Scroll Half Screen Up"));
return true; return true;
} }
@@ -142,7 +139,7 @@ ExtensionSystem::IPlugin::ShutdownFlag EmacsKeysPlugin::aboutToShutdown()
return SynchronousShutdown; return SynchronousShutdown;
} }
void EmacsKeysPlugin::editorAboutToClose(Core::IEditor *editor) void EmacsKeysPlugin::editorAboutToClose(IEditor *editor)
{ {
QPlainTextEdit *w = qobject_cast<QPlainTextEdit*>(editor->widget()); QPlainTextEdit *w = qobject_cast<QPlainTextEdit*>(editor->widget());
if (!w) if (!w)
@@ -154,7 +151,7 @@ void EmacsKeysPlugin::editorAboutToClose(Core::IEditor *editor)
} }
} }
void EmacsKeysPlugin::currentEditorChanged(Core::IEditor *editor) void EmacsKeysPlugin::currentEditorChanged(IEditor *editor)
{ {
if (!editor) { if (!editor) {
m_currentEditorWidget = 0; m_currentEditorWidget = 0;
@@ -324,14 +321,12 @@ void EmacsKeysPlugin::insertLineAndIndent()
m_currentState->endOwnAction(KeysActionOther); m_currentState->endOwnAction(KeysActionOther);
} }
QAction *EmacsKeysPlugin::registerAction(Core::Id id, const char *slot, QAction *EmacsKeysPlugin::registerAction(Id id, void (EmacsKeysPlugin::*callback)(),
const QString &title) const QString &title)
{ {
QAction *result = new QAction(title, this); QAction *result = new QAction(title, this);
Core::ActionManager::registerAction(result, id, ActionManager::registerAction(result, id, Context(Core::Constants::C_GLOBAL), true);
Core::Context(Core::Constants::C_GLOBAL), true); connect(result, &QAction::triggered, this, callback);
connect(result, SIGNAL(triggered(bool)), this, slot);
return result; return result;
} }
@@ -382,3 +377,6 @@ void EmacsKeysPlugin::genericVScroll(int direction)
m_currentEditorWidget->setTextCursor(cursor); m_currentEditorWidget->setTextCursor(cursor);
m_currentState->endOwnAction(KeysActionOther); m_currentState->endOwnAction(KeysActionOther);
} }
} // namespace Internal
} // namespace EmacsKeys

View File

@@ -58,7 +58,7 @@ public:
void extensionsInitialized(); void extensionsInitialized();
ShutdownFlag aboutToShutdown(); ShutdownFlag aboutToShutdown();
private slots: private:
void editorAboutToClose(Core::IEditor *editor); void editorAboutToClose(Core::IEditor *editor);
void currentEditorChanged(Core::IEditor *editor); void currentEditorChanged(Core::IEditor *editor);
@@ -87,9 +87,8 @@ private slots:
void scrollHalfDown(); // C-v void scrollHalfDown(); // C-v
void scrollHalfUp(); // M-v void scrollHalfUp(); // M-v
private: QAction *registerAction(Core::Id id, void (EmacsKeysPlugin::*callback)(),
QAction *registerAction(Core::Id id, const char *slot, const QString &title);
const QString &title);
void genericGoto(QTextCursor::MoveOperation op, bool abortAssist = true); void genericGoto(QTextCursor::MoveOperation op, bool abortAssist = true);
void genericVScroll(int direction); void genericVScroll(int direction);

View File

@@ -27,7 +27,8 @@
#include <QTextCursor> #include <QTextCursor>
#include <QPlainTextEdit> #include <QPlainTextEdit>
using namespace EmacsKeys::Internal; namespace EmacsKeys {
namespace Internal {
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
// EmacsKeysState // EmacsKeysState
@@ -39,12 +40,12 @@ EmacsKeysState::EmacsKeysState(QPlainTextEdit *edit):
m_lastAction(KeysAction3rdParty), m_lastAction(KeysAction3rdParty),
m_editorWidget(edit) m_editorWidget(edit)
{ {
connect(edit, SIGNAL(cursorPositionChanged()), connect(edit, &QPlainTextEdit::cursorPositionChanged,
this, SLOT(cursorPositionChanged())); this, &EmacsKeysState::cursorPositionChanged);
connect(edit, SIGNAL(textChanged()), connect(edit, &QPlainTextEdit::textChanged,
this, SLOT(textChanged())); this, &EmacsKeysState::textChanged);
connect(edit, SIGNAL(selectionChanged()), connect(edit, &QPlainTextEdit::selectionChanged,
this, SLOT(selectionChanged())); this, &EmacsKeysState::selectionChanged);
} }
EmacsKeysState::~EmacsKeysState() {} EmacsKeysState::~EmacsKeysState() {}
@@ -79,3 +80,6 @@ void EmacsKeysState::selectionChanged()
if (!m_ignore3rdParty) if (!m_ignore3rdParty)
setLastAction(KeysAction3rdParty); setLastAction(KeysAction3rdParty);
} }
} // namespace Internal
} // namespace EmacsKeys

View File

@@ -40,8 +40,6 @@ enum EmacsKeysAction {
class EmacsKeysState : public QObject class EmacsKeysState : public QObject
{ {
Q_OBJECT
public: public:
EmacsKeysState(QPlainTextEdit *edit); EmacsKeysState(QPlainTextEdit *edit);
~EmacsKeysState(); ~EmacsKeysState();
@@ -56,12 +54,11 @@ public:
int mark() const { return m_mark; } int mark() const { return m_mark; }
void setMark(int mark) { m_mark = mark; } void setMark(int mark) { m_mark = mark; }
private slots: private:
void cursorPositionChanged(); void cursorPositionChanged();
void textChanged(); void textChanged();
void selectionChanged(); void selectionChanged();
private:
bool m_ignore3rdParty; bool m_ignore3rdParty;
int m_mark; int m_mark;
EmacsKeysAction m_lastAction; EmacsKeysAction m_lastAction;