24 : QAbstractItemModel( parent )
25 , mSensorManager( manager )
35 const QList<QgsAbstractSensor *> sensors = manager->
sensors();
38 if ( !mSensorIds.contains( sensor->id() ) )
40 mSensorIds << sensor->id();
61 switch (
index.column() )
65 return sensor->
name();
70 switch ( sensor->
status() )
73 return tr(
"Disconnected" );
76 return tr(
"Connecting" );
92 return sensor->
type();
102 return sensor->
name();
107 return QVariant::fromValue<Qgis::DeviceConnectionStatus>( sensor->
status() );
122 return QVariant::fromValue<QgsAbstractSensor *>( sensor );
133 if (
index.row() < 0 ||
index.row() >=
rowCount( QModelIndex() ) || role != Qt::EditRole )
140 switch (
index.column() )
144 sensor->
setName( value.toString() );
157 Qt::ItemFlags
flags = QAbstractItemModel::flags(
index );
163 return flags | Qt::ItemIsEditable;
171 if ( role == Qt::DisplayRole )
173 if ( orientation == Qt::Vertical )
175 return QVariant( section + 1 );
182 return QVariant( tr(
"Name" ) );
185 return QVariant( tr(
"Last Value" ) );
200 if ( !hasIndex( row, column,
parent ) )
201 return QModelIndex();
205 return createIndex( row, column );
208 return QModelIndex();
213 return QModelIndex();
220 return mSensorIds.size();
230void QgsSensorModel::sensorAdded(
const QString &
id )
232 beginInsertRows( QModelIndex(), mSensorIds.size(), mSensorIds.size() );
237void QgsSensorModel::sensorRemoved(
const QString &
id )
239 const int sensorIndex = mSensorIds.indexOf(
id );
240 if ( sensorIndex < 0 )
243 beginRemoveRows( QModelIndex(), sensorIndex, sensorIndex );
244 mSensorIds.removeAt( sensorIndex );
248void QgsSensorModel::sensorNameChanged(
const QString &
id )
250 const int sensorIndex = mSensorIds.indexOf(
id );
251 if ( sensorIndex < 0 )
257void QgsSensorModel::sensorStatusChanged(
const QString &
id )
259 const int sensorIndex = mSensorIds.indexOf(
id );
260 if ( sensorIndex < 0 )
266void QgsSensorModel::sensorDataCaptured(
const QString &
id )
268 const int sensorIndex = mSensorIds.indexOf(
id );
269 if ( sensorIndex < 0 )
@ Connected
Device is successfully connected.
@ Connecting
Device is connecting.
@ Disconnected
Device is disconnected.
An abstract base class for sensor classes.
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.