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 <tomaz.canabrava@intel.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
Tomaz Canabrava 2016-01-08 15:21:49 -02:00 committed by Dirk Hohndel
parent c496d5fa05
commit 1210d4b575

View file

@ -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<QString>::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<QString>::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<QString>::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<QString>::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