Navigation Menu

Skip to content

Commit

Permalink
[gui][sensors] Remove the need to apply sensor settings
Browse files Browse the repository at this point in the history
  • Loading branch information
nirvn committed Apr 3, 2023
1 parent 6a7e929 commit 799b290
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 18 deletions.
6 changes: 6 additions & 0 deletions src/app/sensor/qgsprojectsensorsettingswidget.cpp
Expand Up @@ -84,6 +84,12 @@ void QgsProjectSensorSettingsWidget::cancel()

void QgsProjectSensorSettingsWidget::apply()
{
// If a sensor settings panel is open, apply changes
if ( QgsSensorSettingsWidget *widget = dynamic_cast<QgsSensorSettingsWidget *>( mPanelStack->currentPanel() ) )
{
widget->apply();
}

mPreviousSensors = QDomDocument();
QDomElement sensorElem = QgsProject::instance()->sensorManager()->writeXml( mPreviousSensors );
mPreviousSensors.appendChild( sensorElem );
Expand Down
16 changes: 5 additions & 11 deletions src/app/sensor/qgssensortablewidget.cpp
Expand Up @@ -36,9 +36,10 @@ QgsSensorSettingsWidget::QgsSensorSettingsWidget( QgsAbstractSensor *sensor, QWi
setupUi( this );
setPanelTitle( tr( "Sensor Settings" ) );
setObjectName( QStringLiteral( "SensorSettings" ) );
connect( this, &QgsPanelWidget::panelAccepted, this, [ = ]() { apply(); } );

mNameLineEdit->setText( sensor->name() );
connect( mNameLineEdit, &QLineEdit::textChanged, this, [ = ]() { mButtonBox->button( QDialogButtonBox::Apply )->setEnabled( true ); } );
connect( mNameLineEdit, &QLineEdit::textChanged, this, [ = ]() { mDirty = true; } );

const QMap<QString, QString> sensorTypes = QgsGui::sensorGuiRegistry()->sensorTypes();
for ( auto sensorIt = sensorTypes.begin(); sensorIt != sensorTypes.end(); ++sensorIt )
Expand All @@ -48,17 +49,10 @@ QgsSensorSettingsWidget::QgsSensorSettingsWidget( QgsAbstractSensor *sensor, QWi
mTypeComboBox->setCurrentIndex( mTypeComboBox->findData( sensor->type() ) );
connect( mTypeComboBox, static_cast<void ( QComboBox::* )( int )>( &QComboBox::currentIndexChanged ), this, [ = ]()
{
mButtonBox->button( QDialogButtonBox::Apply )->setEnabled( true );
mDirty = true;
setSensorWidget();
} );

mButtonBox->button( QDialogButtonBox::Apply )->setEnabled( false );
connect( mButtonBox->button( QDialogButtonBox::Apply ), &QAbstractButton::clicked, this, [ = ]()
{
mButtonBox->button( QDialogButtonBox::Apply )->setEnabled( false );
apply();
} );

setSensorWidget();
}

Expand All @@ -76,13 +70,13 @@ void QgsSensorSettingsWidget::setSensorWidget()
mSensorWidget->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding );
mSensorWidget->setSensor( mSensor );
mTypeLayout->addWidget( mSensorWidget );
connect( mSensorWidget, &QgsAbstractSensorWidget::changed, this, [ = ]() { mButtonBox->button( QDialogButtonBox::Apply )->setEnabled( true ); } );
connect( mSensorWidget, &QgsAbstractSensorWidget::changed, this, [ = ]() { mDirty = true; } );
}
}

void QgsSensorSettingsWidget::apply()
{
if ( mSensorWidget && mSensor )
if ( mDirty && mSensorWidget && mSensor )
{
mSensor->disconnectSensor();
if ( !mSensorWidget->updateSensor( mSensor ) )
Expand Down
2 changes: 2 additions & 0 deletions src/app/sensor/qgssensortablewidget.h
Expand Up @@ -43,6 +43,8 @@ class APP_EXPORT QgsSensorSettingsWidget : public QgsPanelWidget, private Ui::Qg

QgsAbstractSensor *mSensor = nullptr;
QgsAbstractSensorWidget *mSensorWidget = nullptr;

bool mDirty = false;
};

class APP_EXPORT QgsSensorTableWidget : public QgsPanelWidget, private Ui::QgsSensorTableWidgetBase
Expand Down
7 changes: 0 additions & 7 deletions src/ui/sensor/qgssensorsettingswidgetbase.ui
Expand Up @@ -57,13 +57,6 @@
<layout class="QVBoxLayout" name="mTypeLayout"/>
</widget>
</item>
<item>
<widget class="QDialogButtonBox" name="mButtonBox">
<property name="standardButtons">
<set>QDialogButtonBox::Apply</set>
</property>
</widget>
</item>
</layout>
</widget>
<customwidgets>
Expand Down

0 comments on commit 799b290

Please sign in to comment.