From ab31c6544f88afec62f84c7fe319aa7bed85851d Mon Sep 17 00:00:00 2001 From: Leonardo Zide Date: Sun, 16 Aug 2026 16:39:21 -0700 Subject: [PATCH] Add option to open submodels from the parts picker. Fixes #1031. --- common/lc_partselectionpopup.cpp | 2 ++ common/lc_partselectionwidget.cpp | 22 ++++++++++++++++++++-- common/lc_partselectionwidget.h | 12 ++++++++++++ 3 files changed, 34 insertions(+), 2 deletions(-) diff --git a/common/lc_partselectionpopup.cpp b/common/lc_partselectionpopup.cpp index e4dd61e1..4975935e 100644 --- a/common/lc_partselectionpopup.cpp +++ b/common/lc_partselectionpopup.cpp @@ -60,6 +60,8 @@ std::optional lcShowPartSelectionPopup(PieceInfo* InitialPart, const lcPartSelectionPopup* Popup = new lcPartSelectionPopup(InitialPart, Menu.get()); lcPartSelectionWidget* PartSelectionWidget = Popup->GetPartSelectionWidget(); + PartSelectionWidget->SetIsPopup(true); + if (CustomParts.empty()) { PartSelectionWidget->SetCategory(lcPartCategoryType::AllParts, 0); diff --git a/common/lc_partselectionwidget.cpp b/common/lc_partselectionwidget.cpp index ef8e242e..3f65ebf7 100644 --- a/common/lc_partselectionwidget.cpp +++ b/common/lc_partselectionwidget.cpp @@ -561,7 +561,7 @@ void lcPartSelectionListView::DoubleClicked(const QModelIndex& Index) void lcPartSelectionListView::CustomContextMenuRequested(QPoint Pos) { - if (!mPartSelectionWidget) + if (!mPartSelectionWidget || mPartSelectionWidget->GetIsPopup()) return; QMenu* Menu = new QMenu(this); @@ -587,6 +587,12 @@ void lcPartSelectionListView::CustomContextMenuRequested(QPoint Pos) QAction* RemoveAction = Menu->addAction(tr("Remove from Palette"), mPartSelectionWidget, &lcPartSelectionWidget::RemoveFromPalette); RemoveAction->setEnabled(mCategoryType == lcPartCategoryType::Palette); + if (mContextInfo && mContextInfo->IsModel()) + { + Menu->addSeparator(); + Menu->addAction(tr("Open Submodel"), mPartSelectionWidget, &lcPartSelectionWidget::OpenSubmodel); + } + Menu->exec(viewport()->mapToGlobal(Pos)); delete Menu; } @@ -1150,7 +1156,7 @@ void lcPartSelectionWidget::OptionsMenuAboutToShow() QMenu* Menu = (QMenu*)sender(); Menu->clear(); - Menu->addAction(tr("Edit Palettes..."), this, &lcPartSelectionWidget::EditPartPalettes); + Menu->addAction(tr("Edit Palettes..."), this, &lcPartSelectionWidget::EditPartPalettes)->setEnabled(!mIsPopup); Menu->addSeparator(); @@ -1378,6 +1384,18 @@ void lcPartSelectionWidget::RemoveFromPalette() } } +void lcPartSelectionWidget::OpenSubmodel() +{ + PieceInfo* Info = mPartsWidget->GetContextInfo(); + + if (!Info || !Info->IsModel()) + return; + + lcModel* Model = Info->GetModel(); + + lcGetActiveProject()->SetActiveModel(Model, true); +} + void lcPartSelectionWidget::UpdateInUseCategory() { mPartsWidget->UpdateInUseCategory(); diff --git a/common/lc_partselectionwidget.h b/common/lc_partselectionwidget.h index 1d07a586..df4d1be7 100644 --- a/common/lc_partselectionwidget.h +++ b/common/lc_partselectionwidget.h @@ -278,6 +278,16 @@ public: void SetCategory(lcPartCategoryType Type, int Index); void SetCustomParts(const std::vector>& Parts, int ColorIndex); + bool GetIsPopup() const + { + return mIsPopup; + } + + void SetIsPopup(bool IsPopup) + { + mIsPopup = IsPopup; + } + int GetColorIndex() const { return mPartsWidget->GetListModel()->GetColorIndex(); @@ -316,6 +326,7 @@ signals: public slots: void AddToPalette(); void RemoveFromPalette(); + void OpenSubmodel(); void DockLocationChanged(Qt::DockWidgetArea Area); protected slots: @@ -347,4 +358,5 @@ protected: QSplitter* mSplitter = nullptr; QTreeWidgetItem* mAllPartsCategoryItem = nullptr; std::vector mPartPalettes; + bool mIsPopup = false; };