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

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 INDEXVIEW_H
0019 #define INDEXVIEW_H
0020 
0021 #include <QQuickItem>
0022 #include <QQmlComponent>
0023 
0024 class QAbstractItemModel;
0025 
0026 class IndexViewPrivate;
0027 
0028 /**
0029  * This view has a single delegate instance and display data for a single
0030  * QModelIndex.
0031  *
0032  * This is useful for mobile application pages to get more information out of
0033  * a list item. It allows for more compact list while avoiding the boilerplate
0034  * of having a non-model component.
0035  *
0036  * It can also be used to create the equivalent of "editor widgets" from the
0037  * QtWidgets era.
0038  *
0039  * The IndexView will take the implicit width and height of the component
0040  * unless it is resized or in a managed layout, where it will resize the
0041  * delegate.
0042  */
0043 class Q_DECL_EXPORT IndexView : public QQuickItem
0044 {
0045     Q_OBJECT
0046 public:
0047     explicit IndexView(QQuickItem *parent = nullptr);
0048     virtual ~IndexView();
0049 
0050     Q_PROPERTY(QQmlComponent* delegate READ delegate WRITE setDelegate NOTIFY delegateChanged)
0051     Q_PROPERTY(QModelIndex modelIndex READ modelIndex WRITE setModelIndex NOTIFY indexChanged)
0052     Q_PROPERTY(QAbstractItemModel* model READ model NOTIFY indexChanged)
0053 
0054     virtual void setDelegate(QQmlComponent* delegate);
0055     QQmlComponent* delegate() const;
0056 
0057     QAbstractItemModel *model() const;
0058 
0059     QModelIndex modelIndex() const;
0060     void setModelIndex(const QModelIndex &index);
0061 
0062 Q_SIGNALS:
0063     void delegateChanged(QQmlComponent* delegate);
0064     void indexChanged();
0065 
0066 private:
0067     IndexViewPrivate *d_ptr;
0068     Q_DECLARE_PRIVATE(IndexView)
0069 };
0070 
0071 #endif