QmlProjectManager: De-pimpl QmlProjectItem

And remove dead code.

Change-Id: Ia7bd16c028e7275afb2bf88940eac3894411967a
Reviewed-by: Tim Jenssen <tim.jenssen@qt.io>
This commit is contained in:
hjk
2017-02-28 17:15:19 +01:00
parent ac3710735b
commit c887de8c1a
2 changed files with 23 additions and 123 deletions

View File

@@ -26,71 +26,20 @@
#include "qmlprojectitem.h"
#include "filefilteritems.h"
#include <QDebug>
#include <QDir>
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
void QmlProjectItem::setSourceDirectory(const QString &directoryPath)
{
Q_D(QmlProjectItem);
if (d->sourceDirectory == directoryPath)
if (m_sourceDirectory == directoryPath)
return;
d->sourceDirectory = directoryPath;
m_sourceDirectory = directoryPath;
for (int i = 0; i < d->content.size(); ++i) {
QmlProjectContentItem *contentElement = d->content.at(i);
for (int i = 0; i < m_content.size(); ++i) {
QmlProjectContentItem *contentElement = m_content.at(i);
FileFilterBaseItem *fileFilter = qobject_cast<FileFilterBaseItem*>(contentElement);
if (fileFilter) {
fileFilter->setDefaultDirectory(directoryPath);
@@ -99,23 +48,13 @@ void QmlProjectItem::setSourceDirectory(const QString &directoryPath)
}
}
setImportPaths(d->importPaths);
emit sourceDirectoryChanged();
}
QStringList QmlProjectItem::importPaths() const
{
Q_D(const QmlProjectItem);
return d->absoluteImportPaths;
setImportPaths(m_importPaths);
}
void QmlProjectItem::setImportPaths(const QStringList &importPaths)
{
Q_D(QmlProjectItem);
if (d->importPaths != importPaths)
d->importPaths = importPaths;
if (m_importPaths != importPaths)
m_importPaths = importPaths;
// convert to absolute paths
QStringList absoluteImportPaths;
@@ -123,23 +62,19 @@ void QmlProjectItem::setImportPaths(const QStringList &importPaths)
foreach (const QString &importPath, importPaths)
absoluteImportPaths += QDir::cleanPath(sourceDir.absoluteFilePath(importPath));
if (d->absoluteImportPaths == absoluteImportPaths)
if (m_absoluteImportPaths == absoluteImportPaths)
return;
d->absoluteImportPaths = absoluteImportPaths;
emit importPathsChanged();
m_absoluteImportPaths = absoluteImportPaths;
}
/* Returns list of absolute paths */
QStringList QmlProjectItem::files() const
{
Q_D(const QmlProjectItem);
QStringList files;
for (int i = 0; i < d->content.size(); ++i) {
QmlProjectContentItem *contentElement = d->content.at(i);
FileFilterBaseItem *fileFilter = qobject_cast<FileFilterBaseItem*>(contentElement);
if (fileFilter) {
for (QmlProjectContentItem *contentElement : m_content) {
if (auto fileFilter = qobject_cast<FileFilterBaseItem *>(contentElement)) {
foreach (const QString &file, fileFilter->files()) {
if (!files.contains(file))
files << file;
@@ -157,11 +92,8 @@ QStringList QmlProjectItem::files() const
*/
bool QmlProjectItem::matchesFile(const QString &filePath) const
{
Q_D(const QmlProjectItem);
for (int i = 0; i < d->content.size(); ++i) {
QmlProjectContentItem *contentElement = d->content.at(i);
FileFilterBaseItem *fileFilter = qobject_cast<FileFilterBaseItem*>(contentElement);
if (fileFilter) {
for (QmlProjectContentItem *contentElement : m_content) {
if (auto fileFilter = qobject_cast<FileFilterBaseItem *>(contentElement)) {
if (fileFilter->matchesFile(filePath))
return true;
}
@@ -169,27 +101,4 @@ bool QmlProjectItem::matchesFile(const QString &filePath) const
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
#include "qmlprojectitem.moc"

View File

@@ -39,43 +39,34 @@ public:
QmlProjectContentItem(QObject *parent = 0) : QObject(parent) {}
};
class QmlProjectItemPrivate;
class QmlProjectItem : public QObject
{
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:
QmlProjectItem(QObject *parent = 0);
~QmlProjectItem();
QString sourceDirectory() const;
QString sourceDirectory() const { return m_sourceDirectory; }
void setSourceDirectory(const QString &directoryPath);
QStringList importPaths() const;
QStringList importPaths() const { return m_absoluteImportPaths; }
void setImportPaths(const QStringList &paths);
QStringList files() const;
bool matchesFile(const QString &filePath) const;
QString mainFile() const;
void setMainFile(const QString &mainFilePath);
QString mainFile() const { return m_mainFile; }
void setMainFile(const QString &mainFilePath) { m_mainFile = mainFilePath; }
void appendContent(QmlProjectContentItem* contentItem);
void appendContent(QmlProjectContentItem *item) { m_content.append(item); }
signals:
void qmlFilesChanged(const QSet<QString> &, const QSet<QString> &);
void sourceDirectoryChanged();
void importPathsChanged();
void mainFileChanged();
protected:
QmlProjectItemPrivate *d_ptr;
QString m_sourceDirectory;
QStringList m_importPaths;
QStringList m_absoluteImportPaths;
QString m_mainFile;
QList<QmlProjectContentItem *> m_content; // content property
};
} // namespace QmlProjectManager