Sketcher: modify PR 3201 a bit
+ remove unneeded class members from EditData class + do not include ui-header from within header files + fix possible memory leak in EditDatumDialog + when canceling dialog make sure sketch will be updated
This commit is contained in:
@@ -109,8 +109,8 @@ void finishDistanceConstraint(Gui::Command* cmd, Sketcher::SketchObject* sketch,
|
||||
|
||||
// Ask for the value of the distance immediately
|
||||
if (show && isDriven) {
|
||||
EditDatumDialog *editDatumDialog = new EditDatumDialog(sketch, ConStr.size() - 1);
|
||||
editDatumDialog->exec();
|
||||
EditDatumDialog editDatumDialog(sketch, ConStr.size() - 1);
|
||||
editDatumDialog.exec();
|
||||
}
|
||||
else {
|
||||
// no dialog was shown so commit the command
|
||||
|
||||
@@ -34,11 +34,13 @@
|
||||
#include <Gui/Application.h>
|
||||
#include <Gui/CommandT.h>
|
||||
#include <Gui/Document.h>
|
||||
#include <Gui/MainWindow.h>
|
||||
#include <Gui/View3DInventor.h>
|
||||
#include <Gui/View3DInventorViewer.h>
|
||||
#include <Mod/Sketcher/App/SketchObject.h>
|
||||
|
||||
#include "ViewProviderSketch.h"
|
||||
#include "ui_InsertDatum.h"
|
||||
#include "EditDatumDialog.h"
|
||||
#include "CommandConstraints.h"
|
||||
|
||||
@@ -47,26 +49,26 @@ using namespace SketcherGui;
|
||||
|
||||
/* TRANSLATOR SketcherGui::EditDatumDialog */
|
||||
|
||||
EditDatumDialog::EditDatumDialog(ViewProviderSketch* vp, int ConstrNbr) : ConstrNbr(ConstrNbr)
|
||||
EditDatumDialog::EditDatumDialog(ViewProviderSketch* vp, int ConstrNbr)
|
||||
: ConstrNbr(ConstrNbr)
|
||||
{
|
||||
sketch = vp->getSketchObject();
|
||||
const std::vector<Sketcher::Constraint *> &Constraints = sketch->Constraints.getValues();
|
||||
Constr = Constraints[ConstrNbr];
|
||||
}
|
||||
|
||||
EditDatumDialog::EditDatumDialog(Sketcher::SketchObject* pcSketch, int ConstrNbr) : sketch(pcSketch), ConstrNbr(ConstrNbr)
|
||||
EditDatumDialog::EditDatumDialog(Sketcher::SketchObject* pcSketch, int ConstrNbr)
|
||||
: sketch(pcSketch)
|
||||
, ConstrNbr(ConstrNbr)
|
||||
{
|
||||
const std::vector<Sketcher::Constraint *> &Constraints = sketch->Constraints.getValues();
|
||||
Constr = Constraints[ConstrNbr];
|
||||
}
|
||||
|
||||
EditDatumDialog::~EditDatumDialog(){}
|
||||
|
||||
/*void EditDatumDialog::customEvent(QEvent*)
|
||||
EditDatumDialog::~EditDatumDialog()
|
||||
{
|
||||
this->exec();
|
||||
this->deleteLater();
|
||||
}*/
|
||||
|
||||
}
|
||||
|
||||
void EditDatumDialog::exec(bool atCursor)
|
||||
{
|
||||
@@ -79,10 +81,11 @@ void EditDatumDialog::exec(bool atCursor)
|
||||
return;
|
||||
}
|
||||
|
||||
Gui::MDIView *mdi = Gui::Application::Instance->activeDocument()->getActiveView();
|
||||
QDialog dlg(mdi);
|
||||
|
||||
ui_ins_datum.setupUi(&dlg);
|
||||
QDialog dlg(Gui::getMainWindow());
|
||||
if (ui_ins_datum == nullptr) {
|
||||
ui_ins_datum.reset(new Ui_InsertDatum);
|
||||
ui_ins_datum->setupUi(&dlg);
|
||||
}
|
||||
double datum = Constr->getValue();
|
||||
Base::Quantity init_val;
|
||||
|
||||
@@ -90,81 +93,80 @@ void EditDatumDialog::exec(bool atCursor)
|
||||
datum = Base::toDegrees<double>(datum);
|
||||
dlg.setWindowTitle(tr("Insert angle"));
|
||||
init_val.setUnit(Base::Unit::Angle);
|
||||
ui_ins_datum.label->setText(tr("Angle:"));
|
||||
ui_ins_datum.labelEdit->setParamGrpPath(QByteArray("User parameter:BaseApp/History/SketcherAngle"));
|
||||
ui_ins_datum->label->setText(tr("Angle:"));
|
||||
ui_ins_datum->labelEdit->setParamGrpPath(QByteArray("User parameter:BaseApp/History/SketcherAngle"));
|
||||
}
|
||||
else if (Constr->Type == Sketcher::Radius) {
|
||||
dlg.setWindowTitle(tr("Insert radius"));
|
||||
init_val.setUnit(Base::Unit::Length);
|
||||
ui_ins_datum.label->setText(tr("Radius:"));
|
||||
ui_ins_datum.labelEdit->setParamGrpPath(QByteArray("User parameter:BaseApp/History/SketcherLength"));
|
||||
ui_ins_datum->label->setText(tr("Radius:"));
|
||||
ui_ins_datum->labelEdit->setParamGrpPath(QByteArray("User parameter:BaseApp/History/SketcherLength"));
|
||||
}
|
||||
else if (Constr->Type == Sketcher::Diameter) {
|
||||
dlg.setWindowTitle(tr("Insert diameter"));
|
||||
init_val.setUnit(Base::Unit::Length);
|
||||
ui_ins_datum.label->setText(tr("Diameter:"));
|
||||
ui_ins_datum.labelEdit->setParamGrpPath(QByteArray("User parameter:BaseApp/History/SketcherLength"));
|
||||
ui_ins_datum->label->setText(tr("Diameter:"));
|
||||
ui_ins_datum->labelEdit->setParamGrpPath(QByteArray("User parameter:BaseApp/History/SketcherLength"));
|
||||
}
|
||||
else if (Constr->Type == Sketcher::SnellsLaw) {
|
||||
dlg.setWindowTitle(tr("Refractive index ratio", "Constraint_SnellsLaw"));
|
||||
ui_ins_datum.label->setText(tr("Ratio n2/n1:", "Constraint_SnellsLaw"));
|
||||
ui_ins_datum.labelEdit->setParamGrpPath(QByteArray("User parameter:BaseApp/History/SketcherRefrIndexRatio"));
|
||||
ui_ins_datum->label->setText(tr("Ratio n2/n1:", "Constraint_SnellsLaw"));
|
||||
ui_ins_datum->labelEdit->setParamGrpPath(QByteArray("User parameter:BaseApp/History/SketcherRefrIndexRatio"));
|
||||
}
|
||||
else {
|
||||
dlg.setWindowTitle(tr("Insert length"));
|
||||
init_val.setUnit(Base::Unit::Length);
|
||||
ui_ins_datum.label->setText(tr("Length:"));
|
||||
ui_ins_datum.labelEdit->setParamGrpPath(QByteArray("User parameter:BaseApp/History/SketcherLength"));
|
||||
ui_ins_datum->label->setText(tr("Length:"));
|
||||
ui_ins_datum->labelEdit->setParamGrpPath(QByteArray("User parameter:BaseApp/History/SketcherLength"));
|
||||
}
|
||||
|
||||
init_val.setValue(datum);
|
||||
|
||||
ui_ins_datum.labelEdit->setValue(init_val);
|
||||
ui_ins_datum.labelEdit->pushToHistory();
|
||||
ui_ins_datum.labelEdit->selectNumber();
|
||||
ui_ins_datum.labelEdit->bind(sketch->Constraints.createPath(ConstrNbr));
|
||||
ui_ins_datum.name->setText(Base::Tools::fromStdString(Constr->Name));
|
||||
ui_ins_datum->labelEdit->setValue(init_val);
|
||||
ui_ins_datum->labelEdit->pushToHistory();
|
||||
ui_ins_datum->labelEdit->selectNumber();
|
||||
ui_ins_datum->labelEdit->bind(sketch->Constraints.createPath(ConstrNbr));
|
||||
ui_ins_datum->name->setText(Base::Tools::fromStdString(Constr->Name));
|
||||
|
||||
ui_ins_datum.cbDriving->setChecked(! Constr->isDriving);
|
||||
ui_ins_datum->cbDriving->setChecked(! Constr->isDriving);
|
||||
|
||||
connect(ui_ins_datum.cbDriving, SIGNAL(toggled(bool)), this, SLOT(drivingToggled(bool)));
|
||||
connect(ui_ins_datum.labelEdit, SIGNAL(valueChanged(const Base::Quantity&)), this, SLOT(datumChanged()));
|
||||
connect(ui_ins_datum.labelEdit, SIGNAL(showFormulaDialog(bool)), this, SLOT(formEditorOpened(bool)));
|
||||
connect(ui_ins_datum->cbDriving, SIGNAL(toggled(bool)), this, SLOT(drivingToggled(bool)));
|
||||
connect(ui_ins_datum->labelEdit, SIGNAL(valueChanged(const Base::Quantity&)), this, SLOT(datumChanged()));
|
||||
connect(ui_ins_datum->labelEdit, SIGNAL(showFormulaDialog(bool)), this, SLOT(formEditorOpened(bool)));
|
||||
connect(&dlg, SIGNAL(accepted()), this, SLOT(accepted()));
|
||||
connect(&dlg, SIGNAL(rejected()), this, SLOT(rejected()));
|
||||
|
||||
if (atCursor)
|
||||
dlg.setGeometry(QCursor::pos().x() - dlg.geometry().width() / 2, QCursor::pos().y(), dlg.geometry().width(), dlg.geometry().height());
|
||||
|
||||
|
||||
dlg.exec();
|
||||
this->deleteLater();
|
||||
}
|
||||
}
|
||||
|
||||
void EditDatumDialog::accepted()
|
||||
{
|
||||
Base::Quantity newQuant = ui_ins_datum.labelEdit->value();
|
||||
Base::Quantity newQuant = ui_ins_datum->labelEdit->value();
|
||||
if (newQuant.isQuantity() || (Constr->Type == Sketcher::SnellsLaw && newQuant.isDimensionless())) {
|
||||
// save the value for the history
|
||||
ui_ins_datum.labelEdit->pushToHistory();
|
||||
ui_ins_datum->labelEdit->pushToHistory();
|
||||
|
||||
double newDatum = newQuant.getValue();
|
||||
|
||||
try {
|
||||
|
||||
/*if (ui_ins_datum.cbDriving->isChecked() == Constr->isDriving) {
|
||||
/*if (ui_ins_datum->cbDriving->isChecked() == Constr->isDriving) {
|
||||
Gui::cmdAppObjectArgs(sketch, "toggleDriving(%i)", ConstrNbr);
|
||||
}*/
|
||||
|
||||
if (! ui_ins_datum.cbDriving->isChecked()) {
|
||||
if (ui_ins_datum.labelEdit->hasExpression())
|
||||
ui_ins_datum.labelEdit->apply();
|
||||
if (! ui_ins_datum->cbDriving->isChecked()) {
|
||||
if (ui_ins_datum->labelEdit->hasExpression())
|
||||
ui_ins_datum->labelEdit->apply();
|
||||
else
|
||||
Gui::cmdAppObjectArgs(sketch, "setDatum(%i,App.Units.Quantity('%f %s'))",
|
||||
ConstrNbr, newDatum, (const char*)newQuant.getUnit().getString().toUtf8());
|
||||
}
|
||||
|
||||
QString constraintName = ui_ins_datum.name->text().trimmed();
|
||||
QString constraintName = ui_ins_datum->name->text().trimmed();
|
||||
if (Base::Tools::toStdString(constraintName) != sketch->Constraints[ConstrNbr]->Name) {
|
||||
std::string escapedstr = Base::Tools::escapedUnicodeFromUtf8(constraintName.toUtf8().constData());
|
||||
Gui::cmdAppObjectArgs(sketch, "renameConstraint(%d, u'%s')",
|
||||
@@ -190,29 +192,28 @@ void EditDatumDialog::accepted()
|
||||
void EditDatumDialog::rejected()
|
||||
{
|
||||
Gui::Command::abortCommand();
|
||||
sketch->recomputeFeature();
|
||||
}
|
||||
|
||||
void EditDatumDialog::drivingToggled(bool state)
|
||||
{
|
||||
if (state)
|
||||
{
|
||||
ui_ins_datum.labelEdit->setToLastUsedValue();
|
||||
if (state) {
|
||||
ui_ins_datum->labelEdit->setToLastUsedValue();
|
||||
}
|
||||
sketch->setDriving(ConstrNbr, !state);
|
||||
}
|
||||
|
||||
void EditDatumDialog::datumChanged()
|
||||
{
|
||||
if (ui_ins_datum.labelEdit->text() != ui_ins_datum.labelEdit->getHistory()[0]) {
|
||||
ui_ins_datum.cbDriving->setChecked(false);
|
||||
if (ui_ins_datum->labelEdit->text() != ui_ins_datum->labelEdit->getHistory()[0]) {
|
||||
ui_ins_datum->cbDriving->setChecked(false);
|
||||
}
|
||||
}
|
||||
|
||||
void EditDatumDialog::formEditorOpened(bool state)
|
||||
{
|
||||
if(state)
|
||||
{
|
||||
ui_ins_datum.cbDriving->setChecked(false);
|
||||
if (state) {
|
||||
ui_ins_datum->cbDriving->setChecked(false);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -23,7 +23,7 @@
|
||||
#define SKETCHERGUI_EditDatumDialog_H
|
||||
|
||||
#include <QObject>
|
||||
#include "ui_InsertDatum.h"
|
||||
#include <memory>
|
||||
|
||||
namespace Sketcher {
|
||||
class Constraint;
|
||||
@@ -32,6 +32,7 @@ class SketchObject;
|
||||
|
||||
namespace SketcherGui {
|
||||
class ViewProviderSketch;
|
||||
class Ui_InsertDatum;
|
||||
|
||||
class EditDatumDialog : public QObject {
|
||||
Q_OBJECT
|
||||
@@ -42,14 +43,13 @@ public:
|
||||
~EditDatumDialog();
|
||||
|
||||
void exec(bool atCursor=true);
|
||||
//void customEvent(QEvent*);
|
||||
|
||||
private:
|
||||
Sketcher::SketchObject* sketch;
|
||||
Sketcher::Constraint* Constr;
|
||||
int ConstrNbr;
|
||||
Ui::InsertDatum ui_ins_datum;
|
||||
|
||||
std::unique_ptr<Ui_InsertDatum> ui_ins_datum;
|
||||
|
||||
private Q_SLOTS:
|
||||
void accepted();
|
||||
void rejected();
|
||||
|
||||
@@ -169,7 +169,6 @@ SbVec2s ViewProviderSketch::newCursorPos;
|
||||
struct EditData {
|
||||
EditData():
|
||||
sketchHandler(0),
|
||||
editDatumDialog(false),
|
||||
buttonPress(false),
|
||||
DragPoint(-1),
|
||||
DragCurve(-1),
|
||||
@@ -202,7 +201,6 @@ struct EditData {
|
||||
|
||||
// pointer to the active handler for new sketch objects
|
||||
DrawSketchHandler *sketchHandler;
|
||||
bool editDatumDialog;
|
||||
bool buttonPress;
|
||||
bool handleEscapeButton;
|
||||
|
||||
@@ -449,10 +447,6 @@ bool ViewProviderSketch::keyPressed(bool pressed, int key)
|
||||
edit->sketchHandler->quit();
|
||||
return true;
|
||||
}
|
||||
if (edit && edit->editDatumDialog) {
|
||||
edit->editDatumDialog = false;
|
||||
return true;
|
||||
}
|
||||
if (edit && (edit->DragConstraintSet.empty() == false)) {
|
||||
if (!pressed) {
|
||||
edit->DragConstraintSet.clear();
|
||||
@@ -1022,12 +1016,9 @@ void ViewProviderSketch::editDoubleClicked(void)
|
||||
|
||||
// if its the right constraint
|
||||
if (Constr->isDimensional()) {
|
||||
// Coin's SoIdleSensor causes problems on some platform while Qt seems to work properly (#0001517)
|
||||
Gui::Command::openCommand("Modify sketch constraints");
|
||||
EditDatumDialog *editDatumDialog = new EditDatumDialog(this, id);
|
||||
//QCoreApplication::postEvent(editDatumDialog, new QEvent(QEvent::User));
|
||||
editDatumDialog->exec();
|
||||
edit->editDatumDialog = true; // avoid to double handle "ESC"
|
||||
EditDatumDialog editDatumDialog(this, id);
|
||||
editDatumDialog.exec();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user