Branch 'kolab/integration/4.13.0' - 2 commits - korganizer/views

Christian Mollekopf mollekopf at kolabsys.com
Fri Sep 19 09:16:26 CEST 2014


 korganizer/views/collectionview/reparentingmodel.cpp           |   95 ++++++----
 korganizer/views/collectionview/reparentingmodel.h             |    7 
 korganizer/views/collectionview/tests/reparentingmodeltest.cpp |    2 
 3 files changed, 66 insertions(+), 38 deletions(-)

New commits:
commit 20a81a55a6e1be7bb5aa0ba7f1e4fc23766502ed
Author: Christian Mollekopf <chrigi_1 at fastmail.fm>
Date:   Thu Sep 18 15:01:47 2014 +0200

    ReparentingModel: Fixed warnings.

diff --git a/korganizer/views/collectionview/reparentingmodel.cpp b/korganizer/views/collectionview/reparentingmodel.cpp
index 19f2658..6e73df0 100644
--- a/korganizer/views/collectionview/reparentingmodel.cpp
+++ b/korganizer/views/collectionview/reparentingmodel.cpp
@@ -39,8 +39,8 @@ ReparentingModel::Node::Node(ReparentingModel& model)
 }
 
 ReparentingModel::Node::Node(ReparentingModel& model, ReparentingModel::Node* p, const QModelIndex& srcIndex)
-:   parent(p),
-    sourceIndex(srcIndex),
+:   sourceIndex(srcIndex),
+    parent(p),
     personModel(model),
     mIsSourceNode(true)
 {
@@ -94,7 +94,7 @@ void ReparentingModel::Node::clearHierarchy()
     children.clear();
 }
 
-bool ReparentingModel::Node::setData(const QVariant& value, int role)
+bool ReparentingModel::Node::setData(const QVariant& /* value */, int /* role */)
 {
     return false;
 }
@@ -107,12 +107,12 @@ QVariant ReparentingModel::Node::data(int role) const
     return QVariant();
 }
 
-bool ReparentingModel::Node::adopts(const QModelIndex& sourceIndex)
+bool ReparentingModel::Node::adopts(const QModelIndex& /* sourceIndex */)
 {
     return false;
 }
 
-bool ReparentingModel::Node::isDuplicateOf(const QModelIndex& sourceIndex)
+bool ReparentingModel::Node::isDuplicateOf(const QModelIndex& /* sourceIndex */)
 {
     return false;
 }
@@ -510,18 +510,18 @@ void ReparentingModel::onSourceRowsAboutToBeRemoved(QModelIndex parent, int star
     }
 }
 
-void ReparentingModel::onSourceRowsRemoved(QModelIndex parent, int start, int end)
+void ReparentingModel::onSourceRowsRemoved(QModelIndex /* parent */, int /* start */, int /* end */)
 {
 }
 
-void ReparentingModel::onSourceRowsAboutToBeMoved(QModelIndex sourceParent, int sourceStart, int sourceEnd, QModelIndex destParent, int dest)
+void ReparentingModel::onSourceRowsAboutToBeMoved(QModelIndex /* sourceParent */, int /* sourceStart */, int /* sourceEnd */, QModelIndex /* destParent */, int /* dest */)
 {
     kWarning() << "not implemented";
     //TODO
     beginResetModel();
 }
 
-void ReparentingModel::onSourceRowsMoved(QModelIndex sourceParent, int sourceStart, int sourceEnd, QModelIndex destParent, int dest)
+void ReparentingModel::onSourceRowsMoved(QModelIndex /* sourceParent */, int /* sourceStart */, int /* sourceEnd */, QModelIndex /* destParent */, int /* dest */)
 {
     kWarning() << "not implemented";
     //TODO
@@ -668,7 +668,7 @@ void ReparentingModel::rebuildFromSource(Node *parentNode, const QModelIndex &so
     }
 }
 
