-
Notifications
You must be signed in to change notification settings - Fork 843
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added duplicate selection (CTRL+D), undo and redo (CTRL+Z/Y) with scene history. #133
Open
ReubenJCarter
wants to merge
37
commits into
paceholder:master
Choose a base branch
from
ScanLAB-Projects:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 16 commits
Commits
Show all changes
37 commits
Select commit
Hold shift + click to select a range
27433e0
Added duplicate action to the flow view. Removed shadow effect from n…
4b90d7d
Added duplicating connections, there is a bug to handle connections t…
c508028
added CTRL+D key sequence for duplicate
facd31b
Fixed node delete pointer error
a92ba58
Added very simple Undo Redo system
e42fe23
Added action context WidgetWithChildrenShortcut. Added duplication of…
b5f7310
added updating history for node movement
09a2681
Merge branch 'master' of https://github.com/paceholder/nodeeditor
d649c82
Added Fix for Mingw "invalid initialization of non-const reference of…
c073764
added setViewportUpdateMode(QGraphicsView::FullViewportUpdate); to fl…
243c382
Turn on/off the background grid render based on scale in viewport for…
7215528
Added the ability to set the tool tip for each node
7631c27
Merge branch 'master' of https://github.com/paceholder/nodeeditor
477d904
Made the signal and slot compatible for the setToolTip signal in the …
516ce86
Merge branch 'master' of https://github.com/paceholder/nodeeditor
bc9c58f
Added copy/paste between sheets
a0adb17
Started groups, added anchors, fixed position of nodes when pasting
jacquespillet 02c5c7d
Added getter for history index, added resizing nodes
jacquespillet ddbe4a8
Started groups
jacquespillet 4c2812f
continued groups
jacquespillet d341631
added deleted node
jacquespillet f6fb7b8
Added node templates
jacquespillet 0eb037a
Fixes on groups
jacquespillet b91389b
Added snapping
jacquespillet 51804f1
Added Collapsable group
jacquespillet d198287
Update view on geometry
jacquespillet a0318ec
Loading optimizations
jacquespillet 54b5cf9
Optimized loading
jacquespillet 410c823
started undoRedo
jacquespillet 1c95c67
Merge branch 'master' of https://github.com/ScanLAB-Projects/nodeeditor
jacquespillet 09d7926
progress on undo/redo system
jacquespillet 8b041d4
UndoRedo for paste, duplicate and create connection
jacquespillet 54c1f5b
fixed undo redo
jacquespillet c070645
added gotonode function
jacquespillet f5a177f
added go to node id
jacquespillet 7e89261
added input colour to node
jacquespillet 6f8c72d
fix crash
tomscanlab File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
*.py | ||
*.pyc | ||
CMakeLists.txt.user | ||
/build |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -60,6 +60,8 @@ class NODE_EDITOR_PUBLIC NodeDataModel | |
/// Function creates instances of a model stored in DataModelRegistry | ||
virtual std::unique_ptr<NodeDataModel> | ||
clone() const = 0; | ||
|
||
void setToolTipText(QString toolTipText); | ||
|
||
public: | ||
|
||
|
@@ -126,6 +128,8 @@ class NODE_EDITOR_PUBLIC NodeDataModel | |
virtual | ||
NodePainterDelegate* painterDelegate() const { return nullptr; } | ||
|
||
QString toolTipText(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should be const and inline as other getters |
||
|
||
signals: | ||
|
||
void | ||
|
@@ -139,9 +143,14 @@ class NODE_EDITOR_PUBLIC NodeDataModel | |
|
||
void | ||
computingFinished(); | ||
|
||
void setToolTipTextSignal(QString text); | ||
|
||
|
||
private: | ||
|
||
QString _toolTipText; | ||
|
||
NodeStyle _nodeStyle; | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -42,6 +42,15 @@ FlowScene(std::shared_ptr<DataModelRegistry> registry) | |
: _registry(registry) | ||
{ | ||
setItemIndexMethod(QGraphicsScene::NoIndex); | ||
|
||
ResetHistory(); | ||
UpdateHistory(); | ||
|
||
auto UpdateLamda = [this](Node& n, const QPointF& p) | ||
{ | ||
UpdateHistory(); | ||
}; | ||
connect(this, &FlowScene::nodeMoveFinished, this, UpdateLamda); | ||
} | ||
|
||
|
||
|
@@ -102,7 +111,7 @@ createConnection(Node& nodeIn, | |
_connections[connection->id()] = connection; | ||
|
||
connectionCreated(*connection); | ||
|
||
return connection; | ||
} | ||
|
||
|
@@ -123,6 +132,20 @@ restoreConnection(QJsonObject const &connectionJson) | |
return createConnection(*nodeIn, portIndexIn, *nodeOut, portIndexOut); | ||
} | ||
|
||
void FlowScene::pasteConnection(QJsonObject const &connectionJson, QUuid newIn, QUuid newOut) | ||
{ | ||
QUuid nodeInId = QUuid(connectionJson["in_id"].toString()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. unused nodeInId and nodeOutId |
||
QUuid nodeOutId = QUuid(connectionJson["out_id"].toString()); | ||
|
||
PortIndex portIndexIn = connectionJson["in_index"].toInt(); | ||
PortIndex portIndexOut = connectionJson["out_index"].toInt(); | ||
|
||
auto nodeIn = _nodes[newIn].get(); | ||
auto nodeOut = _nodes[newOut].get(); | ||
|
||
createConnection(*nodeIn, portIndexIn, *nodeOut, portIndexOut); | ||
} | ||
|
||
|
||
void | ||
FlowScene:: | ||
|
@@ -147,6 +170,7 @@ createNode(std::unique_ptr<NodeDataModel> && dataModel) | |
_nodes[node->id()] = std::move(node); | ||
|
||
nodeCreated(*nodePtr); | ||
|
||
return *nodePtr; | ||
} | ||
|
||
|
@@ -156,26 +180,46 @@ FlowScene:: | |
restoreNode(QJsonObject const& nodeJson) | ||
{ | ||
QString modelName = nodeJson["model"].toObject()["name"].toString(); | ||
|
||
auto dataModel = registry().create(modelName); | ||
|
||
if (!dataModel) | ||
throw std::logic_error(std::string("No registered model with name ") + | ||
modelName.toLocal8Bit().data()); | ||
|
||
auto node = std::make_unique<Node>(std::move(dataModel)); | ||
auto ngo = std::make_unique<NodeGraphicsObject>(*this, *node); | ||
node->setGraphicsObject(std::move(ngo)); | ||
|
||
node->restore(nodeJson); | ||
|
||
auto nodePtr = node.get(); | ||
_nodes[node->id()] = std::move(node); | ||
|
||
nodeCreated(*nodePtr); | ||
return *nodePtr; | ||
} | ||
|
||
QUuid FlowScene::pasteNode(QJsonObject &nodeJson) { | ||
QString modelName = nodeJson["model"].toObject()["name"].toString(); | ||
auto dataModel = registry().create(modelName); | ||
|
||
if (!dataModel) | ||
throw std::logic_error(std::string("No registered model with name ") + | ||
modelName.toLocal8Bit().data()); | ||
|
||
auto node = std::make_unique<Node>(std::move(dataModel)); | ||
auto ngo = std::make_unique<NodeGraphicsObject>(*this, *node); | ||
|
||
|
||
node->setGraphicsObject(std::move(ngo)); | ||
|
||
QUuid newId = QUuid::createUuid(); | ||
node->paste(nodeJson, newId); | ||
|
||
auto nodePtr = node.get(); | ||
_nodes[node->id()] = std::move(node); | ||
nodeCreated(*nodePtr); | ||
return newId; | ||
} | ||
|
||
|
||
|
||
void | ||
FlowScene:: | ||
|
@@ -491,6 +535,11 @@ saveToMemory() const | |
} | ||
|
||
|
||
void FlowScene::saveToClipBoard() | ||
{ | ||
|
||
} | ||
|
||
void | ||
FlowScene:: | ||
loadFromMemory(const QByteArray& data) | ||
|
@@ -510,8 +559,73 @@ loadFromMemory(const QByteArray& data) | |
{ | ||
restoreConnection(connectionJsonArray[i].toObject()); | ||
} | ||
|
||
|
||
} | ||
|
||
void FlowScene::Undo() | ||
{ | ||
std::cout << "Undo" << std::endl; | ||
if(historyInx > 1) | ||
{ | ||
writeToHistory = false; | ||
clearScene(); | ||
historyInx--; | ||
loadFromMemory(history[historyInx - 1].data); | ||
writeToHistory = true; | ||
} | ||
} | ||
|
||
void FlowScene::Redo() | ||
{ | ||
std::cout << "Redo" << std::endl; | ||
writeToHistory = false; | ||
if(historyInx < history.size()) | ||
{ | ||
std::cout << "historyInx:" << historyInx << " history.size():" << history.size() << std::endl; | ||
clearScene(); | ||
loadFromMemory(history[historyInx].data); | ||
historyInx++; | ||
} | ||
else | ||
{ | ||
std::cout << "Could not redo" << std::endl; | ||
} | ||
writeToHistory = true; | ||
} | ||
|
||
void FlowScene::UpdateHistory() | ||
{ | ||
if(writeToHistory) | ||
{ | ||
std::cout << "UpdateHistory" << std::endl; | ||
|
||
SceneHistory sh; | ||
sh.data = saveToMemory(); | ||
|
||
if(historyInx < history.size()) | ||
{ | ||
history.resize(historyInx); | ||
history.push_back(sh); | ||
} | ||
else | ||
{ | ||
history.push_back(sh); | ||
} | ||
|
||
historyInx++; | ||
} | ||
} | ||
|
||
void FlowScene::ResetHistory() | ||
{ | ||
historyInx = 0; | ||
writeToHistory = true; | ||
history.clear(); | ||
} | ||
|
||
|
||
|
||
|
||
//------------------------------------------------------------------------------ | ||
namespace QtNodes | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
make it const reference