Showing the changes to interface/src/ScriptsModelFilter.cpp (1 of 6 files). Show all
Unified · Split
| @@ -0,0 +1,44 @@ | |||
| 1 | // | ||
| 2 | // ScriptsModelFilter.cpp | ||
| 3 | // interface/src | ||
| 4 | // | ||
| 5 | // Created by Thijs Wenker on 01/11/15. | ||
| 6 | // Copyright 2015 High Fidelity, Inc. | ||
| 7 | // | ||
| 8 | // Distributed under the Apache License, Version 2.0. | ||
| 9 | // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html | ||
| 10 | // | ||
| 11 | |||
| 12 | #include "ScriptsModelFilter.h" | ||
| 13 | |||
| 14 | ScriptsModelFilter::ScriptsModelFilter(QObject *parent) : | ||
| 15 | QSortFilterProxyModel(parent) { | ||
| 16 | } | ||
| 17 | |||
| 18 | bool ScriptsModelFilter::lessThan(const QModelIndex& left, const QModelIndex& right) const { | ||
| 19 | ScriptsModel* scriptsModel = static_cast<ScriptsModel*>(sourceModel()); | ||
| 20 | TreeNodeBase* leftNode = scriptsModel->getTreeNodeFromIndex(left); | ||
| 21 | TreeNodeBase* rightNode = scriptsModel->getTreeNodeFromIndex(right); | ||
| 22 | if (leftNode->getType() != rightNode->getType()) { | ||
| 23 | return leftNode->getType() == TREE_NODE_TYPE_FOLDER; | ||
| 24 | } | ||
| 25 | return leftNode->getName() < rightNode->getName(); | ||
| 26 | } | ||
| 27 | |||
| 28 | bool ScriptsModelFilter::filterAcceptsRow(int sourceRow, const QModelIndex& sourceParent) const { | ||
| 29 | if (!filterRegExp().isEmpty()) { | ||
| 30 | ScriptsModel* scriptsModel = static_cast<ScriptsModel*>(sourceModel()); | ||
| 31 | TreeNodeBase* node = scriptsModel->getFolderNodes( | ||
| 32 | static_cast<TreeNodeFolder*>(scriptsModel->getTreeNodeFromIndex(sourceParent))).at(sourceRow); | ||
| 33 | QModelIndex sourceIndex = sourceModel()->index(sourceRow, this->filterKeyColumn(), sourceParent); | ||
| 34 | if (node->getType() == TREE_NODE_TYPE_FOLDER) { | ||
| 35 | int rows = scriptsModel->rowCount(sourceIndex); | ||
| 36 | for (int i = 0; i < rows; i++) { | ||
| 37 | if (filterAcceptsRow(i, sourceIndex)) { | ||
| 38 | return true; | ||
| 39 | } | ||
| 40 | } | ||
| 41 | } | ||
| 42 | } | ||
| 43 | return QSortFilterProxyModel::filterAcceptsRow(sourceRow, sourceParent); | ||
| 44 | } | ||