Filer
Public Member Functions | Protected Member Functions | List of all members
CustomProxyModel Class Reference

A custom proxy model for sorting items in views. More...

#include <CustomProxyModel.h>

Inheritance diagram for CustomProxyModel:
Inheritance graph
[legend]
Collaboration diagram for CustomProxyModel:
Collaboration graph
[legend]

Public Member Functions

 CustomProxyModel (QObject *parent=nullptr)
 Constructs a CustomProxyModel object. More...
 
bool lessThan (const QModelIndex &left, const QModelIndex &right) const override
 Returns whether the item referred to by the given index is less than the item referred to by the given other index. Used for sorting. Sorts mount points before non-mount points. More...
 
void setFilteringEnabled (bool enable)
 Toggles the filtering behavior on/off. More...
 
void setSourceModel (QAbstractItemModel *sourceModel) override
 Sets the source model for the proxy model to sourceModel. We override this because we read the hidden file names from the .hidden file when the source model is set. More...
 
bool dropMimeData (const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent) override
 
Qt::DropActions supportedDropActions () const override
 
Qt::DropActions supportedDragActions () const override
 
Qt::ItemFlags flags (const QModelIndex &index) const override
 
bool canDropMimeData (const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent) const override
 
bool isFilteringEnabled () const
 

Protected Member Functions

bool filterAcceptsRow (int sourceRow, const QModelIndex &sourceParent) const override
 Returns whether the item in the row indicated by the given source row and source parent should be included in the model or whether it should be filtered out. More...
 

Detailed Description

A custom proxy model for sorting items in views.

The CustomProxyModel class provides a custom proxy model for sorting items in views, such as QTreeView or QListView. It extends QSortFilterProxyModel and adds custom behavior like sorting mount points before non-mount points on the desktop.

Constructor & Destructor Documentation

◆ CustomProxyModel()

CustomProxyModel::CustomProxyModel ( QObject *  parent = nullptr)

Constructs a CustomProxyModel object.

Parameters
parentThe parent QObject.

Member Function Documentation

◆ filterAcceptsRow()

bool CustomProxyModel::filterAcceptsRow ( int  sourceRow,
const QModelIndex &  sourceParent 
) const
overrideprotected

Returns whether the item in the row indicated by the given source row and source parent should be included in the model or whether it should be filtered out.

Parameters
sourceRowThe source row.
sourceParentThe source parent.
Returns
True if the item should be included; otherwise returns false.

◆ lessThan()

bool CustomProxyModel::lessThan ( const QModelIndex &  left,
const QModelIndex &  right 
) const
override

Returns whether the item referred to by the given index is less than the item referred to by the given other index. Used for sorting. Sorts mount points before non-mount points.

Parameters
leftThe left index.
rightThe right index.
Returns
True if the item referred to by the left index is less than the item referred to by the right index; otherwise returns false. Mount points come before non-mount points on the desktop.

◆ setFilteringEnabled()

void CustomProxyModel::setFilteringEnabled ( bool  enable)

Toggles the filtering behavior on/off.

Parameters
enableTrue to enable filtering, false to disable it.

◆ setSourceModel()

void CustomProxyModel::setSourceModel ( QAbstractItemModel *  sourceModel)
override

Sets the source model for the proxy model to sourceModel. We override this because we read the hidden file names from the .hidden file when the source model is set.

Parameters
sourceModelThe source model.

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