Skip to content

Commit 17a4b07

Browse files
committedNov 13, 2020
[3d][ui] Remove cryptic label-less checkbox for overriding point
model symbol material, and replace by a dedicated "Embedded Textures" entry in the material selection combo box This brings consistency in how materials are set for model symbols and avoids a confusing ui behavior with a disabled material widget and no immediate clues on how to enable these settings.
1 parent c214428 commit 17a4b07

File tree

6 files changed

+57
-46
lines changed

6 files changed

+57
-46
lines changed
 

‎src/3d/symbols/qgspoint3dsymbol_p.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -413,7 +413,9 @@ void QgsModelPoint3DSymbolHandler::makeEntity( Qt3DCore::QEntity *parent, const
413413
}
414414
else
415415
{
416-
if ( mSymbol->shapeProperties()[QStringLiteral( "overwriteMaterial" )].toBool() )
416+
// "overwriteMaterial" is a legacy setting indicating that non-embedded material should be used
417+
if ( mSymbol->shapeProperties()[QStringLiteral( "overwriteMaterial" )].toBool()
418+
|| ( mSymbol->material() && mSymbol->material()->type() != QLatin1String( "null" ) ) )
417419
{
418420
addMeshEntities( context.map(), out.positions, mSymbol.get(), parent, false );
419421
}

‎src/app/3d/qgsmaterialwidget.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,12 @@ QgsAbstractMaterialSettings *QgsMaterialWidget::settings()
8888
return mCurrentSettings->clone();
8989
}
9090

91+
void QgsMaterialWidget::setType( const QString &type )
92+
{
93+
mMaterialTypeComboBox->setCurrentIndex( mMaterialTypeComboBox->findData( type ) );
94+
materialTypeChanged();
95+
}
96+
9197
void QgsMaterialWidget::materialTypeChanged()
9298
{
9399
std::unique_ptr< QgsAbstractMaterialSettings > currentSettings( settings() );

‎src/app/3d/qgsmaterialwidget.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ class QgsMaterialWidget : public QWidget, private Ui::MaterialWidgetBase
4141
void setSettings( const QgsAbstractMaterialSettings *settings, QgsVectorLayer *layer );
4242
QgsAbstractMaterialSettings *settings();
4343

44+
void setType( const QString &type );
45+
4446
signals:
4547

4648
void changed();

‎src/app/3d/qgspoint3dsymbolwidget.cpp

Lines changed: 20 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -74,35 +74,19 @@ QgsPoint3DSymbolWidget::QgsPoint3DSymbolWidget( QWidget *parent )
7474
for ( QDoubleSpinBox *spinBox : constSpinWidgets )
7575
connect( spinBox, static_cast<void ( QDoubleSpinBox::* )( double )>( &QDoubleSpinBox::valueChanged ), this, &QgsPoint3DSymbolWidget::changed );
7676
connect( lineEditModel, &QgsAbstractFileContentSourceLineEdit::sourceChanged, this, &QgsPoint3DSymbolWidget::changed );
77-
connect( cbOverwriteMaterial, static_cast<void ( QCheckBox::* )( int )>( &QCheckBox::stateChanged ), this, &QgsPoint3DSymbolWidget::onOverwriteMaterialChecked );
7877
connect( widgetMaterial, &QgsMaterialWidget::changed, this, &QgsPoint3DSymbolWidget::changed );
7978
connect( btnChangeSymbol, static_cast<void ( QgsSymbolButton::* )( )>( &QgsSymbolButton::changed ), this, &QgsPoint3DSymbolWidget::changed );
8079

8180
// Sync between billboard height and TY
8281
connect( spinBillboardHeight, static_cast<void ( QDoubleSpinBox::* )( double )>( &QDoubleSpinBox::valueChanged ), spinTY, &QDoubleSpinBox::setValue );
8382
connect( spinTY, static_cast<void ( QDoubleSpinBox::* )( double )>( &QDoubleSpinBox::valueChanged ), spinBillboardHeight, &QDoubleSpinBox::setValue );
84-
85-
widgetMaterial->setTechnique( QgsMaterialSettingsRenderingTechnique::InstancedPoints );
8683
}
8784

8885
Qgs3DSymbolWidget *QgsPoint3DSymbolWidget::create( QgsVectorLayer * )
8986
{
9087
return new QgsPoint3DSymbolWidget();
9188
}
9289

