On Sat, Aug 22, 2015 at 6:44 PM, Lubomir I. Ivanov <[email protected]>
wrote:

> On 22 August 2015 at 19:20, Gehad Elrobey <[email protected]> wrote:
> >
> >
> > On Sat, Aug 22, 2015 at 5:58 PM, Lubomir I. Ivanov <[email protected]>
> > wrote:
> >>
> >> can we eventually support HTML/CSS editing of the statistics template,
> >> for instance - adding/removing table columns such as year.avg_depth,
> >> year.max_depth etc?
> >> does that mean we need another Custom.html?
> >>
> >
> > We need to add Custom.html template in printing_templates/statistics, So
> we
> > can saved edited statistics template there, unless we support in-place
> > editing.
> >
> >>
> >> actually, this opens some questions about the Custom.html
> >> concept...something that i have missed.
> >>
> >> how can the user edit, say the 6-dives template and save it from
> >> Subsurface? it always saves to the Custom.html template and editing in
> >> place is not possible. of course this is nice in a way, as they can't
> >> modify the bundled templates but i think *they should* and it's their
> >> problem if they make one of the bundled templates bad.
> >>
> >
> > I though of this, my solution was that they can always export the custom
> > template into subsurface template directory with the name they prefer
> and it
> > will be automatically added to the list, Also it is possible to export
> the
> > template anywhere then import it which will save it to the list.
> >
> >>
> >> editing in-place is the way to go, which means that if the user edits
> >> "Six Dives.html" and presses "save" the actual "Six Dives.html" is
> >> saved - this removes the need for Custom.html.
> >> what do you think? sorry for the late change request, but hopefully
> >> that won't break a lot of things.
> >>
> >
> > I think this will make the user interface more intuitive, but we will
> not be
> > able to handle overwriting the bundled templates (We can still show a
> > warning message).
> >
>
> i agree, that it does become more intuitive as Custom.html is a bit
> confusing.
>
> sometimes giving slightly more freedom to the user isn't that bad. if
> they lose a bundled template they can always re-install the whole app
> in the same folder.
> ...and to make a copy of a bundled template they can just Export in
> the same folder with a new name e.g. MyNewTemplate.html.
>
> let's do it with in-place editing and show the following warning if
> any of the bundled templates is about to be saved by the user:
> <Warning sign> (if possible)
> "You are about to modify a template bundled with Subsurface. Do you
> want to save your changes?"
> <Save>, <Cancel>
>
> For non-bundled templates:
> "Do you want to save your changes?"
> <Save>, <Cancel>
>
> this should include "statistics/Default.html" and it will be nice to
> be able to edit statistics templates as well.
>
>
Hello Lubomir,

I have attached the patches for enabling in-place edit, as well as
supporting to edit the default statistics template.
Sorry a little bit late, I was busy this week.

-- 
regards,

Gehad
From 73411fa8a1b03c943fa4bfd28c3c549278f8c7a0 Mon Sep 17 00:00:00 2001
From: Gehad elrobey <[email protected]>
Date: Thu, 27 Aug 2015 22:40:04 +0200
Subject: [PATCH 1/3] Printing: support in-place editing for templates

Edit the templates into the same file, which is more intuitive as
Custom.html is a bit confusing.

Signed-off-by: Gehad elrobey <[email protected]>
---
 printing_templates/Custom.html | 50 ------------------------------------------
 qt-ui/templateedit.cpp         |  6 +++--
 2 files changed, 4 insertions(+), 52 deletions(-)
 delete mode 100644 printing_templates/Custom.html

diff --git a/printing_templates/Custom.html b/printing_templates/Custom.html
deleted file mode 100644
index 52fdb4b..0000000
--- a/printing_templates/Custom.html
+++ /dev/null
@@ -1,50 +0,0 @@
-<html>
-<head>
-	<style>
-		body {
-			background-color: white;
-			padding: 0;
-			margin: 0;
-			font-size: {{ template_options.font_size }}vw;
-			line-height: {{ template_options.line_spacing }};
-			font-family: {{ template_options.font }};
-		}
-
-		h1 {
-			float: left;
-			font-size: {{ template_options.font_size }}vw;
-		}
-
-		.mainContainer {
-			width: 96%;
-			height: 100%;
-			margin-left: 2%;
-			margin-right: 2%;
-			margin-top: 0%;
-			margin-bottom: 0%;
-			overflow: hidden;
-			border-width: 0;
-			page-break-inside: avoid;
-		}
-
-		.innerContainer {
-			width: 98%;
-			height: 98%;
-			padding: 1%;
-			overflow: hidden;
-		}
-	</style>
-</head>
-<body data-numberofdives = 1>
-{% block main_rows %}
-	{% for dive in dives %}
-		<div class="mainContainer">
-			<div class="innerContainer">
-				<h1>This template is empty</h1>
-				<!-- Template must be filled -->
-			</div>
-		</div>
-	{% endfor %}
-{% endblock %}
-</body>
-</html>
diff --git a/qt-ui/templateedit.cpp b/qt-ui/templateedit.cpp
index b503380..7ca84c8 100644
--- a/qt-ui/templateedit.cpp
+++ b/qt-ui/templateedit.cpp
@@ -75,6 +75,9 @@ void TemplateEdit::updatePreview()
 
 	// update critical UI elements
 	ui->colorpalette->setCurrentIndex(newTemplateOptions.color_palette_index);
+
+	// update grantlee template string
+	grantlee_template = TemplateLayout::readTemplate(printOptions->p_template);
 }
 
 void TemplateEdit::on_fontsize_valueChanged(int font_size)
