Merge pull request #3597 from jamierocks/atl/search
NOISSUE Add search to ATLauncher
This commit is contained in:
commit
280903e52b
@ -14,6 +14,8 @@ FilterModel::FilterModel(QObject *parent) : QSortFilterProxyModel(parent)
|
|||||||
sortings.insert(tr("Sort by popularity"), Sorting::ByPopularity);
|
sortings.insert(tr("Sort by popularity"), Sorting::ByPopularity);
|
||||||
sortings.insert(tr("Sort by name"), Sorting::ByName);
|
sortings.insert(tr("Sort by name"), Sorting::ByName);
|
||||||
sortings.insert(tr("Sort by game version"), Sorting::ByGameVersion);
|
sortings.insert(tr("Sort by game version"), Sorting::ByGameVersion);
|
||||||
|
|
||||||
|
searchTerm = "";
|
||||||
}
|
}
|
||||||
|
|
||||||
const QMap<QString, FilterModel::Sorting> FilterModel::getAvailableSortings()
|
const QMap<QString, FilterModel::Sorting> FilterModel::getAvailableSortings()
|
||||||
@ -37,9 +39,21 @@ FilterModel::Sorting FilterModel::getCurrentSorting()
|
|||||||
return currentSorting;
|
return currentSorting;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void FilterModel::setSearchTerm(const QString term)
|
||||||
|
{
|
||||||
|
searchTerm = term.trimmed();
|
||||||
|
invalidate();
|
||||||
|
}
|
||||||
|
|
||||||
bool FilterModel::filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const
|
bool FilterModel::filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const
|
||||||
{
|
{
|
||||||
return true;
|
if (searchTerm.isEmpty()) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
QModelIndex index = sourceModel()->index(sourceRow, 0, sourceParent);
|
||||||
|
ATLauncher::IndexedPack pack = sourceModel()->data(index, Qt::UserRole).value<ATLauncher::IndexedPack>();
|
||||||
|
return pack.name.contains(searchTerm, Qt::CaseInsensitive);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool FilterModel::lessThan(const QModelIndex &left, const QModelIndex &right) const
|
bool FilterModel::lessThan(const QModelIndex &left, const QModelIndex &right) const
|
||||||
|
@ -18,6 +18,7 @@ public:
|
|||||||
QString translateCurrentSorting();
|
QString translateCurrentSorting();
|
||||||
void setSorting(Sorting sorting);
|
void setSorting(Sorting sorting);
|
||||||
Sorting getCurrentSorting();
|
Sorting getCurrentSorting();
|
||||||
|
void setSearchTerm(QString term);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
bool filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const override;
|
bool filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const override;
|
||||||
@ -26,6 +27,7 @@ protected:
|
|||||||
private:
|
private:
|
||||||
QMap<QString, Sorting> sortings;
|
QMap<QString, Sorting> sortings;
|
||||||
Sorting currentSorting;
|
Sorting currentSorting;
|
||||||
|
QString searchTerm;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -25,6 +25,8 @@ AtlPage::AtlPage(NewInstanceDialog* dialog, QWidget *parent)
|
|||||||
}
|
}
|
||||||
ui->sortByBox->setCurrentText(filterModel->translateCurrentSorting());
|
ui->sortByBox->setCurrentText(filterModel->translateCurrentSorting());
|
||||||
|
|
||||||
|
connect(ui->searchEdit, &QLineEdit::textChanged, this, &AtlPage::triggerSearch);
|
||||||
|
connect(ui->resetButton, &QPushButton::clicked, this, &AtlPage::resetSearch);
|
||||||
connect(ui->sortByBox, &QComboBox::currentTextChanged, this, &AtlPage::onSortingSelectionChanged);
|
connect(ui->sortByBox, &QComboBox::currentTextChanged, this, &AtlPage::onSortingSelectionChanged);
|
||||||
connect(ui->packView->selectionModel(), &QItemSelectionModel::currentChanged, this, &AtlPage::onSelectionChanged);
|
connect(ui->packView->selectionModel(), &QItemSelectionModel::currentChanged, this, &AtlPage::onSelectionChanged);
|
||||||
connect(ui->versionSelectionBox, &QComboBox::currentTextChanged, this, &AtlPage::onVersionSelectionChanged);
|
connect(ui->versionSelectionBox, &QComboBox::currentTextChanged, this, &AtlPage::onVersionSelectionChanged);
|
||||||
@ -59,6 +61,16 @@ void AtlPage::suggestCurrent()
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void AtlPage::triggerSearch()
|
||||||
|
{
|
||||||
|
filterModel->setSearchTerm(ui->searchEdit->text());
|
||||||
|
}
|
||||||
|
|
||||||
|
void AtlPage::resetSearch()
|
||||||
|
{
|
||||||
|
ui->searchEdit->setText("");
|
||||||
|
}
|
||||||
|
|
||||||
void AtlPage::onSortingSelectionChanged(QString data)
|
void AtlPage::onSortingSelectionChanged(QString data)
|
||||||
{
|
{
|
||||||
auto toSet = filterModel->getAvailableSortings().value(data);
|
auto toSet = filterModel->getAvailableSortings().value(data);
|
||||||
|
@ -62,6 +62,9 @@ private:
|
|||||||
void suggestCurrent();
|
void suggestCurrent();
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
|
void triggerSearch();
|
||||||
|
void resetSearch();
|
||||||
|
|
||||||
void onSortingSelectionChanged(QString data);
|
void onSortingSelectionChanged(QString data);
|
||||||
|
|
||||||
void onSelectionChanged(QModelIndex first, QModelIndex second);
|
void onSelectionChanged(QModelIndex first, QModelIndex second);
|
||||||
|
@ -11,30 +11,11 @@
|
|||||||
</rect>
|
</rect>
|
||||||
</property>
|
</property>
|
||||||
<layout class="QGridLayout" name="gridLayout">
|
<layout class="QGridLayout" name="gridLayout">
|
||||||
<item row="0" column="0" colspan="2">
|
<item row="2" column="0" colspan="2">
|
||||||
<widget class="QTreeView" name="packView">
|
<layout class="QGridLayout" name="gridLayout_4" columnstretch="0,0,0" rowminimumheight="0" columnminimumwidth="0,0,0">
|
||||||
<property name="alternatingRowColors">
|
|
||||||
<bool>true</bool>
|
|
||||||
</property>
|
|
||||||
<property name="iconSize">
|
|
||||||
<size>
|
|
||||||
<width>96</width>
|
|
||||||
<height>48</height>
|
|
||||||
</size>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item row="0" column="2">
|
|
||||||
<widget class="QTextBrowser" name="packDescription"/>
|
|
||||||
</item>
|
|
||||||
<item row="1" column="0" colspan="3">
|
|
||||||
<layout class="QGridLayout" name="gridLayout_4" columnstretch="0,0,0">
|
|
||||||
<item row="0" column="2">
|
<item row="0" column="2">
|
||||||
<widget class="QComboBox" name="versionSelectionBox"/>
|
<widget class="QComboBox" name="versionSelectionBox"/>
|
||||||
</item>
|
</item>
|
||||||
<item row="0" column="0">
|
|
||||||
<widget class="QComboBox" name="sortByBox"/>
|
|
||||||
</item>
|
|
||||||
<item row="0" column="1">
|
<item row="0" column="1">
|
||||||
<widget class="QLabel" name="label">
|
<widget class="QLabel" name="label">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
@ -45,12 +26,50 @@
|
|||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
|
<item row="0" column="0">
|
||||||
|
<widget class="QComboBox" name="sortByBox"/>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</item>
|
||||||
|
<item row="0" column="0">
|
||||||
|
<widget class="QLineEdit" name="searchEdit"/>
|
||||||
|
</item>
|
||||||
|
<item row="0" column="1">
|
||||||
|
<widget class="QPushButton" name="resetButton">
|
||||||
|
<property name="text">
|
||||||
|
<string>Reset</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="1" column="0" colspan="2">
|
||||||
|
<layout class="QGridLayout" name="gridLayout_3">
|
||||||
|
<item row="0" column="0">
|
||||||
|
<widget class="QTreeView" name="packView">
|
||||||
|
<property name="iconSize">
|
||||||
|
<size>
|
||||||
|
<width>96</width>
|
||||||
|
<height>48</height>
|
||||||
|
</size>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="0" column="1">
|
||||||
|
<widget class="QTextBrowser" name="packDescription">
|
||||||
|
<property name="openExternalLinks">
|
||||||
|
<bool>true</bool>
|
||||||
|
</property>
|
||||||
|
<property name="openLinks">
|
||||||
|
<bool>true</bool>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
</item>
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
</widget>
|
</widget>
|
||||||
<tabstops>
|
<tabstops>
|
||||||
<tabstop>packView</tabstop>
|
<tabstop>searchEdit</tabstop>
|
||||||
|
<tabstop>resetButton</tabstop>
|
||||||
<tabstop>versionSelectionBox</tabstop>
|
<tabstop>versionSelectionBox</tabstop>
|
||||||
</tabstops>
|
</tabstops>
|
||||||
<resources/>
|
<resources/>
|
||||||
|
Loading…
Reference in New Issue
Block a user