mirror of
				https://github.com/subsurface/subsurface.git
				synced 2025-02-19 22:16:15 +00:00 
			
		
		
		
	core: make owning pointers a top-level features
The undo-code uses owning pointers based on std::unique_ptr to manage lifetime of C-objects. Since these are generally useful, move them from the undo-code to the core-code. In fact, this eliminates one instance of code duplication. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
		
							parent
							
								
									5b1557ccb1
								
							
						
					
					
						commit
						c5d6e0f44f
					
				
					 7 changed files with 50 additions and 31 deletions
				
			
		|  | @ -30,8 +30,8 @@ void clear();				// Reset the undo stack. Delete all commands. | |||
| void setClean();			// Call after save - this marks a state where no changes need to be saved.
 | ||||
| bool isClean();				// Any changes need to be saved?
 | ||||
| QAction *undoAction(QObject *parent);	// Create an undo action.
 | ||||
| QAction *redoAction(QObject *parent);	// Create an redo action.
 | ||||
| QString changesMade();			// return a string with the texts from all commands on the undo stack -> for commit message
 | ||||
| QAction *redoAction(QObject *parent);	// Create a redo action.
 | ||||
| QString changesMade();			// Return a string with the texts from all commands on the undo stack -> for commit message.
 | ||||
| bool placingCommand();			// Currently executing a new command -> might not have to update the field the user just edited.
 | ||||
| 
 | ||||
| // 2) Dive-list related commands
 | ||||
|  |  | |||
|  | @ -7,6 +7,7 @@ | |||
| #include "core/divesite.h" | ||||
| #include "core/trip.h" | ||||
| #include "core/dive.h" | ||||
| #include "core/owning_ptrs.h" | ||||
| 
 | ||||
| #include <QUndoCommand> | ||||
| #include <QCoreApplication>	// For Q_DECLARE_TR_FUNCTIONS | ||||
|  | @ -153,26 +154,6 @@ QVector<T> stdToQt(const std::vector<T> &v) | |||
| // We put everything in a namespace, so that we can shorten names without polluting the global namespace
 | ||||
| namespace Command { | ||||
| 
 | ||||
| // Classes used to automatically call the appropriate free_*() function for owning pointers that go out of scope.
 | ||||
| struct DiveDeleter { | ||||
| 	void operator()(dive *d) { free_dive(d); } | ||||
| }; | ||||
| struct TripDeleter { | ||||
| 	void operator()(dive_trip *t) { free_trip(t); } | ||||
| }; | ||||
| struct DiveSiteDeleter { | ||||
| 	void operator()(dive_site *ds) { free_dive_site(ds); } | ||||
| }; | ||||
| struct EventDeleter { | ||||
| 	void operator()(event *ev) { free(ev); } | ||||
| }; | ||||
| 
 | ||||
| // Owning pointers to dive, dive_trip, dive_site and event objects.
 | ||||
| typedef std::unique_ptr<dive, DiveDeleter> OwningDivePtr; | ||||
| typedef std::unique_ptr<dive_trip, TripDeleter> OwningTripPtr; | ||||
| typedef std::unique_ptr<dive_site, DiveSiteDeleter> OwningDiveSitePtr; | ||||
| typedef std::unique_ptr<event, EventDeleter> OwningEventPtr; | ||||
| 
 | ||||
| // This is the base class of all commands.
 | ||||
| // It defines the Qt-translation functions
 | ||||
| class Base : public QUndoCommand { | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue