OSDN Git Service

3a7451ed9360302e598c49687870e43c93785ea9
[qt-creator-jp/qt-creator-jp.git] / src / plugins / qt4projectmanager / qt-maemo / maemopertargetdeviceconfigurationlistmodel.cpp
1 /**************************************************************************
2 **
3 ** This file is part of Qt Creator
4 **
5 ** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
6 **
7 ** Contact: Nokia Corporation (qt-info@nokia.com)
8 **
9 ** No Commercial Usage
10 **
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
14 ** this package.
15 **
16 ** GNU Lesser General Public License Usage
17 **
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.
24 **
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.
28 **
29 ** If you have questions regarding the use of this file, please contact
30 ** Nokia at qt-info@nokia.com.
31 **
32 **************************************************************************/
33 #include "maemopertargetdeviceconfigurationlistmodel.h"
34
35 #include "qt4maemotarget.h"
36
37 using namespace ProjectExplorer;
38
39 namespace Qt4ProjectManager {
40 namespace Internal {
41
42 MaemoPerTargetDeviceConfigurationListModel::MaemoPerTargetDeviceConfigurationListModel(Target *target)
43     : QAbstractListModel(target)
44 {
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;
51     else
52         Q_ASSERT(false);
53     const MaemoDeviceConfigurations * const devConfs
54         = MaemoDeviceConfigurations::instance();
55     connect(devConfs, SIGNAL(modelReset()), this, SIGNAL(modelReset()));
56     connect(devConfs, SIGNAL(updated()), this, SIGNAL(updated()));
57 }
58
59 int MaemoPerTargetDeviceConfigurationListModel::rowCount(const QModelIndex &parent) const
60 {
61     if (parent.isValid())
62         return 0;
63     int count = 0;
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)
69             ++count;
70     }
71     return count;
72 }
73
74 QVariant MaemoPerTargetDeviceConfigurationListModel::data(const QModelIndex &index,
75     int role) const
76 {
77     if (!index.isValid() || index.row() >= rowCount() || role != Qt::DisplayRole)
78         return QVariant();
79     const MaemoDeviceConfig::ConstPtr &devConf = deviceAt(index.row());
80     Q_ASSERT(devConf);
81     QString displayedName = devConf->name();
82     if (devConf->isDefault())
83         displayedName += QLatin1Char(' ') + tr("(default)");
84     return displayedName;
85 }
86
87 MaemoDeviceConfig::ConstPtr MaemoPerTargetDeviceConfigurationListModel::deviceAt(int idx) const
88 {
89     int currentRow = -1;
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);
97         }
98     }
99     Q_ASSERT(false);
100     return MaemoDeviceConfig::ConstPtr();
101 }
102
103 MaemoDeviceConfig::ConstPtr MaemoPerTargetDeviceConfigurationListModel::defaultDeviceConfig() const
104 {
105     return MaemoDeviceConfigurations::instance()->defaultDeviceConfig(m_targetOsVersion);
106 }
107
108 MaemoDeviceConfig::ConstPtr MaemoPerTargetDeviceConfigurationListModel::find(MaemoDeviceConfig::Id id) const
109 {
110     const MaemoDeviceConfig::ConstPtr &devConf
111         = MaemoDeviceConfigurations::instance()->find(id);
112     return devConf && devConf->osVersion() == m_targetOsVersion
113         ? devConf : defaultDeviceConfig();
114 }
115
116 int MaemoPerTargetDeviceConfigurationListModel::indexForInternalId(MaemoDeviceConfig::Id id) const
117 {
118     const int count = rowCount();
119     for (int i = 0; i < count; ++i) {
120         if (deviceAt(i)->internalId() == id)
121             return i;
122     }
123     return -1;
124 }
125
126 } // namespace Internal
127 } // namespace Qt4ProjectManager