swift
Public Types | Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
swift::gui::models::CListModelBase< T, UseCompare > Class Template Reference

List model. More...

Inheritance diagram for swift::gui::models::CListModelBase< T, UseCompare >:
[legend]

Public Types

using ContainerType = T
 Container type.
 
using ObjectType = typename T::value_type
 Container element type.
 

Public Member Functions

 ~CListModelBase ()=default
 Destructor.
 
virtual bool isValidIndex (const QModelIndex &index) const
 Valid index (in range)
 
const ContainerTypecontainer () const
 Used container data.
 
const ContainerTypecontainerFiltered () const
 Used container data.
 
const ContainerTypecontainerOrFilteredContainer (bool *filtered=nullptr) const
 Full container or cached filtered container as approproiate.
 
bool setInContainer (const QModelIndex &index, const ObjectType &obj)
 Simple set of data in container, using class is responsible for firing signals etc. More...
 
virtual int update (const ContainerType &container, bool sort=true)
 Update by new container. More...
 
virtual swift::misc::CWorkerupdateAsync (const ContainerType &container, bool sort=true)
 Asynchronous update.
 
virtual void updateContainerMaybeAsync (const ContainerType &container, bool sort=true)
 Update by new container.
 
virtual void update (const QModelIndex &index, const ObjectType &object)
 Update single element.
 
virtual void update (int rowIndex, const ObjectType &object)
 Update single element.
 
virtual void moveItems (const ContainerType &items, int position)
 Move items to position, normally called from dropMimeData. More...
 
virtual const ObjectTypeat (const QModelIndex &index) const
 Object at row position.
 
void sort ()
 Sort by given sort order. More...
 
void resort ()
 Sort by given sort order. More...
 
void truncate (int maxNumber, bool forceSort=false)
 Truncate to given number.
 
ContainerType sortContainerByColumn (const ContainerType &container, int column, Qt::SortOrder order) const
 Sort container by given column / order. This is used by sort() but als for asynchronous updates in the views. More...
 
virtual void push_back (const ObjectType &object)
 Similar to ContainerType::push_back.
 
virtual void push_back (const ContainerType &container)
 Similar to ContainerType::push_back.
 
virtual void insert (const ObjectType &object)
 Similar to ContainerType::insert here inserts at first position.
 
virtual void insert (const ContainerType &container)
 Similar to ContainerType::insert here inserts at first position.
 
virtual void remove (const ObjectType &object)
 Remove object.
 
template<class K0 , class V0 , class... KeysValues>
int removeIf (K0 k0, V0 v0, KeysValues... keysValues)
 Remove elements matching some particular key/value pair(s). More...
 
virtual void clear ()
 Clear the list.
 
virtual bool isEmpty () const
 Empty?
 
bool hasFilter () const
 Filter available.
 
void removeFilter ()
 Remove filter.
 
void takeFilterOwnership (std::unique_ptr< IModelFilter< ContainerType >> &filter)
 Set the filter.
 
void setSelectionModel (swift::gui::models::ISelectionModel< ContainerType > *selectionModel)
 Set the selection model.
 
Functions from QStandardItemModel
QVariant data (const QModelIndex &index, int role) const
 
bool setData (const QModelIndex &index, const QVariant &value, int role=Qt::EditRole) final
 
QMimeData * mimeData (const QModelIndexList &indexes) const final
 
void sort (int column, Qt::SortOrder order) final
 
int rowCount (const QModelIndex &parentIndex=QModelIndex()) const final
 
bool canDropMimeData (const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent) const final
 
bool dropMimeData (const QMimeData *mimeData, Qt::DropAction action, int row, int column, const QModelIndex &parent) final
 
Functions from CListModelBaseNonTemplate
QJsonObject toJson (bool selectedOnly=false) const
 Convert to JSON. More...
 
QString toJsonString (QJsonDocument::JsonFormat format=QJsonDocument::Indented, bool selectedOnly=false) const
 Convert to JSON string. More...
 
bool isOrderable () const
 Orderable, normally use a container swift::misc::IOrderableList. More...
 
