summaryrefslogtreecommitdiff
path: root/src/plugins/projectexplorer/selectablefilesmodel.cpp
diff options
context:
space:
mode:
authorTobias Hunger <tobias.hunger@qt.io>2016-04-22 13:57:38 +0200
committerTobias Hunger <tobias.hunger@qt.io>2016-04-29 09:21:27 +0000
commit955d8e4013b62b16c120905c20c8c597322162ed (patch)
tree0b7d78f5e44dedf24aced06d20decde475f0a4b0 /src/plugins/projectexplorer/selectablefilesmodel.cpp
parent6db6870bdd993df1489b6ef85d05b875a577fe09 (diff)
downloadqt-creator-955d8e4013b62b16c120905c20c8c597322162ed.tar.gz
SelectableFilesModel: Check files in the show filter
This is similar to what we did in Qt Creator 3.6. Task-number: QTCREATORBUG-16138 Change-Id: I557ecb4b853ca25497e720fc30bbbbc160e36a70 Reviewed-by: Tim Jenssen <tim.jenssen@theqtcompany.com>
Diffstat (limited to 'src/plugins/projectexplorer/selectablefilesmodel.cpp')
-rw-r--r--src/plugins/projectexplorer/selectablefilesmodel.cpp27
1 files changed, 15 insertions, 12 deletions
diff --git a/src/plugins/projectexplorer/selectablefilesmodel.cpp b/src/plugins/projectexplorer/selectablefilesmodel.cpp
index 2d0dfcc820..689cb96186 100644
--- a/src/plugins/projectexplorer/selectablefilesmodel.cpp
+++ b/src/plugins/projectexplorer/selectablefilesmodel.cpp
@@ -106,12 +106,12 @@ void SelectableFilesModel::cancel()
m_watcher.waitForFinished();
}
-bool SelectableFilesModel::filter(Tree *t)
+SelectableFilesModel::FilterState SelectableFilesModel::filter(Tree *t)
{
if (t->isDir)
- return false;
+ return FilterState::SHOWN;
if (m_files.contains(t->fullPath))
- return false;
+ return FilterState::CHECKED;
auto matchesTreeName = [t](const Glob &g) {
return g.isMatch(t->name);
@@ -119,9 +119,9 @@ bool SelectableFilesModel::filter(Tree *t)
//If one of the "show file" filters matches just return false
if (Utils::anyOf(m_showFilesFilter, matchesTreeName))
- return false;
+ return FilterState::CHECKED;
- return Utils::anyOf(m_hideFilesFilter, matchesTreeName);
+ return Utils::anyOf(m_hideFilesFilter, matchesTreeName) ? FilterState::HIDDEN : FilterState::SHOWN;
}
void SelectableFilesModel::buildTree(const Utils::FileName &baseDir, Tree *tree,
@@ -157,13 +157,15 @@ void SelectableFilesModel::buildTree(const Utils::FileName &baseDir, Tree *tree,
auto t = new Tree;
t->parent = tree;
t->name = fileInfo.fileName();
- t->checked = (m_allFiles || m_files.contains(fn)) ? Qt::Checked : Qt::Unchecked;
+ FilterState state = filter(t);
+ t->checked = ((m_allFiles && state == FilterState::CHECKED)
+ || m_files.contains(fn)) ? Qt::Checked : Qt::Unchecked;
t->fullPath = fn;
t->isDir = false;
allChecked &= t->checked == Qt::Checked;
allUnchecked &= t->checked == Qt::Unchecked;
tree->files.append(t);
- if (!filter(t))
+ if (state != FilterState::HIDDEN)
tree->visibleFiles.append(t);
}
}
@@ -432,8 +434,8 @@ Qt::CheckState SelectableFilesModel::applyFilter(const QModelIndex &index)
// first remove filtered out rows..
for (;visibleIndex < visibleEnd; ++visibleIndex) {
if (startOfBlock == visibleIndex) {
- removeBlock = filter(t->visibleFiles.at(visibleIndex));
- } else if (removeBlock != filter(t->visibleFiles.at(visibleIndex))) {
+ removeBlock = (filter(t->visibleFiles.at(visibleIndex)) == FilterState::HIDDEN);
+ } else if (removeBlock != (filter(t->visibleFiles.at(visibleIndex)) == FilterState::HIDDEN)) {
if (removeBlock) {
beginRemoveRows(index, startOfBlock, visibleIndex - 1);
for (int i=startOfBlock; i < visibleIndex; ++i)
@@ -444,7 +446,7 @@ Qt::CheckState SelectableFilesModel::applyFilter(const QModelIndex &index)
visibleIndex = startOfBlock; // start again at startOfBlock
visibleEnd = t->visibleFiles.size();
}
- removeBlock = filter(t->visibleFiles.at(visibleIndex));
+ removeBlock = (filter(t->visibleFiles.at(visibleIndex)) == FilterState::HIDDEN);
startOfBlock = visibleIndex;
}
}
@@ -459,9 +461,10 @@ Qt::CheckState SelectableFilesModel::applyFilter(const QModelIndex &index)
// Figure out which rows should be visible
QList<Tree *> newRows;
- for (int i=0; i < t->files.size(); ++i)
- if (!filter(t->files.at(i)))
+ for (int i=0; i < t->files.size(); ++i) {
+ if (filter(t->files.at(i)) != FilterState::HIDDEN)
newRows.append(t->files.at(i));
+ }
// now add them!
startOfBlock = 0;
visibleIndex = 0;