initial commit
This commit is contained in:
@@ -75,6 +75,18 @@ void NodeGraph::childEvent(QChildEvent *event)
|
||||
emit NodeRemoved(node);
|
||||
emit node->RemovedFromGraph(this);
|
||||
|
||||
for (auto it=position_map_.begin(); it!=position_map_.end(); it++) {
|
||||
PositionMap &map = it.value();
|
||||
for (auto jt=map.begin(); jt!=map.end(); ) {
|
||||
if (jt.key() == node) {
|
||||
jt = map.erase(jt);
|
||||
emit NodePositionRemoved(node, it.key());
|
||||
} else {
|
||||
jt++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -63,6 +63,39 @@ public:
|
||||
return default_nodes_;
|
||||
}
|
||||
|
||||
bool NodeMapContainsNode(Node* node, void* relative) const
|
||||
{
|
||||
return position_map_.value(relative).contains(node);
|
||||
}
|
||||
|
||||
QPointF GetNodePosition(Node* node, void* relative)
|
||||
{
|
||||
return position_map_.value(relative).value(node);
|
||||
}
|
||||
|
||||
void SetNodePosition(Node* node, void* relative, const QPointF& pos)
|
||||
{
|
||||
position_map_[relative].insert(node, pos);
|
||||
emit NodePositionAdded(node, relative, pos);
|
||||
}
|
||||
|
||||
void RemoveNodePosition(Node* node, void* relative)
|
||||
{
|
||||
PositionMap& map = position_map_[relative];
|
||||
map.remove(node);
|
||||
if (map.isEmpty()) {
|
||||
position_map_.remove(relative);
|
||||
}
|
||||
emit NodePositionRemoved(node, relative);;
|
||||
}
|
||||
|
||||
using PositionMap = QMap<Node*, QPointF>;
|
||||
|
||||
const PositionMap &GetNodesForRelative(void *relative)
|
||||
{
|
||||
return position_map_[relative];
|
||||
}
|
||||
|
||||
signals:
|
||||
/**
|
||||
* @brief Signal emitted when a Node is added to the graph
|
||||
@@ -80,6 +113,10 @@ signals:
|
||||
|
||||
void ValueChanged(const NodeInput& input);
|
||||
|
||||
void NodePositionAdded(Node *node, void *relative, const QPointF &position);
|
||||
|
||||
void NodePositionRemoved(Node *node, void *relative);
|
||||
|
||||
protected:
|
||||
void AddDefaultNode(Node* n)
|
||||
{
|
||||
@@ -93,6 +130,10 @@ private:
|
||||
|
||||
QVector<Node*> default_nodes_;
|
||||
|
||||
QMap<void *, PositionMap> position_map_;
|
||||
|
||||
PositionMap root_position_map_;
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
+68
-48
@@ -91,20 +91,6 @@ void Node::Load(QXmlStreamReader *reader, XMLNodeData& xml_node_data, uint versi
|
||||
LoadInput(reader, xml_node_data, cancelled);
|
||||
} else if (reader->name() == QStringLiteral("ptr")) {
|
||||
xml_node_data.node_ptrs.insert(reader->readElementText().toULongLong(), this);
|
||||
} else if (reader->name() == QStringLiteral("pos")) {
|
||||
QPointF p;
|
||||
|
||||
while (XMLReadNextStartElement(reader)) {
|
||||
if (reader->name() == QStringLiteral("x")) {
|
||||
p.setX(reader->readElementText().toDouble());
|
||||
} else if (reader->name() == QStringLiteral("y")) {
|
||||
p.setY(reader->readElementText().toDouble());
|
||||
} else {
|
||||
reader->skipCurrentElement();
|
||||
}
|
||||
}
|
||||
|
||||
SetPosition(p);
|
||||
} else if (reader->name() == QStringLiteral("label")) {
|
||||
SetLabel(reader->readElementText());
|
||||
} else if (reader->name() == QStringLiteral("color")) {
|
||||
@@ -166,11 +152,6 @@ void Node::Save(QXmlStreamWriter *writer) const
|
||||
{
|
||||
writer->writeTextElement(QStringLiteral("ptr"), QString::number(reinterpret_cast<quintptr>(this)));
|
||||
|
||||
writer->writeStartElement(QStringLiteral("pos"));
|
||||
writer->writeTextElement(QStringLiteral("x"), QString::number(GetPosition().x()));
|
||||
writer->writeTextElement(QStringLiteral("y"), QString::number(GetPosition().y()));
|
||||
writer->writeEndElement(); // pos
|
||||
|
||||
writer->writeTextElement(QStringLiteral("label"), GetLabel());
|
||||
writer->writeTextElement(QStringLiteral("color"), QString::number(override_color_));
|
||||
|
||||
@@ -1483,7 +1464,6 @@ void Node::CopyInputs(const Node *source, Node *destination, bool include_connec
|
||||
CopyInput(source, destination, input, include_connections, true);
|
||||
}
|
||||
|
||||
destination->SetPosition(source->GetPosition());
|
||||
destination->SetLabel(source->GetLabel());
|
||||
destination->SetOverrideColor(source->GetOverrideColor());
|
||||
}
|
||||
@@ -1832,29 +1812,6 @@ QVariant Node::PtrToValue(void *ptr)
|
||||
return reinterpret_cast<quintptr>(ptr);
|
||||
}
|
||||
|
||||
const QPointF &Node::GetPosition() const
|
||||
{
|
||||
return position_;
|
||||
}
|
||||
|
||||
void Node::SetPosition(const QPointF &pos, bool move_dependencies_relatively_too)
|
||||
{
|
||||
QPointF old_pos = position_;
|
||||
|
||||
position_ = pos;
|
||||
|
||||
emit PositionChanged(position_);
|
||||
|
||||
if (move_dependencies_relatively_too) {
|
||||
QPointF difference = pos - old_pos;
|
||||
|
||||
for (auto it=input_connections_.cbegin(); it!=input_connections_.cend(); it++) {
|
||||
Node* c = it->second.node();
|
||||
c->SetPosition(c->GetPosition() + difference, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Node::ParameterValueChanged(const QString& input, int element, const TimeRange& range)
|
||||
{
|
||||
UpdateLastChangedTime();
|
||||
@@ -2303,7 +2260,7 @@ void NodeSetPositionAndShiftSurroundingsCommand::redo()
|
||||
{
|
||||
if (commands_.isEmpty()) {
|
||||
// Move first node
|
||||
NodeSetPositionCommand* set_pos_command = new NodeSetPositionCommand(node_, position_, move_dependencies_);
|
||||
NodeSetPositionCommand* set_pos_command = new NodeSetPositionCommand(node_, relative_, position_, move_dependencies_);
|
||||
set_pos_command->redo();
|
||||
commands_.append(set_pos_command);
|
||||
|
||||
@@ -2312,18 +2269,19 @@ void NodeSetPositionAndShiftSurroundingsCommand::redo()
|
||||
|
||||
// Start moving other nodes
|
||||
foreach (Node* surrounding, node_->parent()->nodes()) {
|
||||
if (bounding_rect.contains(surrounding->GetPosition()) && surrounding != node_) {
|
||||
QPointF new_pos = surrounding->GetPosition();
|
||||
QPointF surrounding_position = node_->parent()->GetNodePosition(surrounding, relative_);
|
||||
if (bounding_rect.contains(surrounding_position) && surrounding != node_) {
|
||||
QPointF new_pos = surrounding_position;
|
||||
|
||||
qreal move_rate = 0.50;
|
||||
|
||||
if (surrounding->GetPosition().y() < position_.y()) {
|
||||
if (surrounding_position.y() < position_.y()) {
|
||||
move_rate = -move_rate;
|
||||
}
|
||||
|
||||
new_pos.setY(new_pos.y() + move_rate);
|
||||
|
||||
auto sur_command = new NodeSetPositionAndShiftSurroundingsCommand(surrounding, new_pos, true);
|
||||
auto sur_command = new NodeSetPositionAndShiftSurroundingsCommand(surrounding, relative_, new_pos, true);
|
||||
sur_command->redo();
|
||||
commands_.append(sur_command);
|
||||
}
|
||||
@@ -2335,4 +2293,66 @@ void NodeSetPositionAndShiftSurroundingsCommand::redo()
|
||||
}
|
||||
}
|
||||
|
||||
void NodeSetPositionCommand::redo()
|
||||
{
|
||||
NodeGraph* graph = node_->parent();
|
||||
if (!(added_ = !graph->NodeMapContainsNode(node_, relevant_))) {
|
||||
old_pos_ = graph->GetNodePosition(node_, relevant_);
|
||||
}
|
||||
graph->SetNodePosition(node_, relevant_, pos_);
|
||||
}
|
||||
|
||||
void NodeSetPositionCommand::undo()
|
||||
{
|
||||
NodeGraph* graph = node_->parent();
|
||||
if (added_) {
|
||||
graph->RemoveNodePosition(node_, relevant_);
|
||||
} else {
|
||||
graph->SetNodePosition(node_, relevant_, old_pos_);
|
||||
}
|
||||
}
|
||||
|
||||
void NodeSetPositionAsChildCommand::redo()
|
||||
{
|
||||
if (!sub_command_) {
|
||||
// Calculate position of node
|
||||
NodeGraph *graph = parent_->parent();
|
||||
QPointF pos = graph->GetNodePosition(parent_, relative_);
|
||||
|
||||
// This is a dependency, so we'll place it one X before
|
||||
pos.setX(pos.x() - 1);
|
||||
|
||||
// The Y will be calculated using the index and child count
|
||||
pos.setY(pos.y() - (double(child_count_)*0.5) + this_index_ + 0.5);
|
||||
|
||||
sub_command_ = new MultiUndoCommand();
|
||||
if (shift_surroundings_) {
|
||||
if (relative_) {
|
||||
sub_command_->add_child(new NodeSetPositionAndShiftSurroundingsCommand(node_, relative_, pos, true));
|
||||
}
|
||||
sub_command_->add_child(new NodeSetPositionAndShiftSurroundingsCommand(node_, nullptr, pos, true));
|
||||
} else {
|
||||
if (relative_) {
|
||||
sub_command_->add_child(new NodeSetPositionCommand(node_, relative_, pos, true));
|
||||
}
|
||||
sub_command_->add_child(new NodeSetPositionCommand(node_, nullptr, pos, true));
|
||||
}
|
||||
}
|
||||
|
||||
sub_command_->redo();
|
||||
}
|
||||
|
||||
void NodeSetPositionToOffsetOfAnotherNodeCommand::redo()
|
||||
{
|
||||
NodeGraph *graph = node_->parent();
|
||||
old_pos_ = graph->GetNodePosition(node_, relative_);
|
||||
graph->SetNodePosition(node_, relative_, graph->GetNodePosition(other_node_, relative_) + offset_);
|
||||
}
|
||||
|
||||
void NodeSetPositionToOffsetOfAnotherNodeCommand::undo()
|
||||
{
|
||||
NodeGraph *graph = node_->parent();
|
||||
graph->SetNodePosition(node_, relative_, old_pos_);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+26
-59
@@ -718,10 +718,6 @@ public:
|
||||
*/
|
||||
virtual NodeValueTable Value(const QString &output, NodeValueDatabase& value) const;
|
||||
|
||||
const QPointF& GetPosition() const;
|
||||
|
||||
void SetPosition(const QPointF& pos, bool move_dependencies_relatively_too = false);
|
||||
|
||||
virtual bool HasGizmos() const;
|
||||
|
||||
virtual void DrawGizmos(NodeValueDatabase& db, QPainter* p);
|
||||
@@ -1180,11 +1176,6 @@ private:
|
||||
*/
|
||||
bool can_be_deleted_;
|
||||
|
||||
/**
|
||||
* @brief UI position for NodeViews
|
||||
*/
|
||||
QPointF position_;
|
||||
|
||||
/**
|
||||
* @brief Custom user label for node
|
||||
*/
|
||||
@@ -1312,35 +1303,29 @@ using NodePtr = std::shared_ptr<Node>;
|
||||
class NodeSetPositionCommand : public UndoCommand
|
||||
{
|
||||
public:
|
||||
NodeSetPositionCommand(Node* node, const QPointF& position, bool move_dependencies_relatively) :
|
||||
node_(node),
|
||||
new_pos_(position),
|
||||
move_deps_(move_dependencies_relatively)
|
||||
NodeSetPositionCommand(Node* node, void* relevant, const QPointF& pos, bool move_dependencies_relatively)
|
||||
{
|
||||
node_ = node;
|
||||
relevant_ = relevant;
|
||||
pos_ = pos;
|
||||
move_deps_ = move_dependencies_relatively;
|
||||
}
|
||||
|
||||
virtual Project * GetRelevantProject() const override
|
||||
virtual Project* GetRelevantProject() const override
|
||||
{
|
||||
return node_->project();
|
||||
}
|
||||
|
||||
virtual void redo() override
|
||||
{
|
||||
old_pos_ = node_->GetPosition();
|
||||
node_->SetPosition(new_pos_, move_deps_);
|
||||
}
|
||||
virtual void redo() override;
|
||||
|
||||
virtual void undo() override
|
||||
{
|
||||
node_->SetPosition(old_pos_, move_deps_);
|
||||
}
|
||||
virtual void undo() override;
|
||||
|
||||
private:
|
||||
Node* node_;
|
||||
|
||||
QPointF new_pos_;
|
||||
void* relevant_;
|
||||
QPointF pos_;
|
||||
QPointF old_pos_;
|
||||
|
||||
bool added_;
|
||||
bool move_deps_;
|
||||
|
||||
};
|
||||
@@ -1348,8 +1333,9 @@ private:
|
||||
class NodeSetPositionAndShiftSurroundingsCommand : public UndoCommand
|
||||
{
|
||||
public:
|
||||
NodeSetPositionAndShiftSurroundingsCommand(Node* node, const QPointF& pos, bool move_dependencies_relatively) :
|
||||
NodeSetPositionAndShiftSurroundingsCommand(Node* node, void *relative, const QPointF& pos, bool move_dependencies_relatively) :
|
||||
node_(node),
|
||||
relative_(relative),
|
||||
position_(pos),
|
||||
move_dependencies_(move_dependencies_relatively)
|
||||
{}
|
||||
@@ -1376,6 +1362,8 @@ public:
|
||||
private:
|
||||
Node* node_;
|
||||
|
||||
void *relative_;
|
||||
|
||||
QPointF position_;
|
||||
|
||||
bool move_dependencies_;
|
||||
@@ -1387,9 +1375,10 @@ private:
|
||||
class NodeSetPositionAsChildCommand : public UndoCommand
|
||||
{
|
||||
public:
|
||||
NodeSetPositionAsChildCommand(Node* node, Node* parent, int this_index, int child_count, bool shift_surroundings) :
|
||||
NodeSetPositionAsChildCommand(Node* node, Node* parent, void *relative, int this_index, int child_count, bool shift_surroundings) :
|
||||
node_(node),
|
||||
parent_(parent),
|
||||
relative_(relative),
|
||||
this_index_(this_index),
|
||||
child_count_(child_count),
|
||||
shift_surroundings_(shift_surroundings),
|
||||
@@ -1407,27 +1396,7 @@ public:
|
||||
return node_->project();
|
||||
}
|
||||
|
||||
virtual void redo() override
|
||||
{
|
||||
if (!sub_command_) {
|
||||
// Calculate position of node
|
||||
QPointF pos = parent_->GetPosition();
|
||||
|
||||
// This is a dependency, so we'll place it one X before
|
||||
pos.setX(pos.x() - 1);
|
||||
|
||||
// The Y will be calculated using the index and child count
|
||||
pos.setY(pos.y() - (double(child_count_)*0.5) + this_index_ + 0.5);
|
||||
|
||||
if (shift_surroundings_) {
|
||||
sub_command_ = new NodeSetPositionAndShiftSurroundingsCommand(node_, pos, true);
|
||||
} else {
|
||||
sub_command_ = new NodeSetPositionCommand(node_, pos, true);
|
||||
}
|
||||
}
|
||||
|
||||
sub_command_->redo();
|
||||
}
|
||||
virtual void redo() override;
|
||||
|
||||
virtual void undo() override
|
||||
{
|
||||
@@ -1437,22 +1406,24 @@ public:
|
||||
private:
|
||||
Node* node_;
|
||||
Node* parent_;
|
||||
void *relative_;
|
||||
|
||||
int this_index_;
|
||||
int child_count_;
|
||||
|
||||
bool shift_surroundings_;
|
||||
|
||||
UndoCommand* sub_command_;
|
||||
MultiUndoCommand* sub_command_;
|
||||
|
||||
};
|
||||
|
||||
class NodeSetPositionToOffsetOfAnotherNodeCommand : public UndoCommand
|
||||
{
|
||||
public:
|
||||
NodeSetPositionToOffsetOfAnotherNodeCommand(Node* node, Node* other_node, const QPointF& offset) :
|
||||
NodeSetPositionToOffsetOfAnotherNodeCommand(Node* node, Node* other_node, void *relative, const QPointF& offset) :
|
||||
node_(node),
|
||||
other_node_(other_node),
|
||||
relative_(relative),
|
||||
offset_(offset)
|
||||
{}
|
||||
|
||||
@@ -1461,20 +1432,16 @@ public:
|
||||
return node_->project();
|
||||
}
|
||||
|
||||
virtual void redo() override
|
||||
{
|
||||
node_->SetPosition(other_node_->GetPosition() + offset_);
|
||||
}
|
||||
virtual void redo() override;
|
||||
|
||||
virtual void undo() override
|
||||
{
|
||||
node_->SetPosition(other_node_->GetPosition() - offset_);
|
||||
}
|
||||
virtual void undo() override;
|
||||
|
||||
private:
|
||||
Node* node_;
|
||||
Node* other_node_;
|
||||
void *relative_;
|
||||
QPointF offset_;
|
||||
QPointF old_pos_;
|
||||
|
||||
};
|
||||
|
||||
|
||||
@@ -137,9 +137,8 @@ void FolderAddChild::redo()
|
||||
Node::ConnectEdge(child_, NodeInput(folder_, Folder::kChildInput, array_index));
|
||||
|
||||
if (autoposition_) {
|
||||
old_position_ = child_->GetPosition();
|
||||
if (!position_command_) {
|
||||
position_command_ = new NodeSetPositionAsChildCommand(child_, folder_, array_index, array_index+1, true);
|
||||
position_command_ = new NodeSetPositionAsChildCommand(child_, folder_, folder_->project(), array_index, array_index+1, true);
|
||||
}
|
||||
position_command_->redo();
|
||||
}
|
||||
|
||||
@@ -180,8 +180,6 @@ private:
|
||||
|
||||
bool autoposition_;
|
||||
|
||||
QPointF old_position_;
|
||||
|
||||
NodeSetPositionAsChildCommand* position_command_;
|
||||
|
||||
};
|
||||
|
||||
@@ -42,14 +42,14 @@ Project::Project() :
|
||||
// Adds a color manager "node" to this project so that it synchronizes
|
||||
color_manager_ = new ColorManager();
|
||||
color_manager_->setParent(this);
|
||||
color_manager_->SetPosition(QPointF(1, 0));
|
||||
SetNodePosition(color_manager_, this, QPointF(1, 0));
|
||||
color_manager_->SetCanBeDeleted(false);
|
||||
AddDefaultNode(color_manager_);
|
||||
|
||||
// Same with project settings
|
||||
settings_ = new ProjectSettingsNode();
|
||||
settings_->setParent(this);
|
||||
settings_->SetPosition(QPointF(2, 0));
|
||||
SetNodePosition(settings_, this, QPointF(2, 0));
|
||||
settings_->SetCanBeDeleted(false);
|
||||
AddDefaultNode(settings_);
|
||||
|
||||
@@ -58,6 +58,7 @@ Project::Project() :
|
||||
root_->setParent(this);
|
||||
root_->SetLabel(tr("Root"));
|
||||
root_->SetCanBeDeleted(false);
|
||||
SetNodePosition(root_, this, QPointF(0, 0));
|
||||
|
||||
connect(color_manager(), &ColorManager::ValueChanged,
|
||||
this, &Project::ColorManagerValueChanged);
|
||||
|
||||
Reference in New Issue
Block a user