nodeview: improved user manual positioning
This commit is contained in:
@@ -89,6 +89,11 @@ public:
|
||||
emit NodePositionRemoved(node, context);
|
||||
}
|
||||
|
||||
bool ContextContainsNode(Node *node, Node *context)
|
||||
{
|
||||
return position_map_[context].contains(node);
|
||||
}
|
||||
|
||||
qreal GetNodeContextHeight(Node *context);
|
||||
|
||||
using PositionMap = QMap<Node*, QPointF>;
|
||||
|
||||
@@ -57,7 +57,6 @@ NodeView::NodeView(QWidget *parent) :
|
||||
setViewportUpdateMode(FullViewportUpdate);
|
||||
|
||||
connect(this, &NodeView::customContextMenuRequested, this, &NodeView::ShowContextMenu);
|
||||
connect(&scene_, &NodeViewScene::NodePositionChanged, this, &NodeView::NodePositionChanged);
|
||||
|
||||
ConnectSelectionChangedSignal();
|
||||
|
||||
@@ -643,9 +642,9 @@ void NodeView::mouseReleaseEvent(QMouseEvent *event)
|
||||
return;
|
||||
}
|
||||
|
||||
if (!attached_items_.isEmpty()) {
|
||||
MultiUndoCommand* command = new MultiUndoCommand();
|
||||
MultiUndoCommand* command = new MultiUndoCommand();
|
||||
|
||||
if (!attached_items_.isEmpty()) {
|
||||
if (paste_command_) {
|
||||
// We've already "done" this command, but MultiUndoCommand prevents "redoing" twice, so we
|
||||
// add it to this command (which may have extra commands added too) so that it all gets undone
|
||||
@@ -670,10 +669,31 @@ void NodeView::mouseReleaseEvent(QMouseEvent *event)
|
||||
}
|
||||
|
||||
DetachItemsFromCursor();
|
||||
|
||||
Core::instance()->undo_stack()->push(command);
|
||||
}
|
||||
|
||||
for (auto it=positions_.begin(); it!=positions_.end(); it++) {
|
||||
NodeViewItem *item = it.key();
|
||||
Position &pos_data = it.value();
|
||||
QPointF current_item_pos = item->GetNodePosition();
|
||||
Node *node = pos_data.node;
|
||||
|
||||
if (pos_data.original_item_pos != current_item_pos) {
|
||||
QPointF diff = current_item_pos - pos_data.original_item_pos;
|
||||
|
||||
foreach (Node *context, filter_nodes_) {
|
||||
if (graph_->ContextContainsNode(node, context)) {
|
||||
QPointF current_node_pos_in_context = graph_->GetNodePosition(node, context);
|
||||
current_node_pos_in_context += diff;
|
||||
command->add_child(new NodeSetPositionCommand(node, context, current_node_pos_in_context, false));
|
||||
}
|
||||
}
|
||||
|
||||
pos_data.original_item_pos = current_item_pos;
|
||||
}
|
||||
}
|
||||
|
||||
Core::instance()->undo_stack()->pushIfHasChildren(command);
|
||||
|
||||
super::mouseReleaseEvent(event);
|
||||
}
|
||||
|
||||
@@ -823,10 +843,13 @@ void NodeView::CreateNodeSlot(QAction *action)
|
||||
Node* new_node = NodeFactory::CreateFromMenuAction(action);
|
||||
|
||||
if (new_node) {
|
||||
Core::instance()->undo_stack()->push(new NodeAddCommand(graph_, new_node));
|
||||
|
||||
NodeViewItem* item = scene_.NodeToUIObject(new_node);
|
||||
AttachItemsToCursor({item});
|
||||
paste_command_ = new MultiUndoCommand();
|
||||
paste_command_->add_child(new NodeAddCommand(graph_, new_node));
|
||||
foreach (Node *context, filter_nodes_) {
|
||||
paste_command_->add_child(new NodeSetPositionCommand(new_node, context, QPointF(0, 0), false));
|
||||
}
|
||||
paste_command_->add_child(new NodeViewAttachNodesToCursor(this, {new_node}));
|
||||
paste_command_->redo();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -940,24 +963,19 @@ void NodeView::RemoveNodePosition(Node *node, Node *relative)
|
||||
{
|
||||
if (filter_mode_ == kFilterShowSelective) {
|
||||
if (filter_nodes_.contains(relative)) {
|
||||
NodeViewItem *item = scene_.item_map().value(node);
|
||||
delete item;
|
||||
}
|
||||
}
|
||||
}
|
||||
// Determine if any other contexts have this node
|
||||
bool found = false;
|
||||
|
||||
void NodeView::NodePositionChanged(NodeViewItem *item, const QPointF &pos)
|
||||
{
|
||||
Position &original_pos = positions_[item];
|
||||
Node *node = original_pos.node;
|
||||
QPointF diff = pos - original_pos.original_item_pos;
|
||||
original_pos.original_item_pos = pos;
|
||||
foreach (Node *context, filter_nodes_) {
|
||||
if (graph_->ContextContainsNode(node, context)) {
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
foreach (Node *context, filter_nodes_) {
|
||||
if (graph_->GetNodesForContext(context).contains(node)) {
|
||||
QPointF p = graph_->GetNodePosition(node, context);
|
||||
p += diff;
|
||||
graph_->SetNodePosition(node, context, p);
|
||||
if (!found) {
|
||||
scene_.RemoveNode(node);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -217,8 +217,6 @@ private slots:
|
||||
void AddNodePosition(Node *node, Node *relative);
|
||||
void RemoveNodePosition(Node *node, Node *relative);
|
||||
|
||||
void NodePositionChanged(NodeViewItem *item, const QPointF &pos);
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -45,8 +45,7 @@ NodeViewItem::NodeViewItem(QGraphicsItem *parent) :
|
||||
expanded_(false),
|
||||
hide_titlebar_(false),
|
||||
highlighted_index_(-1),
|
||||
flow_dir_(NodeViewCommon::kLeftToRight),
|
||||
dont_signal_(false)
|
||||
flow_dir_(NodeViewCommon::kLeftToRight)
|
||||
{
|
||||
// Set flags for this widget
|
||||
setFlag(QGraphicsItem::ItemIsMovable);
|
||||
@@ -337,10 +336,6 @@ QVariant NodeViewItem::itemChange(QGraphicsItem::GraphicsItemChange change, cons
|
||||
{
|
||||
if (change == ItemPositionHasChanged && node_) {
|
||||
ReadjustAllEdges();
|
||||
|
||||
if (!dont_signal_) {
|
||||
emit NodePositionChanged(GetNodePosition());
|
||||
}
|
||||
}
|
||||
|
||||
return QGraphicsItem::itemChange(change, value);
|
||||
@@ -484,8 +479,6 @@ QPointF NodeViewItem::GetInputPointInternal(int index, const QPointF& source_pos
|
||||
|
||||
void NodeViewItem::UpdateNodePosition()
|
||||
{
|
||||
dont_signal_ = true;
|
||||
|
||||
const QPointF &pos = cached_node_pos_;
|
||||
|
||||
switch (flow_dir_) {
|
||||
@@ -506,8 +499,6 @@ void NodeViewItem::UpdateNodePosition()
|
||||
-pos.x() * DefaultItemVerticalPadding());
|
||||
break;
|
||||
}
|
||||
|
||||
dont_signal_ = false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -40,9 +40,8 @@ class NodeViewEdge;
|
||||
*
|
||||
* To retrieve the NodeViewItem for a certain Node, use NodeView::NodeToUIObject().
|
||||
*/
|
||||
class NodeViewItem : public QObject, public QGraphicsRectItem
|
||||
class NodeViewItem : public QGraphicsRectItem
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
NodeViewItem(QGraphicsItem* parent = nullptr);
|
||||
|
||||
@@ -112,9 +111,6 @@ public:
|
||||
|
||||
void SetHighlightedIndex(int index);
|
||||
|
||||
signals:
|
||||
void NodePositionChanged(const QPointF &pos);
|
||||
|
||||
protected:
|
||||
virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = nullptr) override;
|
||||
|
||||
@@ -178,8 +174,6 @@ private:
|
||||
|
||||
QPointF cached_node_pos_;
|
||||
|
||||
bool dont_signal_;
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -159,7 +159,6 @@ NodeViewItem* NodeViewScene::AddNode(Node* node)
|
||||
|
||||
connect(node, &Node::LabelChanged, this, &NodeViewScene::NodeAppearanceChanged);
|
||||
connect(node, &Node::ColorChanged, this, &NodeViewScene::NodeAppearanceChanged);
|
||||
connect(item, &NodeViewItem::NodePositionChanged, this, &NodeViewScene::NodeItemPositionChanged);
|
||||
|
||||
return item;
|
||||
}
|
||||
@@ -279,10 +278,4 @@ void NodeViewScene::NodeAppearanceChanged()
|
||||
item_map_.value(static_cast<Node*>(sender()))->update();
|
||||
}
|
||||
|
||||
void NodeViewScene::NodeItemPositionChanged(const QPointF &pos)
|
||||
{
|
||||
NodeViewItem *item = static_cast<NodeViewItem *>(sender());
|
||||
emit NodePositionChanged(item, pos);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -106,9 +106,6 @@ public slots:
|
||||
*/
|
||||
void SetEdgesAreCurved(bool curved);
|
||||
|
||||
signals:
|
||||
void NodePositionChanged(NodeViewItem *node, const QPointF &pos);
|
||||
|
||||
private:
|
||||
static int DetermineWeight(Node* n);
|
||||
|
||||
@@ -130,8 +127,6 @@ private slots:
|
||||
*/
|
||||
void NodeAppearanceChanged();
|
||||
|
||||
void NodeItemPositionChanged(const QPointF &pos);
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user