Gui: Refactor DlgMaterialPropertiesImp

Because a PropertyMaterialList property is used now it makes no sense any more to pass a list of view providers to the dialog
as it's impossible to set the material at a certain index.
Therefore the dialog has been simplified and setting the material property must be done by the calling instance.
This commit is contained in:
wmayer
2024-06-03 18:37:24 +02:00
committed by Chris Hennes
parent 3df1095580
commit 954d2c1ac3
6 changed files with 81 additions and 265 deletions

View File

@@ -34,7 +34,7 @@
#include <Gui/DockWindowManager.h>
#include <Gui/Document.h>
#include <Gui/Selection.h>
#include <Gui/ViewProvider.h>
#include <Gui/ViewProviderGeometryObject.h>
#include <Gui/WaitCursor.h>
#include <Mod/Material/App/ModelUuids.h>
@@ -278,7 +278,7 @@ void DlgDisplayPropertiesImp::setupConnections()
connect(d->ui.buttonCustomAppearance,
&Gui::ColorButton::clicked,
this,
&DlgDisplayPropertiesImp::onbuttonCustomAppearanceClicked);
&DlgDisplayPropertiesImp::onButtonCustomAppearanceClicked);
connect(d->ui.buttonColorPlot,
&Gui::ColorButton::clicked,
this,
@@ -412,14 +412,24 @@ void DlgDisplayPropertiesImp::reject()
/**
* Opens a dialog that allows to modify the 'ShapeMaterial' property of all selected view providers.
*/
void DlgDisplayPropertiesImp::onbuttonCustomAppearanceClicked()
void DlgDisplayPropertiesImp::onButtonCustomAppearanceClicked()
{
std::vector<Gui::ViewProvider*> Provider = getSelection();
Gui::Dialog::DlgMaterialPropertiesImp dlg("ShapeAppearance", this);
dlg.setViewProviders(Provider);
Gui::Dialog::DlgMaterialPropertiesImp dlg(this);
if (!Provider.empty()) {
if (auto vp = dynamic_cast<Gui::ViewProviderGeometryObject*>(Provider.front())) {
App::Material mat = vp->ShapeAppearance[0];
dlg.setCustomMaterial(mat);
dlg.setDefaultMaterial(mat);
}
}
dlg.exec();
// d->ui.buttonColor->setColor(dlg.diffuseColor());
App::Material mat = dlg.getCustomMaterial();
for (auto vp : Provider) {
if (auto vpg = dynamic_cast<Gui::ViewProviderGeometryObject*>(vp)) {
vpg->ShapeAppearance.setValue(mat);
}
}
}
/**
@@ -430,11 +440,18 @@ void DlgDisplayPropertiesImp::onButtonColorPlotClicked()
std::vector<Gui::ViewProvider*> Provider = getSelection();
static QPointer<Gui::Dialog::DlgMaterialPropertiesImp> dlg = nullptr;
if (!dlg) {
dlg = new Gui::Dialog::DlgMaterialPropertiesImp("TextureMaterial", this);
dlg = new Gui::Dialog::DlgMaterialPropertiesImp(this);
}
dlg->setModal(false);
dlg->setAttribute(Qt::WA_DeleteOnClose);
dlg->setViewProviders(Provider);
if (!Provider.empty()) {
App::Property* prop = Provider.front()->getPropertyByName("TextureMaterial");
if (auto matProp = dynamic_cast<App::PropertyMaterialList*>(prop)) {
App::Material mat = (*matProp)[0];
dlg->setCustomMaterial(mat);
dlg->setDefaultMaterial(mat);
}
}
dlg->show();
}

View File

@@ -75,7 +75,7 @@ private Q_SLOTS:
void onButtonPointColorChanged();
void onSpinLineWidthValueChanged(int);
void onSpinLineTransparencyValueChanged(int);
void onbuttonCustomAppearanceClicked();
void onButtonCustomAppearanceClicked();
void onButtonColorPlotClicked();
void onMaterialSelected(const std::shared_ptr<Materials::Material>& material);

View File

@@ -418,21 +418,30 @@ void FaceAppearances::updatePanel()
d->ui->buttonCustomAppearance->setDisabled(d->index.isEmpty());
}
int FaceAppearances::getFirstIndex() const
{
if (!d->index.isEmpty()) {
return *(d->index.begin());
}
return 0;
}
/**
* Opens a dialog that allows to modify the 'ShapeMaterial' property of all selected view providers.
*/
void FaceAppearances::onButtonCustomAppearanceClicked()
{
std::vector<Gui::ViewProvider*> Provider;
Provider.push_back(d->vp);
Gui::Dialog::DlgFaceMaterialPropertiesImp dlg("ShapeAppearance", this);
dlg.setViewProviders(Provider);
Gui::Dialog::DlgMaterialPropertiesImp dlg(this);
App::Material mat = d->perface[getFirstIndex()];
dlg.setCustomMaterial(mat);
dlg.setDefaultMaterial(mat);
dlg.exec();
// Set the face appearance
if (!d->index.isEmpty()) {
for (int it : d->index) {
d->perface[it] = dlg.getCustomAppearance();
d->perface[it] = dlg.getCustomMaterial();
}
d->vp->ShapeAppearance.setValues(d->perface);
// new color has been applied, unselect so that users can see this

View File

@@ -65,6 +65,7 @@ protected:
void slotDeleteDocument(const Gui::Document&);
void slotDeleteObject(const Gui::ViewProvider&);
void updatePanel();
int getFirstIndex() const;
private:
class Private;