1
0
mirror of https://gitlab.com/kelteseth/ScreenPlay.git synced 2024-11-07 03:22:33 +01:00

Add reset and search by name

This commit is contained in:
kelteseth 2018-01-14 20:15:46 +01:00
parent 13aaee2eef
commit 98a1080399
3 changed files with 29 additions and 5 deletions

View File

@ -97,17 +97,17 @@ Item {
}
function onPageChanged(name) {
if (name === "All") {
installedListFilter.sortBy("All")
installedListFilter.sortByRoleType("All")
navAll.state = "active"
navWallpaper.state = "inactive"
navWidgets.state = "inactive"
} else if (name === "Wallpaper") {
installedListFilter.sortBy("Wallpaper")
installedListFilter.sortByRoleType("Wallpaper")
navAll.state = "inactive"
navWallpaper.state = "active"
navWidgets.state = "inactive"
} else if (name === "Widgets") {
installedListFilter.sortBy("Widgets")
installedListFilter.sortByRoleType("Widgets")
navAll.state = "inactive"
navWallpaper.state = "inactive"
navWidgets.state = "active"
@ -195,6 +195,13 @@ Item {
bottom: parent.bottom
bottomMargin: 10
}
onTextChanged: {
if (txtSearch.text.length === 0) {
installedListFilter.resetFilter()
} else {
installedListFilter.sortByName(txtSearch.text)
}
}
selectByMouse: true
text: qsTr("")

View File

@ -5,7 +5,7 @@ InstalledListFilter::InstalledListFilter(InstalledListModel* ilm)
setSourceModel(ilm);
}
void InstalledListFilter::sortBy(QString type)
void InstalledListFilter::sortByRoleType(QString type)
{
if (type == "All") {
setFilterRole(InstalledListModel::InstalledRole::TitleRole);
@ -20,3 +20,17 @@ void InstalledListFilter::sortBy(QString type)
sort(0);
}
void InstalledListFilter::sortByName(QString name)
{
setFilterRole(InstalledListModel::InstalledRole::TitleRole);
setFilterFixedString(name);
sort(0);
}
void InstalledListFilter::resetFilter()
{
setFilterRole(InstalledListModel::InstalledRole::TitleRole);
setFilterWildcard("*");
sort(0);
}

View File

@ -11,7 +11,10 @@ class InstalledListFilter : public QSortFilterProxyModel
Q_OBJECT
public:
InstalledListFilter(InstalledListModel *ilm);
Q_INVOKABLE void sortBy(QString type);
Q_INVOKABLE void sortByRoleType(QString type);
Q_INVOKABLE void sortByName(QString name);
Q_INVOKABLE void resetFilter();
};