- Public Member Functions inherited from swift::gui::models::CListModelBaseNonTemplate
 ~CListModelBaseNonTemplate ()=default
 Destructor.
 
virtual swift::misc::CPropertyIndex columnToPropertyIndex (int column) const
 Column to property index.
 
virtual int propertyIndexToColumn (const swift::misc::CPropertyIndex &propertyIndex) const
 Property index to column number.
 
virtual swift::misc::CPropertyIndex modelIndexToPropertyIndex (const QModelIndex &index) const
 Index to property index.
 
virtual void setSortColumn (int column)
 Set sort column.
 
void setNoSorting ()
 Disable sorting.
 
void sortByPropertyIndex (const swift::misc::CPropertyIndex &propertyIndex, Qt::SortOrder order=Qt::AscendingOrder)
 Sort by index.
 
virtual bool setSortColumnByPropertyIndex (const swift::misc::CPropertyIndex &propertyIndex)
 Set column for sorting. More...
 
virtual bool setSorting (const swift::misc::CPropertyIndex &propertyIndex, Qt::SortOrder order=Qt::AscendingOrder)
 Sorting.
 
virtual int getSortColumn () const
 Get sort column property index.
 
swift::misc::CPropertyIndex getSortProperty () const
 Sorted by property.
 
virtual bool hasValidSortColumn () const
 Has valid sort column?
 
virtual Qt::SortOrder getSortOrder () const
 Get sort order.
 
void markDestroyed ()
 Mark as about to be destroyed, normally marked from view.
 
bool isModelDestroyed ()
 Model about to be destroyed?
 
virtual void clearHighlighting ()
 Remove all highlighting.
 
virtual bool hasHighlightedRows () const
 Has highlighted rows?
 
void setDropActions (Qt::DropActions dropActions)
 Drop actions.
 
void emitDataChanged (int startRowIndex, int endRowIndex)
 Send signal that data have been changed. More...
 
const CColumnsgetColumns () const
 The columns.
 
bool endsWithEmptyColumn () const
 Using void column at the end?
 
int columnCount (const QModelIndex &modelIndex=QModelIndex()) const final
 
QVariant headerData (int section, Qt::Orientation orientation, int role) const final
 
QModelIndex index (int row, int column, const QModelIndex &parent=QModelIndex()) const final
 
QModelIndex parent (const QModelIndex &child) const final
 
Qt::ItemFlags flags (const QModelIndex &index) const final
 
Qt::DropActions supportedDragActions () const final
 
Qt::DropActions supportedDropActions () const final
 
QStringList mimeTypes () const final
 
- Public Member Functions inherited from swift::gui::CDropBase
virtual ~CDropBase ()
 Dtor.
 
void setAcceptedMetaTypeIds (const QList< int > &ids)
 Accepted ids.
 
void addAcceptedMetaTypeId (int id)
 Accepted ids.
 
virtual bool isDropAllowed () const
 Drop allowed?
 
virtual bool isJsonFileDropAllowed () const
 File drop allowed?
 
virtual void allowDrop (bool allowed)
 Drop allowed.
 
virtual void allowJsonFileDrop (bool allow)
 Allow JSON file drop.
 
bool acceptDrop (const QMimeData *mime) const
 Accept drop?
 
swift::misc::CVariant toCVariant (const QMimeData *mime) const
 Mime data to CVariant (normally encapsulating a value object)
 

Protected Member Functions

 CListModelBase (const QString &translationContext, QObject *parent=nullptr)
 Constructor.
 
void updateFilteredContainer ()
 Update filtered container.
 
void emitModelDataChanged ()
 Model changed.
 
Base class overrides
void onDataChanged (const QModelIndex &topLeft, const QModelIndex &bottomLeft, const QVector< int > &roles)
 Feedback when QStandardItemModel::dataChanged was called. More...
 
void onChangedDigest ()
 Feedback when QStandardItemModel::dataChanged was called. More...
 
- Protected Member Functions inherited from swift::gui::models::CListModelBaseNonTemplate
 CListModelBaseNonTemplate (const QString &translationContext, QObject *parent=nullptr)
 Constructor. More...
 
- Protected Member Functions inherited from swift::gui::CDropBase
 CDropBase ()
 Ctor.
 