-bool ReparentingModel::isDuplicate(const Node::Ptr &proxyNode)
+bool ReparentingModel::isDuplicate(const Node::Ptr &proxyNode) const
 {
     Q_FOREACH(const Node *n, mSourceNodes) {
         // kDebug() << index << index.data().toString();
@@ -814,7 +814,7 @@ bool ReparentingModel::hasChildren(const QModelIndex& parent) const
     return (rowCount(parent) != 0);
 }
 
-int ReparentingModel::columnCount(const QModelIndex& parent) const
+int ReparentingModel::columnCount(const QModelIndex& /* parent */) const
 {
     return 1;
 }
diff --git a/korganizer/views/collectionview/reparentingmodel.h b/korganizer/views/collectionview/reparentingmodel.h
index 3c34806..ad73ba8 100644
--- a/korganizer/views/collectionview/reparentingmodel.h
+++ b/korganizer/views/collectionview/reparentingmodel.h
@@ -77,8 +77,8 @@ public:
         friend class ReparentingModel;
 
         //Allows the implementation to create proxy nodes as necessary
-        virtual void checkSourceIndex(const QModelIndex &sourceIndex){};
-        virtual void checkSourceIndexRemoval(const QModelIndex &sourceIndex){};
+        virtual void checkSourceIndex(const QModelIndex &/* sourceIndex */){};
+        virtual void checkSourceIndexRemoval(const QModelIndex &/* sourceIndex */){};
     };
 
 public:


commit 058851f9348a2bb3d027d2f899db85f3c6b70c4b
Author: Christian Mollekopf <chrigi_1 at fastmail.fm>
Date:   Thu Sep 18 14:57:35 2014 +0200

    ReparentingModel: No longer reset if a new proxy node is inserted.
    
    When inserting a lot of search results always resetting get's prohibitively expensive,
    to the tune of resetting the model for several seconds when inserting 200 nodes.

diff --git a/korganizer/views/collectionview/reparentingmodel.cpp b/korganizer/views/collectionview/reparentingmodel.cpp
index 74363b3..19f2658 100644
--- a/korganizer/views/collectionview/reparentingmodel.cpp
+++ b/korganizer/views/collectionview/reparentingmodel.cpp
@@ -262,10 +262,16 @@ void ReparentingModel::doAddNode(const Node::Ptr &node)
         return;
     }
 
-    beginResetModel();
-    mProxyNodes << node;
-    rebuildAll();
-    endResetModel();
+    if (!isDuplicate(node)) {
+        const int targetRow = mRootNode.children.size();
+        beginInsertRows(QModelIndex(), targetRow, targetRow);
+        mProxyNodes << node;
+        insertProxyNode(node);
+        endInsertRows();
+        reparentSourceNodes(node);
+    } else {
+        mProxyNodes << node;
+    }
 }
 
 void ReparentingModel::removeNode(const ReparentingModel::Node& node)
@@ -662,6 +668,44 @@ void ReparentingModel::rebuildFromSource(Node *parentNode, const QModelIndex &so
     }
 }
 
