asyncselectionhandler_p.h 1.89 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
/*
    Copyright (c) 2009 Tobias Koenig <tokoe@kde.org>

    This library is free software; you can redistribute it and/or modify it
    under the terms of the GNU Library General Public License as published by
    the Free Software Foundation; either version 2 of the License, or (at your
    option) any later version.

    This library is distributed in the hope that it will be useful, but WITHOUT
    ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Library General Public
    License for more details.

    You should have received a copy of the GNU Library General Public License
    along with this library; see the file COPYING.LIB.  If not, write to the
    Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
    02110-1301, USA.
*/

Allen Winter's avatar
Allen Winter committed
20 21
#ifndef AKONADI_ASYNCSELECTIONHANDLER_P_H
#define AKONADI_ASYNCSELECTIONHANDLER_P_H
22

Daniel Vrátil's avatar
Daniel Vrátil committed
23
#include <QObject>
24

25
#include "akonadicore_export.h"
Daniel Vrátil's avatar
Daniel Vrátil committed
26 27
#include "collection.h"
#include "item.h"
28 29 30 31

class QAbstractItemModel;
class QModelIndex;

Laurent Montel's avatar
Laurent Montel committed
32 33
namespace Akonadi
{
34 35 36 37 38 39 40 41 42

/**
 * @internal
 *
 * A helper class to set a current index on a widget with
 * delayed model loading.
 *
 * @author Tobias Koenig <tokoe@kde.org>
 */
43
class AKONADICORE_EXPORT AsyncSelectionHandler : public QObject
44
{
Guy Maurel's avatar
Guy Maurel committed
45
    Q_OBJECT
46

Guy Maurel's avatar
Guy Maurel committed
47
public:
48 49
    /**
     */
Laurent Montel's avatar
Laurent Montel committed
50
    explicit AsyncSelectionHandler(QAbstractItemModel *model, QObject *parent = nullptr);
51 52 53

    ~AsyncSelectionHandler();

Guy Maurel's avatar
Guy Maurel committed
54 55
    void waitForCollection(const Collection &collection);
    void waitForItem(const Item &item);
56

Guy Maurel's avatar
Guy Maurel committed
57 58 59
Q_SIGNALS:
    void collectionAvailable(const QModelIndex &index);
    void itemAvailable(const QModelIndex &index);
60

Guy Maurel's avatar
Guy Maurel committed
61
private Q_SLOTS:
Guy Maurel's avatar
Guy Maurel committed
62
    void rowsInserted(const QModelIndex &parent, int start, int end);
63

Guy Maurel's avatar
Guy Maurel committed
64 65
private:
    bool scanSubTree(const QModelIndex &index, bool searchForItem);
66

67 68 69 70 71 72 73 74
    QAbstractItemModel *mModel;
    Collection mCollection;
    Item mItem;
};

}

#endif