summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAmaury Pouly <amaury.pouly@gmail.com>2014-12-18 10:58:17 +0100
committerAmaury Pouly <amaury.pouly@gmail.com>2015-09-10 15:20:38 +0200
commit2c832968c91cb56e4c252bd8eafb03d7d9c8aeda (patch)
tree8b6dd9e3e4688d4e5bbd7ed2dbbf52b62bd35deb
parent983c8084c9a64e48b29fb1e826cc84c35d2c9849 (diff)
downloadrockbox-2c832968c91cb56e4c252bd8eafb03d7d9c8aeda.tar.gz
rockbox-2c832968c91cb56e4c252bd8eafb03d7d9c8aeda.zip
qeditor: use delegate to show bit range information
Change-Id: I314365c3a2cb9d230c412f24d2a8034a12c43444
-rw-r--r--utils/regtools/qeditor/utils.cpp19
-rw-r--r--utils/regtools/qeditor/utils.h14
2 files changed, 25 insertions, 8 deletions
diff --git a/utils/regtools/qeditor/utils.cpp b/utils/regtools/qeditor/utils.cpp
index 5aef2414a4..4116dbcc81 100644
--- a/utils/regtools/qeditor/utils.cpp
+++ b/utils/regtools/qeditor/utils.cpp
@@ -388,6 +388,14 @@ QString SocFieldCachedItemDelegate::displayText(const QVariant& value, const QLo
388 return strval; 388 return strval;
389 } 389 }
390 } 390 }
391 else if(value.type() == QVariant::UserType && value.userType() == qMetaTypeId< SocFieldBitRange >())
392 {
393 const SocFieldBitRange& br = value.value< SocFieldBitRange >();
394 if(br.GetFirstBit() == br.GetLastBit())
395 return QString("%1").arg(br.GetFirstBit());
396 else
397 return QString("%1:%2").arg(br.GetLastBit()).arg(br.GetFirstBit());
398 }
391 else 399 else
392 return QStyledItemDelegate::displayText(value, locale); 400 return QStyledItemDelegate::displayText(value, locale);
393} 401}
@@ -485,12 +493,7 @@ QVariant RegFieldTableModel::data(const QModelIndex& index, int role) const
485 if(section == BitRangeColumn) 493 if(section == BitRangeColumn)
486 { 494 {
487 if(role == Qt::DisplayRole) 495 if(role == Qt::DisplayRole)
488 { 496 return QVariant::fromValue(SocFieldBitRange(field));
489 if(field.first_bit == field.last_bit)
490 return QVariant(QString("%1").arg(field.first_bit));
491 else
492 return QVariant(QString("%1:%2").arg(field.last_bit).arg(field.first_bit));
493 }
494 else if(role == Qt::TextAlignmentRole) 497 else if(role == Qt::TextAlignmentRole)
495 return QVariant(Qt::AlignVCenter | Qt::AlignHCenter); 498 return QVariant(Qt::AlignVCenter | Qt::AlignHCenter);
496 else 499 else
@@ -603,9 +606,9 @@ void RegFieldTableModel::SetReadOnly(bool en)
603void RegFieldTableModel::SetRegister(const soc_reg_t& reg) 606void RegFieldTableModel::SetRegister(const soc_reg_t& reg)
604{ 607{
605 /* remove all rows */ 608 /* remove all rows */
606 beginRemoveRows(QModelIndex(), 0, rowCount() - 1); 609 beginResetModel();
607 m_reg.field.clear(); 610 m_reg.field.clear();
608 endRemoveRows(); 611 endResetModel();
609 /* add them all */ 612 /* add them all */
610 beginInsertRows(QModelIndex(), 0, reg.field.size() - 1); 613 beginInsertRows(QModelIndex(), 0, reg.field.size() - 1);
611 m_reg = reg; 614 m_reg = reg;
diff --git a/utils/regtools/qeditor/utils.h b/utils/regtools/qeditor/utils.h
index 27476dba61..c78b0a40e4 100644
--- a/utils/regtools/qeditor/utils.h
+++ b/utils/regtools/qeditor/utils.h
@@ -168,6 +168,20 @@ protected:
168 168
169Q_DECLARE_METATYPE(SocFieldCachedValue) 169Q_DECLARE_METATYPE(SocFieldCachedValue)
170 170
171class SocFieldBitRange
172{
173public:
174 SocFieldBitRange():m_first_bit(0),m_last_bit(0) {}
175 SocFieldBitRange(const soc_reg_field_t& field)
176 :m_first_bit(field.first_bit), m_last_bit(field.last_bit) {}
177 unsigned GetFirstBit() const { return m_first_bit; }
178 unsigned GetLastBit() const { return m_last_bit; }
179protected:
180 unsigned m_first_bit, m_last_bit;
181};
182
183Q_DECLARE_METATYPE(SocFieldBitRange)
184
171class SocFieldCachedItemDelegate : public QStyledItemDelegate 185class SocFieldCachedItemDelegate : public QStyledItemDelegate
172{ 186{
173public: 187public: