![]() |
LeechCraft
%{LEECHCRAFT_VERSION}
Modular cross-platform feature rich live environment.
|
#include "mergemodel.h"
Public Types | |
typedef models_t::iterator | iterator |
typedef models_t::const_iterator | const_iterator |
Public Slots | |
virtual void | handleColumnsAboutToBeInserted (const QModelIndex &, int, int) |
virtual void | handleColumnsAboutToBeRemoved (const QModelIndex &, int, int) |
virtual void | handleColumnsInserted (const QModelIndex &, int, int) |
virtual void | handleColumnsRemoved (const QModelIndex &, int, int) |
virtual void | handleDataChanged (const QModelIndex &, const QModelIndex &) |
virtual void | handleRowsAboutToBeInserted (const QModelIndex &, int, int) |
virtual void | handleRowsAboutToBeRemoved (const QModelIndex &, int, int) |
virtual void | handleRowsInserted (const QModelIndex &, int, int) |
virtual void | handleRowsRemoved (const QModelIndex &, int, int) |
Public Member Functions | |
MergeModel (const QStringList &, QObject *=0) | |
virtual | ~MergeModel () |
virtual int | columnCount (const QModelIndex &=QModelIndex()) const |
virtual QVariant | headerData (int, Qt::Orientation, int=Qt::DisplayRole) const |
virtual QVariant | data (const QModelIndex &, int=Qt::DisplayRole) const |
virtual Qt::ItemFlags | flags (const QModelIndex &) const |
virtual QModelIndex | index (int, int, const QModelIndex &=QModelIndex()) const |
virtual QModelIndex | parent (const QModelIndex &) const |
virtual int | rowCount (const QModelIndex &=QModelIndex()) const |
virtual QModelIndex | mapFromSource (const QModelIndex &index) const |
virtual QModelIndex | mapToSource (const QModelIndex &index) const |
virtual void | setSourceModel (QAbstractItemModel *) |
void | SetHeaders (const QStringList &headers) |
void | AddModel (QAbstractItemModel *model) |
void | RemoveModel (QAbstractItemModel *model) |
size_t | Size () const |
const_iterator | FindModel (const QAbstractItemModel *model) const |
iterator | FindModel (const QAbstractItemModel *model) |
int | GetStartingRow (const_iterator it) const |
const_iterator | GetModelForRow (int row, int *starting=0) const |
iterator | GetModelForRow (int row, int *starting=0) |
QList< QAbstractItemModel * > | GetAllModels () const |
Returns all models intalled into this one. More... | |
Protected Types | |
typedef std::deque< QPointer < QAbstractItemModel > > | models_t |
Protected Member Functions | |
virtual bool | AcceptsRow (QAbstractItemModel *model, int row) const |
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 53 of file mergemodel.h.
typedef models_t::const_iterator LeechCraft::Util::MergeModel::const_iterator |
Definition at line 65 of file mergemodel.h.
typedef models_t::iterator LeechCraft::Util::MergeModel::iterator |
Definition at line 64 of file mergemodel.h.
|
protected |
Definition at line 59 of file mergemodel.h.
MergeModel::MergeModel | ( | const QStringList & | headers, |
QObject * | parent = 0 |
||
) |
Definition at line 38 of file mergemodel.cpp.
|
virtual |
Definition at line 45 of file mergemodel.cpp.
|
protectedvirtual |
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.
Definition at line 422 of file mergemodel.cpp.
void MergeModel::AddModel | ( | QAbstractItemModel * | model | ) |
Adds a model to the list of source models. The newly added model is appended to the end.
If the model already exists in the list, it is added again, and bad things would happen, as all the signals and slots would be connected and called twice. So it's your duty to ensure that you don't add the same model more than once.
[in] | model | The model to append to the list. |
Definition at line 181 of file mergemodel.cpp.
References handleColumnsAboutToBeInserted(), handleColumnsAboutToBeRemoved(), handleColumnsInserted(), handleColumnsRemoved(), handleDataChanged(), handleRowsAboutToBeInserted(), handleRowsAboutToBeRemoved(), handleRowsInserted(), handleRowsRemoved(), Models_, and rowCount().
|
virtual |
Definition at line 49 of file mergemodel.cpp.
References mapToSource().
|
virtual |
Definition at line 68 of file mergemodel.cpp.
References mapToSource().
MergeModel::const_iterator 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 250 of file mergemodel.cpp.
References Models_.
Referenced by handleRowsAboutToBeInserted(), handleRowsAboutToBeRemoved(), mapFromSource(), and RemoveModel().
MergeModel::iterator 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 255 of file mergemodel.cpp.
References Models_.
|
virtual |
Definition at line 79 of file mergemodel.cpp.
References mapToSource().
QList< QAbstractItemModel * > 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 338 of file mergemodel.cpp.
References Models_.
MergeModel::const_iterator MergeModel::GetModelForRow | ( | int | row, |
int * | starting = 0 |
||
) | const |
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 298 of file mergemodel.cpp.
References Models_.
Referenced by mapToSource().
MergeModel::iterator MergeModel::GetModelForRow | ( | int | row, |
int * | starting = 0 |
||
) |
This is an overloaded function provided for convenience. Non-const and returns a non-const iterator.
[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 318 of file mergemodel.cpp.
References Models_.
int MergeModel::GetStartingRow | ( | MergeModel::const_iterator | it | ) | const |
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 290 of file mergemodel.cpp.
References Models_.
Referenced by handleRowsAboutToBeInserted(), handleRowsAboutToBeRemoved(), mapFromSource(), and RemoveModel().
|
virtualslot |
Definition at line 347 of file mergemodel.cpp.
Referenced by AddModel().
|
virtualslot |
Definition at line 354 of file mergemodel.cpp.
Referenced by AddModel().
|
virtualslot |
Definition at line 361 of file mergemodel.cpp.
Referenced by AddModel().
|
virtualslot |
Definition at line 368 of file mergemodel.cpp.
Referenced by AddModel().
|
virtualslot |
Definition at line 375 of file mergemodel.cpp.
References mapFromSource().
Referenced by AddModel().
|
virtualslot |
Definition at line 381 of file mergemodel.cpp.
References FindModel(), GetStartingRow(), and mapFromSource().
Referenced by AddModel().
|
virtualslot |
Definition at line 390 of file mergemodel.cpp.
References FindModel(), GetStartingRow(), and mapFromSource().
Referenced by AddModel().
|
virtualslot |
Definition at line 412 of file mergemodel.cpp.
Referenced by AddModel().
|
virtualslot |
Definition at line 417 of file mergemodel.cpp.
Referenced by AddModel().
|
virtual |
Definition at line 60 of file mergemodel.cpp.
|
virtual |
Definition at line 85 of file mergemodel.cpp.
|
virtual |
Returns the model index in the MergeModel given the index from the source model.
[in] | index | Source index. |
Definition at line 117 of file mergemodel.cpp.
References FindModel(), and GetStartingRow().
Referenced by handleDataChanged(), handleRowsAboutToBeInserted(), and handleRowsAboutToBeRemoved().
|
virtual |
Returns the source model index corresponding to the given index from the sorting filter model.
[in] | index | MergeModel's index. |
Definition at line 138 of file mergemodel.cpp.
References GetModelForRow(), and Models_.
Referenced by columnCount(), data(), flags(), and rowCount().
|
virtual |
Definition at line 93 of file mergemodel.cpp.
void 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 260 of file mergemodel.cpp.
References FindModel(), GetStartingRow(), and Models_.
|
virtual |
Definition at line 99 of file mergemodel.cpp.
References mapToSource(), and Models_.
Referenced by AddModel().
void MergeModel::SetHeaders | ( | const QStringList & | headers | ) |
Sets the new headers for this model.
[in] | headers | The new headers. |
Definition at line 176 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 171 of file mergemodel.cpp.
size_t MergeModel::Size | ( | ) | const |
Returns the number of child models in the merger.
Definition at line 285 of file mergemodel.cpp.
References Models_.
|
protected |
Definition at line 60 of file mergemodel.h.
Referenced by AddModel(), FindModel(), GetAllModels(), GetModelForRow(), GetStartingRow(), mapToSource(), RemoveModel(), rowCount(), and Size().