new_docker_build.sh gains Group 12 (212 GUI/Data plugins); fixes LtsUtilsGuiDds visibility (LTO-stripped exports), LtsProjectionWorkstation unity name shadow, 6 unity-off dirs (dup file-scope statics, ddsftc INTERFACE sources) and reconfigures BUILD_FILTERMANAGEMENT/BUILD_PLUGINS_SERVICEMONITOR=ON
352 lines
14 KiB
C++
Executable File
352 lines
14 KiB
C++
Executable File
|
|
|
|
|
|
#include "pdm_combobox.h"
|
|
#include <QtCore/QJsonDocument>
|
|
#include <QtCore/QJsonObject>
|
|
#include <QtCore/QSet>
|
|
#include <QtCore/QSortFilterProxyModel>
|
|
#include <QtGui/QStandardItemModel>
|
|
#include <LtsUtilsSettings/settings.h>
|
|
#include <LtsWidgets/lts_combo_box.h>
|
|
#include <ProjectDataManagement/pdm_translation.h>
|
|
|
|
// External DDS types - only available when external dependencies are present
|
|
#ifdef BUILD_WITH_EXTERNAL_DDS
|
|
#include <ProjectDataManagement/pdm_dtc.h>
|
|
#include <training_area_telegrams.h>
|
|
#endif
|
|
|
|
namespace ProjectDataManagement
|
|
{
|
|
namespace PdmComboBox
|
|
{
|
|
|
|
static QLatin1String emptyEntryComboBox = QLatin1String("--");
|
|
|
|
void ChargeTypeFilterProxyModel::setPropertyFilter(const QString &property, const QVariant &value)
|
|
{
|
|
if (m_property == property && m_value == value)
|
|
return;
|
|
m_property = property;
|
|
m_value = value;
|
|
invalidate();
|
|
}
|
|
|
|
void ChargeTypeFilterProxyModel::setSourceModel(QAbstractItemModel *model)
|
|
{
|
|
m_model = qobject_cast<QStandardItemModel *>(model);
|
|
QSortFilterProxyModel::setSourceModel(model);
|
|
}
|
|
|
|
bool ChargeTypeFilterProxyModel::filterAcceptsRow(int source_row, const QModelIndex &source_parent) const
|
|
{
|
|
if (!m_model || source_parent != QModelIndex())
|
|
return QSortFilterProxyModel::filterAcceptsRow(source_row, source_parent);
|
|
if (m_property.isEmpty() || m_value.isNull())
|
|
return true;
|
|
QStandardItem *item = m_model->item(source_row);
|
|
QJsonObject obj = item->data(Qt::UserRole + 2).toJsonObject();
|
|
if (obj.isEmpty())
|
|
{
|
|
QJsonDocument doc(QJsonDocument::fromJson(item->data(Qt::UserRole + 1).toByteArray()));
|
|
if (doc.isObject())
|
|
obj = doc.object();
|
|
else
|
|
obj = QJsonObject();
|
|
|
|
if (obj.isEmpty())
|
|
obj[QStringLiteral("empty")] = 1;
|
|
item->setData(obj, Qt::UserRole + 2);
|
|
}
|
|
return obj.value(m_property) == m_value;
|
|
}
|
|
|
|
#ifdef BUILD_WITH_EXTERNAL_DDS
|
|
void fillGearClass(QComboBox *cbx, GearClass gearClass, const std::shared_ptr<Interface::Dtc> &dtc)
|
|
{
|
|
QStandardItemModel *itemModel = new QStandardItemModel(cbx);
|
|
ChargeTypeFilterProxyModel *fpm = new ChargeTypeFilterProxyModel(cbx);
|
|
fpm->setSourceModel(itemModel);
|
|
cbx->setModel(fpm);
|
|
|
|
|
|
const auto charges = dtc->chargesForGearClass(gearClass);
|
|
for (const ChargeType &charge : charges)
|
|
{
|
|
QStandardItem *item = new QStandardItem(dtc->trChargeTypeShortName(charge.id, true));
|
|
item->setToolTip(dtc->trChargeTypeName(charge.id, true));
|
|
item->setData(charge.id, CBUserRoles::Id);
|
|
item->setData(QByteArray::fromStdString(charge.properties), CBUserRoles::Properties);
|
|
itemModel->appendRow(item);
|
|
}
|
|
}
|
|
|
|
void fillIgniterType(QComboBox *cbx, int chargeTypeId, const std::shared_ptr<Interface::Dtc> &dtc)
|
|
{
|
|
QStandardItemModel *itemModel = new QStandardItemModel(cbx);
|
|
cbx->setModel(itemModel);
|
|
QStandardItem *itemEmpty = new QStandardItem(emptyEntryComboBox);
|
|
itemEmpty->setData(-1, CBUserRoles::Id);
|
|
itemModel->appendRow(itemEmpty);
|
|
|
|
const auto igniters = dtc->ignitersForChargeType(chargeTypeId);
|
|
for (const IgniterType &igniter : igniters)
|
|
{
|
|
QStandardItem *item = new QStandardItem(dtc->trIgniterTypeShortName(igniter.id));
|
|
item->setToolTip(dtc->trIgniterTypeName(igniter.id));
|
|
item->setData(igniter.id, CBUserRoles::Id);
|
|
item->setData(QByteArray::fromStdString(igniter.properties), CBUserRoles::Properties);
|
|
itemModel->appendRow(item);
|
|
}
|
|
itemModel->sort(0, Qt::AscendingOrder);
|
|
|
|
|
|
if (cbx->count() == 2)
|
|
cbx->setCurrentIndex(1);
|
|
}
|
|
|
|
void fillIgniterFunction(QComboBox *cbx, int chargeTypeId, int igniterTypeId, const std::shared_ptr<Interface::Dtc> &dtc)
|
|
{
|
|
QStandardItemModel *itemModel = new QStandardItemModel(cbx);
|
|
cbx->setModel(itemModel);
|
|
QStandardItem *itemEmpty = new QStandardItem(emptyEntryComboBox);
|
|
itemEmpty->setData(-1, CBUserRoles::Id);
|
|
itemModel->appendRow(itemEmpty);
|
|
|
|
const auto chargeTypeIgTypeIgFunMap = dtc->igniterFunctionsForChargeTypeIgniterType(chargeTypeId, igniterTypeId);
|
|
for (const ChargeTypeIgniterTypeIgniterFunction &chargeTypeIgTypeIgFun : chargeTypeIgTypeIgFunMap)
|
|
{
|
|
QStandardItem *item = new QStandardItem(dtc->trIgniterFunctionShortName(chargeTypeIgTypeIgFun.igniterFunctionId));
|
|
item->setToolTip(dtc->trIgniterFunctionName(chargeTypeIgTypeIgFun.igniterFunctionId));
|
|
item->setData(chargeTypeIgTypeIgFun.igniterFunctionId, CBUserRoles::Id);
|
|
item->setData(QByteArray::fromStdString(chargeTypeIgTypeIgFun.properties), CBUserRoles::Properties);
|
|
itemModel->appendRow(item);
|
|
}
|
|
itemModel->sort(0, Qt::AscendingOrder);
|
|
|
|
|
|
if (cbx->count() == 2)
|
|
cbx->setCurrentIndex(1);
|
|
}
|
|
|
|
void fillLoadType(QComboBox *cbx, int chargeTypeId, const std::shared_ptr<Interface::Dtc> &dtc)
|
|
{
|
|
QStandardItemModel *itemModel = new QStandardItemModel(cbx);
|
|
cbx->setModel(itemModel);
|
|
QStandardItem *itemEmpty = new QStandardItem(emptyEntryComboBox);
|
|
itemEmpty->setData(-1, CBUserRoles::Id);
|
|
itemModel->appendRow(itemEmpty);
|
|
|
|
const auto loads = dtc->loadsForChargeType(chargeTypeId);
|
|
for (const LoadType &load : loads)
|
|
{
|
|
QStandardItem *item = new QStandardItem(dtc->trLoadTypeShortName(load.id));
|
|
item->setToolTip(dtc->trLoadTypeName(load.id));
|
|
item->setData(load.id, CBUserRoles::Id);
|
|
itemModel->appendRow(item);
|
|
}
|
|
itemModel->sort(0, Qt::AscendingOrder);
|
|
|
|
|
|
if (cbx->count() == 2)
|
|
cbx->setCurrentIndex(1);
|
|
}
|
|
|
|
void fillTargetType(QComboBox *cbx, const std::shared_ptr<Interface::Dtc> &dtc)
|
|
{
|
|
QStandardItemModel *itemModel = new QStandardItemModel(cbx);
|
|
cbx->setModel(itemModel);
|
|
QStandardItem *itemEmpty = new QStandardItem(emptyEntryComboBox);
|
|
itemEmpty->setData(-1, CBUserRoles::Id);
|
|
itemModel->appendRow(itemEmpty);
|
|
|
|
const auto targeTypes = dtc->targetTypes();
|
|
for (const TargetType &targetType : targeTypes)
|
|
{
|
|
QStandardItem *item = new QStandardItem(dtc->trTargetTypeName(targetType.id));
|
|
item->setToolTip(dtc->trTargetTypeName(targetType.id));
|
|
item->setData(targetType.id, CBUserRoles::Id);
|
|
itemModel->appendRow(item);
|
|
}
|
|
itemModel->sort(0, Qt::AscendingOrder);
|
|
}
|
|
|
|
void fillTargetSubType(QComboBox *cbx, int targetTypeId, const std::shared_ptr<Interface::Dtc> &dtc)
|
|
{
|
|
QStandardItemModel *itemModel = new QStandardItemModel(cbx);
|
|
cbx->setModel(itemModel);
|
|
|
|
const auto targetSubTypeVec = dtc->targetSubTypesForTargetType(targetTypeId);
|
|
QStandardItem *itemEmpty = new QStandardItem(emptyEntryComboBox);
|
|
itemEmpty->setData(-1, TargetSubTypeRole::Id);
|
|
itemModel->appendRow(itemEmpty);
|
|
|
|
for (const TargetSubType &targetSubType : targetSubTypeVec)
|
|
{
|
|
QStandardItem *item = new QStandardItem(dtc->trTargetSubTypeName(targetSubType.id));
|
|
item->setToolTip(dtc->trTargetSubTypeName(targetSubType.id));
|
|
item->setData(targetSubType.id, TargetSubTypeRole::Id);
|
|
item->setData(QString::fromStdString(targetSubType.abbreviation), TargetSubTypeRole::Abbreviation);
|
|
itemModel->appendRow(item);
|
|
}
|
|
itemModel->sort(0, Qt::AscendingOrder);
|
|
}
|
|
|
|
void fillFirePurpose(QComboBox *cbx, const std::shared_ptr<Interface::Dtc> &dtc)
|
|
{
|
|
QStandardItemModel *itemModel = new QStandardItemModel(cbx);
|
|
cbx->setModel(itemModel);
|
|
QStandardItem *itemEmpty = new QStandardItem(emptyEntryComboBox);
|
|
itemEmpty->setData(-1, CBUserRoles::Id);
|
|
itemModel->appendRow(itemEmpty);
|
|
|
|
const auto &firePurposes = dtc->firePurposes();
|
|
for (const FirePurpose &firePurpose : firePurposes)
|
|
{
|
|
QStandardItem *item = new QStandardItem(dtc->trFirePurposeName(firePurpose.id));
|
|
item->setToolTip(dtc->trFirePurposeName(firePurpose.id));
|
|
item->setData(firePurpose.id, CBUserRoles::Id);
|
|
item->setData(QByteArray::fromStdString(firePurpose.properties), CBUserRoles::Properties);
|
|
itemModel->appendRow(item);
|
|
}
|
|
itemModel->sort(0, Qt::AscendingOrder);
|
|
}
|
|
#endif // BUILD_WITH_EXTERNAL_DDS
|
|
|
|
bool fill(QComboBox *cbx, PdmComboBoxType type)
|
|
{
|
|
if (!cbx)
|
|
return false;
|
|
|
|
const QVariant curData = cbx->currentData();
|
|
|
|
QSignalBlocker block(cbx);
|
|
cbx->clear();
|
|
|
|
switch (type)
|
|
{
|
|
#ifdef BUILD_WITH_EXTERNAL_DDS
|
|
case PdmComboBoxType::CbLanguage:
|
|
{
|
|
const QString languages = LtsUtils::ProjectSettings::getInstance()->value(QStringLiteral("pdm"), QStringLiteral("EquipmentLanguages")).toString();
|
|
const QStringList slLang = languages.split(QLatin1Char(','));
|
|
QSet<int> alreadySeen;
|
|
alreadySeen += static_cast<int>(LanguageConfiguration::LanguageConfiguration_NoChange);
|
|
cbx->addItem(toString(LanguageConfiguration::LanguageConfiguration_NoChange), static_cast<int>(LanguageConfiguration::LanguageConfiguration_NoChange));
|
|
for (const QString &r : slLang)
|
|
{
|
|
const int langId = r.toInt();
|
|
if (alreadySeen.contains(langId))
|
|
continue;
|
|
alreadySeen += langId;
|
|
cbx->addItem(toString(static_cast<LanguageConfiguration>(langId)), static_cast<int>(static_cast<LanguageConfiguration>(langId)));
|
|
}
|
|
break;
|
|
}
|
|
case PdmComboBoxType::CbOperationMode:
|
|
{
|
|
cbx->addItem(toString(OperationMode::OperationMode_NoChange), static_cast<int>(OperationMode::OperationMode_NoChange));
|
|
cbx->addItem(toString(OperationMode::OperationMode_Normal), static_cast<int>(OperationMode::OperationMode_Normal));
|
|
cbx->addItem(toString(OperationMode::OperationMode_BeStill), static_cast<int>(OperationMode::OperationMode_BeStill));
|
|
break;
|
|
}
|
|
case PdmComboBoxType::CbModeHelmet:
|
|
case PdmComboBoxType::CbModeVest:
|
|
{
|
|
cbx->addItem(toString(WphMode::WphMode_NoChange), static_cast<int>(WphMode::WphMode_NoChange));
|
|
cbx->addItem(toString(WphMode::WphMode_Without), static_cast<int>(WphMode::WphMode_Without));
|
|
cbx->addItem(toString(WphMode::WphMode_With), static_cast<int>(WphMode::WphMode_With));
|
|
break;
|
|
}
|
|
case PdmComboBoxType::CbPersonalProtection:
|
|
{
|
|
cbx->addItem(toString(PersonalProtection::PersonalProtection_NoChange), static_cast<int>(PersonalProtection::PersonalProtection_NoChange));
|
|
cbx->addItem(toString(PersonalProtection::PersonalProtection_Without), static_cast<int>(PersonalProtection::PersonalProtection_Without));
|
|
cbx->addItem(toString(PersonalProtection::PersonalProtection_Suit), static_cast<int>(PersonalProtection::PersonalProtection_Suit));
|
|
cbx->addItem(toString(PersonalProtection::PersonalProtection_SuitAndGloves), static_cast<int>(PersonalProtection::PersonalProtection_SuitAndGloves));
|
|
break;
|
|
}
|
|
case PdmComboBoxType::CbProtectionLevel:
|
|
{
|
|
cbx->addItem(toString(ProtectionLevel::ProtectionLevel_NoChange), static_cast<int>(ProtectionLevel::ProtectionLevel_NoChange));
|
|
cbx->addItem(toString(ProtectionLevel::ProtectionLevel_IdzBs), static_cast<int>(ProtectionLevel::ProtectionLevel_IdzBs));
|
|
cbx->addItem(toString(ProtectionLevel::ProtectionLevel_IdzEs), static_cast<int>(ProtectionLevel::ProtectionLevel_IdzEs));
|
|
cbx->addItem(toString(ProtectionLevel::ProtectionLevel_Ksk), static_cast<int>(ProtectionLevel::ProtectionLevel_Ksk));
|
|
cbx->addItem(toString(ProtectionLevel::ProtectionLevel_SoldierWithBodyArmor), static_cast<int>(ProtectionLevel::ProtectionLevel_SoldierWithBodyArmor));
|
|
cbx->addItem(toString(ProtectionLevel::ProtectionLevel_SoldierActor), static_cast<int>(ProtectionLevel::ProtectionLevel_SoldierActor));
|
|
break;
|
|
}
|
|
case PdmComboBoxType::CbHandgrenadeSearchMode:
|
|
{
|
|
cbx->addItem(toString(HandgrenadeSearchMode::HandgrenadeSearchMode_NoChange), static_cast<int>(HandgrenadeSearchMode::HandgrenadeSearchMode_NoChange));
|
|
cbx->addItem(toString(HandgrenadeSearchMode::HandgrenadeSearchMode_On), static_cast<int>(HandgrenadeSearchMode::HandgrenadeSearchMode_On));
|
|
cbx->addItem(toString(HandgrenadeSearchMode::HandgrenadeSearchMode_Off), static_cast<int>(HandgrenadeSearchMode::HandgrenadeSearchMode_Off));
|
|
break;
|
|
}
|
|
case PdmComboBoxType::CbInternationalMode:
|
|
{
|
|
cbx->addItem(toString(InternationalMode::InternationalMode_NoChange), static_cast<int>(InternationalMode::InternationalMode_NoChange));
|
|
cbx->addItem(toString(InternationalMode::InternationalMode_On), static_cast<int>(InternationalMode::InternationalMode_On));
|
|
cbx->addItem(toString(InternationalMode::InternationalMode_Off), static_cast<int>(InternationalMode::InternationalMode_Off));
|
|
break;
|
|
}
|
|
case PdmComboBoxType::CbABCProtectionMode:
|
|
{
|
|
cbx->addItem(toString(ABCProtectionMode::ABCProtectionMode_NoChange), static_cast<int>(ABCProtectionMode::ABCProtectionMode_NoChange));
|
|
cbx->addItem(toString(ABCProtectionMode::ABCProtectionMode_On), static_cast<int>(ABCProtectionMode::ABCProtectionMode_On));
|
|
cbx->addItem(toString(ABCProtectionMode::ABCProtectionMode_Off), static_cast<int>(ABCProtectionMode::ABCProtectionMode_Off));
|
|
break;
|
|
}
|
|
#endif // BUILD_WITH_EXTERNAL_DDS
|
|
case PdmComboBoxType::CbUnkown:
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
|
|
if (curData.isValid() && (cbx->findData(curData) != -1))
|
|
cbx->setCurrentIndex(cbx->findData(curData));
|
|
else if (cbx->count())
|
|
cbx->setCurrentIndex(0);
|
|
|
|
cbx->model()->sort(0, Qt::AscendingOrder);
|
|
return true;
|
|
}
|
|
|
|
#ifdef BUILD_WITH_EXTERNAL_DDS
|
|
bool fill(QComboBox *cbx, GearClass gearClass, const std::shared_ptr<Interface::Dtc> &dtc)
|
|
{
|
|
if (!cbx)
|
|
return false;
|
|
|
|
const QVariant curData = cbx->currentData();
|
|
|
|
QSignalBlocker block(cbx);
|
|
|
|
cbx->clear();
|
|
fillGearClass(cbx, gearClass, dtc);
|
|
|
|
if (curData.isValid() && (cbx->findData(curData) != -1))
|
|
cbx->setCurrentIndex(cbx->findData(curData));
|
|
else if (cbx->count())
|
|
cbx->setCurrentIndex(0);
|
|
|
|
return true;
|
|
}
|
|
#endif // BUILD_WITH_EXTERNAL_DDS
|
|
|
|
bool setChargeTypePropertyFilter(QComboBox *cbx, const QString &property, const QVariant &value)
|
|
{
|
|
if (!cbx)
|
|
return false;
|
|
ChargeTypeFilterProxyModel *fpm = qobject_cast<ChargeTypeFilterProxyModel *>(cbx->model());
|
|
if (!fpm)
|
|
return false;
|
|
fpm->setPropertyFilter(property, value);
|
|
return true;
|
|
}
|
|
|
|
}
|
|
}
|