From 398c1c898d2c486da5374791b52aaf2dd9210e26 Mon Sep 17 00:00:00 2001 From: mwganson Date: Sat, 4 Sep 2021 13:09:45 -0500 Subject: [PATCH] [Edit menu -> Copy / Duplicate] Add Use Original Selections button to dependency selection dialog --- src/Gui/DlgObjectSelection.cpp | 26 ++++++++++++++++++++++++++ src/Gui/DlgObjectSelection.h | 4 ++++ 2 files changed, 30 insertions(+) diff --git a/src/Gui/DlgObjectSelection.cpp b/src/Gui/DlgObjectSelection.cpp index 1556b310e6..7c194d4a28 100644 --- a/src/Gui/DlgObjectSelection.cpp +++ b/src/Gui/DlgObjectSelection.cpp @@ -22,6 +22,7 @@ #include "PreCompiled.h" #ifndef _PreComp_ # include +# include #endif #include @@ -43,6 +44,12 @@ DlgObjectSelection::DlgObjectSelection( const std::vector &objs, QWidget* parent, Qt::WindowFlags fl) : QDialog(parent, fl), ui(new Ui_DlgObjectSelection) { + /** + * make a copy of the originally selected objects + * so we can return them if the user clicks useOriginalsBtn + */ + this->originalSelections = objs; + ui->setupUi(this); // make sure to show a horizontal scrollbar if needed @@ -97,6 +104,14 @@ DlgObjectSelection::DlgObjectSelection( v.second.inList[obj] = &it->second; } } + /** + * create useOriginalsBtn and add to the button box + * tried adding to .ui file, but could never get the + * formatting exactly the way I wanted it. -- + */ + useOriginalsBtn = new QPushButton(tr("&Use Original Selections")); + useOriginalsBtn->setToolTip(tr("Ignore dependencies and proceed with objects\noriginally selected prior to opening this dialog")); + ui->buttonBox->addButton(useOriginalsBtn,QDialogButtonBox::ActionRole); connect(ui->treeWidget, SIGNAL(itemExpanded(QTreeWidgetItem*)), this, SLOT(onItemExpanded(QTreeWidgetItem*))); @@ -110,6 +125,7 @@ DlgObjectSelection::DlgObjectSelection( this, SLOT(onDepSelectionChanged())); connect(ui->buttonBox, SIGNAL(accepted()), this, SLOT(accept())); connect(ui->buttonBox, SIGNAL(rejected()), this, SLOT(reject())); + connect(useOriginalsBtn, SIGNAL(clicked()), this, SLOT(onUseOriginalsBtnClicked())); } /** @@ -293,6 +309,11 @@ void DlgObjectSelection::onItemChanged(QTreeWidgetItem * item, int column) { } std::vector DlgObjectSelection::getSelections() const { + + if (returnOriginals){ + return originalSelections; + } + std::vector res; for(auto &v : objMap) { if(v.second.checkState != Qt::Unchecked) @@ -356,6 +377,11 @@ void DlgObjectSelection::onDepSelectionChanged() { ui->treeWidget->scrollToItem(scroll); } +void DlgObjectSelection::onUseOriginalsBtnClicked(){ + returnOriginals = true; + QDialog::accept(); +} + void DlgObjectSelection::accept() { QDialog::accept(); } diff --git a/src/Gui/DlgObjectSelection.h b/src/Gui/DlgObjectSelection.h index 315ed3126a..060cda0276 100644 --- a/src/Gui/DlgObjectSelection.h +++ b/src/Gui/DlgObjectSelection.h @@ -45,10 +45,14 @@ private Q_SLOTS: void onItemChanged(QTreeWidgetItem * item, int); void onItemSelectionChanged(); void onDepSelectionChanged(); + void onUseOriginalsBtnClicked(); private: QTreeWidgetItem *createItem(App::DocumentObject *obj, QTreeWidgetItem *parent); App::DocumentObject *objFromItem(QTreeWidgetItem *item); + QPushButton *useOriginalsBtn; + std::vector originalSelections; + bool returnOriginals = false; private: struct Info {