Printing: make statistics template editable

Now inplace edit is supported, so enable editing the "Default"
statistics template, Also show warning when editing this template.

Signed-off-by: Gehad elrobey <gehadelrobey@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
Gehad elrobey 2015-09-16 21:32:32 -03:00 committed by Dirk Hohndel
parent d3c75f2c72
commit bdedc97036

View file

@ -22,6 +22,11 @@ TemplateEdit::TemplateEdit(QWidget *parent, struct print_options *printOptions,
ui->linespacing->setValue(templateOptions->line_spacing); ui->linespacing->setValue(templateOptions->line_spacing);
grantlee_template = TemplateLayout::readTemplate(printOptions->p_template); grantlee_template = TemplateLayout::readTemplate(printOptions->p_template);
if (printOptions->type == print_options::DIVELIST) {
grantlee_template = TemplateLayout::readTemplate(printOptions->p_template);
} else if (printOptions->type == print_options::STATISTICS) {
grantlee_template = TemplateLayout::readTemplate(QString::fromUtf8("statistics") + QDir::separator() + printOptions->p_template);
}
// gui // gui
btnGroup = new QButtonGroup; btnGroup = new QButtonGroup;
@ -35,9 +40,6 @@ TemplateEdit::TemplateEdit(QWidget *parent, struct print_options *printOptions,
ui->plainTextEdit->setPlainText(grantlee_template); ui->plainTextEdit->setPlainText(grantlee_template);
editingCustomColors = false; editingCustomColors = false;
if (printOptions->type == print_options::STATISTICS) {
ui->plainTextEdit->setEnabled(false);
}
updatePreview(); updatePreview();
} }
@ -78,6 +80,11 @@ void TemplateEdit::updatePreview()
// update grantlee template string // update grantlee template string
grantlee_template = TemplateLayout::readTemplate(printOptions->p_template); grantlee_template = TemplateLayout::readTemplate(printOptions->p_template);
if (printOptions->type == print_options::DIVELIST) {
grantlee_template = TemplateLayout::readTemplate(printOptions->p_template);
} else if (printOptions->type == print_options::STATISTICS) {
grantlee_template = TemplateLayout::readTemplate(QString::fromUtf8("statistics") + QDir::separator() + printOptions->p_template);
}
} }
void TemplateEdit::on_fontsize_valueChanged(int font_size) void TemplateEdit::on_fontsize_valueChanged(int font_size)
@ -130,7 +137,7 @@ void TemplateEdit::saveSettings()
QString message = "Do you want to save your changes?"; QString message = "Do you want to save your changes?";
bool templateChanged = false; bool templateChanged = false;
if (grantlee_template.compare(ui->plainTextEdit->toPlainText())) { if (grantlee_template.compare(ui->plainTextEdit->toPlainText())) {
if (bundledTemplates.contains(printOptions->p_template)) { if (bundledTemplates.contains(printOptions->p_template) || (printOptions->p_template == "Default.html" && printOptions->type == print_options::STATISTICS)) {
message = "You are about to modify a template bundled with Subsurface. Do you want to save your changes?"; message = "You are about to modify a template bundled with Subsurface. Do you want to save your changes?";
} }
templateChanged = true; templateChanged = true;
@ -142,6 +149,11 @@ void TemplateEdit::saveSettings()
memcpy(templateOptions, &newTemplateOptions, sizeof(struct template_options)); memcpy(templateOptions, &newTemplateOptions, sizeof(struct template_options));
if (templateChanged) { if (templateChanged) {
TemplateLayout::writeTemplate(printOptions->p_template, ui->plainTextEdit->toPlainText()); TemplateLayout::writeTemplate(printOptions->p_template, ui->plainTextEdit->toPlainText());
if (printOptions->type == print_options::DIVELIST) {
TemplateLayout::writeTemplate(printOptions->p_template, ui->plainTextEdit->toPlainText());
} else if (printOptions->type == print_options::STATISTICS) {
TemplateLayout::writeTemplate(QString::fromUtf8("statistics") + QDir::separator() + printOptions->p_template, ui->plainTextEdit->toPlainText());
}
} }
if (templateOptions->color_palette_index == CUSTOM) { if (templateOptions->color_palette_index == CUSTOM) {
custom_colors = templateOptions->color_palette; custom_colors = templateOptions->color_palette;