summaryrefslogtreecommitdiffstats
path: root/utils/regtools/qeditor/regdisplaypanel.cpp
diff options
context:
space:
mode:
authorAmaury Pouly <amaury.pouly@gmail.com>2016-02-06 15:08:43 +0000
committerAmaury Pouly <amaury.pouly@gmail.com>2016-02-06 15:20:48 +0000
commit6b9610fb908b27d1e0383c8d9bde3a88f35ed30c (patch)
tree1b0f5e2821b44d20f3704c584e309f5911357040 /utils/regtools/qeditor/regdisplaypanel.cpp
parent0f701a64bee43e79f95970ae9c0ec43ea7fcdf17 (diff)
downloadrockbox-6b9610fb908b27d1e0383c8d9bde3a88f35ed30c.tar.gz
rockbox-6b9610fb908b27d1e0383c8d9bde3a88f35ed30c.tar.bz2
rockbox-6b9610fb908b27d1e0383c8d9bde3a88f35ed30c.zip
regtoosl/qeditor: port to the new description format
This big commit port qeditor from v1 to v2 register file format. Although the display code was much simplified, the edit code had to be rewritten. The new code also brings many improvement to the register display widget. The new code also compiles with both Qt4 and Qt5, although it is recommended to use Qt5 to get some improvements, especially in the layout of editor. Change-Id: I24633ac37a144f25d9e705b565654269ec9cfbd3
Diffstat (limited to 'utils/regtools/qeditor/regdisplaypanel.cpp')
-rw-r--r--utils/regtools/qeditor/regdisplaypanel.cpp157
1 files changed, 87 insertions, 70 deletions
diff --git a/utils/regtools/qeditor/regdisplaypanel.cpp b/utils/regtools/qeditor/regdisplaypanel.cpp
index 167c776cce..a72d280d6c 100644
--- a/utils/regtools/qeditor/regdisplaypanel.cpp
+++ b/utils/regtools/qeditor/regdisplaypanel.cpp
@@ -21,36 +21,26 @@
#include "regdisplaypanel.h"
#include <QHeaderView>
#include <QDebug>
-
-/**
- * RegItemEditorCreator
- */
-
-QWidget *RegItemEditorCreator::createWidget(QWidget * parent) const
-{
- return new RegLineEdit(parent);
-}
-
-QByteArray RegItemEditorCreator::valuePropertyName () const
-{
- return QByteArray("text");
-}
+#include <QStandardItemModel>
/**
* SocDisplayPanel
*/
-SocDisplayPanel::SocDisplayPanel(QWidget *parent, const SocRef& dev_ref)
- :QGroupBox(parent), m_soc(dev_ref)
+SocDisplayPanel::SocDisplayPanel(QWidget *parent, IoBackend *io_backend,
+ const soc_desc::soc_ref_t& ref)
+ :QGroupBox(parent), m_soc(ref)
{
+ Q_UNUSED(io_backend)
QVBoxLayout *right_layout = new QVBoxLayout;
m_name = new QLabel(this);
m_name->setTextFormat(Qt::RichText);
- m_name->setText("<h1>" + QString::fromStdString(m_soc.GetSoc().name) + "</h1>");
+ m_name->setText("<h1>" + QString::fromStdString(m_soc.get()->name) + "</h1>");
m_desc = new QLabel(this);
m_name->setTextFormat(Qt::RichText);
- m_desc->setText(QString::fromStdString(m_soc.GetSoc().desc));
+ m_desc->setText(QString::fromStdString(m_soc.get()->desc));
+ m_desc->setVisible(m_desc->text().size() != 0);
right_layout->addWidget(m_name, 0);
right_layout->addWidget(m_desc, 0);
@@ -71,24 +61,21 @@ QWidget *SocDisplayPanel::GetWidget()
}
/**
- * DevDisplayPanel
+ * NodeDisplayPanel
*/
-DevDisplayPanel::DevDisplayPanel(QWidget *parent, const SocDevRef& dev_ref)
- :QGroupBox(parent), m_dev(dev_ref), m_reg_font(font())
+NodeDisplayPanel::NodeDisplayPanel(QWidget *parent, IoBackend *io_backend,
+ const soc_desc::node_inst_t& ref)
+ :QGroupBox(parent), m_node(ref)
{
+ BackendHelper helper(io_backend, ref.soc());
QVBoxLayout *right_layout = new QVBoxLayout;
- const soc_dev_addr_t& dev_addr = m_dev.GetDevAddr();
-
- m_reg_font.setWeight(100);
- m_reg_font.setKerning(false);
- QString dev_name;
- dev_name.sprintf("HW_%s_BASE", dev_addr.name.c_str());
+ QString dev_name = helper.GetPath(ref);
QLabel *label_names = new QLabel("<b>" + dev_name + "</b>");
label_names->setTextFormat(Qt::RichText);
- QLabel *label_addr = new QLabel("<b>" + QString().sprintf("0x%03x", dev_addr.addr) + "</b>");
+ QLabel *label_addr = new QLabel("<b>" + QString().sprintf("0x%03x", ref.addr()) + "</b>");
label_addr->setTextFormat(Qt::RichText);
QHBoxLayout *top_layout = new QHBoxLayout;
@@ -99,27 +86,38 @@ DevDisplayPanel::DevDisplayPanel(QWidget *parent, const SocDevRef& dev_ref)
m_name = new QLabel(this);
m_name->setTextFormat(Qt::RichText);
- m_name->setText("<h1>" + QString::fromStdString(m_dev.GetDev().long_name) + "</h1>");
-
- m_desc = new QLabel(this);
- m_name->setTextFormat(Qt::RichText);
- m_desc->setText(QString::fromStdString(m_dev.GetDev().desc));
+ /* if instance has a title, it overrides node title.*/
+ std::string title = ref.get()->title;
+ if(title.empty())
+ title = ref.node().get()->title;
+ m_name->setText("<h1>" + QString::fromStdString(title) + "</h1>");
+
+ /* put description from the node and from the instance */
+ m_node_desc = new QLabel(this);
+ m_node_desc->setTextFormat(Qt::RichText);
+ m_node_desc->setText(QString::fromStdString(ref.node().get()->desc));
+ m_node_desc->setVisible(m_node_desc->text().size() != 0);
+ m_inst_desc = new QLabel(this);
+ m_inst_desc->setTextFormat(Qt::RichText);
+ m_inst_desc->setText(QString::fromStdString(ref.get()->desc));
+ m_inst_desc->setVisible(m_inst_desc->text().size() != 0);
right_layout->addWidget(m_name, 0);
right_layout->addLayout(top_layout, 0);
- right_layout->addWidget(m_desc, 0);
+ right_layout->addWidget(m_node_desc, 0);
+ right_layout->addWidget(m_inst_desc, 0);
right_layout->addStretch(1);
setTitle("Device Description");
setLayout(right_layout);
}
-void DevDisplayPanel::AllowWrite(bool en)
+void NodeDisplayPanel::AllowWrite(bool en)
{
Q_UNUSED(en);
}
-QWidget *DevDisplayPanel::GetWidget()
+QWidget *NodeDisplayPanel::GetWidget()
{
return this;
}
@@ -128,34 +126,29 @@ QWidget *DevDisplayPanel::GetWidget()
* RegDisplayPanel
*/
-RegDisplayPanel::RegDisplayPanel(QWidget *parent, IoBackend *io_backend, const SocRegRef& reg_ref)
- :QGroupBox(parent), m_io_backend(io_backend), m_reg(reg_ref), m_reg_font(font())
+RegDisplayPanel::RegDisplayPanel(QWidget *parent, IoBackend *io_backend,
+ const soc_desc::node_inst_t& ref)
+ :QGroupBox(parent), m_io_backend(io_backend), m_node(ref), m_reg_font(font())
{
bool read_only = m_io_backend->IsReadOnly();
+ BackendHelper helper(m_io_backend, ref.soc());
QVBoxLayout *right_layout = new QVBoxLayout;
- const soc_dev_addr_t& dev_addr = m_reg.GetDevAddr();
- const soc_reg_t& reg = m_reg.GetReg();
- const soc_reg_addr_t& reg_addr = m_reg.GetRegAddr();
-
m_reg_font.setWeight(100);
m_reg_font.setKerning(false);
- QString reg_name;
- reg_name.sprintf("HW_%s_%s", dev_addr.name.c_str(), reg_addr.name.c_str());
+ QString reg_name = helper.GetPath(ref);
QStringList names;
QVector< soc_addr_t > addresses;
names.append(reg_name);
- addresses.append(reg_addr.addr);
- if(reg.flags & REG_HAS_SCT)
+ addresses.append(ref.addr());
+
+ std::vector< soc_desc::variant_ref_t > variants = ref.node().reg().variants();
+ for(size_t i = 0; i < variants.size(); i++)
{
- names.append(reg_name + "_SET");
- names.append(reg_name + "_CLR");
- names.append(reg_name + "_TOG");
- addresses.append(reg_addr.addr + 4);
- addresses.append(reg_addr.addr + 8);
- addresses.append(reg_addr.addr + 12);
+ names.append(reg_name + "/" + QString::fromStdString(variants[i].get()->type));
+ addresses.append(ref.addr() + variants[i].get()->offset);
}
QString str;
@@ -188,7 +181,7 @@ RegDisplayPanel::RegDisplayPanel(QWidget *parent, IoBackend *io_backend, const S
m_raw_val_edit->SetReadOnly(read_only);
m_raw_val_edit->GetLineEdit()->setAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
m_raw_val_edit->GetLineEdit()->setValidator(new SocFieldValidator(m_raw_val_edit));
- m_raw_val_edit->EnableSCT(!!(reg.flags & REG_HAS_SCT));
+ //m_raw_val_edit->EnableSCT(!!(reg.flags & REG_HAS_SCT));
m_raw_val_edit->GetLineEdit()->setFont(m_reg_font);
QHBoxLayout *raw_val_layout = new QHBoxLayout;
raw_val_layout->addStretch();
@@ -198,9 +191,13 @@ RegDisplayPanel::RegDisplayPanel(QWidget *parent, IoBackend *io_backend, const S
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->SetRegister(*m_node.node().reg().get());
m_value_model->SetReadOnly(read_only);
- m_value_table->setModel(m_value_model);
+ RegFieldProxyModel *proxy_model = new RegFieldProxyModel(this);
+ proxy_model->setSourceModel(m_value_model);
+ m_value_table->setModel(proxy_model);
+ m_value_table->setSortingEnabled(true);
+ m_value_table->sortByColumn(0, Qt::DescendingOrder);
m_value_table->verticalHeader()->setVisible(false);
m_value_table->resizeColumnsToContents();
m_value_table->horizontalHeader()->setStretchLastSection(true);
@@ -217,17 +214,36 @@ RegDisplayPanel::RegDisplayPanel(QWidget *parent, IoBackend *io_backend, const S
m_table_delegate->setItemEditorFactory(m_table_edit_factory);
m_value_table->setItemDelegate(m_table_delegate);
- m_sexy_display2 = new Unscroll<RegSexyDisplay2>(this);
+ m_sexy_display2 = new Unscroll<YRegDisplay>(this);
m_sexy_display2->setFont(m_reg_font);
m_sexy_display2->setModel(m_value_model);
+ m_sexy_display2->setWidth(m_node.node().reg().get()->width);
m_sexy_display2->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
+ m_name = new QLabel(this);
+ m_name->setTextFormat(Qt::RichText);
+ m_name->setText("<h1>" + QString::fromStdString(ref.node().get()->title) + "</h1>");
+
+ /* put description from the node, from the instance and register */
+ m_node_desc = new QLabel(this);
+ m_node_desc->setTextFormat(Qt::RichText);
+ m_node_desc->setText(QString::fromStdString(ref.node().get()->desc));
+ m_node_desc->setVisible(m_node_desc->text().size() != 0);
+ m_inst_desc = new QLabel(this);
+ m_inst_desc->setTextFormat(Qt::RichText);
+ m_inst_desc->setText(QString::fromStdString(ref.get()->desc));
+ m_inst_desc->setVisible(m_inst_desc->text().size() != 0);
m_desc = new QLabel(this);
m_desc->setTextFormat(Qt::RichText);
- m_desc->setText(QString::fromStdString(m_reg.GetReg().desc));
+ m_desc->setText(QString::fromStdString(m_node.node().reg().get()->desc));
+ m_desc->setVisible(m_desc->text().size() != 0);
+ right_layout->addWidget(m_name);
right_layout->addWidget(m_desc);
right_layout->addLayout(top_layout);
+ right_layout->addWidget(m_node_desc);
+ right_layout->addWidget(m_inst_desc);
+ right_layout->addWidget(m_desc);
if(raw_val_layout)
right_layout->addLayout(raw_val_layout);
right_layout->addWidget(m_sexy_display2);
@@ -252,8 +268,10 @@ RegDisplayPanel::RegDisplayPanel(QWidget *parent, IoBackend *io_backend, const S
connect(m_raw_val_edit->GetLineEdit(), SIGNAL(returnPressed()), this,
SLOT(OnRawRegValueReturnPressed()));
- connect(m_value_table->model(), SIGNAL(OnValueModified(int)), this,
+ connect(m_value_model, SIGNAL(OnValueModified(int)), this,
SLOT(OnRegValueChanged(int)));
+ connect(m_sexy_display2, SIGNAL(clicked(const QModelIndex&)), this,
+ SLOT(OnRegFieldActivated(const QModelIndex&)));
}
RegDisplayPanel::~RegDisplayPanel()
@@ -263,12 +281,9 @@ RegDisplayPanel::~RegDisplayPanel()
void RegDisplayPanel::Reload()
{
- const soc_dev_addr_t& dev_addr = m_reg.GetDevAddr();
- const soc_reg_t& reg = m_reg.GetReg();
- const soc_reg_addr_t& reg_addr = m_reg.GetRegAddr();
soc_word_t value;
- BackendHelper helper(m_io_backend, m_reg);
- bool has_value = helper.ReadRegister(dev_addr.name.c_str(), reg_addr.name.c_str(), value);
+ BackendHelper helper(m_io_backend, m_node.soc());
+ bool has_value = helper.ReadRegister(m_node, value);
if(has_value)
{
@@ -296,7 +311,6 @@ void RegDisplayPanel::AllowWrite(bool en)
m_raw_val_edit->SetReadOnly(m_io_backend->IsReadOnly() || !m_allow_write);
m_value_model->SetReadOnly(m_io_backend->IsReadOnly() || !m_allow_write);
}
- Reload();
}
IoBackend::WriteMode RegDisplayPanel::EditModeToWriteMode(RegLineEdit::EditMode mode)
@@ -320,9 +334,8 @@ void RegDisplayPanel::OnRawRegValueReturnPressed()
if(state != QValidator::Acceptable)
return;
IoBackend::WriteMode mode = EditModeToWriteMode(m_raw_val_edit->GetMode());
- BackendHelper helper(m_io_backend, m_reg);
- helper.WriteRegister(m_reg.GetDevAddr().name.c_str(), m_reg.GetRegAddr().name.c_str(),
- val, mode);
+ BackendHelper helper(m_io_backend, m_node.soc());
+ helper.WriteRegister(m_node, val, mode);
// register write can change all fields
Reload();
}
@@ -332,13 +345,17 @@ void RegDisplayPanel::OnRegValueChanged(int index)
QVariant var = m_value_model->GetValue(index);
if(!var.isValid())
return;
- BackendHelper helper(m_io_backend, m_reg);
- helper.WriteRegister(m_reg.GetDevAddr().name.c_str(), m_reg.GetRegAddr().name.c_str(),
- var.value< soc_word_t >(), IoBackend::Write);
+ BackendHelper helper(m_io_backend, m_node.soc());
+ helper.WriteRegister(m_node, var.value< soc_word_t >(), IoBackend::Write);
// register write can change all fields
Reload();
}
+void RegDisplayPanel::OnRegFieldActivated(const QModelIndex& index)
+{
+ Q_UNUSED(index);
+}
+
QWidget *RegDisplayPanel::GetWidget()
{
return this;