diff --git a/src/Base/Tools.h b/src/Base/Tools.h index affd12c95e..5521715b3c 100644 --- a/src/Base/Tools.h +++ b/src/Base/Tools.h @@ -32,6 +32,44 @@ #include #include #include +#include + +#if (QT_VERSION < 0x050300) +class QSignalBlocker +{ +public: + QSignalBlocker(QObject *object) + : object(object) + , blocked(object && object->blockSignals(true)) + , inhibited(false) + { + } + ~QSignalBlocker() + { + if (object && !inhibited) + object->blockSignals(blocked); + } + void reblock() + { + if (object) + object->blockSignals(true); + inhibited = false; + } + void unblock() + { + if (object) + object->blockSignals(blocked); + inhibited = true; + } + +private: + QObject *object; + bool blocked; + bool inhibited; +}; +#endif + +// ---------------------------------------------------------------------------- namespace Base { diff --git a/src/Mod/Sketcher/Gui/TaskSketcherGeneral.cpp b/src/Mod/Sketcher/Gui/TaskSketcherGeneral.cpp index 8b75462ed3..557c024587 100644 --- a/src/Mod/Sketcher/Gui/TaskSketcherGeneral.cpp +++ b/src/Mod/Sketcher/Gui/TaskSketcherGeneral.cpp @@ -33,6 +33,7 @@ #include #include #include +#include #include #include "ViewProviderSketch.h" @@ -47,15 +48,15 @@ SketcherGeneralWidget::SketcherGeneralWidget(QWidget *parent) // connecting the needed signals connect(ui->checkBoxShowGrid, SIGNAL(toggled(bool)), - this, SLOT(toggleGridView(bool))); + this, SLOT(onToggleGridView(bool))); connect(ui->checkBoxGridSnap, SIGNAL(stateChanged(int)), - this, SLOT(toggleGridSnap(int))); + this, SLOT(onToggleGridSnap(int))); connect(ui->gridSize, SIGNAL(valueChanged(double)), - this, SLOT(setGridSize(double))); + this, SLOT(onSetGridSize(double))); connect(ui->checkBoxAutoconstraints, SIGNAL(stateChanged(int)), this, SIGNAL(emitToggleAutoconstraints(int))); connect(ui->renderingOrder->model(), SIGNAL(layoutChanged()), - this, SLOT(renderOrderChanged())); + this, SLOT(onRenderOrderChanged())); } SketcherGeneralWidget::~SketcherGeneralWidget() @@ -73,7 +74,7 @@ void SketcherGeneralWidget::saveSettings() hGrp->SetBool("GridSnap", ui->checkBoxGridSnap->isChecked()); hGrp->SetBool("AutoConstraints", ui->checkBoxAutoconstraints->isChecked()); - + //not necessary to save renderOrder, as it is already stored in renderOrderChanged on every change. } @@ -93,26 +94,46 @@ void SketcherGeneralWidget::loadSettings() int topid = hGrpp->GetInt("TopRenderGeometryId",1); int midid = hGrpp->GetInt("MidRenderGeometryId",2); int lowid = hGrpp->GetInt("LowRenderGeometryId",3); - + QListWidgetItem *newItem = new QListWidgetItem; newItem->setData(Qt::UserRole, QVariant(topid)); newItem->setText( topid==1?tr("Normal Geometry"):topid==2?tr("Construction Geometry"):tr("External Geometry")); ui->renderingOrder->insertItem(0,newItem); - + newItem = new QListWidgetItem; newItem->setData(Qt::UserRole, QVariant(midid)); newItem->setText(midid==1?tr("Normal Geometry"):midid==2?tr("Construction Geometry"):tr("External Geometry")); ui->renderingOrder->insertItem(1,newItem); - + newItem = new QListWidgetItem; newItem->setData(Qt::UserRole, QVariant(lowid)); newItem->setText(lowid==1?tr("Normal Geometry"):lowid==2?tr("Construction Geometry"):tr("External Geometry")); ui->renderingOrder->insertItem(2,newItem); - + ui->checkBoxRedundantAutoconstraints->onRestore(); } -void SketcherGeneralWidget::toggleGridView(bool on) +void SketcherGeneralWidget::setGridSize(double val) +{ + ui->gridSize->setValue(Base::Quantity(val,Base::Unit::Length)); +} + +void SketcherGeneralWidget::checkGridView(bool on) +{ + ui->checkBoxShowGrid->setChecked(on); +} + +void SketcherGeneralWidget::checkGridSnap(bool on) +{ + ui->checkBoxGridSnap->setChecked(on); +} + +void SketcherGeneralWidget::checkAutoconstraints(bool on) +{ + ui->checkBoxAutoconstraints->setChecked(on); +} + +void SketcherGeneralWidget::onToggleGridView(bool on) { ui->label->setEnabled(on); ui->gridSize->setEnabled(on); @@ -120,17 +141,12 @@ void SketcherGeneralWidget::toggleGridView(bool on) emitToggleGridView(on); } -void SketcherGeneralWidget::setGridSize(double val) +void SketcherGeneralWidget::onSetGridSize(double val) { emitSetGridSize(val); } -void SketcherGeneralWidget::setInitGridSize(double val) -{ - ui->gridSize->setValue(Base::Quantity(val,Base::Unit::Length)); -} - -void SketcherGeneralWidget::toggleGridSnap(int state) +void SketcherGeneralWidget::onToggleGridSnap(int state) { emitToggleGridSnap(state); } @@ -143,17 +159,17 @@ void SketcherGeneralWidget::changeEvent(QEvent *e) } } -void SketcherGeneralWidget::renderOrderChanged() +void SketcherGeneralWidget::onRenderOrderChanged() { int topid = ui->renderingOrder->item(0)->data(Qt::UserRole).toInt(); int midid = ui->renderingOrder->item(1)->data(Qt::UserRole).toInt(); int lowid = ui->renderingOrder->item(2)->data(Qt::UserRole).toInt(); - + ParameterGrp::handle hGrp = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/Mod/Sketcher"); hGrp->SetInt("TopRenderGeometryId",topid); hGrp->SetInt("MidRenderGeometryId",midid); hGrp->SetInt("LowRenderGeometryId",lowid); - + emitRenderOrderChanged(); } @@ -175,58 +191,92 @@ TaskSketcherGeneral::TaskSketcherGeneral(ViewProviderSketch *sketchView) // connecting the needed signals QObject::connect( widget, SIGNAL(emitToggleGridView(bool)), - this , SLOT (toggleGridView(bool)) - ); + this , SLOT (onToggleGridView(bool)) + ); + QObject::connect( widget, SIGNAL(emitToggleGridSnap(int)), - this , SLOT (toggleGridSnap(int)) - ); + this , SLOT (onToggleGridSnap(int)) + ); QObject::connect( widget, SIGNAL(emitSetGridSize(double)), - this , SLOT (setGridSize(double)) - ); + this , SLOT (onSetGridSize(double)) + ); QObject::connect( widget, SIGNAL(emitToggleAutoconstraints(int)), - this , SLOT (toggleAutoconstraints(int)) - ); - + this , SLOT (onToggleAutoconstraints(int)) + ); + QObject::connect( widget, SIGNAL(emitRenderOrderChanged()), - this , SLOT (renderOrderChanged()) + this , SLOT (onRenderOrderChanged()) ); - Gui::Selection().Attach(this); + QSignalBlocker block(widget); widget->loadSettings(); - widget->setInitGridSize(sketchView->GridSize.getValue() ); + widget->setGridSize(sketchView->GridSize.getValue()); + widget->checkGridView(sketchView->ShowGrid.getValue()); + widget->checkGridSnap(sketchView->GridSnap.getValue()); + widget->checkAutoconstraints(sketchView->Autoconstraints.getValue()); + + Gui::Application* app = Gui::Application::Instance; + changedSketchView = app->signalChangedObject.connect(boost::bind + (&TaskSketcherGeneral::onChangedSketchView, this, _1, _2)); } TaskSketcherGeneral::~TaskSketcherGeneral() { - widget->saveSettings(); Gui::Selection().Detach(this); } -void TaskSketcherGeneral::toggleGridView(bool on) +void TaskSketcherGeneral::onChangedSketchView(const Gui::ViewProvider& vp, + const App::Property& prop) { + if (sketchView == &vp) { + if (&sketchView->ShowGrid == &prop) { + QSignalBlocker block(widget); + widget->checkGridView(sketchView->ShowGrid.getValue()); + } + else if (&sketchView->GridSize == &prop) { + QSignalBlocker block(widget); + widget->setGridSize(sketchView->GridSize.getValue()); + } + else if (&sketchView->GridSnap == &prop) { + QSignalBlocker block(widget); + widget->checkGridSnap(sketchView->GridSnap.getValue()); + } + else if (&sketchView->Autoconstraints == &prop) { + QSignalBlocker block(widget); + widget->checkAutoconstraints(sketchView->Autoconstraints.getValue()); + } + } +} + +void TaskSketcherGeneral::onToggleGridView(bool on) +{ + Base::ConnectionBlocker block(changedSketchView); sketchView->ShowGrid.setValue(on); } -void TaskSketcherGeneral::setGridSize(double val) +void TaskSketcherGeneral::onSetGridSize(double val) { + Base::ConnectionBlocker block(changedSketchView); if (val > 0) sketchView->GridSize.setValue(val); } -void TaskSketcherGeneral::toggleGridSnap(int state) +void TaskSketcherGeneral::onToggleGridSnap(int state) { + Base::ConnectionBlocker block(changedSketchView); sketchView->GridSnap.setValue(state == Qt::Checked); } -void TaskSketcherGeneral::toggleAutoconstraints(int state) +void TaskSketcherGeneral::onToggleAutoconstraints(int state) { + Base::ConnectionBlocker block(changedSketchView); sketchView->Autoconstraints.setValue(state == Qt::Checked); } @@ -244,7 +294,7 @@ void TaskSketcherGeneral::OnChange(Gui::SelectionSingleton::SubjectType &rCaller } /// @endcond DOXERR -void TaskSketcherGeneral::renderOrderChanged() +void TaskSketcherGeneral::onRenderOrderChanged() { sketchView->updateColor(); } diff --git a/src/Mod/Sketcher/Gui/TaskSketcherGeneral.h b/src/Mod/Sketcher/Gui/TaskSketcherGeneral.h index d3f755d628..faad23a7b6 100644 --- a/src/Mod/Sketcher/Gui/TaskSketcherGeneral.h +++ b/src/Mod/Sketcher/Gui/TaskSketcherGeneral.h @@ -26,6 +26,7 @@ #include #include +#include class Ui_TaskSketcherGeneral; @@ -33,6 +34,10 @@ namespace App { class Property; } +namespace Gui { +class ViewProvider; +} + namespace SketcherGui { class ViewProviderSketch; @@ -47,21 +52,23 @@ public: void saveSettings(); void loadSettings(); - void setInitGridSize(double val); + void setGridSize(double val); + void checkGridView(bool); + void checkGridSnap(bool); + void checkAutoconstraints(bool); Q_SIGNALS: - void setGridSnap(int Type); void emitToggleGridView(bool); void emitToggleGridSnap(int); void emitSetGridSize(double); void emitToggleAutoconstraints(int); void emitRenderOrderChanged(); -public Q_SLOTS: - void toggleGridView(bool on); - void setGridSize(double val); - void toggleGridSnap(int state); - void renderOrderChanged(); +private Q_SLOTS: + void onToggleGridView(bool on); + void onSetGridSize(double val); + void onToggleGridSnap(int state); + void onRenderOrderChanged(); void on_checkBoxRedundantAutoconstraints_stateChanged(int); protected: @@ -83,19 +90,21 @@ public: void OnChange(Gui::SelectionSingleton::SubjectType &rCaller, Gui::SelectionSingleton::MessageType Reason); -Q_SIGNALS: - void setGridSnap(int Type); - public Q_SLOTS: - void toggleGridView(bool on); - void setGridSize(double val); - void toggleGridSnap(int state); - void toggleAutoconstraints(int state); - void renderOrderChanged(); + void onToggleGridView(bool on); + void onSetGridSize(double val); + void onToggleGridSnap(int state); + void onToggleAutoconstraints(int state); + void onRenderOrderChanged(); + +private: + void onChangedSketchView(const Gui::ViewProvider&, + const App::Property&); private: ViewProviderSketch *sketchView; SketcherGeneralWidget* widget; + boost::signals2::scoped_connection changedSketchView; }; } //namespace SketcherGui