digiKam
Digikam::AlbumFilterModel Class Reference
+ Inheritance diagram for Digikam::AlbumFilterModel:

Public Types

enum  FilterBehavior { SimpleFiltering , FullFiltering , StrictFiltering }
 
enum  MatchResult {
  NoMatch = 0 , DirectMatch , ParentMatch , ChildMatch ,
  SpecialMatch
}
 

Public Slots

void setSearchTextSettings (const SearchTextSettings &settings)
 

Signals

void hasSearchResult (bool hasResult)
 
void searchTextSettingsAboutToChange (bool searched, bool willSearch)
 
void searchTextSettingsChanged (bool wasSearching, bool searched)
 
void signalFilterChanged ()
 

Public Member Functions

 AlbumFilterModel (QObject *const parent=nullptr)
 
AlbumalbumForIndex (const QModelIndex &index) const
 Convenience methods. More...
 
QVariant dataForCurrentSortRole (Album *album) const
 
QModelIndex indexForAlbum (Album *album) const
 
virtual bool isFiltering () const
 
QModelIndex mapFromSourceAlbumModel (const QModelIndex &index) const
 
QModelIndex mapToSourceAlbumModel (const QModelIndex &index) const
 
MatchResult matchResult (const QModelIndex &index) const
 
QModelIndex rootAlbumIndex () const
 
SearchTextSettings searchTextSettings () const
 
void setFilterBehavior (FilterBehavior behavior)
 
void setSourceAlbumModel (AbstractAlbumModel *const source)
 
void setSourceFilterModel (AlbumFilterModel *const source)
 
AbstractAlbumModelsourceAlbumModel () const
 
AlbumFilterModelsourceFilterModel () const
 
void updateFilter ()
 

Static Public Member Functions

template<typename T >
static int compareByOrder (const T &a, const T &b, Qt::SortOrder sortOrder)
 
static int compareByOrder (int compareResult, Qt::SortOrder sortOrder)
 
template<typename T >
static int compareValue (const T &a, const T &b)
 

Protected Slots

void slotAlbumRenamed (Album *album)
 
void slotAlbumsHaveBeenUpdated (int type)
 

Protected Member Functions

bool filterAcceptsRow (int source_row, const QModelIndex &source_parent) const override
 
bool lessThan (const QModelIndex &left, const QModelIndex &right) const override
 
virtual bool matches (Album *album) const
 
MatchResult matchResult (Album *album) const
 
void setSourceModel (QAbstractItemModel *const model) override
 

Protected Attributes

QPointer< AlbumFilterModelm_chainedModel
 
FilterBehavior m_filterBehavior
 
QObject * m_parent
 
SearchTextSettings m_settings
 

Member Enumeration Documentation

◆ FilterBehavior

Enumerator
SimpleFiltering 

If an index does not matched, the index and all its children are filtered out. This is the Qt default behavior, but undesirable for album trees.

FullFiltering 

Default behavior. If an index matches, it is shown, which directly means all its parents are shown as well. In addition, all its children are shown as well.

StrictFiltering 

If an index matches, it is shown, which directly means all its parents are shown as well. Its children are not shown unless they also match.

◆ MatchResult

Enumerator
NoMatch 

This enum can be used as a boolean value if match/no match only is needed.

DirectMatch 

The index itself is matched.

ParentMatch 

A parent if the index is matched.

ChildMatch 

A child of the index is matched.

SpecialMatch 

The index is matched not because of search settings, but because it has a special type.

Constructor & Destructor Documentation

◆ AlbumFilterModel()

Digikam::AlbumFilterModel::AlbumFilterModel ( QObject *const  parent = nullptr)
explicit

Member Function Documentation

◆ albumForIndex()

◆ compareByOrder() [1/2]

template<typename T >
static int Digikam::AlbumFilterModel::compareByOrder ( const T a,
const T b,
Qt::SortOrder  sortOrder 
)
inlinestatic

◆ compareByOrder() [2/2]

static int Digikam::AlbumFilterModel::compareByOrder ( int  compareResult,
Qt::SortOrder  sortOrder 
)
inlinestatic

Takes a typical result from a compare method (0 is equal, -1 is less than, 1 is greater than) and applies the given sort order to it.

Referenced by lessThan().

◆ compareValue()

template<typename T >
static int Digikam::AlbumFilterModel::compareValue ( const T a,
const T b 
)
inlinestatic

Returns the usual compare result of -1, 0, or 1 for lessThan, equals and greaterThan.

◆ dataForCurrentSortRole()

◆ filterAcceptsRow()

bool Digikam::AlbumFilterModel::filterAcceptsRow ( int  source_row,
const QModelIndex &  source_parent 
) const
overrideprotected

◆ hasSearchResult

void Digikam::AlbumFilterModel::hasSearchResult ( bool  hasResult)
signal

Indicates whether the newly applied filter results in a search result or not.

Parameters
hasResulttrue if the new filter matches any album, else false

Referenced by setSearchTextSettings().

◆ indexForAlbum()

QModelIndex Digikam::AlbumFilterModel::indexForAlbum ( Album album) const

◆ isFiltering()

bool Digikam::AlbumFilterModel::isFiltering ( ) const
virtual

Returns if the currently applied filters will result in any filtering.

Returns
true if the current selected filter could result in any filtering without checking if this really happens.

Reimplemented in Digikam::TagPropertiesFilterModel, Digikam::SearchFilterModel, and Digikam::CheckableAlbumFilterModel.

References m_settings.

Referenced by Digikam::CheckableAlbumFilterModel::isFiltering(), and updateFilter().

◆ lessThan()

◆ mapFromSourceAlbumModel()

QModelIndex Digikam::AlbumFilterModel::mapFromSourceAlbumModel ( const QModelIndex &  index) const

References m_chainedModel.

Referenced by indexForAlbum(), and rootAlbumIndex().

◆ mapToSourceAlbumModel()

QModelIndex Digikam::AlbumFilterModel::mapToSourceAlbumModel ( const QModelIndex &  index) const

◆ matches()

bool Digikam::AlbumFilterModel::matches ( Album album) const
protectedvirtual

This method provides the basic match checking algorithm. Return true if this single album matches the current criteria. This method can be overridden to provide custom filtering.

Parameters
albumthe album to tell if it matches the filter criteria or not.

Reimplemented in Digikam::TagsManagerFilterModel, Digikam::TagPropertiesFilterModel, Digikam::SearchFilterModel, and Digikam::CheckableAlbumFilterModel.

References Digikam::AbstractAlbumModel::AlbumTitleRole, Digikam::SearchTextSettings::caseSensitive, Digikam::AbstractAlbumModel::indexForAlbum(), m_chainedModel, m_settings, sourceAlbumModel(), and Digikam::SearchTextSettings::text.

Referenced by Digikam::CheckableAlbumFilterModel::matches(), and matchResult().

◆ matchResult() [1/2]

AlbumFilterModel::MatchResult Digikam::AlbumFilterModel::matchResult ( Album album) const
protected

Returns if the filter matches this album (same logic as filterAcceptsRow). An album matches if the search text settings are found in a parent album's title, in the album's title or in a child album's title, or if it is a special album (root) that is never filtered out.

References ChildMatch, Digikam::AlbumIterator::current(), DirectMatch, FullFiltering, Digikam::PAlbum::isAlbumRoot(), Digikam::TAlbum::isInternalTag(), Digikam::Album::isRoot(), m_filterBehavior, matches(), NoMatch, Digikam::Album::parent(), ParentMatch, SimpleFiltering, and SpecialMatch.

◆ matchResult() [2/2]

AlbumFilterModel::MatchResult Digikam::AlbumFilterModel::matchResult ( const QModelIndex &  index) const

Returns the MatchResult of an index of this model. Never returns NoMatch for a valid index, because in this case, the index would rather be filtered out.

References albumForIndex().

Referenced by Digikam::AbstractAlbumTreeView::expandMatches(), and filterAcceptsRow().

◆ rootAlbumIndex()

◆ searchTextSettings()

SearchTextSettings Digikam::AlbumFilterModel::searchTextSettings ( ) const

Returns the settings currently used for filtering.

Returns
current settings for filtering.

References m_settings.

◆ searchTextSettingsAboutToChange

