#include "ism_combobox.h" #include #include #include namespace InfrastructureManagement { bool IsmComboBox::fill(LtsWidgets::LtsComboBox *cbx, IsmComboBoxType type, LtsSession::LtsSession *session, const std::shared_ptr &dtc, int filter) { Q_UNUSED(session); cbx->clear(); switch (type) { case IsmComboBoxType::CbRadioStations: { auto cb = [cbx,filter](const InfrastructureManagement::MainStructureElement &mse) { if (mse.structureElementTypeId == InfrastructureManagement::StructureElementType::RadioStation && !mse.isDeleted && mse.id > 0 ) { const RadioStation &rs = RadioStation::fromMSE(mse); if (((filter >= 0) && rs.radios.contains(static_cast(filter))) || (filter < 0)) { cbx->addItem(QString::fromStdString(mse.name), mse.id); cbx->setItemData(cbx->findData(mse.id), rs.radioStationId, Qt::UserRole + 1); } } }; dtc->mainStructureElements(cb); break; } case IsmComboBoxType::CbApproachingPoints: { auto cb = [cbx](const InfrastructureManagement::MainStructureElement &mse) { if ((mse.structureElementTypeId == InfrastructureManagement::StructureElementType::ApproachingPoint) && !mse.isDeleted && (mse.id > 0)) { cbx->addItem(QString::fromStdString(mse.name), mse.id); cbx->setItemData(cbx->findData(mse.id), mse.angle, Qt::UserRole + 1); } }; dtc->mainStructureElements(cb); break; } case IsmComboBoxType::CbScheduleStatus: { cbx->addItem(toString(ScheduleStatus::Active), static_cast(ScheduleStatus::Active)); cbx->addItem(toString(ScheduleStatus::Inactive), static_cast(ScheduleStatus::Inactive)); break; } case IsmComboBoxType::CbBridgeStatus: { cbx->addItem(toString(BridgeStatus::Intact), static_cast(BridgeStatus::Intact)); cbx->addItem(toString(BridgeStatus::Broken), static_cast(BridgeStatus::Broken)); } case IsmComboBoxType::CbUnknown: default: break; } return cbx->count() > 0; } RadioStation RadioStation::fromMSE(const MainStructureElement &mse) { RadioStation rs; rs.mse_id = mse.id; rs.name = QString::fromStdString(mse.name); LtsUtils::JsonObject jo = LtsUtils::JsonObject::fromJson(mse.properties); LtsUtils::JsonArray radios = jo.valueOr("radios", {}); const QVector &radiosAsVector = radios.toVector(); for (const LtsUtils::JsonObject &radio : std::as_const(radiosAsVector)) { FrequencyBand fb = static_cast(radio.valueOr("frequencyBand", -1)); int count = radio.valueOr("count", 0); if (fb != FrequencyBand::INVALID) rs.radios.insert(fb,count); } rs.radioStationId = jo.valueOr("stationId", 0); return rs; } }