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
|
#pragma once
|
||||||
|
|
||||||
#include "qmlprojectitem.h"
|
|
||||||
|
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
#include <QRegularExpression>
|
#include <QRegularExpression>
|
||||||
#include <QSet>
|
#include <QSet>
|
||||||
@@ -38,6 +36,17 @@ namespace Utils { class FileSystemWatcher; }
|
|||||||
|
|
||||||
namespace QmlProjectManager {
|
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 {
|
class FileFilterBaseItem : public QmlProjectContentItem {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
|
@@ -28,8 +28,10 @@
|
|||||||
#include "filefilteritems.h"
|
#include "filefilteritems.h"
|
||||||
#include <qmljs/qmljssimplereader.h>
|
#include <qmljs/qmljssimplereader.h>
|
||||||
|
|
||||||
#include <QVariant>
|
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
|
#include <QVariant>
|
||||||
|
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
enum {
|
enum {
|
||||||
debug = false
|
debug = false
|
||||||
@@ -37,7 +39,9 @@ enum {
|
|||||||
|
|
||||||
namespace {
|
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"));
|
const auto directoryProperty = node->property(QLatin1String("directory"));
|
||||||
if (directoryProperty.isValid())
|
if (directoryProperty.isValid())
|
||||||
@@ -148,17 +152,24 @@ QmlProjectItem *QmlProjectFileFormat::parseProjectFile(const Utils::FilePath &fi
|
|||||||
qDebug() << "reading type:" << childNode->name();
|
qDebug() << "reading type:" << childNode->name();
|
||||||
|
|
||||||
if (childNode->name() == QLatin1String("QmlFiles")) {
|
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")) {
|
} 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")) {
|
} 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")) {
|
} 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")) {
|
} 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")) {
|
} 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") {
|
} else if (childNode->name() == "Environment") {
|
||||||
const auto properties = childNode->properties();
|
const auto properties = childNode->properties();
|
||||||
auto i = properties.constBegin();
|
auto i = properties.constBegin();
|
||||||
|
@@ -40,13 +40,12 @@ void QmlProjectItem::setSourceDirectory(const QString &directoryPath)
|
|||||||
|
|
||||||
m_sourceDirectory = directoryPath;
|
m_sourceDirectory = directoryPath;
|
||||||
|
|
||||||
for (auto contentElement : qAsConst(m_content)) {
|
for (auto &fileFilter : m_content) {
|
||||||
auto fileFilter = qobject_cast<FileFilterBaseItem*>(contentElement);
|
|
||||||
if (fileFilter) {
|
|
||||||
fileFilter->setDefaultDirectory(directoryPath);
|
fileFilter->setDefaultDirectory(directoryPath);
|
||||||
connect(fileFilter, &FileFilterBaseItem::filesChanged,
|
connect(fileFilter.get(),
|
||||||
this, &QmlProjectItem::qmlFilesChanged);
|
&FileFilterBaseItem::filesChanged,
|
||||||
}
|
this,
|
||||||
|
&QmlProjectItem::qmlFilesChanged);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -99,14 +98,12 @@ QStringList QmlProjectItem::files() const
|
|||||||
{
|
{
|
||||||
QSet<QString> files;
|
QSet<QString> files;
|
||||||
|
|
||||||
for (const auto contentElement : qAsConst(m_content)) {
|
for (const auto &fileFilter : m_content) {
|
||||||
if (auto fileFilter = qobject_cast<const FileFilterBaseItem *>(contentElement)) {
|
|
||||||
const QStringList fileList = fileFilter->files();
|
const QStringList fileList = fileFilter->files();
|
||||||
for (const QString &file : fileList) {
|
for (const QString &file : fileList) {
|
||||||
files.insert(file);
|
files.insert(file);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
return Utils::toList(files);
|
return Utils::toList(files);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -118,9 +115,8 @@ QStringList QmlProjectItem::files() const
|
|||||||
*/
|
*/
|
||||||
bool QmlProjectItem::matchesFile(const QString &filePath) const
|
bool QmlProjectItem::matchesFile(const QString &filePath) const
|
||||||
{
|
{
|
||||||
return Utils::contains(m_content, [&filePath](const QmlProjectContentItem *item) {
|
return Utils::contains(m_content, [&filePath](const auto &fileFilter) {
|
||||||
auto fileFilter = qobject_cast<const FileFilterBaseItem *>(item);
|
return fileFilter->matchesFile(filePath);
|
||||||
return fileFilter && fileFilter->matchesFile(filePath);
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -25,22 +25,19 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include "filefilteritems.h"
|
||||||
|
|
||||||
#include <utils/environment.h>
|
#include <utils/environment.h>
|
||||||
|
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
#include <QSet>
|
#include <QSet>
|
||||||
#include <QStringList>
|
#include <QStringList>
|
||||||
|
|
||||||
|
#include <memory>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
namespace QmlProjectManager {
|
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
|
class QmlProjectItem : public QObject
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
@@ -91,9 +88,12 @@ public:
|
|||||||
void setShaderToolArgs(const QStringList &args) {m_shaderToolArgs = args; }
|
void setShaderToolArgs(const QStringList &args) {m_shaderToolArgs = args; }
|
||||||
|
|
||||||
QStringList shaderToolFiles() const { return m_shaderToolFiles; }
|
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;
|
Utils::EnvironmentItems environment() const;
|
||||||
void addToEnviroment(const QString &key, const QString &value);
|
void addToEnviroment(const QString &key, const QString &value);
|
||||||
@@ -112,7 +112,7 @@ protected:
|
|||||||
QString m_mainFile;
|
QString m_mainFile;
|
||||||
QString m_mainUiFile;
|
QString m_mainUiFile;
|
||||||
Utils::EnvironmentItems m_environment;
|
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_forceFreeType = false;
|
||||||
bool m_qtForMCUs = false;
|
bool m_qtForMCUs = false;
|
||||||
bool m_qt6Project = false;
|
bool m_qt6Project = false;
|
||||||
|
Reference in New Issue
Block a user