Skip to content

Commit 23968f1

Browse files
kdmamrexodia
authored andcommitted
Iterating QMap with ranged for. Inlined renderShortcuts. Save button now has default focus
Using ranged for instead of iterators. Inlined renderShortcuts since it was used only once Adjusted layout of shortcuts Ui
1 parent 59ddfa6 commit 23968f1

File tree

3 files changed

+50
-71
lines changed

3 files changed

+50
-71
lines changed

src/gui/Src/Gui/ShortcutsDialog.cpp

Lines changed: 19 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -34,46 +34,37 @@ ShortcutsDialog::ShortcutsDialog(QWidget* parent) : QDialog(parent), ui(new Ui::
3434
connect(ui->tblShortcuts, SIGNAL(itemSelectionChanged()), this, SLOT(syncTextfield()));
3535
connect(ui->shortcutEdit, SIGNAL(askForSave()), this, SLOT(updateShortcut()));
3636
connect(this, SIGNAL(rejected()), this, SLOT(rejectedSlot()));
37-
connect(ui->bntClearFilter, SIGNAL(released()), this, SLOT(on_btnClearFilter()));
3837
connect(ui->filterEdit, SIGNAL(textChanged(const QString &)), this, SLOT(on_FilterTextChanged(const QString &)));
3938
}
4039

4140
void ShortcutsDialog::showShortcutsFiltered(const QString & actionName)
4241
{
4342
QMap<QString, Configuration::Shortcut> shorcutsToShow;
4443
filterShortcutsByName(actionName, shorcutsToShow);
45-
renderShortcuts(shorcutsToShow);
46-
}
47-
48-
void ShortcutsDialog::filterShortcutsByName(const QString & nameFilter, QMap<QString, Configuration::Shortcut> & mapToFill)
49-
{
50-
for(QMap<QString, Configuration::Shortcut>::iterator i = Config()->Shortcuts.begin();
51-
i != Config()->Shortcuts.end();
52-
++i)
53-
{
54-
if(i.value().Name.contains(nameFilter, Qt::CaseInsensitive) || nameFilter == QString())
55-
{
56-
mapToFill.insert(i.value().Name, i.value());
57-
}
58-
}
59-
}
60-
61-
void ShortcutsDialog::renderShortcuts(QMap<QString, Configuration::Shortcut> & shortcuts)
62-
{
6344
ui->tblShortcuts->clearContents();
64-
ui->tblShortcuts->setRowCount(shortcuts.count());
45+
ui->tblShortcuts->setRowCount(shorcutsToShow.count());
6546
currentRow = 0;
6647

6748
int row = 0;
68-
for(QMap<QString, Configuration::Shortcut>::const_iterator it = shortcuts.begin(); it != shortcuts.end();
69-
++it, row++)
49+
for(auto shortcut : shorcutsToShow)
7050
{
71-
QTableWidgetItem* shortcutName = new QTableWidgetItem(it.value().Name);
72-
QTableWidgetItem* shortcutKey = new QTableWidgetItem(it.value().Hotkey.toString(QKeySequence::NativeText));
51+
QTableWidgetItem* shortcutName = new QTableWidgetItem(shortcut.Name);
52+
QTableWidgetItem* shortcutKey = new QTableWidgetItem(shortcut.Hotkey.toString(QKeySequence::NativeText));
7353
ui->tblShortcuts->setItem(row, 0, shortcutName);
7454
ui->tblShortcuts->setItem(row, 1, shortcutKey);
55+
row++;
56+
}
57+
ui->tblShortcuts->setSortingEnabled(true);}
58+
59+
void ShortcutsDialog::filterShortcutsByName(const QString & nameFilter, QMap<QString, Configuration::Shortcut> & mapToFill)
60+
{
61+
for(auto shortcut : Config()->Shortcuts)
62+
{
63+
if(shortcut.Name.contains(nameFilter, Qt::CaseInsensitive) || nameFilter == QString())
64+
{
65+
mapToFill.insert(shortcut.Name, shortcut);
66+
}
7567
}
76-
ui->tblShortcuts->setSortingEnabled(true);
7768
}
7869

