summaryrefslogtreecommitdiff
path: root/utils/regtools
diff options
context:
space:
mode:
authorAmaury Pouly <amaury.pouly@gmail.com>2014-12-15 22:44:17 +0100
committerAmaury Pouly <amaury.pouly@gmail.com>2014-12-15 22:44:17 +0100
commit94c4834bbbcda9ef71ec8d5ff080b41374d8e7c0 (patch)
treea424068bce4a0374335f77bbf74a2d5c052118ca /utils/regtools
parent3b3d9bf725a5b04e4cd9bc4254fbd2594b518e89 (diff)
Revert "regtools/qeditor: use the new model, drop unused code"
This reverts commit 3b3d9bf725a5b04e4cd9bc4254fbd2594b518e89. Gerrit did crap on this one.
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, 111 insertions, 67 deletions
diff --git a/utils/regtools/qeditor/regdisplaypanel.cpp b/utils/regtools/qeditor/regdisplaypanel.cpp
index bbfb4f5840..d450b4e203 100644
--- a/utils/regtools/qeditor/regdisplaypanel.cpp
+++ b/utils/regtools/qeditor/regdisplaypanel.cpp
@@ -176,17 +176,46 @@ 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 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 = 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->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();
@@ -224,13 +253,12 @@ 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->model(), SIGNAL(OnValueModified(int)), this,
- SLOT(OnRegValueChanged(int)));
+ connect(m_raw_val_edit->GetLineEdit(), SIGNAL(returnPressed()), this, SLOT(OnRawRegValueReturnPressed()));
+ connect(m_value_table, SIGNAL(cellChanged(int, int)), this, SLOT(OnRegFieldValueChanged(int, int)));
}
RegDisplayPanel::~RegDisplayPanel()
@@ -252,15 +280,38 @@ 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);
}
@@ -269,10 +320,7 @@ 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();
}
@@ -300,19 +348,23 @@ 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::OnRegValueChanged(int index)
+void RegDisplayPanel::OnRegFieldValueChanged(int row, int col)
{
- QVariant var = m_value_model->GetValue(index);
- if(!var.isValid())
+ if(m_ignore_cell_change || col != FieldValueColumn)
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(),
- var.value< soc_word_t >(), IoBackend::Write);
- // register write can change all fields
+ regval, IoBackend::Write);
Reload();
}
diff --git a/utils/regtools/qeditor/regdisplaypanel.h b/utils/regtools/qeditor/regdisplaypanel.h
index 09943b59a2..ce6f108350 100644
--- a/utils/regtools/qeditor/regdisplaypanel.h
+++ b/utils/regtools/qeditor/regdisplaypanel.h
@@ -86,8 +86,7 @@ protected:
bool m_allow_write;
RegLineEdit *m_raw_val_edit;
RegSexyDisplay *m_sexy_display;
- GrowingTableView *m_value_table;
- RegFieldTableModel *m_value_model;
+ GrowingTableWidget *m_value_table;
QStyledItemDelegate *m_table_delegate;
QItemEditorFactory *m_table_edit_factory;
RegItemEditorCreator *m_regedit_creator;
@@ -96,10 +95,11 @@ protected:
QLabel *m_desc;
QWidget *m_viewport;
QScrollArea *m_scroll;
+ bool m_ignore_cell_change;
private slots:
void OnRawRegValueReturnPressed();
- void OnRegValueChanged(int index);
+ void OnRegFieldValueChanged(int row, int col);
};
#endif /* REGDISPLAYPANEL_H */
diff --git a/utils/regtools/qeditor/utils.cpp b/utils/regtools/qeditor/utils.cpp
index 448ed92c3e..036f1595a3 100644
--- a/utils/regtools/qeditor/utils.cpp
+++ b/utils/regtools/qeditor/utils.cpp
@@ -331,22 +331,7 @@ QString SocFieldCachedItemDelegate::displayText(const QVariant& value, const QLo
{
const SocFieldCachedValue& v = value.value< SocFieldCachedValue >();
int bitcount = v.field().last_bit - v.field().first_bit;
- 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;
- }
+ return QString("0x%1").arg(v.value(), (bitcount + 3) / 4, 16, QChar('0'));
}
else
return QStyledItemDelegate::displayText(value, locale);
@@ -543,25 +528,34 @@ void RegSexyDisplay::paintEvent(QPaintEvent *event)
}
/**
- * GrowingTableView
+ * GrowingTextEdit
*/
-GrowingTableView::GrowingTableView(QWidget *parent)
- :QTableView(parent)
+GrowingTextEdit::GrowingTextEdit(QWidget *parent)
+ :QTextEdit(parent)
{
+ connect(this, SIGNAL(textChanged()), this, SLOT(TextChanged()));
+ setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
+ setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
}
-void GrowingTableView::setModel(QAbstractItemModel *m)
+void GrowingTextEdit::TextChanged()
+{
+ 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)
{
- 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 GrowingTableView::DataChanged(const QModelIndex& tl, const QModelIndex& br)
+void GrowingTableWidget::DataChanged(const QModelIndex& tl, const QModelIndex& br)
{
Q_UNUSED(tl);
Q_UNUSED(br);
@@ -569,7 +563,7 @@ void GrowingTableView::DataChanged(const QModelIndex& tl, const QModelIndex& br)
resizeColumnsToContents();
int h = contentsMargins().top() + contentsMargins().bottom();
h += horizontalHeader()->height();
- for(int i = 0; i < model()->rowCount(); i++)
+ for(int i = 0; i < rowCount(); i++)
h += rowHeight(i);
setMinimumHeight(h);
}
diff --git a/utils/regtools/qeditor/utils.h b/utils/regtools/qeditor/utils.h
index 6612ce20a4..970010233a 100644
--- a/utils/regtools/qeditor/utils.h
+++ b/utils/regtools/qeditor/utils.h
@@ -149,20 +149,9 @@ Q_DECLARE_METATYPE(SocFieldCachedValue)
class SocFieldCachedItemDelegate : public QStyledItemDelegate
{
public:
- 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;
+ virtual QString displayText(const QVariant& value, const QLocale& locale) const;
};
class SocFieldCachedEditor : public SocFieldEditor
@@ -214,12 +203,21 @@ private:
mutable QSize m_size;
};
-class GrowingTableView : public QTableView
+class GrowingTextEdit : public QTextEdit
+{
+ Q_OBJECT
+public:
+ GrowingTextEdit(QWidget *parent = 0);
+
+protected slots:
+ void TextChanged();
+};
+
+class GrowingTableWidget : public QTableWidget
{
Q_OBJECT
public:
- GrowingTableView(QWidget *parent = 0);
- virtual void setModel(QAbstractItemModel *model);
+ GrowingTableWidget(QWidget *parent = 0);
protected slots:
void DataChanged(const QModelIndex& tl, const QModelIndex& br);