void Digikam::AlbumFilterModel::searchTextSettingsAboutToChange ( bool  searched,
bool  willSearch 
)
signal

This signal indicates that a new SearchTextSettings arrived and is about to be applied to the model.

Parameters
searchedtrue if filtering by text was enabled before applying the new settings
willSearchtrue if the new settings can result in any filtering by text, else false.

Referenced by setSearchTextSettings().

◆ searchTextSettingsChanged

void Digikam::AlbumFilterModel::searchTextSettingsChanged ( bool  wasSearching,
bool  searched 
)
signal

Indicates that new search text settings were applied.

Parameters
wasSearchingtrue if this is not a new search that
searchedtrue if the new settings result in any filtering

Referenced by setSearchTextSettings().

◆ setFilterBehavior()

void Digikam::AlbumFilterModel::setFilterBehavior ( FilterBehavior  behavior)

Sets the filter behavior. Default is FullFiltering.

References m_filterBehavior.

◆ setSearchTextSettings

void Digikam::AlbumFilterModel::setSearchTextSettings ( const SearchTextSettings settings)
slot

Accepts new settings used for filtering and applies them to the model.

Parameters
settingsnew settings to apply. An empty text will be interpreted as no filtering

References hasSearchResult(), m_settings, Digikam::Album::PHYSICAL, rootAlbumIndex(), searchTextSettingsAboutToChange(), searchTextSettingsChanged(), signalFilterChanged(), sourceAlbumModel(), and Digikam::SearchTextSettings::text.

Referenced by Digikam::AbstractAlbumTreeView::setSearchTextSettings().

◆ setSourceAlbumModel()

void Digikam::AlbumFilterModel::setSourceAlbumModel ( AbstractAlbumModel *const  source)

Sets the source model. Note: If a chained filter model is set, it will not be reset, but the source album model will be made source of the chained filter model.

References m_chainedModel, and setSourceModel().

Referenced by Digikam::AbstractAlbumTreeView::setAlbumFilterModel(), Digikam::AbstractAlbumTreeView::setAlbumModel(), Digikam::SearchFilterModel::setSourceAlbumModel(), Digikam::CheckableAlbumFilterModel::setSourceAlbumModel(), and setSourceFilterModel().

◆ setSourceFilterModel()

void Digikam::AlbumFilterModel::setSourceFilterModel ( AlbumFilterModel *const  source)

Sets a chained filter model. Note: If a direct source album model is set as current source, it will be set as sourceAlbumModel of the new source filter model.

References m_chainedModel, setSourceAlbumModel(), setSourceModel(), and sourceAlbumModel().

Referenced by Digikam::CheckableAlbumFilterModel::setSourceFilterModel().

◆ setSourceModel()

void Digikam::AlbumFilterModel::setSourceModel ( QAbstractItemModel *const  model)
overrideprotected

Use setSourceAlbumModel.

See also
setSourceAlbumModel
Parameters
modelsource model

Referenced by setSourceAlbumModel(), and setSourceFilterModel().

◆ signalFilterChanged

◆ slotAlbumRenamed

void Digikam::AlbumFilterModel::slotAlbumRenamed ( Album album)
protectedslot

◆ slotAlbumsHaveBeenUpdated

void Digikam::AlbumFilterModel::slotAlbumsHaveBeenUpdated ( int  type)
protectedslot

References sourceAlbumModel().

Referenced by AlbumFilterModel(), and slotAlbumRenamed().

◆ sourceAlbumModel()

◆ sourceFilterModel()

AlbumFilterModel * Digikam::AlbumFilterModel::sourceFilterModel ( ) const

References m_chainedModel.

◆ updateFilter()

void Digikam::AlbumFilterModel::updateFilter ( )

Force invalidateFilter() externally.

References isFiltering().

Member Data Documentation

◆ m_chainedModel

◆ m_filterBehavior

FilterBehavior Digikam::AlbumFilterModel::m_filterBehavior
protected

Referenced by matchResult(), and setFilterBehavior().

◆ m_parent

QObject* Digikam::AlbumFilterModel::m_parent
protected

◆ m_settings

SearchTextSettings Digikam::AlbumFilterModel::m_settings
protected

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