File: undocommands.cpp

package info (click to toggle)
boats 201004-1
  • links: PTS
  • area: main
  • in suites: squeeze
  • size: 1,152 kB
  • ctags: 1,038
  • sloc: cpp: 7,080; makefile: 47; xml: 10
file content (959 lines) | stat: -rw-r--r-- 34,120 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
//
// C++ Implementation: undocommands
//
// Description:
//
//
// Author: Thibaut GRIDEL <tgridel@free.fr>
//
// Copyright (c) 2008-2010 Thibaut GRIDEL
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program.  If not, see <http://www.gnu.org/licenses/>.
//
//
#include "undocommands.h"

#include <iostream>
#include <cmath>

#include "commontypes.h"
#include "boats.h"

#include "situationmodel.h"
#include "trackmodel.h"
#include "boatmodel.h"
#include "markmodel.h"
#include "polylinemodel.h"
#include "pointmodel.h"

extern int debugLevel;

// Set Title
SetTitleUndoCommand::SetTitleUndoCommand(SituationModel* situation, QString title, QUndoCommand *parent)
        : QUndoCommand(parent),
        m_situation(situation),
        m_oldTitle(situation->title()),
        m_newTitle(title) {
    if (debugLevel & 1 << COMMAND) std::cout << "new settitleundocommand" << std::endl;
}

SetTitleUndoCommand::~SetTitleUndoCommand() {
    if (debugLevel & 1 << COMMAND) std::cout << "end settitleundocommand" << std::endl;
}

void SetTitleUndoCommand::undo() {
    if (debugLevel & 1 << COMMAND) std::cout << "undo settitleundocommand"<< std::endl;
    m_situation->setTitle(m_oldTitle);
}

void SetTitleUndoCommand::redo() {
    if (debugLevel & 1 << COMMAND) std::cout << "redo settitleundocommand" << std::endl;
    m_situation->setTitle(m_newTitle);
}

bool SetTitleUndoCommand::mergeWith(const QUndoCommand *command) {
    const SetTitleUndoCommand *settitleCommand = static_cast<const SetTitleUndoCommand*>(command);
    if (m_situation != settitleCommand->m_situation)
        return false;

    m_newTitle = settitleCommand->m_newTitle;
    return true;
}

// Set Rules
SetRulesUndoCommand::SetRulesUndoCommand(SituationModel* situation, QString rules, QUndoCommand *parent)
        : QUndoCommand(parent),
        m_situation(situation),
        m_oldRules(situation->rules()),
        m_newRules(rules) {
    if (debugLevel & 1 << COMMAND) std::cout << "new setrulesundocommand" << std::endl;
}

SetRulesUndoCommand::~SetRulesUndoCommand() {
    if (debugLevel & 1 << COMMAND) std::cout << "end setrulesundocommand" << std::endl;
}

void SetRulesUndoCommand::undo() {
    if (debugLevel & 1 << COMMAND) std::cout << "undo setrulesundocommand"<< std::endl;
    m_situation->setRules(m_oldRules);
}

void SetRulesUndoCommand::redo() {
    if (debugLevel & 1 << COMMAND) std::cout << "redo setrulesundocommand" << std::endl;
    m_situation->setRules(m_newRules);
}

bool SetRulesUndoCommand::mergeWith(const QUndoCommand *command) {
    const SetRulesUndoCommand *setrulesCommand = static_cast<const SetRulesUndoCommand*>(command);
    if (m_situation != setrulesCommand->m_situation)
        return false;

    m_newRules = setrulesCommand->m_newRules;
    return true;
}

// Show Layline
SetShowLaylineUndoCommand::SetShowLaylineUndoCommand(SituationModel *situation, QUndoCommand *parent)
        : QUndoCommand(parent),
        m_situation(situation) {
    if (debugLevel & 1 << COMMAND) std::cout << "new showlaylineundocommand" << std::endl;
}

SetShowLaylineUndoCommand::~SetShowLaylineUndoCommand() {
    if (debugLevel & 1 << COMMAND) std::cout << "end showlaylineundocommand" << std::endl;
}

void SetShowLaylineUndoCommand::undo() {
    if (debugLevel & 1 << COMMAND) std::cout << "undo showlaylineundocommand" << std::endl;
    m_situation->setShowLayline(!m_situation->showLayline());
}

void SetShowLaylineUndoCommand::redo() {
    if (debugLevel & 1 << COMMAND) std::cout << "redo showlaylineundocommand" << std::endl;
    m_situation->setShowLayline(!m_situation->showLayline());
}

bool SetShowLaylineUndoCommand::mergeWith(const QUndoCommand *command) {
    const SetShowLaylineUndoCommand *zoneCommand = static_cast<const SetShowLaylineUndoCommand*>(command);
    if (m_situation != zoneCommand->m_situation)
        return false;
    undo();
    m_situation->undoStack()->setIndex(m_situation->undoStack()->index()-1);
    return true;
}

