예제 #1
0
void RegEditPanel::OnFormulaChanged(int index)
{
    if(index == -1)
        return;
    m_ref.GetReg().formula.type = static_cast< soc_reg_formula_type_t >(m_formula_combo->itemData(index).toInt());
    UpdateFormula();
    emit OnModified(true);
}
예제 #2
0
RegEditPanel::RegEditPanel(SocRegRef ref, QWidget *parent)
    :QWidget(parent), m_ref(ref), m_reg_font(font())
{
    m_reg_font.setWeight(100);
    m_reg_font.setKerning(false);

    m_name_group = new QGroupBox("Name", this);
    m_name_edit = new QLineEdit(this);
    m_name_edit->setText(QString::fromStdString(ref.GetReg().name));
    QVBoxLayout *name_group_layout = new QVBoxLayout;
    name_group_layout->addWidget(m_name_edit);
    m_name_group->setLayout(name_group_layout);

    m_instances_table = new QTableWidget(this);
    m_instances_table->setRowCount(ref.GetReg().addr.size() + 1);
    m_instances_table->setColumnCount(RegInstNrColumns);
    for(size_t row = 0; row < ref.GetReg().addr.size(); row++)
        FillRow(row, ref.GetReg().addr[row]);
    CreateNewAddrRow(ref.GetReg().addr.size());
    m_instances_table->setHorizontalHeaderItem(RegInstIconColumn, new QTableWidgetItem(""));
    m_instances_table->setHorizontalHeaderItem(RegInstNameColumn, new QTableWidgetItem("Name"));
    m_instances_table->setHorizontalHeaderItem(RegInstAddrColumn, new QTableWidgetItem("Address"));
    m_instances_table->verticalHeader()->setVisible(false);
    m_instances_table->resizeColumnsToContents();
    m_instances_table->horizontalHeader()->setStretchLastSection(true);
    m_instances_table->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum);
    m_instances_group = new QGroupBox("Instances", this);
    QHBoxLayout *instances_group_layout = new QHBoxLayout;
    instances_group_layout->addWidget(m_instances_table);
    m_instances_group->setLayout(instances_group_layout);

    m_desc_group = new QGroupBox("Description", this);
    QHBoxLayout *group_layout = new QHBoxLayout;
    m_desc_edit = new MyTextEditor(this);
    m_desc_edit->SetTextHtml(QString::fromStdString(ref.GetReg().desc));
    group_layout->addWidget(m_desc_edit);
    m_desc_group->setLayout(group_layout);

    bool has_sct = m_ref.GetReg().flags & REG_HAS_SCT;
    m_sct_check = new QCheckBox("Set/Clear/Toggle", this);
    m_sct_check->setCheckState(has_sct ? Qt::Checked : Qt::Unchecked);
    QHBoxLayout *flags_layout = new QHBoxLayout;
    flags_layout->addWidget(m_sct_check);
    flags_layout->addStretch();
    m_flags_group = new QGroupBox("Flags", this);
    m_flags_group->setLayout(flags_layout);

    m_formula_combo = new QComboBox(this);
    m_formula_combo->addItem("None", QVariant(REG_FORMULA_NONE));
    m_formula_combo->addItem("String", QVariant(REG_FORMULA_STRING));
    m_formula_combo->setCurrentIndex(m_formula_combo->findData(QVariant(m_ref.GetReg().formula.type)));
    m_formula_type_label = new QLabel("Type:", this);
    QHBoxLayout *formula_top_layout = new QHBoxLayout;
    formula_top_layout->addWidget(m_formula_type_label);
    formula_top_layout->addWidget(m_formula_combo);
    m_formula_string_edit = new QLineEdit(QString::fromStdString(ref.GetReg().formula.string), this);
    QVBoxLayout *formula_layout = new QVBoxLayout;
    formula_layout->addLayout(formula_top_layout);
    formula_layout->addWidget(m_formula_string_edit);
    m_formula_string_gen = new QPushButton("Generate", this);
    formula_layout->addWidget(m_formula_string_gen);
    m_formula_group = new QGroupBox("Formula", this);
    m_formula_group->setLayout(formula_layout);

    QVBoxLayout *name_layout = new QVBoxLayout;
    name_layout->addWidget(m_name_group);
    name_layout->addWidget(m_flags_group);
    name_layout->addWidget(m_formula_group);
    name_layout->addStretch();

    QHBoxLayout *top_layout = new QHBoxLayout;
    top_layout->addWidget(m_instances_group);
    top_layout->addLayout(name_layout);
    top_layout->addWidget(m_desc_group, 1);

    m_sexy_display = new RegSexyDisplay(m_ref, this);
    m_sexy_display->setFont(m_reg_font);

    m_field_table = new QTableWidget;
    m_field_table->setRowCount(m_ref.GetReg().field.size());
    m_field_table->setColumnCount(4);
    for(size_t row = 0; row < m_ref.GetReg().field.size(); row++)
    {
        const soc_reg_field_t& field = m_ref.GetReg().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_field_table->setItem(row, 1, item);
        item = new QTableWidgetItem(QString(field.name.c_str()));
        item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
        m_field_table->setItem(row, 2, item);
        item = new QTableWidgetItem(QString(field.desc.c_str()));
        item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
        m_field_table->setItem(row, 3, item);
        UpdateWarning(row);
    }
    m_field_table->setHorizontalHeaderItem(0, new QTableWidgetItem(""));
    m_field_table->setHorizontalHeaderItem(1, new QTableWidgetItem("Bits"));
    m_field_table->setHorizontalHeaderItem(2, new QTableWidgetItem("Name"));
    m_field_table->setHorizontalHeaderItem(3, new QTableWidgetItem("Description"));
    m_field_table->verticalHeader()->setVisible(false);
    m_field_table->resizeColumnsToContents();
    m_field_table->horizontalHeader()->setStretchLastSection(true);
    QHBoxLayout *field_layout = new QHBoxLayout;
    field_layout->addWidget(m_field_table);
    m_field_group = new QGroupBox("Flags", this);
    m_field_group->setLayout(field_layout);

    QVBoxLayout *layout = new QVBoxLayout;
    layout->addLayout(top_layout, 0);
    layout->addWidget(m_sexy_display, 0);
    layout->addWidget(m_field_group);

    UpdateFormula();

    setLayout(layout);

    SocFieldItemDelegate *m_table_delegate = new SocFieldItemDelegate(this);
    QItemEditorFactory *m_table_edit_factory = new QItemEditorFactory();
    SocFieldEditorCreator *m_table_edit_creator = new SocFieldEditorCreator();
    m_table_edit_factory->registerEditor(QVariant::UInt, m_table_edit_creator);
    m_table_delegate->setItemEditorFactory(m_table_edit_factory);
    m_instances_table->setItemDelegate(m_table_delegate);

    connect(m_instances_table, SIGNAL(cellActivated(int,int)), this, SLOT(OnInstActivated(int,int)));
    connect(m_instances_table, SIGNAL(cellChanged(int,int)), this, SLOT(OnInstChanged(int,int)));
    connect(m_name_edit, SIGNAL(textChanged(const QString&)), this, SLOT(OnNameEdited(const QString&)));
    connect(m_desc_edit, SIGNAL(OnTextChanged()), this, SLOT(OnDescEdited()));
    connect(m_sct_check, SIGNAL(stateChanged(int)), this, SLOT(OnSctEdited(int)));
    connect(m_formula_combo, SIGNAL(currentIndexChanged(int)), this, SLOT(OnFormulaChanged(int)));
    connect(m_formula_string_edit, SIGNAL(textChanged(const QString&)), this, 
        SLOT(OnFormulaStringChanged(const QString&)));
    connect(m_formula_string_gen, SIGNAL(clicked(bool)), this, SLOT(OnFormulaGenerate(bool)));
}
예제 #3
0
RegEditPanel::RegEditPanel(SocRegRef ref, QWidget *parent)
    :QWidget(parent), m_ref(ref), m_reg_font(font())
{
    m_reg_font.setWeight(100);
    m_reg_font.setKerning(false);

    m_name_group = new QGroupBox("Name", this);
    m_name_edit = new QLineEdit(this);
    m_name_edit->setText(QString::fromStdString(ref.GetReg().name));
    QVBoxLayout *name_group_layout = new QVBoxLayout;
    name_group_layout->addWidget(m_name_edit);
    m_name_group->setLayout(name_group_layout);

    m_instances_table = new QTableWidget(this);
    m_instances_table->setRowCount(ref.GetReg().addr.size() + 1);
    m_instances_table->setColumnCount(RegInstNrColumns);
    for(size_t row = 0; row < ref.GetReg().addr.size(); row++)
        FillRow(row, ref.GetReg().addr[row]);
    CreateNewAddrRow(ref.GetReg().addr.size());
    m_instances_table->setHorizontalHeaderItem(RegInstIconColumn, new QTableWidgetItem(""));
    m_instances_table->setHorizontalHeaderItem(RegInstNameColumn, new QTableWidgetItem("Name"));
    m_instances_table->setHorizontalHeaderItem(RegInstAddrColumn, new QTableWidgetItem("Address"));
    m_instances_table->verticalHeader()->setVisible(false);
    m_instances_table->resizeColumnsToContents();
    m_instances_table->horizontalHeader()->setStretchLastSection(true);
    m_instances_table->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum);
    m_instances_group = new QGroupBox("Instances", this);
    QHBoxLayout *instances_group_layout = new QHBoxLayout;
    instances_group_layout->addWidget(m_instances_table);
    m_instances_group->setLayout(instances_group_layout);

    m_desc_group = new QGroupBox("Description", this);
    QHBoxLayout *group_layout = new QHBoxLayout;
    m_desc_edit = new MyTextEditor(this);
    m_desc_edit->SetTextHtml(QString::fromStdString(ref.GetReg().desc));
    group_layout->addWidget(m_desc_edit);
    m_desc_group->setLayout(group_layout);

    bool has_sct = m_ref.GetReg().flags & REG_HAS_SCT;
    m_sct_check = new QCheckBox("Set/Clear/Toggle", this);
    m_sct_check->setCheckState(has_sct ? Qt::Checked : Qt::Unchecked);
    QHBoxLayout *flags_layout = new QHBoxLayout;
    flags_layout->addWidget(m_sct_check);
    flags_layout->addStretch();
    m_flags_group = new QGroupBox("Flags", this);
    m_flags_group->setLayout(flags_layout);

    m_formula_combo = new QComboBox(this);
    m_formula_combo->addItem("None", QVariant(REG_FORMULA_NONE));
    m_formula_combo->addItem("String", QVariant(REG_FORMULA_STRING));
    m_formula_combo->setCurrentIndex(m_formula_combo->findData(QVariant(m_ref.GetReg().formula.type)));
    m_formula_type_label = new QLabel("Type:", this);
    QHBoxLayout *formula_top_layout = new QHBoxLayout;
    formula_top_layout->addWidget(m_formula_type_label);
    formula_top_layout->addWidget(m_formula_combo);
    m_formula_string_edit = new QLineEdit(QString::fromStdString(ref.GetReg().formula.string), this);
    QVBoxLayout *formula_layout = new QVBoxLayout;
    formula_layout->addLayout(formula_top_layout);
    formula_layout->addWidget(m_formula_string_edit);
    m_formula_string_gen = new QPushButton("Generate", this);
    formula_layout->addWidget(m_formula_string_gen);
    m_formula_group = new QGroupBox("Formula", this);
    m_formula_group->setLayout(formula_layout);

    QVBoxLayout *name_layout = new QVBoxLayout;
    name_layout->addWidget(m_name_group);
    name_layout->addWidget(m_flags_group);
    name_layout->addWidget(m_formula_group);
    name_layout->addStretch();

    QHBoxLayout *top_layout = new QHBoxLayout;
    top_layout->addWidget(m_instances_group);
    top_layout->addLayout(name_layout);
    top_layout->addWidget(m_desc_group, 1);

    m_value_table = new QTableView(this);
    m_value_model = new RegFieldTableModel(m_value_table); // view takes ownership
    m_value_model->SetRegister(m_ref.GetReg());
    m_value_model->SetReadOnly(true);
    m_value_table->setModel(m_value_model);
    m_value_table->verticalHeader()->setVisible(false);
    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 ?
    m_table_delegate = new SocFieldCachedItemDelegate(this);
    m_value_table->setItemDelegate(m_table_delegate);
    m_value_table->resizeColumnsToContents();

    m_sexy_display2 = new Unscroll<RegSexyDisplay2>(this);
    m_sexy_display2->setFont(m_reg_font);
    m_sexy_display2->setModel(m_value_model);
    m_sexy_display2->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);

    QHBoxLayout *field_layout = new QHBoxLayout;
    field_layout->addWidget(m_value_table);
    m_field_group = new QGroupBox("Flags", this);
    m_field_group->setLayout(field_layout);

    QVBoxLayout *layout = new QVBoxLayout;
    layout->addLayout(top_layout, 0);
    layout->addWidget(m_sexy_display2, 0);
    layout->addWidget(m_field_group);

    UpdateFormula();

    setLayout(layout);

    SocFieldItemDelegate *m_table_delegate = new SocFieldItemDelegate(this);
    QItemEditorFactory *m_table_edit_factory = new QItemEditorFactory();
    SocFieldEditorCreator *m_table_edit_creator = new SocFieldEditorCreator();
    m_table_edit_factory->registerEditor(QVariant::UInt, m_table_edit_creator);
    m_table_delegate->setItemEditorFactory(m_table_edit_factory);
    m_instances_table->setItemDelegate(m_table_delegate);

    connect(m_instances_table, SIGNAL(cellActivated(int,int)), this, SLOT(OnInstActivated(int,int)));
    connect(m_instances_table, SIGNAL(cellChanged(int,int)), this, SLOT(OnInstChanged(int,int)));
    connect(m_name_edit, SIGNAL(textChanged(const QString&)), this, SLOT(OnNameEdited(const QString&)));
    connect(m_desc_edit, SIGNAL(OnTextChanged()), this, SLOT(OnDescEdited()));
    connect(m_sct_check, SIGNAL(stateChanged(int)), this, SLOT(OnSctEdited(int)));
    connect(m_formula_combo, SIGNAL(currentIndexChanged(int)), this, SLOT(OnFormulaChanged(int)));
    connect(m_formula_string_edit, SIGNAL(textChanged(const QString&)), this, 
        SLOT(OnFormulaStringChanged(const QString&)));
    connect(m_formula_string_gen, SIGNAL(clicked(bool)), this, SLOT(OnFormulaGenerate(bool)));
}