File indexing completed on 2024-06-23 05:28:19
0001 /* 0002 This file is part of LightDM-KDE. 0003 0004 Copyright 2011, 2012 David Edmundson <kde@davidedmundson.co.uk> 0005 0006 LightDM-KDE is free software: you can redistribute it and/or modify 0007 it under the terms of the GNU General Public License as published by 0008 the Free Software Foundation, either version 3 of the License, or 0009 (at your option) any later version. 0010 0011 LightDM-KDE is distributed in the hope that it will be useful, 0012 but WITHOUT ANY WARRANTY; without even the implied warranty of 0013 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 0014 GNU General Public License for more details. 0015 0016 You should have received a copy of the GNU General Public License 0017 along with LightDM-KDE. If not, see <http://www.gnu.org/licenses/>. 0018 */ 0019 #ifndef EXTRAROWPROXYMODEL_H 0020 #define EXTRAROWPROXYMODEL_H 0021 0022 #include <QSortFilterProxyModel> 0023 #include <QHash> 0024 #include <QVector> 0025 #include <QWeakPointer> 0026 #include <QStandardItemModel> 0027 0028 /** 0029 * A proxy model which makes it possible to append extra rows at the end 0030 */ 0031 class ExtraRowProxyModel : public QAbstractListModel 0032 { 0033 Q_OBJECT 0034 public: 0035 ExtraRowProxyModel(QObject *parent = 0); 0036 0037 int rowCount(const QModelIndex &parent = QModelIndex()) const; // reimp 0038 QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const; // reimp 0039 0040 void setSourceModel(QAbstractItemModel* model); 0041 0042 /** Returns a pointer to the extra row model, which can be edited as appropriate*/ 0043 QStandardItemModel* extraRowModel() const; 0044 0045 private slots: 0046 void onSourceRowsInserted(const QModelIndex &parent,int start,int end); 0047 void onSourceRowsRemoved(const QModelIndex &parent,int start,int end); 0048 void onSourceDataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight); 0049 0050 void onExtraRowsInserted(const QModelIndex &parent,int start,int end); 0051 void onExtraRowsRemoved(const QModelIndex &parent,int start,int end); 0052 void onExtraDataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight); 0053 0054 0055 private: 0056 int sourceRowCount() const; 0057 0058 QWeakPointer<QAbstractItemModel> m_model; 0059 QStandardItemModel *m_extraRowModel; 0060 }; 0061 0062 #endif /* EXTRAROWPROXYMODEL_H */