// Set Layline
SetLaylineUndoCommand::SetLaylineUndoCommand(SituationModel* situation, const int angle, QUndoCommand *parent)
        : QUndoCommand(parent),
        m_situation(situation),
        m_oldAngle(situation->laylineAngle()),
        m_newAngle(angle) {
    if (debugLevel & 1 << COMMAND) std::cout << "new setlaylineundocommand" << std::endl;
}

SetLaylineUndoCommand::~SetLaylineUndoCommand() {
    if (debugLevel & 1 << COMMAND) std::cout << "end setlaylineundocommand" << std::endl;
}

void SetLaylineUndoCommand::undo() {
    if (debugLevel & 1 << COMMAND) std::cout << "undo setlaylineundocommand" << std::endl;
    m_situation->setLaylineAngle(m_oldAngle);
}

void SetLaylineUndoCommand::redo() {
    if (debugLevel & 1 << COMMAND) std::cout << "redo setlaylineundocommand" << std::endl;
    m_situation->setLaylineAngle(m_newAngle);
}

bool SetLaylineUndoCommand::mergeWith(const QUndoCommand *command) {
    const SetLaylineUndoCommand *setlaylineCommand = static_cast<const SetLaylineUndoCommand*>(command);
    if (m_situation != setlaylineCommand->m_situation)
        return false;

    m_newAngle = setlaylineCommand->m_newAngle;
    return true;
}

// Set Series
SetSituationSeriesUndoCommand::SetSituationSeriesUndoCommand(SituationModel* situation, const int series, QUndoCommand *parent)
        : QUndoCommand(parent),
        m_situation(situation),
        m_oldSeries(situation->situationSeries()),
        m_newSeries(series) {
    if (debugLevel & 1 << COMMAND) std::cout << "new SetSituationSeriesUndoCommand" << std::endl;
}

SetSituationSeriesUndoCommand::~SetSituationSeriesUndoCommand() {
    if (debugLevel & 1 << COMMAND) std::cout << "end SetSituationSeriesUndoCommand" << std::endl;
}

void SetSituationSeriesUndoCommand::undo() {
    if (debugLevel & 1 << COMMAND) std::cout << "undo SetSituationSeriesUndoCommand" << std::endl;
    m_situation->setSituationSeries(m_oldSeries);
}

void SetSituationSeriesUndoCommand::redo() {
    if (debugLevel & 1 << COMMAND) std::cout << "redo SetSituationSeriesUndoCommand" << std::endl;
    m_situation->setSituationSeries(m_newSeries);
}

bool SetSituationSeriesUndoCommand::mergeWith(const QUndoCommand *command) {
    const SetSituationSeriesUndoCommand *setseriesCommand = static_cast<const SetSituationSeriesUndoCommand*>(command);
    if (m_situation != setseriesCommand->m_situation)
        return false;

    m_newSeries = setseriesCommand->m_newSeries;
    return true;
}

// Set Abstract
SetAbstractUndoCommand::SetAbstractUndoCommand(SituationModel* situation, QString abstract, QUndoCommand *parent)
        : QUndoCommand(parent),
        m_situation(situation),
        m_oldAbstract(situation->abstract()),
        m_newAbstract(abstract) {
    if (debugLevel & 1 << COMMAND) std::cout << "new setabstractundocommand" << std::endl;
}

SetAbstractUndoCommand::~SetAbstractUndoCommand() {
    if (debugLevel & 1 << COMMAND) std::cout << "end setabstractundocommand" << std::endl;
}

void SetAbstractUndoCommand::undo() {
    if (debugLevel & 1 << COMMAND) std::cout << "undo setabstractundocommand"<< std::endl;
    m_situation->setAbstract(m_oldAbstract);
}

void SetAbstractUndoCommand::redo() {
    if (debugLevel & 1 << COMMAND) std::cout << "redo setabstractundocommand" << std::endl;
    m_situation->setAbstract(m_newAbstract);
}

bool SetAbstractUndoCommand::mergeWith(const QUndoCommand *command) {
    const SetAbstractUndoCommand *setabstractCommand = static_cast<const SetAbstractUndoCommand*>(command);
    if (m_situation != setabstractCommand->m_situation)
        return false;

    m_newAbstract = setabstractCommand->m_newAbstract;
    return true;
}

// Set Description
SetDescriptionUndoCommand::SetDescriptionUndoCommand(SituationModel* situation, QString description, QUndoCommand *parent)
        : QUndoCommand(parent),
        m_situation(situation),
        m_oldDescription(situation->description()),
        m_newDescription(description) {
    if (debugLevel & 1 << COMMAND) std::cout << "new setdescriptionundocommand" << std::endl;
}

SetDescriptionUndoCommand::~SetDescriptionUndoCommand() {
    if (debugLevel & 1 << COMMAND) std::cout << "end setdescriptionundocommand" << std::endl;
}

void SetDescriptionUndoCommand::undo() {
    if (debugLevel & 1 << COMMAND) std::cout << "undo setdescriptionundocommand"<< std::endl;
    m_situation->setDescription(m_oldDescription);
}

