fix (partially) #44226 (#44723)

This commit is contained in:
Vincent Cloarec 2021-08-17 02:54:24 -04:00 committed by GitHub
parent a4b1d0bf13
commit 9a4f0f5d60
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 65 additions and 57 deletions

View File

@ -63,7 +63,7 @@ QgsNewMeshLayerDialog::QgsNewMeshLayerDialog( QWidget *parent, Qt::WindowFlags f
connect( mFormatComboBox, static_cast<void ( QComboBox::* )( int )>( &QComboBox::currentIndexChanged ), connect( mFormatComboBox, static_cast<void ( QComboBox::* )( int )>( &QComboBox::currentIndexChanged ),
this, &QgsNewMeshLayerDialog::onFormatChanged ); this, &QgsNewMeshLayerDialog::onFormatChanged );
connect( mFileWidget, &QgsFileWidget::fileChanged, this, &QgsNewMeshLayerDialog::onFilePathChanged ); connect( mFileWidget, &QgsFileWidget::fileChanged, this, &QgsNewMeshLayerDialog::onFilePathChanged );
connect( mEmptyMeshRadioButton, &QRadioButton::toggled, this, &QgsNewMeshLayerDialog::updateDialog ); connect( mInitializeMeshGroupBox, &QGroupBox::toggled, this, &QgsNewMeshLayerDialog::updateDialog );
connect( mMeshFileRadioButton, &QRadioButton::toggled, this, &QgsNewMeshLayerDialog::updateDialog ); connect( mMeshFileRadioButton, &QRadioButton::toggled, this, &QgsNewMeshLayerDialog::updateDialog );
connect( mMeshFromFileWidget, &QgsFileWidget::fileChanged, this, &QgsNewMeshLayerDialog::updateDialog ); connect( mMeshFromFileWidget, &QgsFileWidget::fileChanged, this, &QgsNewMeshLayerDialog::updateDialog );
connect( mMeshProjectComboBox, &QgsMapLayerComboBox::layerChanged, this, &QgsNewMeshLayerDialog::updateDialog ); connect( mMeshProjectComboBox, &QgsMapLayerComboBox::layerChanged, this, &QgsNewMeshLayerDialog::updateDialog );
@ -107,7 +107,7 @@ void QgsNewMeshLayerDialog::updateSourceMeshframe()
{ {
mMeshProjectComboBox->setEnabled( false ); mMeshProjectComboBox->setEnabled( false );
mMeshFromFileWidget->setEnabled( false ); mMeshFromFileWidget->setEnabled( false );
if ( mEmptyMeshRadioButton->isChecked() ) if ( !mInitializeMeshGroupBox->isChecked() )
{ {
mSourceMeshFromFile.reset(); mSourceMeshFromFile.reset();
mSourceMeshFrameReady = true; mSourceMeshFrameReady = true;
@ -222,7 +222,7 @@ bool QgsNewMeshLayerDialog::apply()
QgsMeshLayer *source = nullptr; QgsMeshLayer *source = nullptr;
if ( mEmptyMeshRadioButton->isChecked() ) if ( !mInitializeMeshGroupBox->isChecked() )
{ {
crs = mProjectionSelectionWidget->crs(); crs = mProjectionSelectionWidget->crs();
} }
@ -247,7 +247,17 @@ bool QgsNewMeshLayerDialog::apply()
result = providerMetadata->createMeshData( mesh, fileName, format, crs ); result = providerMetadata->createMeshData( mesh, fileName, format, crs );
if ( result ) if ( result )
{ {
std::unique_ptr<QgsMeshLayer> newMeshLayer = std::make_unique<QgsMeshLayer>( fileName, mLayerNameLineEdit->text(), QStringLiteral( "mdal" ) ); QString layerName = mLayerNameLineEdit->text();
if ( layerName.isEmpty() )
{
layerName = fileName;
QFileInfo fileInfo( fileName );
layerName = fileInfo.baseName();
}
std::unique_ptr<QgsMeshLayer> newMeshLayer = std::make_unique<QgsMeshLayer>( fileName, layerName, QStringLiteral( "mdal" ) );
if ( newMeshLayer->crs() != crs )
newMeshLayer->setCrs( crs );
if ( newMeshLayer->isValid() ) if ( newMeshLayer->isValid() )
QgsProject::instance()->addMapLayer( newMeshLayer.release(), true, true ); QgsProject::instance()->addMapLayer( newMeshLayer.release(), true, true );

View File

@ -14,45 +14,42 @@
<string>New Mesh Layer</string> <string>New Mesh Layer</string>
</property> </property>
<layout class="QGridLayout" name="gridLayout1"> <layout class="QGridLayout" name="gridLayout1">
<item row="0" column="0"> <item row="4" column="1">
<widget class="QgsProjectionSelectionWidget" name="mProjectionSelectionWidget" native="true"/>
</item>
<item row="1" column="1">
<widget class="QLineEdit" name="mLayerNameLineEdit">
<property name="text">
<string/>
</property>
</widget>
</item>
<item row="6" column="0" colspan="2">
<widget class="QDialogButtonBox" name="buttonBox">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Help|QDialogButtonBox::Ok</set>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_3"> <widget class="QLabel" name="label_3">
<property name="text"> <property name="text">
<string>Layer name</string> <string>Layer name</string>
</property> </property>
</widget> </widget>
</item> </item>
<item row="0" column="1"> <item row="3" column="0">
<widget class="QLineEdit" name="mLayerNameLineEdit">
<property name="text">
<string>New mesh layer</string>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_2">
<property name="text">
<string>File name</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QgsFileWidget" name="mFileWidget" native="true"/>
</item>
<item row="2" column="0">
<widget class="QLabel" name="label"> <widget class="QLabel" name="label">
<property name="text"> <property name="text">
<string>File format</string> <string>File format</string>
</property> </property>
</widget> </widget>
</item> </item>
<item row="2" column="1"> <item row="5" column="0" colspan="2">
<widget class="QComboBox" name="mFormatComboBox"/> <widget class="QGroupBox" name="mInitializeMeshGroupBox">
</item>
<item row="3" column="1">
<widget class="QgsProjectionSelectionWidget" name="mProjectionSelectionWidget" native="true"/>
</item>
<item row="4" column="0" colspan="2">
<widget class="QGroupBox" name="groupBox">
<property name="sizePolicy"> <property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Expanding"> <sizepolicy hsizetype="Preferred" vsizetype="Expanding">
<horstretch>0</horstretch> <horstretch>0</horstretch>
@ -62,6 +59,12 @@
<property name="title"> <property name="title">
<string>Initialize Mesh Using</string> <string>Initialize Mesh Using</string>
</property> </property>
<property name="checkable">
<bool>true</bool>
</property>
<property name="checked">
<bool>false</bool>
</property>
<layout class="QGridLayout" name="gridLayout"> <layout class="QGridLayout" name="gridLayout">
<property name="leftMargin"> <property name="leftMargin">
<number>0</number> <number>0</number>
@ -75,52 +78,48 @@
<property name="bottomMargin"> <property name="bottomMargin">
<number>0</number> <number>0</number>
</property> </property>
<item row="2" column="0"> <item row="1" column="1">
<widget class="QgsFileWidget" name="mMeshFromFileWidget" native="true"/>
</item>
<item row="0" column="1">
<widget class="QgsMapLayerComboBox" name="mMeshProjectComboBox"/>
</item>
<item row="2" column="0" colspan="2">
<widget class="QTextBrowser" name="mInformationTextBrowser"/>
</item>
<item row="1" column="0">
<widget class="QRadioButton" name="mMeshFileRadioButton"> <widget class="QRadioButton" name="mMeshFileRadioButton">
<property name="text"> <property name="text">
<string>Mesh from file</string> <string>Mesh from file</string>
</property> </property>
</widget> </widget>
</item> </item>
<item row="1" column="0"> <item row="0" column="0">
<widget class="QRadioButton" name="mMeshProjectRadioButton"> <widget class="QRadioButton" name="mMeshProjectRadioButton">
<property name="text"> <property name="text">
<string>Mesh from the current project</string> <string>Mesh from the current project</string>
</property> </property>
</widget>
</item>
<item row="0" column="0">
<widget class="QRadioButton" name="mEmptyMeshRadioButton">
<property name="text">
<string>Empty mesh</string>
</property>
<property name="checked"> <property name="checked">
<bool>true</bool> <bool>true</bool>
</property> </property>
</widget> </widget>
</item> </item>
<item row="2" column="1">
<widget class="QgsFileWidget" name="mMeshFromFileWidget" native="true"/>
</item>
<item row="1" column="1">
<widget class="QgsMapLayerComboBox" name="mMeshProjectComboBox"/>
</item>
<item row="3" column="0" colspan="2">
<widget class="QTextBrowser" name="mInformationTextBrowser"/>
</item>
</layout> </layout>
</widget> </widget>
</item> </item>
<item row="5" column="0" colspan="2"> <item row="3" column="1">
<widget class="QDialogButtonBox" name="buttonBox"> <widget class="QComboBox" name="mFormatComboBox"/>
<property name="orientation"> </item>
<enum>Qt::Horizontal</enum> <item row="0" column="0">
</property> <widget class="QLabel" name="label_2">
<property name="standardButtons"> <property name="text">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Help|QDialogButtonBox::Ok</set> <string>File name</string>
</property> </property>
</widget> </widget>
</item> </item>
<item row="0" column="1">
<widget class="QgsFileWidget" name="mFileWidget" native="true"/>
</item>
</layout> </layout>
</widget> </widget>
<customwidgets> <customwidgets>
@ -145,7 +144,6 @@
<tabstops> <tabstops>
<tabstop>mLayerNameLineEdit</tabstop> <tabstop>mLayerNameLineEdit</tabstop>
<tabstop>mFormatComboBox</tabstop> <tabstop>mFormatComboBox</tabstop>
<tabstop>mEmptyMeshRadioButton</tabstop>
<tabstop>mMeshProjectRadioButton</tabstop> <tabstop>mMeshProjectRadioButton</tabstop>
<tabstop>mMeshProjectComboBox</tabstop> <tabstop>mMeshProjectComboBox</tabstop>
<tabstop>mMeshFileRadioButton</tabstop> <tabstop>mMeshFileRadioButton</tabstop>