PartDesign: Fillet/chamfer/draft/thickness: Merge Add & Remove buttons.

This commit is contained in:
Paddle
2023-03-21 16:28:18 +01:00
parent c26dc2e685
commit 8ada7af302
10 changed files with 141 additions and 279 deletions

View File

@@ -62,8 +62,7 @@ TaskChamferParameters::TaskChamferParameters(ViewProviderDressUp *DressUpView, Q
bool useAllEdges = pcChamfer->UseAllEdges.getValue();
ui->checkBoxUseAllEdges->setChecked(useAllEdges);
ui->buttonRefAdd->setEnabled(!useAllEdges);
ui->buttonRefRemove->setEnabled(!useAllEdges);
ui->buttonRefSel->setEnabled(!useAllEdges);
ui->listWidgetReferences->setEnabled(!useAllEdges);
QMetaObject::invokeMethod(ui->chamferSize, "setFocus", Qt::QueuedConnection);
@@ -85,15 +84,13 @@ TaskChamferParameters::TaskChamferParameters(ViewProviderDressUp *DressUpView, Q
this, &TaskChamferParameters::onAngleChanged);
connect(ui->flipDirection, &QCheckBox::toggled,
this, &TaskChamferParameters::onFlipDirection);
connect(ui->buttonRefAdd, &QToolButton::toggled,
this, &TaskChamferParameters::onButtonRefAdd);
connect(ui->buttonRefRemove, &QToolButton::toggled,
this, &TaskChamferParameters::onButtonRefRemove);
connect(ui->buttonRefSel, &QToolButton::toggled,
this, &TaskChamferParameters::onButtonRefSel);
connect(ui->checkBoxUseAllEdges, &QCheckBox::toggled,
this, &TaskChamferParameters::onCheckBoxUseAllEdgesToggled);
// Create context menu
createDeleteAction(ui->listWidgetReferences, ui->buttonRefRemove);
createDeleteAction(ui->listWidgetReferences);
connect(deleteAction, &QAction::triggered, this, &TaskChamferParameters::onRefDeleted);
createAddAllEdgesAction(ui->listWidgetReferences);
@@ -160,29 +157,25 @@ void TaskChamferParameters::onSelectionChanged(const Gui::SelectionChanges& msg)
if (msg.Type == Gui::SelectionChanges::AddSelection) {
if (referenceSelected(msg)) {
if (selectionMode == refAdd) {
// Clear selection.
Gui::Selection().clearSelection();
if (removeItemFromListWidget(ui->listWidgetReferences, msg.pSubName)) {
// if there is only one item left, it cannot be deleted
if (ui->listWidgetReferences->count() == 1) {
deleteAction->setEnabled(false);
deleteAction->setStatusTip(tr("There must be at least one item"));
// we must also end the selection mode
exitSelectionMode();
clearButtons(none);
}
}
else {
ui->listWidgetReferences->addItem(QString::fromStdString(msg.pSubName));
// it might be the second one so we can enable the context menu
if (ui->listWidgetReferences->count() > 1) {
deleteAction->setEnabled(true);
deleteAction->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) {
deleteAction->setEnabled(false);
deleteAction->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
@@ -194,8 +187,7 @@ void TaskChamferParameters::onSelectionChanged(const Gui::SelectionChanges& msg)
void TaskChamferParameters::onCheckBoxUseAllEdgesToggled(bool checked)
{
PartDesign::Chamfer* pcChamfer = static_cast<PartDesign::Chamfer*>(DressUpView->getObject());
ui->buttonRefRemove->setEnabled(!checked);
ui->buttonRefAdd->setEnabled(!checked);
ui->buttonRefSel->setEnabled(!checked);
ui->listWidgetReferences->setEnabled(!checked);
pcChamfer->UseAllEdges.setValue(checked);
pcChamfer->getDocument()->recomputeFeature(pcChamfer);
@@ -203,8 +195,7 @@ void TaskChamferParameters::onCheckBoxUseAllEdgesToggled(bool checked)
void TaskChamferParameters::clearButtons(const selectionModes notThis)
{
if (notThis != refAdd) ui->buttonRefAdd->setChecked(false);
if (notThis != refRemove) ui->buttonRefRemove->setChecked(false);
if (notThis != refSel) ui->buttonRefSel->setChecked(false);
DressUpView->highlightReferences(false);
}
@@ -255,15 +246,12 @@ void TaskChamferParameters::onRefDeleted()
if (ui->listWidgetReferences->count() == 1) {
deleteAction->setEnabled(false);
deleteAction->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::onAddAllEdges()
{
TaskDressUpParameters::addAllEdges(ui->listWidgetReferences);
ui->buttonRefRemove->setEnabled(true);
}
void TaskChamferParameters::onTypeChanged(int index)

View File

@@ -15,36 +15,18 @@
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QToolButton" name="buttonRefAdd">
<property name="toolTip">
<string>Click button to enter selection mode,
<widget class="QToolButton" name="buttonRefSel">
<property name="toolTip">
<string>Click button to enter selection mode,
click again to end selection</string>
</property>
<property name="text">
<string>Add</string>
</property>
<property name="checkable">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QToolButton" name="buttonRefRemove">
<property name="toolTip">
<string>Click button to enter selection mode,
click again to end selection</string>
</property>
<property name="text">
<string>Remove</string>
</property>
<property name="checkable">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</property>
<property name="text">
<string>Select</string>
</property>
<property name="checkable">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QListWidget" name="listWidgetReferences">

View File

@@ -85,17 +85,15 @@ TaskDraftParameters::TaskDraftParameters(ViewProviderDressUp *DressUpView, QWidg
this, &TaskDraftParameters::onAngleChanged);
connect(ui->checkReverse, &QCheckBox::toggled,
this, &TaskDraftParameters::onReversedChanged);
connect(ui->buttonRefAdd, &QToolButton::toggled,
this, &TaskDraftParameters::onButtonRefAdd);
connect(ui->buttonRefRemove, &QToolButton::toggled,
this, &TaskDraftParameters::onButtonRefRemove);
connect(ui->buttonRefSel, &QToolButton::toggled,
this, &TaskDraftParameters::onButtonRefSel);
connect(ui->buttonPlane, &QToolButton::toggled,
this, &TaskDraftParameters::onButtonPlane);
connect(ui->buttonLine, &QToolButton::toggled,
this, &TaskDraftParameters::onButtonLine);
// Create context menu
createDeleteAction(ui->listWidgetReferences, ui->buttonRefRemove);
createDeleteAction(ui->listWidgetReferences);
connect(deleteAction, &QAction::triggered, this, &TaskDraftParameters::onRefDeleted);
connect(ui->listWidgetReferences, &QListWidget::currentItemChanged,
@@ -127,34 +125,31 @@ void TaskDraftParameters::onSelectionChanged(const Gui::SelectionChanges& msg)
if (msg.Type == Gui::SelectionChanges::AddSelection) {
if (referenceSelected(msg)) {
if (selectionMode == refAdd) {
ui->listWidgetReferences->addItem(QString::fromStdString(msg.pSubName));
// it might be the second one so we can enable the context menu
if (ui->listWidgetReferences->count() > 1) {
deleteAction->setEnabled(true);
deleteAction->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();
// Clear selection.
Gui::Selection().clearSelection();
if (removeItemFromListWidget(ui->listWidgetReferences, msg.pSubName)) {
// if there is only one item left, it cannot be deleted
if (ui->listWidgetReferences->count() == 1) {
deleteAction->setEnabled(false);
deleteAction->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);
}
}
else {
ui->listWidgetReferences->addItem(QString::fromStdString(msg.pSubName));
// it might be the second one so we can enable the context menu
if (ui->listWidgetReferences->count() > 1) {
deleteAction->setEnabled(true);
deleteAction->setStatusTip(QString());
}
}
// highlight existing references for possible further selections
DressUpView->highlightReferences(true);
} else if (selectionMode == plane) {
}
else if (selectionMode == plane) {
PartDesign::Draft* pcDraft = static_cast<PartDesign::Draft*>(DressUpView->getObject());
std::vector<std::string> planes;
App::DocumentObject* selObj;
@@ -170,7 +165,8 @@ void TaskDraftParameters::onSelectionChanged(const Gui::SelectionChanges& msg)
DressUpView->highlightReferences(true);
// hide the draft if there was a computation error
hideOnError();
} else if (selectionMode == line) {
}
else if (selectionMode == line) {
PartDesign::Draft* pcDraft = static_cast<PartDesign::Draft*>(DressUpView->getObject());
std::vector<std::string> edges;
App::DocumentObject* selObj;
@@ -192,8 +188,7 @@ void TaskDraftParameters::onSelectionChanged(const Gui::SelectionChanges& msg)
void TaskDraftParameters::clearButtons(const selectionModes notThis)
{
if (notThis != refAdd) ui->buttonRefAdd->setChecked(false);
if (notThis != refRemove) ui->buttonRefRemove->setChecked(false);
if (notThis != refSel) ui->buttonRefSel->setChecked(false);
if (notThis != line) ui->buttonLine->setChecked(false);
if (notThis != plane) ui->buttonPlane->setChecked(false);
DressUpView->highlightReferences(false);
@@ -271,8 +266,6 @@ void TaskDraftParameters::onRefDeleted(void)
if (ui->listWidgetReferences->count() == 1) {
deleteAction->setEnabled(false);
deleteAction->setStatusTip(tr("There must be at least one item"));
ui->buttonRefRemove->setEnabled(false);
ui->buttonRefRemove->setToolTip(tr("There must be at least one item"));
}
}

View File

@@ -15,36 +15,19 @@
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QToolButton" name="buttonRefAdd">
<property name="toolTip">
<string>Click button to enter selection mode,
<widget class="QToolButton" name="buttonRefSel">
<property name="toolTip">
<string>Click button to enter selection mode,
click again to end selection</string>
</property>
<property name="text">
<string>Add face</string>
</property>
<property name="checkable">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QToolButton" name="buttonRefRemove">
<property name="toolTip">
<string>Click button to enter selection mode,
click again to end selection</string>
</property>
<property name="text">
<string>Remove face</string>
</property>
<property name="checkable">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</property>
<property name="text">
<string>Select face</string>
</property>
<property name="checkable">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QListWidget" name="listWidgetReferences">

View File

@@ -97,8 +97,7 @@ void TaskDressUpParameters::setupTransaction()
bool TaskDressUpParameters::referenceSelected(const Gui::SelectionChanges& msg)
{
if ((msg.Type == Gui::SelectionChanges::AddSelection) && (
(selectionMode == refAdd) || (selectionMode == refRemove))) {
if ((msg.Type == Gui::SelectionChanges::AddSelection) && (selectionMode == refSel)) {
if (strcmp(msg.pDocName, DressUpView->getObject()->getDocument()->getName()) != 0)
return false;
@@ -115,17 +114,11 @@ bool TaskDressUpParameters::referenceSelected(const Gui::SelectionChanges& msg)
std::vector<std::string> refs = pcDressUp->Base.getSubValues();
std::vector<std::string>::iterator f = std::find(refs.begin(), refs.end(), subName);
if (selectionMode == refAdd) {
if (f == refs.end())
refs.push_back(subName);
else
return false; // duplicate selection
} else {
if (f != refs.end())
refs.erase(f);
else
return false;
}
if (f != refs.end())
refs.erase(f);
else
refs.push_back(subName);
DressUpView->highlightReferences(false);
setupTransaction();
pcDressUp->Base.setValue(base, refs);
@@ -162,7 +155,7 @@ void TaskDressUpParameters::addAllEdges(QListWidget* widget)
pcDressUp->getDocument()->recomputeFeature(pcDressUp);
hideObject();
DressUpView->highlightReferences(true);
onButtonRefAdd(true);
onButtonRefSel(true);
if (deleteAction) {
deleteAction->setEnabled(widget->count() > 1);
@@ -171,12 +164,12 @@ void TaskDressUpParameters::addAllEdges(QListWidget* widget)
}
}
void TaskDressUpParameters::onButtonRefAdd(bool checked)
void TaskDressUpParameters::onButtonRefSel(bool checked)
{
if (checked) {
clearButtons(refAdd);
clearButtons(refSel);
hideObject();
selectionMode = refAdd;
selectionMode = refSel;
if (addAllEdgesAction)
addAllEdgesAction->setEnabled(true);
AllowSelectionFlags allow;
@@ -194,25 +187,6 @@ void TaskDressUpParameters::onButtonRefAdd(bool checked)
}
}
void TaskDressUpParameters::onButtonRefRemove(const bool checked)
{
if (checked) {
clearButtons(refRemove);
hideObject();
selectionMode = refRemove;
AllowSelectionFlags allow;
allow.setFlag(AllowSelection::EDGE, allowEdges);
allow.setFlag(AllowSelection::FACE, allowFaces);
Gui::Selection().clearSelection();
Gui::Selection().addSelectionGate(new ReferenceSelection(this->getBase(), allow));
DressUpView->highlightReferences(true);
}
else {
exitSelectionMode();
DressUpView->highlightReferences(false);
}
}
void TaskDressUpParameters::doubleClicked(QListWidgetItem* item) {
// 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
@@ -286,7 +260,7 @@ void TaskDressUpParameters::createAddAllEdgesAction(QListWidget* parentList)
}
void TaskDressUpParameters::createDeleteAction(QListWidget* parentList, QWidget* parentButton)
void TaskDressUpParameters::createDeleteAction(QListWidget* parentList)
{
// creates a context menu, a shortcut for it and connects it to a slot function
@@ -301,8 +275,6 @@ void TaskDressUpParameters::createDeleteAction(QListWidget* parentList, QWidget*
if (parentList->count() == 1) {
deleteAction->setEnabled(false);
deleteAction->setStatusTip(tr("There must be at least one item"));
parentButton->setEnabled(false);
parentButton->setToolTip(tr("There must be at least one item"));
}
parentList->setContextMenuPolicy(Qt::ActionsContextMenu);
}
@@ -347,7 +319,7 @@ const std::vector<std::string> TaskDressUpParameters::getReferences() const
}
// TODO: This code is identical with TaskTransformedParameters::removeItemFromListWidget()
void TaskDressUpParameters::removeItemFromListWidget(QListWidget* widget, const char* itemstr)
bool TaskDressUpParameters::removeItemFromListWidget(QListWidget* widget, const char* itemstr)
{
QList<QListWidgetItem*> items = widget->findItems(QString::fromLatin1(itemstr), Qt::MatchExactly);
if (!items.empty()) {
@@ -355,7 +327,9 @@ void TaskDressUpParameters::removeItemFromListWidget(QListWidget* widget, const
QListWidgetItem* it = widget->takeItem(widget->row(*i));
delete it;
}
return true;
}
return false;
}
void TaskDressUpParameters::hideOnError()

View File

@@ -63,13 +63,12 @@ public:
}
protected Q_SLOTS:
void onButtonRefAdd(const bool checked);
void onButtonRefRemove(const bool checked);
void onButtonRefSel(const bool checked);
void doubleClicked(QListWidgetItem* item);
void setSelection(QListWidgetItem* current);
void itemClickedTimeout();
virtual void onRefDeleted(void) = 0;
void createDeleteAction(QListWidget* parentList, QWidget* parentButton);
void createDeleteAction(QListWidget* parentList);
void createAddAllEdgesAction(QListWidget* parentList);
protected:
@@ -81,9 +80,9 @@ protected:
void addAllEdges(QListWidget* listWidget);
protected:
enum selectionModes { none, refAdd, refRemove, plane, line };
enum selectionModes { none, refSel, plane, line };
virtual void clearButtons(const selectionModes notThis) = 0;
static void removeItemFromListWidget(QListWidget* widget, const char* itemstr);
static bool removeItemFromListWidget(QListWidget* widget, const char* itemstr);
ViewProviderDressUp* getDressUpView() const
{ return DressUpView; }

View File

@@ -58,8 +58,7 @@ TaskFilletParameters::TaskFilletParameters(ViewProviderDressUp *DressUpView, QWi
PartDesign::Fillet* pcFillet = static_cast<PartDesign::Fillet*>(DressUpView->getObject());
bool useAllEdges = pcFillet->UseAllEdges.getValue();
ui->checkBoxUseAllEdges->setChecked(useAllEdges);
ui->buttonRefAdd->setEnabled(!useAllEdges);
ui->buttonRefRemove->setEnabled(!useAllEdges);
ui->buttonRefSel->setEnabled(!useAllEdges);
ui->listWidgetReferences->setEnabled(!useAllEdges);
double r = pcFillet->Radius.getValue();
@@ -79,15 +78,13 @@ TaskFilletParameters::TaskFilletParameters(ViewProviderDressUp *DressUpView, QWi
connect(ui->filletRadius, qOverload<double>(&Gui::QuantitySpinBox::valueChanged),
this, &TaskFilletParameters::onLengthChanged);
connect(ui->buttonRefAdd, &QToolButton::toggled,
this, &TaskFilletParameters::onButtonRefAdd);
connect(ui->buttonRefRemove, &QToolButton::toggled,
this, &TaskFilletParameters::onButtonRefRemove);
connect(ui->buttonRefSel, &QToolButton::toggled,
this, &TaskFilletParameters::onButtonRefSel);
connect(ui->checkBoxUseAllEdges, &QToolButton::toggled,
this, &TaskFilletParameters::onCheckBoxUseAllEdgesToggled);
// Create context menu
createDeleteAction(ui->listWidgetReferences, ui->buttonRefRemove);
createDeleteAction(ui->listWidgetReferences);
connect(deleteAction, &QAction::triggered, this, &TaskFilletParameters::onRefDeleted);
createAddAllEdgesAction(ui->listWidgetReferences);
@@ -114,29 +111,25 @@ void TaskFilletParameters::onSelectionChanged(const Gui::SelectionChanges& msg)
if (msg.Type == Gui::SelectionChanges::AddSelection) {
if (referenceSelected(msg)) {
if (selectionMode == refAdd) {
// Clear selection.
Gui::Selection().clearSelection();
if (removeItemFromListWidget(ui->listWidgetReferences, msg.pSubName)) {
// if there is only one item left, it cannot be deleted
if (ui->listWidgetReferences->count() == 1) {
deleteAction->setEnabled(false);
deleteAction->setStatusTip(tr("There must be at least one item"));
// we must also end the selection mode
exitSelectionMode();
clearButtons(none);
}
}
else {
ui->listWidgetReferences->addItem(QString::fromStdString(msg.pSubName));
// it might be the second one so we can enable the context menu
if (ui->listWidgetReferences->count() > 1) {
deleteAction->setEnabled(true);
deleteAction->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) {
deleteAction->setEnabled(false);
deleteAction->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
@@ -148,8 +141,7 @@ void TaskFilletParameters::onSelectionChanged(const Gui::SelectionChanges& msg)
void TaskFilletParameters::onCheckBoxUseAllEdgesToggled(bool checked)
{
PartDesign::Fillet* pcFillet = static_cast<PartDesign::Fillet*>(DressUpView->getObject());
ui->buttonRefRemove->setEnabled(!checked);
ui->buttonRefAdd->setEnabled(!checked);
ui->buttonRefSel->setEnabled(!checked);
ui->listWidgetReferences->setEnabled(!checked);
pcFillet->UseAllEdges.setValue(checked);
pcFillet->getDocument()->recomputeFeature(pcFillet);
@@ -157,8 +149,7 @@ void TaskFilletParameters::onCheckBoxUseAllEdgesToggled(bool checked)
void TaskFilletParameters::clearButtons(const selectionModes notThis)
{
if (notThis != refAdd) ui->buttonRefAdd->setChecked(false);
if (notThis != refRemove) ui->buttonRefRemove->setChecked(false);
if (notThis != refSel) ui->buttonRefSel->setChecked(false);
DressUpView->highlightReferences(false);
}
@@ -209,15 +200,12 @@ void TaskFilletParameters::onRefDeleted()
if (ui->listWidgetReferences->count() == 1) {
deleteAction->setEnabled(false);
deleteAction->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 TaskFilletParameters::onAddAllEdges()
{
TaskDressUpParameters::addAllEdges(ui->listWidgetReferences);
ui->buttonRefRemove->setEnabled(true);
}
void TaskFilletParameters::onLengthChanged(double len)

View File

@@ -15,36 +15,18 @@
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QToolButton" name="buttonRefAdd">
<property name="toolTip">
<string>Click button to enter selection mode,
<widget class="QToolButton" name="buttonRefSel">
<property name="toolTip">
<string>Click button to enter selection mode,
click again to end selection</string>
</property>
<property name="text">
<string>Add</string>
</property>
<property name="checkable">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QToolButton" name="buttonRefRemove">
<property name="toolTip">
<string>Click button to enter selection mode,
click again to end selection</string>
</property>
<property name="text">
<string>Remove</string>
</property>
<property name="checkable">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</property>
<property name="text">
<string>Select</string>
</property>
<property name="checkable">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QListWidget" name="listWidgetReferences">

View File

@@ -86,17 +86,15 @@ TaskThicknessParameters::TaskThicknessParameters(ViewProviderDressUp *DressUpVie
this, &TaskThicknessParameters::onReversedChanged);
connect(ui->checkIntersection, &QCheckBox::toggled,
this, &TaskThicknessParameters::onIntersectionChanged);
connect(ui->buttonRefAdd, &QToolButton::toggled,
this, &TaskThicknessParameters::onButtonRefAdd);
connect(ui->buttonRefRemove, &QToolButton::toggled,
this, &TaskThicknessParameters::onButtonRefRemove);
connect(ui->buttonRefSel, &QToolButton::toggled,
this, &TaskThicknessParameters::onButtonRefSel);
connect(ui->modeComboBox, qOverload<int>(&QComboBox::currentIndexChanged),
this, &TaskThicknessParameters::onModeChanged);
connect(ui->joinComboBox, qOverload<int>(&QComboBox::currentIndexChanged),
this, &TaskThicknessParameters::onJoinTypeChanged);
// Create context menu
createDeleteAction(ui->listWidgetReferences, ui->buttonRefRemove);
createDeleteAction(ui->listWidgetReferences);
connect(deleteAction, &QAction::triggered, this, &TaskThicknessParameters::onRefDeleted);
connect(ui->listWidgetReferences, &QListWidget::currentItemChanged,
@@ -126,29 +124,25 @@ void TaskThicknessParameters::onSelectionChanged(const Gui::SelectionChanges& ms
if (msg.Type == Gui::SelectionChanges::AddSelection) {
if (referenceSelected(msg)) {
if (selectionMode == refAdd) {
// Clear selection.
Gui::Selection().clearSelection();
if (removeItemFromListWidget(ui->listWidgetReferences, msg.pSubName)) {
// if there is only one item left, it cannot be deleted
if (ui->listWidgetReferences->count() == 1) {
deleteAction->setEnabled(false);
deleteAction->setStatusTip(tr("There must be at least one item"));
// we must also end the selection mode
exitSelectionMode();
clearButtons(none);
}
}
else {
ui->listWidgetReferences->addItem(QString::fromStdString(msg.pSubName));
// it might be the second one so we can enable the context menu
if (ui->listWidgetReferences->count() > 1) {
deleteAction->setEnabled(true);
deleteAction->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) {
deleteAction->setEnabled(false);
deleteAction->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
@@ -159,8 +153,7 @@ void TaskThicknessParameters::onSelectionChanged(const Gui::SelectionChanges& ms
void TaskThicknessParameters::clearButtons(const selectionModes notThis)
{
if (notThis != refAdd) ui->buttonRefAdd->setChecked(false);
if (notThis != refRemove) ui->buttonRefRemove->setChecked(false);
if (notThis != refSel) ui->buttonRefSel->setChecked(false);
DressUpView->highlightReferences(false);
}
@@ -211,8 +204,6 @@ void TaskThicknessParameters::onRefDeleted(void)
if (ui->listWidgetReferences->count() == 1) {
deleteAction->setEnabled(false);
deleteAction->setStatusTip(tr("There must be at least one item"));
ui->buttonRefRemove->setEnabled(false);
ui->buttonRefRemove->setToolTip(tr("There must be at least one item"));
}
}

View File

@@ -15,36 +15,18 @@
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QToolButton" name="buttonRefAdd">
<property name="toolTip">
<string>Click button to enter selection mode,
<widget class="QToolButton" name="buttonRefSel">
<property name="toolTip">
<string>Click button to enter selection mode,
click again to end selection</string>
</property>
<property name="text">
<string>Add face</string>
</property>
<property name="checkable">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QToolButton" name="buttonRefRemove">
<property name="toolTip">
<string>Click button to enter selection mode,
click again to end selection</string>
</property>
<property name="text">
<string>Remove face</string>
</property>
<property name="checkable">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</property>
<property name="text">
<string>Select face</string>
</property>
<property name="checkable">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QListWidget" name="listWidgetReferences">