Skip to content

Commit

Permalink
fix: [shortcut] Fix shortcut key import issue
Browse files Browse the repository at this point in the history
When the imported shortcut key has a format problem, the shortcut key is displayed incorrectly

Log: fix bug
Bug: https://pms.uniontech.com/bug-view-277815.html
  • Loading branch information
Kakueeen authored and deepin-mozart committed Oct 14, 2024
1 parent 41effa0 commit f758155
Showing 1 changed file with 20 additions and 10 deletions.
30 changes: 20 additions & 10 deletions src/plugins/option/optioncore/mainframe/shortcutsettingwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -230,10 +230,17 @@ void ShortcutSettingWidgetPrivate::updateShortcut(QTreeWidgetItem *item, const Q
if (!scItem)
return;

setModified(item, scItem->cmd->defaultKeySequences() != keyList);
scItem->shortcutKeys = keyList;
// remove empty QKeySequence
QList<QKeySequence> tmpKeyList = keyList;
auto iter = std::remove_if(tmpKeyList.begin(), tmpKeyList.end(), [](const QKeySequence &key) {
return key.isEmpty();
});
tmpKeyList.erase(iter, tmpKeyList.end());

setModified(item, scItem->cmd->defaultKeySequences() != tmpKeyList);
scItem->shortcutKeys = tmpKeyList;
commandWidget->removeItemWidget(item, 2);
if (keyList.isEmpty()) {
if (tmpKeyList.isEmpty()) {
item->setText(2, "");
return;
}
Expand Down Expand Up @@ -385,14 +392,17 @@ void ShortcutSettingWidgetPrivate::importAction()
const QVariant v = settings.value(key);
if (QMetaType::Type(v.type()) == QMetaType::QStringList) {
auto list = v.toStringList();
QList<QKeySequence> keySequenceList;
std::transform(list.begin(), list.end(), std::back_inserter(keySequenceList),
[](const QString &s) {
return QKeySequence::fromString(s);
});
mapping.insert(key, keySequenceList);
for (const auto &str : list) {
auto shortcut = QKeySequence::fromString(str);
if (!shortcut.isEmpty() && shortcut.toString().isEmpty())
continue;
mapping[key] << shortcut;
}
} else {
mapping.insert(key, { QKeySequence::fromString(v.toString()) });
auto shortcut = QKeySequence::fromString(v.toString());
if (!shortcut.isEmpty() && shortcut.toString().isEmpty())
continue;
mapping[key] << shortcut;
}
}
settings.endGroup();
Expand Down

0 comments on commit f758155

Please sign in to comment.