Skip to content

Commit

Permalink
[3d][ui] Remove cryptic label-less checkbox for overriding point
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
nyalldawson committed Nov 13, 2020
1 parent c214428 commit 17a4b07
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 46 deletions.
4 changes: 3 additions & 1 deletion src/3d/symbols/qgspoint3dsymbol_p.cpp
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -413,7 +413,9 @@ void QgsModelPoint3DSymbolHandler::makeEntity( Qt3DCore::QEntity *parent, const
} }
else else
{ {
if ( mSymbol->shapeProperties()[QStringLiteral( "overwriteMaterial" )].toBool() ) // "overwriteMaterial" is a legacy setting indicating that non-embedded material should be used
if ( mSymbol->shapeProperties()[QStringLiteral( "overwriteMaterial" )].toBool()
|| ( mSymbol->material() && mSymbol->material()->type() != QLatin1String( "null" ) ) )
{ {
addMeshEntities( context.map(), out.positions, mSymbol.get(), parent, false ); addMeshEntities( context.map(), out.positions, mSymbol.get(), parent, false );
} }
Expand Down
6 changes: 6 additions & 0 deletions src/app/3d/qgsmaterialwidget.cpp
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -88,6 +88,12 @@ QgsAbstractMaterialSettings *QgsMaterialWidget::settings()
return mCurrentSettings->clone(); return mCurrentSettings->clone();
} }


void QgsMaterialWidget::setType( const QString &type )
{
mMaterialTypeComboBox->setCurrentIndex( mMaterialTypeComboBox->findData( type ) );
materialTypeChanged();
}

void QgsMaterialWidget::materialTypeChanged() void QgsMaterialWidget::materialTypeChanged()
{ {
std::unique_ptr< QgsAbstractMaterialSettings > currentSettings( settings() ); std::unique_ptr< QgsAbstractMaterialSettings > currentSettings( settings() );
Expand Down
2 changes: 2 additions & 0 deletions src/app/3d/qgsmaterialwidget.h
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ class QgsMaterialWidget : public QWidget, private Ui::MaterialWidgetBase
void setSettings( const QgsAbstractMaterialSettings *settings, QgsVectorLayer *layer ); void setSettings( const QgsAbstractMaterialSettings *settings, QgsVectorLayer *layer );
QgsAbstractMaterialSettings *settings(); QgsAbstractMaterialSettings *settings();


void setType( const QString &type );

signals: signals:


void changed(); void changed();
Expand Down
45 changes: 20 additions & 25 deletions src/app/3d/qgspoint3dsymbolwidget.cpp
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -74,35 +74,19 @@ QgsPoint3DSymbolWidget::QgsPoint3DSymbolWidget( QWidget *parent )
for ( QDoubleSpinBox *spinBox : constSpinWidgets ) for ( QDoubleSpinBox *spinBox : constSpinWidgets )
connect( spinBox, static_cast<void ( QDoubleSpinBox::* )( double )>( &QDoubleSpinBox::valueChanged ), this, &QgsPoint3DSymbolWidget::changed ); connect( spinBox, static_cast<void ( QDoubleSpinBox::* )( double )>( &QDoubleSpinBox::valueChanged ), this, &QgsPoint3DSymbolWidget::changed );
connect( lineEditModel, &QgsAbstractFileContentSourceLineEdit::sourceChanged, this, &QgsPoint3DSymbolWidget::changed ); connect( lineEditModel, &QgsAbstractFileContentSourceLineEdit::sourceChanged, this, &QgsPoint3DSymbolWidget::changed );
connect( cbOverwriteMaterial, static_cast<void ( QCheckBox::* )( int )>( &QCheckBox::stateChanged ), this, &QgsPoint3DSymbolWidget::onOverwriteMaterialChecked );
connect( widgetMaterial, &QgsMaterialWidget::changed, this, &QgsPoint3DSymbolWidget::changed ); connect( widgetMaterial, &QgsMaterialWidget::changed, this, &QgsPoint3DSymbolWidget::changed );
connect( btnChangeSymbol, static_cast<void ( QgsSymbolButton::* )( )>( &QgsSymbolButton::changed ), this, &QgsPoint3DSymbolWidget::changed ); connect( btnChangeSymbol, static_cast<void ( QgsSymbolButton::* )( )>( &QgsSymbolButton::changed ), this, &QgsPoint3DSymbolWidget::changed );


// Sync between billboard height and TY // Sync between billboard height and TY
connect( spinBillboardHeight, static_cast<void ( QDoubleSpinBox::* )( double )>( &QDoubleSpinBox::valueChanged ), spinTY, &QDoubleSpinBox::setValue ); connect( spinBillboardHeight, static_cast<void ( QDoubleSpinBox::* )( double )>( &QDoubleSpinBox::valueChanged ), spinTY, &QDoubleSpinBox::setValue );
connect( spinTY, static_cast<void ( QDoubleSpinBox::* )( double )>( &QDoubleSpinBox::valueChanged ), spinBillboardHeight, &QDoubleSpinBox::setValue ); connect( spinTY, static_cast<void ( QDoubleSpinBox::* )( double )>( &QDoubleSpinBox::valueChanged ), spinBillboardHeight, &QDoubleSpinBox::setValue );

widgetMaterial->setTechnique( QgsMaterialSettingsRenderingTechnique::InstancedPoints );
} }


