LeechCraft  0.6.70-13605-g8cd066ad6a
Modular cross-platform feature rich live environment.
LC::Util::MergeModel Class Reference

#include "mergemodel.h"

+ Inheritance diagram for LC::Util::MergeModel:
+ Collaboration diagram for LC::Util::MergeModel:

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)
 
virtual void handleModelAboutToBeReset ()
 
virtual void handleModelReset ()
 

Public Member Functions

 MergeModel (const QStringList &headers, QObject *parent=0)
 Constructs the merge model. More...
 
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. More...
 
QMimeData * mimeData (const QModelIndexList &indices) const override
 Returns the MIME data for the given indices. More...
 
virtual QModelIndex mapFromSource (const QModelIndex &index) const
 Returns the model index in the MergeModel given the index from the source model. More...
 
virtual QModelIndex mapToSource (const QModelIndex &index) const
 Returns the source model index corresponding to the given index from the sorting filter model. More...
 
virtual void setSourceModel (QAbstractItemModel *)
 
void SetHeaders (const QStringList &headers)
 Sets the new headers for this model. More...
 
void AddModel (QAbstractItemModel *model)
 Adds a model to the list of source models. More...
 
void RemoveModel (QAbstractItemModel *model)
 Removes a model from the list of source models. More...
 
size_t Size () const
 Returns the number of child models in the merger. More...
 
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. More...
 
iterator FindModel (const QAbstractItemModel *model)
 This is an overloaded function provided for convenience. Non-const and returns a non-const iterator. More...
 
int GetStartingRow (const_iterator it) const
 Finds starting row for the model pointed by it. More...
 
const_iterator GetModelForRow (int row, int *starting=0) const
 Returns the model for the given row. More...
 
iterator GetModelForRow (int row, int *starting=0)
 This is an overloaded function provided for convenience. More...
 
QList< QAbstractItemModel * > GetAllModels () const
 Returns all models intalled into this one. More...
 

Protected Types

typedef QList< QPointer< QAbstractItemModel > > models_t
 

Protected Member Functions

virtual bool AcceptsRow (QAbstractItemModel *model, int row) const
 Allows to filter rows from the resulting model. More...
 

Protected Attributes

models_t Models_
 

Detailed Description

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 109 of file mergemodel.h.

Member Typedef Documentation

◆ const_iterator

typedef models_t::const_iterator LC::Util::MergeModel::const_iterator

Definition at line 151 of file mergemodel.h.

◆ iterator

typedef models_t::iterator LC::Util::MergeModel::iterator

Definition at line 150 of file mergemodel.h.

◆ models_t

typedef QList<QPointer<QAbstractItemModel> > LC::Util::MergeModel::models_t
protected

Definition at line 141 of file mergemodel.h.

Constructor & Destructor Documentation

◆ MergeModel()

LC::Util::MergeModel::MergeModel ( const QStringList &  headers,
QObject *  parent = 0 
)

Constructs the merge model.

Sets the given headers and parent object.

Parameters
[in]headersThe headers of the model.
[in]parentThe parent object of the model.

Definition at line 93 of file mergemodel.cpp.

Member Function Documentation

◆ AcceptsRow()

bool LC::Util::MergeModel::AcceptsRow ( QAbstractItemModel *  model,
int  row 
) const
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.

Parameters
[in]modelThe source model the row belongs.
[in]rowThe row index in the source model.
Returns
Whether the given row should be displayed.

Definition at line 563 of file mergemodel.cpp.

◆ AddModel()

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.

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.

Parameters
[in]modelThe model to append to the list.

Definition at line 281 of file mergemodel.cpp.

◆ columnCount()

int LC::Util::MergeModel::columnCount ( const QModelIndex &  index = QModelIndex ()) const
override

Definition at line 100 of file mergemodel.cpp.

◆ data()

QVariant LC::Util::MergeModel::data ( const QModelIndex &  index,
int  role = Qt::DisplayRole 
) const
override

