diff options
author | Radovan Zivkovic <pivonroll@gmail.com> | 2013-08-05 01:04:20 +0200 |
---|---|---|
committer | Oswald Buddenhagen <oswald.buddenhagen@digia.com> | 2014-03-11 19:54:55 +0100 |
commit | 02d8fb1f5f42f11c1a8b2ee4887ef72a6f94cd2d (patch) | |
tree | 1a5deb5e2aae04aa6c1295a2485af109b9408858 | |
parent | 4112d34028f991b061c9bc79d3d14b0061bfcbb2 (diff) |
Removed FileType class.
Change-Id: I0ba9c93157d819e663dc5cf6ab6e897d645046c8
Reviewed-by: Bojan Petrovic <bojan85@gmail.com>
5 files changed, 163 insertions, 389 deletions
diff --git a/src/plugins/vcprojectmanager/vcprojectmodel/file.cpp b/src/plugins/vcprojectmanager/vcprojectmodel/file.cpp index a21741237f..99bf48823b 100644 --- a/src/plugins/vcprojectmanager/vcprojectmodel/file.cpp +++ b/src/plugins/vcprojectmanager/vcprojectmodel/file.cpp @@ -30,41 +30,93 @@ #include "file.h" #include "fileconfiguration.h" -#include "filetype.h" #include "fileconfigurationfactory.h" +#include "vcprojectdocument.h" + +#include <projectexplorer/projectexplorerconstants.h> +#include <coreplugin/mimedatabase.h> +#include <coreplugin/icore.h> namespace VcProjectManager { namespace Internal { File::File(VcProjectDocument *parentProjectDoc) - : m_fileType(FileType::Ptr(new FileType(parentProjectDoc))) + : m_parentProjectDoc(parentProjectDoc) { } File::File(const File &file) { - m_fileType = file.m_fileType->clone(); + m_parentProjectDoc = file.m_parentProjectDoc; + m_relativePath = file.m_relativePath; + + foreach (const File::Ptr &f, file.m_files) + m_files.append(File::Ptr(new File(*f))); + + foreach (const FileConfiguration::Ptr &fileConfig, m_fileConfigurations) + m_fileConfigurations.append(fileConfig->clone()); } File &File::operator =(const File &file) { - if (this != &file) - m_fileType = file.m_fileType->clone(); + if (this != &file) { + m_parentProjectDoc = file.m_parentProjectDoc; + m_relativePath = file.m_relativePath; + + m_files.clear(); + m_fileConfigurations.clear(); + + foreach (const File::Ptr &f, file.m_files) + m_files.append(File::Ptr(new File(*f))); + + foreach (const FileConfiguration::Ptr &fileConfig, m_fileConfigurations) + m_fileConfigurations.append(fileConfig->clone()); + } return *this; } File::~File() { + m_files.clear(); + m_fileConfigurations.clear(); } void File::processNode(const QDomNode &node) { - m_fileType->processNode(node); + if (node.isNull()) + return; + + if (node.nodeType() == QDomNode::ElementNode) + processNodeAttributes(node.toElement()); + + if (node.hasChildNodes()) { + QDomNode firstChild = node.firstChild(); + if (!firstChild.isNull()) { + if (firstChild.nodeName() == QLatin1String("FileConfiguration")) + processFileConfiguration(firstChild); + else if (firstChild.nodeName() == QLatin1String("File")) + processFile(firstChild); + } + } } void File::processNodeAttributes(const QDomElement &element) { - Q_UNUSED(element) + QDomNamedNodeMap namedNodeMap = element.attributes(); + + for (int i = 0; i < namedNodeMap.size(); ++i) { + QDomNode domNode = namedNodeMap.item(i); + + if (domNode.nodeType() == QDomNode::AttributeNode) { + QDomAttr domElement = domNode.toAttr(); + + if (domElement.name() == QLatin1String("RelativePath")) + m_relativePath = domElement.value(); + + else + m_anyAttribute.insert(domElement.name(), domElement.value()); + } + } } VcNodeWidget *File::createSettingsWidget() @@ -74,67 +126,146 @@ VcNodeWidget *File::createSettingsWidget() QDomNode File::toXMLDomNode(QDomDocument &domXMLDocument) const { - return m_fileType->toXMLDomNode(domXMLDocument); + QDomElement fileNode = domXMLDocument.createElement(QLatin1String("File")); + + fileNode.setAttribute(QLatin1String("RelativePath"), m_relativePath); + + QHashIterator<QString, QString> it(m_anyAttribute); + + while (it.hasNext()) { + it.next(); + fileNode.setAttribute(it.key(), it.value()); + } + + foreach (const File::Ptr &file, m_files) + fileNode.appendChild(file->toXMLDomNode(domXMLDocument)); + + foreach (const FileConfiguration::Ptr &fileConfig, m_fileConfigurations) + fileNode.appendChild(fileConfig->toXMLDomNode(domXMLDocument)); + + return fileNode; } void File::addFile(File::Ptr file) { - m_fileType->addFile(file); + if (m_files.contains(file)) + return; + m_files.append(file); } void File::removeFile(File::Ptr file) { - m_fileType->removeFile(file); + if (m_files.contains(file)) + m_files.removeAll(file); } void File::addFileConfiguration(FileConfiguration::Ptr fileConfig) { - m_fileType->addFileConfiguration(fileConfig); + if (m_fileConfigurations.contains(fileConfig)) + return; + m_fileConfigurations.append(fileConfig); } void File::removeFileConfiguration(FileConfiguration::Ptr fileConfig) { - m_fileType->removeFileConfiguration(fileConfig); + if (m_fileConfigurations.contains(fileConfig)) + m_fileConfigurations.removeAll(fileConfig); } QString File::attributeValue(const QString &attributeName) const { - return m_fileType->attributeValue(attributeName); + return m_anyAttribute.value(attributeName); } void File::setAttribute(const QString &attributeName, const QString &attributeValue) { - m_fileType->setAttribute(attributeName, attributeValue); + m_anyAttribute.insert(attributeName, attributeValue); } void File::clearAttribute(const QString &attributeName) { - m_fileType->clearAttribute(attributeName); + // no need to clear the attribute's value if attribute isn't present + if (m_anyAttribute.contains(attributeName)) + m_anyAttribute.insert(attributeName, QString()); } void File::removeAttribute(const QString &attributeName) { - m_fileType->removeAttribute(attributeName); + m_anyAttribute.remove(attributeName); } QString File::relativePath() const { - return m_fileType->relativePath(); + return m_relativePath; } void File::setRelativePath(const QString &relativePath) { - m_fileType->setRelativePath(relativePath); + m_relativePath = relativePath; } ProjectExplorer::FileType File::fileType() const { - return m_fileType->fileType(); + const Core::MimeDatabase *mdb = Core::ICore::mimeDatabase(); + QString mimeType = mdb->findByFile(canonicalPath()).type(); + + if (mimeType == QLatin1String(ProjectExplorer::Constants::CPP_SOURCE_MIMETYPE) + || mimeType == QLatin1String(ProjectExplorer::Constants::C_SOURCE_MIMETYPE)) + return ProjectExplorer::SourceType; + if (mimeType == QLatin1String(ProjectExplorer::Constants::CPP_HEADER_MIMETYPE) + || mimeType == QLatin1String(ProjectExplorer::Constants::C_HEADER_MIMETYPE)) + return ProjectExplorer::HeaderType; + if (mimeType == QLatin1String(ProjectExplorer::Constants::RESOURCE_MIMETYPE)) + return ProjectExplorer::ResourceType; + if (mimeType == QLatin1String(ProjectExplorer::Constants::FORM_MIMETYPE)) + return ProjectExplorer::FormType; + if (mimeType == QLatin1String(ProjectExplorer::Constants::QML_MIMETYPE)) + return ProjectExplorer::QMLType; + + return ProjectExplorer::UnknownFileType; } QString File::canonicalPath() const { - return m_fileType->canonicalPath(); + if (m_parentProjectDoc) { + QFileInfo fileInfo(m_parentProjectDoc->filePath()); + fileInfo = QFileInfo(fileInfo.canonicalPath() + QLatin1Char('/') + m_relativePath); + return fileInfo.canonicalFilePath(); + } + + return QString() + m_relativePath; +} + +void File::processFileConfiguration(const QDomNode &fileConfigNode) +{ + FileConfiguration::Ptr fileConfig = FileConfigFactory::createFileConfiguration(m_parentProjectDoc->documentVersion()); + fileConfig->processNode(fileConfigNode); + m_fileConfigurations.append(fileConfig); + + // process next sibling + QDomNode nextSibling = fileConfigNode.nextSibling(); + if (!nextSibling.isNull()) { + if (nextSibling.nodeName() == QLatin1String("FileConfiguration")) + processFileConfiguration(nextSibling); + else + processFile(nextSibling); + } +} + +void File::processFile(const QDomNode &fileNode) +{ + File::Ptr file(new File(m_parentProjectDoc)); + file->processNode(fileNode); + m_files.append(file); + + // process next sibling + QDomNode nextSibling = fileNode.nextSibling(); + if (!nextSibling.isNull()) { + if (nextSibling.nodeName() == QLatin1String("FileConfiguration")) + processFileConfiguration(nextSibling); + else + processFile(nextSibling); + } } } // namespace Internal diff --git a/src/plugins/vcprojectmanager/vcprojectmodel/file.h b/src/plugins/vcprojectmanager/vcprojectmodel/file.h index bfa37f90c5..558807373d 100644 --- a/src/plugins/vcprojectmanager/vcprojectmodel/file.h +++ b/src/plugins/vcprojectmanager/vcprojectmodel/file.h @@ -31,12 +31,15 @@ #define VCPROJECTMANAGER_INTERNAL_FILE_H #include "ivcprojectnodemodel.h" +#include "fileconfiguration.h" -#include "filetype.h" +#include <projectexplorer/projectnodes.h> namespace VcProjectManager { namespace Internal { +class VcProjectDocument; + class File : public IVcProjectXMLNode { friend class FileFactory; @@ -69,7 +72,14 @@ public: ProjectExplorer::FileType fileType() const; QString canonicalPath() const; private: - FileType::Ptr m_fileType; + void processFileConfiguration(const QDomNode &fileConfigNode); + void processFile(const QDomNode &fileNode); + + QString m_relativePath; // required + QList<QSharedPointer<File> > m_files; + QList<FileConfiguration::Ptr> m_fileConfigurations; + QHash<QString, QString> m_anyAttribute; + VcProjectDocument *m_parentProjectDoc; }; } // namespace Internal diff --git a/src/plugins/vcprojectmanager/vcprojectmodel/filetype.cpp b/src/plugins/vcprojectmanager/vcprojectmodel/filetype.cpp deleted file mode 100644 index 585e19ffef..0000000000 --- a/src/plugins/vcprojectmanager/vcprojectmodel/filetype.cpp +++ /dev/null @@ -1,272 +0,0 @@ -/************************************************************************** -** -** Copyright (c) 2013 Bojan Petrovic -** Copyright (c) 2013 Radovan Zivkvoic -** Contact: http://www.qt-project.org/legal -** -** This file is part of Qt Creator. -** -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. For licensing terms and -** conditions see http://qt.digia.com/licensing. For further information -** use the contact form at http://qt.digia.com/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -****************************************************************************/ -#include "filetype.h" - -#include "file.h" -#include "fileconfigurationfactory.h" -#include "vcprojectdocument.h" - -#include <projectexplorer/projectexplorerconstants.h> -#include <coreplugin/mimedatabase.h> -#include <coreplugin/icore.h> - -namespace VcProjectManager { -namespace Internal { - -FileType::~FileType() -{ - m_files.clear(); - m_fileConfigurations.clear(); -} - -void FileType::processNode(const QDomNode &node) -{ - if (node.isNull()) - return; - - if (node.nodeType() == QDomNode::ElementNode) - processNodeAttributes(node.toElement()); - - if (node.hasChildNodes()) { - QDomNode firstChild = node.firstChild(); - if (!firstChild.isNull()) { - if (firstChild.nodeName() == QLatin1String("FileConfiguration")) - processFileConfiguration(firstChild); - else if (firstChild.nodeName() == QLatin1String("File")) - processFile(firstChild); - } - } -} - -QDomNode FileType::toXMLDomNode(QDomDocument &domXMLDocument) const -{ - QDomElement fileNode = domXMLDocument.createElement(QLatin1String("File")); - - fileNode.setAttribute(QLatin1String("RelativePath"), m_relativePath); - - QHashIterator<QString, QString> it(m_anyAttribute); - - while (it.hasNext()) { - it.next(); - fileNode.setAttribute(it.key(), it.value()); - } - - foreach (const File::Ptr &file, m_files) - fileNode.appendChild(file->toXMLDomNode(domXMLDocument)); - - foreach (const FileConfiguration::Ptr &fileConfig, m_fileConfigurations) - fileNode.appendChild(fileConfig->toXMLDomNode(domXMLDocument)); - - return fileNode; -} - -ProjectExplorer::FileType FileType::fileType() const -{ - const Core::MimeDatabase *mdb = Core::ICore::mimeDatabase(); - QString mimeType = mdb->findByFile(canonicalPath()).type(); - - if (mimeType == QLatin1String(ProjectExplorer::Constants::CPP_SOURCE_MIMETYPE) - || mimeType == QLatin1String(ProjectExplorer::Constants::C_SOURCE_MIMETYPE)) - return ProjectExplorer::SourceType; - if (mimeType == QLatin1String(ProjectExplorer::Constants::CPP_HEADER_MIMETYPE) - || mimeType == QLatin1String(ProjectExplorer::Constants::C_HEADER_MIMETYPE)) - return ProjectExplorer::HeaderType; - if (mimeType == QLatin1String(ProjectExplorer::Constants::RESOURCE_MIMETYPE)) - return ProjectExplorer::ResourceType; - if (mimeType == QLatin1String(ProjectExplorer::Constants::FORM_MIMETYPE)) - return ProjectExplorer::FormType; - if (mimeType == QLatin1String(ProjectExplorer::Constants::QML_MIMETYPE)) - return ProjectExplorer::QMLType; - - return ProjectExplorer::UnknownFileType; -} - -FileType::Ptr FileType::clone() const -{ - return FileType::Ptr(new FileType(*this)); -} - -void FileType::addFile(QSharedPointer<File> file) -{ - if (m_files.contains(file)) - return; - m_files.append(file); -} - -void FileType::removeFile(QSharedPointer<File> file) -{ - if (m_files.contains(file)) - m_files.removeAll(file); -} - -void FileType::addFileConfiguration(FileConfiguration::Ptr fileConfig) -{ - if (m_fileConfigurations.contains(fileConfig)) - return; - m_fileConfigurations.append(fileConfig); -} - -void FileType::removeFileConfiguration(FileConfiguration::Ptr fileConfig) -{ - if (m_fileConfigurations.contains(fileConfig)) - m_fileConfigurations.removeAll(fileConfig); -} - -QString FileType::attributeValue(const QString &attributeName) const -{ - return m_anyAttribute.value(attributeName); -} - -void FileType::setAttribute(const QString &attributeName, const QString &attributeValue) -{ - m_anyAttribute.insert(attributeName, attributeValue); -} - -void FileType::clearAttribute(const QString &attributeName) -{ - // no need to clear the attribute's value if attribute isn't present - if (m_anyAttribute.contains(attributeName)) - m_anyAttribute.insert(attributeName, QString()); -} - -void FileType::removeAttribute(const QString &attributeName) -{ - m_anyAttribute.remove(attributeName); -} - -QString FileType::relativePath() const -{ - return m_relativePath; -} - -void FileType::setRelativePath(const QString &relativePath) -{ - m_relativePath = relativePath; -} - -QString FileType::canonicalPath() const -{ - if (m_parentProjectDoc) { - QFileInfo fileInfo(m_parentProjectDoc->filePath()); - fileInfo = QFileInfo(fileInfo.canonicalPath() + QLatin1Char('/') + m_relativePath); - return fileInfo.canonicalFilePath(); - } - - return QString() + m_relativePath; -} - -FileType::FileType(VcProjectDocument *parentProjectDoc) - : m_parentProjectDoc(parentProjectDoc) -{ -} - -FileType::FileType(const FileType &fileType) -{ - m_parentProjectDoc = fileType.m_parentProjectDoc; - m_relativePath = fileType.m_relativePath; - - foreach (const File::Ptr &file, fileType.m_files) - m_files.append(File::Ptr(new File(*file))); - - foreach (const FileConfiguration::Ptr &fileConfig, m_fileConfigurations) - m_fileConfigurations.append(fileConfig->clone()); -} - -FileType &FileType::operator=(const FileType &fileType) -{ - if (this != &fileType) { - m_parentProjectDoc = fileType.m_parentProjectDoc; - m_relativePath = fileType.m_relativePath; - - m_files.clear(); - m_fileConfigurations.clear(); - - foreach (const File::Ptr &file, fileType.m_files) - m_files.append(File::Ptr(new File(*file))); - - foreach (const FileConfiguration::Ptr &fileConfig, m_fileConfigurations) - m_fileConfigurations.append(fileConfig->clone()); - } - return *this; -} - -void FileType::processNodeAttributes(const QDomElement &element) -{ - QDomNamedNodeMap namedNodeMap = element.attributes(); - - for (int i = 0; i < namedNodeMap.size(); ++i) { - QDomNode domNode = namedNodeMap.item(i); - - if (domNode.nodeType() == QDomNode::AttributeNode) { - QDomAttr domElement = domNode.toAttr(); - - if (domElement.name() == QLatin1String("RelativePath")) - m_relativePath = domElement.value(); - - else - m_anyAttribute.insert(domElement.name(), domElement.value()); - } - } -} - -void FileType::processFileConfiguration(const QDomNode &fileConfigNode) -{ - FileConfiguration::Ptr fileConfig = FileConfigFactory::createFileConfiguration(m_parentProjectDoc->documentVersion()); - fileConfig->processNode(fileConfigNode); - m_fileConfigurations.append(fileConfig); - - // process next sibling - QDomNode nextSibling = fileConfigNode.nextSibling(); - if (!nextSibling.isNull()) { - if (nextSibling.nodeName() == QLatin1String("FileConfiguration")) - processFileConfiguration(nextSibling); - else - processFile(nextSibling); - } -} - -void FileType::processFile(const QDomNode &fileNode) -{ - File::Ptr file(new File(m_parentProjectDoc)); - file->processNode(fileNode); - m_files.append(file); - - // process next sibling - QDomNode nextSibling = fileNode.nextSibling(); - if (!nextSibling.isNull()) { - if (nextSibling.nodeName() == QLatin1String("FileConfiguration")) - processFileConfiguration(nextSibling); - else - processFile(nextSibling); - } -} - -} // namespace Internal -} // namespace VcProjectManager diff --git a/src/plugins/vcprojectmanager/vcprojectmodel/filetype.h b/src/plugins/vcprojectmanager/vcprojectmodel/filetype.h deleted file mode 100644 index 8da6504c96..0000000000 --- a/src/plugins/vcprojectmanager/vcprojectmodel/filetype.h +++ /dev/null @@ -1,93 +0,0 @@ -/************************************************************************** -** -** Copyright (c) 2013 Bojan Petrovic -** Copyright (c) 2013 Radovan Zivkvoic -** Contact: http://www.qt-project.org/legal -** -** This file is part of Qt Creator. -** -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. For licensing terms and -** conditions see http://qt.digia.com/licensing. For further information -** use the contact form at http://qt.digia.com/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -****************************************************************************/ -#ifndef VCPROJECTMANAGER_INTERNAL_FILETYPE_H -#define VCPROJECTMANAGER_INTERNAL_FILETYPE_H - -#include <projectexplorer/projectnodes.h> - -#include "fileconfiguration.h" -#include "vcprojectdocument_constants.h" - -namespace VcProjectManager { -namespace Internal { - -class File; -class VcProjectDocument; - -typedef QSharedPointer<File> Ptr; - -class FileType -{ - friend class File; - -public: - typedef QSharedPointer<FileType> Ptr; - - ~FileType(); - - void processNode(const QDomNode &node); - QDomNode toXMLDomNode(QDomDocument &domXMLDocument) const; - ProjectExplorer::FileType fileType() const; - FileType::Ptr clone() const; - - void addFile(QSharedPointer<File> file); - void removeFile(QSharedPointer<File> file); - void addFileConfiguration(FileConfiguration::Ptr fileConfig); - void removeFileConfiguration(FileConfiguration::Ptr fileConfig); - - QString attributeValue(const QString &attributeName) const; - void setAttribute(const QString &attributeName, const QString &attributeValue); - void clearAttribute(const QString &attributeName); - void removeAttribute(const QString &attributeName); - - QString relativePath() const; - void setRelativePath(const QString &relativePath); - - QString canonicalPath() const; - -private: - FileType(VcProjectDocument *parentProjectDoc); - FileType(const FileType &fileType); - FileType& operator=(const FileType &fileType); - void processNodeAttributes(const QDomElement &element); - void processFileConfiguration(const QDomNode &fileConfigNode); - void processFile(const QDomNode &fileNode); - - QString m_relativePath; // required - QList<QSharedPointer<File> > m_files; - QList<FileConfiguration::Ptr> m_fileConfigurations; - QHash<QString, QString> m_anyAttribute; - VcProjectDocument *m_parentProjectDoc; -}; - -} // namespace Internal -} // namespace VcProjectManager - -#endif // VCPROJECTMANAGER_INTERNAL_FILETYPE_H diff --git a/src/plugins/vcprojectmanager/vcprojectmodel/vcprojectmodel.pri b/src/plugins/vcprojectmanager/vcprojectmodel/vcprojectmodel.pri index afae02535c..aa4fd77149 100644 --- a/src/plugins/vcprojectmanager/vcprojectmodel/vcprojectmodel.pri +++ b/src/plugins/vcprojectmanager/vcprojectmodel/vcprojectmodel.pri @@ -18,7 +18,6 @@ HEADERS += \ vcprojectmodel/folder.h \ vcprojectmodel/filtertype.h \ vcprojectmodel/filter.h \ - vcprojectmodel/filetype.h \ vcprojectmodel/files_private.h \ vcprojectmodel/files.h \ vcprojectmodel/fileconfigurationfactory.h \ @@ -73,7 +72,6 @@ SOURCES += \ vcprojectmodel/folder.cpp \ vcprojectmodel/filtertype.cpp \ vcprojectmodel/filter.cpp \ - vcprojectmodel/filetype.cpp \ vcprojectmodel/files_private.cpp \ vcprojectmodel/files.cpp \ vcprojectmodel/fileconfigurationfactory.cpp \ |