![]() |
LeechCraft 0.6.70-19214-g121e5318a7
Modular cross-platform feature rich live environment.
|
#include "mergemodel.h"
Public Types | |
| using | iterator = models_t::iterator |
| using | const_iterator = models_t::const_iterator |
Public Member Functions | |
| MergeModel (QStringList headers, QObject *parent=nullptr) | |
| Constructs the merge model. | |
| int | columnCount (const QModelIndex &=QModelIndex()) const override |
| QVariant | headerData (int, Qt::Orientation, int=Qt::DisplayRole) const override |
| QVariant | data (const QModelIndex &, int=Qt::DisplayRole) const override |
| Qt::ItemFlags | flags (const QModelIndex &) const override |
| QModelIndex | index (int, int, const QModelIndex &=QModelIndex()) const override |
| QModelIndex | parent (const QModelIndex &) const override |
| int | rowCount (const QModelIndex &=QModelIndex()) const override |
| QStringList | mimeTypes () const override |
| Returns the union of MIME types of the models. | |
| QMimeData * | mimeData (const QModelIndexList &indices) const override |
| Returns the MIME data for the given indices. | |
| virtual QModelIndex | mapFromSource (const QModelIndex &index) const |
| Returns the model index in the MergeModel given the index from the source model. | |
| virtual QModelIndex | mapToSource (const QModelIndex &index) const |
| Returns the source model index corresponding to the given index from the sorting filter model. | |
| virtual void | setSourceModel (QAbstractItemModel *) |
| void | SetHeaders (const QStringList &headers) |
| Sets the new headers for this model. | |
| void | AddModel (QAbstractItemModel *model) |
| Adds a model to the list of source models. | |
| void | RemoveModel (QAbstractItemModel *model) |
| Removes a model from the list of source models. | |
| size_t | Size () const |
| Returns the number of child models in the merger. | |
| 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. | |
| iterator | FindModel (const QAbstractItemModel *model) |
| This is an overloaded function provided for convenience. Non-const and returns a non-const iterator. | |
| int | GetStartingRow (const_iterator it) const |
| Finds starting row for the model pointed by it. | |
| int | GetStartingRow (iterator it) |
| Finds starting row for the model pointed by it. | |
| const_iterator | GetModelForRow (int row, int *starting=nullptr) const |
| Returns the model for the given row. | |
| iterator | GetModelForRow (int row, int *starting=nullptr) |
| This is an overloaded function provided for convenience. | |
| QList< QAbstractItemModel * > | GetAllModels () const |
| Returns all models intalled into this one. | |
Protected Types | |
| using | models_t = QList<QPointer<QAbstractItemModel>> |
Protected Member Functions | |
| virtual void | HandleRowsAboutToBeInserted (QAbstractItemModel *, const QModelIndex &, int, int) |
| virtual void | HandleRowsAboutToBeRemoved (QAbstractItemModel *, const QModelIndex &, int, int) |
| virtual void | HandleRowsInserted (QAbstractItemModel *, const QModelIndex &, int, int) |
| virtual void | HandleRowsRemoved (QAbstractItemModel *, const QModelIndex &, int, int) |
| virtual void | HandleModelAboutToBeReset (QAbstractItemModel *) |
| virtual void | HandleModelReset (QAbstractItemModel *) |
| virtual bool | AcceptsRow (QAbstractItemModel *model, int row) const |
| Allows to filter rows from the resulting model. | |
Protected Attributes | |
| models_t | Models_ |
Merges data from multiple source models into one resulting model and provides means to lookup models by row, get starting rows for a model etc.
To add a new source model, one should use AddModel() as setSourceModel() throws an std::runtime_error exception.
Currently it doesn't support hierarchical source models. Seems like it would never support it at least someone would try to implement it.
Definition at line 34 of file mergemodel.h.
| using LC::Util::MergeModel::const_iterator = models_t::const_iterator |
Definition at line 48 of file mergemodel.h.
| using LC::Util::MergeModel::iterator = models_t::iterator |
Definition at line 47 of file mergemodel.h.
|
protected |
Definition at line 38 of file mergemodel.h.
|
explicit |
Constructs the merge model.
Sets the given headers and parent object.
| [in] | headers | The headers of the model. |
| [in] | parent | The parent object of the model. |
Definition at line 20 of file mergemodel.cpp.
References LC::Util::InstallModelSanitizer(), and parent().
Referenced by AddModel().
|
protectedvirtual |
Allows to filter rows from the resulting model.
This virtual function could be overridden to provide custom filtering facilities. If the row in the model should be merged into the resulting model, this function should return true, otherwise if it returns false the row would be filtered out.
| [in] | model | The source model the row belongs. |
| [in] | row | The row index in the source model. |
Definition at line 451 of file mergemodel.cpp.
| void LC::Util::MergeModel::AddModel | ( | QAbstractItemModel * | model | ) |
Adds a model to the list of source models.
The newly added model is appended to the end.
Adding a model that is already in the list is an invariant violation, as its signals would be connected and handled twice, and is reported via qFatal().
| [in] | model | The model to append to the list. |
Definition at line 202 of file mergemodel.cpp.
References MergeModel(), FindModel(), HandleModelAboutToBeReset(), HandleModelReset(), HandleRowsAboutToBeInserted(), HandleRowsAboutToBeRemoved(), HandleRowsInserted(), HandleRowsRemoved(), mapFromSource(), Models_, and rowCount().
|
override |
Definition at line 28 of file mergemodel.cpp.
References index(), and mapToSource().
|
override |
Definition at line 44 of file mergemodel.cpp.
References index(), and mapToSource().
| MergeModel::iterator LC::Util::MergeModel::FindModel | ( | const QAbstractItemModel * | model | ) |
This is an overloaded function provided for convenience. Non-const and returns a non-const iterator.
| [in] | model | The model to find. |
Definition at line 273 of file mergemodel.cpp.
References Models_.
| MergeModel::const_iterator LC::Util::MergeModel::FindModel | ( | const QAbstractItemModel * | model | ) | const |
Returns a const_iterator corresponding to the passed model, or one-past-end if no such model is found.
| [in] | model | The model to find. |
Definition at line 268 of file mergemodel.cpp.
References Models_.
Referenced by AddModel(), GetModelForRow(), GetModelForRow(), HandleModelAboutToBeReset(), HandleModelReset(), HandleRowsAboutToBeInserted(), HandleRowsAboutToBeRemoved(), HandleRowsInserted(), and RemoveModel().
|
override |
Definition at line 61 of file mergemodel.cpp.
References index(), and mapToSource().
| QList< QAbstractItemModel * > LC::Util::MergeModel::GetAllModels | ( | ) | const |
Returns all models intalled into this one.
Only those models that are not null (and, thus, haven't been destroyed) are returned in the list. This list is guaranteed to contain only valid objects.
Definition at line 346 of file mergemodel.cpp.
References Models_.
Referenced by mimeTypes().
| MergeModel::iterator LC::Util::MergeModel::GetModelForRow | ( | int | row, |
| int * | starting = nullptr ) |
This is an overloaded function provided for convenience.
| [in] | row | The row that should be identified. |
| [in,out] | starting | The pointer to variable that will store the starting row, if not null. |
| std::runtime_error | Throws if there is no model for such row. |
Definition at line 335 of file mergemodel.cpp.
References FindModel(), and GetStartingRow().
| MergeModel::const_iterator LC::Util::MergeModel::GetModelForRow | ( | int | row, |
| int * | starting = nullptr ) const |
Returns the model for the given row.
Returns the model that corresponds to the given row. If there is no such model, throws std::runtime_error. If starting is not null, it also calculates and returns the starting row for the returned model. This allows one to avoid calling GetStartingRow() after this function and thus speed things up.
| [in] | row | The row that should be identified. |
| [in,out] | starting | The pointer to variable that will store the starting row, if not null. |
| std::runtime_error | Throws if there is no model for such row. |
Definition at line 324 of file mergemodel.cpp.
References FindModel(), and GetStartingRow().
| int LC::Util::MergeModel::GetStartingRow | ( | MergeModel::const_iterator | it | ) | const |
Finds starting row for the model pointed by it.
Returns the row in the resulting MergeModel from which do begin rows which belong to the model corresponding to the given const_iterator.
| [in] | it | The iterator corresponding to the model. |
Definition at line 308 of file mergemodel.cpp.
References Models_.
Referenced by GetModelForRow(), GetModelForRow(), HandleModelAboutToBeReset(), HandleModelReset(), HandleRowsAboutToBeInserted(), HandleRowsAboutToBeRemoved(), and HandleRowsInserted().
| int LC::Util::MergeModel::GetStartingRow | ( | MergeModel::iterator | it | ) |
Finds starting row for the model pointed by it.
Returns the row in the resulting MergeModel from which do begin rows which belong to the model corresponding to the given const_iterator.
| [in] | it | The iterator corresponding to the model. |
Definition at line 316 of file mergemodel.cpp.
References Models_.
|
protectedvirtual |
Definition at line 425 of file mergemodel.cpp.
References FindModel(), and GetStartingRow().
Referenced by AddModel().
|
protectedvirtual |
Definition at line 436 of file mergemodel.cpp.
References FindModel(), and GetStartingRow().
Referenced by AddModel().
|
protectedvirtual |
Definition at line 355 of file mergemodel.cpp.
References FindModel(), GetStartingRow(), mapFromSource(), and parent().
Referenced by AddModel().
|
protectedvirtual |
Definition at line 364 of file mergemodel.cpp.
References LC::Util::ModelItemBase< T >::EraseChildren(), FindModel(), GetStartingRow(), mapFromSource(), and parent().
Referenced by AddModel().
|
protectedvirtual |
Definition at line 387 of file mergemodel.cpp.
References FindModel(), GetStartingRow(), mapFromSource(), and parent().
Referenced by AddModel().
|
protectedvirtual |
Definition at line 419 of file mergemodel.cpp.
Referenced by AddModel().
|
override |
Definition at line 36 of file mergemodel.cpp.
|
override |
Definition at line 75 of file mergemodel.cpp.
References parent().
Referenced by columnCount(), data(), flags(), mimeData(), and parent().
|
virtual |
Returns the model index in the MergeModel given the index from the source model.
| [in] | index | Source index. |
Definition at line 152 of file mergemodel.cpp.
References parent().
Referenced by AddModel(), HandleRowsAboutToBeInserted(), HandleRowsAboutToBeRemoved(), and HandleRowsInserted().
|
virtual |
Returns the source model index corresponding to the given index from the sorting filter model.
| [in] | index | MergeModel's index. |
Definition at line 182 of file mergemodel.cpp.
References LC::Util::ModelItem::GetIndex().
Referenced by columnCount(), data(), flags(), and mimeData().
|
override |
Returns the MIME data for the given indices.
This function queries the corresponding source model for each index of the indices, merging the URL list (if any) and using first obtained data of any other format.
| [in] | indices | The indices for which to return the MIME data. |
Definition at line 131 of file mergemodel.cpp.
References index(), and mapToSource().
|
override |
Returns the union of MIME types of the models.
Definition at line 109 of file mergemodel.cpp.
References GetAllModels().
|
override |
Definition at line 87 of file mergemodel.cpp.
References index(), and parent().
Referenced by MergeModel(), HandleRowsAboutToBeInserted(), HandleRowsAboutToBeRemoved(), HandleRowsInserted(), index(), mapFromSource(), parent(), and rowCount().
| void LC::Util::MergeModel::RemoveModel | ( | QAbstractItemModel * | model | ) |
Removes a model from the list of source models.
If there is no such model, this function does nothing.
| [in] | model | The model to remove from the list. |
Definition at line 278 of file mergemodel.cpp.
References FindModel(), and Models_.
|
override |
Definition at line 100 of file mergemodel.cpp.
References LC::Util::ModelItem::GetModel(), and parent().
Referenced by AddModel().
| void LC::Util::MergeModel::SetHeaders | ( | const QStringList & | headers | ) |
Sets the new headers for this model.
| [in] | headers | The new headers. |
Definition at line 197 of file mergemodel.cpp.
|
virtual |
You shouldn't use this function because its semantics in the context of multiple source models aren't clearly defined. Calling this function results in std::runtime_error.
| std::runtime_error | No matter what, you'd get it. |
Definition at line 192 of file mergemodel.cpp.
| size_t LC::Util::MergeModel::Size | ( | ) | const |
Returns the number of child models in the merger.
Definition at line 303 of file mergemodel.cpp.
References Models_.
|
protected |
Definition at line 39 of file mergemodel.h.
Referenced by AddModel(), FindModel(), FindModel(), GetAllModels(), GetStartingRow(), GetStartingRow(), RemoveModel(), and Size().