mirror of
https://github.com/subsurface/subsurface.git
synced 2025-01-19 14:25:27 +00:00
Printing: use grantlee templates from the current existing template list
We use templates from the grantlee templates list created and dynamically. So we don't need static templates anymore. Signed-off-by: Gehad elrobey <gehadelrobey@gmail.com> Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com>
This commit is contained in:
parent
c95358c4b9
commit
2b2c506cb7
5 changed files with 11 additions and 45 deletions
|
@ -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();
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Add table
Reference in a new issue