1 /**************************************************************************
3 ** This file is part of Qt Creator
5 ** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
7 ** Contact: Nokia Corporation (info@qt.nokia.com)
10 ** GNU Lesser General Public License Usage
12 ** This file may be used under the terms of the GNU Lesser General Public
13 ** License version 2.1 as published by the Free Software Foundation and
14 ** appearing in the file LICENSE.LGPL included in the packaging of this file.
15 ** Please review the following information to ensure the GNU Lesser General
16 ** Public License version 2.1 requirements will be met:
17 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
19 ** In addition, as a special exception, Nokia gives you certain additional
20 ** rights. These rights are described in the Nokia Qt LGPL Exception
21 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
25 ** Alternatively, this file may be used in accordance with the terms and
26 ** conditions contained in a signed written agreement between you and Nokia.
28 ** If you have questions regarding the use of this file, please contact
29 ** Nokia at qt-info@nokia.com.
31 **************************************************************************/
33 #include "moduleshandler.h"
35 #include <utils/qtcassert.h>
37 #include <QtCore/QDebug>
38 #include <QtGui/QSortFilterProxyModel>
41 //////////////////////////////////////////////////////////////////
45 //////////////////////////////////////////////////////////////////
50 ModulesModel::ModulesModel(ModulesHandler *parent)
51 : QAbstractItemModel(parent)
54 QVariant ModulesModel::headerData(int section,
55 Qt::Orientation orientation, int role) const
57 if (orientation == Qt::Horizontal && role == Qt::DisplayRole) {
58 static QString headers[] = {
59 tr("Module name") + " ",
60 tr("Module path") + " ",
61 tr("Symbols read") + " ",
62 tr("Symbols type") + " ",
63 tr("Start address") + " ",
64 tr("End address") + " "
66 return headers[section];
71 QVariant ModulesModel::data(const QModelIndex &index, int role) const
73 int row = index.row();
74 if (row < 0 || row >= m_modules.size())
77 const Module &module = m_modules.at(row);
79 switch (index.column()) {
81 if (role == Qt::DisplayRole)
82 return module.moduleName;
84 //if (role == Qt::DecorationRole)
85 // return module.symbolsRead ? icon2 : icon;
88 if (role == Qt::DisplayRole)
89 return module.modulePath;
92 if (role == Qt::DisplayRole)
93 switch (module.symbolsRead) {
94 case Module::UnknownReadState: return tr("unknown");
95 case Module::ReadFailed: return tr("no");
96 case Module::ReadOk: return tr("yes");
100 if (role == Qt::DisplayRole)
101 switch (module.symbolsType) {
102 case Module::UnknownType: return tr("unknown");
103 case Module::PlainSymbols: return tr("plain");
104 case Module::FastSymbols: return tr("fast");
108 if (role == Qt::DisplayRole)
109 return QString(QLatin1String("0x")
110 + QString::number(module.startAddress, 16));
113 if (role == Qt::DisplayRole) {
114 if (module.endAddress)
115 return QString(QLatin1String("0x")
116 + QString::number(module.endAddress, 16));
117 //: End address of loaded module
118 return tr("<unknown>", "address");
125 void ModulesModel::addModule(const Module &m)
127 beginInsertRows(QModelIndex(), m_modules.size(), m_modules.size());
128 m_modules.push_back(m);
132 void ModulesModel::setModules(const Modules &m)
138 void ModulesModel::clearModel()
140 if (!m_modules.isEmpty()) {
146 int ModulesModel::indexOfModule(const QString &name) const
148 // Recent modules are more likely to be unloaded first.
149 for (int i = m_modules.size() - 1; i >= 0; i--)
150 if (m_modules.at(i).moduleName == name)
155 void ModulesModel::removeModule(const QString &moduleName)
157 const int index = indexOfModule(moduleName);
158 QTC_ASSERT(index != -1, return);
159 beginRemoveRows(QModelIndex(), index, index);
160 m_modules.remove(index);
164 void ModulesModel::updateModule(const QString &moduleName, const Module &module)
166 const int index = indexOfModule(moduleName);
167 QTC_ASSERT(index != -1, return);
168 m_modules[index] = module;
172 //////////////////////////////////////////////////////////////////
176 //////////////////////////////////////////////////////////////////
178 ModulesHandler::ModulesHandler()
180 m_model = new ModulesModel(this);
181 m_proxyModel = new QSortFilterProxyModel(this);
182 m_proxyModel->setSourceModel(m_model);
185 QAbstractItemModel *ModulesHandler::model() const
190 void ModulesHandler::removeAll()
192 m_model->clearModel();
195 void ModulesHandler::addModule(const Module &module)
197 m_model->addModule(module);
200 void ModulesHandler::removeModule(const QString &moduleName)
202 m_model->removeModule(moduleName);
205 void ModulesHandler::updateModule(const QString &moduleName, const Module &module)
207 m_model->updateModule(moduleName, module);
210 void ModulesHandler::setModules(const Modules &modules)
212 m_model->setModules(modules);
215 Modules ModulesHandler::modules() const
217 return m_model->modules();
220 } // namespace Internal
221 } // namespace Debugger