From 02edd66ae9494e0323e618747eeb0d38f0df75d4 Mon Sep 17 00:00:00 2001 From: Miodrag Milanovic Date: Mon, 29 Oct 2018 19:39:52 +0100 Subject: Changes to cover issues from code review --- gui/designwidget.cc | 50 ++++++++++++++++++++++++-------------------------- gui/designwidget.h | 1 + 2 files changed, 25 insertions(+), 26 deletions(-) diff --git a/gui/designwidget.cc b/gui/designwidget.cc index 29e9ed0c..daeea19d 100644 --- a/gui/designwidget.cc +++ b/gui/designwidget.cc @@ -289,7 +289,7 @@ void DesignWidget::newContext(Context *ctx) std::lock_guard lock(ctx->mutex); { - std::map, std::vector> belMap; + TreeModel::ElementXYRoot::ElementMap belMap; for (auto bel : ctx->getBels()) { auto loc = ctx->getBelLocation(bel); belMap[std::pair(loc.x, loc.y)].push_back(bel); @@ -303,7 +303,7 @@ void DesignWidget::newContext(Context *ctx) #ifdef ARCH_ICE40 { - std::map, std::vector> wireMap; + TreeModel::ElementXYRoot::ElementMap wireMap; for (int i = 0; i < ctx->chip_info->num_wires; i++) { const auto wire = &ctx->chip_info->wire_data[i]; WireId wireid; @@ -317,7 +317,7 @@ void DesignWidget::newContext(Context *ctx) } { - std::map, std::vector> pipMap; + TreeModel::ElementXYRoot::ElementMap pipMap; for (int i = 0; i < ctx->chip_info->num_pips; i++) { const auto pip = &ctx->chip_info->pip_data[i]; PipId pipid; @@ -453,6 +453,8 @@ int DesignWidget::getIndexByElementType(ElementType type) return 3; if (type == ElementType::CELL) return 4; + if (type == ElementType::GROUP) + return 5; return -1; } void DesignWidget::addProperty(QtProperty *topItem, int propertyType, const QString &name, QVariant value, @@ -473,6 +475,12 @@ QtProperty *DesignWidget::addSubGroup(QtProperty *topItem, const QString &name) return item; } +void DesignWidget::clearAllSelectionModels() +{ + for (int i = 0; i <= getIndexByElementType(ElementType::GROUP); i++) + selectionModel[i]->clearSelection(); +} + void DesignWidget::onClickedBel(BelId bel, bool keep) { boost::optional item; @@ -488,15 +496,12 @@ void DesignWidget::onClickedBel(BelId bel, bool keep) } int index = getIndexByElementType(ElementType::BEL); if (!keep) - { - for(int i=0;i<6;i++) - selectionModel[i]->clearSelection(); - } - if (tabWidget->currentIndex() != index) { + clearAllSelectionModels(); + if (tabWidget->currentIndex() != index) { tabWidget->setCurrentIndex(index); } selectionModel[index]->setCurrentIndex(getTreeByElementType(ElementType::BEL)->indexFromNode(*item), - keep ? QItemSelectionModel::Select : QItemSelectionModel::ClearAndSelect); + keep ? QItemSelectionModel::Select : QItemSelectionModel::ClearAndSelect); } void DesignWidget::onClickedWire(WireId wire, bool keep) @@ -512,16 +517,13 @@ void DesignWidget::onClickedWire(WireId wire, bool keep) Q_EMIT selected(getDecals(ElementType::WIRE, ctx->getWireName(wire)), keep); } - int index = getIndexByElementType(ElementType::WIRE); + int index = getIndexByElementType(ElementType::WIRE); if (!keep) - { - for(int i=0;i<6;i++) - selectionModel[i]->clearSelection(); - } + clearAllSelectionModels(); if (tabWidget->currentIndex() != index) tabWidget->setCurrentIndex(index); selectionModel[index]->setCurrentIndex(getTreeByElementType(ElementType::WIRE)->indexFromNode(*item), - keep ? QItemSelectionModel::Select : QItemSelectionModel::ClearAndSelect); + keep ? QItemSelectionModel::Select : QItemSelectionModel::ClearAndSelect); } void DesignWidget::onClickedPip(PipId pip, bool keep) @@ -537,24 +539,21 @@ void DesignWidget::onClickedPip(PipId pip, bool keep) Q_EMIT selected(getDecals(ElementType::PIP, ctx->getPipName(pip)), keep); } - + int index = getIndexByElementType(ElementType::PIP); if (!keep) - { - for(int i=0;i<6;i++) - selectionModel[i]->clearSelection(); - } + clearAllSelectionModels(); if (tabWidget->currentIndex() != index) tabWidget->setCurrentIndex(index); selectionModel[index]->setCurrentIndex(getTreeByElementType(ElementType::PIP)->indexFromNode(*item), - keep ? QItemSelectionModel::Select : QItemSelectionModel::ClearAndSelect); + keep ? QItemSelectionModel::Select : QItemSelectionModel::ClearAndSelect); } void DesignWidget::onSelectionChanged(int num, const QItemSelection &, const QItemSelection &) { int num_selected = 0; std::vector decals; - for(int i=0;i<6;i++) { + for (int i = 0; i <= getIndexByElementType(ElementType::GROUP); i++) { num_selected += selectionModel[i]->selectedIndexes().size(); for (auto index : selectionModel[i]->selectedIndexes()) { TreeModel::Item *item = treeModel[i]->nodeFromIndex(index); @@ -562,7 +561,7 @@ void DesignWidget::onSelectionChanged(int num, const QItemSelection &, const QIt std::move(d.begin(), d.end(), std::back_inserter(decals)); } } - if (num_selected>1 || (selectionModel[num]->selectedIndexes().size() == 0)) { + if (num_selected > 1 || (selectionModel[num]->selectedIndexes().size() == 0)) { Q_EMIT selected(decals, false); return; } @@ -931,7 +930,7 @@ void DesignWidget::prepareMenuTree(int num, const QPoint &pos) return; QList items; - for(int i=0;i<6;i++) { + for (int i = 0; i <= getIndexByElementType(ElementType::GROUP); i++) { for (auto index : selectionModel[i]->selectedIndexes()) { TreeModel::Item *item = treeModel[i]->nodeFromIndex(index); items.append(item); @@ -969,8 +968,7 @@ void DesignWidget::onItemDoubleClicked(QTreeWidgetItem *item, int column) auto it = getTreeByElementType(type)->nodeForId(ctx->id(selectedProperty->valueText().toStdString())); if (it) { int num = getIndexByElementType(type); - for(int i=0;i<6;i++) - selectionModel[i]->clearSelection(); + clearAllSelectionModels(); if (tabWidget->currentIndex() != num) tabWidget->setCurrentIndex(num); selectionModel[num]->setCurrentIndex(getTreeByElementType(type)->indexFromNode(*it), diff --git a/gui/designwidget.h b/gui/designwidget.h index f27eced2..89c6e702 100644 --- a/gui/designwidget.h +++ b/gui/designwidget.h @@ -73,6 +73,7 @@ class DesignWidget : public QWidget void addToHistory(int tab, QModelIndex item); std::vector getDecals(ElementType type, IdString value); void updateHighlightGroup(QList item, int group); + void clearAllSelectionModels(); Q_SIGNALS: void selected(std::vector decal, bool keep); void highlight(std::vector decal, int group); -- cgit v1.2.3