File indexing completed on 2024-04-28 04:41:52
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 LISTVIEW_H 0019 #define LISTVIEW_H 0020 0021 // KQuickItemViews 0022 #include <KQuickItemViews/singlemodelviewbase.h> 0023 class ListViewPrivate; 0024 class ListView; 0025 0026 // Qt 0027 class QQuickItem; 0028 0029 /** 0030 * Equivalent of the QtQuick.ListView.Section class to keep the API mostly 0031 * compatible. 0032 * 0033 * A section model can be set. If it does, this class doesn't do *any* check if 0034 * the section model matches the sections. It is entirely the responsibility of 0035 * the programmer to provide a valid/compatible model. 0036 */ 0037 class Q_DECL_EXPORT ListViewSections : public QObject 0038 { 0039 Q_OBJECT 0040 0041 friend class ListView; 0042 public: 0043 Q_PROPERTY(QQmlComponent* delegate READ delegate WRITE setDelegate) 0044 Q_PROPERTY(QString property READ property WRITE setProperty) 0045 Q_PROPERTY(QStringList roles READ roles WRITE setRoles ) 0046 Q_PROPERTY(int role READ role ) 0047 0048 Q_PROPERTY(QSharedPointer<QAbstractItemModel> model READ model WRITE setModel) 0049 0050 explicit ListViewSections(ListView* parent); 0051 virtual ~ListViewSections(); 0052 0053 QQmlComponent* delegate() const; 0054 void setDelegate(QQmlComponent* component); 0055 0056 QString property() const; 0057 void setProperty(const QString& property); 0058 0059 QStringList roles() const; 0060 void setRoles(const QStringList& list); 0061 0062 QSharedPointer<QAbstractItemModel> model() const; 0063 void setModel(const QSharedPointer<QAbstractItemModel>& m); 0064 0065 int role() const; 0066 0067 private: 0068 ListViewPrivate* d_ptr; 0069 }; 0070 0071 Q_DECLARE_METATYPE(ListViewSections*) 0072 0073 /** 0074 * Re-implementation of QtQuick.ListView. 0075 * 0076 * Why: 0077 * 0078 * * The original is not capable of generating a proper "table of content" and 0079 * scrollbar. 0080 * * The "section" support of the original system is limited to a single string, 0081 * this is useless for some use cases. 0082 * * The section didn't support getting the metadata, such as the number of 0083 * entries (lazy loaded, of course). 0084 * * Real drag and drop (QMimeData and models) are not supported 0085 * * Models are generally badly supported. 0086 * * The QtQuick.ListView is remotely close enough to a drop-in replacement for 0087 * QtWidgets::QListView. Stable and mature models should not require modifications 0088 * to acknowledge misguided QtQuick.ListView changes. 0089 */ 0090 class Q_DECL_EXPORT ListView : public SingleModelViewBase 0091 { 0092 Q_OBJECT 0093 0094 friend class ListViewItem; 0095 friend class ListViewSections; 0096 public: 0097 Q_PROPERTY(ListViewSections* section READ section CONSTANT) 0098 Q_PROPERTY(int count READ count /*NOTIFY contentChanged*/) 0099 Q_PROPERTY(int currentIndex READ currentIndex WRITE setCurrentIndex NOTIFY indexChanged) 0100 0101 explicit ListView(QQuickItem* parent = nullptr); 0102 virtual ~ListView(); 0103 0104 ListViewSections* section() const; 0105 0106 int count() const; 0107 0108 int currentIndex() const; 0109 void setCurrentIndex(int index); 0110 0111 protected: 0112 virtual void applyModelChanges(QAbstractItemModel* m); 0113 0114 Q_SIGNALS: 0115 void indexChanged(int index); 0116 0117 private: 0118 0119 ListViewPrivate* d_ptr; 0120 Q_DECLARE_PRIVATE(ListView) 0121 }; 0122 0123 #endif