fix #297894: re-enable searching cells by palette names

This commit is contained in:
Dmitri Ovodok 2019-12-18 15:46:02 +02:00
parent 9a8d4fa50e
commit 64d72b2e98
3 changed files with 14 additions and 9 deletions

View file

@ -1008,17 +1008,23 @@ bool FilterPaletteTreeModel::filterAcceptsRow(int sourceRow, const QModelIndex&
}
//---------------------------------------------------------
// ChildFilterProxyModel::filterAcceptsRow
// PaletteCellFilterProxyModel::filterAcceptsRow
//---------------------------------------------------------
bool ChildFilterProxyModel::filterAcceptsRow(int sourceRow, const QModelIndex& sourceParent) const
bool PaletteCellFilterProxyModel::filterAcceptsRow(int sourceRow, const QModelIndex& sourceParent) const
{
const QAbstractItemModel* model = sourceModel();
const QModelIndex rowIndex = model->index(sourceRow, 0, sourceParent);
const int rowCount = model->rowCount(rowIndex);
if (rowCount == 0)
return QSortFilterProxyModel::filterAcceptsRow(sourceRow, sourceParent);
if (rowCount == 0) {
if (QSortFilterProxyModel::filterAcceptsRow(sourceRow, sourceParent))
return true;
// accept row if its parent is accepted by filter: necessary to be able to search by palette name
if (sourceParent.isValid() && QSortFilterProxyModel::filterAcceptsRow(sourceParent.row(), sourceParent.parent()))
return true;
return false;
}
for (int i = 0; i < rowCount; ++i) {
if (filterAcceptsRow(i, rowIndex))

View file

@ -194,14 +194,13 @@ class FilterPaletteTreeModel : public QSortFilterProxyModel {
};
//---------------------------------------------------------
// ChildFilterProxyModel
/// Filters model's items that do not have own children.
// PaletteCellFilterProxyModel
//---------------------------------------------------------
class ChildFilterProxyModel : public QSortFilterProxyModel {
class PaletteCellFilterProxyModel : public QSortFilterProxyModel {
Q_OBJECT
public:
ChildFilterProxyModel(QObject* parent = nullptr) : QSortFilterProxyModel(parent) {}
PaletteCellFilterProxyModel(QObject* parent = nullptr) : QSortFilterProxyModel(parent) {}
bool filterAcceptsRow(int sourceRow, const QModelIndex& sourceParent) const override;
};

View file

@ -605,7 +605,7 @@ QAbstractItemModel* PaletteWorkspace::mainPaletteModel()
visFilterModel->setSourceModel(userPalette);
// Wrap it into another proxy model to enable filtering by palette cell name
QSortFilterProxyModel* textFilterModel = new ChildFilterProxyModel(this);
QSortFilterProxyModel* textFilterModel = new PaletteCellFilterProxyModel(this);
textFilterModel->setFilterCaseSensitivity(Qt::CaseInsensitive);
textFilterModel->setSourceModel(visFilterModel);
visFilterModel->setParent(textFilterModel);