提交 d3662b69 编写于 作者: L Levi Armstrong

Fix crashing

上级 5b0b325d
......@@ -162,15 +162,10 @@ QList<BuildInfo *> ROSBuildConfigurationFactory::availableBuilds(const Target *p
int ROSBuildConfigurationFactory::priority(const Kit *k, const QString &projectPath) const
{
#if QT_CREATOR_VER < QT_CREATOR_VER_CHECK(4,3,0)
Utils::MimeDatabase mdb;
if (k && mdb.mimeTypeForFile(projectPath).matchesName(QLatin1String(Constants::ROS_MIME_TYPE)))
if (k && Utils::mimeTypeForFile(projectPath).matchesName(QLatin1String(Constants::ROS_MIME_TYPE)))
return 0;
#else
if (k && Utils::mimeTypeForFile(projectPath).matchesName(QLatin1String(Constants::ROS_MIME_TYPE) ))
return 0;
#endif
return -1;
}
......
......@@ -111,11 +111,8 @@ bool ROSCatkinMakeStep::init(QList<const BuildStep *> &earlierSteps)
if (!bc)
emit addTask(Task::buildConfigurationMissingTask());
#if QT_CREATOR_VER < QT_CREATOR_VER_CHECK(4,3,0)
ToolChain *tc = ToolChainKitInformation::toolChain(target()->kit(), ToolChain::Language::Cxx);
#else
ToolChain *tc = ToolChainKitInformation::toolChain(target()->kit(), ProjectExplorer::Constants::CXX_LANGUAGE_ID);
#endif
if (!tc)
emit addTask(Task::compilerMissingTask());
......
......@@ -120,11 +120,7 @@ bool ROSCatkinToolsStep::init(QList<const BuildStep *> &earlierSteps)
if (!bc)
emit addTask(Task::buildConfigurationMissingTask());
#if QT_CREATOR_VER < QT_CREATOR_VER_CHECK(4,3,0)
ToolChain *tc = ToolChainKitInformation::toolChain(target()->kit(), ToolChain::Language::Cxx);
#else
ToolChain *tc = ToolChainKitInformation::toolChain(target()->kit(), ProjectExplorer::Constants::CXX_LANGUAGE_ID);
#endif
if (!tc)
emit addTask(Task::compilerMissingTask());
......
......@@ -47,17 +47,14 @@
#include <qtsupport/qtkitinformation.h>
#include <utils/fileutils.h>
#include <utils/qtcassert.h>
#include <utils/algorithm.h>
#include <QDir>
#include <QProcessEnvironment>
#include <QtXml/QDomDocument>
#if QT_CREATOR_VER < QT_CREATOR_VER_CHECK(4,3,0)
#include <cpptools/projectpartbuilder.h>
#else
#include <cpptools/cpprawprojectpart.h>
#include <cpptools/cppprojectupdater.h>
#endif
#include <cpptools/cpprawprojectpart.h>
#include <cpptools/cppprojectupdater.h>
using namespace Core;
using namespace ProjectExplorer;
......@@ -72,44 +69,18 @@ namespace Internal {
////////////////////////////////////////////////////////////////////////////////////
ROSProject::ROSProject(const Utils::FileName &fileName) :
#if QT_CREATOR_VER >= QT_CREATOR_VER_CHECK(4,3,0)
ProjectExplorer::Project(Constants::ROS_MIME_TYPE, fileName),
ProjectExplorer::Project(Constants::ROS_MIME_TYPE, fileName, [this]() { refresh(); }),
m_cppCodeModelUpdater(new CppTools::CppProjectUpdater(this)),
#endif
m_workspaceWatcher(new ROSWorkspaceWatcher(this))
{
setId(Constants::ROS_PROJECT_ID);
#if QT_CREATOR_VER < QT_CREATOR_VER_CHECK(4,3,0)
setDocument(new ROSProjectFile(this, fileName));
#endif
DocumentManager::addDocument(document(), true);
ROSProjectNode *project_node = new ROSProjectNode(this->projectFilePath());
setRootProjectNode(project_node);
setProjectContext(Context(Constants::ROS_PROJECT_CONTEXT));
#if QT_CREATOR_VER < QT_CREATOR_VER_CHECK(4,3,0)
setProjectLanguages(Context(ProjectExplorer::Constants::LANG_CXX));
m_projectName = projectFilePath().toFileInfo().completeBaseName();
FileNode *projectWorkspaceNode = new FileNode(projectFilePath(),
ProjectFileType,
/* generated = */ false);
rootProjectNode()->addFileNodes(QList<FileNode *>() << projectWorkspaceNode);
#else
setProjectLanguages(Context(ProjectExplorer::Constants::CXX_LANGUAGE_ID));
setDisplayName(projectFilePath().toFileInfo().completeBaseName());
FileNode *projectWorkspaceNode = new FileNode(projectFilePath(),
FileType::Project,
/* generated = */ false);
rootProjectNode()->addNode(projectWorkspaceNode);
#endif
ROSProjectNode *project_node = new ROSProjectNode(this->projectFilePath());
project_node->addNode(new FileNode(projectFilePath(), FileType::Project, false));
setRootProjectNode(project_node);
refresh();
......@@ -126,28 +97,10 @@ ROSProject::ROSProject(const Utils::FileName &fileName) :
ROSProject::~ROSProject()
{
#if QT_CREATOR_VER < QT_CREATOR_VER_CHECK(4,3,0)
m_codeModelFuture.cancel();
#else
delete m_cppCodeModelUpdater;
m_cppCodeModelUpdater = nullptr;
#endif
m_projectFutureInterface->cancel();
projectManager()->unregisterProject(this);
}
void ROSProject::settManager(ROSManager* manager)
{
#if QT_CREATOR_VER >= QT_CREATOR_VER_CHECK(4,3,0)
m_manager = manager;
#else
setProjectManager(manager);
#endif
projectManager()->registerProject(this);
refresh();
}
bool ROSProject::saveProjectFile()
......@@ -261,6 +214,7 @@ void ROSProject::refresh()
m_projectFutureInterface->setProgressValue(floor(100.0 * (float)cnt / (float)max));
}
m_projectFutureInterface->setProgressValue(100);
m_projectFutureInterface->reportFinished();
......@@ -282,11 +236,7 @@ void ROSProject::refreshCppCodeModel()
const Utils::FileName sysRoot = SysRootKitInformation::sysRoot(k);
#if QT_CREATOR_VER < QT_CREATOR_VER_CHECK(4,3,0)
m_codeModelFuture.cancel(); // This may need to be removed
#else
m_cppCodeModelUpdater->cancel();
#endif
CppTools::ProjectPart::QtVersion activeQtVersion = CppTools::ProjectPart::NoQt;
if (QtSupport::BaseQtVersion *qtVersion =
......@@ -297,65 +247,33 @@ void ROSProject::refreshCppCodeModel()
activeQtVersion = CppTools::ProjectPart::Qt5;
}
#if QT_CREATOR_VER < QT_CREATOR_VER_CHECK(4,3,0)
CppTools::CppModelManager *modelManager = CppTools::CppModelManager::instance();
CppTools::ProjectInfo pInfo(this);
QStringList workspaceFiles = m_workspaceWatcher->getWorkspaceFiles();
ToolChain *toolChain = ToolChainKitInformation::toolChain(activeTarget()->kit(), ToolChain::Language::Cxx);
foreach(ROSUtils::PackageBuildInfo buildInfo, m_wsPackageBuildInfo)
{
QStringList packageFiles = workspaceFiles.filter(buildInfo.parent.path.toString() + QDir::separator());
foreach(ROSUtils::PackageTargetInfo targetInfo, buildInfo.targets)
{
CppTools::ProjectPartBuilder ppBuilder(pInfo);
ppBuilder.setDisplayName(targetInfo.name);
ppBuilder.setQtVersion(activeQtVersion);
QSet<QString> toolChainIncludes;
foreach (const HeaderPath &hp, toolChain->systemHeaderPaths(targetInfo.flags, sysRoot))
toolChainIncludes.insert(hp.path());
QStringList includePaths;
foreach (const QString &i, targetInfo.includes) {
if (!toolChainIncludes.contains(i))
includePaths.append(i);
}
ppBuilder.setIncludePaths(includePaths);
ppBuilder.setCxxFlags(targetInfo.flags);
const QList<Id> languages = ppBuilder.createProjectPartsForFiles(packageFiles);
foreach (Id language, languages)
setProjectLanguage(language, true);
}
}
pInfo.finish();
m_codeModelFuture = modelManager->updateProjectInfo(pInfo);
#else
CppTools::RawProjectParts rpps;
QStringList workspaceFiles = m_workspaceWatcher->getWorkspaceFiles();
ToolChain *cToolChain = ToolChainKitInformation::toolChain(k,
ProjectExplorer::Constants::C_LANGUAGE_ID);
ToolChain *cxxToolChain = ToolChainKitInformation::toolChain(k,
ProjectExplorer::Constants::CXX_LANGUAGE_ID);
ToolChain *cxxToolChain = ToolChainKitInformation::toolChain(k, ProjectExplorer::Constants::CXX_LANGUAGE_ID);
foreach(ROSUtils::PackageBuildInfo buildInfo, m_wsPackageBuildInfo)
{
QStringList packageFiles = workspaceFiles.filter(buildInfo.parent.path.toString() + QDir::separator());
QStringList packgeFiles = workspaceFiles.filter(buildInfo.parent.path.toString() + QDir::separator());
foreach(ROSUtils::PackageTargetInfo targetInfo, buildInfo.targets)
{
CppTools::RawProjectPart rpp;
rpp.setDisplayName(targetInfo.name);
const QString defineArg
= Utils::transform(targetInfo.defines, [](const QString &s) -> QString {
QString result = QString::fromLatin1("#define ") + s;
int assignIndex = result.indexOf('=');
if (assignIndex != -1)
result[assignIndex] = ' ';
return result;
}).join('\n');
rpp.setProjectFileLocation(projectFilePath().toString());
rpp.setBuildSystemTarget(buildInfo.parent.name + '|' + targetInfo.name + '|' + projectFilePath().toString());
rpp.setDisplayName(buildInfo.parent.name + '|' + targetInfo.name);
rpp.setQtVersion(activeQtVersion);
rpp.setDefines(defineArg.toUtf8());
QSet<QString> toolChainIncludes;
foreach (const HeaderPath &hp, cxxToolChain->systemHeaderPaths(targetInfo.flags, sysRoot))
......@@ -369,20 +287,12 @@ void ROSProject::refreshCppCodeModel()
rpp.setIncludePaths(includePaths);
rpp.setFlagsForCxx({cxxToolChain, targetInfo.flags});
//const QList<Id> languages = ppBuilder.createProjectPartsForFiles(packageFiles);
//foreach (Id language, languages)
// setProjectLanguage(language, true);
setProjectLanguage( ProjectExplorer::Constants::CXX_LANGUAGE_ID, true);
rpp.setFiles(packgeFiles);
rpps.append(rpp);
}
}
//CppTools::GeneratedCodeModelSupport::update(generators);
m_cppCodeModelUpdater->update({this, cToolChain, cxxToolChain, k, rpps});
#endif
m_cppCodeModelUpdater->update({this, nullptr, cxxToolChain, k, rpps});
}
QStringList ROSProject::files(FilesMode fileMode) const
......@@ -391,15 +301,6 @@ QStringList ROSProject::files(FilesMode fileMode) const
return m_workspaceWatcher->getWorkspaceFiles();
}
ROSManager *ROSProject::projectManager() const
{
#if QT_CREATOR_VER < QT_CREATOR_VER_CHECK(4,3,0)
return static_cast<ROSManager *>(Project::projectManager());
#else
return m_manager;
#endif
}
Project::RestoreResult ROSProject::fromMap(const QVariantMap &map, QString *errorMessage)
{
RestoreResult result = Project::fromMap(map, errorMessage);
......@@ -439,53 +340,5 @@ void ROSProject::buildQueueFinished(bool success)
refreshCppCodeModel();
}
////////////////////////////////////////////////////////////////////////////////////
//
// ROSProjectFile
//
////////////////////////////////////////////////////////////////////////////////////
ROSProjectFile::ROSProjectFile(ROSProject *parent, const Utils::FileName& fileName)
: IDocument(parent),
m_project(parent)
{
setId(Constants::ROS_PROJECT_FILE_ID);
setMimeType(QLatin1String(Constants::ROS_MIME_TYPE));
setFilePath(fileName);
}
bool ROSProjectFile::save(QString *, const QString &, bool)
{
return false;
}
bool ROSProjectFile::isModified() const
{
return false;
}
bool ROSProjectFile::isSaveAsAllowed() const
{
return false;
}
IDocument::ReloadBehavior ROSProjectFile::reloadBehavior(ChangeTrigger state, ChangeType type) const
{
Q_UNUSED(state);
Q_UNUSED(type);
return BehaviorSilent;
}
bool ROSProjectFile::reload(QString *errorString, ReloadFlag flag, ChangeType type)
{
Q_UNUSED(errorString);
Q_UNUSED(flag);
if (type == TypePermissions)
return true;
m_project->refresh();
return true;
}
} // namespace Internal
} // namespace GenericProjectManager
......@@ -58,16 +58,8 @@ public:
ROSProject(const Utils::FileName &filename);
~ROSProject() override;
#if QT_CREATOR_VER < QT_CREATOR_VER_CHECK(4,3,0)
QString displayName() const override { return m_projectName; }
ROSManager *projectManager() const override;
QStringList files(FilesMode fileMode) const override;
#else
ROSManager *projectManager() const;
QStringList files(FilesMode fileMode) const;
#endif
void settManager(ROSManager* manager);
void refresh();
......@@ -93,44 +85,15 @@ private:
void repositoryChanged(const QString &repository);
ROSUtils::ROSProjectFileContent m_projectFileContent;
QFutureInterface<void> *m_projectFutureInterface = nullptr;
ROSUtils::PackageInfoMap m_wsPackageInfo;
ROSUtils::PackageBuildInfoMap m_wsPackageBuildInfo;
Utils::Environment m_wsEnvironment;
#if QT_CREATOR_VER < QT_CREATOR_VER_CHECK(4,3,0)
QFuture<void> m_codeModelFuture;
QString m_projectName;
#else
CppTools::CppProjectUpdater *m_cppCodeModelUpdater;
/// RJG TODO: Check who will release it
ROSManager *m_manager;
#endif
QFutureInterface<void> *m_projectFutureInterface = nullptr;
ROSUtils::PackageInfoMap m_wsPackageInfo;
ROSUtils::PackageBuildInfoMap m_wsPackageBuildInfo;
Utils::Environment m_wsEnvironment;
// Moved here so ctor init order is correct
// else on >= 4.3.0 you will see compilation warrning -Wreorder
CppTools::CppProjectUpdater *m_cppCodeModelUpdater;
ROSWorkspaceWatcher *m_workspaceWatcher;
};
class ROSProjectFile : public Core::IDocument
{
Q_OBJECT
public:
ROSProjectFile(ROSProject *parent, const Utils::FileName& fileName);
bool save(QString *errorString, const QString &fileName, bool autoSave) override;
bool isModified() const override;
bool isSaveAsAllowed() const override;
ReloadBehavior reloadBehavior(ChangeTrigger state, ChangeType type) const override;
bool reload(QString *errorString, ReloadFlag flag, ChangeType type) override;
private:
ROSProject *m_project;
};
} // namespace Internal
} // namespace ROSProjectManager
......
......@@ -21,14 +21,6 @@
#ifndef ROSPROJECTCONSTANTS_H
#define ROSPROJECTCONSTANTS_H
#include <QStringList>
// Import Qt Creator Versions
#include <app/app_version.h>
#define APP_VERSION ((IDE_VERSION_MAJOR << 16)|(IDE_VERSION_MINOR << 8)|(IDE_VERSION_RELEASE))
#define APP_VERSION_CHECK(_major, _minor, _patch) ((_major << 16)|(_minor << 8)|(_patch))
#define QT_CREATOR_VER ((IDE_VERSION_MAJOR << 16)|(IDE_VERSION_MINOR << 8)|(IDE_VERSION_RELEASE))
#define QT_CREATOR_VER_CHECK(major, minor, patch) ((major << 16)|(minor << 8)|(patch))
namespace ROSProjectManager {
namespace Constants {
......
......@@ -38,9 +38,6 @@ namespace Internal {
static ROSManager *m_instance = 0;
ROSManager::ROSManager()
#if QT_CREATOR_VER >= QT_CREATOR_VER_CHECK(4,3,0)
: ProjectExplorer::Project(Constants::ROS_MIME_TYPE, Utils::FileName::fromString(""))
#endif
{
m_instance = this;
m_terminalPane = new ROSTerminalPane();
......@@ -59,35 +56,6 @@ ROSManager *ROSManager::instance()
return m_instance;
}
QString ROSManager::mimeType() const
{
return QLatin1String(Constants::ROS_MIME_TYPE);
}
ProjectExplorer::Project *ROSManager::openProject(const QString &fileName, QString *errorString)
{
if (!QFileInfo(fileName).isFile()) {
if (errorString)
*errorString = tr("Failed opening project \"%1\": Project is not a file.")
.arg(fileName);
return 0;
}
ROSProject *rosProject = new ROSProject(Utils::FileName::fromString(fileName));
rosProject->settManager(this);
return rosProject;
}
void ROSManager::registerProject(ROSProject *project)
{
m_projects.append(project);
}
void ROSManager::unregisterProject(ROSProject *project)
{
m_projects.removeAll(project);
}
QTermWidget &ROSManager::startTerminal(int startnow, const QString name)
{
return m_terminalPane->startTerminal(startnow, name);
......
......@@ -22,26 +22,16 @@
#define ROSPROJECTMANAGER_H
#include "ros_project_constants.h"
#if QT_CREATOR_VER < QT_CREATOR_VER_CHECK(4,3,0)
#include <projectexplorer/iprojectmanager.h>
#else
#include <projectexplorer/project.h>
#endif
#include "ros_terminal_pane.h"
#include <projectexplorer/processparameters.h>
#include <qtermwidget5/qtermwidget.h>
#include "ros_terminal_pane.h"
namespace ROSProjectManager {
namespace Internal {
class ROSProject;
#if QT_CREATOR_VER < QT_CREATOR_VER_CHECK(4,3,0)
class ROSManager : public ProjectExplorer::IProjectManager
#else
class ROSManager : public ProjectExplorer::Project
#endif
class ROSManager : public QObject
{
Q_OBJECT
......@@ -49,18 +39,11 @@ public:
ROSManager();
~ROSManager();
virtual QString mimeType() const;
virtual ProjectExplorer::Project *openProject(const QString &fileName, QString *errorString);
void registerProject(ROSProject *project);
void unregisterProject(ROSProject *project);
static ROSManager *instance();
QTermWidget &startTerminal(int startnow = 1, const QString name = QString());
private:
QList<ROSProject *> m_projects;
ROSTerminalPane *m_terminalPane;
};
......
......@@ -48,11 +48,7 @@ bool ROSProjectNode::removeFile(const QString &parentPath, const QString &fileNa
{
if (fn->filePath().fileName() == fileName)
{
#if QT_CREATOR_VER < QT_CREATOR_VER_CHECK(4,3,0)
folder->removeFileNodes(QList<FileNode *>() << fn);
#else
folder->removeNode(fn);
#endif
return true;
}
}
......@@ -67,30 +63,17 @@ bool ROSProjectNode::addFile(const QString &parentPath, const QString &fileName)
QFileInfo fileInfo(QDir(parentPath), fileName);
#if QT_CREATOR_VER < QT_CREATOR_VER_CHECK(4,3,0)
FileType fileType = ResourceType;
if (Constants::SOURCE_FILE_EXTENSIONS.contains(fileInfo.suffix()))
fileType = HeaderType;
else if(Constants::HEADER_FILE_EXTENSIONS.contains(fileInfo.suffix()))
fileType = SourceType;
#else
FileType fileType = FileType::Resource;
if (Constants::SOURCE_FILE_EXTENSIONS.contains(fileInfo.suffix()))
fileType = FileType::Header;
else if(Constants::HEADER_FILE_EXTENSIONS.contains(fileInfo.suffix()))
fileType = FileType::Source;
#endif
FileNode *fileNode = new FileNode(Utils::FileName::fromString(fileInfo.absoluteFilePath()),
fileType, /*generated = */ false);
#if QT_CREATOR_VER < QT_CREATOR_VER_CHECK(4,3,0)
folder->addFileNodes(QList<FileNode *>() << fileNode);
#else
folder->addNode(fileNode);
#endif
return true;
}
......@@ -112,20 +95,11 @@ bool ROSProjectNode::renameFile(const QString &parentPath, const QString &oldFil
bool ROSProjectNode::removeDirectory(const QString &parentPath, const QString &dirName)
{
FolderNode *folder = findFolderbyAbsolutePath(parentPath);
#if QT_CREATOR_VER < QT_CREATOR_VER_CHECK(4,3,0)
foreach (FolderNode *fn, folder->subFolderNodes())
#else
foreach (FolderNode *fn, folder->folderNodes())
#endif
{
if (getFolderName(fn) == dirName)
{
#if QT_CREATOR_VER < QT_CREATOR_VER_CHECK(4,3,0)
folder->removeFolderNodes(QList<FolderNode *>() << fn);
#else
folder->removeNode(fn);
#endif
return true;
}
}
......@@ -170,21 +144,17 @@ void ROSProjectNode::renameDirectoryHelper(FolderNode * &folder)
}
// Update subFolders
#if QT_CREATOR_VER < QT_CREATOR_VER_CHECK(4,3,0)
foreach(FolderNode *fn, folder->subFolderNodes())
#else
foreach(FolderNode *fn, folder->folderNodes())
#endif
{
foreach(FolderNode *fn, folder->folderNodes()) {
QString newFilePath = folder->filePath().toString() + getFolderName(fn) + QLatin1Char('/');
fn->setAbsoluteFilePathAndLine(Utils::FileName::fromString(newFilePath), -1);
renameDirectoryHelper(fn);
}
}
FolderNode *ROSProjectNode::findFolderbyAbsolutePath(const QString &absolutePath) const
FolderNode *ROSProjectNode::findFolderbyAbsolutePath(const QString &absolutePath)
{
if (filePath().parentDir().toString() != absolutePath)
Utils::FileName temp = filePath().parentDir();
if (temp.toString() != absolutePath)
{
Utils::FileName folder = Utils::FileName::fromString(absolutePath);
FolderNode *parent = findFolderbyAbsolutePath(folder.parentDir().toString());
......@@ -192,12 +162,7 @@ FolderNode *ROSProjectNode::findFolderbyAbsolutePath(const QString &absolutePath
if (!parent)
return 0;
#if QT_CREATOR_VER < QT_CREATOR_VER_CHECK(4,3,0)
foreach (FolderNode *fn, parent->subFolderNodes())
#else
foreach (FolderNode *fn, parent->folderNodes())
#endif
{
foreach (FolderNode *fn, parent->folderNodes()) {
if (fn->filePath().toString() == (absolutePath + QLatin1Char('/')))
return fn;
}
......@@ -206,11 +171,7 @@ FolderNode *ROSProjectNode::findFolderbyAbsolutePath(const QString &absolutePath
}
else
{
#if QT_CREATOR_VER < QT_CREATOR_VER_CHECK(4,3,0)
return projectNode()->asFolderNode();
#else
return projectNode(Utils::FileName::fromString(absolutePath))->asFolderNode();
#endif
return asFolderNode();
}
}
......@@ -225,12 +186,7 @@ FolderNode *ROSProjectNode::createFolderbyAbsolutePath(const QString &absolutePa
if (!parent)
parent = createFolderbyAbsolutePath(folder.parentDir().toString());
#if QT_CREATOR_VER < QT_CREATOR_VER_CHECK(4,3,0)
parent->addFolderNodes(QList<FolderNode*>() << folderNode);