LeechCraft 0.6.70-16373-g319c272718
Modular cross-platform feature rich live environment.
Loading...
Searching...
No Matches
mergemodel.h
Go to the documentation of this file.
1/**********************************************************************
2 * LeechCraft - modular cross-platform feature rich internet client.
3 * Copyright (C) 2006-2014 Georg Rudoy
4 *
5 * Distributed under the Boost Software License, Version 1.0.
6 * (See accompanying file LICENSE or copy at https://www.boost.org/LICENSE_1_0.txt)
7 **********************************************************************/
8
9#pragma once
10
11#include <functional>
12#include <QPointer>
13#include <QAbstractProxyModel>
14#include <QStringList>
15#include <QStack>
16#include "modelsconfig.h"
17#include "modelitem.h"
18
19namespace LC::Util
20{
34 class UTIL_MODELS_API MergeModel : public QAbstractItemModel
35 {
36 mutable bool DefaultAcceptsRowImpl_ = false;
37 protected:
40 private:
41 QStringList Headers_;
42
43 ModelItem_ptr Root_;
44
45 QStack<std::function<void ()>> RemovalRefreshers_;
46 public:
47 using iterator = models_t::iterator;
48 using const_iterator = models_t::const_iterator;
49
57 explicit MergeModel (QStringList headers, QObject *parent = nullptr);
58
59 int columnCount (const QModelIndex& = QModelIndex ()) const override;
60 QVariant headerData (int, Qt::Orientation, int = Qt::DisplayRole) const override;
61 QVariant data (const QModelIndex&, int = Qt::DisplayRole) const override;
62 Qt::ItemFlags flags (const QModelIndex&) const override;
63 QModelIndex index (int, int, const QModelIndex& = QModelIndex ()) const override;
64 QModelIndex parent (const QModelIndex&) const override;
65 int rowCount (const QModelIndex& = QModelIndex ()) const override;
66
71 QStringList mimeTypes () const override;
72
83 QMimeData* mimeData (const QModelIndexList& indices) const override;
84
91 virtual QModelIndex mapFromSource (const QModelIndex& index) const;
92
99 virtual QModelIndex mapToSource (const QModelIndex& index) const;
100
109 virtual void setSourceModel (QAbstractItemModel*);
110
115 void SetHeaders (const QStringList& headers);
116
129 void AddModel (QAbstractItemModel *model);
130
137 void RemoveModel (QAbstractItemModel *model);
138
143 size_t Size () const;
144
151 const_iterator FindModel (const QAbstractItemModel *model) const;
152
159 iterator FindModel (const QAbstractItemModel *model);
160
170 int GetStartingRow (const_iterator it) const;
171
181 int GetStartingRow (iterator it);
182
200 const_iterator GetModelForRow (int row, int *starting = nullptr) const;
201
213 iterator GetModelForRow (int row, int *starting = nullptr);
214
224 protected:
225 virtual void HandleRowsAboutToBeInserted (QAbstractItemModel*, const QModelIndex&, int, int);
226 virtual void HandleRowsAboutToBeRemoved (QAbstractItemModel*, const QModelIndex&, int, int);
227 virtual void HandleRowsInserted (QAbstractItemModel*, const QModelIndex&, int, int);
228 virtual void HandleRowsRemoved (QAbstractItemModel*, const QModelIndex&, int, int);
229 virtual void HandleModelAboutToBeReset (QAbstractItemModel*);
230 virtual void HandleModelReset (QAbstractItemModel*);
231
244 virtual bool AcceptsRow (QAbstractItemModel *model, int row) const;
245 private:
246 int RowCount (QAbstractItemModel*) const;
247 };
248}
QList< QAbstractItemModel * > GetAllModels() const
Returns all models intalled into this one.
QModelIndex index(int, int, const QModelIndex &=QModelIndex()) const override
const_iterator FindModel(const QAbstractItemModel *model) const
Returns a const_iterator corresponding to the passed model, or one-past-end if no such model is found...
virtual bool AcceptsRow(QAbstractItemModel *model, int row) const
Allows to filter rows from the resulting model.
QList< QPointer< QAbstractItemModel > > models_t
Definition mergemodel.h:38
const_iterator GetModelForRow(int row, int *starting=nullptr) const
Returns the model for the given row.
virtual void HandleRowsAboutToBeInserted(QAbstractItemModel *, const QModelIndex &, int, int)
void AddModel(QAbstractItemModel *model)
Adds a model to the list of source models.
QMimeData * mimeData(const QModelIndexList &indices) const override
Returns the MIME data for the given indices.
virtual void HandleModelReset(QAbstractItemModel *)
size_t Size() const
Returns the number of child models in the merger.
virtual void HandleModelAboutToBeReset(QAbstractItemModel *)
virtual void setSourceModel(QAbstractItemModel *)
int GetStartingRow(const_iterator it) const
Finds starting row for the model pointed by it.
virtual void HandleRowsAboutToBeRemoved(QAbstractItemModel *, const QModelIndex &, int, int)
QModelIndex parent(const QModelIndex &) const override
virtual void HandleRowsRemoved(QAbstractItemModel *, const QModelIndex &, int, int)
virtual QModelIndex mapToSource(const QModelIndex &index) const
Returns the source model index corresponding to the given index from the sorting filter model.
void RemoveModel(QAbstractItemModel *model)
Removes a model from the list of source models.
int columnCount(const QModelIndex &=QModelIndex()) const override
int rowCount(const QModelIndex &=QModelIndex()) const override
void SetHeaders(const QStringList &headers)
Sets the new headers for this model.
Qt::ItemFlags flags(const QModelIndex &) const override
models_t::const_iterator const_iterator
Definition mergemodel.h:48
virtual QModelIndex mapFromSource(const QModelIndex &index) const
Returns the model index in the MergeModel given the index from the source model.
QStringList mimeTypes() const override
Returns the union of MIME types of the models.
models_t::iterator iterator
Definition mergemodel.h:47
QVariant data(const QModelIndex &, int=Qt::DisplayRole) const override
MergeModel(QStringList headers, QObject *parent=nullptr)
Constructs the merge model.
virtual void HandleRowsInserted(QAbstractItemModel *, const QModelIndex &, int, int)
QVariant headerData(int, Qt::Orientation, int=Qt::DisplayRole) const override
#define UTIL_MODELS_API
std::shared_ptr< ModelItem > ModelItem_ptr
Definition modelitem.h:19