global: made every user action set a project "modified" state that will prevent

the main window from closing instantly
This commit is contained in:
itsmattkc
2020-03-03 14:33:45 +11:00
parent 0f5cd40c45
commit baf3fbde05
25 changed files with 377 additions and 238 deletions
+17 -17
View File
@@ -1,7 +1,7 @@
#include "nodeviewundo.h"
NodeEdgeAddCommand::NodeEdgeAddCommand(NodeOutput *output, NodeInput *input, QUndoCommand *parent) :
QUndoCommand(parent),
UndoCommand(parent),
output_(output),
input_(input),
old_edge_(nullptr),
@@ -9,7 +9,7 @@ NodeEdgeAddCommand::NodeEdgeAddCommand(NodeOutput *output, NodeInput *input, QUn
{
}
void NodeEdgeAddCommand::redo()
void NodeEdgeAddCommand::redo_internal()
{
if (done_) {
return;
@@ -22,7 +22,7 @@ void NodeEdgeAddCommand::redo()
done_ = true;
}
void NodeEdgeAddCommand::undo()
void NodeEdgeAddCommand::undo_internal()
{
if (!done_) {
return;
@@ -38,7 +38,7 @@ void NodeEdgeAddCommand::undo()
}
NodeEdgeRemoveCommand::NodeEdgeRemoveCommand(NodeOutput *output, NodeInput *input, QUndoCommand *parent) :
QUndoCommand(parent),
UndoCommand(parent),
output_(output),
input_(input),
done_(false)
@@ -46,14 +46,14 @@ NodeEdgeRemoveCommand::NodeEdgeRemoveCommand(NodeOutput *output, NodeInput *inpu
}
NodeEdgeRemoveCommand::NodeEdgeRemoveCommand(NodeEdgePtr edge, QUndoCommand *parent) :
QUndoCommand(parent),
UndoCommand(parent),
output_(edge->output()),
input_(edge->input()),
done_(false)
{
}
void NodeEdgeRemoveCommand::redo()
void NodeEdgeRemoveCommand::redo_internal()
{
if (done_) {
return;
@@ -63,7 +63,7 @@ void NodeEdgeRemoveCommand::redo()
done_ = true;
}
void NodeEdgeRemoveCommand::undo()
void NodeEdgeRemoveCommand::undo_internal()
{
if (!done_) {
return;
@@ -74,7 +74,7 @@ void NodeEdgeRemoveCommand::undo()
}
NodeAddCommand::NodeAddCommand(NodeGraph *graph, Node *node, QUndoCommand *parent) :
QUndoCommand(parent),
UndoCommand(parent),
graph_(graph),
node_(node)
{
@@ -82,24 +82,24 @@ NodeAddCommand::NodeAddCommand(NodeGraph *graph, Node *node, QUndoCommand *paren
node_->setParent(&memory_manager_);
}
void NodeAddCommand::redo()
void NodeAddCommand::redo_internal()
{
graph_->AddNode(node_);
}
void NodeAddCommand::undo()
void NodeAddCommand::undo_internal()
{
graph_->TakeNode(node_, &memory_manager_);
}
NodeRemoveCommand::NodeRemoveCommand(NodeGraph *graph, const QList<Node *> &nodes, QUndoCommand *parent) :
QUndoCommand(parent),
UndoCommand(parent),
graph_(graph),
nodes_(nodes)
{
}
void NodeRemoveCommand::redo()
void NodeRemoveCommand::redo_internal()
{
// Cache edges for undoing
foreach (Node* n, nodes_) {
@@ -119,7 +119,7 @@ void NodeRemoveCommand::redo()
}
}
void NodeRemoveCommand::undo()
void NodeRemoveCommand::undo_internal()
{
// Re-add nodes to graph
foreach (Node* n, nodes_) {
@@ -135,7 +135,7 @@ void NodeRemoveCommand::undo()
}
NodeRemoveWithExclusiveDeps::NodeRemoveWithExclusiveDeps(NodeGraph *graph, Node *node, QUndoCommand *parent) :
QUndoCommand(parent)
UndoCommand(parent)
{
QList<Node*> node_and_its_deps;
node_and_its_deps.append(node);
@@ -145,7 +145,7 @@ NodeRemoveWithExclusiveDeps::NodeRemoveWithExclusiveDeps(NodeGraph *graph, Node
}
NodeCopyInputsCommand::NodeCopyInputsCommand(Node *src, Node *dest, bool include_connections, QUndoCommand *parent) :
QUndoCommand(parent),
UndoCommand(parent),
src_(src),
dest_(dest),
include_connections_(include_connections)
@@ -153,14 +153,14 @@ NodeCopyInputsCommand::NodeCopyInputsCommand(Node *src, Node *dest, bool include
}
NodeCopyInputsCommand::NodeCopyInputsCommand(Node *src, Node *dest, QUndoCommand *parent) :
QUndoCommand(parent),
UndoCommand(parent),
src_(src),
dest_(dest),
include_connections_(true)
{
}
void NodeCopyInputsCommand::redo()
void NodeCopyInputsCommand::redo_internal()
{
Node::CopyInputs(src_, dest_, include_connections_);
}
+21 -15
View File
@@ -6,18 +6,20 @@
#include "node/graph.h"
#include "node/node.h"
#include "nodeviewitem.h"
#include "undo/undocommand.h"
/**
* @brief An undoable commnd for connecting two NodeParams together
*
* Can be considered a QUndoCommand wrapper for NodeParam::ConnectEdge()/
*/
class NodeEdgeAddCommand : public QUndoCommand {
class NodeEdgeAddCommand : public UndoCommand {
public:
NodeEdgeAddCommand(NodeOutput* output, NodeInput* input, QUndoCommand* parent = nullptr);
virtual void redo() override;
virtual void undo() override;
protected:
virtual void redo_internal() override;
virtual void undo_internal() override;
private:
NodeOutput* output_;
@@ -33,13 +35,14 @@ private:
*
* Can be considered a QUndoCommand wrapper for NodeParam::DisonnectEdge()/
*/
class NodeEdgeRemoveCommand : public QUndoCommand {
class NodeEdgeRemoveCommand : public UndoCommand {
public:
NodeEdgeRemoveCommand(NodeOutput* output, NodeInput* input, QUndoCommand* parent = nullptr);
NodeEdgeRemoveCommand(NodeEdgePtr edge, QUndoCommand* parent = nullptr);
virtual void redo() override;
virtual void undo() override;
protected:
virtual void redo_internal() override;
virtual void undo_internal() override;
private:
NodeOutput* output_;
@@ -48,12 +51,13 @@ private:
bool done_;
};
class NodeAddCommand : public QUndoCommand {
class NodeAddCommand : public UndoCommand {
public:
NodeAddCommand(NodeGraph* graph, Node* node, QUndoCommand* parent = nullptr);
virtual void redo() override;
virtual void undo() override;
protected:
virtual void redo_internal() override;
virtual void undo_internal() override;
private:
QObject memory_manager_;
@@ -62,14 +66,15 @@ private:
Node* node_;
};
class NodeRemoveCommand : public QUndoCommand {
class NodeRemoveCommand : public UndoCommand {
public:
NodeRemoveCommand(NodeGraph* graph,
const QList<Node*>& nodes,
QUndoCommand* parent = nullptr);
virtual void redo() override;
virtual void undo() override;
protected:
virtual void redo_internal() override;
virtual void undo_internal() override;
private:
QObject memory_manager_;
@@ -79,7 +84,7 @@ private:
QList<NodeEdgePtr> edges_;
};
class NodeRemoveWithExclusiveDeps : public QUndoCommand {
class NodeRemoveWithExclusiveDeps : public UndoCommand {
public:
NodeRemoveWithExclusiveDeps(NodeGraph* graph,
Node* node,
@@ -89,7 +94,7 @@ private:
NodeRemoveCommand* remove_command_;
};
class NodeCopyInputsCommand : public QUndoCommand {
class NodeCopyInputsCommand : public UndoCommand {
public:
NodeCopyInputsCommand(Node* src,
Node* dest,
@@ -100,7 +105,8 @@ public:
Node* dest,
QUndoCommand* parent = nullptr);
virtual void redo() override;
protected:
virtual void redo_internal() override;
private:
Node* src_;