void SetDescriptionUndoCommand::redo() {
    if (debugLevel & 1 << COMMAND) std::cout << "redo setdescriptionundocommand" << std::endl;
    m_situation->setDescription(m_newDescription);
}

bool SetDescriptionUndoCommand::mergeWith(const QUndoCommand *command) {
    const SetDescriptionUndoCommand *setdescriptionCommand = static_cast<const SetDescriptionUndoCommand*>(command);
    if (m_situation != setdescriptionCommand->m_situation)
        return false;

    m_newDescription = setdescriptionCommand->m_newDescription;
    return true;
}

// Add Track
AddTrackUndoCommand::AddTrackUndoCommand(SituationModel* situation, QUndoCommand *parent)
        : QUndoCommand(parent),
        m_situation(situation) {
    if (debugLevel & 1 << COMMAND) std::cout << "new addtrackundocommand" << std::endl;
    m_track = new TrackModel(situation);
}

AddTrackUndoCommand::~AddTrackUndoCommand() {
    if (debugLevel & 1 << COMMAND) std::cout << "end addtrackundocommand" << std::endl;
    delete m_track;
}

void AddTrackUndoCommand::redo() {
    if (debugLevel & 1 << COMMAND) std::cout << "redo addtrackundocommand" << std::endl;
    m_situation->addTrack(m_track);
}

void AddTrackUndoCommand::undo() {
    if (debugLevel & 1 << COMMAND) std::cout << "undo addtrackundocommand" << std::endl;
    m_situation->deleteTrack(m_track);
}

// Delete Track
DeleteTrackUndoCommand::DeleteTrackUndoCommand(SituationModel* situation, TrackModel* track, QUndoCommand *parent)
        : QUndoCommand(parent),
        m_situation(situation),
        m_track(track) {
    if (debugLevel & 1 << COMMAND) std::cout << "new removetrackundocommand" << std::endl;
}

DeleteTrackUndoCommand::~DeleteTrackUndoCommand() {
    if (debugLevel & 1 << COMMAND) std::cout << "end removetrackundocommand" << std::endl;
}

void DeleteTrackUndoCommand::redo() {
    if (debugLevel & 1 << COMMAND) std::cout << "redo removetrackundocommand" << std::endl;
    m_situation->deleteTrack(m_track);
}

void DeleteTrackUndoCommand::undo() {
    if (debugLevel & 1 << COMMAND) std::cout << "undo removetrackundocommand" << std::endl;
    m_situation->addTrack(m_track);
}

// Set Series
SetSeriesUndoCommand::SetSeriesUndoCommand(TrackModel* track, const Boats::Series series, QUndoCommand *parent)
    : QUndoCommand(parent),
    m_track(track),
    m_oldSeries(track->series()),
    m_newSeries(series) {
    if (debugLevel & 1 << COMMAND) std::cout << "new setseriesundocommand" << std::endl;
}

SetSeriesUndoCommand::~SetSeriesUndoCommand() {
    if (debugLevel & 1 << COMMAND) std::cout << "end setseriesundocommand" << std::endl;
}

void SetSeriesUndoCommand::undo() {
    if (debugLevel & 1 << COMMAND) std::cout << "undo setseriesundocommand" << std::endl;
    m_track->setSeries(m_oldSeries);
}

void SetSeriesUndoCommand::redo() {
    if (debugLevel & 1 << COMMAND) std::cout << "redo setseriesundocommand" << std::endl;
    m_track->setSeries(m_newSeries);
}

bool SetSeriesUndoCommand::mergeWith(const QUndoCommand *command) {
    const SetSeriesUndoCommand *seriesCommand = static_cast<const SetSeriesUndoCommand*>(command);
    if (m_track != seriesCommand->m_track)
        return false;

    m_newSeries = seriesCommand->m_newSeries;
    return true;
}

// Set Color
SetColorUndoCommand::SetColorUndoCommand(TrackModel* track, const QColor color, QUndoCommand *parent)
    : QUndoCommand(parent),
    m_track(track),
    m_oldColor(track->color()),
    m_newColor(color) {
    if (debugLevel & 1 << COMMAND) std::cout << "new setcolorundocommand" << std::endl;
}

SetColorUndoCommand::~SetColorUndoCommand() {
    if (debugLevel & 1 << COMMAND) std::cout << "end setcolorundocommand" << std::endl;
}

void SetColorUndoCommand::undo() {
    if (debugLevel & 1 << COMMAND) std::cout << "undo setcolorundocommand" << std::endl;
    m_track->setColor(m_oldColor);
}

void SetColorUndoCommand::redo() {
    if (debugLevel & 1 << COMMAND) std::cout << "redo setcolorundocommand" << std::endl;
    m_track->setColor(m_newColor);
}

bool SetColorUndoCommand::mergeWith(const QUndoCommand *command) {
    const SetColorUndoCommand *colorCommand = static_cast<const SetColorUndoCommand*>(command);
    if (m_track != colorCommand->m_track)
        return false;

    m_newColor = colorCommand->m_newColor;
    return true;
}

// Show Path
SetShowPathUndoCommand::SetShowPathUndoCommand(TrackModel *track, QUndoCommand *parent)
        : QUndoCommand(parent),
        m_track(track) {
    if (debugLevel & 1 << COMMAND) std::cout << "new showlaylineundocommand" << std::endl;
}

SetShowPathUndoCommand::~SetShowPathUndoCommand() {
    if (debugLevel & 1 << COMMAND) std::cout << "end showlaylineundocommand" << std::endl;
}

void SetShowPathUndoCommand::undo() {
    if (debugLevel & 1 << COMMAND) std::cout << "undo showlaylineundocommand" << std::endl;
    m_track->setShowPath(!m_track->showPath());
}

void SetShowPathUndoCommand::redo() {
    if (debugLevel & 1 << COMMAND) std::cout << "redo showlaylineundocommand" << std::endl;
    m_track->setShowPath(!m_track->showPath());
}

bool SetShowPathUndoCommand::mergeWith(const QUndoCommand *command) {
    const SetShowPathUndoCommand *showPathCommand = static_cast<const SetShowPathUndoCommand*>(command);
    if (m_track != showPathCommand->m_track)
        return false;
    undo();
    m_track->situation()->undoStack()->setIndex(m_track->situation()->undoStack()->index()-1);
    return true;
}

// Move Model
MoveModelUndoCommand::MoveModelUndoCommand(QList<PositionModel*> &modelList, const QPointF &deltaPosition, QUndoCommand *parent)
        : QUndoCommand(parent),
        m_modelList(modelList),
        m_deltaPosition(deltaPosition) {
    if (debugLevel & 1 << COMMAND) std::cout << "new movemodelundocommand" << std::endl;
}

MoveModelUndoCommand::~MoveModelUndoCommand() {
    if (debugLevel & 1 << COMMAND) std::cout << "end movemodelundocommand" << std::endl;
}

void MoveModelUndoCommand::undo() {
    if (debugLevel & 1 << COMMAND) std::cout << "undo movemodelundocommand" << std::endl;
    for(int i=0; i< m_modelList.size(); i++) {
        PositionModel *model = m_modelList[i];
        model->setPosition(model->position() - m_deltaPosition);
    }
}

void MoveModelUndoCommand::redo() {
    if (debugLevel & 1 << COMMAND) std::cout << "redo movemodelundocommand" << std::endl;
    for(int i=0; i< m_modelList.size(); i++) {
        PositionModel *model = m_modelList[i];
        model->setPosition(model->position() + m_deltaPosition);
    }
}

bool MoveModelUndoCommand::mergeWith(const QUndoCommand *command) {
    const MoveModelUndoCommand *moveCommand = static_cast<const MoveModelUndoCommand*>(command);
    if (m_modelList != moveCommand->m_modelList)
        return false;

    m_deltaPosition += moveCommand->m_deltaPosition;
    return true;
}

// Add Boat
AddBoatUndoCommand::AddBoatUndoCommand(TrackModel* track, QPointF& position, qreal heading, QUndoCommand *parent)
        : QUndoCommand(parent),
        m_track(track) {
    if (debugLevel & 1 << COMMAND) std::cout << "new addboatundocommand" << std::endl;
    m_boat = new BoatModel(track);
    m_boat->setPosition(position);
    m_boat->setHeading(heading);
}

AddBoatUndoCommand::~AddBoatUndoCommand() {
    if (debugLevel & 1 << COMMAND) std::cout << "end addboatundocommand" << std::endl;
    delete m_boat;
}

void AddBoatUndoCommand::redo() {
    if (debugLevel & 1 << COMMAND) std::cout << "redo addboatundocommand" << std::endl;
    m_track->addBoat(m_boat);
}

void AddBoatUndoCommand::undo() {
    if (debugLevel & 1 << COMMAND) std::cout << "undo addboatundocommand" << std::endl;
    m_track->deleteBoat(m_boat);
}

// Heading Boat
HeadingBoatUndoCommand::HeadingBoatUndoCommand(QList<BoatModel*> &boatList, const qreal &heading, QUndoCommand *parent)
        : QUndoCommand(parent),
        m_boatList(boatList),
        m_heading(heading) {
    if (debugLevel & 1 << COMMAND) std::cout << "new headingboatundocommand" << std::endl;
    foreach (const BoatModel *boat, boatList) {
        m_headingList << boat->heading();
    }
}

HeadingBoatUndoCommand::~HeadingBoatUndoCommand() {
    if (debugLevel & 1 << COMMAND) std::cout << "end headingboatundocommand" << std::endl;
}

void HeadingBoatUndoCommand::undo() {
    if (debugLevel & 1 << COMMAND) std::cout << "undo headingboatundocommand" << std::endl;
    for(int i=0; i< m_boatList.size(); i++) {
        BoatModel *boat = m_boatList[i];
        boat->setHeading(m_headingList[i]);
    }
}

