From fb2218486a24f7e2fd57b4f7a03227c79e273b3d Mon Sep 17 00:00:00 2001 From: Ryan Cohen Date: Tue, 27 Feb 2024 13:22:05 -0500 Subject: [PATCH] Connect signals/slots so that ISA filters work properly --- src/sliderulestab.cpp | 59 ++++++++++++++++++++++++++++++++++++++----- src/sliderulestab.h | 10 +++++--- 2 files changed, 59 insertions(+), 10 deletions(-) diff --git a/src/sliderulestab.cpp b/src/sliderulestab.cpp index cf619d4c..91f79749 100644 --- a/src/sliderulestab.cpp +++ b/src/sliderulestab.cpp @@ -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(*instr)); @@ -135,11 +154,7 @@ SliderulesTab::SliderulesTab(QToolBar *toolbar, QWidget *parent) isaFamilyBox->setCurrentIndex( isaFamilyBox->findData(QVariant(static_cast(isaInfo.isaFamily())))); - isaBox->clear(); - for (const auto &isa : ISAFamilySets.at(isaInfo.isaFamily())) { - isaBox->addItem(ISANames.at(isa), QVariant(static_cast(isa))); - } - + resetISAFilter(isaInfo); isaBox->setCurrentIndex( isaBox->findData(QVariant(static_cast(isaInfo.isaID())))); @@ -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(isaFamilyBox->currentData().toInt())); + }); + connect(isaBox, &QComboBox::activated, m_isaModel.get(), [=] { + m_isaModel->changeISA(static_cast(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(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(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(isa))); + } +} + } // namespace Ripes diff --git a/src/sliderulestab.h b/src/sliderulestab.h index f6b51d5c..0b254cf1 100644 --- a/src/sliderulestab.h +++ b/src/sliderulestab.h @@ -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 m_isaInfo = nullptr; - // std::shared_ptr m_prevIsaInfo = nullptr; + std::shared_ptr m_prevIsaInfo = nullptr; std::vector> m_instrItems; }; @@ -81,6 +81,8 @@ public slots: // void updateView(const ISAInfoBase &isaInfo); private: + void resetISAFilter(const ISAInfoBase &isaInfo); + Ui::SliderulesTab *ui = nullptr; QComboBox *isaFamilyBox = nullptr;