Request For Comments - Undo/Redo framework

Dirk Hohndel dirk at hohndel.org
Sat Feb 14 16:09:30 PST 2015


Hi Grace...

On Sat, Feb 14, 2015 at 09:28:54PM +0300, Grace Karanja wrote:
> 
> The attached patch now implements undo for time shifts in dives.

Thanks. Some comments below...

> diff --git a/qt-ui/simplewidgets.cpp b/qt-ui/simplewidgets.cpp
> index 5c08a3f..22e589e 100644
> --- a/qt-ui/simplewidgets.cpp
> +++ b/qt-ui/simplewidgets.cpp
> @@ -200,7 +201,16 @@ void ShiftTimesDialog::buttonClicked(QAbstractButton *button)
>  			amount *= -1;
>  		if (amount != 0) {
>  			// DANGER, DANGER - this could get our dive_table unsorted...
> -			shift_times(amount);

At first I thought that this was a bug and that we are now no longer
shifting time...

But it turns out that we are triggering the 'redo' action right away and
THAT takes care of applying the action. I found that slightly confusing,
but it works.

> +			for_each_dive (i, dive) {
> +				if (!dive->selected)
> +					continue;
> +
> +				affectedDives.append(dive->id);
> +			}

Very nice. Here you don't need to store the whole dives, just their id and
then you can re-apply the change!

/D


More information about the subsurface mailing list