Merge pull request #17567 from wwmayer/issue_17523

Mat: Tmp. block signals of material widget
This commit is contained in:
Yorik van Havre
2024-11-04 17:43:54 +01:00
committed by GitHub
2 changed files with 30 additions and 67 deletions

View File

@@ -22,7 +22,6 @@
#include "PreCompiled.h"
#ifndef _PreComp_
#include <QDockWidget>
#include <QSignalBlocker>
#include <algorithm>
#include <boost_signals2.hpp>
@@ -50,17 +49,12 @@ namespace sp = std::placeholders;
/* TRANSLATOR Gui::Dialog::DlgDisplayPropertiesImp */
#if 0 // needed for Qt's lupdate utility
qApp->translate("QDockWidget", "Display properties");
#endif
class DlgDisplayPropertiesImp::Private
{
using DlgDisplayPropertiesImp_Connection = boost::signals2::connection;
public:
Ui::DlgDisplayProperties ui;
bool floating;
DlgDisplayPropertiesImp_Connection connectChangedObject;
static void setElementColor(const std::vector<Gui::ViewProvider*>& views,
@@ -141,14 +135,7 @@ public:
}
};
/**
* Constructs a DlgDisplayPropertiesImp which is a child of 'parent', with the
* name 'name' and widget flags set to 'f'
*
* The dialog will by default be modeless, unless you set 'modal' to
* true to construct a modal dialog.
*/
DlgDisplayPropertiesImp::DlgDisplayPropertiesImp(bool floating, QWidget* parent, Qt::WindowFlags fl)
DlgDisplayPropertiesImp::DlgDisplayPropertiesImp(QWidget* parent, Qt::WindowFlags fl)
: QDialog(parent, fl)
, d(new Private)
{
@@ -159,31 +146,14 @@ DlgDisplayPropertiesImp::DlgDisplayPropertiesImp(bool floating, QWidget* parent,
d->ui.changePlot->hide();
d->ui.buttonLineColor->setModal(false);
d->ui.buttonPointColor->setModal(false);
d->floating = floating;
// Create a filter to only include current format materials
// that contain the basic render model.
setupFilters();
std::vector<Gui::ViewProvider*> views = getSelection();
setDisplayModes(views);
setColorPlot(views);
setShapeAppearance(views);
setLineColor(views);
setPointColor(views);
setPointSize(views);
setLineWidth(views);
setTransparency(views);
setLineTransparency(views);
// embed this dialog into a dockable widget container
if (floating) {
Gui::DockWindowManager* pDockMgr = Gui::DockWindowManager::instance();
QDockWidget* dw =
pDockMgr->addDockWindow("Display properties", this, Qt::AllDockWidgetAreas);
dw->setFeatures(QDockWidget::DockWidgetMovable | QDockWidget::DockWidgetFloatable);
dw->setFloating(true);
dw->show();
{
QSignalBlocker block(d->ui.widgetMaterial);
setPropertiesFromSelection();
}
Gui::Selection().Attach(this);
@@ -194,9 +164,6 @@ DlgDisplayPropertiesImp::DlgDisplayPropertiesImp(bool floating, QWidget* parent,
// NOLINTEND
}
/**
* Destroys the object and frees any allocated resources
*/
DlgDisplayPropertiesImp::~DlgDisplayPropertiesImp()
{
// no need to delete child widgets, Qt does it all for us
@@ -297,6 +264,20 @@ void DlgDisplayPropertiesImp::changeEvent(QEvent* e)
QDialog::changeEvent(e);
}
void DlgDisplayPropertiesImp::setPropertiesFromSelection()
{
std::vector<Gui::ViewProvider*> views = getSelection();
setDisplayModes(views);
setColorPlot(views);
setShapeAppearance(views);
setLineColor(views);
setPointColor(views);
setPointSize(views);
setLineWidth(views);
setTransparency(views);
setLineTransparency(views);
}
/// @cond DOXERR
void DlgDisplayPropertiesImp::OnChange(Gui::SelectionSingleton::SubjectType& rCaller,
Gui::SelectionSingleton::MessageType Reason)
@@ -306,16 +287,7 @@ void DlgDisplayPropertiesImp::OnChange(Gui::SelectionSingleton::SubjectType& rCa
|| Reason.Type == Gui::SelectionChanges::RmvSelection
|| Reason.Type == Gui::SelectionChanges::SetSelection
|| Reason.Type == Gui::SelectionChanges::ClrSelection) {
std::vector<Gui::ViewProvider*> views = getSelection();
setDisplayModes(views);
setColorPlot(views);
setShapeAppearance(views);
setLineColor(views);
setPointColor(views);
setPointSize(views);
setLineWidth(views);
setTransparency(views);
setLineTransparency(views);
setPropertiesFromSelection();
}
}
/// @endcond
@@ -341,16 +313,12 @@ void DlgDisplayPropertiesImp::slotChangedObject(const Gui::ViewProvider& obj,
App::Color value = static_cast<const App::PropertyColor&>(prop).getValue();
if (prop_name == "LineColor") {
bool blocked = d->ui.buttonLineColor->blockSignals(true);
d->ui.buttonLineColor->setColor(QColor((int)(255.0f * value.r),
(int)(255.0f * value.g),
(int)(255.0f * value.b)));
d->ui.buttonLineColor->setColor(value.asValue<QColor>());
d->ui.buttonLineColor->blockSignals(blocked);
}
else if (prop_name == "PointColor") {
bool blocked = d->ui.buttonPointColor->blockSignals(true);
d->ui.buttonPointColor->setColor(QColor((int)(255.0f * value.r),
(int)(255.0f * value.g),
(int)(255.0f * value.b)));
d->ui.buttonPointColor->setColor(value.asValue<QColor>());
d->ui.buttonPointColor->blockSignals(blocked);
}
}
@@ -396,16 +364,8 @@ void DlgDisplayPropertiesImp::slotChangedObject(const Gui::ViewProvider& obj,
}
}
/**
* Destroys the dock window this object is embedded into without destroying itself.
*/
void DlgDisplayPropertiesImp::reject()
{
if (d->floating) {
// closes the dock window
Gui::DockWindowManager* pDockMgr = Gui::DockWindowManager::instance();
pDockMgr->removeDockWindow(this);
}
QDialog::reject();
}
@@ -519,7 +479,8 @@ void DlgDisplayPropertiesImp::onButtonLineColorChanged()
{
std::vector<Gui::ViewProvider*> Provider = getSelection();
QColor s = d->ui.buttonLineColor->color();
App::Color c(s.red() / 255.0, s.green() / 255.0, s.blue() / 255.0);
App::Color c {};
c.setValue<QColor>(s);
for (auto it : Provider) {
if (auto* prop = dynamic_cast<App::PropertyColor*>(it->getPropertyByName("LineColor"))) {
prop->setValue(c);
@@ -531,7 +492,8 @@ void DlgDisplayPropertiesImp::onButtonPointColorChanged()
{
std::vector<Gui::ViewProvider*> Provider = getSelection();
QColor s = d->ui.buttonPointColor->color();
App::Color c(s.red() / 255.0, s.green() / 255.0, s.blue() / 255.0);
App::Color c {};
c.setValue<QColor>(s);
for (auto it : Provider) {
if (auto* prop = dynamic_cast<App::PropertyColor*>(it->getPropertyByName("PointColor"))) {
prop->setValue(c);
@@ -552,7 +514,8 @@ void DlgDisplayPropertiesImp::onSpinLineTransparencyValueChanged(int transparenc
void DlgDisplayPropertiesImp::setDisplayModes(const std::vector<Gui::ViewProvider*>& views)
{
QStringList commonModes, modes;
QStringList commonModes;
QStringList modes;
for (auto it = views.begin(); it != views.end(); ++it) {
if (auto* prop =
dynamic_cast<App::PropertyEnumeration*>((*it)->getPropertyByName("DisplayMode"))) {
@@ -694,7 +657,7 @@ void DlgDisplayPropertiesImp::onMaterialSelected(
TaskDisplayProperties::TaskDisplayProperties()
{
this->setButtonPosition(TaskDisplayProperties::North);
widget = new DlgDisplayPropertiesImp(false);
widget = new DlgDisplayPropertiesImp();
addTaskBox(widget);
}

View File

@@ -56,8 +56,7 @@ class DlgDisplayPropertiesImp: public QDialog, public Gui::SelectionSingleton::O
Q_OBJECT
public:
explicit DlgDisplayPropertiesImp(bool floating,
QWidget* parent = nullptr,
explicit DlgDisplayPropertiesImp(QWidget* parent = nullptr,
Qt::WindowFlags fl = Qt::WindowFlags());
~DlgDisplayPropertiesImp() override;
/// Observer message from the Selection
@@ -96,6 +95,7 @@ private:
void setTransparency(const std::vector<Gui::ViewProvider*>&);
void setLineTransparency(const std::vector<Gui::ViewProvider*>&);
std::vector<Gui::ViewProvider*> getSelection() const;
void setPropertiesFromSelection();
private:
class Private;