summaryrefslogtreecommitdiffstats
path: root/utils/regtools
diff options
context:
space:
mode:
Diffstat (limited to 'utils/regtools')
-rw-r--r--utils/regtools/qeditor/regdisplaypanel.cpp96
-rw-r--r--utils/regtools/qeditor/regdisplaypanel.h6
-rw-r--r--utils/regtools/qeditor/utils.cpp48
-rw-r--r--utils/regtools/qeditor/utils.h28
4 files changed, 67 insertions, 111 deletions
diff --git a/utils/regtools/qeditor/regdisplaypanel.cpp b/utils/regtools/qeditor/regdisplaypanel.cpp
index 8238fa9606..3dbdb54241 100644
--- a/utils/regtools/qeditor/regdisplaypanel.cpp
+++ b/utils/regtools/qeditor/regdisplaypanel.cpp
@@ -196,46 +196,17 @@ RegDisplayPanel::RegDisplayPanel(QWidget *parent, IoBackend *io_backend, const S
raw_val_layout->addWidget(m_raw_val_edit);
raw_val_layout->addStretch();
- m_value_table = new GrowingTableWidget;
- m_value_table->setRowCount(reg.field.size());
- m_value_table->setColumnCount(5);
- for(size_t row = 0; row < reg.field.size(); row++)
- {
- const soc_reg_field_t& field = reg.field[row];
- QString bits_str;
- if(field.first_bit == field.last_bit)
- bits_str.sprintf("%d", field.first_bit);
- else
- bits_str.sprintf("%d:%d", field.last_bit, field.first_bit);
- QTableWidgetItem *item = new QTableWidgetItem(bits_str);
- item->setTextAlignment(Qt::AlignVCenter | Qt::AlignHCenter);
- item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
- m_value_table->setItem(row, FieldBitsColumn, item);
- item = new QTableWidgetItem(QString(field.name.c_str()));
- item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
- m_value_table->setItem(row, FieldNameColumn, item);
- item = new QTableWidgetItem();
- item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
- item->setData(Qt::DisplayRole, QVariant::fromValue(SocFieldCachedValue()));
- item->setTextAlignment(Qt::AlignVCenter | Qt::AlignHCenter);
- m_value_table->setItem(row, FieldValueColumn, item);
- item = new QTableWidgetItem("");
- item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
- item->setTextAlignment(Qt::AlignVCenter | Qt::AlignHCenter);
- m_value_table->setItem(row, FieldMeaningColumn, item);
- item = new QTableWidgetItem(QString(field.desc.c_str()));
- item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
- m_value_table->setItem(row, FieldDescColumn, item);
- }
- m_value_table->setHorizontalHeaderItem(FieldBitsColumn, new QTableWidgetItem("Bits"));
- m_value_table->setHorizontalHeaderItem(FieldNameColumn, new QTableWidgetItem("Name"));
- m_value_table->setHorizontalHeaderItem(FieldValueColumn, new QTableWidgetItem("Value"));
- m_value_table->setHorizontalHeaderItem(FieldMeaningColumn, new QTableWidgetItem("Meaning"));
- m_value_table->setHorizontalHeaderItem(FieldDescColumn, new QTableWidgetItem("Description"));
+ m_value_table = new GrowingTableView;
+ m_value_model = new RegFieldTableModel(m_value_table); // view takes ownership
+ m_value_model->SetRegister(m_reg.GetReg());
+ m_value_model->SetReadOnly(read_only);
+ m_value_table->setModel(m_value_model);
m_value_table->verticalHeader()->setVisible(false);
m_value_table->resizeColumnsToContents();
m_value_table->horizontalHeader()->setStretchLastSection(true);
m_value_table->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
+ // FIXME we cannot use setAlternatingRowColors() because we override the
+ // background color, should it be part of the model ?
SocFieldCachedItemDelegate *m_table_delegate = new SocFieldCachedItemDelegate(this);
m_table_edit_factory = new QItemEditorFactory();
@@ -273,12 +244,13 @@ RegDisplayPanel::RegDisplayPanel(QWidget *parent, IoBackend *io_backend, const S
setLayout(layout);
AllowWrite(false);
- m_ignore_cell_change = false;
// load data
Reload();
- connect(m_raw_val_edit->GetLineEdit(), SIGNAL(returnPressed()), this, SLOT(OnRawRegValueReturnPressed()));
- connect(m_value_table, SIGNAL(cellChanged(int, int)), this, SLOT(OnRegFieldValueChanged(int, int)));
+ connect(m_raw_val_edit->GetLineEdit(), SIGNAL(returnPressed()), this,
+ SLOT(OnRawRegValueReturnPressed()));
+ connect(m_value_table->model(), SIGNAL(OnValueModified(int)), this,
+ SLOT(OnRegValueChanged(int)));
}
RegDisplayPanel::~RegDisplayPanel()
@@ -300,38 +272,15 @@ void RegDisplayPanel::Reload()
m_raw_val_name->show();
m_raw_val_edit->show();
m_raw_val_edit->GetLineEdit()->setText(QString().sprintf("0x%08x", value));
+ m_value_model->SetValues(QVector< QVariant >(1, QVariant(value)));
}
else
{
m_raw_val_name->hide();
m_raw_val_edit->hide();
+ m_value_model->SetValues(QVector< QVariant >());
}
- m_ignore_cell_change = true;
- for(size_t row = 0; row < reg.field.size(); row++)
- {
- const soc_reg_field_t& field = reg.field[row];
- QTableWidgetItem *item = m_value_table->item(row, FieldValueColumn);
- QTableWidgetItem *desc_item = m_value_table->item(row, FieldMeaningColumn);
- if(has_value)
- {
- soc_word_t v = (value & field.bitmask()) >> field.first_bit;
- QString value_name;
- foreach(const soc_reg_field_value_t& rval, field.value)
- if(v == rval.value)
- value_name = rval.name.c_str();
- item->setData(Qt::DisplayRole, QVariant::fromValue(SocFieldCachedValue(field, v)));
- if(value_name.size() != 0)
- desc_item->setText(value_name);
- }
- else
- item->setData(Qt::DisplayRole, QVariant::fromValue(SocFieldCachedValue()));
- item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
- if(m_allow_write)
- item->setFlags(item->flags() | Qt::ItemIsEditable);
- }
- m_ignore_cell_change = false;
-
m_value_table->resizeColumnsToContents();
m_value_table->horizontalHeader()->setStretchLastSection(true);
}
@@ -340,7 +289,10 @@ void RegDisplayPanel::AllowWrite(bool en)
{
m_allow_write = en;
if(m_raw_val_edit)
+ {
m_raw_val_edit->SetReadOnly(m_io_backend->IsReadOnly() || !m_allow_write);
+ m_value_model->SetReadOnly(m_io_backend->IsReadOnly() || !m_allow_write);
+ }
Reload();
}
@@ -368,23 +320,19 @@ void RegDisplayPanel::OnRawRegValueReturnPressed()
BackendHelper helper(m_io_backend, m_reg);
helper.WriteRegister(m_reg.GetDevAddr().name.c_str(), m_reg.GetRegAddr().name.c_str(),
val, mode);
+ // register write can change all fields
Reload();
}
-void RegDisplayPanel::OnRegFieldValueChanged(int row, int col)
+void RegDisplayPanel::OnRegValueChanged(int index)
{
- if(m_ignore_cell_change || col != FieldValueColumn)
+ QVariant var = m_value_model->GetValue(index);
+ if(!var.isValid())
return;
- QTableWidgetItem *item = m_value_table->item(row, col);
- SocFieldCachedValue val = item->data(Qt::DisplayRole).value< SocFieldCachedValue >();
BackendHelper helper(m_io_backend, m_reg);
- soc_word_t regval;
- if(!helper.ReadRegister(m_reg.GetDevAddr().name.c_str(), m_reg.GetRegAddr().name.c_str(), regval))
- return;
- regval = (regval & ~val.field().bitmask()) |
- ((val.value() << val.field().first_bit) & val.field().bitmask());
helper.WriteRegister(m_reg.GetDevAddr().name.c_str(), m_reg.GetRegAddr().name.c_str(),
- regval, IoBackend::Write);
+ var.value< soc_word_t >(), IoBackend::Write);
+ // register write can change all fields
Reload();
}
diff --git a/utils/regtools/qeditor/regdisplaypanel.h b/utils/regtools/qeditor/regdisplaypanel.h
index b7c0c11c6c..313fc7e369 100644
--- a/utils/regtools/qeditor/regdisplaypanel.h
+++ b/utils/regtools/qeditor/regdisplaypanel.h
@@ -106,7 +106,8 @@ protected:
bool m_allow_write;
RegLineEdit *m_raw_val_edit;
RegSexyDisplay *m_sexy_display;
- GrowingTableWidget *m_value_table;
+ GrowingTableView *m_value_table;
+ RegFieldTableModel *m_value_model;
QStyledItemDelegate *m_table_delegate;
QItemEditorFactory *m_table_edit_factory;
RegItemEditorCreator *m_regedit_creator;
@@ -115,11 +116,10 @@ protected:
QLabel *m_desc;
QWidget *m_viewport;
QScrollArea *m_scroll;
- bool m_ignore_cell_change;
private slots:
void OnRawRegValueReturnPressed();
- void OnRegFieldValueChanged(int row, int col);
+ void OnRegValueChanged(int index);
};
#endif /* REGDISPLAYPANEL_H */
diff --git a/utils/regtools/qeditor/utils.cpp b/utils/regtools/qeditor/utils.cpp
index df7f714f03..5aef2414a4 100644
--- a/utils/regtools/qeditor/utils.cpp
+++ b/utils/regtools/qeditor/utils.cpp
@@ -371,7 +371,22 @@ QString SocFieldCachedItemDelegate::displayText(const QVariant& value, const QLo
{
const SocFieldCachedValue& v = value.value< SocFieldCachedValue >();
int bitcount = v.field().last_bit - v.field().first_bit;
- return QString("0x%1").arg(v.value(), (bitcount + 3) / 4, 16, QChar('0'));
+ QString name = v.value_name();
+ QString strval = QString("0x%1").arg(v.value(), (bitcount + 3) / 4, 16, QChar('0'));
+ switch(m_mode)
+ {
+ case DisplayName:
+ if(name.size() > 0)
+ return name;
+ /* fallthrough */
+ case DisplayValueAndName:
+ if(name.size() > 0)
+ return QString("%1 (%2)").arg(strval).arg(name);
+ /* fallthrough */
+ case DisplayValue:
+ default:
+ return strval;
+ }
}
else
return QStyledItemDelegate::displayText(value, locale);
@@ -791,34 +806,25 @@ void RegSexyDisplay::paintEvent(QPaintEvent *event)
}
/**
- * GrowingTextEdit
+ * GrowingTableView
*/
-GrowingTextEdit::GrowingTextEdit(QWidget *parent)
- :QTextEdit(parent)
-{
- connect(this, SIGNAL(textChanged()), this, SLOT(TextChanged()));
- setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
- setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
-}
-
-void GrowingTextEdit::TextChanged()
+GrowingTableView::GrowingTableView(QWidget *parent)
+ :QTableView(parent)
{
- int content_size = document()->documentLayout()->documentSize().height();
- content_size = qMax(content_size, fontMetrics().height());
- setFixedHeight(content_size + contentsMargins().top() + contentsMargins().bottom());
}
-/**
- * GrowingTableWidget
- */
-GrowingTableWidget::GrowingTableWidget(QWidget *parent)
- :QTableWidget(parent)
+void GrowingTableView::setModel(QAbstractItemModel *m)
{
+ if(model())
+ disconnect(model(), SIGNAL(dataChanged(const QModelIndex&, const QModelIndex&)),
+ this, SLOT(DataChanged(const QModelIndex&, const QModelIndex&)));
+ QTableView::setModel(m);
connect(model(), SIGNAL(dataChanged(const QModelIndex&, const QModelIndex&)),
this, SLOT(DataChanged(const QModelIndex&, const QModelIndex&)));
+ DataChanged(QModelIndex(), QModelIndex());
}
-void GrowingTableWidget::DataChanged(const QModelIndex& tl, const QModelIndex& br)
+void GrowingTableView::DataChanged(const QModelIndex& tl, const QModelIndex& br)
{
Q_UNUSED(tl);
Q_UNUSED(br);
@@ -826,7 +832,7 @@ void GrowingTableWidget::DataChanged(const QModelIndex& tl, const QModelIndex& b
resizeColumnsToContents();
int h = contentsMargins().top() + contentsMargins().bottom();
h += horizontalHeader()->height();
- for(int i = 0; i < rowCount(); i++)
+ for(int i = 0; i < model()->rowCount(); i++)
h += rowHeight(i);
setMinimumHeight(h);
}
diff --git a/utils/regtools/qeditor/utils.h b/utils/regtools/qeditor/utils.h
index da9638baf7..27476dba61 100644
--- a/utils/regtools/qeditor/utils.h
+++ b/utils/regtools/qeditor/utils.h
@@ -171,9 +171,20 @@ Q_DECLARE_METATYPE(SocFieldCachedValue)
class SocFieldCachedItemDelegate : public QStyledItemDelegate
{
public:
- SocFieldCachedItemDelegate(QObject *parent = 0):QStyledItemDelegate(parent) {}
+ enum DisplayMode
+ {
+ DisplayValueAndName, /* "value (name)" or "value" if no name */
+ DisplayName, /* "name" or "value" if no name */
+ DisplayValue, /* "value" */
+ };
+ SocFieldCachedItemDelegate(QObject *parent = 0):QStyledItemDelegate(parent) {}
virtual QString displayText(const QVariant& value, const QLocale& locale) const;
+ void SetMode(DisplayMode mode) { m_mode = mode; }
+ DisplayMode GetMode() const { return m_mode; }
+
+protected:
+ DisplayMode m_mode;
};
class SocFieldCachedEditor : public SocFieldEditor
@@ -291,21 +302,12 @@ private:
mutable QSize m_size;
};
-class GrowingTextEdit : public QTextEdit
-{
- Q_OBJECT
-public:
- GrowingTextEdit(QWidget *parent = 0);
-
-protected slots:
- void TextChanged();
-};
-
-class GrowingTableWidget : public QTableWidget
+class GrowingTableView : public QTableView
{
Q_OBJECT
public:
- GrowingTableWidget(QWidget *parent = 0);
+ GrowingTableView(QWidget *parent = 0);
+ virtual void setModel(QAbstractItemModel *model);
protected slots:
void DataChanged(const QModelIndex& tl, const QModelIndex& br);