Qgs3DSymbolWidget *QgsPoint3DSymbolWidget::create( QgsVectorLayer * ) Qgs3DSymbolWidget *QgsPoint3DSymbolWidget::create( QgsVectorLayer * )
{ {
return new QgsPoint3DSymbolWidget(); return new QgsPoint3DSymbolWidget();
} }


void QgsPoint3DSymbolWidget::onOverwriteMaterialChecked( int state )
{
if ( state == Qt::Checked )
{
widgetMaterial->setEnabled( true );
}
else
{
widgetMaterial->setEnabled( false );
}
emit changed();
}

void QgsPoint3DSymbolWidget::setSymbol( const QgsAbstract3DSymbol *symbol, QgsVectorLayer *layer ) void QgsPoint3DSymbolWidget::setSymbol( const QgsAbstract3DSymbol *symbol, QgsVectorLayer *layer )
{ {
const QgsPoint3DSymbol *pointSymbol = dynamic_cast< const QgsPoint3DSymbol *>( symbol ); const QgsPoint3DSymbol *pointSymbol = dynamic_cast< const QgsPoint3DSymbol *>( symbol );
Expand All @@ -114,8 +98,8 @@ void QgsPoint3DSymbolWidget::setSymbol( const QgsAbstract3DSymbol *symbol, QgsVe
QVariantMap vm = pointSymbol->shapeProperties(); QVariantMap vm = pointSymbol->shapeProperties();
int index = cboShape->findData( pointSymbol->shape() ); int index = cboShape->findData( pointSymbol->shape() );
cboShape->setCurrentIndex( index != -1 ? index : 1 ); // use cylinder by default if shape is not set cboShape->setCurrentIndex( index != -1 ? index : 1 ); // use cylinder by default if shape is not set
widgetMaterial->setEnabled( true );
QgsMaterialSettingsRenderingTechnique technique = QgsMaterialSettingsRenderingTechnique::InstancedPoints; QgsMaterialSettingsRenderingTechnique technique = QgsMaterialSettingsRenderingTechnique::InstancedPoints;
bool forceNullMaterial = false;
switch ( cboShape->currentIndex() ) switch ( cboShape->currentIndex() )
{ {
case 0: // sphere case 0: // sphere
Expand Down Expand Up @@ -143,9 +127,11 @@ void QgsPoint3DSymbolWidget::setSymbol( const QgsAbstract3DSymbol *symbol, QgsVe
case 6: // 3d model case 6: // 3d model
{ {
lineEditModel->setSource( vm[QStringLiteral( "model" )].toString() ); lineEditModel->setSource( vm[QStringLiteral( "model" )].toString() );
bool overwriteMaterial = vm[QStringLiteral( "overwriteMaterial" )].toBool(); // "overwriteMaterial" is a legacy setting indicating that non-null material should be used
widgetMaterial->setEnabled( overwriteMaterial ); forceNullMaterial = ( vm.contains( QStringLiteral( "overwriteMaterial" ) ) && !vm[QStringLiteral( "overwriteMaterial" )].toBool() )
cbOverwriteMaterial->setChecked( overwriteMaterial ); || !pointSymbol->material()
|| pointSymbol->material()->type() == QLatin1String( "null" );
technique = QgsMaterialSettingsRenderingTechnique::TrianglesFromModel;
break; break;
} }
case 7: // billboard case 7: // billboard
Expand All @@ -160,6 +146,11 @@ void QgsPoint3DSymbolWidget::setSymbol( const QgsAbstract3DSymbol *symbol, QgsVe
widgetMaterial->setSettings( pointSymbol->material(), layer ); widgetMaterial->setSettings( pointSymbol->material(), layer );
widgetMaterial->setTechnique( technique ); widgetMaterial->setTechnique( technique );


if ( forceNullMaterial )
{
widgetMaterial->setType( QStringLiteral( "null" ) );
}

// decompose the transform matrix // decompose the transform matrix
// assuming the last row has values [0 0 0 1] // assuming the last row has values [0 0 0 1]
// see https://math.stackexchange.com/questions/237369/given-this-transformation-matrix-how-do-i-decompose-it-into-translation-rotati // see https://math.stackexchange.com/questions/237369/given-this-transformation-matrix-how-do-i-decompose-it-into-translation-rotati
Expand Down Expand Up @@ -220,7 +211,6 @@ QgsAbstract3DSymbol *QgsPoint3DSymbolWidget::symbol()
break; break;
case 6: // 3d model case 6: // 3d model
vm[QStringLiteral( "model" )] = lineEditModel->source(); vm[QStringLiteral( "model" )] = lineEditModel->source();
vm[QStringLiteral( "overwriteMaterial" )] = cbOverwriteMaterial->isChecked();
break; break;
case 7: // billboard case 7: // billboard
sym->setBillboardSymbol( btnChangeSymbol->clonedSymbol<QgsMarkerSymbol>() ); sym->setBillboardSymbol( btnChangeSymbol->clonedSymbol<QgsMarkerSymbol>() );
Expand Down Expand Up @@ -258,10 +248,9 @@ void QgsPoint3DSymbolWidget::onShapeChanged()
<< labelTopRadius << spinTopRadius << labelTopRadius << spinTopRadius
<< labelBottomRadius << spinBottomRadius << labelBottomRadius << spinBottomRadius
<< labelLength << spinLength << labelLength << spinLength
<< labelModel << lineEditModel << cbOverwriteMaterial << labelModel << lineEditModel
<< labelBillboardHeight << spinBillboardHeight << labelBillboardSymbol << btnChangeSymbol; << labelBillboardHeight << spinBillboardHeight << labelBillboardSymbol << btnChangeSymbol;


widgetMaterial->setEnabled( true );
materialsGroupBox->show(); materialsGroupBox->show();
transformationWidget->show(); transformationWidget->show();
QList<QWidget *> activeWidgets; QList<QWidget *> activeWidgets;
Expand All @@ -287,8 +276,8 @@ void QgsPoint3DSymbolWidget::onShapeChanged()
activeWidgets << labelRadius << spinRadius << labelMinorRadius << spinMinorRadius; activeWidgets << labelRadius << spinRadius << labelMinorRadius << spinMinorRadius;
break; break;
case 6: // 3d model case 6: // 3d model
activeWidgets << labelModel << lineEditModel << cbOverwriteMaterial; activeWidgets << labelModel << lineEditModel;
widgetMaterial->setEnabled( cbOverwriteMaterial->isChecked() ); technique = QgsMaterialSettingsRenderingTechnique::TrianglesFromModel;
break; break;
case 7: // billboard case 7: // billboard
activeWidgets << labelBillboardHeight << spinBillboardHeight << labelBillboardSymbol << btnChangeSymbol; activeWidgets << labelBillboardHeight << spinBillboardHeight << labelBillboardSymbol << btnChangeSymbol;
Expand All @@ -301,6 +290,12 @@ void QgsPoint3DSymbolWidget::onShapeChanged()


widgetMaterial->setTechnique( technique ); widgetMaterial->setTechnique( technique );


if ( cboShape->currentIndex() == 6 )
{
// going from different shape -> model resets the material to the null type
widgetMaterial->setType( QStringLiteral( "null" ) );
}

const auto constAllWidgets = allWidgets; const auto constAllWidgets = allWidgets;
for ( QWidget *w : constAllWidgets ) for ( QWidget *w : constAllWidgets )
{ {
Expand Down
1 change: 0 additions & 1 deletion src/app/3d/qgspoint3dsymbolwidget.h
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ class QgsPoint3DSymbolWidget : public Qgs3DSymbolWidget, private Ui::Point3DSymb


private slots: private slots:
void onShapeChanged(); void onShapeChanged();
void onOverwriteMaterialChecked( int state );
}; };


#endif // QGSPOINT3DSYMBOLWIDGET_H #endif // QGSPOINT3DSYMBOLWIDGET_H
45 changes: 26 additions & 19 deletions src/ui/3d/point3dsymbolwidget.ui
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -14,7 +14,16 @@
<string notr="true">Form</string> <string notr="true">Form</string>
</property> </property>
<layout class="QFormLayout" name="formLayout"> <layout class="QFormLayout" name="formLayout">
<property name="margin"> <property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number> <number>0</number>
</property> </property>
<item row="2" column="0" colspan="2"> <item row="2" column="0" colspan="2">
Expand Down Expand Up @@ -182,7 +191,16 @@
<string>Shading</string> <string>Shading</string>
</property> </property>
<layout class="QGridLayout" name="shadingGroup"> <layout class="QGridLayout" name="shadingGroup">
<property name="margin"> <property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number> <number>0</number>
</property> </property>
<item row="0" column="0"> <item row="0" column="0">
Expand Down Expand Up @@ -238,17 +256,7 @@
<item row="7" column="1"> <item row="7" column="1">
<layout class="QHBoxLayout" name="horizontalLayout"> <layout class="QHBoxLayout" name="horizontalLayout">
<item> <item>
<widget class="Qgs3DModelSourceLineEdit" name="lineEditModel"/> <widget class="Qgs3DModelSourceLineEdit" name="lineEditModel" native="true"/>
</item>
<item>
<widget class="QCheckBox" name="cbOverwriteMaterial">
<property name="toolTip">
<string>Overwrite model material</string>
</property>
<property name="text">
<string/>
</property>
</widget>
</item> </item>
</layout> </layout>
</item> </item>
Expand Down Expand Up @@ -404,6 +412,11 @@
</layout> </layout>
</widget> </widget>
<customwidgets> <customwidgets>
<customwidget>
<class>QgsDoubleSpinBox</class>
<extends>QDoubleSpinBox</extends>
<header>qgsdoublespinbox.h</header>
</customwidget>
<customwidget> <customwidget>
<class>Qgs3DModelSourceLineEdit</class> <class>Qgs3DModelSourceLineEdit</class>
<extends>QWidget</extends> <extends>QWidget</extends>
Expand All @@ -416,11 +429,6 @@
<header>qgsmaterialwidget.h</header> <header>qgsmaterialwidget.h</header>
<container>1</container> <container>1</container>
</customwidget> </customwidget>
<customwidget>
<class>QgsDoubleSpinBox</class>
<extends>QDoubleSpinBox</extends>
<header>qgsdoublespinbox.h</header>
</customwidget>
<customwidget> <customwidget>
<class>QgsSymbolButton</class> <class>QgsSymbolButton</class>
<extends>QToolButton</extends> <extends>QToolButton</extends>
Expand All @@ -442,7 +450,6 @@
<tabstop>spinSize</tabstop> <tabstop>spinSize</tabstop>
<tabstop>spinLength</tabstop> <tabstop>spinLength</tabstop>
<tabstop>lineEditModel</tabstop> <tabstop>lineEditModel</tabstop>
<tabstop>cbOverwriteMaterial</tabstop>
<tabstop>spinBillboardHeight</tabstop> <tabstop>spinBillboardHeight</tabstop>
<tabstop>btnChangeSymbol</tabstop> <tabstop>btnChangeSymbol</tabstop>
<tabstop>cboAltClamping</tabstop> <tabstop>cboAltClamping</tabstop>
Expand Down

0 comments on commit 17a4b07

Please sign in to comment.