Skip to content

Commit 2c29cb1

Browse files
authored
Merge pull request #974 from tweksteen/b_747
Add lcMouseShortcuts::Clear()
2 parents e9b0f93 + 9faa187 commit 2c29cb1

File tree

2 files changed

+22
-8
lines changed

2 files changed

+22
-8
lines changed

common/lc_shortcuts.cpp

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -128,9 +128,20 @@ bool lcKeyboardShortcuts::Load(QTextStream& Stream)
128128
return true;
129129
}
130130

131+
void lcMouseShortcuts::Clear()
132+
{
133+
for (int ShortcutIndex = 0; ShortcutIndex < static_cast<int>(lcTool::Count); ShortcutIndex++)
134+
{
135+
mShortcuts[ShortcutIndex].Modifiers1 = Qt::NoModifier;
136+
mShortcuts[ShortcutIndex].Button1 = Qt::NoButton;
137+
mShortcuts[ShortcutIndex].Modifiers2 = Qt::NoModifier;
138+
mShortcuts[ShortcutIndex].Button2 = Qt::NoButton;
139+
}
140+
}
141+
131142
void lcMouseShortcuts::Reset()
132143
{
133-
memset(mShortcuts, 0, sizeof(mShortcuts));
144+
Clear();
134145

135146
lcToolShortcut& RotateViewShortcut = mShortcuts[static_cast<int>(lcTool::RotateView)];
136147
RotateViewShortcut.Modifiers1 = Qt::AltModifier;
@@ -174,25 +185,25 @@ bool lcMouseShortcuts::Save(QStringList& Shortcuts)
174185
{
175186
Shortcuts.clear();
176187

177-
for (int ToolIdx = 0; ToolIdx < static_cast<int>(lcTool::Count); ToolIdx++)
188+
for (int ShortcutIndex = 0; ShortcutIndex < static_cast<int>(lcTool::Count); ShortcutIndex++)
178189
{
179190
int ButtonIndex1 = 0;
180-
for (int Button1 = mShortcuts[ToolIdx].Button1; Button1; Button1 >>= 1)
191+
for (int Button1 = mShortcuts[ShortcutIndex].Button1; Button1; Button1 >>= 1)
181192
ButtonIndex1++;
182193

183194
if (!ButtonIndex1)
184195
continue;
185196

186-
QString Shortcut = QKeySequence(mShortcuts[ToolIdx].Modifiers1 | (Qt::Key_0 + ButtonIndex1)).toString(QKeySequence::PortableText);
197+
QString Shortcut = QKeySequence(mShortcuts[ShortcutIndex].Modifiers1 | (Qt::Key_0 + ButtonIndex1)).toString(QKeySequence::PortableText);
187198

188199
int ButtonIndex2 = 0;
189-
for (int Button2 = mShortcuts[ToolIdx].Button2; Button2; Button2 >>= 1)
200+
for (int Button2 = mShortcuts[ShortcutIndex].Button2; Button2; Button2 >>= 1)
190201
ButtonIndex2++;
191202

192203
if (ButtonIndex2)
193-
Shortcut += ',' + QKeySequence(mShortcuts[ToolIdx].Modifiers2 | (Qt::Key_0 + ButtonIndex2)).toString(QKeySequence::PortableText);
204+
Shortcut += ',' + QKeySequence(mShortcuts[ShortcutIndex].Modifiers2 | (Qt::Key_0 + ButtonIndex2)).toString(QKeySequence::PortableText);
194205

195-
Shortcuts << QString::fromLatin1(gToolNames[ToolIdx]) + QLatin1String("=") + Shortcut;
206+
Shortcuts << QString::fromLatin1(gToolNames[ShortcutIndex]) + QLatin1String("=") + Shortcut;
196207
}
197208

198209
return true;
@@ -216,7 +227,7 @@ bool lcMouseShortcuts::Load(const QString& FileName)
216227

217228
bool lcMouseShortcuts::Load(const QStringList& FullShortcuts)
218229
{
219-
memset(mShortcuts, 0, sizeof(mShortcuts));
230+
Clear();
220231

221232
for (const QString& FullShortcut : FullShortcuts)
222233
{

common/lc_shortcuts.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@ class lcMouseShortcuts
4040
};
4141

4242
lcToolShortcut mShortcuts[static_cast<int>(lcTool::Count)];
43+
44+
private:
45+
void Clear();
4346
};
4447

4548
extern lcMouseShortcuts gMouseShortcuts;

0 commit comments

Comments
 (0)