[Edit menu -> Copy / Duplicate] Add Use Original Selections button to dependency selection dialog

This commit is contained in:
mwganson
2021-09-04 13:09:45 -05:00
parent 37d9757399
commit 096fb76585
2 changed files with 30 additions and 0 deletions

View File

@@ -22,6 +22,7 @@
#include "PreCompiled.h"
#ifndef _PreComp_
# include <QTreeWidget>
# include <QPushButton>
#endif
#include <Base/Console.h>
@@ -43,6 +44,12 @@ DlgObjectSelection::DlgObjectSelection(
const std::vector<App::DocumentObject*> &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. -- <TheMarkster>
*/
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<App::DocumentObject*> DlgObjectSelection::getSelections() const {
if (returnOriginals){
return originalSelections;
}
std::vector<App::DocumentObject*> 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();
}

View File

@@ -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<App::DocumentObject*> originalSelections;
bool returnOriginals = false;
private:
struct Info {