Search in "Manage sets" window (#3229)

* search field added; sortfilterproxy displayed in treeview

* searching works properly

* moving with filter on works; view isnt't updated yet

* clangify & view updating figured out

* moving disabled when sorting is active

* drag&drop disabled when view sorted

* clangified

* foreach replaced

* button rename & SORT_RESET defined

* changed variable names

* 'x' button added & searchlabel text modified

* 'enabled' column won't grow anymore

* column resize improvement

* button hint & restore original order added

* moving with filter on works; view isnt't updated yet

* sort disable build in column headers (3 clicks)

* codacy fix

* typo + wording

* background color for warning

* buttons moved down a bit

* clicking "default order" button will hide the warning text
This commit is contained in:
David Szabo 2018-06-10 17:00:42 +02:00 committed by Zach H
parent 91b3c7343d
commit 81803e2612
4 changed files with 183 additions and 29 deletions

View file

@ -252,3 +252,37 @@ QStringList SetsModel::mimeTypes() const
{
return QStringList() << "application/x-cockatricecardset";
}
SetsDisplayModel::SetsDisplayModel(QObject *parent) : QSortFilterProxyModel(parent)
{
setFilterCaseSensitivity(Qt::CaseInsensitive);
setSortCaseSensitivity(Qt::CaseInsensitive);
}
void SetsDisplayModel::fetchMore(const QModelIndex &index)
{
int itemsToFetch = sourceModel()->rowCount(index);
beginInsertRows(QModelIndex(), 0, itemsToFetch - 1);
endInsertRows();
}
bool SetsDisplayModel::filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const
{
auto typeIndex = sourceModel()->index(sourceRow, SetsModel::SetTypeCol, sourceParent);
auto nameIndex = sourceModel()->index(sourceRow, SetsModel::LongNameCol, sourceParent);
auto shortNameIndex = sourceModel()->index(sourceRow, SetsModel::ShortNameCol, sourceParent);
return (sourceModel()->data(typeIndex).toString().contains(filterRegExp()) ||
sourceModel()->data(nameIndex).toString().contains(filterRegExp()) ||
sourceModel()->data(shortNameIndex).toString().contains(filterRegExp()));
}
bool SetsDisplayModel::lessThan(const QModelIndex &left, const QModelIndex &right) const
{
QString leftString = sourceModel()->data(left, SetsModel::SortRole).toString();
QString rightString = sourceModel()->data(right, SetsModel::SortRole).toString();
return QString::localeAwareCompare(leftString, rightString) < 0;
}