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:
Nikhil Tanwar 2023-09-12 22:46:34 +05:30 committed by Matthieu Gautier
parent cadac0a1e9
commit a50f1e73be
2 changed files with 15 additions and 5 deletions

View File

@ -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 value = item->data(Qt::UserRole).toString();
@ -182,8 +182,10 @@ bool KiwixChoiceBox::addSelection(QListWidgetItem *item)
item->setSelected(true);
searcher->setFixedWidth(20);
searcher->setFocus();
emit(choiceUpdated(getCurrentSelected()));
if (updateRequired) {
searcher->setFocus();
emit(choiceUpdated(getCurrentSelected()));
}
return true;
}
@ -238,6 +240,14 @@ void KiwixChoiceBox::setSelections(QStringList selections, QStringList defaultSe
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();
for (const auto &selection: selections)
{
@ -245,7 +255,7 @@ void KiwixChoiceBox::setSelections(SelectionList selections, QStringList default
item->setData(Qt::UserRole, selection.first);
choiceSelector->addItem(item);
if (defaultSelection.contains(selection.first)) {
addSelection(item);
addSelection(item, false);
}
}
if (choiceSelector->selectedItems().isEmpty())

View File

@ -52,7 +52,7 @@ private:
QStringList getCurrentSelected();
bool removeSelection(QListWidgetItem *item);
void clearSelections();
bool addSelection(QListWidgetItem *item);
bool addSelection(QListWidgetItem *item, bool updateRequired = true);
void showOptions();
void hideOptions();
void showPlaceholder();