ClangTools: Prompt for files to analyze

If the run button is clicked, the user is prompted to select the files
for analysis.

Change-Id: I21e4ee6b7c14392a8c1a901ac7aa1c9c16e30f0d
Reviewed-by: Ivan Donchevskii <ivan.donchevskii@qt.io>
This commit is contained in:
Nikolai Kosjar
2018-05-02 14:51:05 +02:00
parent ef528e1801
commit 1bc605d050
22 changed files with 546 additions and 61 deletions

View File

@@ -25,15 +25,19 @@
#include "clangtool.h"
#include "clangselectablefilesdialog.h"
#include "clangtoolsconstants.h"
#include "clangtoolsdiagnostic.h"
#include "clangtoolsdiagnosticmodel.h"
#include "clangtoolsutils.h"
#include <coreplugin/actionmanager/actioncontainer.h>
#include <coreplugin/actionmanager/actionmanager.h>
#include <coreplugin/coreconstants.h>
#include <coreplugin/icore.h>
#include <cpptools/cppmodelmanager.h>
#include <debugger/analyzer/analyzermanager.h>
#include <projectexplorer/kitinformation.h>
@@ -58,6 +62,33 @@ using namespace Utils;
namespace ClangTools {
namespace Internal {
static FileInfos sortedFileInfos(const QVector<CppTools::ProjectPart::Ptr> &projectParts)
{
FileInfos fileInfos;
for (CppTools::ProjectPart::Ptr projectPart : projectParts) {
QTC_ASSERT(projectPart, continue);
if (!projectPart->selectedForBuilding)
continue;
for (const CppTools::ProjectFile &file : projectPart->files) {
QTC_ASSERT(file.kind != CppTools::ProjectFile::Unclassified, continue);
QTC_ASSERT(file.kind != CppTools::ProjectFile::Unsupported, continue);
if (file.path == CppTools::CppModelManager::configurationFileName())
continue;
if (CppTools::ProjectFile::isSource(file.kind)) {
const FileInfo info{Utils::FileName::fromString(file.path), file.kind, projectPart};
fileInfos.append(info);
}
}
}
Utils::sort(fileInfos, &FileInfo::file);
return fileInfos;
}
ClangTool::ClangTool(const QString &name)
: m_name(name)
{
@@ -67,6 +98,23 @@ ClangTool::ClangTool(const QString &name)
m_stopAction = Debugger::createStopAction();
}
FileInfos ClangTool::collectFileInfos(Project *project, bool askUserForFileSelection) const
{
auto projectInfo = CppTools::CppModelManager::instance()->projectInfo(project);
QTC_ASSERT(projectInfo.isValid(), return FileInfos());
const FileInfos allFileInfos = sortedFileInfos(projectInfo.projectParts());
if (askUserForFileSelection) {
SelectableFilesDialog dialog(projectInfo, allFileInfos);
if (dialog.exec() == QDialog::Rejected)
return FileInfos();
return dialog.filteredFileInfos();
} else {
return allFileInfos;
}
}
const QString &ClangTool::name() const
{
return m_name;