QUndoStack set memory limit to commands
-
Hi,
I have QUndoStack to control my commands and everything is super, except limit to commands. Standard QUndoStack allows to set limit by number of commands, but I want to control commands memory using, at least as QCache with commands weight . Because, I have plots with delete and add commands, so it may take up a lot of memory.
Main question: in which way it would better to do - try to re-implement QUndoStack or maybe using another structure.
I saw similar question, but without answer:
https://forum.qt.io/topic/59506/remove-first-qundocommand-from-qundostack -
Okay, I implemented my own stack. Just add command setMaxWeight in bytes and add check in push() method to ensure enough weight available. If currentWeight is greater maxWeight, I started to delete command from bottom of the stack.
I used another abstract class for command, that inherits QUndoCOmmand and have custom virtual method:
size_t wieght() const;
And inherited my commands by that class