void HeadingBoatUndoCommand::redo() {
    if (debugLevel & 1 << COMMAND) std::cout << "redo headingboatundocommand" << std::endl;
    for(int i=0; i< m_boatList.size(); i++) {
        BoatModel *boat = m_boatList[i];
        boat->setHeading(m_heading);
    }
}

bool HeadingBoatUndoCommand::mergeWith(const QUndoCommand *command) {
    const HeadingBoatUndoCommand *headingCommand = static_cast<const HeadingBoatUndoCommand*>(command);
    if (m_boatList != headingCommand->m_boatList)
        return false;

    m_heading = headingCommand->m_heading;
    return true;
}

// Overlap Boat
OverlapBoatUndoCommand::OverlapBoatUndoCommand(SituationModel* situation, QList<BoatModel*> &boatList, Boats::Overlaps overlaps, QUndoCommand *parent)
        : QUndoCommand(parent),
        m_situation(situation),
        m_boatList(boatList),
        m_overlaps(overlaps) {
    if (debugLevel & 1 << COMMAND) std::cout << "new overlapboatundocommand" << std::endl;
}

OverlapBoatUndoCommand::~OverlapBoatUndoCommand() {
    if (debugLevel & 1 << COMMAND) std::cout << "end overlapboatundocommand" << std::endl;
}

void OverlapBoatUndoCommand::undo() {
    if (debugLevel & 1 << COMMAND) std::cout << "undo overlapboatundocommand" << std::endl;
    for(int i=0; i< m_boatList.size(); i++) {
        BoatModel *boat = m_boatList[i];
        boat->setOverlap(boat->overlap() ^ m_overlaps);
    }
}

void OverlapBoatUndoCommand::redo() {
    if (debugLevel & 1 << COMMAND) std::cout << "redo overlapboatundocommand" << std::endl;
    for(int i=0; i< m_boatList.size(); i++) {
        BoatModel *boat = m_boatList[i];
        boat->setOverlap(boat->overlap() ^ m_overlaps);
    }
}

bool OverlapBoatUndoCommand::mergeWith(const QUndoCommand *command) {
    const OverlapBoatUndoCommand *overlapCommand = static_cast<const OverlapBoatUndoCommand*>(command);
    if (m_boatList != overlapCommand->m_boatList)
        return false;

    if ((m_overlaps ^ overlapCommand->m_overlaps) == Boats::none) {
        undo();
        m_situation->undoStack()->setIndex(m_situation->undoStack()->index()-1);
    } else {
        m_overlaps = m_overlaps ^ overlapCommand->m_overlaps;
    }
    return true;
}

// Flag Boat
FlagBoatUndoCommand::FlagBoatUndoCommand(SituationModel* situation, QList<BoatModel*> &boatList, Boats::Flag flag, QUndoCommand *parent)
        : QUndoCommand(parent),
        m_situation(situation),
        m_boatList(boatList),
        m_flag(flag) {
    if (debugLevel & 1 << COMMAND) std::cout << "new flagboatundocommand" << std::endl;
    foreach (const BoatModel *boat, boatList) {
        m_flagList << boat->flag();
    }
}

FlagBoatUndoCommand::~FlagBoatUndoCommand() {
    if (debugLevel & 1 << COMMAND) std::cout << "end flagboatundocommand" << std::endl;
}

void FlagBoatUndoCommand::undo() {
    if (debugLevel & 1 << COMMAND) std::cout << "undo flagboatundocommand" << std::endl;
    for(int i=0; i< m_boatList.size(); i++) {
        BoatModel *boat = m_boatList[i];
        boat->setFlag(m_flagList[i]);
    }
}

void FlagBoatUndoCommand::redo() {
    if (debugLevel & 1 << COMMAND) std::cout << "redo flagboatundocommand" << std::endl;
    for(int i=0; i< m_boatList.size(); i++) {
        BoatModel *boat = m_boatList[i];
        boat->setFlag(m_flag);
    }
}

bool FlagBoatUndoCommand::mergeWith(const QUndoCommand *command) {
    const FlagBoatUndoCommand *flagCommand = static_cast<const FlagBoatUndoCommand*>(command);
    if (m_boatList != flagCommand->m_boatList)
        return false;

    m_flag = flagCommand->m_flag;
    return true;
}

// Trim Boat
TrimBoatUndoCommand::TrimBoatUndoCommand(QList<BoatModel*> &boatList, const qreal &trim, QUndoCommand *parent)
        : QUndoCommand(parent),
        m_boatList(boatList),
        m_trim(trim) {
    if (debugLevel & 1 << COMMAND) std::cout << "new trimboatundocommand" << std::endl;
    foreach (const BoatModel *boat, boatList) {
        m_trimList << boat->trim();
    }
}

TrimBoatUndoCommand::~TrimBoatUndoCommand() {
    if (debugLevel & 1 << COMMAND) std::cout << "end trimboatundocommand" << std::endl;
}

