/** * @RDE_HEADER@ * InfrastructureManagement - IsmComboBox Gui Plugin * $Id$ * $HeadURL$ * $Author$ * Created by Iuliana Ojog, SLSE, 2018-01-16 */ #include "ism_combobox.h" #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), ScheduleStatus::Active); cbx->addItem(toString(ScheduleStatus::Inactive), ScheduleStatus::Inactive); break; } case IsmComboBoxType::CbBridgeStatus: { cbx->addItem(toString(BridgeStatus::Intact), BridgeStatus::Intact); cbx->addItem(toString(BridgeStatus::Broken), 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", {}); // The best and easiest solution is to iterate over the JsonArray right!? // for (const QJsonValue &radioValues : qAsConst(radios)) // for (const JsonObject &radioObject : qAsConst(radios)) const QVector &radiosAsVector = radios.toVector(); for (const LtsUtils::JsonObject &radio : qAsConst(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; } } // namespace InfrastructureManagement