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

List:       kde-commits
Subject:    =?utf-8?q?=5Bkdepim=5D_calendarsupport=3A_Added_support_for_movi?=
From:       Sergio Martins <iamsergio () gmail ! com>
Date:       2011-02-18 20:54:09
Message-ID: 20110218205409.96C5CA609B () git ! kde ! org
[Download RAW message or body]

Git commit a922b8c6e5547782c9cf6e333b7a6ef2cfe49af4 by Sergio Martins.
Committed on 18/02/2011 at 21:49.
Pushed by smartins into branch 'master'.

Added support for moving items between collections.

Basically, by honouring the rowsMoved() signal.
There's still a refresh problem in korganizer, looking into that now.

M  +37   -11   calendarsupport/calendar.cpp     
M  +2    -2    calendarsupport/calendar_p.h     

http://commits.kde.org/kdepim/a922b8c6e5547782c9cf6e333b7a6ef2cfe49af4

diff --git a/calendarsupport/calendar.cpp b/calendarsupport/calendar.cpp
index d88fc48..62b8cfa 100644
--- a/calendarsupport/calendar.cpp
+++ b/calendarsupport/calendar.cpp
@@ -21,12 +21,15 @@
 #include "calendar.h"
 #include "calendar_p.h"
 
+#include "collectionselection.h"
 #include "blockalarmsattribute.h"
 #include "utils.h"
 
 #include <KLocale>
-
+#include <KSelectionProxyModel>
+#include <Akonadi/EntityMimeTypeFilterModel>
 #include <QtCore/QMultiHash>
+#include <QItemSelection>
 
 using namespace CalendarSupport;
 
@@ -76,7 +79,7 @@ Calendar::Private::Private( QAbstractItemModel *treeModel, \
QAbstractItemModel *m  this, SLOT(dataChangedInTreeModel(QModelIndex,QModelIndex)) );
 
   connect( m_treeModel, SIGNAL(rowsMoved(QModelIndex,int,int,QModelIndex,int)),
-           SLOT(onRowsMoved(QModelIndex,int,int,QModelIndex,int)) );
+           SLOT(onRowsMovedInTreeModel(QModelIndex,int,int,QModelIndex,int)) );
 
   /*
   connect( m_monitor, SIGNAL(itemLinked(const Akonadi::Item,Akonadi::Collection)),
@@ -130,8 +133,8 @@ void Calendar::Private::layoutChanged()
 
 }
 
-void Calendar::Private::onRowsMoved( const QModelIndex &sourceParent, int \
                sourceStart, int sourceEnd,
-                                     const QModelIndex &destinationParent, int \
destinationRow ) +void Calendar::Private::onRowsMovedInTreeModel( const QModelIndex \
&sourceParent, int sourceStart, int sourceEnd, +                                      \
const QModelIndex &destinationParent, int destinationRow )  {
   Q_ASSERT( sourceEnd >= sourceStart );
   Q_ASSERT( sourceStart >= 0 );
@@ -145,14 +148,37 @@ void Calendar::Private::onRowsMoved( const QModelIndex \
&sourceParent, int source  const int numItems = sourceEnd - sourceStart + 1;
     Akonadi::Item::List movedItems = itemsFromModel( m_treeModel, destinationParent, \
                destinationRow,
                                                      destinationRow + numItems - 1 \
                );
-    foreach( const Akonadi::Item &item, movedItems ) {
-      if ( item.isValid() && item.hasPayload<KCalCore::Incidence::Ptr>() ) {
-        // We have old items ( that think they belong to another collection ) inside \
                m_itemMap
-        if ( m_itemMap.contains( item.id() ) )
-          m_itemMap.insert( item.id(), item );
-          q->notifyIncidenceChanged( item );
+
+    { // Start hack
+      // KSelectionProxyModel doesn't honour rowsMoved() yet, so, if the source \
model emitted rowsMoved +      // (items changing collection) we could only catch it \
in the onLayoutChanged() slot, which isn't +      // performant. So we listen to the \
source model's rowsMoved() and check manuall if it when in or +      // out of the \
selection, and notify the application. +      Akonadi::EntityMimeTypeFilterModel *m = \
qobject_cast<Akonadi::EntityMimeTypeFilterModel*>( m_model ); +      if ( m ) {
+        KSelectionProxyModel *sm = qobject_cast<KSelectionProxyModel*>( \
m->sourceModel() ); +        if ( sm ) {
+          CollectionSelection collectionSelection( sm->selectionModel() );
+          const bool sourceCollectionIsSelected = collectionSelection.contains( \
sourceCollection.id() ); +          const bool destinationCollectionIsSelected = \
collectionSelection.contains( destinationCollection.id() ); +          if ( \
sourceCollectionIsSelected && destinationCollectionIsSelected ) { +            \
foreach( const Akonadi::Item item, movedItems ) { +              if ( item.isValid() \
&& item.hasPayload<KCalCore::Incidence::Ptr>() ) { +                // We have old \
items ( that think they belong to another collection ) inside m_itemMap +             \
if ( m_itemMap.contains( item.id() ) ) { +                  m_itemMap.insert( \
item.id(), item ); +                }
+                q->notifyIncidenceChanged( item );
+              }
+            }
+          } else if ( !sourceCollectionIsSelected && destinationCollectionIsSelected \
) { // Added +            itemsAdded( movedItems );
+          } else if ( sourceCollectionIsSelected && !destinationCollectionIsSelected \
) { // Removed +            itemsRemoved( movedItems );
+          }
+        }
       }
-    }
+    } // end hack
   }
 }
 
diff --git a/calendarsupport/calendar_p.h b/calendarsupport/calendar_p.h
index 5e88d7e..f9b92de 100644
--- a/calendarsupport/calendar_p.h
+++ b/calendarsupport/calendar_p.h
@@ -152,8 +152,8 @@ class Calendar::Private : public QObject
     void modelReset();
     void dataChanged( const QModelIndex &topLeft, const QModelIndex &bottomRight );
 
-    void onRowsMoved( const QModelIndex &sourceParent, int sourceStart, int \
                sourceEnd,
-                      const QModelIndex &destinationParent, int destinationRow );
+    void onRowsMovedInTreeModel( const QModelIndex &sourceParent, int sourceStart, \
int sourceEnd, +                                 const QModelIndex \
&destinationParent, int destinationRow );  };
 
 }


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

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