void TrimBoatUndoCommand::undo() {
    if (debugLevel & 1 << COMMAND) std::cout << "undo trimboatundocommand" << std::endl;
    for(int i=0; i< m_boatList.size(); i++) {
        BoatModel *model = m_boatList[i];
        model->setTrim(m_trimList[i]);
    }
}

void TrimBoatUndoCommand::redo() {
    if (debugLevel & 1 << COMMAND) std::cout << "redo trimboatundocommand" << std::endl;
    for(int i=0; i< m_boatList.size(); i++) {
        BoatModel *model = m_boatList[i];
        model->setTrim(m_trim);
    }
}

bool TrimBoatUndoCommand::mergeWith(const QUndoCommand *command) {
    const TrimBoatUndoCommand *moveCommand = static_cast<const TrimBoatUndoCommand*>(command);
    if (m_boatList != moveCommand->m_boatList)
        return false;

    m_trim = moveCommand->m_trim;
    return true;
}

// Spin Boat
SpinBoatUndoCommand::SpinBoatUndoCommand(SituationModel* situation, QList<BoatModel*> &boatList, bool spin, QUndoCommand *parent)
        : QUndoCommand(parent),
        m_situation(situation),
        m_boatList(boatList),
        m_spin(spin) {
    if (debugLevel & 1 << COMMAND) std::cout << "new spinboatundocommand" << std::endl;
    foreach (const BoatModel *boat, boatList) {
        m_spinList << boat->spin();
    }
}

SpinBoatUndoCommand::~SpinBoatUndoCommand() {
    if (debugLevel & 1 << COMMAND) std::cout << "end spinboatundocommand" << std::endl;
}

void SpinBoatUndoCommand::undo() {
    if (debugLevel & 1 << COMMAND) std::cout << "undo spinboatundocommand" << std::endl;
    for(int i=0; i< m_boatList.size(); i++) {
        BoatModel *boat = m_boatList[i];
        boat->setSpin(m_spinList[i]);
    }
}

void SpinBoatUndoCommand::redo() {
    if (debugLevel & 1 << COMMAND) std::cout << "redo spinboatundocommand" << std::endl;
    for(int i=0; i< m_boatList.size(); i++) {
        BoatModel *boat = m_boatList[i];
        boat->setSpin(m_spin);
    }
}

bool SpinBoatUndoCommand::mergeWith(const QUndoCommand *command) {
    const SpinBoatUndoCommand *spinCommand = static_cast<const SpinBoatUndoCommand*>(command);
    if (m_boatList != spinCommand->m_boatList)
        return false;

    m_spin = spinCommand->m_spin;
    return true;
}

// Set Text
SetTextUndoCommand::SetTextUndoCommand(PositionModel* model, QString text, QUndoCommand *parent)
        : QUndoCommand(parent),
        m_model(model),
        m_oldText(model->text()),
        m_newText(text) {
    if (debugLevel & 1 << COMMAND) std::cout << "new settextundocommand" << std::endl;
}

SetTextUndoCommand::~SetTextUndoCommand() {
    if (debugLevel & 1 << COMMAND) std::cout << "end settextundocommand" << std::endl;
}

void SetTextUndoCommand::undo() {
    if (debugLevel & 1 << COMMAND) std::cout << "undo settextundocommand"<< std::endl;
    m_model->setText(m_oldText);
}

void SetTextUndoCommand::redo() {
    if (debugLevel & 1 << COMMAND) std::cout << "redo settextundocommand" << std::endl;
    m_model->setText(m_newText);
}

bool SetTextUndoCommand::mergeWith(const QUndoCommand *command) {
    const SetTextUndoCommand *setTextCommand = static_cast<const SetTextUndoCommand*>(command);
    if (m_model != setTextCommand->m_model)
        return false;

    m_newText = setTextCommand->m_newText;
    return true;
}

// Move Text
MoveTextUndoCommand::MoveTextUndoCommand(PositionModel *model, const QPointF &deltaPosition, QUndoCommand *parent)
        : QUndoCommand(parent),
        m_model(model),
        m_deltaPosition(deltaPosition) {
    if (debugLevel & 1 << COMMAND) std::cout << "new movetextundocommand" << std::endl;
}

MoveTextUndoCommand::~MoveTextUndoCommand() {
    if (debugLevel & 1 << COMMAND) std::cout << "end movetextundocommand" << std::endl;
}

void MoveTextUndoCommand::undo() {
    if (debugLevel & 1 << COMMAND) std::cout << "undo movetextundocommand" << std::endl;
    m_model->setTextPosition(m_model->textPosition() - m_deltaPosition);
}

void MoveTextUndoCommand::redo() {
    if (debugLevel & 1 << COMMAND) std::cout << "redo movetextundocommand" << std::endl;
    m_model->setTextPosition(m_model->textPosition() + m_deltaPosition);
}

bool MoveTextUndoCommand::mergeWith(const QUndoCommand *command) {
    const MoveTextUndoCommand *moveCommand = static_cast<const MoveTextUndoCommand*>(command);
    if (m_model != moveCommand->m_model)
        return false;

    m_deltaPosition += moveCommand->m_deltaPosition;
    return true;
}

