2010-05-09 17:51:04 +02:00
|
|
|
/* This file is part of Clementine.
|
2014-11-02 19:36:21 +01:00
|
|
|
Copyright 2010-2011, David Sansome <davidsansome@gmail.com>
|
|
|
|
Copyright 2014, Krzysztof Sobiecki <sobkas@gmail.com>
|
|
|
|
Copyright 2014, John Maguire <john.maguire@gmail.com>
|
2010-05-09 17:51:04 +02:00
|
|
|
|
|
|
|
Clementine is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
Clementine is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with Clementine. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2014-11-01 19:26:05 +01:00
|
|
|
#ifndef CORE_MERGEDPROXYMODEL_H_
|
|
|
|
#define CORE_MERGEDPROXYMODEL_H_
|
2010-05-09 17:51:04 +02:00
|
|
|
|
2014-02-06 17:44:29 +01:00
|
|
|
#include <QAbstractProxyModel>
|
2020-09-18 16:15:19 +02:00
|
|
|
#include <memory>
|
2010-05-09 17:51:04 +02:00
|
|
|
|
|
|
|
std::size_t hash_value(const QModelIndex& index);
|
|
|
|
|
2014-02-06 17:44:29 +01:00
|
|
|
class MergedProxyModelPrivate;
|
|
|
|
|
2010-05-09 17:51:04 +02:00
|
|
|
class MergedProxyModel : public QAbstractProxyModel {
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
public:
|
2014-11-01 19:26:05 +01:00
|
|
|
explicit MergedProxyModel(QObject* parent = nullptr);
|
2010-05-09 17:53:28 +02:00
|
|
|
~MergedProxyModel();
|
2010-05-09 17:51:04 +02:00
|
|
|
|
2010-05-09 19:53:27 +02:00
|
|
|
// Make another model appear as a child of the given item in the source model.
|
2014-02-07 16:34:20 +01:00
|
|
|
void AddSubModel(const QModelIndex& source_parent,
|
|
|
|
QAbstractItemModel* submodel);
|
2010-07-04 02:33:34 +02:00
|
|
|
void RemoveSubModel(const QModelIndex& source_parent);
|
2010-05-09 17:51:04 +02:00
|
|
|
|
2010-05-09 19:53:27 +02:00
|
|
|
// Find the item in the source model that is the parent of the model
|
|
|
|
// containing proxy_index. If proxy_index is in the source model, then
|
|
|
|
// this just returns mapToSource(proxy_index).
|
|
|
|
QModelIndex FindSourceParent(const QModelIndex& proxy_index) const;
|
|
|
|
|
2010-05-09 17:51:04 +02:00
|
|
|
// QAbstractItemModel
|
2014-02-07 16:34:20 +01:00
|
|
|
QModelIndex index(int row, int column, const QModelIndex& parent) const;
|
|
|
|
QModelIndex parent(const QModelIndex& child) const;
|
|
|
|
int rowCount(const QModelIndex& parent) const;
|
|
|
|
int columnCount(const QModelIndex& parent) const;
|
|
|
|
QVariant data(const QModelIndex& proxyIndex,
|
|
|
|
int role = Qt::DisplayRole) const;
|
|
|
|
bool hasChildren(const QModelIndex& parent) const;
|
|
|
|
QMap<int, QVariant> itemData(const QModelIndex& proxyIndex) const;
|
|
|
|
Qt::ItemFlags flags(const QModelIndex& index) const;
|
|
|
|
bool setData(const QModelIndex& index, const QVariant& value, int role);
|
2010-05-09 19:19:48 +02:00
|
|
|
QStringList mimeTypes() const;
|
2014-02-07 16:34:20 +01:00
|
|
|
QMimeData* mimeData(const QModelIndexList& indexes) const;
|
|
|
|
bool dropMimeData(const QMimeData* data, Qt::DropAction action, int row,
|
|
|
|
int column, const QModelIndex& parent);
|
|
|
|
bool canFetchMore(const QModelIndex& parent) const;
|
2010-05-11 20:01:30 +02:00
|
|
|
void fetchMore(const QModelIndex& parent);
|
2010-05-09 17:51:04 +02:00
|
|
|
|
|
|
|
// QAbstractProxyModel
|
2010-05-09 19:53:27 +02:00
|
|
|
// Note that these implementations of map{To,From}Source will not always
|
|
|
|
// give you an index in sourceModel(), you might get an index in one of the
|
|
|
|
// child models instead.
|
2014-02-07 16:34:20 +01:00
|
|
|
QModelIndex mapFromSource(const QModelIndex& sourceIndex) const;
|
|
|
|
QModelIndex mapToSource(const QModelIndex& proxyIndex) const;
|
|
|
|
void setSourceModel(QAbstractItemModel* sourceModel);
|
2010-05-09 17:51:04 +02:00
|
|
|
|
2011-01-10 23:26:13 +01:00
|
|
|
// Convenience functions that call map{To,From}Source multiple times.
|
|
|
|
QModelIndexList mapFromSource(const QModelIndexList& source_indexes) const;
|
|
|
|
QModelIndexList mapToSource(const QModelIndexList& proxy_indexes) const;
|
|
|
|
|
2014-11-01 19:26:05 +01:00
|
|
|
signals:
|
2010-05-17 01:44:33 +02:00
|
|
|
void SubModelReset(const QModelIndex& root, QAbstractItemModel* model);
|
|
|
|
|
2010-05-09 17:51:04 +02:00
|
|
|
private slots:
|
|
|
|
void SourceModelReset();
|
2020-12-21 09:06:51 +01:00
|
|
|
void SubModelAboutToBeReset();
|
2010-05-09 17:51:04 +02:00
|
|
|
void SubModelReset();
|
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
void RowsAboutToBeInserted(const QModelIndex& source_parent, int start,
|
|
|
|
int end);
|
2010-05-09 17:51:04 +02:00
|
|
|
void RowsInserted(const QModelIndex& source_parent, int start, int end);
|
2014-02-07 16:34:20 +01:00
|
|
|
void RowsAboutToBeRemoved(const QModelIndex& source_parent, int start,
|
|
|
|
int end);
|
2010-05-09 17:51:04 +02:00
|
|
|
void RowsRemoved(const QModelIndex& source_parent, int start, int end);
|
2014-02-07 16:34:20 +01:00
|
|
|
void DataChanged(const QModelIndex& top_left,
|
|
|
|
const QModelIndex& bottom_right);
|
2010-05-09 17:51:04 +02:00
|
|
|
|
2010-09-18 14:33:23 +02:00
|
|
|
void LayoutAboutToBeChanged();
|
|
|
|
void LayoutChanged();
|
|
|
|
|
2010-05-09 17:51:04 +02:00
|
|
|
private:
|
|
|
|
QModelIndex GetActualSourceParent(const QModelIndex& source_parent,
|
2010-05-11 20:01:30 +02:00
|
|
|
QAbstractItemModel* model) const;
|
|
|
|
QAbstractItemModel* GetModel(const QModelIndex& source_index) const;
|
2010-05-09 17:53:28 +02:00
|
|
|
void DeleteAllMappings();
|
2010-12-29 00:21:56 +01:00
|
|
|
bool IsKnownModel(const QAbstractItemModel* model) const;
|
2010-05-09 17:51:04 +02:00
|
|
|
|
2010-09-18 14:33:23 +02:00
|
|
|
QMap<QAbstractItemModel*, QPersistentModelIndex> merge_points_;
|
2010-05-11 20:01:30 +02:00
|
|
|
QAbstractItemModel* resetting_model_;
|
2010-09-18 14:33:23 +02:00
|
|
|
|
|
|
|
QMap<QAbstractItemModel*, QModelIndex> old_merge_points_;
|
2014-02-06 17:44:29 +01:00
|
|
|
|
|
|
|
std::unique_ptr<MergedProxyModelPrivate> p_;
|
2010-05-09 17:51:04 +02:00
|
|
|
};
|
|
|
|
|
2014-11-01 19:26:05 +01:00
|
|
|
#endif // CORE_MERGEDPROXYMODEL_H_
|