Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Gui: Add cancel button to transform task UI dialog #10529

Merged
merged 1 commit into from Sep 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
26 changes: 26 additions & 0 deletions src/Gui/TaskCSysDragger.cpp
Expand Up @@ -45,11 +45,11 @@

static double degreesToRadians(const double &degreesIn)
{
return degreesIn * (M_PI / 180.0);

Check warning on line 48 in src/Gui/TaskCSysDragger.cpp

View workflow job for this annotation

GitHub Actions / Lint / Lint

180.0 is a magic number; consider replacing it with a named constant [cppcoreguidelines-avoid-magic-numbers,readability-magic-numbers]
}


TaskCSysDragger::TaskCSysDragger(Gui::ViewProviderDocumentObject* vpObjectIn, Gui::SoFCCSysDragger* draggerIn) :

Check warning on line 52 in src/Gui/TaskCSysDragger.cpp

View workflow job for this annotation

GitHub Actions / Lint / Lint

constructor does not initialize these fields: tSpinBox, rSpinBox [cppcoreguidelines-pro-type-member-init]
dragger(draggerIn)
{
assert(vpObjectIn);
Expand All @@ -67,21 +67,31 @@
Gui::Application::Instance->commandManager().getCommandByName("Std_PerspectiveCamera")->setEnabled(true);
}

void TaskCSysDragger::dragStartCallback(void *, SoDragger *)

Check warning on line 70 in src/Gui/TaskCSysDragger.cpp

View workflow job for this annotation

GitHub Actions / Lint / Lint

all parameters should be named in a function [readability-named-parameter]
{
// This is called when a manipulator is about to manipulating
if(firstDrag)
{
Gui::Application::Instance->activeDocument()->openCommand(QT_TRANSLATE_NOOP("Command", "Transform"));
firstDrag=false;
}
}

