mirror of
https://github.com/subsurface/subsurface.git
synced 2025-01-31 20:23:25 +00:00
printoptions.cpp: correctly remember the last selected template
To find the last selected template index in the combo box, comparing against `printOptions->p_template` would work fine, except the `on_printTemplate_currentIndexChanged()` slot updates `printOptions->p_template` each time QComboBox::addItem() is called. This makes the `for` loop to add new combo box items and find the index of the last selected template not possible. To work around the issue, a local QString variable `storedTemplate` is introduced and it does not change during the `for` loop. Fixes #595 Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com>
This commit is contained in:
parent
305a35a48c
commit
e9673938fb
1 changed files with 4 additions and 2 deletions
|
@ -53,13 +53,15 @@ void PrintOptions::setupTemplates()
|
|||
QStringList currList = printOptions->type == print_options::DIVELIST ?
|
||||
grantlee_templates : grantlee_statistics_templates;
|
||||
|
||||
// temp. store the template from options, as addItem() updates it via:
|
||||
// on_printTemplate_currentIndexChanged()
|
||||
QString storedTemplate = printOptions->p_template;
|
||||
qSort(currList);
|
||||
int current_index = 0;
|
||||
ui.printTemplate->clear();
|
||||
Q_FOREACH(const QString& theme, currList) {
|
||||
if (theme == printOptions->p_template){
|
||||
if (theme == storedTemplate) // find the stored template in the list
|
||||
current_index = currList.indexOf(theme);
|
||||
}
|
||||
ui.printTemplate->addItem(theme.split('.')[0], theme);
|
||||
}
|
||||
ui.printTemplate->setCurrentIndex(current_index);
|
||||
|
|
Loading…
Add table
Reference in a new issue