diff options
author | Tomaz Canabrava <tomaz.canabrava@intel.com> | 2016-01-08 15:21:49 -0200 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2016-01-08 10:01:51 -0800 |
commit | 1210d4b575728f2acacb2813a69cf0ee4920a9be (patch) | |
tree | 10d6040c1f0b7e328fce33bb2072c91a0337a692 /desktop-widgets/printoptions.cpp | |
parent | c496d5fa05a9921515e2cbf840d5df39d027b2ed (diff) | |
download | subsurface-1210d4b575728f2acacb2813a69cf0ee4920a9be.tar.gz |
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>
Diffstat (limited to 'desktop-widgets/printoptions.cpp')
-rw-r--r-- | desktop-widgets/printoptions.cpp | 42 |
1 files changed, 11 insertions, 31 deletions
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<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 |