17#include "moc_qgssensormodel.cpp" 
   25  : QAbstractItemModel( parent )
 
   26  , mSensorManager( manager )
 
   36  const QList<QgsAbstractSensor *> sensors = manager->
sensors();
 
   39    if ( !mSensorIds.contains( sensor->id() ) )
 
   41      mSensorIds << sensor->id();
 
 
   62      switch ( 
index.column() )
 
   66          return sensor->
name();
 
   71          switch ( sensor->
status() )
 
   74              return tr( 
"Disconnected" );
 
   77              return tr( 
"Connecting" );
 
   93      return sensor->
type();
 
  103      return sensor->
name();
 
  108      return QVariant::fromValue<Qgis::DeviceConnectionStatus>( sensor->
status() );
 
  123      return QVariant::fromValue<QgsAbstractSensor *>( sensor );
 
 
  134  if ( 
index.row() < 0 || 
index.row() >= 
rowCount( QModelIndex() ) || role != Qt::EditRole )
 
  141  switch ( 
index.column() )
 
  145      sensor->
setName( value.toString() );
 
 
  158  Qt::ItemFlags 
flags = QAbstractItemModel::flags( 
index );
 
  164      return flags | Qt::ItemIsEditable;
 
 
  172  if ( role == Qt::DisplayRole )
 
  174    if ( orientation == Qt::Vertical ) 
 
  176      return QVariant( section + 1 );
 
  183          return QVariant( tr( 
"Name" ) );
 
  186          return QVariant( tr( 
"Last Value" ) );
 
 
  201  if ( !hasIndex( row, column, 
parent ) )
 
  202    return QModelIndex();
 
  206    return createIndex( row, column );
 
  209  return QModelIndex();
 
 
  214  return QModelIndex();
 
 
  221    return mSensorIds.size();
 
 
  231void QgsSensorModel::sensorAdded( 
const QString &
id )
 
  233  beginInsertRows( QModelIndex(), mSensorIds.size(), mSensorIds.size() );
 
  238void QgsSensorModel::sensorRemoved( 
const QString &
id )
 
  240  const int sensorIndex = mSensorIds.indexOf( 
id );
 
  241  if ( sensorIndex < 0 )
 
  244  beginRemoveRows( QModelIndex(), sensorIndex, sensorIndex );
 
  245  mSensorIds.removeAt( sensorIndex );
 
  249void QgsSensorModel::sensorNameChanged( 
const QString &
id )
 
  251  const int sensorIndex = mSensorIds.indexOf( 
id );
 
  252  if ( sensorIndex < 0 )
 
  258void QgsSensorModel::sensorStatusChanged( 
const QString &
id )
 
  260  const int sensorIndex = mSensorIds.indexOf( 
id );
 
  261  if ( sensorIndex < 0 )
 
  267void QgsSensorModel::sensorDataCaptured( 
const QString &
id )
 
  269  const int sensorIndex = mSensorIds.indexOf( 
id );
 
  270  if ( sensorIndex < 0 )
 
@ Connected
Device is successfully connected.
 
@ Connecting
Device is connecting.
 
@ Disconnected
Device is disconnected.
 
An abstract base class for sensors.
 
QString id() const
Returns the sensor ID.
 
Qgis::DeviceConnectionStatus status() const
Returns the current sensor status.
 
QgsAbstractSensor::SensorData data() const
Returns the latest captured data from the sensor.
 
QString name() const
Returns the user-friendly name identifying the sensor.
 
virtual QString type() const
Returns the sensor type.
 
void setName(const QString &name)
Sets the user-friendly name identfying the sensor.
 
void sensorNameChanged(const QString &id)
Emitted when a sensor name has changed.
 
QList< QgsAbstractSensor * > sensors() const
Returns a list of pointers to all registered sensors.
 
void sensorDataCaptured(const QString &id)
Emitted when newly captured data from a sensor has occurred.
 
QgsAbstractSensor * sensor(const QString &id) const
Returns a registered sensor pointer matching a given id.
 
void sensorAdded(const QString &id)
Emitted when a sensor has been registered.
 
void sensorAboutToBeRemoved(const QString &id)
Emitted when a sensor is about to be removed.
 
void sensorStatusChanged(const QString &id)
Emitted when a sensor status has changed.
 
Qt::ItemFlags flags(const QModelIndex &index) const override
 
QgsSensorModel(QgsSensorManager *manager, QObject *parent=nullptr)
Constructor for QgsSensorModel, for the specified manager and parent object.
 
QModelIndex parent(const QModelIndex &index) const override
 
QModelIndex index(int row, int column, const QModelIndex &parent=QModelIndex()) const override
 
QVariant headerData(int section, Qt::Orientation orientation, int role=Qt::DisplayRole) const override
 
int rowCount(const QModelIndex &parent=QModelIndex()) const override
 
int columnCount(const QModelIndex &parent=QModelIndex()) const override
 
QVariant data(const QModelIndex &index, int role) const override
 
@ SensorLastTimestamp
Sensor timestamp of last captured value.
 
@ Sensor
Sensor object pointer.
 
@ SensorStatus
Sensor status (disconnected, connected, etc.)
 
@ SensorLastValue
Sensor last captured value.
 
bool setData(const QModelIndex &index, const QVariant &value, int role=Qt::EditRole) override
 
#define BUILTIN_UNREACHABLE
 
QVariant lastValue
Last captured sensor value stored as a QVariant.
 
QDateTime lastTimestamp
Timestamp of last captured sensor value.