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.print_selected = true;
|
||||||
printOptions.color_selected = true;
|
printOptions.color_selected = true;
|
||||||
printOptions.landscape = false;
|
printOptions.landscape = false;
|
||||||
printOptions.p_template = print_options::ONE_DIVE;
|
|
||||||
printOptions.type = print_options::DIVELIST;
|
printOptions.type = print_options::DIVELIST;
|
||||||
templateOptions.font_index = 0;
|
templateOptions.font_index = 0;
|
||||||
templateOptions.font_size = 9;
|
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.print_selected = s.value("print_selected").toBool();
|
||||||
printOptions.color_selected = s.value("color_selected").toBool();
|
printOptions.color_selected = s.value("color_selected").toBool();
|
||||||
printOptions.landscape = s.value("landscape").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);
|
qprinter.setOrientation((QPrinter::Orientation)printOptions.landscape);
|
||||||
templateOptions.font_index = s.value("font").toInt();
|
templateOptions.font_index = s.value("font").toInt();
|
||||||
templateOptions.font_size = s.value("font_size").toDouble();
|
templateOptions.font_size = s.value("font_size").toDouble();
|
||||||
|
|
|
@ -29,16 +29,12 @@ void PrintOptions::setup()
|
||||||
ui.radioStatisticsPrint->setChecked(true);
|
ui.radioStatisticsPrint->setChecked(true);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
switch (printOptions->p_template) {
|
|
||||||
case print_options::ONE_DIVE:
|
// insert existing templates in the UI
|
||||||
ui.printTemplate->setCurrentIndex(0);
|
ui.printTemplate->clear();
|
||||||
break;
|
qSort(grantlee_templates);
|
||||||
case print_options::TWO_DIVE:
|
for (QList<QString>::iterator i = grantlee_templates.begin(); i != grantlee_templates.end(); ++i) {
|
||||||
ui.printTemplate->setCurrentIndex(1);
|
ui.printTemplate->addItem((*i).split('.')[0], QVariant::fromValue(*i));
|
||||||
break;
|
|
||||||
case print_options::CUSTOM:
|
|
||||||
ui.printTemplate->setCurrentIndex(2);
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// general print option checkboxes
|
// general print option checkboxes
|
||||||
|
@ -93,17 +89,7 @@ void PrintOptions::printSelectedClicked(bool check)
|
||||||
|
|
||||||
void PrintOptions::on_printTemplate_currentIndexChanged(int index)
|
void PrintOptions::on_printTemplate_currentIndexChanged(int index)
|
||||||
{
|
{
|
||||||
switch(index){
|
printOptions->p_template = ui.printTemplate->itemData(index).toString();
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void PrintOptions::on_editButton_clicked()
|
void PrintOptions::on_editButton_clicked()
|
||||||
|
|
|
@ -11,11 +11,7 @@ struct print_options {
|
||||||
TABLE,
|
TABLE,
|
||||||
STATISTICS
|
STATISTICS
|
||||||
} type;
|
} type;
|
||||||
enum print_template {
|
QString p_template;
|
||||||
ONE_DIVE,
|
|
||||||
TWO_DIVE,
|
|
||||||
CUSTOM
|
|
||||||
} p_template;
|
|
||||||
bool print_selected;
|
bool print_selected;
|
||||||
bool color_selected;
|
bool color_selected;
|
||||||
bool landscape;
|
bool landscape;
|
||||||
|
|
|
@ -21,13 +21,7 @@ TemplateEdit::TemplateEdit(QWidget *parent, struct print_options *printOptions,
|
||||||
ui->colorpalette->setCurrentIndex(templateOptions->color_palette_index);
|
ui->colorpalette->setCurrentIndex(templateOptions->color_palette_index);
|
||||||
ui->linespacing->setValue(templateOptions->line_spacing);
|
ui->linespacing->setValue(templateOptions->line_spacing);
|
||||||
|
|
||||||
if (printOptions->p_template == print_options::ONE_DIVE) {
|
grantlee_template = TemplateLayout::readTemplate(printOptions->p_template);
|
||||||
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");
|
|
||||||
}
|
|
||||||
|
|
||||||
// gui
|
// gui
|
||||||
btnGroup = new QButtonGroup;
|
btnGroup = new QButtonGroup;
|
||||||
|
@ -118,7 +112,7 @@ void TemplateEdit::saveSettings()
|
||||||
if (msgBox.exec() == QMessageBox::Save) {
|
if (msgBox.exec() == QMessageBox::Save) {
|
||||||
memcpy(templateOptions, &newTemplateOptions, sizeof(struct template_options));
|
memcpy(templateOptions, &newTemplateOptions, sizeof(struct template_options));
|
||||||
if (grantlee_template.compare(ui->plainTextEdit->toPlainText())) {
|
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());
|
TemplateLayout::writeTemplate("custom.html", ui->plainTextEdit->toPlainText());
|
||||||
}
|
}
|
||||||
if (templateOptions->color_palette_index == 1) {
|
if (templateOptions->color_palette_index == 1) {
|
||||||
|
|
|
@ -49,7 +49,6 @@ QString TemplateLayout::generate()
|
||||||
{
|
{
|
||||||
int progress = 0;
|
int progress = 0;
|
||||||
int totalWork = getTotalWork(PrintOptions);
|
int totalWork = getTotalWork(PrintOptions);
|
||||||
QString templateName;
|
|
||||||
|
|
||||||
QString htmlContent;
|
QString htmlContent;
|
||||||
m_engine = new Grantlee::Engine(this);
|
m_engine = new Grantlee::Engine(this);
|
||||||
|
@ -83,14 +82,7 @@ QString TemplateLayout::generate()
|
||||||
|
|
||||||
Grantlee::Context c(mapping);
|
Grantlee::Context c(mapping);
|
||||||
|
|
||||||
if (PrintOptions->p_template == print_options::ONE_DIVE) {
|
Grantlee::Template t = m_engine->loadByName(PrintOptions->p_template);
|
||||||
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);
|
|
||||||
if (!t || t->error()) {
|
if (!t || t->error()) {
|
||||||
qDebug() << "Can't load template";
|
qDebug() << "Can't load template";
|
||||||
return htmlContent;
|
return htmlContent;
|
||||||
|
|
Loading…
Add table
Reference in a new issue