2009-02-25 09:15:00 +01:00
|
|
|
/**************************************************************************
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
|
|
|
|
** This file is part of Qt Creator
|
|
|
|
|
**
|
2011-01-11 16:28:15 +01:00
|
|
|
** Copyright (c) 2011 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
|
|
|
**
|
2010-12-17 16:01:08 +01:00
|
|
|
** No Commercial Usage
|
2008-12-02 14:17:16 +01:00
|
|
|
**
|
2010-12-17 16:01:08 +01:00
|
|
|
** This file contains pre-release code and may not be distributed.
|
|
|
|
|
** You may use this file in accordance with the terms and conditions
|
|
|
|
|
** contained in the Technology Preview License Agreement accompanying
|
|
|
|
|
** this package.
|
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
|
|
|
**
|
2010-12-17 16:01:08 +01:00
|
|
|
** In addition, as a special exception, Nokia gives you certain additional
|
|
|
|
|
** rights. These rights are described in the Nokia Qt LGPL Exception
|
|
|
|
|
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
|
|
|
|
**
|
|
|
|
|
** If you have questions regarding the use of this file, please contact
|
|
|
|
|
** Nokia at qt-info@nokia.com.
|
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 "registerhandler.h"
|
2010-09-22 17:30:22 +02:00
|
|
|
#include "watchdelegatewidgets.h"
|
2008-12-02 12:01:29 +01:00
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////
|
|
|
|
|
//
|
|
|
|
|
// RegisterHandler
|
|
|
|
|
//
|
|
|
|
|
//////////////////////////////////////////////////////////////////
|
|
|
|
|
|
2010-11-05 13:35:31 +01:00
|
|
|
namespace Debugger {
|
|
|
|
|
namespace Internal {
|
|
|
|
|
|
|
|
|
|
RegisterHandler::RegisterHandler()
|
|
|
|
|
: m_base(-1)
|
2009-08-13 16:16:19 +02:00
|
|
|
{
|
2009-08-18 08:34:48 +02:00
|
|
|
setNumberBase(16);
|
2009-08-13 16:16:19 +02:00
|
|
|
}
|
2008-12-02 12:01:29 +01:00
|
|
|
|
|
|
|
|
int RegisterHandler::rowCount(const QModelIndex &parent) const
|
|
|
|
|
{
|
2009-05-13 17:42:07 +02:00
|
|
|
return parent.isValid() ? 0 : m_registers.size();
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int RegisterHandler::columnCount(const QModelIndex &parent) const
|
|
|
|
|
{
|
2009-05-13 17:42:07 +02:00
|
|
|
return parent.isValid() ? 0 : 2;
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
2010-09-22 17:30:22 +02:00
|
|
|
// Editor value: Preferably number, else string.
|
2010-11-05 13:35:31 +01:00
|
|
|
QVariant Register::editValue() const
|
2010-09-22 09:41:15 +02:00
|
|
|
{
|
|
|
|
|
bool ok = true;
|
|
|
|
|
// Try to convert to number?
|
2010-11-05 13:35:31 +01:00
|
|
|
const qulonglong v = value.toULongLong(&ok, 0); // Autodetect format
|
2010-09-22 09:41:15 +02:00
|
|
|
if (ok)
|
2010-11-05 13:35:31 +01:00
|
|
|
return QVariant(v);
|
|
|
|
|
return QVariant(value);
|
2010-09-22 17:30:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Editor value: Preferably padded number, else padded string.
|
2010-11-05 13:35:31 +01:00
|
|
|
QString Register::displayValue(int base, int strlen) const
|
2010-09-22 17:30:22 +02:00
|
|
|
{
|
2010-11-05 13:35:31 +01:00
|
|
|
const QVariant editV = editValue();
|
2010-09-22 17:30:22 +02:00
|
|
|
if (editV.type() == QVariant::ULongLong)
|
2010-11-05 13:35:31 +01:00
|
|
|
return QString::fromAscii("%1").arg(editV.toULongLong(), strlen, base);
|
2010-09-22 17:30:22 +02:00
|
|
|
const QString stringValue = editV.toString();
|
2010-11-05 13:35:31 +01:00
|
|
|
if (stringValue.size() < strlen)
|
|
|
|
|
return QString(strlen - stringValue.size(), QLatin1Char(' ')) + value;
|
2010-09-22 17:30:22 +02:00
|
|
|
return stringValue;
|
2010-09-22 09:41:15 +02:00
|
|
|
}
|
|
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
QVariant RegisterHandler::data(const QModelIndex &index, int role) const
|
|
|
|
|
{
|
|
|
|
|
if (!index.isValid() || index.row() >= m_registers.size())
|
|
|
|
|
return QVariant();
|
|
|
|
|
|
|
|
|
|
const Register ® = m_registers.at(index.row());
|
|
|
|
|
|
2010-09-22 09:41:15 +02:00
|
|
|
switch (role) {
|
|
|
|
|
case Qt::DisplayRole:
|
2008-12-02 12:01:29 +01:00
|
|
|
switch (index.column()) {
|
2010-09-22 09:41:15 +02:00
|
|
|
case 0: {
|
|
|
|
|
const QString padding = QLatin1String(" ");
|
|
|
|
|
return QVariant(padding + reg.name + padding);
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
2010-09-22 09:41:15 +02:00
|
|
|
case 1: // Display: Pad value for alignment
|
2010-11-05 13:35:31 +01:00
|
|
|
return reg.displayValue(m_base, m_strlen);
|
2010-09-22 09:41:15 +02:00
|
|
|
} // switch column
|
|
|
|
|
case Qt::EditRole: // Edit: Unpadded for editing
|
2010-11-05 13:35:31 +01:00
|
|
|
return reg.editValue();
|
2010-09-22 09:41:15 +02:00
|
|
|
case Qt::TextAlignmentRole:
|
|
|
|
|
return index.column() == 1 ? QVariant(Qt::AlignRight) : QVariant();
|
|
|
|
|
default:
|
|
|
|
|
break;
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
return QVariant();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QVariant RegisterHandler::headerData(int section, Qt::Orientation orientation,
|
|
|
|
|
int role) const
|
|
|
|
|
{
|
|
|
|
|
if (orientation == Qt::Horizontal && role == Qt::DisplayRole) {
|
2009-04-08 12:11:30 +02:00
|
|
|
switch (section) {
|
|
|
|
|
case 0: return tr("Name");
|
2009-08-13 16:16:19 +02:00
|
|
|
case 1: return tr("Value (base %1)").arg(m_base);
|
2008-12-02 12:01:29 +01:00
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
return QVariant();
|
|
|
|
|
}
|
|
|
|
|
|
2009-08-18 08:34:48 +02:00
|
|
|
Qt::ItemFlags RegisterHandler::flags(const QModelIndex &idx) const
|
|
|
|
|
{
|
|
|
|
|
if (!idx.isValid())
|
2010-09-22 17:30:22 +02:00
|
|
|
return Qt::ItemFlags();
|
2009-08-18 08:34:48 +02:00
|
|
|
|
2010-09-22 17:30:22 +02:00
|
|
|
const Qt::ItemFlags notEditable = Qt::ItemIsSelectable|Qt::ItemIsEnabled;
|
|
|
|
|
// Can edit registers if they are hex numbers and not arrays.
|
2010-11-05 13:35:31 +01:00
|
|
|
if (idx.column() == 1
|
|
|
|
|
&& IntegerWatchLineEdit::isUnsignedHexNumber(m_registers.at(idx.row()).value))
|
2010-09-22 17:30:22 +02:00
|
|
|
return notEditable | Qt::ItemIsEditable;
|
|
|
|
|
return notEditable;
|
2009-08-18 08:34:48 +02:00
|
|
|
}
|
|
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
void RegisterHandler::removeAll()
|
|
|
|
|
{
|
|
|
|
|
m_registers.clear();
|
|
|
|
|
reset();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool RegisterHandler::isEmpty() const
|
|
|
|
|
{
|
|
|
|
|
return m_registers.isEmpty();
|
|
|
|
|
}
|
|
|
|
|
|
2011-04-06 14:07:09 +02:00
|
|
|
// Compare register sets by name
|
|
|
|
|
static inline bool compareRegisterSet(const Registers &r1, const Registers &r2)
|
|
|
|
|
{
|
|
|
|
|
if (r1.size() != r2.size())
|
|
|
|
|
return false;
|
|
|
|
|
const int size = r1.size();
|
|
|
|
|
for (int r = 0; r < size; r++)
|
|
|
|
|
if (r1.at(r).name != r2.at(r).name)
|
|
|
|
|
return false;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2010-02-10 11:37:57 +01:00
|
|
|
void RegisterHandler::setRegisters(const Registers ®isters)
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
|
|
|
|
m_registers = registers;
|
2011-04-06 14:07:09 +02:00
|
|
|
const int size = m_registers.size();
|
|
|
|
|
for (int r = 0; r < size; r++)
|
|
|
|
|
m_registers[r].changed = false;
|
2010-09-22 09:41:15 +02:00
|
|
|
calculateWidth();
|
2008-12-02 12:01:29 +01:00
|
|
|
reset();
|
|
|
|
|
}
|
|
|
|
|
|
2010-09-01 13:56:51 +02:00
|
|
|
void RegisterHandler::setAndMarkRegisters(const Registers ®isters)
|
|
|
|
|
{
|
2011-04-06 14:07:09 +02:00
|
|
|
if (!compareRegisterSet(m_registers, registers)) {
|
|
|
|
|
setRegisters(registers);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
const int size = m_registers.size();
|
|
|
|
|
for (int r = 0; r < size; r++) {
|
|
|
|
|
if (m_registers.at(r).value != registers.at(r).value) {
|
|
|
|
|
// Indicate red if values change, keep changed.
|
|
|
|
|
m_registers[r].changed = m_registers[r].changed || !m_registers.at(r).value.isEmpty();
|
|
|
|
|
m_registers[r].value = registers.at(r).value;
|
|
|
|
|
const QModelIndex regIndex = index(r, 1);
|
|
|
|
|
emit dataChanged(regIndex, regIndex);
|
|
|
|
|
}
|
|
|
|
|
}
|
2010-09-01 13:56:51 +02:00
|
|
|
}
|
|
|
|
|
|
2010-02-10 11:37:57 +01:00
|
|
|
Registers RegisterHandler::registers() const
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
|
|
|
|
return m_registers;
|
|
|
|
|
}
|
2009-08-13 16:16:19 +02:00
|
|
|
|
2010-09-22 09:41:15 +02:00
|
|
|
void RegisterHandler::calculateWidth()
|
|
|
|
|
{
|
|
|
|
|
m_strlen = (m_base == 2 ? 64 : m_base == 8 ? 32 : m_base == 10 ? 26 : 16);
|
|
|
|
|
}
|
|
|
|
|
|
2009-08-13 16:16:19 +02:00
|
|
|
void RegisterHandler::setNumberBase(int base)
|
|
|
|
|
{
|
2010-09-22 09:41:15 +02:00
|
|
|
if (m_base != base) {
|
|
|
|
|
m_base = base;
|
|
|
|
|
calculateWidth();
|
|
|
|
|
emit reset();
|
|
|
|
|
}
|
2009-08-13 16:16:19 +02:00
|
|
|
}
|
2010-11-05 13:35:31 +01:00
|
|
|
|
|
|
|
|
} // namespace Internal
|
|
|
|
|
} // namespace Debugger
|