Protected Attributes

ContainerType m_container
 used container
 
ContainerType m_containerFiltered
 cache for filtered container data
 
std::unique_ptr< IModelFilter< ContainerType > > m_filter
 used filter
 
ISelectionModel< ContainerType > * m_selectionModel = nullptr
 selection model
 
- Protected Attributes inherited from swift::gui::models::CListModelBaseNonTemplate
CColumns m_columns
 columns metadata
 
int m_sortColumn
 currently sorted column
 
bool m_modelDestroyed = false
 
Qt::SortOrder m_sortOrder
 sort order (asc/desc)
 
Qt::DropActions m_dropActions = Qt::IgnoreAction
 drop actions
 
swift::misc::CPropertyIndexList m_sortTieBreakers
 how column values are sorted if equal, if no value is given this is random
 

Additional Inherited Members

- Signals inherited from swift::gui::models::CListModelBaseNonTemplate
void asyncUpdateFinished ()
 Asynchronous update finished.
 
void modelDataChanged (int count, bool withFilter)
 Data changed. More...
 
void modelDataChangedDigest (int count, bool withFilter)
 Data changed, digest version.
 
void changed ()
 Model has been changed Triggered with each change, for performance consider using changedDigest.
 
void changedDigest ()
 Model has been changed, digest signal.
 
void objectChanged (const swift::misc::CVariant &object, const swift::misc::CPropertyIndex &changedIndex)
 Template free information, that object changed.
 
- Static Public Attributes inherited from swift::gui::models::CListModelBaseNonTemplate
static constexpr int asyncThreshold = 50
 Number of elements when to use asynchronous updates.
 

Detailed Description

template<typename T, bool UseCompare = false>
class swift::gui::models::CListModelBase< T, UseCompare >

List model.

Definition at line 34 of file listmodelbase.h.

Member Function Documentation

◆ canDropMimeData()

template<typename T , bool UseCompare>
bool swift::gui::models::CListModelBase< T, UseCompare >::canDropMimeData ( const QMimeData *  data,
Qt::DropAction  action,
int  row,
int  column,
const QModelIndex &  parent 
) const
final

Definition at line 36 of file listmodelbase.cpp.

◆ data()

template<typename T , bool UseCompare>
QVariant swift::gui::models::CListModelBase< T, UseCompare >::data ( const QModelIndex &  index,
int  role 
) const

Definition at line 79 of file listmodelbase.cpp.

◆ dropMimeData()

template<typename T , bool UseCompare>
bool swift::gui::models::CListModelBase< T, UseCompare >::dropMimeData ( const QMimeData *  mimeData,
Qt::DropAction  action,
int  row,
int  column,
const QModelIndex &  parent 
)
final

Definition at line 49 of file listmodelbase.cpp.

◆ isOrderable()

template<typename T , bool UseCompare>
bool swift::gui::models::CListModelBase< T, UseCompare >::isOrderable
virtual

Orderable, normally use a container swift::misc::IOrderableList.

Implements swift::gui::models::CListModelBaseNonTemplate.

Definition at line 586 of file listmodelbase.cpp.

◆ mimeData()

template<typename T , bool UseCompare>
QMimeData * swift::gui::models::CListModelBase< T, UseCompare >::mimeData ( const QModelIndexList &  indexes) const
final

Definition at line 543 of file listmodelbase.cpp.

◆ moveItems()

template<typename T , bool UseCompare>
void swift::gui::models::CListModelBase< T, UseCompare >::moveItems ( const ContainerType items,
int  position 
)
virtual

◆ onChangedDigest()

template<typename T , bool UseCompare>
void swift::gui::models::CListModelBase< T, UseCompare >::onChangedDigest
protectedvirtual

Feedback when QStandardItemModel::dataChanged was called.

Implements swift::gui::models::CListModelBaseNonTemplate.

Definition at line 454 of file listmodelbase.cpp.

◆ onDataChanged()

template<typename T , bool UseCompare>
void swift::gui::models::CListModelBase< T, UseCompare >::onDataChanged ( const QModelIndex &  topLeft,
const QModelIndex &  bottomLeft,
const QVector< int > &  roles 
)
protectedvirtual

