Files
qt5-legatus-legacy/Lts/Plugins/InfrastructureManagement/Gui/IsmComboBox/ism_combobox.cpp
T
2026-08-13 18:33:10 +02:00

100 lines
3.2 KiB
C++
Executable File

/**
* @RDE_HEADER@
* InfrastructureManagement - IsmComboBox Gui Plugin
* $Id$
* $HeadURL$
* $Author$
* Created by Iuliana Ojog, SLSE, 2018-01-16
*/
#include "ism_combobox.h"
#include <InfrastructureManagement/ism_translation.h>
#include <LtsUtilsCore/json_object.h>
namespace InfrastructureManagement
{
bool IsmComboBox::fill(LtsWidgets::LtsComboBox *cbx, IsmComboBoxType type, LtsSession::LtsSession *session,
const std::shared_ptr<Interface::Dtc> &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<FrequencyBand>(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<LtsUtils::JsonArray>("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<LtsUtils::JsonObject> &radiosAsVector = radios.toVector<LtsUtils::JsonObject>();
for (const LtsUtils::JsonObject &radio : qAsConst(radiosAsVector))
{
FrequencyBand fb = static_cast<FrequencyBand>(radio.valueOr<int>("frequencyBand", -1));
int count = radio.valueOr<int>("count", 0);
if (fb != FrequencyBand::INVALID)
rs.radios.insert(fb,count);
}
rs.radioStationId = jo.valueOr<int>("stationId", 0);
return rs;
}
} // namespace InfrastructureManagement