20 #include "asyncselectionhandler_p.h"
22 #include <akonadi/entitytreemodel.h>
24 using namespace Akonadi;
26 AsyncSelectionHandler::AsyncSelectionHandler( QAbstractItemModel *model, QObject *parent )
27 : QObject( parent ), mModel( model )
31 connect( mModel, SIGNAL(rowsInserted(QModelIndex,
int,
int)),
32 this, SLOT(rowsInserted(QModelIndex,
int,
int)) );
35 AsyncSelectionHandler::~AsyncSelectionHandler()
39 bool AsyncSelectionHandler::scanSubTree(
const QModelIndex &index,
bool searchForItem )
41 if ( searchForItem ) {
44 if ( mItem.id() == id ) {
45 emit itemAvailable( index );
51 if ( mCollection.
id() == id ) {
52 emit collectionAvailable( index );
57 for (
int row = 0; row < mModel->rowCount( index ); ++row ) {
58 const QModelIndex childIndex = mModel->index( row, 0, index );
59 if ( scanSubTree( childIndex, searchForItem ) ) {
67 void AsyncSelectionHandler::waitForCollection(
const Collection &collection )
69 mCollection = collection;
71 scanSubTree( QModelIndex(),
false );
74 void AsyncSelectionHandler::waitForItem(
const Item &item )
78 scanSubTree( QModelIndex(),
true );
81 void AsyncSelectionHandler::rowsInserted(
const QModelIndex &parent,
int start,
int end )
83 for (
int i = start; i <= end; ++i ) {
84 scanSubTree( mModel->index( i, 0, parent ), false );
85 scanSubTree( mModel->index( i, 0, parent ), true );
89 #include "moc_asyncselectionhandler_p.cpp"
Represents a collection of PIM items.
qint64 Id
Describes the unique id type.
Id id() const
Returns the unique identifier of the entity.