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 **************************************************************************/
34 #include "moduleshandler.h"
36 #include <utils/qtcassert.h>
38 #include <QtCore/QDebug>
39 #include <QtGui/QSortFilterProxyModel>
42 //////////////////////////////////////////////////////////////////
46 //////////////////////////////////////////////////////////////////
51 ModulesModel::ModulesModel(ModulesHandler *parent)
52 : QAbstractItemModel(parent)
55 QVariant ModulesModel::headerData(int section,
56 Qt::Orientation orientation, int role) const
58 if (orientation == Qt::Horizontal && role == Qt::DisplayRole) {
59 static QString headers[] = {
60 tr("Module name") + " ",
61 tr("Module path") + " ",
62 tr("Symbols read") + " ",
63 tr("Symbols type") + " ",
64 tr("Start address") + " ",
65 tr("End address") + " "
67 return headers[section];
72 QVariant ModulesModel::data(const QModelIndex &index, int role) const
74 int row = index.row();
75 if (row < 0 || row >= m_modules.size())
78 const Module &module = m_modules.at(row);
80 switch (index.column()) {
82 if (role == Qt::DisplayRole)
83 return module.moduleName;
85 //if (role == Qt::DecorationRole)
86 // return module.symbolsRead ? icon2 : icon;
89 if (role == Qt::DisplayRole)
90 return module.modulePath;
93 if (role == Qt::DisplayRole)
94 switch (module.symbolsRead) {
95 case Module::UnknownReadState: return tr("unknown");
96 case Module::ReadFailed: return tr("no");
97 case Module::ReadOk: return tr("yes");
101 if (role == Qt::DisplayRole)
102 switch (module.symbolsType) {
103 case Module::UnknownType: return tr("unknown");
104 case Module::PlainSymbols: return tr("plain");
105 case Module::FastSymbols: return tr("fast");
109 if (role == Qt::DisplayRole)
110 return QString(QLatin1String("0x")
111 + QString::number(module.startAddress, 16));
114 if (role == Qt::DisplayRole) {
115 if (module.endAddress)
116 return QString(QLatin1String("0x")
117 + QString::number(module.endAddress, 16));
118 //: End address of loaded module
119 return tr("<unknown>", "address");
126 void ModulesModel::addModule(const Module &m)
128 beginInsertRows(QModelIndex(), m_modules.size(), m_modules.size());
129 m_modules.push_back(m);
133 void ModulesModel::setModules(const Modules &m)
139 void ModulesModel::clearModel()
141 if (!m_modules.isEmpty()) {
147 int ModulesModel::indexOfModule(const QString &name) const
149 // Recent modules are more likely to be unloaded first.
150 for (int i = m_modules.size() - 1; i >= 0; i--)
151 if (m_modules.at(i).moduleName == name)
156 void ModulesModel::removeModule(const QString &moduleName)
158 const int index = indexOfModule(moduleName);
159 QTC_ASSERT(index != -1, return);
160 beginRemoveRows(QModelIndex(), index, index);
161 m_modules.remove(index);
165 void ModulesModel::updateModule(const QString &moduleName, const Module &module)
167 const int index = indexOfModule(moduleName);
168 QTC_ASSERT(index != -1, return);
169 m_modules[index] = module;
173 //////////////////////////////////////////////////////////////////
177 //////////////////////////////////////////////////////////////////
179 ModulesHandler::ModulesHandler()
181 m_model = new ModulesModel(this);
182 m_proxyModel = new QSortFilterProxyModel(this);
183 m_proxyModel->setSourceModel(m_model);
186 QAbstractItemModel *ModulesHandler::model() const
191 void ModulesHandler::removeAll()
193 m_model->clearModel();
196 void ModulesHandler::addModule(const Module &module)
198 m_model->addModule(module);
201 void ModulesHandler::removeModule(const QString &moduleName)
203 m_model->removeModule(moduleName);
206 void ModulesHandler::updateModule(const QString &moduleName, const Module &module)
208 m_model->updateModule(moduleName, module);
211 void ModulesHandler::setModules(const Modules &modules)
213 m_model->setModules(modules);
216 Modules ModulesHandler::modules() const
218 return m_model->modules();
221 } // namespace Internal
222 } // namespace Debugger