/** * @RDE_HEADER@ * HMI Plugin for AlarmManagement (Interface for access from other Plugins) * $Id$ * $HeadURL$ * $Author$ * Created by Steve Kemayou, SLSE, 2023-05-26 */ #include "alm_emergency_call_model.h" #include #include #include namespace AlarmManagement { EmergencyCallModel::EmergencyCallModel(QObject *parent) : LtsWidgets::LtsAbstractTableModel( { tr("Id"), tr("Sample Time"), tr("Incoming Time"), tr("Name"), tr("Issi"), tr("Position"), tr("Expired"), tr("Operator"), tr("Deleted Timestamp"), tr("Comment"), }, parent) , m_dtc(nullptr) , m_logger(getLogger("EmergencyCallModel")) {} QVariant EmergencyCallModel::data(const QModelIndex &index, int role) const { if (role != Qt::DisplayRole || !indexIsValid(index)) return QVariant(); const AlarmManagement::AlmEmergencyCall &almEmergency = m_vecData.at(index.row()); switch (index.column()) { case Columns::ID: return almEmergency.id(); case SAMPLE_TIME: return QDateTime::fromMSecsSinceEpoch(almEmergency.sampleTime()); case INCOMING_TIME: return QDateTime::fromMSecsSinceEpoch(almEmergency.incomingTime()); case NAME: return QString::fromStdString(almEmergency.name()); case ISSI: return almEmergency.issi(); case POSITION: { if (std::isnan(almEmergency.position().lat())) return tr("---"); const QString mgrs = LtsCoordTrans::mgrsFromGeographic(almEmergency.position().lon(), almEmergency.position().lat()); return mgrs; } case EXPIRED: return almEmergency.expired(); case OPERATION_ID: { if (almEmergency.operatorId() == 0) return QStringLiteral("-"); return QString::fromStdString(m_opmDtc.get()->user(almEmergency.operatorId()).name()); } case DELETED_TIMESTAMP: return QDateTime::fromMSecsSinceEpoch(almEmergency.deleted()); case COMMENT: return QString::fromStdString(almEmergency.comment()); default: break; } // switch return {}; } bool EmergencyCallModel::initModel(const std::shared_ptr &dtc, const std::shared_ptr &opmDtc) { m_dtc = dtc; m_opmDtc = opmDtc; auto cb = [this](const AlarmManagement::AlmEmergencyCall & d) { onAlarmEmergencyCallChanged(d, DataModification::eAdded); }; m_dtc->almEmergencyCalls(cb); connect(m_dtc.get(), &Interface::Dtc::almEmergencyCallChanged, this, &EmergencyCallModel::onAlarmEmergencyCallChanged); return true; } void EmergencyCallModel::onAlarmEmergencyCallChanged(const AlarmManagement::AlmEmergencyCall &data, const DataModification modType) { const int id = data.id(); int row = findRowForId(id); switch (modType) { case DataModification::eModified: { if (row < 0) return; setRowData(row, data); break; } case DataModification::eAdded: insertRow(data); break; case DataModification::eRemoved: removeRow(row); break; } } ///************************** /// EmergencyCallProxyModel ///************************** /*! * \brief EmergencyCallProxyModel::setSourceModel * \param sourceModel */ void EmergencyCallProxyModel::setSourceModel(QAbstractItemModel *sourceModel) { m_sourceModel = qobject_cast(sourceModel); LtsWidgets::LtsColumnFilterProxyModel::setSourceModel(sourceModel); } void EmergencyCallProxyModel::hideByExerciseStopped(bool show) { if (m_hideByExerciseStopped == show) return; m_hideByExerciseStopped = show; invalidateFilter(); } void EmergencyCallProxyModel::setShowExpired(bool show) { if (m_showExpired == show) return; m_showExpired = show; invalidateFilter(); } bool EmergencyCallProxyModel::filterAcceptsRow(int source_row, const QModelIndex &source_parent) const { Q_UNUSED(source_parent) return checkFilter(source_row); } bool EmergencyCallProxyModel::checkFilter(int source_row) const { const auto sos = m_sourceModel->getRowData(source_row); if ((sos.expired() && !showExpired()) || (exerciseStopped() && !sos.expired())) return false; return true; } } // namespace AlarmManagement