From 8a1bcc925eabeee401af5a3c3501adc697d78131 Mon Sep 17 00:00:00 2001 From: donovaly Date: Sun, 29 Mar 2020 17:57:45 +0200 Subject: [PATCH] [TD] Section dialog overhaul - replace use uniformly Gui::QuantitySpinBox - fix and uniform size of all objects in the dialog - apply changes immediately once the section is created because this speeds up the workflow a lot, especially for when changing the plane position - some code cleanup: remove unused void, avoid unused variables --- src/Mod/TechDraw/Gui/TaskSectionView.cpp | 113 ++- src/Mod/TechDraw/Gui/TaskSectionView.h | 17 +- src/Mod/TechDraw/Gui/TaskSectionView.ui | 901 +++++++++++------------ 3 files changed, 516 insertions(+), 515 deletions(-) diff --git a/src/Mod/TechDraw/Gui/TaskSectionView.cpp b/src/Mod/TechDraw/Gui/TaskSectionView.cpp index fcb879ccfd..8e86e9a150 100644 --- a/src/Mod/TechDraw/Gui/TaskSectionView.cpp +++ b/src/Mod/TechDraw/Gui/TaskSectionView.cpp @@ -94,19 +94,12 @@ TaskSectionView::TaskSectionView(TechDraw::DrawViewPart* base) : m_saveBaseName = m_base->getNameInDocument(); m_savePageName = m_base->findParentPage()->getNameInDocument(); - - ui->setupUi(this); + ui->setupUi(this); - connect(ui->pbUp, SIGNAL(clicked(bool)), - this, SLOT(onUpClicked(bool))); - connect(ui->pbDown, SIGNAL(clicked(bool)), - this, SLOT(onDownClicked(bool))); - connect(ui->pbRight, SIGNAL(clicked(bool)), - this, SLOT(onRightClicked(bool))); - connect(ui->pbLeft, SIGNAL(clicked(bool)), - this, SLOT(onLeftClicked(bool))); - connect(ui->pbApply, SIGNAL(clicked(bool)), - this, SLOT(onApplyClicked(bool))); + connect(ui->pbUp, SIGNAL(clicked(bool)), this, SLOT(onUpClicked())); + connect(ui->pbDown, SIGNAL(clicked(bool)), this, SLOT(onDownClicked())); + connect(ui->pbRight, SIGNAL(clicked(bool)), this, SLOT(onRightClicked())); + connect(ui->pbLeft, SIGNAL(clicked(bool)), this, SLOT(onLeftClicked())); setUiPrimary(); } @@ -143,16 +136,10 @@ TaskSectionView::TaskSectionView(TechDraw::DrawViewSection* section) : ui->setupUi(this); - connect(ui->pbUp, SIGNAL(clicked(bool)), - this, SLOT(onUpClicked(bool))); - connect(ui->pbDown, SIGNAL(clicked(bool)), - this, SLOT(onDownClicked(bool))); - connect(ui->pbRight, SIGNAL(clicked(bool)), - this, SLOT(onRightClicked(bool))); - connect(ui->pbLeft, SIGNAL(clicked(bool)), - this, SLOT(onLeftClicked(bool))); - connect(ui->pbApply, SIGNAL(clicked(bool)), - this, SLOT(onApplyClicked(bool))); + connect(ui->pbUp, SIGNAL(clicked(bool)), this, SLOT(onUpClicked())); + connect(ui->pbDown, SIGNAL(clicked(bool)), this, SLOT(onDownClicked())); + connect(ui->pbRight, SIGNAL(clicked(bool)), this, SLOT(onRightClicked())); + connect(ui->pbLeft, SIGNAL(clicked(bool)), this, SLOT(onLeftClicked())); m_dirName = m_section->SectionDirection.getValueAsString(); saveSectionState(); @@ -180,6 +167,18 @@ void TaskSectionView::setUiPrimary() ui->sbOrgX->setValue(origin.x); ui->sbOrgY->setValue(origin.y); ui->sbOrgZ->setValue(origin.z); + + // before the user did not select an orientation, + // the section properties cannot be changed + this->setToolTip(QObject::tr("Select at first an orientation")); + enableAll(false); + + // now connect and not earlier to avoid premature apply() calls + connect(ui->leSymbol, SIGNAL(textChanged(QString)), this, SLOT(onIdentifierChanged())); + connect(ui->sbScale, SIGNAL(valueChanged(double)), this, SLOT(onScaleChanged())); + connect(ui->sbOrgX, SIGNAL(valueChanged(double)), this, SLOT(onXChanged())); + connect(ui->sbOrgY, SIGNAL(valueChanged(double)), this, SLOT(onYChanged())); + connect(ui->sbOrgZ, SIGNAL(valueChanged(double)), this, SLOT(onZChanged())); } void TaskSectionView::setUiEdit() @@ -200,6 +199,13 @@ void TaskSectionView::setUiEdit() ui->sbOrgX->setValue(origin.x); ui->sbOrgY->setValue(origin.y); ui->sbOrgZ->setValue(origin.z); + + // connect affter initializing the object values + connect(ui->leSymbol, SIGNAL(textChanged(QString)), this, SLOT(onIdentifierChanged())); + connect(ui->sbScale, SIGNAL(valueChanged(double)), this, SLOT(onScaleChanged())); + connect(ui->sbOrgX, SIGNAL(valueChanged(double)), this, SLOT(onXChanged())); + connect(ui->sbOrgY, SIGNAL(valueChanged(double)), this, SLOT(onYChanged())); + connect(ui->sbOrgZ, SIGNAL(valueChanged(double)), this, SLOT(onZChanged())); } //save the start conditions @@ -231,51 +237,64 @@ void TaskSectionView::restoreSectionState() } } -void TaskSectionView::blockButtons(bool b) -{ - Q_UNUSED(b); -} - -void TaskSectionView::onUpClicked(bool b) +void TaskSectionView::onUpClicked() { // Base::Console().Message("TSV::onUpClicked()\n"); - Q_UNUSED(b); checkAll(false); ui->pbUp->setChecked(true); applyQuick("Up"); } -void TaskSectionView::onDownClicked(bool b) +void TaskSectionView::onDownClicked() { // Base::Console().Message("TSV::onDownClicked()\n"); - Q_UNUSED(b); checkAll(false); ui->pbDown->setChecked(true); applyQuick("Down"); } -void TaskSectionView::onLeftClicked(bool b) +void TaskSectionView::onLeftClicked() { // Base::Console().Message("TSV::onLeftClicked()\n"); checkAll(false); ui->pbLeft->setChecked(true); - Q_UNUSED(b); applyQuick("Left"); } -void TaskSectionView::onRightClicked(bool b) +void TaskSectionView::onRightClicked() { // Base::Console().Message("TSV::onRightClicked()\n"); - Q_UNUSED(b); checkAll(false); ui->pbRight->setChecked(true); applyQuick("Right"); } -void TaskSectionView::onApplyClicked(bool b) +void TaskSectionView::onIdentifierChanged() +{ + checkAll(false); + apply(); +} + +void TaskSectionView::onScaleChanged() +{ + checkAll(false); + apply(); +} + +void TaskSectionView::onXChanged() +{ + checkAll(false); + apply(); +} + +void TaskSectionView::onYChanged() +{ + checkAll(false); + apply(); +} + +void TaskSectionView::onZChanged() { -// Base::Console().Message("TSV::onApplyClicked()\n"); - Q_UNUSED(b); checkAll(false); apply(); } @@ -288,13 +307,22 @@ void TaskSectionView::checkAll(bool b) ui->pbLeft->setChecked(b); } +void TaskSectionView::enableAll(bool b) +{ + ui->leSymbol->setEnabled(b); + ui->sbScale->setEnabled(b); + ui->sbOrgX->setEnabled(b); + ui->sbOrgY->setEnabled(b); + ui->sbOrgZ->setEnabled(b); +} + //****************************************************************************** bool TaskSectionView::apply(void) { // Base::Console().Message("TSV::apply() - m_dirName: %s\n", m_dirName.c_str()); if (m_dirName.empty()) { std::string msg = - Base::Tools::toStdString(tr("TSV::apply - Nothing to apply. No section direction picked yet")); + Base::Tools::toStdString(tr("Nothing to apply. No section direction picked yet")); Base::Console().Error((msg + "\n").c_str()); return false; } @@ -318,6 +346,11 @@ void TaskSectionView::applyQuick(std::string dir) if (isSectionValid()) { updateSectionView(); m_section->recomputeFeature(); + this->setToolTip(QObject::tr("Select at first an orientation")); + // we can in any case enable all objects in the dialog + // and remove the dialog-wide tooltip if there was one + enableAll(true); + this->setToolTip(QString()); } else { failNoObject(m_sectionName); } @@ -420,7 +453,7 @@ void TaskSectionView::updateSectionView(void) lblText.c_str()); Command::doCommand(Command::Doc,"App.activeDocument().%s.Scale = %0.6f", m_sectionName.c_str(), - ui->sbScale->value()); + ui->sbScale->value().getValue()); m_section->setCSFromBase(m_dirName.c_str()); } } diff --git a/src/Mod/TechDraw/Gui/TaskSectionView.h b/src/Mod/TechDraw/Gui/TaskSectionView.h index acd2f74d30..955df54a1d 100644 --- a/src/Mod/TechDraw/Gui/TaskSectionView.h +++ b/src/Mod/TechDraw/Gui/TaskSectionView.h @@ -51,15 +51,17 @@ public: virtual bool reject(); protected Q_SLOTS: - void onUpClicked(bool b); - void onDownClicked(bool b); - void onLeftClicked(bool b); - void onRightClicked(bool b); - void onApplyClicked(bool b); + void onUpClicked(); + void onDownClicked(); + void onLeftClicked(); + void onRightClicked(); + void onIdentifierChanged(); + void onScaleChanged(); + void onXChanged(); + void onYChanged(); + void onZChanged(); protected: - void blockButtons(bool b); - void changeEvent(QEvent *e); void saveSectionState(); void restoreSectionState(); @@ -75,6 +77,7 @@ protected: void setUiEdit(); void checkAll(bool b); + void enableAll(bool b); void failNoObject(std::string objName); bool isBaseValid(void); diff --git a/src/Mod/TechDraw/Gui/TaskSectionView.ui b/src/Mod/TechDraw/Gui/TaskSectionView.ui index 95cf59f30e..158dd94da4 100644 --- a/src/Mod/TechDraw/Gui/TaskSectionView.ui +++ b/src/Mod/TechDraw/Gui/TaskSectionView.ui @@ -1,468 +1,433 @@ - - - TechDrawGui::TaskSectionView - - - - 0 - 0 - 368 - 450 - - - - - 0 - 0 - - - - - 250 - 450 - - - - Section Parameters - - - - - - - 0 - 0 - - - - - 350 - 400 - - - - QFrame::StyledPanel - - - QFrame::Raised - - - - - - QFormLayout::AllNonFixedFieldsGrow - - - - - BaseView - - - - - - - false - - - - - - - Identifier - - - - - - - - 0 - 32 - - - - Identifier for this section - - - - - - - - 0 - 32 - - - - - 0 - 0 - - - - 4 - - - 0.000000000000000 - - - 999.000000000000000 - - - 1.000000000000000 - - - - - - - Scale - - - - - - - - - Qt::Horizontal - - - - - - - Section Orientation - - - - - - - - - Looking right - - - - - - - :/icons/actions/section-right.svg - - - - - 48 - 48 - - - - true - - - - - - - Looking up - - - - - - - - - - - - - :/icons/actions/section-up.svg - - - - - 48 - 48 - - - - true - - - - - - - Looking left - - - - - - - :/icons/actions/section-left.svg - - - - - 48 - 48 - - - - true - - - - - - - Looking down - - - - - - - :/icons/actions/section-down.svg - - - - - 48 - 48 - - - - true - - - - - - - - - Qt::Horizontal - - - - - - - Section Plane Location - - - Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter - - - - - - - QFormLayout::AllNonFixedFieldsGrow - - - - - - 0 - 0 - - - - - 150 - 0 - - - - X - - - Qt::AlignCenter - - - - - - - - 0 - 0 - - - - - 150 - 32 - - - - <html><head/><body><p>Location of section plane in 3D coordinates</p></body></html> - - - - - - - - - - - 0 - 0 - - - - - 150 - 0 - - - - Y - - - Qt::AlignCenter - - - - - - - - 0 - 0 - - - - - 150 - 32 - - - - <html><head/><body><p>Location of section plane in 3D coordinates</p></body></html> - - - - - - - - - - - 0 - 0 - - - - - 150 - 0 - - - - Z - - - Qt::AlignCenter - - - - - - - - 0 - 0 - - - - - 150 - 32 - - - - <html><head/><body><p>Location of section plane in 3D coordinates</p></body></html> - - - - - - - - - - - - - - Apply - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - - - Qt::Vertical - - - - 20 - 40 - - - - - - - - - - - - Gui::QuantitySpinBox - QWidget -
Gui/QuantitySpinBox.h
-
-
- - - - -
+ + + TechDrawGui::TaskSectionView + + + + 0 + 0 + 370 + 326 + + + + + 0 + 0 + + + + Section Parameters + + + + + + + + BaseView + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + false + + + + 0 + 22 + + + + + + + + Identifier + + + + + + + + 0 + 22 + + + + Identifier for this section + + + + + + + Scale + + + + + + + + 0 + 0 + + + + + 0 + 22 + + + + + 0 + 0 + + + + Scale factor for the section view + + + 0.000000000000000 + + + 999.000000000000000 + + + 1.000000000000000 + + + 4 + + + + + + + + + Qt::Horizontal + + + + + + + Section Orientation + + + + + + + + + 50 + 50 + + + + Looking up + + + + + + + + + + + + + :/icons/actions/section-up.svg + + + + + 48 + 48 + + + + true + + + + + + + + 50 + 50 + + + + Looking down + + + + + + + :/icons/actions/section-down.svg + + + + + 48 + 48 + + + + true + + + + + + + + 50 + 50 + + + + Looking left + + + + + + + :/icons/actions/section-left.svg + + + + + 48 + 48 + + + + true + + + + + + + + 50 + 50 + + + + Looking right + + + + + + + :/icons/actions/section-right.svg + + + + + 48 + 48 + + + + true + + + + + + + + + + + + Qt::Horizontal + + + + + + + Position from the 3D origin of the object in the view + + + Section Plane Location + + + + + + + + + 0 + 0 + + + + + 0 + 0 + + + + X + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + 0 + 0 + + + + + 150 + 22 + + + + + + + + + + + + 0 + 0 + + + + + 0 + 0 + + + + Y + + + + + + + + 0 + 0 + + + + + 150 + 22 + + + + + + + + + + + + 0 + 0 + + + + + 0 + 0 + + + + Z + + + + + + + + 0 + 0 + + + + + 150 + 22 + + + + + + + + + + + + + + + + + Gui::QuantitySpinBox + QWidget +
Gui/QuantitySpinBox.h
+
+
+ + + + +