27#include <QDialogButtonBox>
30#include "moc_qgsmaterialwidget.cpp"
32using namespace Qt::StringLiterals;
44 for (
const QString &type : materialTypes )
46 if ( type ==
"null"_L1 )
52 mMaterialTypeComboBox->setCurrentIndex( -1 );
53 connect( mMaterialTypeComboBox,
static_cast<void ( QComboBox::* )(
int )
>( &QComboBox::currentIndexChanged ),
this, &QgsMaterialWidget::materialTypeChanged );
54 materialTypeChanged();
64 rebuildAvailableTypes();
67void QgsMaterialWidget::rebuildAvailableTypes()
69 const QString prevType = mMaterialTypeComboBox->currentData().toString();
70 mMaterialTypeComboBox->blockSignals(
true );
71 mMaterialTypeComboBox->clear();
74 for (
const QString &type : materialTypes )
79 else if ( type ==
"null"_L1 && !mFilterByTechnique )
85 const int prevIndex = mMaterialTypeComboBox->findData( prevType );
86 if ( prevIndex == -1 )
89 const int metalroughIndex = mMaterialTypeComboBox->findData( u
"metalrough"_s );
90 if ( metalroughIndex >= 0 )
91 mMaterialTypeComboBox->setCurrentIndex( metalroughIndex );
93 mMaterialTypeComboBox->setCurrentIndex( 0 );
96 mMaterialTypeComboBox->setCurrentIndex( prevIndex );
98 if ( QgsMaterialSettingsWidget *w = qobject_cast<QgsMaterialSettingsWidget *>( mStackedWidget->currentWidget() ) )
100 w->setTechnique( mTechnique );
103 mMaterialTypeComboBox->blockSignals(
false );
104 materialTypeChanged();
109 mFilterByTechnique = enabled;
110 rebuildAvailableTypes();
115 mMaterialTypeComboBox->setCurrentIndex( mMaterialTypeComboBox->findData(
settings->type() ) );
116 mCurrentSettings.reset(
settings->clone() );
118 updateMaterialWidget();
123 return mCurrentSettings ? std::unique_ptr< QgsAbstractMaterialSettings >( mCurrentSettings->clone() ) :
nullptr;
128 mMaterialTypeComboBox->setCurrentIndex( mMaterialTypeComboBox->findData( type ) );
129 materialTypeChanged();
143 mPreviewVisible = visible;
146 w->setPreviewVisible( visible );
150void QgsMaterialWidget::materialTypeChanged()
152 std::unique_ptr<QgsAbstractMaterialSettings> currentSettings(
settings() );
153 const QString existingType = currentSettings ? currentSettings->type() : QString();
154 const QString newType = mMaterialTypeComboBox->currentData().toString();
155 if ( existingType == newType )
162 std::unique_ptr<QgsAbstractMaterialSettings> newMaterial( am->create() );
165 if ( currentSettings )
168 QDomElement tempElem = doc.createElement( u
"temp"_s );
173 mCurrentSettings = std::move( newMaterial );
174 updateMaterialWidget();
180void QgsMaterialWidget::materialWidgetChanged()
182 if ( QgsMaterialSettingsWidget *w = qobject_cast<QgsMaterialSettingsWidget *>( mStackedWidget->currentWidget() ) )
184 mCurrentSettings = w->settings();
189void QgsMaterialWidget::updateMaterialWidget()
191 if ( mStackedWidget->currentWidget() != mPageDummy )
194 if ( QgsMaterialSettingsWidget *w = qobject_cast<QgsMaterialSettingsWidget *>( mStackedWidget->currentWidget() ) )
196 mStackedWidget->removeWidget( mStackedWidget->currentWidget() );
199 const QString settingsType = mCurrentSettings->type();
202 if ( QgsMaterialSettingsWidget *w = am->createWidget() )
204 w->setSettings( mCurrentSettings.get(), mLayer );
205 w->setTechnique( mTechnique );
206 w->setPreviewVisible( mPreviewVisible );
208 mStackedWidget->addWidget( w );
209 mStackedWidget->setCurrentWidget( w );
217 mStackedWidget->setCurrentWidget( mPageDummy );
230 QVBoxLayout *vLayout =
new QVBoxLayout();
232 mWidget->setPreviewVisible(
true );
233 vLayout->addWidget( mWidget, 1 );
237 mWidget->setSettings(
settings,
nullptr );
240 mButtonBox =
new QDialogButtonBox( QDialogButtonBox::Cancel | QDialogButtonBox::Ok, Qt::Horizontal );
241 connect( mButtonBox, &QDialogButtonBox::accepted,
this, &QDialog::accept );
242 connect( mButtonBox, &QDialogButtonBox::rejected,
this, &QDialog::reject );
243 vLayout->addWidget( mButtonBox );
244 setLayout( vLayout );
245 setWindowTitle( tr(
"Material" ) );
252 return mWidget->settings();
MaterialRenderingTechnique
Material rendering techniques.
Abstract base class for material settings.
static QgsMaterialRegistry * materialRegistry()
Returns registry of available 3D materials.
static void enableAutoGeometryRestore(QWidget *widget, const QString &key=QString())
Register the widget to allow its position to be automatically saved and restored when open and closed...
QStringList materialSettingsTypes() const
Returns a list of all available material settings types.
A container for the context for various read/write operations on objects.
Represents a vector layer which manages a vector based dataset.