1 /**************************************************************************
3 ** This file is part of Qt Creator
5 ** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
7 ** Contact: Nokia Corporation (qt-info@nokia.com)
11 ** This file contains pre-release code and may not be distributed.
12 ** You may use this file in accordance with the terms and conditions
13 ** contained in the Technology Preview License Agreement accompanying
16 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
25 ** In addition, as a special exception, Nokia gives you certain additional
26 ** rights. These rights are described in the Nokia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
29 ** If you have questions regarding the use of this file, please contact
30 ** Nokia at qt-info@nokia.com.
32 **************************************************************************/
33 #include "maemopertargetdeviceconfigurationlistmodel.h"
35 #include "qt4maemotarget.h"
37 using namespace ProjectExplorer;
39 namespace Qt4ProjectManager {
42 MaemoPerTargetDeviceConfigurationListModel::MaemoPerTargetDeviceConfigurationListModel(Target *target)
43 : QAbstractListModel(target)
45 if (qobject_cast<Qt4Maemo5Target *>(target))
46 m_targetOsVersion = MaemoGlobal::Maemo5;
47 else if (qobject_cast<Qt4HarmattanTarget *>(target))
48 m_targetOsVersion = MaemoGlobal::Maemo6;
49 else if (qobject_cast<Qt4MeegoTarget *>(target))
50 m_targetOsVersion = MaemoGlobal::Meego;
53 const MaemoDeviceConfigurations * const devConfs
54 = MaemoDeviceConfigurations::instance();
55 connect(devConfs, SIGNAL(modelReset()), this, SIGNAL(modelReset()));
56 connect(devConfs, SIGNAL(updated()), this, SIGNAL(updated()));
59 int MaemoPerTargetDeviceConfigurationListModel::rowCount(const QModelIndex &parent) const
64 const MaemoDeviceConfigurations * const devConfs
65 = MaemoDeviceConfigurations::instance();
66 const int devConfsCount = devConfs->rowCount();
67 for (int i = 0; i < devConfsCount; ++i) {
68 if (devConfs->deviceAt(i)->osVersion() == m_targetOsVersion)
74 QVariant MaemoPerTargetDeviceConfigurationListModel::data(const QModelIndex &index,
77 if (!index.isValid() || index.row() >= rowCount() || role != Qt::DisplayRole)
79 const MaemoDeviceConfig::ConstPtr &devConf = deviceAt(index.row());
81 QString displayedName = devConf->name();
82 if (devConf->isDefault())
83 displayedName += QLatin1Char(' ') + tr("(default)");
87 MaemoDeviceConfig::ConstPtr MaemoPerTargetDeviceConfigurationListModel::deviceAt(int idx) const
90 const MaemoDeviceConfigurations * const devConfs
91 = MaemoDeviceConfigurations::instance();
92 const int devConfsCount = devConfs->rowCount();
93 for (int i = 0; i < devConfsCount; ++i) {
94 if (devConfs->deviceAt(i)->osVersion() == m_targetOsVersion) {
95 if (++currentRow == idx)
96 return devConfs->deviceAt(i);
100 return MaemoDeviceConfig::ConstPtr();
103 MaemoDeviceConfig::ConstPtr MaemoPerTargetDeviceConfigurationListModel::defaultDeviceConfig() const
105 return MaemoDeviceConfigurations::instance()->defaultDeviceConfig(m_targetOsVersion);
108 MaemoDeviceConfig::ConstPtr MaemoPerTargetDeviceConfigurationListModel::find(MaemoDeviceConfig::Id id) const
110 const MaemoDeviceConfig::ConstPtr &devConf
111 = MaemoDeviceConfigurations::instance()->find(id);
112 return devConf && devConf->osVersion() == m_targetOsVersion
113 ? devConf : defaultDeviceConfig();
116 int MaemoPerTargetDeviceConfigurationListModel::indexForInternalId(MaemoDeviceConfig::Id id) const
118 const int count = rowCount();
119 for (int i = 0; i < count; ++i) {
120 if (deviceAt(i)->internalId() == id)
126 } // namespace Internal
127 } // namespace Qt4ProjectManager