// Delete Boat
DeleteBoatUndoCommand::DeleteBoatUndoCommand(TrackModel* track, BoatModel* boat, QUndoCommand *parent)
        : QUndoCommand(parent),
        m_track(track),
        m_boat(boat) {
    if (debugLevel & 1 << COMMAND) std::cout << "new deleteboatundocommand" << std::endl;
}

DeleteBoatUndoCommand::~DeleteBoatUndoCommand() {
    if (debugLevel & 1 << COMMAND) std::cout << "end deletebboatundocommand" << std::endl;
}

void DeleteBoatUndoCommand::redo() {
    if (debugLevel & 1 << COMMAND) std::cout << "redo deletebboatundocommand" << std::endl;
    m_order = m_track->deleteBoat(m_boat);
}

void DeleteBoatUndoCommand::undo() {
    if (debugLevel & 1 << COMMAND) std::cout << "undo deletebboatundocommand" << std::endl;
    m_track->addBoat(m_boat, m_order);
}

// Add Mark
AddMarkUndoCommand::AddMarkUndoCommand(SituationModel* situation, QPointF& position, QUndoCommand *parent)
        : QUndoCommand(parent),
        m_situation(situation) {
    if (debugLevel & 1 << COMMAND) std::cout << "new addmarkundocommand" << std::endl;
    m_mark = new MarkModel(situation);
    m_mark->setPosition(position);
}

AddMarkUndoCommand::~AddMarkUndoCommand() {
    if (debugLevel & 1 << COMMAND) std::cout << "end addmarkundocommand" << std::endl;
    delete m_mark;
}

void AddMarkUndoCommand::redo() {
    if (debugLevel & 1 << COMMAND) std::cout << "redo addmarkundocommand" << std::endl;
    m_situation->addMark(m_mark);
}

void AddMarkUndoCommand::undo() {
    if (debugLevel & 1 << COMMAND) std::cout << "undo addmarkundocommand" << std::endl;
    m_situation->deleteMark(m_mark);
}

// Zone Mark
ZoneMarkUndoCommand::ZoneMarkUndoCommand(SituationModel *situation, const QList<MarkModel*> &markList, QUndoCommand *parent)
        : QUndoCommand(parent),
        m_situation(situation),
        m_markList(markList) {
    if (debugLevel & 1 << COMMAND) std::cout << "new zonemarkundocommand" << std::endl;
}

ZoneMarkUndoCommand::~ZoneMarkUndoCommand() {
    if (debugLevel & 1 << COMMAND) std::cout << "end zonemarkundocommand" << std::endl;
}

void ZoneMarkUndoCommand::undo() {
    if (debugLevel & 1 << COMMAND) std::cout << "undo zonemarkundocommand" << std::endl;
    for(int i=0; i< m_markList.size(); i++) {
        MarkModel *mark = m_markList[i];
        mark->setZone(!mark->zone());
    }
}

void ZoneMarkUndoCommand::redo() {
    if (debugLevel & 1 << COMMAND) std::cout << "redo zonemarkundocommand" << std::endl;
    for(int i=0; i< m_markList.size(); i++) {
        MarkModel *mark = m_markList[i];
        mark->setZone(!mark->zone());
    }
}

bool ZoneMarkUndoCommand::mergeWith(const QUndoCommand *command) {
    const ZoneMarkUndoCommand *zoneCommand = static_cast<const ZoneMarkUndoCommand*>(command);
    if (m_markList != zoneCommand->m_markList)
        return false;
    undo();
    m_situation->undoStack()->setIndex(m_situation->undoStack()->index()-1);
    return true;
}

// Set Length
LengthMarkUndoCommand::LengthMarkUndoCommand(SituationModel* situation, const int length, QUndoCommand *parent)
        : QUndoCommand(parent),
        m_situation(situation),
        m_oldLength(situation->situationLength()),
        m_newLength(length) {
    if (debugLevel & 1 << COMMAND) std::cout << "new lengthmarkundocommand" << std::endl;
}

LengthMarkUndoCommand::~LengthMarkUndoCommand() {
    if (debugLevel & 1 << COMMAND) std::cout << "end lengthmarkundocommand" << std::endl;
}

void LengthMarkUndoCommand::undo() {
    if (debugLevel & 1 << COMMAND) std::cout << "undo lengthmarkundocommand" << std::endl;
    m_situation->setSituationLength(m_oldLength);
}

void LengthMarkUndoCommand::redo() {
    if (debugLevel & 1 << COMMAND) std::cout << "redo lengthmarkundocommand" << std::endl;
    m_situation->setSituationLength(m_newLength);
}

bool LengthMarkUndoCommand::mergeWith(const QUndoCommand *command) {
    const LengthMarkUndoCommand *lengthmarkCommand = static_cast<const LengthMarkUndoCommand*>(command);
    if (m_situation != lengthmarkCommand->m_situation)
        return false;

    m_newLength = lengthmarkCommand->m_newLength;
    return true;
}

