Skip to content

Commit

Permalink
fixes 0003689: Snap to grid checkbox in edit control widget does not …
Browse files Browse the repository at this point in the history
…update
  • Loading branch information
wwmayer committed Nov 14, 2018
1 parent da09f7c commit 4f02b20
Show file tree
Hide file tree
Showing 3 changed files with 150 additions and 53 deletions.
38 changes: 38 additions & 0 deletions src/Base/Tools.h
Expand Up @@ -32,6 +32,44 @@
#include <string>
#include <boost/signals2.hpp>
#include <QString>
#include <QObject>

#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
{
Expand Down
126 changes: 88 additions & 38 deletions src/Mod/Sketcher/Gui/TaskSketcherGeneral.cpp
Expand Up @@ -33,6 +33,7 @@
#include <Gui/BitmapFactory.h>
#include <Gui/ViewProvider.h>
#include <Gui/WaitCursor.h>
#include <Base/Tools.h>
#include <Base/UnitsApi.h>

#include "ViewProviderSketch.h"
Expand All @@ -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()
Expand All @@ -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.
}

Expand All @@ -93,44 +94,59 @@ 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);
ui->checkBoxGridSnap->setEnabled(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);
}
Expand All @@ -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();
}

Expand All @@ -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);
}

Expand All @@ -244,7 +294,7 @@ void TaskSketcherGeneral::OnChange(Gui::SelectionSingleton::SubjectType &rCaller
}
/// @endcond DOXERR

void TaskSketcherGeneral::renderOrderChanged()
void TaskSketcherGeneral::onRenderOrderChanged()
{
sketchView->updateColor();
}
Expand Down
39 changes: 24 additions & 15 deletions src/Mod/Sketcher/Gui/TaskSketcherGeneral.h
Expand Up @@ -26,13 +26,18 @@

#include <Gui/TaskView/TaskView.h>
#include <Gui/Selection.h>
#include <boost/signals2.hpp>

class Ui_TaskSketcherGeneral;

namespace App {
class Property;
}

namespace Gui {
class ViewProvider;
}

namespace SketcherGui {

class ViewProviderSketch;
Expand All @@ -47,21 +52,23 @@ class SketcherGeneralWidget : public QWidget

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:
Expand All @@ -83,19 +90,21 @@ class TaskSketcherGeneral : public Gui::TaskView::TaskBox,
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
Expand Down

0 comments on commit 4f02b20

Please sign in to comment.