FakeVimPlugin: Introduce member initialization.

Change-Id: I0e09933ededd48133662a65da701c228e6c08419
Reviewed-by: hjk <hjk@theqtcompany.com>
This commit is contained in:
Jarek Kobus
2015-06-18 13:32:25 +02:00
parent b3e0c33682
commit 716f43f357
3 changed files with 72 additions and 124 deletions

View File

@@ -262,7 +262,7 @@ enum EventResult
struct CursorPosition struct CursorPosition
{ {
CursorPosition() : line(-1), column(-1) {} CursorPosition() {}
CursorPosition(int block, int column) : line(block), column(column) {} CursorPosition(int block, int column) : line(block), column(column) {}
explicit CursorPosition(const QTextCursor &tc) explicit CursorPosition(const QTextCursor &tc)
: line(tc.block().blockNumber()), column(tc.positionInBlock()) {} : line(tc.block().blockNumber()), column(tc.positionInBlock()) {}
@@ -279,8 +279,8 @@ struct CursorPosition
{ return line == other.line && column == other.column; } { return line == other.line && column == other.column; }
bool operator!=(const CursorPosition &other) const { return !operator==(other); } bool operator!=(const CursorPosition &other) const { return !operator==(other); }
int line; // Line in document (from 0, folded lines included). int line = -1; // Line in document (from 0, folded lines included).
int column; // Position on line. int column = -1; // Position on line.
}; };
QDebug operator<<(QDebug ts, const CursorPosition &pos) QDebug operator<<(QDebug ts, const CursorPosition &pos)
@@ -335,8 +335,7 @@ typedef QHashIterator<QChar, Mark> MarksIterator;
struct State struct State
{ {
State() : revision(-1), position(), marks(), lastVisualMode(NoVisualMode), State() {}
lastVisualModeInverted(false) {}
State(int revision, const CursorPosition &position, const Marks &marks, State(int revision, const CursorPosition &position, const Marks &marks,
VisualMode lastVisualMode, bool lastVisualModeInverted) : revision(revision), VisualMode lastVisualMode, bool lastVisualModeInverted) : revision(revision),
position(position), marks(marks), lastVisualMode(lastVisualMode), position(position), marks(marks), lastVisualMode(lastVisualMode),
@@ -344,11 +343,11 @@ struct State
bool isValid() const { return position.isValid(); } bool isValid() const { return position.isValid(); }
int revision; int revision = -1;
CursorPosition position; CursorPosition position;
Marks marks; Marks marks;
VisualMode lastVisualMode; VisualMode lastVisualMode = NoVisualMode;
bool lastVisualModeInverted; bool lastVisualModeInverted = false;
}; };
struct Column struct Column
@@ -365,11 +364,11 @@ QDebug operator<<(QDebug ts, const Column &col)
struct Register struct Register
{ {
Register() : rangemode(RangeCharMode) {} Register() {}
Register(const QString &c) : contents(c), rangemode(RangeCharMode) {} Register(const QString &c) : contents(c) {}
Register(const QString &c, RangeMode m) : contents(c), rangemode(m) {} Register(const QString &c, RangeMode m) : contents(c), rangemode(m) {}
QString contents; QString contents;
RangeMode rangemode; RangeMode rangemode = RangeCharMode;
}; };
QDebug operator<<(QDebug ts, const Register &reg) QDebug operator<<(QDebug ts, const Register &reg)
@@ -379,15 +378,9 @@ QDebug operator<<(QDebug ts, const Register &reg)
struct SearchData struct SearchData
{ {
SearchData()
{
forward = true;
highlightMatches = true;
}
QString needle; QString needle;
bool forward; bool forward = true;
bool highlightMatches; bool highlightMatches = true;
}; };
// If string begins with given prefix remove it with trailing spaces and return true. // If string begins with given prefix remove it with trailing spaces and return true.
@@ -875,10 +868,6 @@ static bool isOnlyControlModifier(const Qt::KeyboardModifiers &mods)
} }
Range::Range()
: beginPos(-1), endPos(-1), rangemode(RangeCharMode)
{}
Range::Range(int b, int e, RangeMode m) Range::Range(int b, int e, RangeMode m)
: beginPos(qMin(b, e)), endPos(qMax(b, e)), rangemode(m) : beginPos(qMin(b, e)), endPos(qMax(b, e)), rangemode(m)
{} {}
@@ -969,11 +958,9 @@ public:
return m & ~Qt::KeypadModifier; return m & ~Qt::KeypadModifier;
} }
Input() Input() {}
: m_key(0), m_xkey(0), m_modifiers(0) {}
explicit Input(QChar x) explicit Input(QChar x)
: m_key(x.unicode()), m_xkey(x.unicode()), m_modifiers(0), m_text(x) : m_key(x.unicode()), m_xkey(x.unicode()), m_text(x)
{ {
if (x.isUpper()) if (x.isUpper())
m_modifiers = Qt::ShiftModifier; m_modifiers = Qt::ShiftModifier;
@@ -1168,9 +1155,9 @@ public:
<< quoteUnprintable(m_text); << quoteUnprintable(m_text);
} }
private: private:
int m_key; int m_key = 0;
int m_xkey; int m_xkey = 0;
Qt::KeyboardModifiers m_modifiers; Qt::KeyboardModifiers m_modifiers = NoModifier;
QString m_text; QString m_text;
}; };
@@ -1240,7 +1227,7 @@ QDebug operator<<(QDebug ts, const Input &input) { return input.dump(ts); }
class Inputs : public QVector<Input> class Inputs : public QVector<Input>
{ {
public: public:
Inputs() : m_noremap(true), m_silent(false) {} Inputs() {}
explicit Inputs(const QString &str, bool noremap = true, bool silent = false) explicit Inputs(const QString &str, bool noremap = true, bool silent = false)
: m_noremap(noremap), m_silent(silent) : m_noremap(noremap), m_silent(silent)
@@ -1256,8 +1243,8 @@ public:
private: private:
void parseFrom(const QString &str); void parseFrom(const QString &str);
bool m_noremap; bool m_noremap = true;
bool m_silent; bool m_silent = false;
}; };
static Input parseVimKeyName(const QString &keyName) static Input parseVimKeyName(const QString &keyName)
@@ -1327,7 +1314,7 @@ void Inputs::parseFrom(const QString &str)
class History class History
{ {
public: public:
History() : m_items(QString()), m_index(0) {} History() : m_items(QString()) {}
void append(const QString &item); void append(const QString &item);
const QString &move(const QStringRef &prefix, int skip); const QString &move(const QStringRef &prefix, int skip);
const QString &current() const { return m_items[m_index]; } const QString &current() const { return m_items[m_index]; }
@@ -1337,7 +1324,7 @@ public:
private: private:
// Last item is always empty or current search prefix. // Last item is always empty or current search prefix.
QStringList m_items; QStringList m_items;
int m_index; int m_index = 0;
}; };
void History::append(const QString &item) void History::append(const QString &item)
@@ -1372,8 +1359,6 @@ const QString &History::move(const QStringRef &prefix, int skip)
class CommandBuffer class CommandBuffer
{ {
public: public:
CommandBuffer() : m_pos(0), m_anchor(0), m_userPos(0), m_historyAutoSave(true) {}
void setPrompt(const QChar &prompt) { m_prompt = prompt; } void setPrompt(const QChar &prompt) { m_prompt = prompt; }
void setContents(const QString &s) { m_buffer = s; m_anchor = m_pos = s.size(); } void setContents(const QString &s) { m_buffer = s; m_anchor = m_pos = s.size(); }
@@ -1494,10 +1479,10 @@ private:
QString m_buffer; QString m_buffer;
QChar m_prompt; QChar m_prompt;
History m_history; History m_history;
int m_pos; int m_pos = 0;
int m_anchor; int m_anchor = 0;
int m_userPos; // last position of inserted text (for retrieving history items) int m_userPos = 0; // last position of inserted text (for retrieving history items)
bool m_historyAutoSave; // store items to history on clear()? bool m_historyAutoSave = true; // store items to history on clear()?
}; };
// Mappings for a specific mode (trie structure) // Mappings for a specific mode (trie structure)
@@ -1519,8 +1504,6 @@ class MappingsIterator : public QVector<ModeMapping::Iterator>
public: public:
MappingsIterator(Mappings *mappings, char mode = -1, const Inputs &inputs = Inputs()) MappingsIterator(Mappings *mappings, char mode = -1, const Inputs &inputs = Inputs())
: m_parent(mappings) : m_parent(mappings)
, m_lastValid(-1)
, m_mode(0)
{ {
reset(mode); reset(mode);
walk(inputs); walk(inputs);
@@ -1626,20 +1609,19 @@ public:
private: private:
Mappings *m_parent; Mappings *m_parent;
Mappings::Iterator m_modeMapping; Mappings::Iterator m_modeMapping;
int m_lastValid; int m_lastValid = -1;
char m_mode; char m_mode = 0;
Inputs m_currentInputs; Inputs m_currentInputs;
}; };
// state of current mapping // state of current mapping
struct MappingState { struct MappingState {
MappingState() MappingState() {}
: noremap(false), silent(false), editBlock(false) {}
MappingState(bool noremap, bool silent, bool editBlock) MappingState(bool noremap, bool silent, bool editBlock)
: noremap(noremap), silent(silent), editBlock(editBlock) {} : noremap(noremap), silent(silent), editBlock(editBlock) {}
bool noremap; bool noremap = false;
bool silent; bool silent = false;
bool editBlock; bool editBlock = false;
}; };
class FakeVimHandler::Private : public QObject class FakeVimHandler::Private : public QObject
@@ -2163,27 +2145,19 @@ public:
// Data shared among editors with same document. // Data shared among editors with same document.
struct BufferData struct BufferData
{ {
BufferData()
: lastRevision(0)
, editBlockLevel(0)
, breakEditBlock(false)
, lastVisualMode(NoVisualMode)
, lastVisualModeInverted(false)
{}
QStack<State> undo; QStack<State> undo;
QStack<State> redo; QStack<State> redo;
State undoState; State undoState;
int lastRevision; int lastRevision = 0;
int editBlockLevel; // current level of edit blocks int editBlockLevel = 0; // current level of edit blocks
bool breakEditBlock; // if true, joinPreviousEditBlock() starts new edit block bool breakEditBlock = false; // if true, joinPreviousEditBlock() starts new edit block
QStack<CursorPosition> jumpListUndo; QStack<CursorPosition> jumpListUndo;
QStack<CursorPosition> jumpListRedo; QStack<CursorPosition> jumpListRedo;
VisualMode lastVisualMode; VisualMode lastVisualMode = NoVisualMode;
bool lastVisualModeInverted; bool lastVisualModeInverted = false;
Marks marks; Marks marks;
@@ -2215,47 +2189,28 @@ public:
static struct GlobalData static struct GlobalData
{ {
GlobalData() GlobalData()
: passing(false) : mappings()
, mode(CommandMode)
, submode(NoSubMode)
, subsubmode(NoSubSubMode)
, visualMode(NoVisualMode)
, mvcount(0)
, opcount(0)
, movetype(MoveInclusive)
, rangemode(RangeCharMode)
, gflag(false)
, mappings()
, currentMap(&mappings) , currentMap(&mappings)
, mapDepth(0)
, currentMessageLevel(MessageInfo)
, lastSearchForward(false)
, highlightsCleared(false)
, findPending(false)
, returnToMode(CommandMode)
, isRecording(false)
, currentRegister(0)
, lastExecutedRegister(0)
{ {
commandBuffer.setPrompt(QLatin1Char(':')); commandBuffer.setPrompt(QLatin1Char(':'));
} }
// Current state. // Current state.
bool passing; // let the core see the next event bool passing = false; // let the core see the next event
Mode mode; Mode mode = CommandMode;
SubMode submode; SubMode submode = NoSubMode;
SubSubMode subsubmode; SubSubMode subsubmode = NoSubSubMode;
Input subsubdata; Input subsubdata;
VisualMode visualMode; VisualMode visualMode = NoVisualMode;
Input minibufferData; Input minibufferData;
// [count] for current command, 0 if no [count] available // [count] for current command, 0 if no [count] available
int mvcount; int mvcount = 0;
int opcount; int opcount = 0;
MoveType movetype; MoveType movetype = MoveInclusive;
RangeMode rangemode; RangeMode rangemode = RangeCharMode;
bool gflag; // whether current command started with 'g' bool gflag = false; // whether current command started with 'g'
// Extra data for ';'. // Extra data for ';'.
Input semicolonType; // 'f', 'F', 't', 'T' Input semicolonType; // 'f', 'F', 't', 'T'
@@ -2273,7 +2228,7 @@ public:
QList<Input> pendingInput; QList<Input> pendingInput;
MappingsIterator currentMap; MappingsIterator currentMap;
QStack<MappingState> mapStates; QStack<MappingState> mapStates;
int mapDepth; int mapDepth = 0;
// Command line buffers. // Command line buffers.
CommandBuffer commandBuffer; CommandBuffer commandBuffer;
@@ -2281,15 +2236,15 @@ public:
// Current mini buffer message. // Current mini buffer message.
QString currentMessage; QString currentMessage;
MessageLevel currentMessageLevel; MessageLevel currentMessageLevel = MessageInfo;
QString currentCommand; QString currentCommand;
// Search state. // Search state.
QString lastSearch; // last search expression as entered by user QString lastSearch; // last search expression as entered by user
QString lastNeedle; // last search expression translated with vimPatternToQtPattern() QString lastNeedle; // last search expression translated with vimPatternToQtPattern()
bool lastSearchForward; // last search command was '/' or '*' bool lastSearchForward = false; // last search command was '/' or '*'
bool highlightsCleared; // ':nohlsearch' command is active until next search bool highlightsCleared = false; // ':nohlsearch' command is active until next search
bool findPending; // currently searching using external tool (until editor is focused again) bool findPending = false; // currently searching using external tool (until editor is focused again)
// Last substitution command. // Last substitution command.
QString lastSubstituteFlags; QString lastSubstituteFlags;
@@ -2300,13 +2255,13 @@ public:
Marks marks; Marks marks;
// Return to insert/replace mode after single command (<C-O>). // Return to insert/replace mode after single command (<C-O>).
Mode returnToMode; Mode returnToMode = CommandMode;
// Currently recorded macro // Currently recorded macro
bool isRecording; bool isRecording = false;
QString recorded; QString recorded;
int currentRegister; int currentRegister = 0;
int lastExecutedRegister; int lastExecutedRegister = 0;
} g; } g;
}; };

