use nodes as context rather than void
This commit is contained in:
+1
-1
@@ -44,7 +44,7 @@ void NodeGraph::Clear()
|
||||
}
|
||||
}
|
||||
|
||||
qreal NodeGraph::GetNodeContextHeight(void *context)
|
||||
qreal NodeGraph::GetNodeContextHeight(Node *context)
|
||||
{
|
||||
const PositionMap &map = position_map_.value(context);
|
||||
|
||||
|
||||
+17
-17
@@ -63,39 +63,39 @@ public:
|
||||
return default_nodes_;
|
||||
}
|
||||
|
||||
bool NodeMapContainsNode(Node* node, void* relative) const
|
||||
bool NodeMapContainsNode(Node* node, Node* context) const
|
||||
{
|
||||
return position_map_.value(relative).contains(node);
|
||||
return position_map_.value(context).contains(node);
|
||||
}
|
||||
|
||||
QPointF GetNodePosition(Node* node, void* relative)
|
||||
QPointF GetNodePosition(Node* node, Node* context)
|
||||
{
|
||||
return position_map_.value(relative).value(node);
|
||||
return position_map_.value(context).value(node);
|
||||
}
|
||||
|
||||
void SetNodePosition(Node* node, void* relative, const QPointF& pos)
|
||||
void SetNodePosition(Node* node, Node* context, const QPointF& pos)
|
||||
{
|
||||
position_map_[relative].insert(node, pos);
|
||||
emit NodePositionAdded(node, relative, pos);
|
||||
position_map_[context].insert(node, pos);
|
||||
emit NodePositionAdded(node, context, pos);
|
||||
}
|
||||
|
||||
void RemoveNodePosition(Node* node, void* relative)
|
||||
void RemoveNodePosition(Node* node, Node* context)
|
||||
{
|
||||
PositionMap& map = position_map_[relative];
|
||||
PositionMap& map = position_map_[context];
|
||||
map.remove(node);
|
||||
if (map.isEmpty()) {
|
||||
position_map_.remove(relative);
|
||||
position_map_.remove(context);
|
||||
}
|
||||
emit NodePositionRemoved(node, relative);;
|
||||
emit NodePositionRemoved(node, context);
|
||||
}
|
||||
|
||||
qreal GetNodeContextHeight(void *context);
|
||||
qreal GetNodeContextHeight(Node *context);
|
||||
|
||||
using PositionMap = QMap<Node*, QPointF>;
|
||||
|
||||
const PositionMap &GetNodesForRelative(void *relative)
|
||||
const PositionMap &GetNodesForContext(Node *context)
|
||||
{
|
||||
return position_map_[relative];
|
||||
return position_map_[context];
|
||||
}
|
||||
|
||||
signals:
|
||||
@@ -115,9 +115,9 @@ signals:
|
||||
|
||||
void ValueChanged(const NodeInput& input);
|
||||
|
||||
void NodePositionAdded(Node *node, void *relative, const QPointF &position);
|
||||
void NodePositionAdded(Node *node, Node *relative, const QPointF &position);
|
||||
|
||||
void NodePositionRemoved(Node *node, void *relative);
|
||||
void NodePositionRemoved(Node *node, Node *relative);
|
||||
|
||||
protected:
|
||||
void AddDefaultNode(Node* n)
|
||||
@@ -132,7 +132,7 @@ private:
|
||||
|
||||
QVector<Node*> default_nodes_;
|
||||
|
||||
QMap<void *, PositionMap> position_map_;
|
||||
QMap<Node *, PositionMap> position_map_;
|
||||
|
||||
PositionMap root_position_map_;
|
||||
|
||||
|
||||
+8
-8
@@ -1303,7 +1303,7 @@ using NodePtr = std::shared_ptr<Node>;
|
||||
class NodeSetPositionCommand : public UndoCommand
|
||||
{
|
||||
public:
|
||||
NodeSetPositionCommand(Node* node, void* relevant, const QPointF& pos, bool move_dependencies_relatively)
|
||||
NodeSetPositionCommand(Node* node, Node* relevant, const QPointF& pos, bool move_dependencies_relatively)
|
||||
{
|
||||
node_ = node;
|
||||
relevant_ = relevant;
|
||||
@@ -1322,7 +1322,7 @@ public:
|
||||
|
||||
private:
|
||||
Node* node_;
|
||||
void* relevant_;
|
||||
Node* relevant_;
|
||||
QPointF pos_;
|
||||
QPointF old_pos_;
|
||||
bool added_;
|
||||
@@ -1333,7 +1333,7 @@ private:
|
||||
class NodeSetPositionAndShiftSurroundingsCommand : public UndoCommand
|
||||
{
|
||||
public:
|
||||
NodeSetPositionAndShiftSurroundingsCommand(Node* node, void *relative, const QPointF& pos, bool move_dependencies_relatively) :
|
||||
NodeSetPositionAndShiftSurroundingsCommand(Node* node, Node *relative, const QPointF& pos, bool move_dependencies_relatively) :
|
||||
node_(node),
|
||||
relative_(relative),
|
||||
position_(pos),
|
||||
@@ -1362,7 +1362,7 @@ public:
|
||||
private:
|
||||
Node* node_;
|
||||
|
||||
void *relative_;
|
||||
Node *relative_;
|
||||
|
||||
QPointF position_;
|
||||
|
||||
@@ -1375,7 +1375,7 @@ private:
|
||||
class NodeSetPositionAsChildCommand : public UndoCommand
|
||||
{
|
||||
public:
|
||||
NodeSetPositionAsChildCommand(Node* node, Node* parent, void *relative, int this_index, int child_count, bool shift_surroundings) :
|
||||
NodeSetPositionAsChildCommand(Node* node, Node* parent, Node *relative, int this_index, int child_count, bool shift_surroundings) :
|
||||
node_(node),
|
||||
parent_(parent),
|
||||
relative_(relative),
|
||||
@@ -1406,7 +1406,7 @@ public:
|
||||
private:
|
||||
Node* node_;
|
||||
Node* parent_;
|
||||
void *relative_;
|
||||
Node *relative_;
|
||||
|
||||
int this_index_;
|
||||
int child_count_;
|
||||
@@ -1420,7 +1420,7 @@ private:
|
||||
class NodeSetPositionToOffsetOfAnotherNodeCommand : public UndoCommand
|
||||
{
|
||||
public:
|
||||
NodeSetPositionToOffsetOfAnotherNodeCommand(Node* node, Node* other_node, void *relative, const QPointF& offset) :
|
||||
NodeSetPositionToOffsetOfAnotherNodeCommand(Node* node, Node* other_node, Node *relative, const QPointF& offset) :
|
||||
node_(node),
|
||||
other_node_(other_node),
|
||||
relative_(relative),
|
||||
@@ -1439,7 +1439,7 @@ public:
|
||||
private:
|
||||
Node* node_;
|
||||
Node* other_node_;
|
||||
void *relative_;
|
||||
Node *relative_;
|
||||
QPointF offset_;
|
||||
QPointF old_pos_;
|
||||
|
||||
|
||||
@@ -139,7 +139,7 @@ void FolderAddChild::redo()
|
||||
|
||||
if (autoposition_) {
|
||||
if (!position_command_) {
|
||||
position_command_ = new NodeSetPositionAsChildCommand(child_, folder_, folder_->project(), array_index, array_index+1, true);
|
||||
position_command_ = new NodeSetPositionAsChildCommand(child_, folder_, folder_->project()->root(), array_index, array_index+1, true);
|
||||
}
|
||||
position_command_->redo();
|
||||
}
|
||||
|
||||
@@ -39,27 +39,27 @@ Project::Project() :
|
||||
// Generate UUID for this project
|
||||
RegenerateUuid();
|
||||
|
||||
// Folder root for project
|
||||
root_ = new Folder();
|
||||
root_->setParent(this);
|
||||
root_->SetLabel(tr("Root"));
|
||||
root_->SetCanBeDeleted(false);
|
||||
SetNodePosition(root_, root_, QPointF(0, 0));
|
||||
|
||||
// Adds a color manager "node" to this project so that it synchronizes
|
||||
color_manager_ = new ColorManager();
|
||||
color_manager_->setParent(this);
|
||||
SetNodePosition(color_manager_, this, QPointF(1, 0));
|
||||
SetNodePosition(color_manager_, root_, QPointF(1, 0));
|
||||
color_manager_->SetCanBeDeleted(false);
|
||||
AddDefaultNode(color_manager_);
|
||||
|
||||
// Same with project settings
|
||||
settings_ = new ProjectSettingsNode();
|
||||
settings_->setParent(this);
|
||||
SetNodePosition(settings_, this, QPointF(2, 0));
|
||||
SetNodePosition(settings_, root_, QPointF(2, 0));
|
||||
settings_->SetCanBeDeleted(false);
|
||||
AddDefaultNode(settings_);
|
||||
|
||||
// Folder root for project
|
||||
root_ = new Folder();
|
||||
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