forked from qt-creator/qt-creator
QmlProjectManager: De-pimpl QmlProjectItem
And remove dead code. Change-Id: Ia7bd16c028e7275afb2bf88940eac3894411967a Reviewed-by: Tim Jenssen <tim.jenssen@qt.io>
This commit is contained in:
@@ -26,71 +26,20 @@
|
|||||||
#include "qmlprojectitem.h"
|
#include "qmlprojectitem.h"
|
||||||
#include "filefilteritems.h"
|
#include "filefilteritems.h"
|
||||||
|
|
||||||
#include <QDebug>
|
|
||||||
#include <QDir>
|
#include <QDir>
|
||||||
|
|
||||||
namespace QmlProjectManager {
|
namespace QmlProjectManager {
|
||||||
|
|
||||||
class QmlProjectItemPrivate : public QObject {
|
|
||||||
Q_OBJECT
|
|
||||||
|
|
||||||
public:
|
|
||||||
QString sourceDirectory;
|
|
||||||
QStringList importPaths;
|
|
||||||
QStringList absoluteImportPaths;
|
|
||||||
QString mainFile;
|
|
||||||
|
|
||||||
QList<QmlFileFilterItem*> qmlFileFilters() const;
|
|
||||||
|
|
||||||
// content property
|
|
||||||
QList<QmlProjectContentItem*> content;
|
|
||||||
};
|
|
||||||
|
|
||||||
QList<QmlFileFilterItem*> QmlProjectItemPrivate::qmlFileFilters() const
|
|
||||||
{
|
|
||||||
QList<QmlFileFilterItem*> qmlFilters;
|
|
||||||
for (int i = 0; i < content.size(); ++i) {
|
|
||||||
QmlProjectContentItem *contentElement = content.at(i);
|
|
||||||
QmlFileFilterItem *qmlFileFilter = qobject_cast<QmlFileFilterItem*>(contentElement);
|
|
||||||
if (qmlFileFilter)
|
|
||||||
qmlFilters << qmlFileFilter;
|
|
||||||
}
|
|
||||||
return qmlFilters;
|
|
||||||
}
|
|
||||||
|
|
||||||
QmlProjectItem::QmlProjectItem(QObject *parent) :
|
|
||||||
QObject(parent),
|
|
||||||
d_ptr(new QmlProjectItemPrivate)
|
|
||||||
{
|
|
||||||
// Q_D(QmlProjectItem);
|
|
||||||
//
|
|
||||||
// QmlFileFilter *defaultQmlFilter = new QmlFileFilter(this);
|
|
||||||
// d->content.append(defaultQmlFilter);
|
|
||||||
}
|
|
||||||
|
|
||||||
QmlProjectItem::~QmlProjectItem()
|
|
||||||
{
|
|
||||||
delete d_ptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
QString QmlProjectItem::sourceDirectory() const
|
|
||||||
{
|
|
||||||
Q_D(const QmlProjectItem);
|
|
||||||
return d->sourceDirectory;
|
|
||||||
}
|
|
||||||
|
|
||||||
// kind of initialization
|
// kind of initialization
|
||||||
void QmlProjectItem::setSourceDirectory(const QString &directoryPath)
|
void QmlProjectItem::setSourceDirectory(const QString &directoryPath)
|
||||||
{
|
{
|
||||||
Q_D(QmlProjectItem);
|
if (m_sourceDirectory == directoryPath)
|
||||||
|
|
||||||
if (d->sourceDirectory == directoryPath)
|
|
||||||
return;
|
return;
|
||||||
|
|
||||||
d->sourceDirectory = directoryPath;
|
m_sourceDirectory = directoryPath;
|
||||||
|
|
||||||
for (int i = 0; i < d->content.size(); ++i) {
|
for (int i = 0; i < m_content.size(); ++i) {
|
||||||
QmlProjectContentItem *contentElement = d->content.at(i);
|
QmlProjectContentItem *contentElement = m_content.at(i);
|
||||||
FileFilterBaseItem *fileFilter = qobject_cast<FileFilterBaseItem*>(contentElement);
|
FileFilterBaseItem *fileFilter = qobject_cast<FileFilterBaseItem*>(contentElement);
|
||||||
if (fileFilter) {
|
if (fileFilter) {
|
||||||
fileFilter->setDefaultDirectory(directoryPath);
|
fileFilter->setDefaultDirectory(directoryPath);
|
||||||
@@ -99,23 +48,13 @@ void QmlProjectItem::setSourceDirectory(const QString &directoryPath)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
setImportPaths(d->importPaths);
|
setImportPaths(m_importPaths);
|
||||||
|
|
||||||
emit sourceDirectoryChanged();
|
|
||||||
}
|
|
||||||
|
|
||||||
QStringList QmlProjectItem::importPaths() const
|
|
||||||
{
|
|
||||||
Q_D(const QmlProjectItem);
|
|
||||||
return d->absoluteImportPaths;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void QmlProjectItem::setImportPaths(const QStringList &importPaths)
|
void QmlProjectItem::setImportPaths(const QStringList &importPaths)
|
||||||
{
|
{
|
||||||
Q_D(QmlProjectItem);
|
if (m_importPaths != importPaths)
|
||||||
|
m_importPaths = importPaths;
|
||||||
if (d->importPaths != importPaths)
|
|
||||||
d->importPaths = importPaths;
|
|
||||||
|
|
||||||
// convert to absolute paths
|
// convert to absolute paths
|
||||||
QStringList absoluteImportPaths;
|
QStringList absoluteImportPaths;
|
||||||
@@ -123,23 +62,19 @@ void QmlProjectItem::setImportPaths(const QStringList &importPaths)
|
|||||||
foreach (const QString &importPath, importPaths)
|
foreach (const QString &importPath, importPaths)
|
||||||
absoluteImportPaths += QDir::cleanPath(sourceDir.absoluteFilePath(importPath));
|
absoluteImportPaths += QDir::cleanPath(sourceDir.absoluteFilePath(importPath));
|
||||||
|
|
||||||
if (d->absoluteImportPaths == absoluteImportPaths)
|
if (m_absoluteImportPaths == absoluteImportPaths)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
d->absoluteImportPaths = absoluteImportPaths;
|
m_absoluteImportPaths = absoluteImportPaths;
|
||||||
emit importPathsChanged();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Returns list of absolute paths */
|
/* Returns list of absolute paths */
|
||||||
QStringList QmlProjectItem::files() const
|
QStringList QmlProjectItem::files() const
|
||||||
{
|
{
|
||||||
Q_D(const QmlProjectItem);
|
|
||||||
QStringList files;
|
QStringList files;
|
||||||
|
|
||||||
for (int i = 0; i < d->content.size(); ++i) {
|
for (QmlProjectContentItem *contentElement : m_content) {
|
||||||
QmlProjectContentItem *contentElement = d->content.at(i);
|
if (auto fileFilter = qobject_cast<FileFilterBaseItem *>(contentElement)) {
|
||||||
FileFilterBaseItem *fileFilter = qobject_cast<FileFilterBaseItem*>(contentElement);
|
|
||||||
if (fileFilter) {
|
|
||||||
foreach (const QString &file, fileFilter->files()) {
|
foreach (const QString &file, fileFilter->files()) {
|
||||||
if (!files.contains(file))
|
if (!files.contains(file))
|
||||||
files << file;
|
files << file;
|
||||||
@@ -157,11 +92,8 @@ QStringList QmlProjectItem::files() const
|
|||||||
*/
|
*/
|
||||||
bool QmlProjectItem::matchesFile(const QString &filePath) const
|
bool QmlProjectItem::matchesFile(const QString &filePath) const
|
||||||
{
|
{
|
||||||
Q_D(const QmlProjectItem);
|
for (QmlProjectContentItem *contentElement : m_content) {
|
||||||
for (int i = 0; i < d->content.size(); ++i) {
|
if (auto fileFilter = qobject_cast<FileFilterBaseItem *>(contentElement)) {
|
||||||
QmlProjectContentItem *contentElement = d->content.at(i);
|
|
||||||
FileFilterBaseItem *fileFilter = qobject_cast<FileFilterBaseItem*>(contentElement);
|
|
||||||
if (fileFilter) {
|
|
||||||
if (fileFilter->matchesFile(filePath))
|
if (fileFilter->matchesFile(filePath))
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -169,27 +101,4 @@ bool QmlProjectItem::matchesFile(const QString &filePath) const
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
QString QmlProjectItem::mainFile() const
|
|
||||||
{
|
|
||||||
Q_D(const QmlProjectItem);
|
|
||||||
return d->mainFile;
|
|
||||||
}
|
|
||||||
|
|
||||||
void QmlProjectItem::setMainFile(const QString &mainFilePath)
|
|
||||||
{
|
|
||||||
Q_D(QmlProjectItem);
|
|
||||||
if (mainFilePath == d->mainFile)
|
|
||||||
return;
|
|
||||||
d->mainFile = mainFilePath;
|
|
||||||
emit mainFileChanged();
|
|
||||||
}
|
|
||||||
|
|
||||||
void QmlProjectItem::appendContent(QmlProjectContentItem *contentItem)
|
|
||||||
{
|
|
||||||
Q_D(QmlProjectItem);
|
|
||||||
d->content.append(contentItem);
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace QmlProjectManager
|
} // namespace QmlProjectManager
|
||||||
|
|
||||||
#include "qmlprojectitem.moc"
|
|
||||||
|
@@ -39,43 +39,34 @@ public:
|
|||||||
QmlProjectContentItem(QObject *parent = 0) : QObject(parent) {}
|
QmlProjectContentItem(QObject *parent = 0) : QObject(parent) {}
|
||||||
};
|
};
|
||||||
|
|
||||||
class QmlProjectItemPrivate;
|
|
||||||
|
|
||||||
class QmlProjectItem : public QObject
|
class QmlProjectItem : public QObject
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
Q_DECLARE_PRIVATE(QmlProjectItem)
|
|
||||||
|
|
||||||
Q_PROPERTY(QString sourceDirectory READ sourceDirectory NOTIFY sourceDirectoryChanged)
|
|
||||||
Q_PROPERTY(QStringList importPaths READ importPaths WRITE setImportPaths NOTIFY importPathsChanged)
|
|
||||||
Q_PROPERTY(QString mainFile READ mainFile WRITE setMainFile NOTIFY mainFileChanged)
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
QmlProjectItem(QObject *parent = 0);
|
QString sourceDirectory() const { return m_sourceDirectory; }
|
||||||
~QmlProjectItem();
|
|
||||||
|
|
||||||
QString sourceDirectory() const;
|
|
||||||
void setSourceDirectory(const QString &directoryPath);
|
void setSourceDirectory(const QString &directoryPath);
|
||||||
|
|
||||||
QStringList importPaths() const;
|
QStringList importPaths() const { return m_absoluteImportPaths; }
|
||||||
void setImportPaths(const QStringList &paths);
|
void setImportPaths(const QStringList &paths);
|
||||||
|
|
||||||
QStringList files() const;
|
QStringList files() const;
|
||||||
bool matchesFile(const QString &filePath) const;
|
bool matchesFile(const QString &filePath) const;
|
||||||
|
|
||||||
QString mainFile() const;
|
QString mainFile() const { return m_mainFile; }
|
||||||
void setMainFile(const QString &mainFilePath);
|
void setMainFile(const QString &mainFilePath) { m_mainFile = mainFilePath; }
|
||||||
|
|
||||||
void appendContent(QmlProjectContentItem* contentItem);
|
void appendContent(QmlProjectContentItem *item) { m_content.append(item); }
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void qmlFilesChanged(const QSet<QString> &, const QSet<QString> &);
|
void qmlFilesChanged(const QSet<QString> &, const QSet<QString> &);
|
||||||
void sourceDirectoryChanged();
|
|
||||||
void importPathsChanged();
|
|
||||||
void mainFileChanged();
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
QmlProjectItemPrivate *d_ptr;
|
QString m_sourceDirectory;
|
||||||
|
QStringList m_importPaths;
|
||||||
|
QStringList m_absoluteImportPaths;
|
||||||
|
QString m_mainFile;
|
||||||
|
QList<QmlProjectContentItem *> m_content; // content property
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace QmlProjectManager
|
} // namespace QmlProjectManager
|
||||||
|
Reference in New Issue
Block a user