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 );
104 mMaterialTypeComboBox->blockSignals(
false );
105 materialTypeChanged();
110 mFilterByTechnique = enabled;
111 rebuildAvailableTypes();
117 rebuildAvailableTypes();
122 mMaterialTypeComboBox->setCurrentIndex( mMaterialTypeComboBox->findData(
settings->type() ) );
123 mCurrentSettings.reset(
settings->clone() );
125 updateMaterialWidget();
130 return mCurrentSettings ? std::unique_ptr< QgsAbstractMaterialSettings >( mCurrentSettings->clone() ) :
nullptr;
135 mMaterialTypeComboBox->setCurrentIndex( mMaterialTypeComboBox->findData( type ) );
136 materialTypeChanged();
150 mPreviewVisible = visible;
153 w->setPreviewVisible( visible );
157void QgsMaterialWidget::materialTypeChanged()
159 std::unique_ptr<QgsAbstractMaterialSettings> currentSettings(
settings() );
160 const QString existingType = currentSettings ? currentSettings->type() : QString();
161 const QString newType = mMaterialTypeComboBox->currentData().toString();
162 if ( existingType == newType )
169 std::unique_ptr<QgsAbstractMaterialSettings> newMaterial( am->create() );
172 if ( currentSettings )
175 QDomElement tempElem = doc.createElement( u
"temp"_s );
180 mCurrentSettings = std::move( newMaterial );
181 updateMaterialWidget();
187void QgsMaterialWidget::materialWidgetChanged()
189 if ( QgsMaterialSettingsWidget *w = qobject_cast<QgsMaterialSettingsWidget *>( mStackedWidget->currentWidget() ) )
191 mCurrentSettings = w->settings();
196void QgsMaterialWidget::updateMaterialWidget()
198 if ( mStackedWidget->currentWidget() != mPageDummy )
201 if ( QgsMaterialSettingsWidget *w = qobject_cast<QgsMaterialSettingsWidget *>( mStackedWidget->currentWidget() ) )
203 mStackedWidget->removeWidget( mStackedWidget->currentWidget() );
206 const QString settingsType = mCurrentSettings->type();
209 if ( QgsMaterialSettingsWidget *w = am->createWidget() )
211 w->setSettings( mCurrentSettings.get(), mLayer );
212 w->setTechnique( mTechnique );
214 w->setPreviewVisible( mPreviewVisible );
216 mStackedWidget->addWidget( w );
217 mStackedWidget->setCurrentWidget( w );
225 mStackedWidget->setCurrentWidget( mPageDummy );
238 QVBoxLayout *vLayout =
new QVBoxLayout();
240 mWidget->setPreviewVisible(
true );
241 vLayout->addWidget( mWidget, 1 );
245 mWidget->setSettings(
settings,
nullptr );
248 mButtonBox =
new QDialogButtonBox( QDialogButtonBox::Cancel | QDialogButtonBox::Ok, Qt::Horizontal );
249 connect( mButtonBox, &QDialogButtonBox::accepted,
this, &QDialog::accept );
250 connect( mButtonBox, &QDialogButtonBox::rejected,
this, &QDialog::reject );
251 vLayout->addWidget( mButtonBox );
252 setLayout( vLayout );
253 setWindowTitle( tr(
"Material" ) );
260 mWidget->setTechnique( technique );
265 mWidget->setFilterByTechnique( enabled );
270 return mWidget->settings();
MaterialWidgetMode
Modes for material settings widgets.
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.