mirror of
https://github.com/kiwix/kiwix-desktop.git
synced 2025-09-24 04:32:15 -04:00
Keep selected values when changing catalog
If a filter which is available in remote catalog but not in local catalog (or vice versa) is selected, then we keep that filter applied even after the catalog is switched.
This commit is contained in:
parent
cadac0a1e9
commit
a50f1e73be
@ -163,7 +163,7 @@ void KiwixChoiceBox::keyPressEvent(QKeyEvent *event)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool KiwixChoiceBox::addSelection(QListWidgetItem *item)
|
bool KiwixChoiceBox::addSelection(QListWidgetItem *item, bool updateRequired)
|
||||||
{
|
{
|
||||||
auto key = item->text();
|
auto key = item->text();
|
||||||
auto value = item->data(Qt::UserRole).toString();
|
auto value = item->data(Qt::UserRole).toString();
|
||||||
@ -182,8 +182,10 @@ bool KiwixChoiceBox::addSelection(QListWidgetItem *item)
|
|||||||
item->setSelected(true);
|
item->setSelected(true);
|
||||||
|
|
||||||
searcher->setFixedWidth(20);
|
searcher->setFixedWidth(20);
|
||||||
|
if (updateRequired) {
|
||||||
searcher->setFocus();
|
searcher->setFocus();
|
||||||
emit(choiceUpdated(getCurrentSelected()));
|
emit(choiceUpdated(getCurrentSelected()));
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -238,6 +240,14 @@ void KiwixChoiceBox::setSelections(QStringList selections, QStringList defaultSe
|
|||||||
|
|
||||||
void KiwixChoiceBox::setSelections(SelectionList selections, QStringList defaultSelection)
|
void KiwixChoiceBox::setSelections(SelectionList selections, QStringList defaultSelection)
|
||||||
{
|
{
|
||||||
|
auto prevSelections = choiceSelector->selectedItems();
|
||||||
|
for (auto prev : prevSelections) {
|
||||||
|
QPair<QString, QString> prevPair = {prev->data(Qt::UserRole).toString(), prev->text()};
|
||||||
|
if (!selections.contains(prevPair)) {
|
||||||
|
selections.append(prevPair);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
clearSelections();
|
||||||
choiceSelector->clear();
|
choiceSelector->clear();
|
||||||
for (const auto &selection: selections)
|
for (const auto &selection: selections)
|
||||||
{
|
{
|
||||||
@ -245,7 +255,7 @@ void KiwixChoiceBox::setSelections(SelectionList selections, QStringList default
|
|||||||
item->setData(Qt::UserRole, selection.first);
|
item->setData(Qt::UserRole, selection.first);
|
||||||
choiceSelector->addItem(item);
|
choiceSelector->addItem(item);
|
||||||
if (defaultSelection.contains(selection.first)) {
|
if (defaultSelection.contains(selection.first)) {
|
||||||
addSelection(item);
|
addSelection(item, false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (choiceSelector->selectedItems().isEmpty())
|
if (choiceSelector->selectedItems().isEmpty())
|
||||||
|
@ -52,7 +52,7 @@ private:
|
|||||||
QStringList getCurrentSelected();
|
QStringList getCurrentSelected();
|
||||||
bool removeSelection(QListWidgetItem *item);
|
bool removeSelection(QListWidgetItem *item);
|
||||||
void clearSelections();
|
void clearSelections();
|
||||||
bool addSelection(QListWidgetItem *item);
|
bool addSelection(QListWidgetItem *item, bool updateRequired = true);
|
||||||
void showOptions();
|
void showOptions();
|
||||||
void hideOptions();
|
void hideOptions();
|
||||||
void showPlaceholder();
|
void showPlaceholder();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user