Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
filesignificancecheck.cpp
Go to the documentation of this file.
1// Copyright (C) 2022 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
3
5
7
8FileSignificanceCheck *FileSignificanceCheck::m_instance = nullptr;
9
10void FileSignificanceCheck::setRootDirectories(const QStringList &paths)
11{
12 const size_t pathsSize = static_cast<size_t>(paths.size());
13 m_rootDirs.resize(pathsSize);
14 for (size_t i = 0; i < pathsSize; ++i)
15 m_rootDirs[i].setPath(paths.at(i));
16}
17
18void FileSignificanceCheck::setExclusionRegExes(const QVector<QRegularExpression> &expressions)
19{
20 m_exclusionRegExes = expressions;
21}
22
23/*
24 * Return true if the given source file is significant for lupdate.
25 * A file is considered insignificant if
26 * - it's not within any project root
27 * - it's excluded
28 *
29 * This method is called from multiple threads.
30 * Results are cached.
31 */
32bool FileSignificanceCheck::isFileSignificant(const std::string &filePath) const
33{
34 // cache lookup
35 {
36 QReadLocker locker(&m_cacheLock);
37 auto it = m_cache.find(filePath);
38 if (it != m_cache.end())
39 return it->second;
40 }
41
42 // cache miss
43 QWriteLocker locker(&m_cacheLock);
44 QString file = QString::fromUtf8(filePath);
45 QString cleanFile = QDir::cleanPath(file);
46 for (const QRegularExpression &rx : m_exclusionRegExes) {
47 if (rx.match(cleanFile).hasMatch()) {
48 m_cache.insert({filePath, false});
49 return false;
50 }
51 }
52
53 for (const QDir &rootDir : m_rootDirs) {
54 QString relativeFilePath = rootDir.relativeFilePath(file);
55 if (!relativeFilePath.startsWith(QLatin1String("../"))
56 && QFileInfo(relativeFilePath).isRelative()) {
57 m_cache.insert({filePath, true});
58 return true;
59 }
60 }
61
62 m_cache.insert({filePath, false});
63 return false;
64}
65
66QT_END_NAMESPACE
Combined button and popup list for selecting options.