Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ui][sensors] Add a sensors panel in the project properties dialog
- Loading branch information
Showing
16 changed files
with
481 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
/*************************************************************************** | ||
qgsprojectsensorsettingswidget.cpp | ||
--------------------- | ||
begin : March 2022 | ||
copyright : (C) 2022 by Nyall Dawson | ||
email : nyall dot dawson at gmail dot com | ||
*************************************************************************** | ||
* * | ||
* This program is free software; you can redistribute it and/or modify * | ||
* it under the terms of the GNU General Public License as published by * | ||
* the Free Software Foundation; either version 2 of the License, or * | ||
* (at your option) any later version. * | ||
* * | ||
***************************************************************************/ | ||
|
||
#include "qgsprojectsensorsettingswidget.h" | ||
|
||
#include "qgis.h" | ||
#include "qgsabstractsensor.h" | ||
#include "qgsapplication.h" | ||
#include "qgsproject.h" | ||
#include "qgssensormanager.h" | ||
|
||
QgsProjectSensorSettingsWidget::QgsProjectSensorSettingsWidget( QWidget *parent ) | ||
: QgsOptionsPageWidget( parent ) | ||
{ | ||
setupUi( this ); | ||
|
||
QDomElement sensorElem = QgsProject::instance()->sensorManager()->writeXml( mPreviousSensors ); | ||
mPreviousSensors.appendChild( sensorElem ); | ||
|
||
const QList<QgsAbstractSensor *> sensors = QgsProject::instance()->sensorManager()->sensors(); | ||
for ( QgsAbstractSensor *sensor : sensors ) | ||
{ | ||
if ( sensor->status() == Qgis::DeviceConnectionStatus::Connected ) | ||
{ | ||
mConnectedSensors << sensor->id(); | ||
} | ||
} | ||
} | ||
|
||
void QgsProjectSensorSettingsWidget::cancel() | ||
{ | ||
// Capture connected state of current sensors even if we're about to revert as someone might have | ||
// activated a sensor then closed the dialog using the window bar's close button | ||
QList<QgsAbstractSensor *> sensors = QgsProject::instance()->sensorManager()->sensors(); | ||
for ( QgsAbstractSensor *sensor : sensors ) | ||
{ | ||
if ( sensor->status() == Qgis::DeviceConnectionStatus::Connected ) | ||
{ | ||
mConnectedSensors << sensor->id(); | ||
} | ||
} | ||
|
||
QgsProject::instance()->sensorManager()->clear(); | ||
QgsProject::instance()->sensorManager()->readXml( mPreviousSensors.documentElement(), mPreviousSensors ); | ||
|
||
sensors = QgsProject::instance()->sensorManager()->sensors(); | ||
for ( QgsAbstractSensor *sensor : sensors ) | ||
{ | ||
if ( mConnectedSensors.contains( sensor->id() ) ) | ||
{ | ||
sensor->connectSensor(); | ||
} | ||
} | ||
} | ||
|
||
void QgsProjectSensorSettingsWidget::apply() | ||
{ | ||
return; | ||
} | ||
|
||
bool QgsProjectSensorSettingsWidget::isValid() | ||
{ | ||
return true; | ||
} | ||
|
||
|
||
// | ||
// QgsProjectSensorSettingsWidgetFactory | ||
// | ||
|
||
QgsProjectSensorSettingsWidgetFactory::QgsProjectSensorSettingsWidgetFactory( QObject *parent ) | ||
: QgsOptionsWidgetFactory( tr( "Sensors" ), QgsApplication::getThemeIcon( QStringLiteral( "propertyicons/sensor.svg" ) ), QStringLiteral( "sensor" ) ) | ||
{ | ||
setParent( parent ); | ||
} | ||
|
||
|
||
QgsOptionsPageWidget *QgsProjectSensorSettingsWidgetFactory::createWidget( QWidget *parent ) const | ||
{ | ||
return new QgsProjectSensorSettingsWidget( parent ); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
/*************************************************************************** | ||
qgsprojectsensorsettingswidget.h | ||
--------------------- | ||
begin : March 2023 | ||
copyright : (C) 2023 by Mathieu Pellerin | ||
email : mathieu at opengis dot ch | ||
*************************************************************************** | ||
* * | ||
* This program is free software; you can redistribute it and/or modify * | ||
* it under the terms of the GNU General Public License as published by * | ||
* the Free Software Foundation; either version 2 of the License, or * | ||
* (at your option) any later version. * | ||
* * | ||
***************************************************************************/ | ||
|
||
#ifndef QGSPROJECTSENSORSETTINGSWIDGET_H | ||
#define QGSPROJECTSENSORSETTINGSWIDGET_H | ||
|
||
#include "ui_qgsprojectsensorettingswidgetbase.h" | ||
#include "qgsoptionswidgetfactory.h" | ||
|
||
#include <QDomDocument> | ||
|
||
class QgsProjectSensorSettingsWidget : public QgsOptionsPageWidget, private Ui::QgsProjectSensorSettingsWidgetBase | ||
{ | ||
Q_OBJECT | ||
public: | ||
|
||
QgsProjectSensorSettingsWidget( QWidget *parent = nullptr ); | ||
|
||
public slots: | ||
|
||
bool isValid() override; | ||
void apply() override; | ||
void cancel() override; | ||
|
||
private: | ||
|
||
QDomDocument mPreviousSensors; | ||
QStringList mConnectedSensors; | ||
}; | ||
|
||
|
||
class QgsProjectSensorSettingsWidgetFactory : public QgsOptionsWidgetFactory | ||
{ | ||
Q_OBJECT | ||
public: | ||
explicit QgsProjectSensorSettingsWidgetFactory( QObject *parent = nullptr ); | ||
|
||
QgsOptionsPageWidget *createWidget( QWidget *parent = nullptr ) const override; | ||
}; | ||
|
||
|
||
|
||
#endif // QGSPROJECTSENSORSETTINGSWIDGET_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
/*************************************************************************** | ||
qgssensortablewidget.h | ||
--------------------------------- | ||
begin : March 2023 | ||
copyright : (C) 2023 by Mathieu Pellerin | ||
email : mathieu at opengis dot ch | ||
*************************************************************************** | ||
* * | ||
* This program is free software; you can redistribute it and/or modify * | ||
* it under the terms of the GNU General Public License as published by * | ||
* the Free Software Foundation; either version 2 of the License, or * | ||
* (at your option) any later version. * | ||
* * | ||
***************************************************************************/ | ||
|
||
#include "qgssensortablewidget.h" | ||
|
||
#include "qgisapp.h" | ||
#include "qgsapplication.h" | ||
#include "qgssensormanager.h" | ||
#include "qgssensormodel.h" | ||
#include "qgsproject.h" | ||
|
||
#include <QTableWidget> | ||
|
||
QgsSensorTableWidget::QgsSensorTableWidget( QWidget *parent ) | ||
: QgsPanelWidget( parent ) | ||
{ | ||
setupUi( this ); | ||
setPanelTitle( tr( "Sensors List" ) ); | ||
setObjectName( QStringLiteral( "SensorsList" ) ); | ||
|
||
mActionConnection->setEnabled( false ); | ||
|
||
mSensorModel = new QgsSensorModel( QgsProject::instance()->sensorManager(), this ); | ||
|
||
mSensorTable->setModel( mSensorModel ); | ||
mSensorTable->horizontalHeader()->setSectionResizeMode( static_cast<int>( QgsSensorModel::Column::Name ), QHeaderView::Stretch ); | ||
mSensorTable->setSelectionBehavior( QAbstractItemView::SelectRows ); | ||
mSensorTable->setSelectionMode( QAbstractItemView::SingleSelection ); | ||
|
||
connect( QgsProject::instance()->sensorManager(), &QgsSensorManager::sensorStatusChanged, this, [ = ]( const QString & id ) | ||
{ | ||
const QModelIndex index = mSensorTable->currentIndex(); | ||
if ( index.isValid() ) | ||
{ | ||
if ( id == mSensorModel->data( index, QgsSensorModel::SensorId ).toString() ) | ||
{ | ||
QgsAbstractSensor *sensor = mSensorModel->data( index, QgsSensorModel::Sensor ).value<QgsAbstractSensor *>(); | ||
if ( sensor ) | ||
{ | ||
if ( sensor->status() == Qgis::DeviceConnectionStatus::Disconnected ) | ||
{ | ||
mActionConnection->setIcon( QgsApplication::getThemeIcon( QStringLiteral( "mActionStart.svg" ) ) ); | ||
} | ||
else | ||
{ | ||
mActionConnection->setIcon( QgsApplication::getThemeIcon( QStringLiteral( "mActionStop.svg" ) ) ); | ||
} | ||
} | ||
} | ||
} | ||
} ); | ||
|
||
connect( mSensorTable->selectionModel(), &QItemSelectionModel::currentChanged, this, [ = ]( const QModelIndex & current, const QModelIndex & ) | ||
{ | ||
mActionConnection->setEnabled( current.isValid() ); | ||
if ( current.isValid() && mSensorModel->data( current, QgsSensorModel::SensorStatus ).value<Qgis::DeviceConnectionStatus>() == Qgis::DeviceConnectionStatus::Connected ) | ||
{ | ||
mActionConnection->setIcon( QgsApplication::getThemeIcon( QStringLiteral( "mActionStop.svg" ) ) ); | ||
} | ||
else | ||
{ | ||
mActionConnection->setIcon( QgsApplication::getThemeIcon( QStringLiteral( "mActionStart.svg" ) ) ); | ||
} | ||
} ); | ||
|
||
connect( mActionConnection, &QToolButton::clicked, this, [ = ]() | ||
{ | ||
const QModelIndex index = mSensorTable->currentIndex(); | ||
if ( index.isValid() ) | ||
{ | ||
QgsAbstractSensor *sensor = mSensorModel->data( index, QgsSensorModel::Sensor ).value<QgsAbstractSensor *>(); | ||
if ( sensor ) | ||
{ | ||
if ( sensor->status() == Qgis::DeviceConnectionStatus::Disconnected ) | ||
{ | ||
sensor->connectSensor(); | ||
} | ||
else | ||
{ | ||
sensor->disconnectSensor(); | ||
} | ||
} | ||
} | ||
} ); | ||
} |
Oops, something went wrong.