diff options
author | Miikka Heikkinen <miikka.heikkinen@digia.com> | 2014-01-21 08:55:03 +0200 |
---|---|---|
committer | Miikka Heikkinen <miikka.heikkinen@digia.com> | 2014-01-21 09:41:47 +0200 |
commit | 177f9d385c8cd062c4bad78cf6b794a96fa025ad (patch) | |
tree | 14b362622d07a93ea56b077e23894a7384a3ddaa /src/datavisualization/data/abstractitemmodelhandler.cpp | |
parent | 818e29d4c4fd4344df20328ec3fe693acc67e11a (diff) |
Selection correction for scatter when data changes
Implements item 3) in QTRD-2645
Task-number: QTRD-264
Change-Id: Ibe758bbfb3b4a74b55589a410b402bbdf07ea64f
Reviewed-by: Tomi Korpipää <tomi.korpipaa@digia.com>
Diffstat (limited to 'src/datavisualization/data/abstractitemmodelhandler.cpp')
-rw-r--r-- | src/datavisualization/data/abstractitemmodelhandler.cpp | 85 |
1 files changed, 58 insertions, 27 deletions
diff --git a/src/datavisualization/data/abstractitemmodelhandler.cpp b/src/datavisualization/data/abstractitemmodelhandler.cpp index cf87c3f9..879ce086 100644 --- a/src/datavisualization/data/abstractitemmodelhandler.cpp +++ b/src/datavisualization/data/abstractitemmodelhandler.cpp @@ -23,7 +23,8 @@ QT_BEGIN_NAMESPACE_DATAVISUALIZATION AbstractItemModelHandler::AbstractItemModelHandler(QObject *parent) : QObject(parent), - resolvePending(0) + resolvePending(0), + m_fullReset(true) { m_resolveTimer.setSingleShot(true); QObject::connect(&m_resolveTimer, &QTimer::timeout, @@ -81,9 +82,12 @@ void AbstractItemModelHandler::handleColumnsInserted(const QModelIndex &parent, Q_UNUSED(start) Q_UNUSED(end) - // Resolve new items - if (!m_resolveTimer.isActive()) - m_resolveTimer.start(0); // TODO Resolving entire model is inefficient + // Manipulating columns changes all rows in proxies that map rows/columns directly, + // and its effects are not clearly defined in others -> always do full reset. + if (!m_resolveTimer.isActive()) { + m_fullReset = true; + m_resolveTimer.start(0); + } } void AbstractItemModelHandler::handleColumnsMoved(const QModelIndex &sourceParent, @@ -98,9 +102,12 @@ void AbstractItemModelHandler::handleColumnsMoved(const QModelIndex &sourceParen Q_UNUSED(destinationParent) Q_UNUSED(destinationColumn) - // Resolve moved items - if (!m_resolveTimer.isActive()) - m_resolveTimer.start(0); // TODO Resolving entire model is inefficient + // Manipulating columns changes all rows in proxies that map rows/columns directly, + // and its effects are not clearly defined in others -> always do full reset. + if (!m_resolveTimer.isActive()) { + m_fullReset = true; + m_resolveTimer.start(0); + } } void AbstractItemModelHandler::handleColumnsRemoved(const QModelIndex &parent, @@ -110,9 +117,12 @@ void AbstractItemModelHandler::handleColumnsRemoved(const QModelIndex &parent, Q_UNUSED(start) Q_UNUSED(end) - // Remove old items - if (!m_resolveTimer.isActive()) - m_resolveTimer.start(0); // TODO Resolving entire model is inefficient + // Manipulating columns changes all rows in proxies that map rows/columns directly, + // and its effects are not clearly defined in others -> always do full reset. + if (!m_resolveTimer.isActive()) { + m_fullReset = true; + m_resolveTimer.start(0); + } } void AbstractItemModelHandler::handleDataChanged(const QModelIndex &topLeft, @@ -123,9 +133,13 @@ void AbstractItemModelHandler::handleDataChanged(const QModelIndex &topLeft, Q_UNUSED(bottomRight) Q_UNUSED(roles) - // Resolve changed items - if (!m_resolveTimer.isActive()) - m_resolveTimer.start(0); // TODO Resolving entire model is inefficient + // Default handling for dataChanged is to do full reset, as it cannot be optimized + // in a general case, where we do not know which row/column/index the item model item + // actually ended up to in the proxy. + if (!m_resolveTimer.isActive()) { + m_fullReset = true; + m_resolveTimer.start(0); + } } void AbstractItemModelHandler::handleLayoutChanged(const QList<QPersistentModelIndex> &parents, @@ -134,16 +148,20 @@ void AbstractItemModelHandler::handleLayoutChanged(const QList<QPersistentModelI Q_UNUSED(parents) Q_UNUSED(hint) - // Resolve moved items - if (!m_resolveTimer.isActive()) - m_resolveTimer.start(0); // TODO Resolving entire model is inefficient + // Resolve entire model if layout changes + if (!m_resolveTimer.isActive()) { + m_fullReset = true; + m_resolveTimer.start(0); + } } void AbstractItemModelHandler::handleModelReset() { // Data cleared, reset array - if (!m_resolveTimer.isActive()) - m_resolveTimer.start(0); // TODO Resolving entire model is inefficient + if (!m_resolveTimer.isActive()) { + m_fullReset = true; + m_resolveTimer.start(0); + } } void AbstractItemModelHandler::handleRowsInserted(const QModelIndex &parent, int start, int end) @@ -152,9 +170,13 @@ void AbstractItemModelHandler::handleRowsInserted(const QModelIndex &parent, int Q_UNUSED(start) Q_UNUSED(end) - // Resolve new items - if (!m_resolveTimer.isActive()) - m_resolveTimer.start(0); // TODO Resolving entire model is inefficient + // Default handling for rowsInserted is to do full reset, as it cannot be optimized + // in a general case, where we do not know which row/column/index the item model item + // actually ended up to in the proxy. + if (!m_resolveTimer.isActive()) { + m_fullReset = true; + m_resolveTimer.start(0); + } } void AbstractItemModelHandler::handleRowsMoved(const QModelIndex &sourceParent, @@ -169,9 +191,13 @@ void AbstractItemModelHandler::handleRowsMoved(const QModelIndex &sourceParent, Q_UNUSED(destinationParent) Q_UNUSED(destinationRow) - // Resolve moved items - if (!m_resolveTimer.isActive()) - m_resolveTimer.start(0); // TODO Resolving entire model is inefficient + // Default handling for rowsMoved is to do full reset, as it cannot be optimized + // in a general case, where we do not know which row/column/index the item model item + // actually ended up to in the proxy. + if (!m_resolveTimer.isActive()) { + m_fullReset = true; + m_resolveTimer.start(0); + } } void AbstractItemModelHandler::handleRowsRemoved(const QModelIndex &parent, int start, int end) @@ -180,9 +206,13 @@ void AbstractItemModelHandler::handleRowsRemoved(const QModelIndex &parent, int Q_UNUSED(start) Q_UNUSED(end) - // Resolve removed items - if (!m_resolveTimer.isActive()) - m_resolveTimer.start(0); // TODO Resolving entire model is inefficient + // Default handling for rowsRemoved is to do full reset, as it cannot be optimized + // in a general case, where we do not know which row/column/index the item model item + // actually ended up to in the proxy. + if (!m_resolveTimer.isActive()) { + m_fullReset = true; + m_resolveTimer.start(0); + } } void AbstractItemModelHandler::handleMappingChanged() @@ -194,6 +224,7 @@ void AbstractItemModelHandler::handleMappingChanged() void AbstractItemModelHandler::handlePendingResolve() { resolveModel(); + m_fullReset = false; } QT_END_NAMESPACE_DATAVISUALIZATION |