File indexing completed on 2024-06-16 05:11:12
0001 /* 0002 SPDX-FileCopyrightText: 2022 Fushan Wen <qydwhotmail@gmail.com> 0003 0004 SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 0007 #pragma once 0008 0009 #include <QBindable> 0010 #include <QConcatenateTablesProxyModel> 0011 #include <QSize> 0012 0013 #include <KDirWatch> 0014 0015 #include "imageroles.h" 0016 0017 class AbstractImageListModel; 0018 class ImageListModel; 0019 class PackageListModel; 0020 0021 /** 0022 * A proxy model that aggregates data from ImageListModel and PackageListModel. 0023 */ 0024 class ImageProxyModel : public QConcatenateTablesProxyModel, public ImageRoles 0025 { 0026 Q_OBJECT 0027 0028 Q_PROPERTY(int count READ count NOTIFY countChanged) 0029 0030 public: 0031 explicit ImageProxyModel(const QStringList &customPaths, 0032 const QBindable<QSize> &bindableTargetSize, 0033 const QBindable<bool> &bindableUsedInConfig, 0034 QObject *parent); 0035 0036 QHash<int, QByteArray> roleNames() const override; 0037 0038 int count() const; 0039 Q_INVOKABLE int indexOf(const QString &packagePath) const; 0040 0041 QBindable<bool> loading() const; 0042 0043 Q_INVOKABLE void reload(); 0044 Q_INVOKABLE QStringList addBackground(const QString &_path); 0045 void removeBackground(const QString &packagePath); 0046 0047 Q_INVOKABLE void commitAddition(); 0048 Q_INVOKABLE void commitDeletion(); 0049 0050 Q_INVOKABLE void openContainingFolder(int row) const; 0051 0052 Q_SIGNALS: 0053 void countChanged(); 0054 void loadingChanged(); 0055 0056 private Q_SLOTS: 0057 void slotHandleLoaded(AbstractImageListModel *model); 0058 0059 /** 0060 * Slots to handle file change signals from KDirWatch 0061 */ 0062 void slotDirWatchCreated(const QString &path); 0063 void slotDirWatchDeleted(const QString &path); 0064 0065 private: 0066 /** 0067 * Add files to KDirWatch. 0068 * Files or dirs should be already added to KDirWatch when 0069 * rowsInserted or rowsRemoved is emitted. 0070 */ 0071 void setupDirWatch(); 0072 0073 ImageListModel *m_imageModel; 0074 PackageListModel *m_packageModel; 0075 0076 KDirWatch m_dirWatch; 0077 QStringList m_customPaths; 0078 0079 Q_OBJECT_BINDABLE_PROPERTY_WITH_ARGS(ImageProxyModel, int, m_loaded, 0) 0080 Q_OBJECT_BINDABLE_PROPERTY_WITH_ARGS(ImageProxyModel, bool, m_loading, false, &ImageProxyModel::loadingChanged) 0081 0082 QStringList m_pendingAddition; 0083 0084 friend class ImageProxyModelTest; 0085 };