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

List:       kde-commits
Subject:    KDE/kdepim/kmail/messagelistview/core
From:       Szymon Stefanek <pragma () kvirc ! net>
Date:       2009-03-09 13:59:22
Message-ID: 1236607162.856659.22732.nullmailer () svn ! kde ! org
[Download RAW message or body]

SVN commit 937315 by stefanek:

CTRL+, and CTRL+. now always expand/collapse threads, as the shortcut
name suggests. Groups are not expanded/collapsed.

BUG: 183031



 M  +2 -1      model.h  
 M  +45 -37    view.cpp  
 M  +8 -0      view.h  


--- trunk/KDE/kdepim/kmail/messagelistview/core/model.h #937314:937315
@@ -185,7 +185,7 @@
 
   /**
    * Owned invisible root item, useful to implement algorithms that not need
-   * to handle the special case of parentless items
+   * to handle the special case of parentless items. This is never 0.
    */
   Item *mRootItem;
 
@@ -396,6 +396,7 @@
 
   /**
    * Returns the hidden root item that all the messages are (or will be) attached to.
+   * The returned value is never 0.
    */
   Item * rootItem() const
     { return mRootItem; };
--- trunk/KDE/kdepim/kmail/messagelistview/core/view.cpp #937314:937315
@@ -888,9 +888,51 @@
 
 void View::setAllThreadsExpanded( bool expand )
 {
-  setChildrenExpanded( mModel->rootItem(), expand );
+  if ( mAggregation->grouping() == Aggregation::NoGrouping )
+  {
+    // we have no groups so threads start under the root item: just expand/unexpand all
+    setChildrenExpanded( mModel->rootItem(), expand );
+    return;
+  }
+
+  // grouping is in effect: must expand/unexpand one level lower
+
+  QList< Item * > * childList = mModel->rootItem()->childItems();
+  if ( !childList )
+    return;
+
+  foreach ( Item * item, *childList )
+    setChildrenExpanded( item, expand );
 }
 
+void View::setAllGroupsExpanded( bool expand )
+{
+  if ( mAggregation->grouping() == Aggregation::NoGrouping )
+    return; // no grouping in effect
+
+  Item * item = mModel->rootItem();
+
+  QList< Item * > * childList = item->childItems();
+  if ( !childList )
+    return;
+
+  foreach ( Item * item, *childList )
+  {
+    Q_ASSERT( item->type() == Item::GroupHeader );
+    QModelIndex idx = mModel->index( item, 0 );
+    Q_ASSERT( idx.isValid() );
+    Q_ASSERT( static_cast< Item * >( idx.internalPointer() ) == item );
+    if ( expand )
+    {
+      if ( !isExpanded( idx ) )
+        setExpanded( idx, true );
+    } else {
+      if ( isExpanded( idx ) )
+        setExpanded( idx, false );
+    }
+  }
+}
+
 void View::selectMessageItems( const QList< MessageItem * > &list )
 {
   QItemSelection selection;
@@ -2268,46 +2310,12 @@
 
 void View::slotCollapseAllGroups()
 {
-  if ( mAggregation->grouping() == Aggregation::NoGrouping )
-    return;
-
-  Item * item = mModel->rootItem();
-
-  QList< Item * > * childList = item->childItems();
-  if ( !childList )
-    return;
-
-  for ( QList< Item * >::Iterator it = childList->begin(); it != childList->end(); ++it )
-  {
-    Q_ASSERT( ( *it )->type() == Item::GroupHeader );
-    QModelIndex idx = mModel->index( *it, 0 );
-    Q_ASSERT( idx.isValid() );
-    Q_ASSERT( static_cast< Item * >( idx.internalPointer() ) == ( *it ) );
-    if ( isExpanded( idx ) )
-      setExpanded( idx, false );
-  }
+  setAllGroupsExpanded( false );
 }
 
 void View::slotExpandAllGroups()
 {
-  if ( mAggregation->grouping() == Aggregation::NoGrouping )
-    return;
-
-  Item * item = mModel->rootItem();
-
-  QList< Item * > * childList = item->childItems();
-  if ( !childList )
-    return;
-
-  for ( QList< Item * >::Iterator it = childList->begin(); it != childList->end(); ++it )
-  {
-    Q_ASSERT( ( *it )->type() == Item::GroupHeader );
-    QModelIndex idx = mModel->index( *it, 0 );
-    Q_ASSERT( idx.isValid() );
-    Q_ASSERT( static_cast< Item * >( idx.internalPointer() ) == ( *it ) );
-    if ( !isExpanded( idx ) )
-      setExpanded( idx, true );
-  }
+  setAllGroupsExpanded( true );
 }
 
 } // namespace Core
--- trunk/KDE/kdepim/kmail/messagelistview/core/view.h #937314:937315
@@ -260,6 +260,14 @@
   void setAllThreadsExpanded( bool expand );
 
   /**
+   * If expand is true then it expands all the groups (only the toplevel
+   * group item: inner threads are NOT expanded). If expand is false
+   * then it collapses all the groups. If no grouping is in effect
+   * then this function does nothing.
+   */
+  void setAllGroupsExpanded( bool expand );
+
+  /**
    * Selects the next message item in the view.
    *
    * messageTypeFilter can be used to limit the selection to
[prev in list] [next in list] [prev in thread] [next in thread] 

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