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>
This commit is contained in:
Gehad elrobey 2015-07-11 01:06:43 +02:00 committed by Lubomir I. Ivanov
parent d4382c7c4b
commit 7ca311ae85
3 changed files with 14 additions and 5 deletions

View file

@ -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

View file

@ -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());
}

View file

@ -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;
};