Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Merge pull request #52329 from nirvn/sensors_framework_2
Sensor options panel within the project properties dialog
- Loading branch information
Showing
23 changed files
with
1,047 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
/************************************************************************ | ||
* This file has been generated automatically from * | ||
* * | ||
* src/core/sensor/qgssensormodel.h * | ||
* * | ||
* Do not edit manually ! Edit header and run scripts/sipify.pl again * | ||
************************************************************************/ | ||
|
||
|
||
|
||
|
||
|
||
class QgsSensorModel: QAbstractItemModel | ||
{ | ||
%Docstring(signature="appended") | ||
A QAbstractItemModel subclass for showing sensors within a :py:class:`QgsSensorManager`. | ||
|
||
.. versionadded:: 3.32 | ||
%End | ||
|
||
%TypeHeaderCode | ||
#include "qgssensormodel.h" | ||
%End | ||
public: | ||
|
||
enum class Column | ||
{ | ||
Name, | ||
LastValue, | ||
}; | ||
|
||
enum Role | ||
{ | ||
SensorType, | ||
SensorId, | ||
SensorName, | ||
SensorStatus, | ||
SensorLastValue, | ||
SensorLastTimestamp, | ||
Sensor, | ||
}; | ||
|
||
explicit QgsSensorModel( QgsSensorManager *manager, QObject *parent /TransferThis/ = 0 ); | ||
%Docstring | ||
Constructor for QgsSensorModel, for the specified ``manager`` and ``parent`` object. | ||
%End | ||
|
||
virtual QVariant data( const QModelIndex &index, int role ) const; | ||
|
||
virtual bool setData( const QModelIndex &index, const QVariant &value, int role = Qt::EditRole ); | ||
|
||
virtual Qt::ItemFlags flags( const QModelIndex &index ) const; | ||
|
||
virtual QVariant headerData( int section, Qt::Orientation orientation, | ||
int role = Qt::DisplayRole ) const; | ||
virtual QModelIndex index( int row, int column, | ||
const QModelIndex &parent = QModelIndex() ) const; | ||
virtual QModelIndex parent( const QModelIndex &index ) const; | ||
|
||
virtual int rowCount( const QModelIndex &parent = QModelIndex() ) const; | ||
|
||
virtual int columnCount( const QModelIndex &parent = QModelIndex() ) const; | ||
|
||
|
||
}; | ||
|
||
/************************************************************************ | ||
* This file has been generated automatically from * | ||
* * | ||
* src/core/sensor/qgssensormodel.h * | ||
* * | ||
* Do not edit manually ! Edit header and run scripts/sipify.pl again * | ||
************************************************************************/ |
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
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 |
Oops, something went wrong.