Files
qt-migration-legatus/qt6-after/qt6-migrated-legatus/Lts/Plugins/InfrastructureManagement/Gui/IsmComboBox/ism_combobox.cpp
T

95 lines
2.9 KiB
C++
Executable File

#include "ism_combobox.h"
#include <utility>
#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", {});
const QVector<LtsUtils::JsonObject> &radiosAsVector = radios.toVector<LtsUtils::JsonObject>();
for (const LtsUtils::JsonObject &radio : std::as_const(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;
}
}