@@ -128,8 +131,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 = "Custom.html";
-				TemplateLayout::writeTemplate("Custom.html", ui->plainTextEdit->toPlainText());
+				TemplateLayout::writeTemplate(printOptions->p_template, ui->plainTextEdit->toPlainText());
 			}
 			if (templateOptions->color_palette_index == CUSTOM) {
 				custom_colors = templateOptions->color_palette;
-- 
2.5.0

From 964a7fb5f5ca60d32592706b837e35cc3f594893 Mon Sep 17 00:00:00 2001
From: Gehad elrobey <[email protected]>
Date: Fri, 28 Aug 2015 15:52:20 +0200
Subject: [PATCH 2/3] Printing: show warning message when editing bundled
 templates

When editing a bundled template show warning message.

Signed-off-by: Gehad elrobey <[email protected]>
---
 qt-ui/templateedit.cpp | 15 +++++++++++++--
 1 file changed, 13 insertions(+), 2 deletions(-)

diff --git a/qt-ui/templateedit.cpp b/qt-ui/templateedit.cpp
index 7ca84c8..c7ebe7f 100644
--- a/qt-ui/templateedit.cpp
+++ b/qt-ui/templateedit.cpp
@@ -121,16 +121,27 @@ void TemplateEdit::on_colorpalette_currentIndexChanged(int index)
 	updatePreview();
 }
 
+#define PREINSTALLED_TEMPLATE printOptions->p_template == "Flowlayout.html" || printOptions->p_template == "One Dive.html" \
+	|| printOptions->p_template == "Six Dives.html" || printOptions->p_template == "Table.html" || printOptions->p_template == "Two Dives.html"
+
 void TemplateEdit::saveSettings()
 {
 	if ((*templateOptions) != newTemplateOptions || grantlee_template.compare(ui->plainTextEdit->toPlainText())) {
 		QMessageBox msgBox;
-		msgBox.setText("Do you want to save your changes?");
+		QString message = "Do you want to save your changes?";
+		bool templateChanged = false;
+		if (grantlee_template.compare(ui->plainTextEdit->toPlainText())) {
+			if (PREINSTALLED_TEMPLATE) {
+				message = "You are about to modify a template bundled with Subsurface. Do you want to save your changes?";
+			}
+			templateChanged = true;
+		}
+		msgBox.setText(message);
 		msgBox.setStandardButtons(QMessageBox::Save | QMessageBox::Cancel);
 		msgBox.setDefaultButton(QMessageBox::Cancel);
 		if (msgBox.exec() == QMessageBox::Save) {
 			memcpy(templateOptions, &newTemplateOptions, sizeof(struct template_options));
-			if (grantlee_template.compare(ui->plainTextEdit->toPlainText())) {
+			if (templateChanged) {
 				TemplateLayout::writeTemplate(printOptions->p_template, ui->plainTextEdit->toPlainText());
 			}
 			if (templateOptions->color_palette_index == CUSTOM) {
-- 
2.5.0

From 1ee95485f139b81f064319cca7dc57911d9c500e Mon Sep 17 00:00:00 2001
From: Gehad elrobey <[email protected]>
Date: Fri, 28 Aug 2015 19:24:56 +0200
Subject: [PATCH 3/3] 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 <[email protected]>
---
 qt-ui/templateedit.cpp | 24 +++++++++++++++++-------
 1 file changed, 17 insertions(+), 7 deletions(-)

diff --git a/qt-ui/templateedit.cpp b/qt-ui/templateedit.cpp
index c7ebe7f..213b7f8 100644
--- a/qt-ui/templateedit.cpp
+++ b/qt-ui/templateedit.cpp
@@ -21,7 +21,11 @@ TemplateEdit::TemplateEdit(QWidget *parent, struct print_options *printOptions,
 	ui->colorpalette->setCurrentIndex(templateOptions->color_palette_index);
 	ui->linespacing->setValue(templateOptions->line_spacing);
 
-	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
 	btnGroup = new QButtonGroup;
@@ -35,9 +39,6 @@ TemplateEdit::TemplateEdit(QWidget *parent, struct print_options *printOptions,
 
 	ui->plainTextEdit->setPlainText(grantlee_template);
 	editingCustomColors = false;
-	if (printOptions->type == print_options::STATISTICS) {
-		ui->plainTextEdit->setEnabled(false);
-	}
 	updatePreview();
 }
 
@@ -77,7 +78,11 @@ void TemplateEdit::updatePreview()
 	ui->colorpalette->setCurrentIndex(newTemplateOptions.color_palette_index);
 
 	// update grantlee template string
-	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)
@@ -122,7 +127,8 @@ void TemplateEdit::on_colorpalette_currentIndexChanged(int index)
 }
 
 #define PREINSTALLED_TEMPLATE printOptions->p_template == "Flowlayout.html" || printOptions->p_template == "One Dive.html" \
-	|| printOptions->p_template == "Six Dives.html" || printOptions->p_template == "Table.html" || printOptions->p_template == "Two Dives.html"
+	|| printOptions->p_template == "Six Dives.html" || printOptions->p_template == "Table.html" || printOptions->p_template == "Two Dives.html"\
+	|| (printOptions->p_template == "Default.html" && printOptions->type == print_options::STATISTICS)
 
 void TemplateEdit::saveSettings()
 {
@@ -142,7 +148,11 @@ void TemplateEdit::saveSettings()
 		if (msgBox.exec() == QMessageBox::Save) {
 			memcpy(templateOptions, &newTemplateOptions, sizeof(struct template_options));
 			if (templateChanged) {
-				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) {
 				custom_colors = templateOptions->color_palette;
-- 
2.5.0

_______________________________________________
subsurface mailing list
[email protected]
http://lists.subsurface-divelog.org/cgi-bin/mailman/listinfo/subsurface

Reply via email to