Skip to content

Commit

Permalink
refactor: Make tableCellClicked source-static
Browse files Browse the repository at this point in the history
  • Loading branch information
pajlada committed Nov 4, 2023
1 parent 7e2e9ad commit 2ab7d62
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 28 deletions.
53 changes: 29 additions & 24 deletions src/widgets/settingspages/KeyboardSettingsPage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,33 @@
#include <QMessageBox>
#include <QTableView>

namespace {

using namespace chatterino;

void tableCellClicked(const QModelIndex &clicked, EditableModelView *view,
HotkeyModel *model)
{
auto hotkey = getApp()->hotkeys->getHotkeyByName(
clicked.siblingAtColumn(0).data(Qt::EditRole).toString());
if (!hotkey)
{
return; // clicked on header or invalid hotkey
}
EditHotkeyDialog dialog(hotkey);
bool wasAccepted = dialog.exec() == 1;

if (wasAccepted)
{
auto newHotkey = dialog.data();
auto vectorIndex =
getApp()->hotkeys->replaceHotkey(hotkey->name(), newHotkey);
getApp()->hotkeys->save();
}
}

} // namespace

namespace chatterino {

KeyboardSettingsPage::KeyboardSettingsPage()
Expand Down Expand Up @@ -48,8 +75,8 @@ KeyboardSettingsPage::KeyboardSettingsPage()
});

QObject::connect(view->getTableView(), &QTableView::doubleClicked,
[this, view, model](const QModelIndex &clicked) {
this->tableCellClicked(clicked, view, model);
[view, model](const QModelIndex &clicked) {
tableCellClicked(clicked, view, model);
});

auto *resetEverything = new QPushButton("Reset to defaults");
Expand All @@ -67,26 +94,4 @@ KeyboardSettingsPage::KeyboardSettingsPage()
view->addCustomButton(resetEverything);
}

void KeyboardSettingsPage::tableCellClicked(const QModelIndex &clicked,
EditableModelView *view,
HotkeyModel *model)
{
auto hotkey = getApp()->hotkeys->getHotkeyByName(
clicked.siblingAtColumn(0).data(Qt::EditRole).toString());
if (!hotkey)
{
return; // clicked on header or invalid hotkey
}
EditHotkeyDialog dialog(hotkey);
bool wasAccepted = dialog.exec() == 1;

if (wasAccepted)
{
auto newHotkey = dialog.data();
auto vectorIndex =
getApp()->hotkeys->replaceHotkey(hotkey->name(), newHotkey);
getApp()->hotkeys->save();
}
}

} // namespace chatterino
4 changes: 0 additions & 4 deletions src/widgets/settingspages/KeyboardSettingsPage.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,6 @@ class KeyboardSettingsPage : public SettingsPage
{
public:
KeyboardSettingsPage();

private:
void tableCellClicked(const QModelIndex &clicked, EditableModelView *view,
HotkeyModel *model);
};

} // namespace chatterino

0 comments on commit 2ab7d62

Please sign in to comment.