Commit 63fe568b authored by Sergey Shambir's avatar Sergey Shambir

CppTools: improved languages support in ProjectPart

Please, read blueprint here:
http://qt-project.org/wiki/Blueprint-for-language-specs-system

Removed feature from QbsProjectManager: it not longer splits project on
separate C and C++ parts, because Qt version used only by clang parser
(not native) and can be ignored for pure C and Objective-C without C++.

Change-Id: I1c561f7f9f915cc6cb8579d19db74e8352f54c1e
Reviewed-by: default avatarErik Verbruggen <erik.verbruggen@digia.com>
Reviewed-by: default avatarTobias Hunger <tobias.hunger@digia.com>
Reviewed-by: default avatarDaniel Teske <daniel.teske@digia.com>
parent 0c417bbb
......@@ -434,13 +434,15 @@ void AutotoolsProject::updateCppCodeModel()
|| (pinfo.frameworkPaths() != allFrameworkPaths);
if (update) {
pinfo.clearProjectParts();
CPlusPlus::CppModelManagerInterface::ProjectPart::Ptr part(
new CPlusPlus::CppModelManagerInterface::ProjectPart);
CPlusPlus::ProjectPart::Ptr part(new CPlusPlus::ProjectPart);
part->includePaths = allIncludePaths;
part->sourceFiles = m_files;
foreach (const QString &file, m_files)
part->files << CPlusPlus::ProjectFile(file, CPlusPlus::ProjectFile::CXXSource);
part->defines = macros;
part->frameworkPaths = allFrameworkPaths;
part->language = CPlusPlus::CppModelManagerInterface::ProjectPart::CXX11;
part->cVersion = CPlusPlus::ProjectPart::C99;
part->cxxVersion = CPlusPlus::ProjectPart::CXX11;
pinfo.appendProjectPart(part);
modelManager->updateProjectInfo(pinfo);
......
......@@ -372,19 +372,20 @@ bool CMakeProject::parseCMakeLists()
|| pinfo.defines() != allDefines
|| pinfo.frameworkPaths() != allFrameworkPaths) {
pinfo.clearProjectParts();
CPlusPlus::CppModelManagerInterface::ProjectPart::Ptr part(
new CPlusPlus::CppModelManagerInterface::ProjectPart);
CPlusPlus::ProjectPart::Ptr part(new CPlusPlus::ProjectPart);
part->includePaths = allIncludePaths;
// TODO we only want C++ files, not all other stuff that might be in the project
part->sourceFiles = m_files;
CPlusPlus::ProjectFileAdder adder(part->files);
foreach (const QString &file, m_files)
adder.maybeAdd(file);
part->defines = allDefines;
part->frameworkPaths = allFrameworkPaths;
part->cVersion = CPlusPlus::ProjectPart::C99;
if (tc)
part->language = tc->compilerFlags(cxxflags) == ToolChain::STD_CXX11
? CPlusPlus::CppModelManagerInterface::ProjectPart::CXX11
: CPlusPlus::CppModelManagerInterface::ProjectPart::CXX;
part->cxxVersion = tc->compilerFlags(cxxflags) == ToolChain::STD_CXX11
? CPlusPlus::ProjectPart::CXX11
: CPlusPlus::ProjectPart::CXX98;
else
part->language = CPlusPlus::CppModelManagerInterface::ProjectPart::CXX11;
part->cxxVersion = CPlusPlus::ProjectPart::CXX11;
pinfo.appendProjectPart(part);
modelmanager->updateProjectInfo(pinfo);
m_codeModelFuture.cancel();
......
......@@ -1688,17 +1688,19 @@ void AddIncludeForUndefinedIdentifier::match(const CppQuickFixInterface &interfa
QList<CppModelManagerInterface::ProjectInfo> projectInfos = modelManager->projectInfos();
bool inProject = false;
foreach (const CppModelManagerInterface::ProjectInfo &info, projectInfos) {
foreach (CppModelManagerInterface::ProjectPart::Ptr part, info.projectParts()) {
if (part->sourceFiles.contains(doc->fileName()) || part->objcSourceFiles.contains(doc->fileName()) || part->headerFiles.contains(doc->fileName())) {
inProject = true;
includePaths += part->includePaths;
foreach (ProjectPart::Ptr part, info.projectParts()) {
foreach (const ProjectFile &file, part->files) {
if (file.path == doc->fileName()) {
inProject = true;
includePaths += part->includePaths;
}
}
}
}
if (!inProject) {
// better use all include paths than none
foreach (const CppModelManagerInterface::ProjectInfo &info, projectInfos) {
foreach (CppModelManagerInterface::ProjectPart::Ptr part, info.projectParts())
foreach (ProjectPart::Ptr part, info.projectParts())
includePaths += part->includePaths;
}
}
......
......@@ -82,7 +82,7 @@ void CppModelManagerInterface::ProjectInfo::clearProjectParts()
}
void CppModelManagerInterface::ProjectInfo::appendProjectPart(
const CppModelManagerInterface::ProjectPart::Ptr &part)
const ProjectPart::Ptr &part)
{
if (!part)
return;
......@@ -103,12 +103,8 @@ void CppModelManagerInterface::ProjectInfo::appendProjectPart(
// update source files
QSet<QString> srcs = QSet<QString>::fromList(m_sourceFiles);
foreach (const QString &src, part->headerFiles)
srcs.insert(src);
foreach (const QString &src, part->sourceFiles)
srcs.insert(src);
foreach (const QString &src, part->objcSourceFiles)
srcs.insert(src);
foreach (const ProjectFile &file, part->files)
srcs.insert(file.path);
m_sourceFiles = srcs.toList();
// update defines
......
......@@ -33,6 +33,7 @@
#include <cplusplus/CppDocument.h>
#include <languageutils/fakemetaobject.h>
#include "cpptools_global.h"
#include "cppprojectfile.h"
#include <QObject>
#include <QHash>
......@@ -63,48 +64,64 @@ namespace CppTools {
namespace CPlusPlus {
class CPPTOOLS_EXPORT CppModelManagerInterface : public QObject
class CPPTOOLS_EXPORT ProjectPart
{
Q_OBJECT
public:
ProjectPart()
: cVersion(C89)
, cxxVersion(CXX11)
, cxxExtensions(NoExtensions)
, qtVersion(UnknownQt)
{}
public:
enum CVersion {
C89,
C99,
C11
};
class CPPTOOLS_EXPORT ProjectPart
{
public:
ProjectPart()
: language(CXX11)
, qtVersion(UnknownQt)
{}
public: // enums and types
enum Language {
C89 = 1,
C99 = 2,
CXX = 3,
CXX11 = 4
};
enum QtVersion {
UnknownQt = -1,
NoQt = 0,
Qt4 = 1,
Qt5 = 2
};
typedef QSharedPointer<ProjectPart> Ptr;
public: //attributes
QStringList headerFiles;
QStringList sourceFiles;
QStringList objcSourceFiles;
QByteArray defines;
QStringList includePaths;
QStringList frameworkPaths;
QStringList precompiledHeaders;
Language language;
QtVersion qtVersion;
enum CXXVersion {
CXX98,
CXX11
};
enum CXXExtension {
NoExtensions = 0x0,
GnuExtensions = 0x1,
MicrosoftExtensions = 0x2,
BorlandExtensions = 0x4,
OpenMP = 0x8
};
Q_DECLARE_FLAGS(CXXExtensions, CXXExtension)
enum QtVersion {
UnknownQt = -1,
NoQt = 0,
Qt4 = 1,
Qt5 = 2
};
typedef QSharedPointer<ProjectPart> Ptr;
public: //attributes
QList<ProjectFile> files;
QByteArray defines;
QStringList includePaths;
QStringList frameworkPaths;
QStringList precompiledHeaders;
CVersion cVersion;
CXXVersion cxxVersion;
CXXExtensions cxxExtensions;
QtVersion qtVersion;
};
class CPPTOOLS_EXPORT CppModelManagerInterface : public QObject
{
Q_OBJECT
public:
class CPPTOOLS_EXPORT ProjectInfo
{
public:
......@@ -252,4 +269,6 @@ public Q_SLOTS:
} // namespace CPlusPlus
QDebug operator <<(QDebug stream, const CPlusPlus::ProjectFile &cxxFile);
#endif // CPPMODELMANAGERINTERFACE_H
......@@ -89,9 +89,9 @@
namespace CPlusPlus {
uint qHash(const CppModelManagerInterface::ProjectPart &p)
uint qHash(const ProjectPart &p)
{
uint h = qHash(p.defines) ^ p.language ^ p.qtVersion;
uint h = qHash(p.defines) ^ p.cVersion ^ p.cxxVersion ^ p.cxxExtensions ^ p.qtVersion;
foreach (const QString &i, p.includePaths)
h ^= qHash(i);
......@@ -102,12 +102,16 @@ uint qHash(const CppModelManagerInterface::ProjectPart &p)
return h;
}
bool operator==(const CppModelManagerInterface::ProjectPart &p1,
const CppModelManagerInterface::ProjectPart &p2)
bool operator==(const ProjectPart &p1,
const ProjectPart &p2)
{
if (p1.defines != p2.defines)
return false;
if (p1.language != p2.language)
if (p1.cVersion != p2.cVersion)
return false;
if (p1.cxxVersion != p2.cxxVersion)
return false;
if (p1.cxxExtensions != p2.cxxExtensions)
return false;
if (p1.qtVersion!= p2.qtVersion)
return false;
......@@ -769,9 +773,8 @@ QStringList CppModelManager::internalProjectFiles() const
it.next();
ProjectInfo pinfo = it.value();
foreach (const ProjectPart::Ptr &part, pinfo.projectParts()) {
files += part->headerFiles;
files += part->sourceFiles;
files += part->objcSourceFiles;
foreach (const ProjectFile &file, part->files)
files += file.path;
}
}
files.removeDuplicates();
......@@ -839,24 +842,37 @@ void CppModelManager::dumpModelManagerConfiguration()
qDebug()<<" for project:"<< pinfo.project().data()->document()->fileName();
foreach (const ProjectPart::Ptr &part, pinfo.projectParts()) {
qDebug() << "=== part ===";
const char* lang;
switch (part->language) {
case ProjectPart::CXX: lang = "C++"; break;
case ProjectPart::CXX11: lang = "C++11"; break;
case ProjectPart::C89: lang = "C89"; break;
case ProjectPart::C99: lang = "C99"; break;
default: lang = "INVALID";
const char* cVersion;
const char* cxxVersion;
const char* cxxExtensions;
switch (part->cVersion) {
case ProjectPart::C89: cVersion = "C89"; break;
case ProjectPart::C99: cVersion = "C99"; break;
case ProjectPart::C11: cVersion = "C11"; break;
default: cVersion = "INVALID";
}
switch (part->cxxVersion) {
case ProjectPart::CXX98: cVersion = "CXX98"; break;
case ProjectPart::CXX11: cVersion = "CXX11"; break;
default: cxxVersion = "INVALID";
}
switch (part->cxxExtensions) {
case ProjectPart::NoExtensions: cVersion = "NoExtensions"; break;
case ProjectPart::GnuExtensions: cVersion = "GnuExtensions"; break;
case ProjectPart::MicrosoftExtensions: cVersion = "MicrosoftExtensions"; break;
case ProjectPart::BorlandExtensions: cVersion = "BorlandExtensions"; break;
default: cxxExtensions = "INVALID";
}
qDebug() << "language:" << lang;
qDebug() << "cVersion:" << cVersion;
qDebug() << "cxxVersion:" << cxxVersion;
qDebug() << "cxxExtensions:" << cxxExtensions;
qDebug() << "Qt version:" << part->qtVersion;
qDebug() << "precompiled header:" << part->precompiledHeaders;
qDebug() << "defines:" << part->defines;
qDebug() << "includes:" << part->includePaths;
qDebug() << "frameworkPaths:" << part->frameworkPaths;
qDebug() << "headers:" << part->headerFiles;
qDebug() << "sources:" << part->sourceFiles;
qDebug() << "objc sources:" << part->objcSourceFiles;
qDebug() << "files:" << part->files;
qDebug() << "";
}
}
......@@ -988,12 +1004,8 @@ void CppModelManager::updateProjectInfo(const ProjectInfo &pinfo)
foreach (const ProjectInfo &projectInfo, m_projects) {
foreach (const ProjectPart::Ptr &projectPart, projectInfo.projectParts()) {
foreach (const QString &sourceFile, projectPart->sourceFiles)
m_srcToProjectPart[sourceFile].append(projectPart);
foreach (const QString &objcSourceFile, projectPart->objcSourceFiles)
m_srcToProjectPart[objcSourceFile].append(projectPart);
foreach (const QString &headerFile, projectPart->headerFiles)
m_srcToProjectPart[headerFile].append(projectPart);
foreach (const ProjectFile &cxxFile, projectPart->files)
m_srcToProjectPart[cxxFile.path].append(projectPart);
}
}
}
......@@ -1004,9 +1016,9 @@ void CppModelManager::updateProjectInfo(const ProjectInfo &pinfo)
emit projectPartsUpdated(pinfo.project().data());
}
QList<CppModelManager::ProjectPart::Ptr> CppModelManager::projectPart(const QString &fileName) const
QList<ProjectPart::Ptr> CppModelManager::projectPart(const QString &fileName) const
{
QList<CppModelManager::ProjectPart::Ptr> parts = m_srcToProjectPart.value(fileName);
QList<ProjectPart::Ptr> parts = m_srcToProjectPart.value(fileName);
if (!parts.isEmpty())
return parts;
......
......@@ -94,7 +94,7 @@ public:
virtual QList<ProjectInfo> projectInfos() const;
virtual ProjectInfo projectInfo(ProjectExplorer::Project *project) const;
virtual void updateProjectInfo(const ProjectInfo &pinfo);
virtual QList<ProjectPart::Ptr> projectPart(const QString &fileName) const;
virtual QList<CPlusPlus::ProjectPart::Ptr> projectPart(const QString &fileName) const;
virtual CPlusPlus::Snapshot snapshot() const;
virtual Document::Ptr document(const QString &fileName) const;
......@@ -244,7 +244,7 @@ private:
mutable QMutex m_protectExtraDiagnostics;
QHash<QString, QHash<int, QList<Document::DiagnosticMessage> > > m_extraDiagnostics;
QMap<QString, QList<ProjectPart::Ptr> > m_srcToProjectPart;
QMap<QString, QList<CPlusPlus::ProjectPart::Ptr> > m_srcToProjectPart;
CppCompletionAssistProvider *m_completionAssistProvider;
CppCompletionAssistProvider *m_completionFallback;
......
......@@ -39,7 +39,8 @@ using namespace CppTools::Internal;
typedef CPlusPlus::Document Document;
typedef CPlusPlus::CppModelManagerInterface::ProjectInfo ProjectInfo;
typedef CPlusPlus::CppModelManagerInterface::ProjectPart ProjectPart;
typedef CPlusPlus::ProjectPart ProjectPart;
typedef CPlusPlus::ProjectFile ProjectFile;
typedef ProjectExplorer::Project Project;
namespace {
......@@ -81,7 +82,7 @@ void CppToolsPlugin::test_modelmanager_paths()
ProjectPart::Ptr part(new ProjectPart);
pi.appendProjectPart(part);
part->language = ProjectPart::CXX;
part->cxxVersion = ProjectPart::CXX98;
part->qtVersion = ProjectPart::Qt5;
part->defines = QByteArray("#define OH_BEHAVE -1\n");
part->includePaths = QStringList() << testIncludeDir(false);
......@@ -109,19 +110,20 @@ void CppToolsPlugin::test_modelmanager_framework_headers()
ProjectPart::Ptr part(new ProjectPart);
pi.appendProjectPart(part);
part->language = ProjectPart::CXX;
part->cxxVersion = ProjectPart::CXX98;
part->qtVersion = ProjectPart::Qt5;
part->defines = QByteArray("#define OH_BEHAVE -1\n");
part->includePaths << testIncludeDir();
part->frameworkPaths << testFrameworksDir();
part->sourceFiles << testSource(QLatin1String("test_modelmanager_framework_headers.cpp"));
const QString &source = testSource(QLatin1String("test_modelmanager_framework_headers.cpp"));
part->files << ProjectFile(source, ProjectFile::CXXSource);
mm->updateProjectInfo(pi);
mm->updateSourceFiles(part->sourceFiles).waitForFinished();
mm->updateSourceFiles(QStringList(source)).waitForFinished();
QCoreApplication::processEvents();
QVERIFY(mm->snapshot().contains(part->sourceFiles.first()));
Document::Ptr doc = mm->snapshot().document(part->sourceFiles.first());
QVERIFY(mm->snapshot().contains(source));
Document::Ptr doc = mm->snapshot().document(source);
QVERIFY(!doc.isNull());
CPlusPlus::Namespace *ns = doc->globalNamespace();
QVERIFY(ns);
......
/****************************************************************************
**
** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
** Contact: http://www.qt-project.org/legal
**
** This file is part of Qt Creator.
**
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Digia. For licensing terms and
** conditions see http://qt.digia.com/licensing. For further information
** use the contact form at http://qt.digia.com/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file. Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Digia gives you certain additional
** rights. These rights are described in the Digia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
****************************************************************************/
#include "cppprojectfile.h"
#include <coreplugin/icore.h>
#include "cpptoolsconstants.h"
#include <QDebug>
namespace CPlusPlus {
ProjectFile::ProjectFile()
: kind(CHeader)
{
}
ProjectFile::ProjectFile(const QString &file, Kind kind)
: path(file)
, kind(kind)
{
}
ProjectFileAdder::ProjectFileAdder(QList<ProjectFile> &files)
: m_files(files)
{
addMapping(CppTools::Constants::C_SOURCE_MIMETYPE, ProjectFile::CSource);
addMapping(CppTools::Constants::C_HEADER_MIMETYPE, ProjectFile::CHeader);
addMapping(CppTools::Constants::CPP_SOURCE_MIMETYPE, ProjectFile::CSource);
addMapping(CppTools::Constants::CPP_HEADER_MIMETYPE, ProjectFile::CHeader);
addMapping(CppTools::Constants::OBJECTIVE_CPP_SOURCE_MIMETYPE, ProjectFile::ObjCXXSource);
}
ProjectFileAdder::~ProjectFileAdder()
{
}
bool ProjectFileAdder::maybeAdd(const QString &path)
{
m_fileInfo.setFile(path);
foreach (const Pair &pair, m_mapping)
if (pair.first.matchesFile(path)) {
m_files << ProjectFile(path, pair.second);
return true;
}
return false;
}
void ProjectFileAdder::addMapping(const char *mimeName, ProjectFile::Kind kind)
{
const Core::MimeDatabase *mimeDatabase = Core::ICore::mimeDatabase();
Core::MimeType mimeType = mimeDatabase->findByType(QLatin1String(mimeName));
if (!mimeType.isNull())
m_mapping.append(Pair(mimeType, kind));
}
} // namespace CPlusPlus
QDebug operator <<(QDebug stream, const CPlusPlus::ProjectFile &cxxFile)
{
const char *kind;
switch (cxxFile.kind) {
case CPlusPlus::ProjectFile::CHeader: kind = "CHeader"; break;
case CPlusPlus::ProjectFile::CSource: kind = "CSource"; break;
case CPlusPlus::ProjectFile::CXXHeader: kind = "CXXHeader"; break;
case CPlusPlus::ProjectFile::CXXSource: kind = "CXXSource"; break;
case CPlusPlus::ProjectFile::ObjCHeader: kind = "ObjCHeader"; break;
case CPlusPlus::ProjectFile::ObjCSource: kind = "ObjCSource"; break;
case CPlusPlus::ProjectFile::ObjCXXHeader: kind = "ObjCXXHeader"; break;
case CPlusPlus::ProjectFile::ObjCXXSource: kind = "ObjCXXSource"; break;
case CPlusPlus::ProjectFile::CudaSource: kind = "CudaSource"; break;
case CPlusPlus::ProjectFile::OpenCLSource: kind = "OpenCLSource"; break;
default: kind = "INVALID"; break;
}
stream << cxxFile.path << QLatin1String(", ") << kind;
return stream;
}
/****************************************************************************
**
** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
** Contact: http://www.qt-project.org/legal
**
** This file is part of Qt Creator.
**
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Digia. For licensing terms and
** conditions see http://qt.digia.com/licensing. For further information
** use the contact form at http://qt.digia.com/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file. Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Digia gives you certain additional
** rights. These rights are described in the Digia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
****************************************************************************/
#ifndef CPLUSPLUS_CPPPROJECTFILE_H
#define CPLUSPLUS_CPPPROJECTFILE_H
#include <QString>
#include <QMap>
#include <coreplugin/mimedatabase.h>
#include "cpptools_global.h"
namespace CPlusPlus {
class CPPTOOLS_EXPORT ProjectFile
{
public:
// enums and types
enum Kind {
CHeader = 1,
CSource = 2,
CXXHeader = 3,
CXXSource = 4,
ObjCHeader = 5,
ObjCSource = 6,
ObjCXXHeader = 7,
ObjCXXSource = 8,
CudaSource = 9,
OpenCLSource = 10
};
ProjectFile();
ProjectFile(const QString &file, Kind kind);
QString path;
Kind kind;
};
class CPPTOOLS_EXPORT ProjectFileAdder
{
public:
ProjectFileAdder(QList<ProjectFile> &files);
~ProjectFileAdder();
bool maybeAdd(const QString &path);
private:
typedef QPair<Core::MimeType, ProjectFile::Kind> Pair;
void addMapping(const char *mimeName, ProjectFile::Kind kind);
QList<ProjectFile> &m_files;
QList<Pair> m_mapping;
QFileInfo m_fileInfo;
};
} // namespace CPlusPlus
QDebug operator <<(QDebug stream, const CPlusPlus::ProjectFile &cxxFile);
#endif // CPLUSPLUS_CPPPROJECTFILE_H
......@@ -48,7 +48,8 @@ HEADERS += completionsettingspage.h \
TypeHierarchyBuilder.h \
cppindexingsupport.h \
builtinindexingsupport.h \
cpppointerdeclarationformatter.h
cpppointerdeclarationformatter.h \
cppprojectfile.h
SOURCES += completionsettingspage.cpp \
cppclassesfilter.cpp \
......@@ -90,7 +91,8 @@ SOURCES += completionsettingspage.cpp \
TypeHierarchyBuilder.cpp \
cppindexingsupport.cpp \
builtinindexingsupport.cpp \
cpppointerdeclarationformatter.cpp
cpppointerdeclarationformatter.cpp \
cppprojectfile.cpp
FORMS += completionsettingspage.ui \
cppfilesettingspage.ui \
......
......@@ -59,27 +59,6 @@ using namespace ProjectExplorer;
namespace GenericProjectManager {
namespace Internal {
static QList<Core::MimeType> cppMimeTypes()
{
QStringList mimeTypesNames;
mimeTypesNames << QLatin1String(CppTools::Constants::C_SOURCE_MIMETYPE)
<< QLatin1String(CppTools::Constants::C_HEADER_MIMETYPE)
<< QLatin1String(CppTools::Constants::CPP_SOURCE_MIMETYPE)
<< QLatin1String(CppTools::Constants::OBJECTIVE_CPP_SOURCE_MIMETYPE)
<< QLatin1String(CppTools::Constants::CPP_HEADER_MIMETYPE);
QList<Core::MimeType> mimeTypes;
const Core::MimeDatabase *mimeDatabase = Core::ICore::mimeDatabase();
foreach (const QString &typeName, mimeTypesNames) {
Core::MimeType mimeType = mimeDatabase->findByType(typeName);
if (!mimeType.isNull())
mimeTypes.append(mimeType);
}
return mimeTypes;
}
////////////////////////////////////////////////////////////////////////////////////
//
// GenericProject
......@@ -267,8 +246,7 @@ void GenericProject::refresh(RefreshOptions options)
if (modelManager) {
CPlusPlus::CppModelManagerInterface::ProjectInfo pinfo = modelManager->projectInfo(this);
pinfo.clearProjectParts();
CPlusPlus::CppModelManagerInterface::ProjectPart::Ptr part(
new CPlusPlus::CppModelManagerInterface::ProjectPart);
CPlusPlus::ProjectPart::Ptr part(new CPlusPlus::ProjectPart);
Kit *k = activeTarget() ? activeTarget()->kit() : KitManager::instance()->defaultKit();
if (ToolChain *tc = ToolChainKitInformation::toolChain(k)) {
......@@ -290,29 +268,23 @@ void GenericProject::refresh(RefreshOptions options)
// ### add _defines.
// Add any C/C++ files to be parsed
const QList<Core::MimeType> mimeTypes = cppMimeTypes();
QFileInfo fileInfo;
foreach (const QString &file, files()) {
fileInfo.setFile(file);
foreach (const Core::MimeType &mimeType, mimeTypes) {
if (mimeType.matchesFile(fileInfo)) {
part->sourceFiles += file;
break;
}
}
}
CPlusPlus::ProjectFileAdder adder(part->files);
foreach (const QString &file, files())
adder.maybeAdd(file);
QStringList filesToUpdate;
if (options & Configuration) {
filesToUpdate = part->sourceFiles;
foreach (const CPlusPlus::ProjectFile &file, part->files)
filesToUpdate << file.path;
filesToUpdate.append(CPlusPlus::CppModelManagerInterface::configurationFileName());
// Full update, if there's a code model update, cancel it
m_codeModelFuture.cancel();
} else if (options & Files) {
// Only update files that got added to the list
QSet<QString> newFileList = part->sourceFiles.toSet();
QSet<QString> newFileList;
foreach (const CPlusPlus::ProjectFile &file, part->files)
newFileList.insert(file.path);
newFileList.subtract(oldFileList);
filesToUpdate.append(newFileList.toList());
}
......
......@@ -430,13 +430,13 @@ void QbsProject::updateCppCodeModel(const qbs::ProjectData *prj)
CPlusPlus::CppModelManagerInterface::ProjectInfo pinfo = modelmanager->projectInfo(this);