Skip to content

Commit a7c0ca1

Browse files
committed
Template: Revise trySetTemplateGeoreferenced
Don't return the resulting value, but indicate success or error. This is necessary to suppress an error message if the user intentionally cancelled CRS configuration on enabling geoerefencing.
1 parent d170bda commit a7c0ca1

File tree

4 files changed

+12
-13
lines changed

4 files changed

+12
-13
lines changed

src/gui/widgets/template_list_widget.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
* Copyright 2012, 2013 Thomas Schöps
3-
* Copyright 2012-2019 Kai Pastor
3+
* Copyright 2012-2020 Kai Pastor
44
*
55
* This file is part of OpenOrienteering.
66
*
@@ -1102,7 +1102,7 @@ void TemplateListWidget::changeGeorefClicked()
11021102
if (position_action->isChecked())
11031103
position_action->trigger();
11041104
}
1105-
if (templ->trySetTemplateGeoreferenced(new_value, this) != new_value)
1105+
if (!templ->trySetTemplateGeoreferenced(new_value, this))
11061106
{
11071107
QMessageBox::warning(this, tr("Error"), tr("Cannot change the georeferencing state."));
11081108
georef_action->setChecked(templ->isTemplateGeoreferenced());

src/templates/template.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
* Copyright 2012, 2013 Thomas Schöps
3-
* Copyright 2013-2019 Kai Pastor
3+
* Copyright 2013-2020 Kai Pastor
44
*
55
* This file is part of OpenOrienteering.
66
*
@@ -676,9 +676,9 @@ bool Template::canChangeTemplateGeoreferenced()
676676
}
677677

678678
// virtual
679-
bool Template::trySetTemplateGeoreferenced(bool /*value*/, QWidget* /*dialog_parent*/)
679+
bool Template::trySetTemplateGeoreferenced(bool value, QWidget* /*dialog_parent*/)
680680
{
681-
return is_georeferenced;
681+
return isTemplateGeoreferenced() == value;
682682
}
683683

684684

src/templates/template.h

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
* Copyright 2012, 2013 Thomas Schöps
3-
* Copyright 2012-2019 Kai Pastor
3+
* Copyright 2012-2020 Kai Pastor
44
*
55
* This file is part of OpenOrienteering.
66
*
@@ -518,12 +518,11 @@ Q_OBJECT
518518
* Tries to change the usage of georeferencing data.
519519
*
520520
* If supported by the actual template, this function tries to switch the
521-
* state between non-georeferenced and georeferenced. It returns the final
522-
* state which may be the same as before if the change is not implemented
523-
* or fails for other reasons.
521+
* state between non-georeferenced and georeferenced. It returns false when
522+
* an error occurred, and true if the change was successful or if it was
523+
* explicitly cancelled by the user.
524524
*
525-
* The default implementation changes nothing, and it just returns the
526-
* current state.
525+
* The default implementation returns true iff the state matches the value.
527526
*/
528527
virtual bool trySetTemplateGeoreferenced(bool value, QWidget* dialog_parent);
529528

src/templates/template_image.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -385,7 +385,7 @@ bool TemplateImage::trySetTemplateGeoreferenced(bool value, QWidget* dialog_pare
385385
dialog_parent,
386386
tr("Select the coordinate reference system of the coordinates in the world file") );
387387
if (dialog.exec() == QDialog::Rejected)
388-
return isTemplateGeoreferenced();
388+
return true; // not failed!
389389

390390
setTemplateAreaDirty();
391391
available_georef.effective.crs_spec = dialog.currentCRSSpec();
@@ -404,7 +404,7 @@ bool TemplateImage::trySetTemplateGeoreferenced(bool value, QWidget* dialog_pare
404404
}
405405
map->setTemplatesDirty();
406406
}
407-
return isTemplateGeoreferenced();
407+
return isTemplateGeoreferenced() == value;
408408
}
409409

410410
void TemplateImage::updateGeoreferencing()

0 commit comments

Comments
 (0)