93-
void QgsPoint3DSymbolWidget::onOverwriteMaterialChecked( int state )
94-
{
95-
if ( state == Qt::Checked )
96-
{
97-
widgetMaterial->setEnabled( true );
98-
}
99-
else
100-
{
101-
widgetMaterial->setEnabled( false );
102-
}
103-
emit changed();
104-
}
105-
10690
void QgsPoint3DSymbolWidget::setSymbol( const QgsAbstract3DSymbol *symbol, QgsVectorLayer *layer )
10791
{
10892
const QgsPoint3DSymbol *pointSymbol = dynamic_cast< const QgsPoint3DSymbol *>( symbol );
@@ -114,8 +98,8 @@ void QgsPoint3DSymbolWidget::setSymbol( const QgsAbstract3DSymbol *symbol, QgsVe
11498
QVariantMap vm = pointSymbol->shapeProperties();
11599
int index = cboShape->findData( pointSymbol->shape() );
116100
cboShape->setCurrentIndex( index != -1 ? index : 1 ); // use cylinder by default if shape is not set
117-
widgetMaterial->setEnabled( true );
118101
QgsMaterialSettingsRenderingTechnique technique = QgsMaterialSettingsRenderingTechnique::InstancedPoints;
102+
bool forceNullMaterial = false;
119103
switch ( cboShape->currentIndex() )
120104
{
121105
case 0: // sphere
@@ -143,9 +127,11 @@ void QgsPoint3DSymbolWidget::setSymbol( const QgsAbstract3DSymbol *symbol, QgsVe
143127
case 6: // 3d model
144128
{
145129
lineEditModel->setSource( vm[QStringLiteral( "model" )].toString() );
146-
bool overwriteMaterial = vm[QStringLiteral( "overwriteMaterial" )].toBool();
147-
widgetMaterial->setEnabled( overwriteMaterial );
148-
cbOverwriteMaterial->setChecked( overwriteMaterial );
130+
// "overwriteMaterial" is a legacy setting indicating that non-null material should be used
131+
forceNullMaterial = ( vm.contains( QStringLiteral( "overwriteMaterial" ) ) && !vm[QStringLiteral( "overwriteMaterial" )].toBool() )
132+
|| !pointSymbol->material()
133+
|| pointSymbol->material()->type() == QLatin1String( "null" );
134+
technique = QgsMaterialSettingsRenderingTechnique::TrianglesFromModel;
149135
break;
150136
}
151137
case 7: // billboard
@@ -160,6 +146,11 @@ void QgsPoint3DSymbolWidget::setSymbol( const QgsAbstract3DSymbol *symbol, QgsVe
160146
widgetMaterial->setSettings( pointSymbol->material(), layer );
161147
widgetMaterial->setTechnique( technique );
162148

149+
if ( forceNullMaterial )
150+
{
151+
widgetMaterial->setType( QStringLiteral( "null" ) );
152+
}
153+
163154
// decompose the transform matrix
164155
// assuming the last row has values [0 0 0 1]
165156
// see https://math.stackexchange.com/questions/237369/given-this-transformation-matrix-how-do-i-decompose-it-into-translation-rotati
@@ -220,7 +211,6 @@ QgsAbstract3DSymbol *QgsPoint3DSymbolWidget::symbol()
220211
break;
221212
case 6: // 3d model
222213
vm[QStringLiteral( "model" )] = lineEditModel->source();
223-
vm[QStringLiteral( "overwriteMaterial" )] = cbOverwriteMaterial->isChecked();
224214
break;
225215
case 7: // billboard
226216
sym->setBillboardSymbol( btnChangeSymbol->clonedSymbol<QgsMarkerSymbol>() );
@@ -258,10 +248,9 @@ void QgsPoint3DSymbolWidget::onShapeChanged()
258248
<< labelTopRadius << spinTopRadius
259249
<< labelBottomRadius << spinBottomRadius
260250
<< labelLength << spinLength
261-
<< labelModel << lineEditModel << cbOverwriteMaterial
251+
<< labelModel << lineEditModel
262252
<< labelBillboardHeight << spinBillboardHeight << labelBillboardSymbol << btnChangeSymbol;
263253

264-
widgetMaterial->setEnabled( true );
265254
materialsGroupBox->show();
266255
transformationWidget->show();
267256
QList<QWidget *> activeWidgets;
@@ -287,8 +276,8 @@ void QgsPoint3DSymbolWidget::onShapeChanged()
287276
activeWidgets << labelRadius << spinRadius << labelMinorRadius << spinMinorRadius;
288277
break;
289278
case 6: // 3d model
290-
activeWidgets << labelModel << lineEditModel << cbOverwriteMaterial;
291-
widgetMaterial->setEnabled( cbOverwriteMaterial->isChecked() );
279+
activeWidgets << labelModel << lineEditModel;
280+
technique = QgsMaterialSettingsRenderingTechnique::TrianglesFromModel;
292281
break;
293282
case 7: // billboard
294283
activeWidgets << labelBillboardHeight << spinBillboardHeight << labelBillboardSymbol << btnChangeSymbol;
@@ -301,6 +290,12 @@ void QgsPoint3DSymbolWidget::onShapeChanged()
301290

302291
widgetMaterial->setTechnique( technique );
303292

293+
if ( cboShape->currentIndex() == 6 )
294+
{
295+
// going from different shape -> model resets the material to the null type
296+
widgetMaterial->setType( QStringLiteral( "null" ) );
297+
}
298+
304299
const auto constAllWidgets = allWidgets;
305300
for ( QWidget *w : constAllWidgets )
306301
{

‎src/app/3d/qgspoint3dsymbolwidget.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ class QgsPoint3DSymbolWidget : public Qgs3DSymbolWidget, private Ui::Point3DSymb
3737

3838
private slots:
3939
void onShapeChanged();
40-
void onOverwriteMaterialChecked( int state );
4140
};
4241

4342
#endif // QGSPOINT3DSYMBOLWIDGET_H

‎src/ui/3d/point3dsymbolwidget.ui

Lines changed: 26 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,16 @@
1414
<string notr="true">Form</string>
1515
</property>
1616
<layout class="QFormLayout" name="formLayout">
17-
<property name="margin">
17+
<property name="leftMargin">
18+
<number>0</number>
19+
</property>
20+
<property name="topMargin">
21+
<number>0</number>
22+
</property>
23+
<property name="rightMargin">
24+
<number>0</number>
25+
</property>
26+
<property name="bottomMargin">
1827
<number>0</number>
1928
</property>
2029
<item row="2" column="0" colspan="2">
@@ -182,7 +191,16 @@
182191
<string>Shading</string>
183192
</property>
184193
<layout class="QGridLayout" name="shadingGroup">
185-
<property name="margin">
194+
<property name="leftMargin">
195+
<number>0</number>
196+
</property>
197+
<property name="topMargin">
198+
<number>0</number>
199+
</property>
200+
<property name="rightMargin">
201+
<number>0</number>
202+
</property>
203+
<property name="bottomMargin">
186204
<number>0</number>
187205
</property>
188206
<item row="0" column="0">
@@ -238,17 +256,7 @@
238256
<item row="7" column="1">
239257
<layout class="QHBoxLayout" name="horizontalLayout">
240258
<item>
241-
<widget class="Qgs3DModelSourceLineEdit" name="lineEditModel"/>
242-
</item>
243-
<item>
244-
<widget class="QCheckBox" name="cbOverwriteMaterial">
245-
<property name="toolTip">
246-
<string>Overwrite model material</string>
247-
</property>
248-
<property name="text">
249-
<string/>
250-
</property>
251-
</widget>
259+
<widget class="Qgs3DModelSourceLineEdit" name="lineEditModel" native="true"/>
252260
</item>
253261
</layout>
254262
</item>
@@ -404,6 +412,11 @@
404412
</layout>
405413
</widget>
406414
<customwidgets>
415+
<customwidget>
416+
<class>QgsDoubleSpinBox</class>
417+
<extends>QDoubleSpinBox</extends>
418+
<header>qgsdoublespinbox.h</header>
419+
</customwidget>
407420
<customwidget>
408421
<class>Qgs3DModelSourceLineEdit</class>
409422
<extends>QWidget</extends>
@@ -416,11 +429,6 @@
416429
<header>qgsmaterialwidget.h</header>
417430
<container>1</container>
418431
</customwidget>
419-
<customwidget>
420-
<class>QgsDoubleSpinBox</class>
421-
<extends>QDoubleSpinBox</extends>
422-
<header>qgsdoublespinbox.h</header>
423-
</customwidget>
424432
<customwidget>
425433
<class>QgsSymbolButton</class>
426434
<extends>QToolButton</extends>
@@ -442,7 +450,6 @@
442450
<tabstop>spinSize</tabstop>
443451
<tabstop>spinLength</tabstop>
444452
<tabstop>lineEditModel</tabstop>
445-
<tabstop>cbOverwriteMaterial</tabstop>
446453
<tabstop>spinBillboardHeight</tabstop>
447454
<tabstop>btnChangeSymbol</tabstop>
448455
<tabstop>cboAltClamping</tabstop>

0 commit comments

Comments
 (0)
Please sign in to comment.