Definition at line 119 of file mergemodel.cpp.

◆ FindModel() [1/2]

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.

Parameters
[in]modelThe model to find.
Returns
The iterator.

Definition at line 357 of file mergemodel.cpp.

◆ FindModel() [2/2]

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.

Parameters
[in]modelThe model to find.
Returns
The iterator.

Definition at line 352 of file mergemodel.cpp.

Referenced by handleRowsInserted().

+ Here is the caller graph for this function:

◆ flags()

Qt::ItemFlags LC::Util::MergeModel::flags ( const QModelIndex &  index) const
override

Definition at line 136 of file mergemodel.cpp.

◆ GetAllModels()

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.

Returns
The list of models.

Definition at line 422 of file mergemodel.cpp.

◆ GetModelForRow() [1/2]

MergeModel::iterator LC::Util::MergeModel::GetModelForRow ( int  row,
int *  starting = 0 
)

This is an overloaded function provided for convenience.

Parameters
[in]rowThe row that should be identified.
[in,out]startingThe pointer to variable that will store the starting row, if not null.
Returns
Iterator associated with the model.
Exceptions
std::runtime_errorThrows if there is no model for such row.

Definition at line 411 of file mergemodel.cpp.

◆ GetModelForRow() [2/2]

MergeModel::const_iterator LC::Util::MergeModel::GetModelForRow ( int  row,
int *  starting = 0 
) 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.

Parameters
[in]rowThe row that should be identified.
[in,out]startingThe pointer to variable that will store the starting row, if not null.
Returns
Iterator associated with the model.
Exceptions
std::runtime_errorThrows if there is no model for such row.

Definition at line 400 of file mergemodel.cpp.

References mapFromSource().

+ Here is the call graph for this function:

◆ 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.

Parameters
[in]itThe iterator corresponding to the model.
Returns
The starting row.

Definition at line 392 of file mergemodel.cpp.

Referenced by handleRowsInserted().

+ Here is the caller graph for this function:

◆ handleColumnsAboutToBeInserted

void LC::Util::MergeModel::handleColumnsAboutToBeInserted ( const QModelIndex &  ,
int  ,
int   
)
virtualslot

Definition at line 431 of file mergemodel.cpp.

◆ handleColumnsAboutToBeRemoved

void LC::Util::MergeModel::handleColumnsAboutToBeRemoved ( const QModelIndex &  ,
int  ,
int   
)
virtualslot

Definition at line 435 of file mergemodel.cpp.

◆ handleColumnsInserted

void LC::Util::MergeModel::handleColumnsInserted ( const QModelIndex &  ,
int  ,
int   
)
virtualslot

Definition at line 441 of file mergemodel.cpp.

◆ handleColumnsRemoved

void LC::Util::MergeModel::handleColumnsRemoved ( const QModelIndex &  ,
int  ,
int   
)
virtualslot

Definition at line 445 of file mergemodel.cpp.

◆ handleDataChanged

void LC::Util::MergeModel::handleDataChanged ( const QModelIndex &  topLeft,
const QModelIndex &  bottomRight 
)
virtualslot

Definition at line 451 of file mergemodel.cpp.

◆ handleModelAboutToBeReset

void LC::Util::MergeModel::handleModelAboutToBeReset ( )
virtualslot

Definition at line 535 of file mergemodel.cpp.

◆ handleModelReset

void LC::Util::MergeModel::handleModelReset ( )
virtualslot

Definition at line 547 of file mergemodel.cpp.

◆ handleRowsAboutToBeInserted

void LC::Util::MergeModel::handleRowsAboutToBeInserted ( const QModelIndex &  parent,
int  first,
int  last 
)
virtualslot

Definition at line 457 of file mergemodel.cpp.

References parent().

+ Here is the call graph for this function:

◆ handleRowsAboutToBeRemoved

void LC::Util::MergeModel::handleRowsAboutToBeRemoved ( const QModelIndex &  parent,
int  first,
int  last 
)
virtualslot

