Skip to content

Commit

Permalink
improve fillet dialog logic
Browse files Browse the repository at this point in the history
- now also the case of only one item in the list is handled properly (single-click will highlight it, double-click will show the final fillet)
  • Loading branch information
donovaly authored and wwmayer committed Feb 17, 2020
1 parent 757cfce commit 702b37a
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 23 deletions.
2 changes: 1 addition & 1 deletion src/Mod/PartDesign/Gui/TaskChamferParameters.cpp
Expand Up @@ -101,7 +101,7 @@ TaskChamferParameters::TaskChamferParameters(ViewProviderDressUp *DressUpView, Q
connect(action, SIGNAL(triggered()), this, SLOT(onRefDeleted()));
ui->listWidgetReferences->setContextMenuPolicy(Qt::ActionsContextMenu);

connect(ui->listWidgetReferences, SIGNAL(currentItemChanged(QListWidgetItem*, QListWidgetItem*)),
connect(ui->listWidgetReferences, SIGNAL(itemClicked(QListWidgetItem*)),
this, SLOT(setSelection(QListWidgetItem*)));
connect(ui->listWidgetReferences, SIGNAL(itemDoubleClicked(QListWidgetItem*)),
this, SLOT(doubleClicked(QListWidgetItem*)));
Expand Down
2 changes: 1 addition & 1 deletion src/Mod/PartDesign/Gui/TaskDraftParameters.cpp
Expand Up @@ -115,7 +115,7 @@ TaskDraftParameters::TaskDraftParameters(ViewProviderDressUp *DressUpView, QWidg
connect(action, SIGNAL(triggered()), this, SLOT(onRefDeleted()));
ui->listWidgetReferences->setContextMenuPolicy(Qt::ActionsContextMenu);

connect(ui->listWidgetReferences, SIGNAL(currentItemChanged(QListWidgetItem*, QListWidgetItem*)),
connect(ui->listWidgetReferences, SIGNAL(itemClicked(QListWidgetItem*)),
this, SLOT(setSelection(QListWidgetItem*)));
connect(ui->listWidgetReferences, SIGNAL(itemDoubleClicked(QListWidgetItem*)),
this, SLOT(doubleClicked(QListWidgetItem*)));
Expand Down
52 changes: 33 additions & 19 deletions src/Mod/PartDesign/Gui/TaskDressUpParameters.cpp
Expand Up @@ -156,10 +156,11 @@ void TaskDressUpParameters::onButtonRefRemove(const bool checked)
}

void TaskDressUpParameters::doubleClicked(QListWidgetItem* item) {
// executed when the user selected a new item in the list
// executed when the user double-clicks on any item in the list
// shows the fillets as they are -> useful to switch out of selection mode

Q_UNUSED(item)
wasDoubleClicked = true;

// assure we are not in selection mode
exitSelectionMode();
Expand All @@ -170,29 +171,42 @@ void TaskDressUpParameters::doubleClicked(QListWidgetItem* item) {
// remove any highlights andd selections
DressUpView->highlightReferences(false);
Gui::Selection().clearSelection();

// enable next possible single-click event after double-click time passed
QTimer::singleShot(QApplication::doubleClickInterval(), this, SLOT(itemClickedTimeout()));
}

void TaskDressUpParameters::setSelection(QListWidgetItem* current) {
// executed when the user selected a new item in the list
// executed when the user selected an item in the list (but double-clicked it)
// highlights the currently selected item

// name of the item
std::string subName = current->text().toStdString();
// get the document name
std::string docName = DressUpView->getObject()->getDocument()->getName();
// get the name of the body we are in
Part::BodyBase* body = PartDesign::Body::findBodyOf(DressUpView->getObject());
std::string objName = body->getNameInDocument();

// hide fillet to see the original edge
// (a fillet creates new edges so that the original one is not available)
hideObject();
// highlight all objects in the list
DressUpView->highlightReferences(true);
// clear existing selections
Gui::Selection().clearSelection();
// highligh the selected item
Gui::Selection().addSelection(docName.c_str(), objName.c_str(), subName.c_str(), 0, 0, 0);
if (!wasDoubleClicked) {
// we treat it as single-click event once the QApplication double-click time is passed
QTimer::singleShot(QApplication::doubleClickInterval(), this, SLOT(itemClickedTimeout()));

// name of the item
std::string subName = current->text().toStdString();
// get the document name
std::string docName = DressUpView->getObject()->getDocument()->getName();
// get the name of the body we are in
Part::BodyBase* body = PartDesign::Body::findBodyOf(DressUpView->getObject());
std::string objName = body->getNameInDocument();

// hide fillet to see the original edge
// (a fillet creates new edges so that the original one is not available)
hideObject();
// highlight all objects in the list
DressUpView->highlightReferences(true);
// clear existing selections
Gui::Selection().clearSelection();
// highligh the selected item
Gui::Selection().addSelection(docName.c_str(), objName.c_str(), subName.c_str(), 0, 0, 0);
}
}

void TaskDressUpParameters::itemClickedTimeout() {
// executed after double-click time passed
wasDoubleClicked = false;
}

const std::vector<std::string> TaskDressUpParameters::getReferences() const
Expand Down
2 changes: 2 additions & 0 deletions src/Mod/PartDesign/Gui/TaskDressUpParameters.h
Expand Up @@ -63,11 +63,13 @@ protected Q_SLOTS:
void onButtonRefRemove(const bool checked);
void doubleClicked(QListWidgetItem* item);
void setSelection(QListWidgetItem* current);
void itemClickedTimeout();
virtual void onRefDeleted(void) = 0;

protected:
void exitSelectionMode();
bool referenceSelected(const Gui::SelectionChanges& msg);
bool wasDoubleClicked = false;

protected:
enum selectionModes { none, refAdd, refRemove, plane, line };
Expand Down
2 changes: 1 addition & 1 deletion src/Mod/PartDesign/Gui/TaskFilletParameters.cpp
Expand Up @@ -102,7 +102,7 @@ TaskFilletParameters::TaskFilletParameters(ViewProviderDressUp *DressUpView, QWi
connect(deleteAction, SIGNAL(triggered()), this, SLOT(onRefDeleted()));
ui->listWidgetReferences->setContextMenuPolicy(Qt::ActionsContextMenu);

connect(ui->listWidgetReferences, SIGNAL(currentItemChanged(QListWidgetItem*, QListWidgetItem*)),
connect(ui->listWidgetReferences, SIGNAL(itemClicked(QListWidgetItem*)),
this, SLOT(setSelection(QListWidgetItem*)));
connect(ui->listWidgetReferences, SIGNAL(itemDoubleClicked(QListWidgetItem*)),
this, SLOT(doubleClicked(QListWidgetItem*)));
Expand Down
2 changes: 1 addition & 1 deletion src/Mod/PartDesign/Gui/TaskThicknessParameters.cpp
Expand Up @@ -117,7 +117,7 @@ TaskThicknessParameters::TaskThicknessParameters(ViewProviderDressUp *DressUpVie
connect(action, SIGNAL(triggered()), this, SLOT(onRefDeleted()));
ui->listWidgetReferences->setContextMenuPolicy(Qt::ActionsContextMenu);

connect(ui->listWidgetReferences, SIGNAL(currentItemChanged(QListWidgetItem*, QListWidgetItem*)),
connect(ui->listWidgetReferences, SIGNAL(itemClicked(QListWidgetItem*)),
this, SLOT(setSelection(QListWidgetItem*)));
connect(ui->listWidgetReferences, SIGNAL(itemDoubleClicked(QListWidgetItem*)),
this, SLOT(doubleClicked(QListWidgetItem*)));
Expand Down

1 comment on commit 702b37a

@esopalumpa
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi,

I saw you changed the fillet/chamver logic – which I approve, but I do not understand why we still have separate add/remove actions.
We could have one select-button witch switches to a toggle-selection-mode. If you click on an unselected element it gets selected, if you click on an already selected element it gets unselected.

Please sign in to comment.