[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    KDE/kdepim/mobile
From:       Tobias Koenig <tokoe () kde ! org>
Date:       2010-11-25 10:38:23
Message-ID: 20101125103823.4C438AC8A2 () svn ! kde ! org
[Download RAW message or body]

SVN commit 1200595 by tokoe:

Extend HierarchyResolver to provide the parent->children
mapping as well


 M  +24 -8     lib/hierarchyresolver.cpp  
 M  +15 -1     lib/hierarchyresolver.h  
 M  +2 -1      tasks/threadgroupermodel.cpp  


--- trunk/KDE/kdepim/mobile/lib/hierarchyresolver.cpp #1200594:1200595
@@ -31,14 +31,18 @@
   mRelations.insert( child, parent );
 }
 
-QHash<QByteArray, QByteArray> HierarchyResolver::resolve() const
+void HierarchyResolver::resolve()
 {
-  QHash<QByteArray, QByteArray> result;
+  mChildParentResultMap.clear();
+  mParentChildrenResultMap.clear();
 
   // first insert all top nodes
-  foreach ( const QByteArray &node, mTopNodes )
-    result.insert( node, node );
+  foreach ( const QByteArray &node, mTopNodes ) {
+    mChildParentResultMap.insert( node, node );
 
+    mParentChildrenResultMap.insert( node, QSet<QByteArray>() );
+  }
+
   // search top-most parents for each added relation child node
   QHashIterator<QByteArray, QByteArray> it( mRelations );
   while ( it.hasNext() ) {
@@ -46,8 +50,11 @@
 
     // check if direct parent is top node
     if ( mTopNodes.contains( it.value() ) ) {
-      result.insert( it.key(), it.value() ); // we are done
-      continue;
+      mChildParentResultMap.insert( it.key(), it.value() );
+
+      mParentChildrenResultMap[ it.value() ].insert( it.key() );
+
+      continue; // we are done
     }
 
     // iterate up the parent path
@@ -55,8 +62,17 @@
     while ( mRelations.contains( parentNode ) )
       parentNode = mRelations.value( parentNode );
 
-    result.insert( it.key(), parentNode );
+    mChildParentResultMap.insert( it.key(), parentNode );
+    mParentChildrenResultMap[ parentNode ].insert( it.key() );
   }
+}
 
-  return result;
+QHash<QByteArray, QByteArray> HierarchyResolver::childParentMap() const
+{
+  return mChildParentResultMap;
 }
+
+QHash<QByteArray, QSet<QByteArray> > HierarchyResolver::parentChildrenMap() const
+{
+  return mParentChildrenResultMap;
+}
--- trunk/KDE/kdepim/mobile/lib/hierarchyresolver.h #1200594:1200595
@@ -57,16 +57,30 @@
     void addRelation( const QByteArray &child, const QByteArray &parent );
 
     /**
+     * Resolves the hierarchy.
+     */
+    void resolve();
+
+    /**
      * Returns a hash with the child node as key and its resolved top-most parent
      * node as value.
      *
      * The top-most parent of a parent node is the node itself.
      */
-    QHash<QByteArray, QByteArray> resolve() const;
+    QHash<QByteArray, QByteArray> childParentMap() const;
 
+    /**
+     * Returns a hash with the top-most parent node as key and a set of all its descendant
+     * nodes as value.
+     */
+    QHash<QByteArray, QSet<QByteArray> > parentChildrenMap() const;
+
   private:
     QSet<QByteArray> mTopNodes;
     QHash<QByteArray, QByteArray> mRelations;
+
+    QHash<QByteArray, QByteArray> mChildParentResultMap;
+    QHash<QByteArray, QSet<QByteArray> > mParentChildrenResultMap;
 };
 
 #endif
--- trunk/KDE/kdepim/mobile/tasks/threadgroupermodel.cpp #1200594:1200595
@@ -182,7 +182,8 @@
     }
   }
 
-  m_threads = resolver.resolve();
+  resolver.resolve();
+  m_threads = resolver.childParentMap();
 }
 
 ThreadGrouperModel::ThreadGrouperModel( QObject *parent )
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic