Container model of sensor channels. More...
#include <projecteditor.h>


Public Types | |
| enum | Field { FieldSensorId = Qt::UserRole, FieldSensorChannelNr, FieldSensorCustomName } |
Public Member Functions | |
| SensorChannelModel (QObject *parent=0) | |
| QVariant | data (const QModelIndex &index, int role) const |
| void | setConstraint (const int &sens_id) |
| int | constraint () |
| void | unconstrain () |
Container model of sensor channels.
{
FieldSensorId = Qt::UserRole,
FieldSensorChannelNr,
FieldSensorCustomName
};
| SensorChannelModel::SensorChannelModel | ( | QObject * | parent = 0 |
) | [inline] |
: SqlQueryModel(parent), sens_id(0){ setDependency("tbl_sensor_channel_calibrations"); setDependency("tbl_sensor_channels"); defaultQuery = QString("SELECT '#' || sens_chan_nr || ': ' || sens_chan_name || COALESCE(' [' || (SELECT count(*) || ' calibrations: last @ ' || max(sens_chan_cali_timestamp) || ']' FROM tbl_sensor_channel_calibrations scc WHERE scc.sens_id = c.sens_id AND scc.sens_chan_nr = c.sens_chan_nr)::text, ' [Never calibrated]'), " "sens_id, sens_chan_nr, " "sens_type || ' (' || sens_serialnr || ')' " "FROM tbl_sensor_channels c " "INNER JOIN tbl_sensors s USING (sens_id) "); unconstrain(); }
| int SensorChannelModel::constraint | ( | ) | [inline] |
{
return sens_id;
}
| QVariant SensorChannelModel::data | ( | const QModelIndex & | index, | |
| int | role | |||
| ) | const [inline] |
{
if (!index.isValid())
return QVariant();
switch (role) {
case SensorChannelModel::FieldSensorId:
return QSqlQueryModel::data(this->index(index.row(), 1));
case SensorChannelModel::FieldSensorChannelNr:
return QSqlQueryModel::data(this->index(index.row(), 2));
case SensorChannelModel::FieldSensorCustomName:
return QSqlQueryModel::data(this->index(index.row(), 3));
default:
return QSqlQueryModel::data(index, role);
}
}
| void SensorChannelModel::setConstraint | ( | const int & | sens_id | ) | [inline] |
{
this->sens_id = sens_id;
setQuery(Database::execStatic(defaultQuery + QString(" WHERE sens_id = ") + QString::number(sens_id) + " ORDER BY sens_id, sens_chan_nr "));
// This should check whether constraint is successfull;
if (query().lastError().isValid()) {
unconstrain();
return;
}
constrained = true;
}
| void SensorChannelModel::unconstrain | ( | ) | [inline] |
Referenced by SensorChannelModel(), and setConstraint().
{
setQuery(Database::execStatic(defaultQuery + " ORDER BY sens_id, sens_chan_nr "));
constrained = false;
sens_id = 0;
}
1.7.1