void TaskCSysDragger::setupGui()
{
auto incrementsBox = new Gui::TaskView::TaskBox(
Gui::BitmapFactory().pixmap("button_valid"),
tr("Increments"), true, nullptr);

auto gridLayout = new QGridLayout();

Check warning on line 86 in src/Gui/TaskCSysDragger.cpp

View workflow job for this annotation

GitHub Actions / Lint / Lint

initializing non-owner 'QGridLayout *' with a newly created 'gsl::owner<>' [cppcoreguidelines-owning-memory]
gridLayout->setColumnStretch(1, 1);

auto tLabel = new QLabel(tr("Translation Increment:"), incrementsBox);
gridLayout->addWidget(tLabel, 0, 0, Qt::AlignRight);

QFontMetrics metrics(QApplication::font());
int spinBoxWidth = metrics.averageCharWidth() * 20;

Check warning on line 93 in src/Gui/TaskCSysDragger.cpp

View workflow job for this annotation

GitHub Actions / Lint / Lint

20 is a magic number; consider replacing it with a named constant [cppcoreguidelines-avoid-magic-numbers,readability-magic-numbers]
tSpinBox = new QuantitySpinBox(incrementsBox);

Check warning on line 94 in src/Gui/TaskCSysDragger.cpp

View workflow job for this annotation

GitHub Actions / Lint / Lint

assigning newly created 'gsl::owner<>' to non-owner 'Gui::QuantitySpinBox *' [cppcoreguidelines-owning-memory]
tSpinBox->setMinimum(0.0);
tSpinBox->setMaximum(std::numeric_limits<double>::max());
tSpinBox->setUnit(Base::Unit::Length);
Expand All @@ -91,9 +101,9 @@
auto rLabel = new QLabel(tr("Rotation Increment:"), incrementsBox);
gridLayout->addWidget(rLabel, 1, 0, Qt::AlignRight);

rSpinBox = new QuantitySpinBox(incrementsBox);

Check warning on line 104 in src/Gui/TaskCSysDragger.cpp

View workflow job for this annotation

GitHub Actions / Lint / Lint

assigning newly created 'gsl::owner<>' to non-owner 'Gui::QuantitySpinBox *' [cppcoreguidelines-owning-memory]
rSpinBox->setMinimum(0.0);
rSpinBox->setMaximum(180.0);

Check warning on line 106 in src/Gui/TaskCSysDragger.cpp

View workflow job for this annotation

GitHub Actions / Lint / Lint

180.0 is a magic number; consider replacing it with a named constant [cppcoreguidelines-avoid-magic-numbers,readability-magic-numbers]
rSpinBox->setUnit(Base::Unit::Angle);
rSpinBox->setMinimumWidth(spinBoxWidth);
gridLayout->addWidget(rSpinBox, 1, 1, Qt::AlignLeft);
Expand All @@ -117,6 +127,7 @@

void TaskCSysDragger::open()
{
dragger->addStartCallback(dragStartCallback, this);
//we can't have user switching camera types while dragger is shown.
Gui::Application::Instance->commandManager().getCommandByName("Std_OrthographicCamera")->setEnabled(false);
Gui::Application::Instance->commandManager().getCommandByName("Std_PerspectiveCamera")->setEnabled(false);
Expand All @@ -124,7 +135,7 @@
// dragger->rotationIncrement.setValue(lastRotationIncrement);
ParameterGrp::handle hGrp = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/History/Dragger");
double lastTranslationIncrement = hGrp->GetFloat("LastTranslationIncrement", 1.0);
double lastRotationIncrement = hGrp->GetFloat("LastRotationIncrement", 15.0);

Check warning on line 138 in src/Gui/TaskCSysDragger.cpp

View workflow job for this annotation

GitHub Actions / Lint / Lint

15.0 is a magic number; consider replacing it with a named constant [cppcoreguidelines-avoid-magic-numbers,readability-magic-numbers]
tSpinBox->setValue(lastTranslationIncrement);
rSpinBox->setValue(lastRotationIncrement);

Expand All @@ -141,11 +152,26 @@
if (dObject) {
Gui::Document* document = Gui::Application::Instance->getDocument(dObject->getDocument());
assert(document);
firstDrag = true;
document->commitCommand();
document->resetEdit();
document->getDocument()->recompute();
}
return Gui::TaskView::TaskDialog::accept();
}

bool TaskCSysDragger::reject()
{
App::DocumentObject* dObject = vpObject.getObject();
if (dObject) {
Gui::Document* document = Gui::Application::Instance->getDocument(dObject->getDocument());
assert(document);
firstDrag = true;
document->abortCommand();
document->resetEdit();
document->getDocument()->recompute();
}
return Gui::TaskView::TaskDialog::reject();
}

#include "moc_TaskCSysDragger.cpp"

Check failure on line 177 in src/Gui/TaskCSysDragger.cpp

View workflow job for this annotation

GitHub Actions / Lint / Lint

'moc_TaskCSysDragger.cpp' file not found [clang-diagnostic-error]

Check warning on line 177 in src/Gui/TaskCSysDragger.cpp

View workflow job for this annotation

GitHub Actions / Lint / Lint

suspicious #include of file with '.cpp' extension [bugprone-suspicious-include]
7 changes: 6 additions & 1 deletion src/Gui/TaskCSysDragger.h
Expand Up @@ -20,12 +20,14 @@
* *
***************************************************************************/


#ifndef TASKCSYSDRAGGER_H
#define TASKCSYSDRAGGER_H

#include "TaskView/TaskDialog.h"
#include <App/DocumentObserver.h>

class SoDragger;

namespace Gui
{
Expand All @@ -37,16 +39,19 @@
{
Q_OBJECT
public:
TaskCSysDragger(ViewProviderDocumentObject *vpObjectIn, SoFCCSysDragger *draggerIn);

Check failure on line 42 in src/Gui/TaskCSysDragger.h

View workflow job for this annotation

GitHub Actions / Lint / Lint

unknown type name 'ViewProviderDocumentObject' [clang-diagnostic-error]

Check failure on line 42 in src/Gui/TaskCSysDragger.h

View workflow job for this annotation

GitHub Actions / Lint / Lint

unknown type name 'ViewProviderDocumentObject'
~TaskCSysDragger() override;
QDialogButtonBox::StandardButtons getStandardButtons() const override
{ return QDialogButtonBox::Ok;}
{ return QDialogButtonBox::Ok | QDialogButtonBox::Cancel;}
void open() override;
bool accept() override;
bool reject() override;
private Q_SLOTS:
void onTIncrementSlot(double freshValue);
void onRIncrementSlot(double freshValue);
private:
static inline bool firstDrag = true;
static void dragStartCallback(void * data, SoDragger * d);
void setupGui();
App::DocumentObjectT vpObject;
SoFCCSysDragger *dragger;
Expand Down
9 changes: 1 addition & 8 deletions src/Gui/ViewProviderDragger.cpp
Expand Up @@ -146,7 +146,6 @@ bool ViewProviderDragger::setEdit(int ModNum)
pcTransform->translation.connectFrom(&csysDragger->translation);
pcTransform->rotation.connectFrom(&csysDragger->rotation);

csysDragger->addStartCallback(dragStartCallback, this);
csysDragger->addFinishCallback(dragFinishCallback, this);

// dragger node is added to viewer's editing root in setEditViewer
Expand Down Expand Up @@ -212,12 +211,6 @@ void ViewProviderDragger::unsetEditViewer(Gui::View3DInventorViewer* viewer)
}
}

void ViewProviderDragger::dragStartCallback(void *, SoDragger *)
{
// This is called when a manipulator is about to manipulating
Gui::Application::Instance->activeDocument()->openCommand(QT_TRANSLATE_NOOP("Command", "Transform"));
}

void ViewProviderDragger::dragFinishCallback(void *data, SoDragger *d)
{
// This is called when a manipulator has done manipulating
Expand All @@ -226,7 +219,7 @@ void ViewProviderDragger::dragFinishCallback(void *data, SoDragger *d)
auto dragger = static_cast<SoFCCSysDragger *>(d);
updatePlacementFromDragger(sudoThis, dragger);

Gui::Application::Instance->activeDocument()->commitCommand();
//Gui::Application::Instance->activeDocument()->commitCommand();
}

void ViewProviderDragger::updatePlacementFromDragger(ViewProviderDragger* sudoThis, SoFCCSysDragger* draggerIn)
Expand Down
2 changes: 0 additions & 2 deletions src/Gui/ViewProviderDragger.h
Expand Up @@ -72,9 +72,7 @@ class GuiExport ViewProviderDragger : public ViewProviderDocumentObject
SoFCCSysDragger *csysDragger = nullptr;

private:
static void dragStartCallback(void * data, SoDragger * d);
static void dragFinishCallback(void * data, SoDragger * d);

static void updatePlacementFromDragger(ViewProviderDragger *sudoThis, SoFCCSysDragger *draggerIn);

bool checkLink();
Expand Down