2009-02-25 09:15:00 +01:00
|
|
|
/**************************************************************************
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
|
|
|
|
** This file is part of Qt Creator
|
|
|
|
|
**
|
2010-03-05 11:25:49 +01:00
|
|
|
** Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
2009-06-17 00:01:27 +10:00
|
|
|
** Contact: Nokia Corporation (qt-info@nokia.com)
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
2009-02-25 09:15:00 +01:00
|
|
|
** Commercial Usage
|
2008-12-02 14:17:16 +01:00
|
|
|
**
|
2009-02-25 09:15:00 +01:00
|
|
|
** Licensees holding valid Qt Commercial licenses may use this file in
|
|
|
|
|
** accordance with the Qt Commercial License Agreement provided with the
|
|
|
|
|
** Software or, alternatively, in accordance with the terms contained in
|
|
|
|
|
** a written agreement between you and Nokia.
|
2008-12-02 14:17:16 +01:00
|
|
|
**
|
2009-02-25 09:15:00 +01:00
|
|
|
** GNU Lesser General Public License Usage
|
2008-12-02 14:17:16 +01:00
|
|
|
**
|
2009-02-25 09:15:00 +01:00
|
|
|
** 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.
|
2008-12-02 14:17:16 +01:00
|
|
|
**
|
2009-02-25 09:15:00 +01:00
|
|
|
** If you are unsure which license is appropriate for your use, please
|
2009-08-14 09:30:56 +02:00
|
|
|
** contact the sales department at http://qt.nokia.com/contact.
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
2009-02-25 09:15:00 +01:00
|
|
|
**************************************************************************/
|
2008-12-02 15:08:31 +01:00
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
#include "moduleshandler.h"
|
|
|
|
|
|
2009-02-17 11:16:23 +01:00
|
|
|
#include <utils/qtcassert.h>
|
2008-12-02 12:01:29 +01:00
|
|
|
|
|
|
|
|
#include <QtCore/QDebug>
|
|
|
|
|
#include <QtCore/QDir>
|
|
|
|
|
#include <QtCore/QList>
|
|
|
|
|
#include <QtCore/QTextStream>
|
|
|
|
|
|
|
|
|
|
#include <QtGui/QAction>
|
|
|
|
|
#include <QtGui/QMainWindow>
|
|
|
|
|
#include <QtGui/QStandardItemModel>
|
|
|
|
|
#include <QtGui/QSortFilterProxyModel>
|
|
|
|
|
|
|
|
|
|
using namespace Debugger;
|
|
|
|
|
using namespace Debugger::Internal;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////
|
|
|
|
|
//
|
|
|
|
|
// ModulesModel
|
|
|
|
|
//
|
|
|
|
|
//////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
|
class Debugger::Internal::ModulesModel : public QAbstractItemModel
|
|
|
|
|
{
|
2009-04-16 19:42:58 +02:00
|
|
|
Q_OBJECT
|
|
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
public:
|
2010-05-19 15:14:15 +02:00
|
|
|
explicit ModulesModel(ModulesHandler *parent);
|
2008-12-02 12:01:29 +01:00
|
|
|
|
|
|
|
|
// QAbstractItemModel
|
|
|
|
|
int columnCount(const QModelIndex &parent) const
|
2010-05-03 19:12:52 +02:00
|
|
|
{ return parent.isValid() ? 0 : 5; }
|
2008-12-02 12:01:29 +01:00
|
|
|
int rowCount(const QModelIndex &parent) const
|
|
|
|
|
{ return parent.isValid() ? 0 : m_modules.size(); }
|
|
|
|
|
QModelIndex parent(const QModelIndex &) const { return QModelIndex(); }
|
|
|
|
|
QModelIndex index(int row, int column, const QModelIndex &) const
|
|
|
|
|
{ return createIndex(row, column); }
|
|
|
|
|
QVariant headerData(int section, Qt::Orientation orientation, int role) const;
|
|
|
|
|
QVariant data(const QModelIndex &index, int role) const;
|
|
|
|
|
bool setData(const QModelIndex &index, const QVariant &value, int role);
|
|
|
|
|
|
2010-05-19 15:14:15 +02:00
|
|
|
void clearModel();
|
|
|
|
|
void addModule(const Module &m);
|
|
|
|
|
void removeModule(const QString &moduleName);
|
|
|
|
|
void setModules(const QList<Module> &m);
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2010-05-19 15:14:15 +02:00
|
|
|
const QList<Module> &modules() const { return m_modules; }
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
int indexOfModule(const QString &name) const;
|
|
|
|
|
|
|
|
|
|
const QVariant m_yes;
|
|
|
|
|
const QVariant m_no;
|
2008-12-02 12:01:29 +01:00
|
|
|
QList<Module> m_modules;
|
|
|
|
|
};
|
|
|
|
|
|
2010-05-19 15:14:15 +02:00
|
|
|
ModulesModel::ModulesModel(ModulesHandler *parent) :
|
|
|
|
|
QAbstractItemModel(parent),
|
|
|
|
|
m_yes(tr("yes")), m_no(tr("no"))
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
QVariant ModulesModel::headerData(int section,
|
|
|
|
|
Qt::Orientation orientation, int role) const
|
|
|
|
|
{
|
|
|
|
|
if (orientation == Qt::Horizontal && role == Qt::DisplayRole) {
|
|
|
|
|
static QString headers[] = {
|
2010-01-29 21:33:57 +01:00
|
|
|
tr("Module name") + " ",
|
2010-05-03 19:12:52 +02:00
|
|
|
tr("Module path") + " ",
|
2008-12-02 12:01:29 +01:00
|
|
|
tr("Symbols read") + " ",
|
|
|
|
|
tr("Start address") + " ",
|
2009-05-07 15:34:52 +02:00
|
|
|
tr("End address") + " "
|
2008-12-02 12:01:29 +01:00
|
|
|
};
|
|
|
|
|
return headers[section];
|
|
|
|
|
}
|
|
|
|
|
return QVariant();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QVariant ModulesModel::data(const QModelIndex &index, int role) const
|
|
|
|
|
{
|
|
|
|
|
int row = index.row();
|
|
|
|
|
if (row < 0 || row >= m_modules.size())
|
|
|
|
|
return QVariant();
|
|
|
|
|
|
|
|
|
|
const Module &module = m_modules.at(row);
|
|
|
|
|
|
|
|
|
|
switch (index.column()) {
|
|
|
|
|
case 0:
|
|
|
|
|
if (role == Qt::DisplayRole)
|
|
|
|
|
return module.moduleName;
|
|
|
|
|
// FIXME: add icons
|
|
|
|
|
//if (role == Qt::DecorationRole)
|
|
|
|
|
// return module.symbolsRead ? icon2 : icon;
|
|
|
|
|
break;
|
|
|
|
|
case 1:
|
|
|
|
|
if (role == Qt::DisplayRole)
|
2010-05-03 19:12:52 +02:00
|
|
|
return module.modulePath;
|
2008-12-02 12:01:29 +01:00
|
|
|
break;
|
|
|
|
|
case 2:
|
|
|
|
|
if (role == Qt::DisplayRole)
|
2010-05-19 15:14:15 +02:00
|
|
|
return module.symbolsRead ? m_yes : m_no;
|
2008-12-02 12:01:29 +01:00
|
|
|
break;
|
|
|
|
|
case 3:
|
2010-05-03 19:12:52 +02:00
|
|
|
if (role == Qt::DisplayRole)
|
|
|
|
|
return module.startAddress;
|
|
|
|
|
break;
|
|
|
|
|
case 4:
|
2008-12-02 12:01:29 +01:00
|
|
|
if (role == Qt::DisplayRole)
|
|
|
|
|
return module.endAddress;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
return QVariant();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool ModulesModel::setData(const QModelIndex &index, const QVariant &value, int role)
|
|
|
|
|
{
|
|
|
|
|
return QAbstractItemModel::setData(index, value, role);
|
|
|
|
|
}
|
|
|
|
|
|
2010-05-19 15:14:15 +02:00
|
|
|
void ModulesModel::addModule(const Module &m)
|
|
|
|
|
{
|
|
|
|
|
beginInsertRows(QModelIndex(), m_modules.size(), m_modules.size());
|
|
|
|
|
m_modules.push_back(m);
|
|
|
|
|
endInsertRows();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ModulesModel::setModules(const QList<Module> &m)
|
|
|
|
|
{
|
|
|
|
|
m_modules = m;
|
|
|
|
|
reset();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ModulesModel::clearModel()
|
|
|
|
|
{
|
|
|
|
|
if (!m_modules.isEmpty()) {
|
|
|
|
|
m_modules.clear();
|
|
|
|
|
reset();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int ModulesModel::indexOfModule(const QString &name) const
|
|
|
|
|
{
|
|
|
|
|
// Recent modules are more likely to be unloaded first.
|
|
|
|
|
for (int i = m_modules.size() - 1; i >= 0; i--)
|
|
|
|
|
if (m_modules.at(i).moduleName == name)
|
|
|
|
|
return i;
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ModulesModel::removeModule(const QString &moduleName)
|
|
|
|
|
{
|
|
|
|
|
const int index = indexOfModule(moduleName);
|
|
|
|
|
QTC_ASSERT(index != -1, return);
|
|
|
|
|
|
|
|
|
|
beginRemoveRows(QModelIndex(), index, index);
|
|
|
|
|
m_modules.removeAt(index);
|
|
|
|
|
endRemoveRows();
|
|
|
|
|
}
|
2008-12-02 12:01:29 +01:00
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////
|
|
|
|
|
//
|
|
|
|
|
// ModulesHandler
|
|
|
|
|
//
|
|
|
|
|
//////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
|
ModulesHandler::ModulesHandler()
|
|
|
|
|
{
|
|
|
|
|
m_model = new ModulesModel(this);
|
|
|
|
|
m_proxyModel = new QSortFilterProxyModel(this);
|
|
|
|
|
m_proxyModel->setSourceModel(m_model);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QAbstractItemModel *ModulesHandler::model() const
|
|
|
|
|
{
|
|
|
|
|
return m_proxyModel;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ModulesHandler::removeAll()
|
|
|
|
|
{
|
|
|
|
|
m_model->clearModel();
|
|
|
|
|
}
|
|
|
|
|
|
2010-05-19 15:14:15 +02:00
|
|
|
void ModulesHandler::addModule(const Module &module)
|
|
|
|
|
{
|
|
|
|
|
m_model->addModule(module);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ModulesHandler::removeModule(const QString &moduleName)
|
|
|
|
|
{
|
|
|
|
|
m_model->removeModule(moduleName);
|
|
|
|
|
}
|
2008-12-02 12:01:29 +01:00
|
|
|
|
|
|
|
|
void ModulesHandler::setModules(const QList<Module> &modules)
|
|
|
|
|
{
|
2010-05-19 15:14:15 +02:00
|
|
|
m_model->setModules(modules);
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QList<Module> ModulesHandler::modules() const
|
|
|
|
|
{
|
2010-05-19 15:14:15 +02:00
|
|
|
return m_model->modules();
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
2009-04-16 19:42:58 +02:00
|
|
|
|
|
|
|
|
#include "moduleshandler.moc"
|