7970
void ShortcutsDialog::updateShortcut()
@@ -163,11 +154,11 @@ void ShortcutsDialog::syncTextfield()
163154
if(indexes.count() < 1)
164155
return;
165156
currentRow = indexes.at(0).row();
166-
for(QMap<QString, Configuration::Shortcut>::iterator i = Config()->Shortcuts.begin(); i != Config()->Shortcuts.end(); ++i)
157+
for(auto shortcut : Config()->Shortcuts)
167158
{
168-
if(i.value().Name == ui->tblShortcuts->item(currentRow, 0)->text())
159+
if(shortcut.Name == ui->tblShortcuts->item(currentRow, 0)->text())
169160
{
170-
currentShortcut = i.value();
161+
currentShortcut = shortcut;
171162
break;
172163
}
173164
}
@@ -192,12 +183,6 @@ void ShortcutsDialog::rejectedSlot()
192183
Config()->readShortcuts();
193184
}
194185

195-
void ShortcutsDialog::on_btnClearFilter()
196-
{
197-
ui->filterEdit->clear();
198-
showShortcutsFiltered(QString());
199-
}
200-
201186
void ShortcutsDialog::on_FilterTextChanged(const QString & actionName)
202187
{
203188
showShortcutsFiltered(actionName);

src/gui/Src/Gui/ShortcutsDialog.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,12 @@ private slots:
2828
void on_btnSave_clicked();
2929
void on_btnClearShortcut_clicked();
3030
void rejectedSlot();
31-
void on_btnClearFilter();
3231
void on_FilterTextChanged(const QString & actionName);
32+
3333
private:
3434
Ui::ShortcutsDialog* ui;
3535
QMap<QString, Configuration::Shortcut> ShortcutsBackup;
3636
void filterShortcutsByName(const QString & nameFilter, QMap<QString, Configuration::Shortcut> & mapToFill);
37-
void renderShortcuts(QMap<QString, Configuration::Shortcut> & shortcuts);
3837
void showShortcutsFiltered(const QString & actionName);
3938
};
4039

src/gui/Src/Gui/ShortcutsDialog.ui

Lines changed: 30 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -19,45 +19,37 @@
1919
</property>
2020
<layout class="QVBoxLayout" name="verticalLayout">
2121
<item>
22-
<widget class="QTableWidget" name="tblShortcuts"/>
23-
</item>
24-
<item>
25-
<widget class="QGroupBox" name="filterBox">
26-
<property name="title">
27-
<string>Filter</string>
22+
<widget class="QLineEdit" name="filterEdit">
23+
<property name="placeholderText">
24+
<string>Instruction name filter</string>
2825
</property>
29-
<layout class="QHBoxLayout" name="horizontalLayout_3">
30-
<item>
31-
<widget class="QLineEdit" name="filterEdit"/>
32-
</item>
33-
<item>
34-
<widget class="QPushButton" name="bntClearFilter">
35-
<property name="text">
36-
<string>Clear</string>
37-
</property>
38-
</widget>
39-
</item>
40-
</layout>
4126
</widget>
4227
</item>
4328
<item>
44-
<widget class="QGroupBox" name="groupBox">
45-
<property name="title">
46-
<string>Shortcut</string>
47-
</property>
48-
<layout class="QHBoxLayout" name="horizontalLayout">
49-
<item>
50-
<widget class="ShortcutEdit" name="shortcutEdit"/>
51-
</item>
52-
<item>
53-
<widget class="QPushButton" name="btnClearShortcut">
54-
<property name="text">
55-
<string>Clear</string>
56-
</property>
57-
</widget>
58-
</item>
59-
</layout>
60-
</widget>
29+
<widget class="QTableWidget" name="tblShortcuts"/>
30+
</item>
31+
<item>
32+
<layout class="QHBoxLayout" name="horizontalLayout_4">
33+
<item>
34+
<widget class="QGroupBox" name="groupBox">
35+
<property name="title">
36+
<string>Shortcut</string>
37+
</property>
38+
<layout class="QHBoxLayout" name="horizontalLayout">
39+
<item>
40+
<widget class="ShortcutEdit" name="shortcutEdit"/>
41+
</item>
42+
<item>
43+
<widget class="QPushButton" name="btnClearShortcut">
44+
<property name="text">
45+
<string>Clear</string>
46+
</property>
47+
</widget>
48+
</item>
49+
</layout>
50+
</widget>
51+
</item>
52+
</layout>
6153
</item>
6254
<item>
6355
<layout class="QHBoxLayout" name="horizontalLayout_2">
@@ -79,6 +71,9 @@
7971
<property name="text">
8072
<string>Save</string>
8173
</property>
74+
<property name="default">
75+
<bool>true</bool>
76+
</property>
8277
</widget>
8378
</item>
8479
<item>

0 commit comments

Comments
 (0)