Definition at line 469 of file mergemodel.cpp.

◆ handleRowsInserted

void LC::Util::MergeModel::handleRowsInserted ( const QModelIndex &  parent,
int  first,
int  last 
)
virtualslot

Definition at line 495 of file mergemodel.cpp.

References FindModel(), and GetStartingRow().

+ Here is the call graph for this function:

◆ handleRowsRemoved

void LC::Util::MergeModel::handleRowsRemoved ( const QModelIndex &  ,
int  ,
int   
)
virtualslot

Definition at line 529 of file mergemodel.cpp.

◆ headerData()

QVariant LC::Util::MergeModel::headerData ( int  column,
Qt::Orientation  orient,
int  role = Qt::DisplayRole 
) const
override

Definition at line 111 of file mergemodel.cpp.

References index(), and parent().

+ Here is the call graph for this function:

◆ index()

QModelIndex LC::Util::MergeModel::index ( int  row,
int  column,
const QModelIndex &  parent = QModelIndex () 
) const
override

Definition at line 150 of file mergemodel.cpp.

Referenced by headerData().

+ Here is the caller graph for this function:

◆ mapFromSource()

QModelIndex LC::Util::MergeModel::mapFromSource ( const QModelIndex &  index) const
virtual

Returns the model index in the MergeModel given the index from the source model.

Parameters
[in]indexSource index.
Returns
MergeModel's index.

Definition at line 231 of file mergemodel.cpp.

Referenced by GetModelForRow().

+ Here is the caller graph for this function:

◆ mapToSource()

QModelIndex LC::Util::MergeModel::mapToSource ( const QModelIndex &  index) const
virtual

Returns the source model index corresponding to the given index from the sorting filter model.

Parameters
[in]indexMergeModel's index.
Returns
Source index.

Definition at line 261 of file mergemodel.cpp.

◆ mimeData()

QMimeData * LC::Util::MergeModel::mimeData ( const QModelIndexList &  indices) const
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.

Parameters
[in]indicesThe indices for which to return the MIME data.
Returns
The MIME data.

Definition at line 206 of file mergemodel.cpp.

◆ mimeTypes()

QStringList LC::Util::MergeModel::mimeTypes ( ) const
override

Returns the union of MIME types of the models.

Returns
The union of all the MIME types.

Definition at line 184 of file mergemodel.cpp.

References parent().

+ Here is the call graph for this function:

◆ parent()

QModelIndex LC::Util::MergeModel::parent ( const QModelIndex &  index) const
override

Definition at line 162 of file mergemodel.cpp.

Referenced by handleRowsAboutToBeInserted(), headerData(), and mimeTypes().

+ Here is the caller graph for this function:

◆ RemoveModel()

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.

Parameters
[in]modelThe model to remove from the list.

Definition at line 362 of file mergemodel.cpp.

◆ rowCount()

int LC::Util::MergeModel::rowCount ( const QModelIndex &  parent = QModelIndex ()) const
override

Definition at line 175 of file mergemodel.cpp.

◆ SetHeaders()

void LC::Util::MergeModel::SetHeaders ( const QStringList &  headers)

Sets the new headers for this model.

Parameters
[in]headersThe new headers.

Definition at line 276 of file mergemodel.cpp.

◆ setSourceModel()

void LC::Util::MergeModel::setSourceModel ( QAbstractItemModel *  )
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.

Exceptions
std::runtime_errorNo matter what, you'd get it.

Definition at line 271 of file mergemodel.cpp.

◆ Size()

size_t LC::Util::MergeModel::Size ( ) const

Returns the number of child models in the merger.

Returns
The number of child models.

Definition at line 387 of file mergemodel.cpp.

Member Data Documentation

◆ Models_

models_t LC::Util::MergeModel::Models_
protected

Definition at line 142 of file mergemodel.h.


The documentation for this class was generated from the following files: