diff options
author | Radovan Zivkovic <pivonroll@gmail.com> | 2013-10-11 10:38:18 +0200 |
---|---|---|
committer | Oswald Buddenhagen <oswald.buddenhagen@digia.com> | 2014-03-11 19:55:00 +0100 |
commit | d6acc9bc57eb9f5b88ca8e4d38c8ee22015b5c15 (patch) | |
tree | 7b8ebeaeabcc46513ae6ca3ef8e1122892c255f6 | |
parent | c8215657519d730909b4ce8f626a1ac39f2d51bd (diff) |
Platforms implements IPlatforms interface.
Change-Id: Ib3dd23bfbf82bf3105316258c2ac676423155645
Reviewed-by: Tobias Hunger <tobias.hunger@digia.com>
9 files changed, 117 insertions, 59 deletions
diff --git a/src/plugins/vcprojectmanager/interfaces/interfaces.pri b/src/plugins/vcprojectmanager/interfaces/interfaces.pri index c7bd816b5e..073bac5c04 100644 --- a/src/plugins/vcprojectmanager/interfaces/interfaces.pri +++ b/src/plugins/vcprojectmanager/interfaces/interfaces.pri @@ -25,4 +25,5 @@ HEADERS += \ interfaces/ireferences.h \ interfaces/itoolfile.h \ interfaces/itoolfiles.h \ - interfaces/iplatform.h + interfaces/iplatform.h \ + interfaces/iplatforms.h diff --git a/src/plugins/vcprojectmanager/interfaces/iplatform.h b/src/plugins/vcprojectmanager/interfaces/iplatform.h index 237b6f158e..623d97ef5a 100644 --- a/src/plugins/vcprojectmanager/interfaces/iplatform.h +++ b/src/plugins/vcprojectmanager/interfaces/iplatform.h @@ -44,6 +44,7 @@ public: virtual QString displayName() const = 0; virtual void setName(const QString &displayName) = 0; + virtual IPlatform* clone() const = 0; }; } // namespace Internal diff --git a/src/plugins/vcprojectmanager/interfaces/iplatforms.h b/src/plugins/vcprojectmanager/interfaces/iplatforms.h new file mode 100644 index 0000000000..31499ab659 --- /dev/null +++ b/src/plugins/vcprojectmanager/interfaces/iplatforms.h @@ -0,0 +1,54 @@ +/************************************************************************** +** +** Copyright (c) 2013 Bojan Petrovic +** Copyright (c) 2013 Radovan Zivkovic +** 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_IPLATFORMHANDLER_H +#define VCPROJECTMANAGER_INTERNAL_IPLATFORMHANDLER_H + +#include "../vcprojectmodel/ivcprojectnodemodel.h" + +namespace VcProjectManager { +namespace Internal { + +class IPlatform; + +class IPlatforms : public IVcProjectXMLNode +{ +public: + virtual ~IPlatforms() {} + + virtual void addPlatform(IPlatform *platform) = 0; + virtual int platformCount() const = 0; + virtual IPlatform* platform(int index) const = 0; + virtual void removePlatform(IPlatform *platform) = 0; +}; + +} // namespace Internal +} // namespace VcProjectManager + +#endif // VCPROJECTMANAGER_INTERNAL_IPLATFORMHANDLER_H diff --git a/src/plugins/vcprojectmanager/vcprojectmodel/platform.cpp b/src/plugins/vcprojectmanager/vcprojectmodel/platform.cpp index bb69a761e3..d5120f475a 100644 --- a/src/plugins/vcprojectmanager/vcprojectmodel/platform.cpp +++ b/src/plugins/vcprojectmanager/vcprojectmodel/platform.cpp @@ -83,6 +83,11 @@ void Platform::setName(const QString &name) m_name = name; } +IPlatform *Platform::clone() const +{ + return new Platform(*this); +} + void Platform::processNodeAttributes(const QDomElement &element) { QDomNamedNodeMap namedNodeMap = element.attributes(); diff --git a/src/plugins/vcprojectmanager/vcprojectmodel/platform.h b/src/plugins/vcprojectmanager/vcprojectmodel/platform.h index cf6a610285..ea2de38125 100644 --- a/src/plugins/vcprojectmanager/vcprojectmodel/platform.h +++ b/src/plugins/vcprojectmanager/vcprojectmodel/platform.h @@ -40,8 +40,6 @@ namespace Internal { class Platform : public IPlatform { public: - typedef QSharedPointer<Platform> Ptr; - Platform(); Platform(const Platform &platform); Platform& operator=(const Platform &platform); @@ -53,6 +51,7 @@ public: QString displayName() const; void setName(const QString &displayName); + IPlatform *clone() const; private: void processNodeAttributes(const QDomElement &element); diff --git a/src/plugins/vcprojectmanager/vcprojectmodel/platforms.cpp b/src/plugins/vcprojectmanager/vcprojectmodel/platforms.cpp index 88b8c05e41..ea83105c69 100644 --- a/src/plugins/vcprojectmanager/vcprojectmodel/platforms.cpp +++ b/src/plugins/vcprojectmanager/vcprojectmodel/platforms.cpp @@ -29,6 +29,8 @@ ****************************************************************************/ #include "platforms.h" +#include <utils/qtcassert.h> + namespace VcProjectManager { namespace Internal { @@ -38,24 +40,25 @@ Platforms::Platforms() Platforms::Platforms(const Platforms &platforms) { - foreach (const Platform::Ptr &platform, platforms.m_platforms) - m_platforms.append(Platform::Ptr(new Platform(*platform))); + foreach (const IPlatform *platform, platforms.m_platforms) + m_platforms.append(platform->clone()); } Platforms &Platforms::operator =(const Platforms &platforms) { if (this != &platforms) { + qDeleteAll(m_platforms); m_platforms.clear(); - foreach (const Platform::Ptr &platform, platforms.m_platforms) - m_platforms.append(Platform::Ptr(new Platform(*platform))); + foreach (const IPlatform *platform, platforms.m_platforms) + m_platforms.append(platform->clone()); } return *this; } Platforms::~Platforms() { - m_platforms.clear(); + qDeleteAll(m_platforms); } void Platforms::processNode(const QDomNode &node) @@ -79,59 +82,57 @@ QDomNode Platforms::toXMLDomNode(QDomDocument &domXMLDocument) const { QDomElement platformsNode = domXMLDocument.createElement(QLatin1String("Platforms")); - foreach (const Platform::Ptr &platform, m_platforms) + foreach (const IPlatform *platform, m_platforms) platformsNode.appendChild(platform->toXMLDomNode(domXMLDocument)); return platformsNode; } -bool Platforms::isEmpty() const +void Platforms::addPlatform(IPlatform *platform) { - return m_platforms.isEmpty(); -} + if (!platform || m_platforms.contains(platform)) + return; + foreach (const IPlatform *plat, m_platforms) { + if (plat && platform && plat->displayName() == platform->displayName()) + return; + } -void Platforms::processPlatform(const QDomNode &node) -{ - Platform::Ptr platform(new Platform); - platform->processNode(node); m_platforms.append(platform); - - // process next sibling - QDomNode nextSibling = node.nextSibling(); - if (!nextSibling.isNull()) - processPlatform(nextSibling); } -void Platforms::addPlatform(Platform::Ptr platform) +int Platforms::platformCount() const { - if (m_platforms.contains(platform)) - return; - - foreach (const Platform::Ptr &platf, m_platforms) { - if (platf->displayName() == platform->displayName()) - return; - } - m_platforms.append(platform); + return m_platforms.size(); } -void Platforms::removePlatform(Platform::Ptr platform) +IPlatform *Platforms::platform(int index) const { - m_platforms.removeAll(platform); + QTC_ASSERT(0 <= index && index < m_platforms.size(), return 0); + return m_platforms[index]; } -void Platforms::removePlatform(const QString &platformName) +void Platforms::removePlatform(IPlatform *platform) { - foreach (const Platform::Ptr &platform, m_platforms) { - if (platform->displayName() == platformName) { - removePlatform(platform); - return; + if (!platform || !m_platforms.contains(platform)) + return; + foreach (const IPlatform *plat, m_platforms) { + if (plat && platform && plat->displayName() == platform->displayName()) { + m_platforms.removeOne(platform); + delete platform; } } } -QList<Platform::Ptr> Platforms::platforms() const +void Platforms::processPlatform(const QDomNode &node) { - return m_platforms; + IPlatform *platform = new Platform; + platform->processNode(node); + m_platforms.append(platform); + + // process next sibling + QDomNode nextSibling = node.nextSibling(); + if (!nextSibling.isNull()) + processPlatform(nextSibling); } } // namespace Internal diff --git a/src/plugins/vcprojectmanager/vcprojectmodel/platforms.h b/src/plugins/vcprojectmanager/vcprojectmodel/platforms.h index c34a84486b..578b90266c 100644 --- a/src/plugins/vcprojectmanager/vcprojectmodel/platforms.h +++ b/src/plugins/vcprojectmanager/vcprojectmodel/platforms.h @@ -30,7 +30,7 @@ #ifndef VCPROJECTMANAGER_INTERNAL_PLATFORMS_H #define VCPROJECTMANAGER_INTERNAL_PLATFORMS_H -#include "ivcprojectnodemodel.h" +#include "../interfaces/iplatforms.h" #include <QList> @@ -41,7 +41,7 @@ namespace Internal { class Platform; -class Platforms : public IVcProjectXMLNode +class Platforms : public IPlatforms { public: typedef QSharedPointer<Platforms> Ptr; @@ -55,17 +55,15 @@ public: VcNodeWidget* createSettingsWidget(); QDomNode toXMLDomNode(QDomDocument &domXMLDocument) const; - bool isEmpty() const; + void addPlatform(IPlatform *platform); + int platformCount() const; + IPlatform *platform(int index) const; + void removePlatform(IPlatform *platform); +private: void processPlatform(const QDomNode &node); + QList<IPlatform *> m_platforms; - void addPlatform(Platform::Ptr platform); - void removePlatform(Platform::Ptr platform); - void removePlatform(const QString &platformName); - QList<Platform::Ptr> platforms() const; - -private: - QList<Platform::Ptr> m_platforms; }; } // namespace Internal diff --git a/src/plugins/vcprojectmanager/vcprojectmodel/vcprojectdocument.cpp b/src/plugins/vcprojectmanager/vcprojectmodel/vcprojectdocument.cpp index 1fddc81023..aeb512199d 100644 --- a/src/plugins/vcprojectmanager/vcprojectmodel/vcprojectdocument.cpp +++ b/src/plugins/vcprojectmanager/vcprojectmodel/vcprojectdocument.cpp @@ -322,7 +322,7 @@ QDomElement VcProjectDocument::toVcDocumentElement(QDomDocument &domXMLDocument) vcDocNode.setAttribute(itAttr.key(), itAttr.value()); } - if (!m_platforms->isEmpty()) + if (m_platforms->platformCount()) vcDocNode.appendChild(m_platforms->toXMLDomNode(domXMLDocument)); if (m_configurations->configurationContainer()->configurationCount()) diff --git a/src/plugins/vcprojectmanager/widgets/configurationswidgets.cpp b/src/plugins/vcprojectmanager/widgets/configurationswidgets.cpp index eec920f66b..3bc0b65dd8 100644 --- a/src/plugins/vcprojectmanager/widgets/configurationswidgets.cpp +++ b/src/plugins/vcprojectmanager/widgets/configurationswidgets.cpp @@ -122,8 +122,8 @@ void ConfigurationsBaseWidget::onAddNewConfig(QString newConfigName, QString cop if (platforms && !newConfigName.isEmpty()) { if (copyFrom.isEmpty()) { - QList<Platform::Ptr> platformList = platforms->platforms(); - foreach (const Platform::Ptr &platform, platformList) { + for (int i = 0; i < platforms->platformCount(); ++i) { + IPlatform *platform = platforms->platform(i); IConfiguration *newConfig = createConfiguration(newConfigName + QLatin1Char('|') + platform->displayName()); if (newConfig) { @@ -138,9 +138,8 @@ void ConfigurationsBaseWidget::onAddNewConfig(QString newConfigName, QString cop IConfiguration *config = m_configs->configurationContainer()->configuration(copyFrom); if (config) { - QList<Platform::Ptr> platformList = platforms->platforms(); - - foreach (const Platform::Ptr &platform, platformList) { + for (int i = 0; i < platforms->platformCount(); ++i) { + IPlatform *platform = platforms->platform(i); IConfiguration* newConfig = config->clone(); if (newConfig) { @@ -168,8 +167,8 @@ void ConfigurationsBaseWidget::onRenameConfig(QString newConfigName, QString old if (splits.isEmpty()) return; - QList<Platform::Ptr> platformList = platforms->platforms(); - foreach (const Platform::Ptr &platform, platformList) { + for (int i = 0; i < platforms->platformCount(); ++i) { + IPlatform *platform = platforms->platform(i); QString targetConfigName = splits[0] + QLatin1Char('|') + platform->displayName(); QString newName = newConfigName + QLatin1Char('|') + platform->displayName(); IConfiguration *configInNew = configInNewConfigurations(targetConfigName); @@ -219,8 +218,8 @@ void ConfigurationsBaseWidget::onRemoveConfig(QString configNameWithPlatform) if (splits.isEmpty()) return; - QList<Platform::Ptr> platformList = platforms->platforms(); - foreach (const Platform::Ptr &platform, platformList) { + for (int i = 0; i < platforms->platformCount(); ++i) { + IPlatform *platform = platforms->platform(i); QString targetConfigName = splits[0] + QLatin1Char('|') + platform->displayName(); IConfiguration *config = m_configs->configurationContainer()->configuration(targetConfigName); |