1
0
Fork 0
forked from len0rd/rockbox

qeditor: use delegate to show bit range information

Change-Id: I314365c3a2cb9d230c412f24d2a8034a12c43444
This commit is contained in:
Amaury Pouly 2014-12-18 10:58:17 +01:00
parent 983c8084c9
commit 2c832968c9
2 changed files with 25 additions and 8 deletions

View file

@ -388,6 +388,14 @@ QString SocFieldCachedItemDelegate::displayText(const QVariant& value, const QLo
return strval;
}
}
else if(value.type() == QVariant::UserType && value.userType() == qMetaTypeId< SocFieldBitRange >())
{
const SocFieldBitRange& br = value.value< SocFieldBitRange >();
if(br.GetFirstBit() == br.GetLastBit())
return QString("%1").arg(br.GetFirstBit());
else
return QString("%1:%2").arg(br.GetLastBit()).arg(br.GetFirstBit());
}
else
return QStyledItemDelegate::displayText(value, locale);
}
@ -485,12 +493,7 @@ QVariant RegFieldTableModel::data(const QModelIndex& index, int role) const
if(section == BitRangeColumn)
{
if(role == Qt::DisplayRole)
{
if(field.first_bit == field.last_bit)
return QVariant(QString("%1").arg(field.first_bit));
else
return QVariant(QString("%1:%2").arg(field.last_bit).arg(field.first_bit));
}
return QVariant::fromValue(SocFieldBitRange(field));
else if(role == Qt::TextAlignmentRole)
return QVariant(Qt::AlignVCenter | Qt::AlignHCenter);
else
@ -603,9 +606,9 @@ void RegFieldTableModel::SetReadOnly(bool en)
void RegFieldTableModel::SetRegister(const soc_reg_t& reg)
{
/* remove all rows */
beginRemoveRows(QModelIndex(), 0, rowCount() - 1);
beginResetModel();
m_reg.field.clear();
endRemoveRows();
endResetModel();
/* add them all */
beginInsertRows(QModelIndex(), 0, reg.field.size() - 1);
m_reg = reg;

View file

@ -168,6 +168,20 @@ protected:
Q_DECLARE_METATYPE(SocFieldCachedValue)
class SocFieldBitRange
{
public:
SocFieldBitRange():m_first_bit(0),m_last_bit(0) {}
SocFieldBitRange(const soc_reg_field_t& field)
:m_first_bit(field.first_bit), m_last_bit(field.last_bit) {}
unsigned GetFirstBit() const { return m_first_bit; }
unsigned GetLastBit() const { return m_last_bit; }
protected:
unsigned m_first_bit, m_last_bit;
};
Q_DECLARE_METATYPE(SocFieldBitRange)
class SocFieldCachedItemDelegate : public QStyledItemDelegate
{
public: