forked from qt-creator/qt-creator
QmlPropjectManager: Fix ownership
Explicit ownership has the advatage that you can see if you leak memory. Removed overused casting too. Change-Id: I2336aa07525742d6c1415471ea15ed101406a90c Reviewed-by: <github-actions-qt-creator@cristianadam.eu> Reviewed-by: Thomas Hartmann <thomas.hartmann@qt.io>
This commit is contained in:
committed by
Thomas Hartmann
parent
fe5848a47c
commit
84e3ffeaba
@@ -25,8 +25,6 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "qmlprojectitem.h"
|
||||
|
||||
#include <QObject>
|
||||
#include <QRegularExpression>
|
||||
#include <QSet>
|
||||
@@ -38,6 +36,17 @@ namespace Utils { class FileSystemWatcher; }
|
||||
|
||||
namespace QmlProjectManager {
|
||||
|
||||
class QmlProjectContentItem : public QObject
|
||||
{
|
||||
// base class for all elements that should be direct children of Project element
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
QmlProjectContentItem(QObject *parent = nullptr)
|
||||
: QObject(parent)
|
||||
{}
|
||||
};
|
||||
|
||||
class FileFilterBaseItem : public QmlProjectContentItem {
|
||||
Q_OBJECT
|
||||
|
||||
|
@@ -28,8 +28,10 @@
|
||||
#include "filefilteritems.h"
|
||||
#include <qmljs/qmljssimplereader.h>
|
||||
|
||||
#include <QVariant>
|
||||
#include <QDebug>
|
||||
#include <QVariant>
|
||||
|
||||
#include <memory>
|
||||
|
||||
enum {
|
||||
debug = false
|
||||
@@ -37,7 +39,9 @@ enum {
|
||||
|
||||
namespace {
|
||||
|
||||
QmlProjectManager::FileFilterBaseItem *setupFileFilterItem(QmlProjectManager::FileFilterBaseItem *fileFilterItem, const QmlJS::SimpleReaderNode::Ptr &node)
|
||||
std::unique_ptr<QmlProjectManager::FileFilterBaseItem> setupFileFilterItem(
|
||||
std::unique_ptr<QmlProjectManager::FileFilterBaseItem> fileFilterItem,
|
||||
const QmlJS::SimpleReaderNode::Ptr &node)
|
||||
{
|
||||
const auto directoryProperty = node->property(QLatin1String("directory"));
|
||||
if (directoryProperty.isValid())
|
||||
@@ -148,17 +152,24 @@ QmlProjectItem *QmlProjectFileFormat::parseProjectFile(const Utils::FilePath &fi
|
||||
qDebug() << "reading type:" << childNode->name();
|
||||
|
||||
if (childNode->name() == QLatin1String("QmlFiles")) {
|
||||
projectItem->appendContent(setupFileFilterItem(new FileFilterItem("*.qml"), childNode));
|
||||
projectItem->appendContent(
|
||||
setupFileFilterItem(std::make_unique<FileFilterItem>("*.qml"), childNode));
|
||||
} else if (childNode->name() == QLatin1String("JavaScriptFiles")) {
|
||||
projectItem->appendContent(setupFileFilterItem(new FileFilterItem("*.js"), childNode));
|
||||
projectItem->appendContent(
|
||||
setupFileFilterItem(std::make_unique<FileFilterItem>("*.js"), childNode));
|
||||
} else if (childNode->name() == QLatin1String("ImageFiles")) {
|
||||
projectItem->appendContent(setupFileFilterItem(new ImageFileFilterItem(projectItem), childNode));
|
||||
projectItem->appendContent(
|
||||
setupFileFilterItem(std::make_unique<ImageFileFilterItem>(projectItem),
|
||||
childNode));
|
||||
} else if (childNode->name() == QLatin1String("CssFiles")) {
|
||||
projectItem->appendContent(setupFileFilterItem(new FileFilterItem("*.css"), childNode));
|
||||
projectItem->appendContent(
|
||||
setupFileFilterItem(std::make_unique<FileFilterItem>("*.css"), childNode));
|
||||
} else if (childNode->name() == QLatin1String("FontFiles")) {
|
||||
projectItem->appendContent(setupFileFilterItem(new FileFilterItem("*.ttf;*.otf"), childNode));
|
||||
projectItem->appendContent(
|
||||
setupFileFilterItem(std::make_unique<FileFilterItem>("*.ttf;*.otf"), childNode));
|
||||
} else if (childNode->name() == QLatin1String("Files")) {
|
||||
projectItem->appendContent(setupFileFilterItem(new FileFilterBaseItem(), childNode));
|
||||
projectItem->appendContent(
|
||||
setupFileFilterItem(std::make_unique<FileFilterBaseItem>(), childNode));
|
||||
} else if (childNode->name() == "Environment") {
|
||||
const auto properties = childNode->properties();
|
||||
auto i = properties.constBegin();
|
||||
|
@@ -40,13 +40,12 @@ void QmlProjectItem::setSourceDirectory(const QString &directoryPath)
|
||||
|
||||
m_sourceDirectory = directoryPath;
|
||||
|
||||
for (auto contentElement : qAsConst(m_content)) {
|
||||
auto fileFilter = qobject_cast<FileFilterBaseItem*>(contentElement);
|
||||
if (fileFilter) {
|
||||
fileFilter->setDefaultDirectory(directoryPath);
|
||||
connect(fileFilter, &FileFilterBaseItem::filesChanged,
|
||||
this, &QmlProjectItem::qmlFilesChanged);
|
||||
}
|
||||
for (auto &fileFilter : m_content) {
|
||||
fileFilter->setDefaultDirectory(directoryPath);
|
||||
connect(fileFilter.get(),
|
||||
&FileFilterBaseItem::filesChanged,
|
||||
this,
|
||||
&QmlProjectItem::qmlFilesChanged);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -99,12 +98,10 @@ QStringList QmlProjectItem::files() const
|
||||
{
|
||||
QSet<QString> files;
|
||||
|
||||
for (const auto contentElement : qAsConst(m_content)) {
|
||||
if (auto fileFilter = qobject_cast<const FileFilterBaseItem *>(contentElement)) {
|
||||
const QStringList fileList = fileFilter->files();
|
||||
for (const QString &file : fileList) {
|
||||
files.insert(file);
|
||||
}
|
||||
for (const auto &fileFilter : m_content) {
|
||||
const QStringList fileList = fileFilter->files();
|
||||
for (const QString &file : fileList) {
|
||||
files.insert(file);
|
||||
}
|
||||
}
|
||||
return Utils::toList(files);
|
||||
@@ -118,9 +115,8 @@ QStringList QmlProjectItem::files() const
|
||||
*/
|
||||
bool QmlProjectItem::matchesFile(const QString &filePath) const
|
||||
{
|
||||
return Utils::contains(m_content, [&filePath](const QmlProjectContentItem *item) {
|
||||
auto fileFilter = qobject_cast<const FileFilterBaseItem *>(item);
|
||||
return fileFilter && fileFilter->matchesFile(filePath);
|
||||
return Utils::contains(m_content, [&filePath](const auto &fileFilter) {
|
||||
return fileFilter->matchesFile(filePath);
|
||||
});
|
||||
}
|
||||
|
||||
|
@@ -25,22 +25,19 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "filefilteritems.h"
|
||||
|
||||
#include <utils/environment.h>
|
||||
|
||||
#include <QObject>
|
||||
#include <QSet>
|
||||
#include <QStringList>
|
||||
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
|
||||
namespace QmlProjectManager {
|
||||
|
||||
class QmlProjectContentItem : public QObject {
|
||||
// base class for all elements that should be direct children of Project element
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
QmlProjectContentItem(QObject *parent = nullptr) : QObject(parent) {}
|
||||
};
|
||||
|
||||
class QmlProjectItem : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
@@ -91,9 +88,12 @@ public:
|
||||
void setShaderToolArgs(const QStringList &args) {m_shaderToolArgs = args; }
|
||||
|
||||
QStringList shaderToolFiles() const { return m_shaderToolFiles; }
|
||||
void setShaderToolFiles(const QStringList &files) {m_shaderToolFiles = files; }
|
||||
void setShaderToolFiles(const QStringList &files) { m_shaderToolFiles = files; }
|
||||
|
||||
void appendContent(QmlProjectContentItem *item) { m_content.append(item); }
|
||||
void appendContent(std::unique_ptr<FileFilterBaseItem> item)
|
||||
{
|
||||
m_content.push_back(std::move(item));
|
||||
}
|
||||
|
||||
Utils::EnvironmentItems environment() const;
|
||||
void addToEnviroment(const QString &key, const QString &value);
|
||||
@@ -112,7 +112,7 @@ protected:
|
||||
QString m_mainFile;
|
||||
QString m_mainUiFile;
|
||||
Utils::EnvironmentItems m_environment;
|
||||
QVector<QmlProjectContentItem *> m_content; // content property
|
||||
std::vector<std::unique_ptr<FileFilterBaseItem>> m_content; // content property
|
||||
bool m_forceFreeType = false;
|
||||
bool m_qtForMCUs = false;
|
||||
bool m_qt6Project = false;
|
||||
|
Reference in New Issue
Block a user