View File

@@ -50,29 +50,29 @@ enum RangeMode
struct Range struct Range
{ {
Range(); Range() {}
Range(int b, int e, RangeMode m = RangeCharMode); Range(int b, int e, RangeMode m = RangeCharMode);
QString toString() const; QString toString() const;
bool isValid() const; bool isValid() const;
int beginPos; int beginPos = -1;
int endPos; int endPos = -1;
RangeMode rangemode; RangeMode rangemode = RangeCharMode;
}; };
struct ExCommand struct ExCommand
{ {
ExCommand() : hasBang(false), count(1) {} ExCommand() {}
ExCommand(const QString &cmd, const QString &args = QString(), ExCommand(const QString &cmd, const QString &args = QString(),
const Range &range = Range()); const Range &range = Range());
bool matches(const QString &min, const QString &full) const; bool matches(const QString &min, const QString &full) const;
QString cmd; QString cmd;
bool hasBang; bool hasBang = false;
QString args; QString args;
Range range; Range range;
int count; int count = 1;
}; };
// message levels sorted by severity // message levels sorted by severity

View File

@@ -124,8 +124,6 @@ public:
MiniBuffer() MiniBuffer()
: m_label(new QLabel(this)) : m_label(new QLabel(this))
, m_edit(new QLineEdit(this)) , m_edit(new QLineEdit(this))
, m_eventFilter(0)
, m_lastMessageLevel(MessageMode)
{ {
connect(m_edit, &QLineEdit::textEdited, this, &MiniBuffer::changed); connect(m_edit, &QLineEdit::textEdited, this, &MiniBuffer::changed);
connect(m_edit, &QLineEdit::cursorPositionChanged, this, &MiniBuffer::changed); connect(m_edit, &QLineEdit::cursorPositionChanged, this, &MiniBuffer::changed);
@@ -225,9 +223,9 @@ private:
QLabel *m_label; QLabel *m_label;
QLineEdit *m_edit; QLineEdit *m_edit;
QObject *m_eventFilter; QObject *m_eventFilter = nullptr;
QTimer m_hideTimer; QTimer m_hideTimer;
int m_lastMessageLevel; int m_lastMessageLevel = MessageMode;
}; };
class RelativeNumbersColumn : public QWidget class RelativeNumbersColumn : public QWidget
@@ -237,8 +235,6 @@ class RelativeNumbersColumn : public QWidget
public: public:
RelativeNumbersColumn(TextEditorWidget *baseTextEditor) RelativeNumbersColumn(TextEditorWidget *baseTextEditor)
: QWidget(baseTextEditor) : QWidget(baseTextEditor)
, m_currentPos(0)
, m_lineSpacing(0)
, m_editor(baseTextEditor) , m_editor(baseTextEditor)
{ {
setAttribute(Qt::WA_TransparentForMouseEvents, true); setAttribute(Qt::WA_TransparentForMouseEvents, true);
@@ -346,8 +342,8 @@ private slots:
} }
private: private:
int m_currentPos; int m_currentPos = 0;
int m_lineSpacing; int m_lineSpacing = 0;
TextEditorWidget *m_editor; TextEditorWidget *m_editor;
QTimer m_timerUpdate; QTimer m_timerUpdate;
}; };
@@ -1101,9 +1097,9 @@ signals:
private: private:
FakeVimPlugin *q; FakeVimPlugin *q;
FakeVimOptionPage *m_fakeVimOptionsPage; FakeVimOptionPage *m_fakeVimOptionsPage = nullptr;
FakeVimExCommandsPage *m_fakeVimExCommandsPage; FakeVimExCommandsPage *m_fakeVimExCommandsPage = nullptr;
FakeVimUserCommandsPage *m_fakeVimUserCommandsPage; FakeVimUserCommandsPage *m_fakeVimUserCommandsPage = nullptr;
QHash<IEditor *, FakeVimHandler *> m_editorToHandler; QHash<IEditor *, FakeVimHandler *> m_editorToHandler;
void triggerAction(Id id); void triggerAction(Id id);
@@ -1157,11 +1153,8 @@ bool FakeVimUserCommandsModel::setData(const QModelIndex &index,
} }
FakeVimPluginPrivate::FakeVimPluginPrivate(FakeVimPlugin *plugin) FakeVimPluginPrivate::FakeVimPluginPrivate(FakeVimPlugin *plugin)
: q(plugin)
{ {
q = plugin;
m_fakeVimOptionsPage = 0;
m_fakeVimExCommandsPage = 0;
m_fakeVimUserCommandsPage = 0;
defaultExCommandMap()[_(CppTools::Constants::SWITCH_HEADER_SOURCE)] = defaultExCommandMap()[_(CppTools::Constants::SWITCH_HEADER_SOURCE)] =
QRegExp(_("^A$")); QRegExp(_("^A$"));
defaultExCommandMap()[_("Coreplugin.OutputPane.previtem")] = defaultExCommandMap()[_("Coreplugin.OutputPane.previtem")] =