+bool ReparentingModel::isDuplicate(const Node::Ptr &proxyNode)
+{
+    Q_FOREACH(const Node *n, mSourceNodes) {
+        // kDebug() << index << index.data().toString();
+        if (proxyNode->isDuplicateOf(n->sourceIndex)) {
+            return true;
+        }
+    }
+    return false;
+}
+
+void ReparentingModel::insertProxyNode(const Node::Ptr &proxyNode)
+{
+    // kDebug() << "checking " << proxyNode->data(Qt::DisplayRole).toString();
+    proxyNode->parent = &mRootNode;
+    mRootNode.addChild(proxyNode);
+    Q_ASSERT(validateNode(proxyNode.data()));
+}
+
+void ReparentingModel::reparentSourceNodes(const Node::Ptr &proxyNode)
+{
+    //Reparent source nodes according to the provided rules
+    Q_FOREACH(Node *n, mSourceNodes) {
+        if (proxyNode->adopts(n->sourceIndex)) {
+            const int oldRow = n->sourceIndex.row();
+            beginRemoveRows(index(n->parent), oldRow, oldRow);
+            //We lie about the row being removed already, but the view can deal with that better than if we call endRemoveRows after beginInsertRows
+            endRemoveRows();
+
+            const int newRow = proxyNode->children.size();
+            beginInsertRows(index(proxyNode.data()), newRow, newRow);
+            proxyNode->reparent(n);
+            endInsertRows();
+            Q_ASSERT(validateNode(n));
+        }
+    }
+}
+
 void ReparentingModel::rebuildAll()
 {
     mRootNode.children.clear();
@@ -674,30 +718,11 @@ void ReparentingModel::rebuildAll()
     Q_FOREACH(const Node::Ptr &proxyNode, mProxyNodes) {
         // kDebug() << "checking " << proxyNode->data(Qt::DisplayRole).toString();
         //Avoid inserting a node that is already part of the source model
-        bool isDuplicate = false;
-        Q_FOREACH(const Node *n, mSourceNodes) {
-            // kDebug() << index << index.data().toString();
-            if (proxyNode->isDuplicateOf(n->sourceIndex)) {
-                isDuplicate = true;
-                break;
-            }
-        }
-        if (isDuplicate) {
+        if (isDuplicate(proxyNode)) {
             continue;
         }
-
-        proxyNode->parent = &mRootNode;
-        mRootNode.addChild(proxyNode);
-        Q_ASSERT(validateNode(proxyNode.data()));
-
-        //Reparent source nodes according to the provided rules
-        Q_FOREACH(Node *n, mSourceNodes) {
-            if (proxyNode->adopts(n->sourceIndex)) {
-                Node *reparentNode = n;
-                proxyNode->reparent(reparentNode);
-                Q_ASSERT(validateNode(reparentNode));
-            }
-        }
+        insertProxyNode(proxyNode);
+        reparentSourceNodes(proxyNode);
     }
 }
 
diff --git a/korganizer/views/collectionview/reparentingmodel.h b/korganizer/views/collectionview/reparentingmodel.h
index 2f85f04..3c34806 100644
--- a/korganizer/views/collectionview/reparentingmodel.h
+++ b/korganizer/views/collectionview/reparentingmodel.h
@@ -121,6 +121,9 @@ private Q_SLOTS:
 
 private:
     void rebuildFromSource(Node *parentNode, const QModelIndex &idx, const QModelIndexList &skip = QModelIndexList());
+    bool isDuplicate(const Node::Ptr &proxyNode) const;
+    void insertProxyNode(const Node::Ptr &proxyNode);
+    void reparentSourceNodes(const Node::Ptr &proxyNode);
     void rebuildAll();
     QModelIndex index(Node *node) const;
     Node *getReparentNode(const QModelIndex &sourceIndex);
diff --git a/korganizer/views/collectionview/tests/reparentingmodeltest.cpp b/korganizer/views/collectionview/tests/reparentingmodeltest.cpp
index 818b03d..4fe7dbb 100644
--- a/korganizer/views/collectionview/tests/reparentingmodeltest.cpp
+++ b/korganizer/views/collectionview/tests/reparentingmodeltest.cpp
@@ -271,7 +271,7 @@ void ReparentingModelTest::testAddRemoveProxyNode()
     QVERIFY(getIndex("row1", reparentingModel).isValid());
     QVERIFY(!getIndex("proxy1", reparentingModel).isValid());
 
-    QCOMPARE(spy.mSignals, QStringList() << QLatin1String("modelReset") << QLatin1String("rowsRemoved"));
+    QCOMPARE(spy.mSignals, QStringList() << QLatin1String("rowsInserted") << QLatin1String("rowsRemoved"));
 }
 
 void ReparentingModelTest::testDeduplicate()




More information about the commits mailing list