Skip to content

Commit

Permalink
Connect signals/slots so that ISA filters work properly
Browse files Browse the repository at this point in the history
  • Loading branch information
raccog committed Feb 27, 2024
1 parent 342722e commit fb22184
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 10 deletions.
59 changes: 53 additions & 6 deletions src/sliderulestab.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,11 +100,30 @@ const ISAInfoBase *ISAInstructionsModel::isaInfo() const {
return m_isaInfo.get();
}

const ISAInfoBase *ISAInstructionsModel::prevISAInfo() const {
return m_prevIsaInfo.get();
}

void ISAInstructionsModel::changeISAFamily(ISAFamily isaFamily) {
if (m_isaInfo->isaFamily() != isaFamily) {
changeISAInfo(*ISAInfoRegistry::getISA(*ISAFamilySets.at(isaFamily).begin(),
QStringList()));
}
}

void ISAInstructionsModel::changeISA(ISA isa) {
if (m_isaInfo->isaID() != isa) {
changeISAInfo(*ISAInfoRegistry::getISA(isa, QStringList()));
}
}

void ISAInstructionsModel::changeISAInfo(const ISAInfoBase &isaInfo) {
if (!m_isaInfo || !m_isaInfo->eq(&isaInfo, isaInfo.enabledExtensions())) {
beginResetModel();
m_isaInfo =
auto newIsaInfo =
ISAInfoRegistry::getISA(isaInfo.isaID(), isaInfo.enabledExtensions());
m_prevIsaInfo = m_isaInfo ? m_isaInfo : newIsaInfo;
m_isaInfo = newIsaInfo;
m_instrItems.clear();
for (const auto &instr : m_isaInfo->instructions()) {
m_instrItems.push_back(std::make_unique<InstructionItem>(*instr));
Expand Down Expand Up @@ -135,11 +154,7 @@ SliderulesTab::SliderulesTab(QToolBar *toolbar, QWidget *parent)
isaFamilyBox->setCurrentIndex(
isaFamilyBox->findData(QVariant(static_cast<int>(isaInfo.isaFamily()))));

isaBox->clear();
for (const auto &isa : ISAFamilySets.at(isaInfo.isaFamily())) {
isaBox->addItem(ISANames.at(isa), QVariant(static_cast<int>(isa)));
}

resetISAFilter(isaInfo);
isaBox->setCurrentIndex(
isaBox->findData(QVariant(static_cast<int>(isaInfo.isaID()))));

Expand All @@ -153,11 +168,43 @@ SliderulesTab::SliderulesTab(QToolBar *toolbar, QWidget *parent)
baseExtCheckBox->setChecked(true);
baseExtCheckBox->setEnabled(false);

// Update model when the processor is changed
connect(ProcessorHandler::get(), &ProcessorHandler::processorChanged,
m_isaModel.get(),
[=] { m_isaModel->changeISAInfo(*ProcessorHandler::currentISA()); });

// Update model when user changes the filters
connect(isaFamilyBox, &QComboBox::activated, m_isaModel.get(), [=] {
m_isaModel->changeISAFamily(
static_cast<ISAFamily>(isaFamilyBox->currentData().toInt()));
});
connect(isaBox, &QComboBox::activated, m_isaModel.get(), [=] {
m_isaModel->changeISA(static_cast<ISA>(isaBox->currentData().toInt()));
});

// Update UI when model updates
connect(m_isaModel.get(), &ISAInstructionsModel::isaInfoChanged, isaFamilyBox,
[=](const ISAInfoBase &isaInfo) {
isaFamilyBox->setCurrentIndex(isaFamilyBox->findData(
QVariant(static_cast<int>(isaInfo.isaFamily()))));
});
connect(m_isaModel.get(), &ISAInstructionsModel::isaInfoChanged, isaBox,
[=](const ISAInfoBase &isaInfo) {
if (isaInfo.isaFamily() != m_isaModel->prevISAInfo()->isaFamily()) {
resetISAFilter(isaInfo);
}
isaBox->setCurrentIndex(
isaBox->findData(QVariant(static_cast<int>(isaInfo.isaID()))));
});
}

SliderulesTab::~SliderulesTab() { delete ui; }

void SliderulesTab::resetISAFilter(const ISAInfoBase &isaInfo) {
isaBox->clear();
for (const auto &isa : ISAFamilySets.at(isaInfo.isaFamily())) {
isaBox->addItem(ISANames.at(isa), QVariant(static_cast<int>(isa)));
}
}

} // namespace Ripes
10 changes: 6 additions & 4 deletions src/sliderulestab.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,19 +54,19 @@ class ISAInstructionsModel : public QAbstractItemModel {
virtual QModelIndex parent(const QModelIndex &index) const override;

const ISAInfoBase *isaInfo() const;
// const ISAInfoBase *prevISAInfo() const;
const ISAInfoBase *prevISAInfo() const;

signals:
void isaInfoChanged(const ISAInfoBase &isaInfo);

public slots:
// void changeISAFamily(ISAFamily isaFamily);
// void changeISA(ISA isa);
void changeISAFamily(ISAFamily isaFamily);
void changeISA(ISA isa);
void changeISAInfo(const ISAInfoBase &isaInfo);

protected:
std::shared_ptr<const ISAInfoBase> m_isaInfo = nullptr;
// std::shared_ptr<const ISAInfoBase> m_prevIsaInfo = nullptr;
std::shared_ptr<const ISAInfoBase> m_prevIsaInfo = nullptr;

std::vector<std::unique_ptr<InstructionItem>> m_instrItems;
};
Expand All @@ -81,6 +81,8 @@ public slots:
// void updateView(const ISAInfoBase &isaInfo);

private:
void resetISAFilter(const ISAInfoBase &isaInfo);

Ui::SliderulesTab *ui = nullptr;

QComboBox *isaFamilyBox = nullptr;
Expand Down

0 comments on commit fb22184

Please sign in to comment.