Feedback when QStandardItemModel::dataChanged was called.

Implements swift::gui::models::CListModelBaseNonTemplate.

Definition at line 443 of file listmodelbase.cpp.

◆ removeIf()

template<typename T , bool UseCompare = false>
template<class K0 , class V0 , class... KeysValues>
int swift::gui::models::CListModelBase< T, UseCompare >::removeIf ( K0  k0,
V0  v0,
KeysValues...  keysValues 
)
inline

Remove elements matching some particular key/value pair(s).

Parameters
k0A pointer to a member function of T.
v0A value to compare against the value returned by k0.
keysValuesZero or more additional pairs of { pointer to member function of T, value to compare it against }.
Returns
The number of elements removed.

Definition at line 162 of file listmodelbase.h.

◆ resort()

template<typename T , bool UseCompare>
void swift::gui::models::CListModelBase< T, UseCompare >::resort

Sort by given sort order.

See also
getSortColumn()
getSortOrder()
Remarks
always sorts, even if columns did no change

Definition at line 476 of file listmodelbase.cpp.

◆ rowCount()

template<typename T , bool UseCompare>
int swift::gui::models::CListModelBase< T, UseCompare >::rowCount ( const QModelIndex &  parentIndex = QModelIndex()) const
final

Definition at line 29 of file listmodelbase.cpp.

◆ setData()

template<typename T , bool UseCompare>
bool swift::gui::models::CListModelBase< T, UseCompare >::setData ( const QModelIndex &  index,
const QVariant &  value,
int  role = Qt::EditRole 
)
final

Definition at line 112 of file listmodelbase.cpp.

◆ setInContainer()

template<typename T , bool UseCompare>
bool swift::gui::models::CListModelBase< T, UseCompare >::setInContainer ( const QModelIndex &  index,
const ObjectType obj 
)

Simple set of data in container, using class is responsible for firing signals etc.

See also
sendDataChanged

Definition at line 144 of file listmodelbase.cpp.

◆ sort() [1/2]

template<typename T , bool UseCompare>
void swift::gui::models::CListModelBase< T, UseCompare >::sort

Sort by given sort order.

See also
getSortColumn()
getSortOrder()

Definition at line 470 of file listmodelbase.cpp.

◆ sort() [2/2]

template<typename T , bool UseCompare>
void swift::gui::models::CListModelBase< T, UseCompare >::sort ( int  column,
Qt::SortOrder  order 
)
final

Definition at line 483 of file listmodelbase.cpp.

◆ sortContainerByColumn()

template<typename T , bool UseCompare>
CListModelBase< T, UseCompare >::ContainerType swift::gui::models::CListModelBase< T, UseCompare >::sortContainerByColumn ( const ContainerType container,
int  column,
Qt::SortOrder  order 
) const

Sort container by given column / order. This is used by sort() but als for asynchronous updates in the views.

Parameters
containerused list
columncolumn inder
ordersort order (ascending / descending)
Remarks
This function is thread safe. under normal conditions thread safe as long as the column metadata are not changed
Todo:
workaround T579 still not thread-safe, but less likely to crash

Definition at line 514 of file listmodelbase.cpp.

◆ toJson()

template<typename T , bool UseCompare>
QJsonObject swift::gui::models::CListModelBase< T, UseCompare >::toJson ( bool  selectedOnly = false) const
virtual

Convert to JSON.

Implements swift::gui::models::CListModelBaseNonTemplate.

Definition at line 570 of file listmodelbase.cpp.

◆ toJsonString()

template<typename T , bool UseCompare>
QString swift::gui::models::CListModelBase< T, UseCompare >::toJsonString ( QJsonDocument::JsonFormat  format = QJsonDocument::Indented,
bool  selectedOnly = false 
) const
virtual

Convert to JSON string.

Implements swift::gui::models::CListModelBaseNonTemplate.

Definition at line 578 of file listmodelbase.cpp.

◆ update()

template<typename T , bool UseCompare>
int swift::gui::models::CListModelBase< T, UseCompare >::update ( const ContainerType container,
bool  sort = true 
)
virtual

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