[PD] add feature to highlight references in some dialogs
- also fix some logic issues and avoid to break the feature (deleting the last item is now no longer possible)
This commit is contained in:
@@ -50,7 +50,7 @@ using namespace Gui;
|
||||
|
||||
/* TRANSLATOR PartDesignGui::TaskChamferParameters */
|
||||
|
||||
TaskChamferParameters::TaskChamferParameters(ViewProviderDressUp *DressUpView,QWidget *parent)
|
||||
TaskChamferParameters::TaskChamferParameters(ViewProviderDressUp *DressUpView, QWidget *parent)
|
||||
: TaskDressUpParameters(DressUpView, true, true, parent)
|
||||
{
|
||||
// we need a separate container widget to add all controls to
|
||||
@@ -77,11 +77,11 @@ TaskChamferParameters::TaskChamferParameters(ViewProviderDressUp *DressUpView,QW
|
||||
QMetaObject::connectSlotsByName(this);
|
||||
|
||||
connect(ui->chamferDistance, SIGNAL(valueChanged(double)),
|
||||
this, SLOT(onLengthChanged(double)));
|
||||
this, SLOT(onLengthChanged(double)));
|
||||
connect(ui->buttonRefAdd, SIGNAL(toggled(bool)),
|
||||
this, SLOT(onButtonRefAdd(bool)));
|
||||
this, SLOT(onButtonRefAdd(bool)));
|
||||
connect(ui->buttonRefRemove, SIGNAL(toggled(bool)),
|
||||
this, SLOT(onButtonRefRemove(bool)));
|
||||
this, SLOT(onButtonRefRemove(bool)));
|
||||
|
||||
// Create context menu
|
||||
QAction* action = new QAction(tr("Remove"), this);
|
||||
@@ -91,8 +91,20 @@ TaskChamferParameters::TaskChamferParameters(ViewProviderDressUp *DressUpView,QW
|
||||
action->setShortcutVisibleInContextMenu(true);
|
||||
#endif
|
||||
ui->listWidgetReferences->addAction(action);
|
||||
// if there is only one item, it cannot be deleted
|
||||
if (ui->listWidgetReferences->count() == 1) {
|
||||
action->setEnabled(false);
|
||||
action->setStatusTip(tr("There must be at least one item"));
|
||||
ui->buttonRefRemove->setEnabled(false);
|
||||
ui->buttonRefRemove->setToolTip(tr("There must be at least one item"));
|
||||
}
|
||||
connect(action, SIGNAL(triggered()), this, SLOT(onRefDeleted()));
|
||||
ui->listWidgetReferences->setContextMenuPolicy(Qt::ActionsContextMenu);
|
||||
|
||||
connect(ui->listWidgetReferences, SIGNAL(currentItemChanged(QListWidgetItem*, QListWidgetItem*)),
|
||||
this, SLOT(setSelection(QListWidgetItem*)));
|
||||
connect(ui->listWidgetReferences, SIGNAL(itemDoubleClicked(QListWidgetItem*)),
|
||||
this, SLOT(doubleClicked(QListWidgetItem*)));
|
||||
}
|
||||
|
||||
void TaskChamferParameters::onSelectionChanged(const Gui::SelectionChanges& msg)
|
||||
@@ -102,10 +114,32 @@ void TaskChamferParameters::onSelectionChanged(const Gui::SelectionChanges& msg)
|
||||
|
||||
if (msg.Type == Gui::SelectionChanges::AddSelection) {
|
||||
if (referenceSelected(msg)) {
|
||||
if (selectionMode == refAdd)
|
||||
QAction *action = ui->listWidgetReferences->actions().at(0); // we have only one action
|
||||
if (selectionMode == refAdd) {
|
||||
ui->listWidgetReferences->addItem(QString::fromStdString(msg.pSubName));
|
||||
else
|
||||
// it might be the second one so we can enable the context menu
|
||||
if (ui->listWidgetReferences->count() > 1) {
|
||||
action->setEnabled(true);
|
||||
action->setStatusTip(QString());
|
||||
ui->buttonRefRemove->setEnabled(true);
|
||||
ui->buttonRefRemove->setToolTip(tr("Click button to enter selection mode,\nclick again to end selection"));
|
||||
}
|
||||
}
|
||||
else {
|
||||
removeItemFromListWidget(ui->listWidgetReferences, msg.pSubName);
|
||||
// remove its selection too
|
||||
Gui::Selection().clearSelection();
|
||||
// if there is only one item left, it cannot be deleted
|
||||
if (ui->listWidgetReferences->count() == 1) {
|
||||
action->setEnabled(false);
|
||||
action->setStatusTip(tr("There must be at least one item"));
|
||||
ui->buttonRefRemove->setEnabled(false);
|
||||
ui->buttonRefRemove->setToolTip(tr("There must be at least one item"));
|
||||
// we must also end the selection mode
|
||||
exitSelectionMode();
|
||||
clearButtons(none);
|
||||
}
|
||||
}
|
||||
// highlight existing references for possible further selections
|
||||
DressUpView->highlightReferences(true);
|
||||
}
|
||||
@@ -121,6 +155,13 @@ void TaskChamferParameters::clearButtons(const selectionModes notThis)
|
||||
|
||||
void TaskChamferParameters::onRefDeleted(void)
|
||||
{
|
||||
// assure we we are not in selection mode
|
||||
exitSelectionMode();
|
||||
clearButtons(none);
|
||||
// delete any selections since the reference might be highlighted
|
||||
Gui::Selection().clearSelection();
|
||||
DressUpView->highlightReferences(false);
|
||||
|
||||
PartDesign::Chamfer* pcChamfer = static_cast<PartDesign::Chamfer*>(DressUpView->getObject());
|
||||
App::DocumentObject* base = pcChamfer->Base.getValue();
|
||||
std::vector<std::string> refs = pcChamfer->Base.getSubValues();
|
||||
@@ -129,6 +170,15 @@ void TaskChamferParameters::onRefDeleted(void)
|
||||
pcChamfer->Base.setValue(base, refs);
|
||||
ui->listWidgetReferences->model()->removeRow(ui->listWidgetReferences->currentRow());
|
||||
pcChamfer->getDocument()->recomputeFeature(pcChamfer);
|
||||
|
||||
// if there is only one item left, it cannot be deleted
|
||||
if (ui->listWidgetReferences->count() == 1) {
|
||||
QAction *action = ui->listWidgetReferences->actions().at(0); // we have only one action
|
||||
action->setEnabled(false);
|
||||
action->setStatusTip(tr("There must be at least one item"));
|
||||
ui->buttonRefRemove->setEnabled(false);
|
||||
ui->buttonRefRemove->setToolTip(tr("There must be at least one item"));
|
||||
}
|
||||
}
|
||||
|
||||
void TaskChamferParameters::onLengthChanged(double len)
|
||||
@@ -146,7 +196,13 @@ double TaskChamferParameters::getLength(void) const
|
||||
|
||||
TaskChamferParameters::~TaskChamferParameters()
|
||||
{
|
||||
// assure the fillets are shown
|
||||
showObject();
|
||||
// remove any highlights and selections
|
||||
DressUpView->highlightReferences(false);
|
||||
Gui::Selection().clearSelection();
|
||||
Gui::Selection().rmvSelectionGate();
|
||||
|
||||
delete ui;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user