nodeview: optimized selecting
Rather than responding to every single selection change, the selection operation can function as-is and then respond to all of them at the end.
This commit is contained in:
@@ -45,9 +45,10 @@ NodeView::NodeView(QWidget *parent) :
|
|||||||
setRenderHint(QPainter::Antialiasing);
|
setRenderHint(QPainter::Antialiasing);
|
||||||
|
|
||||||
connect(&scene_, &QGraphicsScene::changed, this, &NodeView::ItemsChanged);
|
connect(&scene_, &QGraphicsScene::changed, this, &NodeView::ItemsChanged);
|
||||||
connect(&scene_, &QGraphicsScene::selectionChanged, this, &NodeView::SceneSelectionChangedSlot);
|
|
||||||
connect(this, &NodeView::customContextMenuRequested, this, &NodeView::ShowContextMenu);
|
connect(this, &NodeView::customContextMenuRequested, this, &NodeView::ShowContextMenu);
|
||||||
|
|
||||||
|
ConnectSelectionChangedSignal();
|
||||||
|
|
||||||
SetFlowDirection(NodeViewCommon::kTopToBottom);
|
SetFlowDirection(NodeViewCommon::kTopToBottom);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -129,12 +130,24 @@ void NodeView::DeleteSelected()
|
|||||||
|
|
||||||
void NodeView::SelectAll()
|
void NodeView::SelectAll()
|
||||||
{
|
{
|
||||||
|
// Optimization: rather than respond to every single item being selected, ignore the signal and
|
||||||
|
// then handle them all at the end.
|
||||||
|
DisconnectSelectionChangedSignal();
|
||||||
|
|
||||||
scene_.SelectAll();
|
scene_.SelectAll();
|
||||||
|
|
||||||
|
ReconnectSelectionChangedSignal();
|
||||||
}
|
}
|
||||||
|
|
||||||
void NodeView::DeselectAll()
|
void NodeView::DeselectAll()
|
||||||
{
|
{
|
||||||
|
// Optimization: rather than respond to every single item being selected, ignore the signal and
|
||||||
|
// then handle them all at the end.
|
||||||
|
DisconnectSelectionChangedSignal();
|
||||||
|
|
||||||
scene_.DeselectAll();
|
scene_.DeselectAll();
|
||||||
|
|
||||||
|
ReconnectSelectionChangedSignal();
|
||||||
}
|
}
|
||||||
|
|
||||||
void NodeView::Select(const QList<Node *> &nodes)
|
void NodeView::Select(const QList<Node *> &nodes)
|
||||||
@@ -143,13 +156,19 @@ void NodeView::Select(const QList<Node *> &nodes)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
DeselectAll();
|
// Optimization: rather than respond to every single item being selected, ignore the signal and
|
||||||
|
// then handle them all at the end.
|
||||||
|
DisconnectSelectionChangedSignal();
|
||||||
|
|
||||||
|
scene_.DeselectAll();
|
||||||
|
|
||||||
foreach (Node* n, nodes) {
|
foreach (Node* n, nodes) {
|
||||||
NodeViewItem* item = scene_.NodeToUIObject(n);
|
NodeViewItem* item = scene_.NodeToUIObject(n);
|
||||||
|
|
||||||
item->setSelected(true);
|
item->setSelected(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ReconnectSelectionChangedSignal();
|
||||||
}
|
}
|
||||||
|
|
||||||
void NodeView::SelectWithDependencies(QList<Node *> nodes)
|
void NodeView::SelectWithDependencies(QList<Node *> nodes)
|
||||||
@@ -433,8 +452,10 @@ void NodeView::ShowContextMenu(const QPoint &pos)
|
|||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
QAction* filters_action = m.addAction(tr("Filters..."));
|
Menu* filter_menu = new Menu(tr("Filter"), &m);
|
||||||
connect(filters_action, &QAction::triggered, this, &NodeView::ContextMenuShowFiltersDialog);
|
|
||||||
|
filter_menu->addAction(tr("Show All"))->setData(NodeViewScene::kFilterShowAll);
|
||||||
|
filter_menu->addAction(tr("Show Selected Blocks Only"))->setData(NodeViewScene::kFilterShowSelectedBlocks);
|
||||||
|
|
||||||
m.addSeparator();
|
m.addSeparator();
|
||||||
|
|
||||||
@@ -707,4 +728,20 @@ void NodeView::MoveAttachedNodesToCursor(const QPoint& p)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void NodeView::ConnectSelectionChangedSignal()
|
||||||
|
{
|
||||||
|
connect(&scene_, &QGraphicsScene::selectionChanged, this, &NodeView::SceneSelectionChangedSlot);
|
||||||
|
}
|
||||||
|
|
||||||
|
void NodeView::ReconnectSelectionChangedSignal()
|
||||||
|
{
|
||||||
|
ConnectSelectionChangedSignal();
|
||||||
|
SceneSelectionChangedSlot();
|
||||||
|
}
|
||||||
|
|
||||||
|
void NodeView::DisconnectSelectionChangedSignal()
|
||||||
|
{
|
||||||
|
disconnect(&scene_, &QGraphicsScene::selectionChanged, this, &NodeView::SceneSelectionChangedSlot);
|
||||||
|
}
|
||||||
|
|
||||||
OLIVE_NAMESPACE_EXIT
|
OLIVE_NAMESPACE_EXIT
|
||||||
|
|||||||
@@ -94,6 +94,10 @@ private:
|
|||||||
|
|
||||||
void MoveAttachedNodesToCursor(const QPoint &p);
|
void MoveAttachedNodesToCursor(const QPoint &p);
|
||||||
|
|
||||||
|
void ConnectSelectionChangedSignal();
|
||||||
|
void ReconnectSelectionChangedSignal();
|
||||||
|
void DisconnectSelectionChangedSignal();
|
||||||
|
|
||||||
NodeGraph* graph_;
|
NodeGraph* graph_;
|
||||||
|
|
||||||
struct AttachedItem {
|
struct AttachedItem {
|
||||||
|
|||||||
Reference in New Issue
Block a user