Changeset 53 in projects for punch-card/punch-card-editor/src/qpunchcard/deck.h
- Timestamp:
- Dec 24, 2009, 4:17:54 AM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
punch-card/punch-card-editor/src/qpunchcard/deck.h
r52 r53 11 11 class DeckIndex; 12 12 13 class DeckUndoCommand; 13 14 class DeckAppendCard; 14 15 class DeckModifyCard; … … 68 69 // =========== Undo Framework ================== 69 70 bool isModified() const { return !undo_stack.isClean(); } 71 /// for advanced usage. Handle with care. Object still owned by the Deck. 72 QUndoStack* getUndoStack() { return &undo_stack; } 73 QAction* createRedoAction(const QString& prefix = QString()) { return undo_stack.createRedoAction(this,prefix); } 74 QAction* createUndoAction(const QString& prefix = QString()) { return undo_stack.createUndoAction(this,prefix); } 75 70 76 71 77 // =========== Index Handling, reading access to cards ================== … … 80 86 public: 81 87 // =========== Editing (Undo captured) ================== 88 /** 89 * The main editing command interface. Your code creates a undo 90 * command and executes it by calling this method. It will push 91 * the command on the undo stack *AND* call command->redo() (by 92 * default), if call_redo is true. 93 * It won't return anything. If command is associated with no 94 * or another deck, it will be changed. 95 **/ 96 void run(DeckUndoCommand* command, bool call_redo = true); 97 98 // all following functions are shorthands for run() with 99 // appropriate commands. 100 82 101 /// Insert one new card 83 102 bool insert(DeckIndex after); … … 93 112 94 113 // Quick & dirty, no official standard 95 inlinevoid emitChanged(DeckIndex lower, DeckIndex upper);114 void emitChanged(DeckIndex lower, DeckIndex upper); 96 115 97 116 signals: … … 147 166 bool isLast() const { return i == deck->count(); } 148 167 149 constQPointer<Deck> getDeck() const { return deck; }168 QPointer<Deck> getDeck() const { return deck; } 150 169 void setDeck(Deck* deck) { this->deck = deck; } 151 170 bool assertDeck(Deck* fallback) { if(!deck) deck=fallback; return deck == fallback; } … … 164 183 165 184 /** 185 * The base undo command. Still abstract. 186 **/ 187 class DeckUndoCommand : public QUndoCommand { 188 public: 189 DeckUndoCommand(Deck* deck = 0, QUndoCommand* parent = 0) : QUndoCommand(parent) { 190 this->deck = deck; 191 } 192 //const QPointer<Deck> getDeck() const { return deck; } 193 protected: 194 QPointer<Deck> deck; 195 }; 196 197 /** 166 198 * Lauter schoene UndoCommands 167 199 **/ 168 class DeckAppendCard : public QUndoCommand {169 public: 170 DeckAppendCard(Deck* deck, Card* card, QUndoCommand* parent = 0) : QUndoCommand(parent) {200 class DeckAppendCard : public DeckUndoCommand { 201 public: 202 DeckAppendCard(Deck* deck, Card* card, QUndoCommand* parent = 0) : DeckUndoCommand(deck, parent) { 171 203 this->deck = deck; 172 204 this->card = card; … … 180 212 }; 181 213 182 class DeckModifyCard : public QUndoCommand { 183 public: 184 DeckModifyCard(DeckIndex& position, Card new_content, QUndoCommand* parent=0) 185 : QUndoCommand(parent), position(position), new_content(new_content) { 214 class DeckModifyCard : public DeckUndoCommand { 215 public: 216 DeckModifyCard(Deck* deck, DeckIndex& position, Card new_content, QUndoCommand* parent=0) 217 : DeckUndoCommand(deck, parent), position(position), new_content(new_content) { 218 position.assertDeck(deck); 219 Q_ASSERT(this->deck); 220 186 221 // alten Inhalt irgendwie sichern 187 222 old_content = *position.getCard(); 188 223 setText(position.getDeck()->tr("Changed contents of card").arg(position)); 189 224 } 190 void undo() { position.getDeck()->cards[position] = old_content; } 191 void redo() { position.getDeck()->cards[position] = new_content; } 225 void undo() { 226 position.getDeck()->cards[position] = old_content; 227 deck->emitChanged(position, position); 228 } 229 void redo() { 230 position.getDeck()->cards[position] = new_content; 231 deck->emitChanged(position, position); 232 } 192 233 private: 193 234 DeckIndex position;
Note: See TracChangeset
for help on using the changeset viewer.