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 phongIndex = mMaterialTypeComboBox->findData( u
"phong"_s );
90 if ( phongIndex >= 0 )
91 mMaterialTypeComboBox->setCurrentIndex( phongIndex );
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();
134 mPreviewVisible = visible;
137 w->setPreviewVisible( visible );
141void QgsMaterialWidget::materialTypeChanged()
143 std::unique_ptr<QgsAbstractMaterialSettings> currentSettings(
settings() );
144 const QString existingType = currentSettings ? currentSettings->type() : QString();
145 const QString newType = mMaterialTypeComboBox->currentData().toString();
146 if ( existingType == newType )
153 std::unique_ptr<QgsAbstractMaterialSettings> newMaterial( am->create() );
156 if ( currentSettings )
159 QDomElement tempElem = doc.createElement( u
"temp"_s );
164 mCurrentSettings = std::move( newMaterial );
165 updateMaterialWidget();
171void QgsMaterialWidget::materialWidgetChanged()
173 if ( QgsMaterialSettingsWidget *w = qobject_cast<QgsMaterialSettingsWidget *>( mStackedWidget->currentWidget() ) )
175 mCurrentSettings = w->settings();
180void QgsMaterialWidget::updateMaterialWidget()
182 if ( mStackedWidget->currentWidget() != mPageDummy )
185 if ( QgsMaterialSettingsWidget *w = qobject_cast<QgsMaterialSettingsWidget *>( mStackedWidget->currentWidget() ) )
187 mStackedWidget->removeWidget( mStackedWidget->currentWidget() );
190 const QString settingsType = mCurrentSettings->type();
193 if ( QgsMaterialSettingsWidget *w = am->createWidget() )
195 w->setSettings( mCurrentSettings.get(), mLayer );
196 w->setTechnique( mTechnique );
197 w->setPreviewVisible( mPreviewVisible );
198 mStackedWidget->addWidget( w );
199 mStackedWidget->setCurrentWidget( w );
206 mStackedWidget->setCurrentWidget( mPageDummy );
219 QVBoxLayout *vLayout =
new QVBoxLayout();
221 mWidget->setPreviewVisible(
true );
222 vLayout->addWidget( mWidget, 1 );
226 mWidget->setSettings(
settings,
nullptr );
229 mButtonBox =
new QDialogButtonBox( QDialogButtonBox::Cancel | QDialogButtonBox::Ok, Qt::Horizontal );
230 connect( mButtonBox, &QDialogButtonBox::accepted,
this, &QDialog::accept );
231 connect( mButtonBox, &QDialogButtonBox::rejected,
this, &QDialog::reject );
232 vLayout->addWidget( mButtonBox );
233 setLayout( vLayout );
234 setWindowTitle( tr(
"Material" ) );
241 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.
Basic shading material used for rendering based on the Phong shading model with three color component...
A container for the context for various read/write operations on objects.
Represents a vector layer which manages a vector based dataset.