Fix perf issues zoomed in again

This commit is contained in:
Joey Yakimowich-Payne 2026-02-06 11:17:15 -07:00
commit 5fa5a63d1a
3 changed files with 26 additions and 6 deletions

View file

@ -352,12 +352,11 @@ void WarpGraphModel::refreshFromClient() {
return; return;
} }
Q_EMIT beginBatchUpdate();
m_refreshing = true; m_refreshing = true;
bool sceneChanged = false;
auto nodesResult = m_client->ListNodes(); auto nodesResult = m_client->ListNodes();
if (!nodesResult.ok()) { if (!nodesResult.ok()) {
m_refreshing = false; m_refreshing = false;
Q_EMIT endBatchUpdate();
return; return;
} }
@ -512,6 +511,10 @@ void WarpGraphModel::refreshFromClient() {
m_volumeStates[qtId] = {}; m_volumeStates[qtId] = {};
} }
if (!sceneChanged) {
sceneChanged = true;
Q_EMIT beginBatchUpdate();
}
Q_EMIT nodeCreated(qtId); Q_EMIT nodeCreated(qtId);
} }
@ -526,6 +529,10 @@ void WarpGraphModel::refreshFromClient() {
if (it == m_pwToQt.end()) { if (it == m_pwToQt.end()) {
continue; continue;
} }
if (!sceneChanged) {
sceneChanged = true;
Q_EMIT beginBatchUpdate();
}
QtNodes::NodeId qtId = it->second; QtNodes::NodeId qtId = it->second;
auto nodeIt = m_nodes.find(qtId); auto nodeIt = m_nodes.find(qtId);
if (nodeIt == m_nodes.end()) { if (nodeIt == m_nodes.end()) {
@ -581,6 +588,10 @@ void WarpGraphModel::refreshFromClient() {
QtNodes::ConnectionId connId{outNodeIt->second, outPortIdx, QtNodes::ConnectionId connId{outNodeIt->second, outPortIdx,
inNodeIt->second, inPortIdx}; inNodeIt->second, inPortIdx};
if (m_connections.find(connId) == m_connections.end()) { if (m_connections.find(connId) == m_connections.end()) {
if (!sceneChanged) {
sceneChanged = true;
Q_EMIT beginBatchUpdate();
}
m_connections.insert(connId); m_connections.insert(connId);
m_linkIdToConn.emplace(link.id.value, connId); m_linkIdToConn.emplace(link.id.value, connId);
Q_EMIT connectionCreated(connId); Q_EMIT connectionCreated(connId);
@ -609,6 +620,10 @@ void WarpGraphModel::refreshFromClient() {
{ {
auto connIt = m_connections.find(connId); auto connIt = m_connections.find(connId);
if (connIt != m_connections.end()) { if (connIt != m_connections.end()) {
if (!sceneChanged) {
sceneChanged = true;
Q_EMIT beginBatchUpdate();
}
m_connections.erase(connIt); m_connections.erase(connIt);
Q_EMIT connectionDeleted(connId); Q_EMIT connectionDeleted(connId);
} }
@ -696,7 +711,9 @@ void WarpGraphModel::refreshFromClient() {
} }
m_refreshing = false; m_refreshing = false;
Q_EMIT endBatchUpdate(); if (sceneChanged) {
Q_EMIT endBatchUpdate();
}
} }
const WarpNodeData * const WarpNodeData *

View file

@ -9,6 +9,8 @@
#include <QScrollBar> #include <QScrollBar>
#include <QWheelEvent> #include <QWheelEvent>
#include <QtNodes/internal/ConnectionGraphicsObject.hpp>
#include <cmath> #include <cmath>
class ZoomGraphicsView : public QtNodes::GraphicsView { class ZoomGraphicsView : public QtNodes::GraphicsView {
@ -39,7 +41,8 @@ public:
auto cacheMode = highZoom ? QGraphicsItem::DeviceCoordinateCache auto cacheMode = highZoom ? QGraphicsItem::DeviceCoordinateCache
: QGraphicsItem::NoCache; : QGraphicsItem::NoCache;
for (QGraphicsItem *item : scene()->items()) { for (QGraphicsItem *item : scene()->items()) {
if (item->type() == QGraphicsProxyWidget::Type) if (item->type() == QGraphicsProxyWidget::Type ||
item->type() == QtNodes::ConnectionGraphicsObject::Type)
item->setCacheMode(cacheMode); item->setCacheMode(cacheMode);
} }
} }

View file

@ -2371,7 +2371,7 @@ TEST_CASE("ZoomGraphicsView wheel zoom honors sensitivity and zero delta") {
REQUIRE(view.transform().m11() == Catch::Approx(beforeFlat)); REQUIRE(view.transform().m11() == Catch::Approx(beforeFlat));
} }
TEST_CASE("ZoomGraphicsView updateProxyCacheMode toggles proxy and leaves connection uncached") { TEST_CASE("ZoomGraphicsView updateProxyCacheMode toggles proxy and connection cache") {
auto tc = TestClient::Create(); auto tc = TestClient::Create();
if (!tc.available()) { SUCCEED("PipeWire unavailable"); return; } if (!tc.available()) { SUCCEED("PipeWire unavailable"); return; }
ensureApp(); ensureApp();
@ -2393,7 +2393,7 @@ TEST_CASE("ZoomGraphicsView updateProxyCacheMode toggles proxy and leaves connec
view.setupScale(1.6); view.setupScale(1.6);
view.updateProxyCacheMode(); view.updateProxyCacheMode();
REQUIRE(proxy->cacheMode() == QGraphicsItem::DeviceCoordinateCache); REQUIRE(proxy->cacheMode() == QGraphicsItem::DeviceCoordinateCache);
REQUIRE(connection->cacheMode() == QGraphicsItem::NoCache); REQUIRE(connection->cacheMode() == QGraphicsItem::DeviceCoordinateCache);
view.setupScale(1.0); view.setupScale(1.0);
view.updateProxyCacheMode(); view.updateProxyCacheMode();