Changeset View
Changeset View
Standalone View
Standalone View
commands/kpCommandHistory.cpp
Show All 38 Lines | |||||
39 | 39 | | |||
40 | 40 | | |||
41 | kpCommandHistory::kpCommandHistory (bool doReadConfig, kpMainWindow *mainWindow) | 41 | kpCommandHistory::kpCommandHistory (bool doReadConfig, kpMainWindow *mainWindow) | ||
42 | : kpCommandHistoryBase (doReadConfig, mainWindow->actionCollection ()), | 42 | : kpCommandHistoryBase (doReadConfig, mainWindow->actionCollection ()), | ||
43 | m_mainWindow (mainWindow) | 43 | m_mainWindow (mainWindow) | ||
44 | { | 44 | { | ||
45 | } | 45 | } | ||
46 | 46 | | |||
47 | kpCommandHistory::~kpCommandHistory () | 47 | kpCommandHistory::~kpCommandHistory () = default; | ||
48 | { | | |||
49 | } | | |||
50 | 48 | | |||
51 | 49 | | |||
52 | static bool NextUndoCommandIsCreateBorder (kpCommandHistory *commandHistory) | 50 | static bool NextUndoCommandIsCreateBorder (kpCommandHistory *commandHistory) | ||
53 | { | 51 | { | ||
54 | Q_ASSERT (commandHistory); | 52 | Q_ASSERT (commandHistory); | ||
55 | 53 | | |||
56 | kpCommand *cmd = commandHistory->nextUndoCommand (); | 54 | kpCommand *cmd = commandHistory->nextUndoCommand (); | ||
57 | if (!cmd) | 55 | if (!cmd) { | ||
58 | return false; | 56 | return false; | ||
57 | } | ||||
59 | 58 | | |||
60 | kpToolSelectionCreateCommand *c = dynamic_cast <kpToolSelectionCreateCommand *> (cmd); | 59 | auto *c = dynamic_cast <kpToolSelectionCreateCommand *> (cmd); | ||
61 | if (!c) | 60 | if (!c) { | ||
62 | return false; | 61 | return false; | ||
62 | } | ||||
63 | 63 | | |||
64 | const kpAbstractSelection *sel = c->fromSelection (); | 64 | const kpAbstractSelection *sel = c->fromSelection (); | ||
65 | Q_ASSERT (sel); | 65 | Q_ASSERT (sel); | ||
66 | 66 | | |||
67 | return (!sel->hasContent ()); | 67 | return (!sel->hasContent ()); | ||
68 | } | 68 | } | ||
69 | 69 | | |||
70 | // public | 70 | // public | ||
71 | void kpCommandHistory::addCreateSelectionCommand (kpToolSelectionCreateCommand *cmd, | 71 | void kpCommandHistory::addCreateSelectionCommand (kpToolSelectionCreateCommand *cmd, | ||
72 | bool execute) | 72 | bool execute) | ||
73 | { | 73 | { | ||
74 | if (cmd->fromSelection ()->hasContent ()) | 74 | if (cmd->fromSelection ()->hasContent ()) | ||
75 | { | 75 | { | ||
76 | addCommand (cmd, execute); | 76 | addCommand (cmd, execute); | ||
77 | return; | 77 | return; | ||
78 | } | 78 | } | ||
79 | 79 | | |||
80 | if (::NextUndoCommandIsCreateBorder (this)) | 80 | if (::NextUndoCommandIsCreateBorder (this)) | ||
81 | { | 81 | { | ||
82 | setNextUndoCommand (cmd); | 82 | setNextUndoCommand (cmd); | ||
83 | if (execute) | 83 | if (execute) { | ||
84 | cmd->execute (); | 84 | cmd->execute (); | ||
85 | } | 85 | } | ||
86 | else | 86 | } | ||
87 | else { | ||||
87 | addCommand (cmd, execute); | 88 | addCommand (cmd, execute); | ||
88 | } | 89 | } | ||
90 | } | ||||
89 | 91 | | |||
90 | //--------------------------------------------------------------------- | 92 | //--------------------------------------------------------------------- | ||
91 | 93 | | |||
92 | // public slot virtual [base KCommandHistory] | 94 | // public slot virtual [base KCommandHistory] | ||
93 | void kpCommandHistory::undo () | 95 | void kpCommandHistory::undo () | ||
94 | { | 96 | { | ||
95 | qCDebug(kpLogCommands) << "kpCommandHistory::undo() CALLED!"; | 97 | qCDebug(kpLogCommands) << "kpCommandHistory::undo() CALLED!"; | ||
96 | if (m_mainWindow && m_mainWindow->toolHasBegunShape ()) | 98 | if (m_mainWindow && m_mainWindow->toolHasBegunShape ()) | ||
97 | { | 99 | { | ||
98 | qCDebug(kpLogCommands) << "\thas begun shape - cancel draw"; | 100 | qCDebug(kpLogCommands) << "\thas begun shape - cancel draw"; | ||
99 | m_mainWindow->tool ()->cancelShapeInternal (); | 101 | m_mainWindow->tool ()->cancelShapeInternal (); | ||
100 | } | 102 | } | ||
101 | else | 103 | else { | ||
102 | kpCommandHistoryBase::undo (); | 104 | kpCommandHistoryBase::undo (); | ||
103 | } | 105 | } | ||
106 | } | ||||
104 | 107 | | |||
105 | //--------------------------------------------------------------------- | 108 | //--------------------------------------------------------------------- | ||
106 | 109 | | |||
107 | // public slot virtual [base KCommandHistory] | 110 | // public slot virtual [base KCommandHistory] | ||
108 | void kpCommandHistory::redo () | 111 | void kpCommandHistory::redo () | ||
109 | { | 112 | { | ||
110 | if (m_mainWindow && m_mainWindow->toolHasBegunShape ()) | 113 | if (m_mainWindow && m_mainWindow->toolHasBegunShape ()) | ||
111 | { | 114 | { | ||
112 | // Not completely obvious but what else can we do? | 115 | // Not completely obvious but what else can we do? | ||
113 | // | 116 | // | ||
114 | // Ignoring the request would not be intuitive for tools like | 117 | // Ignoring the request would not be intuitive for tools like | ||
115 | // Polygon & Polyline (where it's not always apparent to the user | 118 | // Polygon & Polyline (where it's not always apparent to the user | ||
116 | // that s/he's still drawing a shape even though the mouse isn't | 119 | // that s/he's still drawing a shape even though the mouse isn't | ||
117 | // down). | 120 | // down). | ||
118 | m_mainWindow->tool ()->cancelShapeInternal (); | 121 | m_mainWindow->tool ()->cancelShapeInternal (); | ||
119 | } | 122 | } | ||
120 | else | 123 | else { | ||
121 | kpCommandHistoryBase::redo (); | 124 | kpCommandHistoryBase::redo (); | ||
122 | } | 125 | } | ||
126 | } | ||||
123 | 127 | | |||
124 | 128 | |