File indexing completed on 2024-05-19 16:31:38
0001 /* 0002 * SPDX-FileCopyrightText: 2015 Dominik Haumann <dhaumann@kde.org> 0003 * 0004 * SPDX-License-Identifier: LGPL-2.1-or-later 0005 */ 0006 #ifndef PLASMA_QUOTA_LIST_MODEL_H 0007 #define PLASMA_QUOTA_LIST_MODEL_H 0008 0009 #include <QAbstractListModel> 0010 #include <QVector> 0011 0012 #include "QuotaItem.h" 0013 0014 /** 0015 * Data model holding disk quota items. 0016 */ 0017 class QuotaListModel : public QAbstractListModel 0018 { 0019 Q_OBJECT 0020 0021 public: 0022 explicit QuotaListModel(QObject *parent = nullptr); 0023 0024 public: // QAbstractListModel overrides 0025 /** 0026 * List of available roles for the QML ListView. 0027 */ 0028 QHash<int, QByteArray> roleNames() const override; 0029 0030 /** 0031 * Returns the data for @p index and given @p role. 0032 */ 0033 QVariant data(const QModelIndex &index, int role) const override; 0034 0035 /** 0036 * Returns the number of items for the toplevel model index, otherwise 0. 0037 */ 0038 int rowCount(const QModelIndex &index) const override; 0039 0040 /** 0041 * Changes the data for @p index to @p variant. 0042 */ 0043 bool setData(const QModelIndex &index, const QVariant &variant, int role = Qt::EditRole) override; 0044 0045 /** 0046 * Inserts @p count rows at position @p row. 0047 */ 0048 bool insertRows(int row, int count, const QModelIndex &parent = QModelIndex()) override; 0049 0050 /** 0051 * Removes @p count rows at position @p row. 0052 */ 0053 bool removeRows(int row, int count, const QModelIndex &parent = QModelIndex()) override; 0054 0055 public: // additional helper functions 0056 /** 0057 * Merges @p items into the existing quota item list. Old items that are 0058 * not available in @p items anymore are deleted. 0059 */ 0060 void updateItems(const QVector<QuotaItem> &items); 0061 0062 /** 0063 * Clears all items in the model. 0064 */ 0065 void clear(); 0066 0067 private: 0068 QVector<QuotaItem> m_items; 0069 }; 0070 0071 #endif // PLASMA_QUOTA_LIST_MODEL_H