// Delete Mark
DeleteMarkUndoCommand::DeleteMarkUndoCommand(SituationModel* situation, MarkModel* mark, QUndoCommand *parent)
        : QUndoCommand(parent),
        m_situation(situation),
        m_mark(mark) {
    if (debugLevel & 1 << COMMAND) std::cout << "new deletemarkundocommand" << std::endl;
}

DeleteMarkUndoCommand::~DeleteMarkUndoCommand() {
    if (debugLevel & 1 << COMMAND) std::cout << "end deletebmarkundocommand" << std::endl;
}

void DeleteMarkUndoCommand::redo() {
    if (debugLevel & 1 << COMMAND) std::cout << "redo deletebmarkundocommand" << std::endl;
    m_order = m_situation->deleteMark(m_mark);
}

void DeleteMarkUndoCommand::undo() {
    if (debugLevel & 1 << COMMAND) std::cout << "undo deletebmarkundocommand" << std::endl;
    m_situation->addMark(m_mark, m_order);
}

// Add PolyLine
AddPolyLineUndoCommand::AddPolyLineUndoCommand(SituationModel* situation, QUndoCommand *parent)
        : QUndoCommand(parent),
        m_situation(situation) {
    if (debugLevel & 1 << COMMAND) std::cout << "new addpolylineundocommand" << std::endl;
    m_polyLine = new PolyLineModel(situation);
}

AddPolyLineUndoCommand::~AddPolyLineUndoCommand() {
    if (debugLevel & 1 << COMMAND) std::cout << "end addpolylineundocommand" << std::endl;
    delete m_polyLine;
}

void AddPolyLineUndoCommand::redo() {
    if (debugLevel & 1 << COMMAND) std::cout << "redo addpolylineundocommand" << std::endl;
    m_situation->addPolyLine(m_polyLine);
}

void AddPolyLineUndoCommand::undo() {
    if (debugLevel & 1 << COMMAND) std::cout << "undo addpolylineundocommand" << std::endl;
    m_situation->deletePolyLine(m_polyLine);
}

// Delete PolyLine
DeletePolyLineUndoCommand::DeletePolyLineUndoCommand(SituationModel* situation, PolyLineModel* polyLine, QUndoCommand *parent)
        : QUndoCommand(parent),
        m_situation(situation),
        m_polyLine(polyLine) {
    if (debugLevel & 1 << COMMAND) std::cout << "new removepolylineundocommand" << std::endl;
}

DeletePolyLineUndoCommand::~DeletePolyLineUndoCommand() {
    if (debugLevel & 1 << COMMAND) std::cout << "end removepolylineundocommand" << std::endl;
}

void DeletePolyLineUndoCommand::redo() {
    if (debugLevel & 1 << COMMAND) std::cout << "redo removepolylineundocommand" << std::endl;
    m_situation->deletePolyLine(m_polyLine);
}

void DeletePolyLineUndoCommand::undo() {
    if (debugLevel & 1 << COMMAND) std::cout << "undo removepolylineundocommand" << std::endl;
    m_situation->addPolyLine(m_polyLine);
}

// Add Point
AddPointUndoCommand::AddPointUndoCommand(PolyLineModel* polyLine, QPointF& position, QUndoCommand *parent)
        : QUndoCommand(parent),
        m_polyLine(polyLine) {
    if (debugLevel & 1 << COMMAND) std::cout << "new addpointundocommand" << std::endl;
    m_point = new PointModel(polyLine);
    m_point->setPosition(position);
}

AddPointUndoCommand::~AddPointUndoCommand() {
    if (debugLevel & 1 << COMMAND) std::cout << "end addpointundocommand" << std::endl;
    delete m_point;
}

void AddPointUndoCommand::redo() {
    if (debugLevel & 1 << COMMAND) std::cout << "redo addpointundocommand" << std::endl;
    m_polyLine->addPoint(m_point);
}

void AddPointUndoCommand::undo() {
    if (debugLevel & 1 << COMMAND) std::cout << "undo addpointundocommand" << std::endl;
    m_polyLine->deletePoint(m_point);
}

// Delete Point
DeletePointUndoCommand::DeletePointUndoCommand(PolyLineModel* polyLine, PointModel* point, QUndoCommand *parent)
        : QUndoCommand(parent),
        m_polyLine(polyLine),
        m_point(point) {
    if (debugLevel & 1 << COMMAND) std::cout << "new deletepointundocommand" << std::endl;
}

DeletePointUndoCommand::~DeletePointUndoCommand() {
    if (debugLevel & 1 << COMMAND) std::cout << "end deletepointundocommand" << std::endl;
}

void DeletePointUndoCommand::redo() {
    if (debugLevel & 1 << COMMAND) std::cout << "redo deletepointundocommand" << std::endl;
    m_order = m_polyLine->deletePoint(m_point);
}

void DeletePointUndoCommand::undo() {
    if (debugLevel & 1 << COMMAND) std::cout << "undo deletepointundocommand" << std::endl;
    m_polyLine->addPoint(m_point, m_order);
}