Skip to content

Commit

Permalink
Update extension filters when model changes
Browse files Browse the repository at this point in the history
  • Loading branch information
raccog committed Feb 27, 2024
1 parent fb22184 commit 453a2e9
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 10 deletions.
38 changes: 29 additions & 9 deletions src/sliderulestab.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -158,15 +158,7 @@ SliderulesTab::SliderulesTab(QToolBar *toolbar, QWidget *parent)
isaBox->setCurrentIndex(
isaBox->findData(QVariant(static_cast<int>(isaInfo.isaID()))));

mainExtBox->clear();
for (const auto &ext :
QStringList(isaInfo.baseExtension()) + isaInfo.supportedExtensions()) {
mainExtBox->addItem(ext, ext);
}

baseExtCheckBox->setText(isaInfo.baseExtension());
baseExtCheckBox->setChecked(true);
baseExtCheckBox->setEnabled(false);
resetExtensionFilters(isaInfo);

// Update model when the processor is changed
connect(ProcessorHandler::get(), &ProcessorHandler::processorChanged,
Expand Down Expand Up @@ -196,6 +188,12 @@ SliderulesTab::SliderulesTab(QToolBar *toolbar, QWidget *parent)
isaBox->setCurrentIndex(
isaBox->findData(QVariant(static_cast<int>(isaInfo.isaID()))));
});
connect(m_isaModel.get(), &ISAInstructionsModel::isaInfoChanged, this,
[=](const ISAInfoBase &isaInfo) {
if (isaInfo.isaID() != m_isaModel->prevISAInfo()->isaID()) {
resetExtensionFilters(isaInfo);
}
});
}

SliderulesTab::~SliderulesTab() { delete ui; }
Expand All @@ -207,4 +205,26 @@ void SliderulesTab::resetISAFilter(const ISAInfoBase &isaInfo) {
}
}

void SliderulesTab::resetExtensionFilters(const ISAInfoBase &isaInfo) {
mainExtBox->clear();
for (const auto &ext :
QStringList(isaInfo.baseExtension()) + isaInfo.supportedExtensions()) {
mainExtBox->addItem(ext, ext);
}

QLayoutItem *child;
while ((child = ui->enabledExtGrid->takeAt(1)) != nullptr) {
delete child->widget();
delete child;
}
for (const auto &ext : isaInfo.supportedExtensions()) {
auto count = ui->enabledExtGrid->count();
ui->enabledExtGrid->addWidget(new QCheckBox(ext), count % 2, count / 2);
}

baseExtCheckBox->setText(isaInfo.baseExtension());
baseExtCheckBox->setChecked(true);
baseExtCheckBox->setEnabled(false);
}

} // namespace Ripes
4 changes: 3 additions & 1 deletion src/sliderulestab.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,11 @@ class SliderulesTab : public RipesTab {
public slots:
// void updateView(const ISAInfoBase &isaInfo);

private:
private slots:
void resetISAFilter(const ISAInfoBase &isaInfo);
void resetExtensionFilters(const ISAInfoBase &isaInfo);

private:
Ui::SliderulesTab *ui = nullptr;

QComboBox *isaFamilyBox = nullptr;
Expand Down

0 comments on commit 453a2e9

Please sign in to comment.