File indexing completed on 2024-04-14 04:36:55

0001 /***************************************************************************
0002  *   Copyright (C) 2018 by Emmanuel Lepage Vallee                          *
0003  *   Author : Emmanuel Lepage Vallee <emmanuel.lepage@kde.org>             *
0004  *                                                                         *
0005  *   This program is free software; you can redistribute it and/or modify  *
0006  *   it under the terms of the GNU General Public License as published by  *
0007  *   the Free Software Foundation; either version 3 of the License, or     *
0008  *   (at your option) any later version.                                   *
0009  *                                                                         *
0010  *   This program is distributed in the hope that it will be useful,       *
0011  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
0012  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
0013  *   GNU General Public License for more details.                          *
0014  *                                                                         *
0015  *   You should have received a copy of the GNU General Public License     *
0016  *   along with this program.  If not, see <http://www.gnu.org/licenses/>. *
0017  **************************************************************************/
0018 #ifndef KQUICKITEMVIEWS_QMODELINDEXWATCHER_H
0019 #define KQUICKITEMVIEWS_QMODELINDEXWATCHER_H
0020 
0021 #include <QtCore/QObject>
0022 #include <QtCore/QModelIndex>
0023 
0024 class QAbstractItemModel;
0025 class QModelIndexWatcherPrivate;
0026 
0027 /**
0028  * This class allows to get events on a QModelIndex from QML.
0029  */
0030 class Q_DECL_EXPORT QModelIndexWatcher : public QObject
0031 {
0032     Q_OBJECT
0033 public:
0034     explicit QModelIndexWatcher(QObject *parent = nullptr);
0035     virtual ~QModelIndexWatcher();
0036 
0037     Q_PROPERTY(bool valid READ isValid NOTIFY validChanged)
0038     Q_PROPERTY(QModelIndex modelIndex READ modelIndex WRITE setModelIndex NOTIFY indexChanged)
0039     Q_PROPERTY(QAbstractItemModel* model READ model NOTIFY validChanged)
0040 
0041     QModelIndex modelIndex() const;
0042     void setModelIndex(const QModelIndex &index);
0043 
0044     QAbstractItemModel *model() const;
0045 
0046     bool isValid() const;
0047 
0048 Q_SIGNALS:
0049     void removed();
0050     void moved();
0051     void dataChanged(const QVector<int>& roles);
0052     void validChanged();
0053     void indexChanged();
0054 
0055 private:
0056     QModelIndexWatcherPrivate *d_ptr;
0057     Q_DECLARE_PRIVATE(QModelIndexWatcher)
0058 };
0059 
0060 #endif