diff options
author | Gehad elrobey <gehadelrobey@gmail.com> | 2015-07-11 01:06:43 +0200 |
---|---|---|
committer | Lubomir I. Ivanov <neolit123@gmail.com> | 2015-07-20 15:28:07 +0300 |
commit | 7ca311ae859199f1e07279bf78e1c36efc97768c (patch) | |
tree | 97ae2718b5fcfe7a4e7b4c4018a0911c0d5e223a | |
parent | d4382c7c4b802b030bab5e64de4b1641f603d543 (diff) | |
download | subsurface-7ca311ae859199f1e07279bf78e1c36efc97768c.tar.gz |
Printing: save only if data is changed in template_options
Check if data is changed before saving the new settings.
Signed-off-by: Gehad elrobey <gehadelrobey@gmail.com>
Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com>
-rw-r--r-- | qt-ui/printoptions.h | 6 | ||||
-rw-r--r-- | qt-ui/templateedit.cpp | 12 | ||||
-rw-r--r-- | qt-ui/templateedit.h | 1 |
3 files changed, 14 insertions, 5 deletions
diff --git a/qt-ui/printoptions.h b/qt-ui/printoptions.h index d96b27a53..3a5c2b179 100644 --- a/qt-ui/printoptions.h +++ b/qt-ui/printoptions.h @@ -26,6 +26,12 @@ struct template_options { int color_palette_index; double font_size; double line_spacing; + bool operator!=(const template_options &other) const { + return other.font_index != font_index + || other.color_palette_index != color_palette_index + || other.font_size != font_size + || other.line_spacing != line_spacing; + } }; // should be based on a custom QPrintDialog class diff --git a/qt-ui/templateedit.cpp b/qt-ui/templateedit.cpp index 19f5db609..0354131ef 100644 --- a/qt-ui/templateedit.cpp +++ b/qt-ui/templateedit.cpp @@ -11,6 +11,7 @@ TemplateEdit::TemplateEdit(QWidget *parent, struct print_options *printOptions, { ui->setupUi(this); this->templateOptions = templateOptions; + newTemplateOptions = *templateOptions; this->printOptions = printOptions; // restore the settings and init the UI @@ -45,32 +46,33 @@ TemplateEdit::~TemplateEdit() void TemplateEdit::on_fontsize_valueChanged(int font_size) { - templateOptions->font_size = font_size; + newTemplateOptions.font_size = font_size; } void TemplateEdit::on_linespacing_valueChanged(double line_spacing) { - templateOptions->line_spacing = line_spacing; + newTemplateOptions.line_spacing = line_spacing; } void TemplateEdit::on_fontSelection_currentIndexChanged(int index) { - templateOptions->font_index = index; + newTemplateOptions.font_index = index; } void TemplateEdit::on_colorpalette_currentIndexChanged(int index) { - templateOptions->color_palette_index = index; + newTemplateOptions.color_palette_index = index; } void TemplateEdit::on_TemplateEdit_finished(int result) { - if (grantlee_template.compare(ui->plainTextEdit->toPlainText())) { + if ((*templateOptions) != newTemplateOptions || grantlee_template.compare(ui->plainTextEdit->toPlainText())) { QMessageBox msgBox; msgBox.setText("Do you want to save your changes?"); msgBox.setStandardButtons(QMessageBox::Save | QMessageBox::Discard); msgBox.setDefaultButton(QMessageBox::Discard); if (msgBox.exec() == QMessageBox::Save) { + memcpy(templateOptions, &newTemplateOptions, sizeof(struct template_options)); printOptions->p_template = print_options::CUSTOM; TemplateLayout::writeTemplate("custom.html", ui->plainTextEdit->toPlainText()); } diff --git a/qt-ui/templateedit.h b/qt-ui/templateedit.h index 296005652..325d7eef3 100644 --- a/qt-ui/templateedit.h +++ b/qt-ui/templateedit.h @@ -29,6 +29,7 @@ private slots: private: Ui::TemplateEdit *ui; struct template_options *templateOptions; + struct template_options newTemplateOptions; struct print_options *printOptions; QString grantlee_template; }; |