mirror of
https://github.com/yuzu-emu/yuzu.git
synced 2024-07-04 23:31:19 +01:00
configure_hotkeys: Move conflict detection logic to IsUsedKey()
We don't need to extract the entire set of hotkeys into a list and then iterate through it. We can traverse the list and early-exit if we're able to.
This commit is contained in:
parent
c03fb00ac1
commit
ef3c0f54d0
2 changed files with 15 additions and 14 deletions
|
@ -31,18 +31,6 @@ ConfigureHotkeys::ConfigureHotkeys(QWidget* parent)
|
||||||
|
|
||||||
ConfigureHotkeys::~ConfigureHotkeys() = default;
|
ConfigureHotkeys::~ConfigureHotkeys() = default;
|
||||||
|
|
||||||
QList<QKeySequence> ConfigureHotkeys::GetUsedKeyList() const {
|
|
||||||
QList<QKeySequence> list;
|
|
||||||
for (int r = 0; r < model->rowCount(); r++) {
|
|
||||||
const QStandardItem* parent = model->item(r, 0);
|
|
||||||
for (int r2 = 0; r2 < parent->rowCount(); r2++) {
|
|
||||||
const QStandardItem* keyseq = parent->child(r2, 1);
|
|
||||||
list << QKeySequence::fromString(keyseq->text(), QKeySequence::NativeText);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return list;
|
|
||||||
}
|
|
||||||
|
|
||||||
void ConfigureHotkeys::Populate(const HotkeyRegistry& registry) {
|
void ConfigureHotkeys::Populate(const HotkeyRegistry& registry) {
|
||||||
for (const auto& group : registry.hotkey_groups) {
|
for (const auto& group : registry.hotkey_groups) {
|
||||||
auto* parent_item = new QStandardItem(group.first);
|
auto* parent_item = new QStandardItem(group.first);
|
||||||
|
@ -87,7 +75,21 @@ void ConfigureHotkeys::Configure(QModelIndex index) {
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ConfigureHotkeys::IsUsedKey(QKeySequence key_sequence) const {
|
bool ConfigureHotkeys::IsUsedKey(QKeySequence key_sequence) const {
|
||||||
return GetUsedKeyList().contains(key_sequence);
|
for (int r = 0; r < model->rowCount(); r++) {
|
||||||
|
const QStandardItem* const parent = model->item(r, 0);
|
||||||
|
|
||||||
|
for (int r2 = 0; r2 < parent->rowCount(); r2++) {
|
||||||
|
const QStandardItem* const key_seq_item = parent->child(r2, 1);
|
||||||
|
const auto key_seq_str = key_seq_item->text();
|
||||||
|
const auto key_seq = QKeySequence::fromString(key_seq_str, QKeySequence::NativeText);
|
||||||
|
|
||||||
|
if (key_sequence == key_seq) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ConfigureHotkeys::applyConfiguration(HotkeyRegistry& registry) {
|
void ConfigureHotkeys::applyConfiguration(HotkeyRegistry& registry) {
|
||||||
|
|
|
@ -34,7 +34,6 @@ public:
|
||||||
private:
|
private:
|
||||||
void Configure(QModelIndex index);
|
void Configure(QModelIndex index);
|
||||||
bool IsUsedKey(QKeySequence key_sequence) const;
|
bool IsUsedKey(QKeySequence key_sequence) const;
|
||||||
QList<QKeySequence> GetUsedKeyList() const;
|
|
||||||
|
|
||||||
std::unique_ptr<Ui::ConfigureHotkeys> ui;
|
std::unique_ptr<Ui::ConfigureHotkeys> ui;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue