forked from 7h0ma5/QLog
-
Notifications
You must be signed in to change notification settings - Fork 21
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
8 changed files
with
205 additions
and
7 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
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,25 @@ | ||
#include "SearchFilterProxyModel.h" | ||
|
||
SearchFilterProxyModel::SearchFilterProxyModel(QObject *parent) | ||
: QSortFilterProxyModel{parent} | ||
{} | ||
|
||
void SearchFilterProxyModel::setSearchString(const QString &searchString) | ||
{ | ||
this->searchString = searchString; | ||
invalidateFilter(); | ||
} | ||
|
||
bool SearchFilterProxyModel::filterAcceptsRow(int source_row, const QModelIndex &source_parent) const | ||
{ | ||
// full-text search | ||
for ( int col = 0; col < sourceModel()->columnCount(); ++col ) | ||
{ | ||
QModelIndex index = sourceModel()->index(source_row, col, source_parent); | ||
QString data = index.data(Qt::DisplayRole).toString(); | ||
|
||
if ( data.contains(searchString, Qt::CaseInsensitive) ) | ||
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,21 @@ | ||
#ifndef SEARCHFILTERPROXYMODEL_H | ||
#define SEARCHFILTERPROXYMODEL_H | ||
|
||
#include <QSortFilterProxyModel> | ||
|
||
class SearchFilterProxyModel : public QSortFilterProxyModel | ||
{ | ||
Q_OBJECT | ||
|
||
public: | ||
SearchFilterProxyModel(QObject* parent = nullptr); | ||
void setSearchString(const QString& searchString); | ||
|
||
protected: | ||
bool filterAcceptsRow(int source_row, const QModelIndex& source_parent) const override; | ||
|
||
private: | ||
QString searchString; | ||
}; | ||
|
||
#endif // SEARCHFILTERPROXYMODEL_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