From 1210d4b575728f2acacb2813a69cf0ee4920a9be Mon Sep 17 00:00:00 2001 From: Tomaz Canabrava Date: Fri, 8 Jan 2016 15:21:49 -0200 Subject: Simplify code on the printingDialog instead of duplicate the code that only chaged the QList that it would access, create a temporary list and use it for dealing with the code. Signed-off-by: Tomaz Canabrava Signed-off-by: Dirk Hohndel --- desktop-widgets/printoptions.cpp | 42 +++++++++++----------------------------- 1 file changed, 11 insertions(+), 31 deletions(-) (limited to 'desktop-widgets/printoptions.cpp') diff --git a/desktop-widgets/printoptions.cpp b/desktop-widgets/printoptions.cpp index 769c89ff4..29aba313d 100644 --- a/desktop-widgets/printoptions.cpp +++ b/desktop-widgets/printoptions.cpp @@ -51,39 +51,19 @@ void PrintOptions::setup() void PrintOptions::setupTemplates() { - if (printOptions->type == print_options::DIVELIST) { - // insert dive list templates in the UI and select the current template - qSort(grantlee_templates); - int current_index = 0, index = 0; - for (QList::iterator i = grantlee_templates.begin(); i != grantlee_templates.end(); ++i) { - if ((*i).compare(printOptions->p_template) == 0) { - current_index = index; - break; - } - index++; + QStringList currList = printOptions->type == print_options::DIVELIST ? + grantlee_templates : grantlee_statistics_templates; + + qSort(currList); + int current_index = 0; + ui.printTemplate->clear(); + Q_FOREACH(const QString& theme, currList) { + if (theme == printOptions->p_template){ + current_index = currList.indexOf(theme); } - ui.printTemplate->clear(); - for (QList::iterator i = grantlee_templates.begin(); i != grantlee_templates.end(); ++i) { - ui.printTemplate->addItem((*i).split('.')[0], QVariant::fromValue(*i)); - } - ui.printTemplate->setCurrentIndex(current_index); - } else if (printOptions->type == print_options::STATISTICS) { - // insert statistics templates in the UI and select the current template - qSort(grantlee_statistics_templates); - int current_index = 0, index = 0; - for (QList::iterator i = grantlee_statistics_templates.begin(); i != grantlee_statistics_templates.end(); ++i) { - if ((*i).compare(printOptions->p_template) == 0) { - current_index = index; - break; - } - index++; - } - ui.printTemplate->clear(); - for (QList::iterator i = grantlee_statistics_templates.begin(); i != grantlee_statistics_templates.end(); ++i) { - ui.printTemplate->addItem((*i).split('.')[0], QVariant::fromValue(*i)); - } - ui.printTemplate->setCurrentIndex(current_index); + ui.printTemplate->addItem(theme.split('.')[0], theme); } + ui.printTemplate->setCurrentIndex(current_index); } // print type radio buttons -- cgit v1.2.3-70-g09d2