Verified Commit 11dd23df authored by Jonah Brüchert's avatar Jonah Brüchert
Browse files

Simplify urlfilterproxymodel

parent 8c2087e2
......@@ -31,11 +31,15 @@ using namespace AngelFish;
UrlFilterProxyModel::UrlFilterProxyModel(QObject *parent) : QSortFilterProxyModel(parent)
{
setFilterCaseSensitivity(Qt::CaseInsensitive);
connect(this, &UrlFilterProxyModel::sourceModelChanged, this, [this] {
sort(0, Qt::DescendingOrder);
});
}
bool UrlFilterProxyModel::filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const
{
QModelIndex index = sourceModel()->index(sourceRow, 0, sourceParent);
const QModelIndex index = sourceModel()->index(sourceRow, 0, sourceParent);
return (sourceModel()->data(index, UrlModel::url).toString().contains(filterRegExp())
|| sourceModel()->data(index, UrlModel::title).toString().contains(filterRegExp()));
......@@ -51,19 +55,3 @@ bool UrlFilterProxyModel::lessThan(const QModelIndex &source_left,
return leftDate < rightDate;
}
void UrlFilterProxyModel::setSourceModel(QAbstractItemModel *sourceModel)
{
if (QSortFilterProxyModel::sourceModel() != sourceModel) {
QSortFilterProxyModel::setSourceModel(sourceModel);
sort(0, Qt::DescendingOrder);
emit sourceModelChanged();
}
}
QAbstractItemModel *UrlFilterProxyModel::sourceModel() const
{
return QSortFilterProxyModel::sourceModel();
}
......@@ -29,18 +29,12 @@ class UrlFilterProxyModel : public QSortFilterProxyModel
{
Q_OBJECT
Q_PROPERTY(QAbstractItemModel *sourceModel READ sourceModel WRITE setSourceModel NOTIFY
sourceModelChanged)
public:
UrlFilterProxyModel(QObject *parent = nullptr);
bool filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const override;
bool lessThan(const QModelIndex &source_left, const QModelIndex &source_right) const override;
void setSourceModel(QAbstractItemModel *sourceModel) override;
QAbstractItemModel *sourceModel() const;
signals:
void sourceModelChanged();
};
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment