diff options
-rw-r--r-- | qt-ui/printdialog.cpp | 2 | ||||
-rw-r--r-- | qt-ui/printoptions.cpp | 28 | ||||
-rw-r--r-- | qt-ui/printoptions.h | 6 | ||||
-rw-r--r-- | qt-ui/templateedit.cpp | 10 | ||||
-rw-r--r-- | templatelayout.cpp | 10 |
5 files changed, 11 insertions, 45 deletions
diff --git a/qt-ui/printdialog.cpp b/qt-ui/printdialog.cpp index 31ec354c8..bb6643b31 100644 --- a/qt-ui/printdialog.cpp +++ b/qt-ui/printdialog.cpp @@ -30,7 +30,6 @@ PrintDialog::PrintDialog(QWidget *parent, Qt::WindowFlags f) : QDialog(parent, f printOptions.print_selected = true; printOptions.color_selected = true; printOptions.landscape = false; - printOptions.p_template = print_options::ONE_DIVE; printOptions.type = print_options::DIVELIST; templateOptions.font_index = 0; templateOptions.font_size = 9; @@ -43,7 +42,6 @@ PrintDialog::PrintDialog(QWidget *parent, Qt::WindowFlags f) : QDialog(parent, f printOptions.print_selected = s.value("print_selected").toBool(); printOptions.color_selected = s.value("color_selected").toBool(); printOptions.landscape = s.value("landscape").toBool(); - printOptions.p_template = (print_options::print_template)s.value("template_selected").toInt(); qprinter.setOrientation((QPrinter::Orientation)printOptions.landscape); templateOptions.font_index = s.value("font").toInt(); templateOptions.font_size = s.value("font_size").toDouble(); diff --git a/qt-ui/printoptions.cpp b/qt-ui/printoptions.cpp index 0e6a0b320..3ed3edf11 100644 --- a/qt-ui/printoptions.cpp +++ b/qt-ui/printoptions.cpp @@ -29,16 +29,12 @@ void PrintOptions::setup() ui.radioStatisticsPrint->setChecked(true); break; } - switch (printOptions->p_template) { - case print_options::ONE_DIVE: - ui.printTemplate->setCurrentIndex(0); - break; - case print_options::TWO_DIVE: - ui.printTemplate->setCurrentIndex(1); - break; - case print_options::CUSTOM: - ui.printTemplate->setCurrentIndex(2); - break; + + // insert existing templates in the UI + ui.printTemplate->clear(); + qSort(grantlee_templates); + for (QList<QString>::iterator i = grantlee_templates.begin(); i != grantlee_templates.end(); ++i) { + ui.printTemplate->addItem((*i).split('.')[0], QVariant::fromValue(*i)); } // general print option checkboxes @@ -93,17 +89,7 @@ void PrintOptions::printSelectedClicked(bool check) void PrintOptions::on_printTemplate_currentIndexChanged(int index) { - switch(index){ - case 0: - printOptions->p_template = print_options::ONE_DIVE; - break; - case 1: - printOptions->p_template = print_options::TWO_DIVE; - break; - case 2: - printOptions->p_template = print_options::CUSTOM; - break; - } + printOptions->p_template = ui.printTemplate->itemData(index).toString(); } void PrintOptions::on_editButton_clicked() diff --git a/qt-ui/printoptions.h b/qt-ui/printoptions.h index 3a55c6994..3ece6b64c 100644 --- a/qt-ui/printoptions.h +++ b/qt-ui/printoptions.h @@ -11,11 +11,7 @@ struct print_options { TABLE, STATISTICS } type; - enum print_template { - ONE_DIVE, - TWO_DIVE, - CUSTOM - } p_template; + QString p_template; bool print_selected; bool color_selected; bool landscape; diff --git a/qt-ui/templateedit.cpp b/qt-ui/templateedit.cpp index 6a6328f64..de280f7a8 100644 --- a/qt-ui/templateedit.cpp +++ b/qt-ui/templateedit.cpp @@ -21,13 +21,7 @@ TemplateEdit::TemplateEdit(QWidget *parent, struct print_options *printOptions, ui->colorpalette->setCurrentIndex(templateOptions->color_palette_index); ui->linespacing->setValue(templateOptions->line_spacing); - if (printOptions->p_template == print_options::ONE_DIVE) { - grantlee_template = TemplateLayout::readTemplate("one_dive.html"); - } else if (printOptions->p_template == print_options::TWO_DIVE) { - grantlee_template = TemplateLayout::readTemplate("two_dives.html"); - } else if (printOptions->p_template == print_options::CUSTOM) { - grantlee_template = TemplateLayout::readTemplate("custom.html"); - } + grantlee_template = TemplateLayout::readTemplate(printOptions->p_template); // gui btnGroup = new QButtonGroup; @@ -118,7 +112,7 @@ void TemplateEdit::saveSettings() if (msgBox.exec() == QMessageBox::Save) { memcpy(templateOptions, &newTemplateOptions, sizeof(struct template_options)); if (grantlee_template.compare(ui->plainTextEdit->toPlainText())) { - printOptions->p_template = print_options::CUSTOM; + printOptions->p_template = "custom.html"; TemplateLayout::writeTemplate("custom.html", ui->plainTextEdit->toPlainText()); } if (templateOptions->color_palette_index == 1) { diff --git a/templatelayout.cpp b/templatelayout.cpp index 9caf773d0..8a03956f3 100644 --- a/templatelayout.cpp +++ b/templatelayout.cpp @@ -49,7 +49,6 @@ QString TemplateLayout::generate() { int progress = 0; int totalWork = getTotalWork(PrintOptions); - QString templateName; QString htmlContent; m_engine = new Grantlee::Engine(this); @@ -83,14 +82,7 @@ QString TemplateLayout::generate() Grantlee::Context c(mapping); - if (PrintOptions->p_template == print_options::ONE_DIVE) { - templateName = "one_dive.html"; - } else if (PrintOptions->p_template == print_options::TWO_DIVE) { - templateName = "two_dives.html"; - } else if (PrintOptions->p_template == print_options::CUSTOM) { - templateName = "custom.html"; - } - Grantlee::Template t = m_engine->loadByName(templateName); + Grantlee::Template t = m_engine->loadByName(PrintOptions->p_template); if (!t || t->error()) { qDebug() << "Can't load template"; return htmlContent; |