File indexing completed on 2024-04-28 04:41:48

0001 /***************************************************************************
0002  *   Copyright (C) 2017 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_SELECTIONADAPTER_H
0019 #define KQUICKITEMVIEWS_SELECTIONADAPTER_H
0020 
0021 // Qt
0022 #include <QtCore/QObject>
0023 class QItemSelectionModel;
0024 class QQmlComponent;
0025 
0026 // KQuickItemViews
0027 #include <adapters/contextadapter.h>
0028 class SelectionAdapterSyncInterface;
0029 class SelectionAdapterPrivate;
0030 class ContextExtension;
0031 namespace StateTracker {
0032     class ViewItem;
0033 }
0034 
0035 /**
0036  * This class adds support for multi-selection using selection models.
0037  *
0038  * It must be attached to a single instance of a `ViewBase` object.
0039  */
0040 class SelectionAdapter : public QObject
0041 {
0042     Q_OBJECT
0043     friend class ModelAdapter; // Notify of all relevant events
0044     friend class ModelAdapterPrivate; // Notify of all relevant events
0045     friend class StateTracker::ViewItem; // Notify of all relevant events
0046     friend class SelectionAdapterSyncInterface; // Its own internals
0047 public:
0048     explicit SelectionAdapter(QObject* parent = nullptr);
0049     virtual ~SelectionAdapter();
0050 
0051     QQmlComponent* highlight() const;
0052     void setHighlight(QQmlComponent* h);
0053 
0054     QSharedPointer<QItemSelectionModel> selectionModel() const;
0055     void setSelectionModel(QSharedPointer<QItemSelectionModel> sm);
0056 
0057     ContextExtension *contextExtension() const;
0058 
0059 Q_SIGNALS:
0060     void currentIndexChanged(const QModelIndex& index);
0061     void selectionModelChanged() const;
0062 
0063 private:
0064     SelectionAdapterSyncInterface* s_ptr;
0065     SelectionAdapterPrivate* d_ptr;
0066     Q_DECLARE_PRIVATE(SelectionAdapter);
0067 };
0068 
0069 #endif