-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
79 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
#include "libraryfilterproxy.h" | ||
#include "librarymodel.h" | ||
#include <QDebug> | ||
|
||
|
||
LibraryFilterProxy::LibraryFilterProxy(QObject *parent) | ||
: QSortFilterProxyModel(parent) | ||
{ | ||
|
||
} | ||
|
||
bool LibraryFilterProxy::filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const | ||
{ | ||
// Here we can specify whatever filter logic we need to and can check multiple Roles. Below | ||
// we are simply checking the Value role to see if that value stored there is even, if so include the | ||
// data entry in this proxy model. | ||
if ( this->sourceModel() == nullptr ) | ||
return false; | ||
|
||
QRegExp reg = filterRegExp(); | ||
|
||
QModelIndex index0 = sourceModel()->index(sourceRow, 0, sourceParent); | ||
if (!index0.isValid()) | ||
return false; | ||
|
||
QVariant value_role = index0.data( LibraryModel::TitleRole ); | ||
if (value_role.toString().toLower().contains(reg.pattern().toLower())) | ||
return true; | ||
|
||
return false; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
#ifndef LIBRARYMODELPROXY_H | ||
#define LIBRARYMODELPROXY_H | ||
|
||
#include <QObject> | ||
#include <QSortFilterProxyModel> | ||
|
||
class LibraryFilterProxy : public QSortFilterProxyModel | ||
{ | ||
public: | ||
LibraryFilterProxy(QObject *parent = 0); | ||
bool filterAcceptsRow( int source_row, const QModelIndex& source_parent ) const override; | ||
}; | ||
|
||
#endif // LIBRARYMODELPROXY_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters