Initial commit
This commit is contained in:
commit
b7d90b9afe
16245 files changed
+3396666
No files matched your search
@@ -0,0 +1,52 @@
|
||||
#
|
||||
# $Id$
|
||||
# $HeadURL$
|
||||
# $Author$
|
||||
#
|
||||
# Created by Malte Diers, SLSE, 2017-02-13
|
||||
#
|
||||
|
||||
SET(aes_base_gui_SRCS
|
||||
aes_base_edit.cpp
|
||||
aes_base_edit.h
|
||||
aes_base_gui_plugin.cpp
|
||||
aes_base_gui_plugin.h
|
||||
aes_base_model.cpp
|
||||
aes_base_model.h
|
||||
aes_base_exports.h
|
||||
aes_itemlist.cpp
|
||||
aes_itemlist.h
|
||||
aes_pixmap_label.cpp
|
||||
aes_pixmap_label.h
|
||||
InfoView/aes_base_info.cpp
|
||||
InfoView/aes_base_info.h
|
||||
)
|
||||
|
||||
NGL_WRAP_UI(aes_base_gui_SRCS
|
||||
aes_itemlist.ui
|
||||
InfoView/aes_base_info.ui
|
||||
)
|
||||
|
||||
NGL_ADD_LIBRARY(WS AesBaseGui SHARED ${aes_base_gui_SRCS})
|
||||
NGL_TARGET_LINK_LIBRARIES(AesBaseGui
|
||||
PRIVATE
|
||||
ExmDataPluginInterface
|
||||
LtsPrinting
|
||||
ngltools
|
||||
PpmGuiComboboxPluginInterface
|
||||
SituationMapGuiPluginInterface
|
||||
svcAesCommon
|
||||
PUBLIC
|
||||
PdmDataPluginInterface
|
||||
PdmGuiPluginInterface
|
||||
LtsCoordTrans # because it's used by every lib which links against AesBaseGui
|
||||
ltsCoordWidget # because it's used by every lib which links against AesBaseGui
|
||||
LtsDataView # because it's used by every lib which links against AesBaseGui
|
||||
LtsSession
|
||||
LtsSessionData
|
||||
LtsUtilsGuiDds
|
||||
LtsWidgets
|
||||
Qt5::Widgets
|
||||
)
|
||||
|
||||
NGL_INSTALL_TARGET(AesBaseGui)
|
||||
@@ -0,0 +1,122 @@
|
||||
#include "aes_base_info.h"
|
||||
#include "ui_aes_base_info.h"
|
||||
|
||||
#include <Plugins/ProjectDataManagement/pdm_data_plugin_interface.h>
|
||||
#include <Plugins/ParticipantManagement/ppm_data_plugin_interface.h>
|
||||
#include <LtsSession/lts_session.h>
|
||||
#include <QDateTime>
|
||||
#include <AreaEffectSimulation/aes_translation.h>
|
||||
#include <ParticipantManagement/ppm_translation.h>
|
||||
|
||||
namespace AreaEffectSimulation
|
||||
{
|
||||
|
||||
BaseInfo::BaseInfo(QWidget *parent)
|
||||
: LtsDialog(parent)
|
||||
, m_session(nullptr)
|
||||
, m_ui(new Ui::BaseInfo)
|
||||
{
|
||||
m_ui->setupUi(this);
|
||||
}
|
||||
|
||||
BaseInfo::~BaseInfo()
|
||||
{
|
||||
delete m_ui;
|
||||
}
|
||||
|
||||
void BaseInfo::retranslate()
|
||||
{
|
||||
translate(m_ui, tr("AES Info"));
|
||||
}
|
||||
|
||||
void BaseInfo::setEffectStart(qint64 effectStart)
|
||||
{
|
||||
if (effectStart > 0)
|
||||
{
|
||||
m_ui->lblEffectStart->show();
|
||||
m_ui->lbxEffectStart->show();
|
||||
m_ui->lblEffectStart->setText(QDateTime::fromMSecsSinceEpoch(effectStart).toString());
|
||||
}
|
||||
else
|
||||
{
|
||||
m_ui->lblEffectStart->hide();
|
||||
m_ui->lbxEffectStart->hide();
|
||||
}
|
||||
}
|
||||
|
||||
void BaseInfo::setEffectDuration(int32_t effectDuration)
|
||||
{
|
||||
if (effectDuration > 0)
|
||||
{
|
||||
m_ui->lblEffectDuration->show();
|
||||
m_ui->lbxEffectDuration->show();
|
||||
m_ui->lblEffectDuration->setText(LtsWidgets::readableDuration(effectDuration, false));
|
||||
}
|
||||
else
|
||||
{
|
||||
m_ui->lblEffectDuration->hide();
|
||||
m_ui->lbxEffectDuration->hide();
|
||||
}
|
||||
}
|
||||
|
||||
bool BaseInfo::setData(const AesItem *item)
|
||||
{
|
||||
if (!m_session)
|
||||
return false;
|
||||
|
||||
std::shared_ptr<ProjectDataManagement::Interface::Dtc> pdmDtc = nullptr;
|
||||
std::shared_ptr<ParticipantManagement::Interface::Dtc> ppmDtc = nullptr;
|
||||
m_session->getDtc<ParticipantManagement::DataInterface>(ppmDtc);
|
||||
|
||||
if (!m_session->getDtc<ProjectDataManagement::DataInterface>(pdmDtc) || !pdmDtc )
|
||||
return false;
|
||||
|
||||
setEffectDuration(item->effectDuration());
|
||||
m_ui->lblIdentifier->setText(QString::fromStdString(item->name().c_str()));
|
||||
m_ui->lblChargeType->setText(pdmDtc->trChargeTypeShortName(item->chargeStruct().chargeTypeId(), true));
|
||||
m_ui->lblChargeType->setToolTip(pdmDtc->trChargeTypeName(item->chargeStruct().chargeTypeId(), true));
|
||||
m_ui->lblEffectState->setText(AreaEffectSimulation::toString(item->effectStateId()));
|
||||
|
||||
|
||||
setEffectStart(item->effectStart().is_set() ? item->effectStart().get() : 0);
|
||||
|
||||
if (item->participantId().is_set())
|
||||
{
|
||||
if (!ppmDtc)
|
||||
m_ui->lblParticipant->setText(tr("ID: %1").arg(item->participantId().get()));
|
||||
else
|
||||
{
|
||||
ParticipantManagement::Participant participant = ppmDtc->participant(item->partyId().get());
|
||||
m_ui->lblParticipant->setText(QString::fromStdString(participant.name()));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
m_ui->lblParticipant->hide();
|
||||
m_ui->lbxParticipant->hide();
|
||||
}
|
||||
|
||||
if (item->partyId().is_set())
|
||||
{
|
||||
if (!ppmDtc)
|
||||
m_ui->lblParty->setText(tr("ID: %1").arg(item->partyId().get()));
|
||||
else
|
||||
{
|
||||
ParticipantManagement::Party party = ppmDtc->party(item->partyId().get());
|
||||
m_ui->lblParty->setText(ParticipantManagement::trPartyName(party.name()));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
m_ui->lblParty->hide();
|
||||
m_ui->lblParty->hide();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void BaseInfo::init(LtsSession::LtsSessionDataDds *session)
|
||||
{
|
||||
m_session = session;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
#pragma once
|
||||
|
||||
#include "../aes_base_exports.h"
|
||||
#include <LtsWidgets/lts_dialog.h>
|
||||
#include <Services/AreaEffectSimulation/aes.hpp>
|
||||
|
||||
|
||||
namespace Ui
|
||||
{
|
||||
class BaseInfo;
|
||||
}
|
||||
|
||||
namespace LtsSession
|
||||
{
|
||||
class LtsSessionDataDds;
|
||||
}
|
||||
|
||||
|
||||
namespace AreaEffectSimulation
|
||||
{
|
||||
|
||||
class AESBASEGUI_EXPORT BaseInfo : public LtsWidgets::LtsDialog
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit BaseInfo(QWidget *parent = nullptr);
|
||||
~BaseInfo();
|
||||
|
||||
bool setData(const AesItem *item);
|
||||
void init(LtsSession::LtsSessionDataDds *session);
|
||||
|
||||
void setEffectStart(qint64 effectStart);
|
||||
void setEffectDuration(int32_t effectDuration);
|
||||
|
||||
private:
|
||||
void retranslate() override;
|
||||
|
||||
LtsSession::LtsSessionDataDds *m_session;
|
||||
Ui::BaseInfo *m_ui;
|
||||
};
|
||||
|
||||
}
|
||||
@@ -0,0 +1,179 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>BaseInfo</class>
|
||||
<widget class="QWidget" name="BaseInfo">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>139</width>
|
||||
<height>162</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string notr="true">Aes Info</string>
|
||||
</property>
|
||||
<property name="toolTip">
|
||||
<string notr="true"/>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout">
|
||||
<property name="leftMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="topMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="rightMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="bottomMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="spacing">
|
||||
<number>6</number>
|
||||
</property>
|
||||
<item row="4" column="0">
|
||||
<widget class="QLabel" name="lbxEffectState">
|
||||
<property name="toolTip">
|
||||
<string/>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Effect State:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="1">
|
||||
<widget class="QLabel" name="lblEffectStart">
|
||||
<property name="toolTip">
|
||||
<string/>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string notr="true">today</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="4" column="1">
|
||||
<widget class="QLabel" name="lblEffectState">
|
||||
<property name="toolTip">
|
||||
<string/>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string notr="true">Active</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="0">
|
||||
<widget class="QLabel" name="lbxEffectDuration">
|
||||
<property name="toolTip">
|
||||
<string/>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Effect Duration:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="1">
|
||||
<widget class="QLabel" name="lblEffectDuration">
|
||||
<property name="toolTip">
|
||||
<string/>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string notr="true">1m</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="0">
|
||||
<widget class="QLabel" name="lbxIdentifier">
|
||||
<property name="toolTip">
|
||||
<string/>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Identifier:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="1">
|
||||
<widget class="QLabel" name="lblIdentifier">
|
||||
<property name="toolTip">
|
||||
<string/>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string notr="true">name</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="5" column="0">
|
||||
<widget class="QLabel" name="lbxParty">
|
||||
<property name="toolTip">
|
||||
<string/>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Party:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="5" column="1">
|
||||
<widget class="QLabel" name="lblParty">
|
||||
<property name="toolTip">
|
||||
<string/>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string notr="true">RED</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<widget class="QLabel" name="lbxEffectStart">
|
||||
<property name="toolTip">
|
||||
<string/>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Effect Start:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="0">
|
||||
<widget class="QLabel" name="lbxChargeTye">
|
||||
<property name="toolTip">
|
||||
<string/>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Charge Type:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="1">
|
||||
<widget class="QLabel" name="lblChargeType">
|
||||
<property name="toolTip">
|
||||
<string/>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string notr="true">Mun</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="6" column="0">
|
||||
<widget class="QLabel" name="lbxParticipant">
|
||||
<property name="toolTip">
|
||||
<string/>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Participant:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="6" column="1">
|
||||
<widget class="QLabel" name="lblParticipant">
|
||||
<property name="toolTip">
|
||||
<string/>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string notr="true">Bla</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<resources/>
|
||||
<connections/>
|
||||
</ui>
|
||||
+357
@@ -0,0 +1,357 @@
|
||||
/**
|
||||
* @RDE_HEADER@
|
||||
* AreaEffectSimulation - Contamination Edit Dialog
|
||||
* $Id$
|
||||
* $HeadURL$
|
||||
* $Author$
|
||||
* Created by Patric Karwat, SLSE, 2016-07-07
|
||||
*/
|
||||
|
||||
|
||||
#include "aes_base_edit.h"
|
||||
|
||||
#include <Plugins/AreaEffectSimulation/aes_data_plugin_interface.h>
|
||||
#include <Plugins/SituationMapPlugin/situation_map_gui_plugin_interface.h>
|
||||
#include <Plugins/ParticipantManagement/ppm_data_plugin_interface.h>
|
||||
#include <Plugins/ExerciseManagement/exm_data_plugin_interface.h>
|
||||
#include <PluginInterfaces/gui_plugin_interface.h>
|
||||
#include <LtsWidgets/lts_date_time_edit.h>
|
||||
#include <LtsCoordTrans/lts_coord_widget.h>
|
||||
#include <LtsCoordTrans/lts_coord_trans.h>
|
||||
#include <QSpinBox>
|
||||
#include <QJsonDocument>
|
||||
|
||||
namespace AreaEffectSimulation
|
||||
{
|
||||
|
||||
BaseEdit::BaseEdit(const QString &menuGroup, const QString &loggerName, QWidget *parent, LtsWidgets::ButtonCombination buttonCombination)
|
||||
: LtsWidgets::LtsDialog(parent, buttonCombination)
|
||||
, m_aesItem()
|
||||
, m_dtc(nullptr)
|
||||
, m_ftc(nullptr)
|
||||
, m_sitMapGuiIfc(nullptr)
|
||||
, m_ppmGuiCbxIfc(nullptr)
|
||||
, m_session(nullptr)
|
||||
, m_menuGroup(menuGroup)
|
||||
, m_requestHelper(new LtsUtils::RequestHelper(this))
|
||||
, m_logger(getLogger(loggerName))
|
||||
{
|
||||
m_aesItem.id(0);
|
||||
connect(this, &BaseEdit::visibilityChanged, this, &BaseEdit::onVisibilityChanged);
|
||||
}
|
||||
|
||||
void BaseEdit::setCombobxToValueIfPossible(QComboBox *cbx, int val)
|
||||
{
|
||||
int idx = cbx->findData(val);
|
||||
if (idx >= 0)
|
||||
cbx->setCurrentIndex(idx);
|
||||
}
|
||||
|
||||
void BaseEdit::onAesItemCreateReply(const Core::FunctionReplyObject &replyObject)
|
||||
{
|
||||
m_requestHelper->requestReply(replyObject);
|
||||
if (!replyObject.error() && m_sitMapGuiIfc)
|
||||
m_sitMapGuiIfc->removePreviewObject();
|
||||
}
|
||||
|
||||
void BaseEdit::onAesItemModifyReply(const Core::FunctionReplyObject &replyObject)
|
||||
{
|
||||
m_requestHelper->requestReply(replyObject);
|
||||
|
||||
if (!replyObject.error() && m_sitMapGuiIfc )
|
||||
m_sitMapGuiIfc->removePreviewObject();
|
||||
}
|
||||
|
||||
bool BaseEdit::isModifiable() const
|
||||
{
|
||||
AesEffectState effectState = m_aesItem.effectStateId();
|
||||
return (effectState == AreaEffectSimulation::AesEffectState_def::EsPaused ||
|
||||
effectState == AreaEffectSimulation::AesEffectState_def::EsActivated ||
|
||||
effectState == AreaEffectSimulation::AesEffectState_def::EsPrepared ||
|
||||
effectState == AreaEffectSimulation::AesEffectState_def::EsCreated ||
|
||||
effectState == AreaEffectSimulation::AesEffectState_def::EsUnknown ||
|
||||
effectState == AreaEffectSimulation::AesEffectState_def::EsReceived) &&
|
||||
(!m_session->isReplayPartition()) &&
|
||||
(m_session->app() != LtsAppDescriptor::App::OC); // not OC-App
|
||||
}
|
||||
|
||||
bool BaseEdit::isOnlyNameModifiable() const
|
||||
{
|
||||
AesEffectState effectState = m_aesItem.effectStateId();
|
||||
return (effectState == AreaEffectSimulation::AesEffectState_def::EsPaused ||
|
||||
effectState == AreaEffectSimulation::AesEffectState_def::EsActivated) &&
|
||||
(!m_session->isReplayPartition()) &&
|
||||
(m_session->app() != LtsAppDescriptor::App::OC); // not OC-App
|
||||
}
|
||||
|
||||
void BaseEdit::correctSpinBoxValue()
|
||||
{
|
||||
QSpinBox *sb = qobject_cast<QSpinBox*>(sender());
|
||||
if (sb)
|
||||
return correctSpinBoxValueInternal(sb);
|
||||
|
||||
QDoubleSpinBox *dsb = qobject_cast<QDoubleSpinBox*>(sender());
|
||||
if (dsb)
|
||||
return correctSpinBoxValueInternal(dsb);
|
||||
}
|
||||
|
||||
void BaseEdit::onVisibilityChanged(bool visible)
|
||||
{
|
||||
if (!m_sitMapGuiIfc)
|
||||
return;
|
||||
|
||||
if (!visible)
|
||||
m_sitMapGuiIfc->removePreviewObject();
|
||||
else
|
||||
showPreviewObject();
|
||||
}
|
||||
|
||||
void BaseEdit::correctSpinBoxValueInternal(QSpinBox *sb)
|
||||
{
|
||||
if (!sb)
|
||||
return;
|
||||
|
||||
int step = sb->singleStep();
|
||||
if (step == 1)
|
||||
return;
|
||||
|
||||
int value = sb->value();
|
||||
int remainder = (value - sb->minimum()) % step;
|
||||
if (remainder == 0)
|
||||
return;
|
||||
|
||||
if (2 * remainder > step)
|
||||
value += (step - remainder);
|
||||
else
|
||||
value -= remainder;
|
||||
|
||||
if (value > sb->maximum())
|
||||
value -= step;
|
||||
|
||||
if(value < sb->minimum())
|
||||
value = sb->minimum();
|
||||
|
||||
sb->setValue(value);
|
||||
}
|
||||
|
||||
void BaseEdit::correctSpinBoxValueInternal(QDoubleSpinBox *sb)
|
||||
{
|
||||
if (!sb)
|
||||
return;
|
||||
|
||||
double step = sb->singleStep();
|
||||
if (qFuzzyCompare(step, pow(10, sb->decimals())))
|
||||
return;
|
||||
|
||||
double value = sb->value();
|
||||
double remainder = fmod(value - sb->minimum(), step);
|
||||
if (qFuzzyCompare(remainder, 0))
|
||||
return;
|
||||
|
||||
if (2 * remainder > step)
|
||||
value += (step - remainder);
|
||||
else
|
||||
value -= remainder;
|
||||
|
||||
if (value > sb->maximum())
|
||||
value -= step;
|
||||
|
||||
if (value < sb->minimum())
|
||||
value = sb->minimum();
|
||||
|
||||
sb->setValue(value);
|
||||
}
|
||||
|
||||
bool BaseEdit::hasValidEffectStart(LtsWidgets::LtsDateTimeEdit *dte) const
|
||||
{
|
||||
if (isOnlyNameModifiable())
|
||||
return true;
|
||||
// if there is visible a enabled/disable checkbox -> also allow 0 as effect start
|
||||
if (dte->isCheckable() && !dte->isChecked())
|
||||
return true;
|
||||
const auto ms = dte->msecsSinceEpoch();
|
||||
return ms > m_session->partitionTime();
|
||||
}
|
||||
|
||||
void BaseEdit::setEffectStartEnabled(LtsWidgets::LtsDateTimeEdit *dte, bool enable)
|
||||
{
|
||||
if (enable)
|
||||
{
|
||||
int exerciseId = m_session->exerciseId();
|
||||
std::shared_ptr<ExerciseManagement::Interface::Dtc> exmDtc;
|
||||
m_session->getDtc<ExerciseManagement::DataInterface>(exmDtc);
|
||||
ExerciseManagement::Exercise exercise = exmDtc->exercise(exerciseId);
|
||||
|
||||
// Enablen der gesamten Checkbox nur, wenn Übung läuft:
|
||||
enable = (exercise.state() == ExerciseManagement::ExerciseState_def::Started ||
|
||||
exercise.state() == ExerciseManagement::ExerciseState_def::Paused);
|
||||
|
||||
// In Übungsvorbereitung keine Eingabe einer Zeit möglich:
|
||||
if (exercise.state() == ExerciseManagement::ExerciseState_def::Created)
|
||||
dte->setChecked(false);
|
||||
else // Ansonsten Status gemäß eingetragener Zeit.
|
||||
dte->setChecked(dte->msecsSinceEpoch() > 0);
|
||||
}
|
||||
else // Ansonsten Status gemäß eingetragener Zeit.
|
||||
dte->setChecked(dte->msecsSinceEpoch() > 0);
|
||||
// Gesamtstatus übernehmen.
|
||||
dte->setEnabled(enable);
|
||||
}
|
||||
|
||||
bool BaseEdit::has2DMap(bool showMsgBoxIfNot2D)
|
||||
{
|
||||
if (!m_sitMapGuiIfc)
|
||||
return false;
|
||||
if (m_sitMapGuiIfc->mapMode() != SituationMap::MapMode::MapMode_2D)
|
||||
{
|
||||
if (showMsgBoxIfNot2D)
|
||||
LtsWidgets::LtsMessageDialog::showMessage(this, tr("Only available in 2D mode"));
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void BaseEdit::setCoordinates(const QVector<QPointF> &coords, bool reverse)
|
||||
{
|
||||
// Reverse if Frontline is chosen and width is taken to the right (like drawing an L)
|
||||
clearCoordinates();
|
||||
const auto cWidgets(coordWidgets());
|
||||
if (!reverse)
|
||||
{
|
||||
for (size_t i = 0; i < cWidgets.size() && i < static_cast<size_t>(coords.size()); ++i)
|
||||
cWidgets.at(i)->setCoordinate(coords.at(i));
|
||||
}
|
||||
else
|
||||
{
|
||||
auto copy(coords);
|
||||
std::reverse(std::begin(copy), std::end(copy));
|
||||
for (size_t i = 0; i < cWidgets.size() && i < static_cast<size_t>(copy.size()); ++i)
|
||||
cWidgets.at(i)->setCoordinate(copy.at(i));
|
||||
}
|
||||
}
|
||||
|
||||
void BaseEdit::setCoordinates(const std::vector<Core::GeoPosition2D> &coords)
|
||||
{
|
||||
clearCoordinates();
|
||||
const auto cWidgets(coordWidgets());
|
||||
for (size_t i = 0; i < cWidgets.size() && i < static_cast<size_t>(coords.size()); ++i)
|
||||
cWidgets.at(i)->setCoordinate(coords.at(i).lon(), coords.at(i).lat());
|
||||
}
|
||||
|
||||
std::vector<Core::GeoPosition2D> BaseEdit::getCoordinates() const
|
||||
{
|
||||
std::vector<Core::GeoPosition2D> segments;
|
||||
const auto cWidgets(coordWidgets());
|
||||
segments.reserve(cWidgets.size());
|
||||
for (const auto cw : cWidgets)
|
||||
{
|
||||
const QPointF coord = cw->coordinate();
|
||||
if (coord.isNull())
|
||||
break;
|
||||
segments.emplace_back(Core::GeoPosition2D(coord.x(), coord.y()));
|
||||
}
|
||||
return segments;
|
||||
}
|
||||
|
||||
QVector<QPointF> BaseEdit::getCoordinatesQPointF() const
|
||||
{
|
||||
QVector<QPointF> segments;
|
||||
const auto cWidgets(coordWidgets());
|
||||
segments.reserve(cWidgets.size());
|
||||
for (const auto *cw : cWidgets)
|
||||
{
|
||||
const QPointF coord = cw->coordinate();
|
||||
if (coord.isNull())
|
||||
break;
|
||||
segments.push_back(coord);
|
||||
}
|
||||
return segments;
|
||||
}
|
||||
|
||||
void BaseEdit::clearCoordinates()
|
||||
{
|
||||
for (auto *cw : coordWidgets())
|
||||
cw->clear();
|
||||
}
|
||||
|
||||
void BaseEdit::enabledCoordinates(bool enable)
|
||||
{
|
||||
for (auto *cw : coordWidgets())
|
||||
cw->setEnabled(enable);
|
||||
}
|
||||
|
||||
|
||||
void BaseEdit::onAreaChanged(const AesItem &data, DataModification modType)
|
||||
{
|
||||
// No, we don't update the UI elements (yet). If we wanted to, we had to
|
||||
// implement a virtual method such as enableUiElements...
|
||||
if (data.id() != m_aesItem.id())
|
||||
return;
|
||||
|
||||
if (modType == DataModification::eRemoved || data.effectStateId() == AesEffectState_def::EsRemoved)
|
||||
{
|
||||
// As a simple 'close()' does not work:
|
||||
__unchange__();
|
||||
closeRequest();
|
||||
return;
|
||||
}
|
||||
m_aesItem = data;
|
||||
enableUiElements(isModifiable() && !isOnlyNameModifiable());
|
||||
}
|
||||
|
||||
bool BaseEdit::init(int aesItemId, LtsSession::LtsSession *session)
|
||||
{
|
||||
if (m_session)
|
||||
{
|
||||
ERROR_LOG(m_logger) << "double init()!";
|
||||
return false;
|
||||
}
|
||||
m_session = session;
|
||||
m_aesItem.id(aesItemId);
|
||||
|
||||
if (!m_session->getDtc<AreaEffectSimulation::DataInterface>(m_dtc))
|
||||
return false;
|
||||
if (!m_session->getFtc<AreaEffectSimulation::DataInterface>(m_ftc))
|
||||
return false;
|
||||
m_session->getForeignGuiInterface<SituationMap::ForeignGuiInterface>(m_sitMapGuiIfc);
|
||||
if (!m_session->getForeignGuiInterface<ParticipantManagement::ForeignGuiComboboxInterface>(m_ppmGuiCbxIfc))
|
||||
return false;
|
||||
|
||||
if (m_session->isReplayPartition() || (LtsAppDescriptor::App::OC == m_session->app()))
|
||||
setUnchangeable();
|
||||
|
||||
if (aesItemId == 0)
|
||||
{
|
||||
m_aesItem.effectSourceId(ProjectDataManagement::EffectSource_def::ES_Internal);
|
||||
m_buttonBox->setText(LtsWidgets::DialogButton::Ok, tr("Add"));
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
double BaseEdit::distance(const Core::GeoPosition2D &p1, const Core::GeoPosition2D &p2)
|
||||
{
|
||||
LtsCoordTrans::UtmCoordinate start = LtsCoordTrans::UtmCoordinate::fromGeographic(p1.lon(), p1.lat());
|
||||
LtsCoordTrans::UtmCoordinate end = LtsCoordTrans::UtmCoordinate::fromGeographic(p2.lon(), p2.lat(), start.zone);
|
||||
double dx = start.x - end.x;
|
||||
double dy = start.y - end.y;
|
||||
return std::sqrt(dx*dx + dy*dy);
|
||||
}
|
||||
|
||||
bool BaseEdit::checkSegementLengths(QWidget *parent) const
|
||||
{
|
||||
auto segments = getCoordinates();
|
||||
for (auto i=0; i<((int) segments.size() - 1); ++i)
|
||||
{
|
||||
double dis = distance(segments[i], segments[i+1]);
|
||||
if (getMaxLength() != 0 && dis > getMaxLength())
|
||||
{
|
||||
LtsWidgets::LtsMessageDialog::showMessage(parent, tr("The distance between Coordinate %1 and %2 is too long.\nThe segment is %3m long, but the maximum segment length is %4m.")
|
||||
.arg(i+1).arg(i+2).arg(QString::number(dis,'d',2),QString::number(getMaxLength(),'d',2)));
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
} // namespace AreaEffectSimulation
|
||||
+116
@@ -0,0 +1,116 @@
|
||||
/**
|
||||
* @RDE_HEADER@
|
||||
* AreaEffectSimulation - Explosion Edit Dialog
|
||||
* $Id$
|
||||
* $HeadURL$
|
||||
* $Author$
|
||||
* Created by Patric Karwat, SLSE, 2016-07-07
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "aes_base_exports.h"
|
||||
#include <AreaEffectSimulation/logger.h>
|
||||
#include <AreaEffectSimulation/aes.hpp>
|
||||
#include <LtsWidgets/lts_dialog.h>
|
||||
#include <LtsWidgets/ui_requirement.h>
|
||||
|
||||
// For not having to include in every derived class, we do it here:
|
||||
#include <LtsUtilsGuiDds/request_helper.h>
|
||||
#include <LtsSession/lts_session.h>
|
||||
#include <LtsUtilsCore/data_modification_enum.h>
|
||||
#include <AreaEffectSimulation/aes_ftc.h>
|
||||
#include <AreaEffectSimulation/aes_operator_rights.h>
|
||||
#include <Plugins/ParticipantManagement/ppm_gui_combobox_plugin_interface.h>
|
||||
|
||||
class QSpinBox;
|
||||
class QDoubleSpinBox;
|
||||
|
||||
namespace SituationMap
|
||||
{
|
||||
class ForeignGuiInterface;
|
||||
}
|
||||
|
||||
namespace LtsWidgets
|
||||
{
|
||||
class LtsDateTimeEdit;
|
||||
}
|
||||
namespace LtsCoordWidget
|
||||
{
|
||||
class LtsCoordWidget;
|
||||
}
|
||||
namespace AreaEffectSimulation
|
||||
{
|
||||
|
||||
namespace Interface
|
||||
{
|
||||
class Ftc;
|
||||
class Dtc;
|
||||
}
|
||||
|
||||
class AESBASEGUI_EXPORT BaseEdit : public LtsWidgets::LtsDialog
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit BaseEdit(const QString &menuGroup,
|
||||
const QString &loggerName,
|
||||
QWidget *parent = nullptr,
|
||||
LtsWidgets::ButtonCombination buttonCombination = LtsWidgets::ButtonCombination::OkApplyCancel);
|
||||
|
||||
bool init(int aesItemId, LtsSession::LtsSession *session);
|
||||
|
||||
QString menuGroup() const { return m_menuGroup; }
|
||||
virtual QString dialogIdentifier() const = 0;
|
||||
|
||||
public Q_SLOTS:
|
||||
void onAreaChanged(const AesItem &data, DataModification modType);
|
||||
|
||||
protected Q_SLOTS:
|
||||
void enaDisa() {}
|
||||
void correctSpinBoxValue();
|
||||
void onVisibilityChanged(bool visible);
|
||||
virtual void showPreviewObject() = 0;
|
||||
|
||||
protected:
|
||||
|
||||
void setCombobxToValueIfPossible(QComboBox *cbx, int val);
|
||||
void onAesItemCreateReply(const Core::FunctionReplyObject &replyObject);
|
||||
void onAesItemModifyReply(const Core::FunctionReplyObject &replyObject);
|
||||
bool isModifiable() const;
|
||||
virtual bool isOnlyNameModifiable() const;
|
||||
virtual void enableUiElements(bool enable) = 0;
|
||||
void correctSpinBoxValueInternal(QSpinBox *sb);
|
||||
void correctSpinBoxValueInternal(QDoubleSpinBox *sb);
|
||||
bool hasValidEffectStart(LtsWidgets::LtsDateTimeEdit *dte) const;
|
||||
void setEffectStartEnabled(LtsWidgets::LtsDateTimeEdit *dte, bool enable = true);
|
||||
|
||||
virtual std::vector<LtsCoordWidget::LtsCoordWidget *> coordWidgets() const { return {}; }
|
||||
void setCoordinates(const QVector<QPointF> &coords, bool reverse);
|
||||
void setCoordinates(const std::vector<Core::GeoPosition2D> &coords);
|
||||
std::vector<Core::GeoPosition2D> getCoordinates() const;
|
||||
QVector<QPointF> getCoordinatesQPointF() const;
|
||||
void clearCoordinates();
|
||||
void enabledCoordinates(bool enable);
|
||||
bool has2DMap(bool showMsgBoxIfNot2D = true);
|
||||
|
||||
static double distance(const Core::GeoPosition2D &p1, const Core::GeoPosition2D &p2);
|
||||
static bool isInBounds(int value, const QPair<int, int>&minMax) { return (value >= minMax.first) && (value <= minMax.second); }
|
||||
|
||||
bool checkSegementLengths(QWidget *parent) const;
|
||||
virtual double getMaxLength() const { return 0; }
|
||||
|
||||
AesItem m_aesItem;
|
||||
|
||||
std::shared_ptr<Interface::Dtc> m_dtc;
|
||||
std::shared_ptr<Interface::Ftc> m_ftc;
|
||||
std::shared_ptr<SituationMap::ForeignGuiInterface> m_sitMapGuiIfc;
|
||||
std::shared_ptr<ParticipantManagement::ForeignGuiComboboxInterface> m_ppmGuiCbxIfc;
|
||||
|
||||
LtsSession::LtsSession *m_session;
|
||||
QString m_menuGroup;
|
||||
LtsUtils::RequestHelper *m_requestHelper;
|
||||
LOGGER_T m_logger;
|
||||
};
|
||||
|
||||
} //namespace AreaEffectSimulation
|
||||
@@ -0,0 +1,21 @@
|
||||
/**
|
||||
* Export definitions
|
||||
* $Id$
|
||||
* $HeadURL$
|
||||
* $Author$
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
#include <QtCore/qglobal.h>
|
||||
|
||||
#ifndef AESBASEGUI_EXPORT
|
||||
# ifdef BUILD_STATIC_LIBRARIES
|
||||
# define AESBASEGUI_EXPORT
|
||||
# else
|
||||
# if defined(MAKE_AESBASEGUI_LIB)
|
||||
# define AESBASEGUI_EXPORT Q_DECL_EXPORT
|
||||
# else
|
||||
# define AESBASEGUI_EXPORT Q_DECL_IMPORT
|
||||
# endif
|
||||
# endif
|
||||
#endif
|
||||
@@ -0,0 +1,60 @@
|
||||
/**
|
||||
* @RDE_HEADER@
|
||||
* GUI Plugin for AreaEffectSimulation - Contamination
|
||||
* $Id$
|
||||
* $HeadURL$
|
||||
* $Author$
|
||||
* Created by Patric Karwat, SLSE, 2016-07-07
|
||||
*/
|
||||
|
||||
#include "aes_base_gui_plugin.h"
|
||||
|
||||
#include <Plugins/AreaEffectSimulation/aes_data_plugin_interface.h>
|
||||
#include <Plugins/ProjectDataManagement/pdm_data_plugin_interface.h>
|
||||
#include <Plugins/ProjectDataManagement/pdm_gui_plugin_interface.h>
|
||||
#include <Plugins/SituationMapPlugin/situation_map_gui_plugin_interface.h>
|
||||
#include <LtsSession/lts_session.h>
|
||||
#include <AreaEffectSimulation/aes_operator_rights.h>
|
||||
|
||||
namespace AreaEffectSimulation
|
||||
{
|
||||
|
||||
AesBaseInterface::AesBaseInterface(LtsSession::LtsSession *session, NGL::INGLLogger &logger)
|
||||
: GuiPluginBase::Interface(session, logger)
|
||||
, m_dtc(nullptr)
|
||||
, m_ftc(nullptr)
|
||||
, m_pdmDtc(nullptr)
|
||||
, m_pdmGuiIfc(nullptr)
|
||||
, m_sitmapGuIfc(nullptr)
|
||||
{}
|
||||
|
||||
|
||||
bool AesBaseInterface::fetchInterfaces()
|
||||
{
|
||||
if (!m_session->getDtc<AreaEffectSimulation::DataInterface>(m_dtc))
|
||||
return false;
|
||||
if (!m_session->getFtc<AreaEffectSimulation::DataInterface>(m_ftc))
|
||||
return false;
|
||||
if (!m_session->getDtc<ProjectDataManagement::DataInterface>(m_pdmDtc))
|
||||
return false;
|
||||
if (!m_session->getForeignGuiInterface<ProjectDataManagement::ForeignGuiInterface>(m_pdmGuiIfc))
|
||||
return false;
|
||||
if (!m_session->getForeignGuiInterface<ParticipantManagement::ForeignGuiComboboxInterface>(m_ppmGuiCbxIfc))
|
||||
return false;
|
||||
|
||||
m_session->getForeignGuiInterface<SituationMap::ForeignGuiInterface>(m_sitmapGuIfc); // optional
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void AesBaseInterface::clearInterfaces()
|
||||
{
|
||||
m_ppmGuiCbxIfc = nullptr;
|
||||
m_sitmapGuIfc = nullptr;
|
||||
m_pdmGuiIfc = nullptr;
|
||||
m_pdmDtc = nullptr;
|
||||
m_ftc = nullptr;
|
||||
m_dtc = nullptr;
|
||||
}
|
||||
|
||||
} // namespace AreaEffectSimulation
|
||||
@@ -0,0 +1,61 @@
|
||||
/**
|
||||
* @RDE_HEADER@
|
||||
* Gui Plugin for AreaEffectSimulation - Contamination
|
||||
* $Id$
|
||||
* $HeadURL$
|
||||
* $Author$
|
||||
* Created by Patric Karwat, SLSE, 2016-07-07
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "aes_base_exports.h"
|
||||
|
||||
#include <PluginInterfaces/gui_plugin_interface.h>
|
||||
#include <Plugins/AreaEffectSimulation/aes_data_plugin_interface.h>
|
||||
#include <Plugins/ProjectDataManagement/pdm_data_plugin_interface.h>
|
||||
#include <Plugins/ProjectDataManagement/pdm_gui_plugin_interface.h>
|
||||
#include <Plugins/SituationMapPlugin/situation_map_gui_plugin_interface.h>
|
||||
#include <Plugins/ParticipantManagement/ppm_gui_combobox_plugin_interface.h>
|
||||
|
||||
|
||||
namespace AreaEffectSimulation
|
||||
{
|
||||
|
||||
class AESBASEGUI_EXPORT AesBaseGuiPlugin : public QObject, public GuiPluginBase::Plugin
|
||||
{
|
||||
Q_INTERFACES(GuiPluginBase::Plugin)
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
AesBaseGuiPlugin() = default;
|
||||
~AesBaseGuiPlugin() = default;
|
||||
};
|
||||
|
||||
class AESBASEGUI_EXPORT AesBaseInterface : public QObject, public GuiPluginBase::Interface
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
QString menuGroup() const override { return tr("Area Effect Simulation"); }
|
||||
bool fetchInterfaces() override;
|
||||
void clearInterfaces() override;
|
||||
bool availableInPartition(IDL::PartitionType partition) const override
|
||||
{
|
||||
return partition == IDL::PartitionType::Exercise ||
|
||||
partition == IDL::PartitionType::Replay;
|
||||
}
|
||||
|
||||
protected:
|
||||
explicit AesBaseInterface(LtsSession::LtsSession *session, NGL::INGLLogger &logger);
|
||||
|
||||
private:
|
||||
std::shared_ptr<AreaEffectSimulation::Interface::Dtc> m_dtc;
|
||||
std::shared_ptr<AreaEffectSimulation::Interface::Ftc> m_ftc;
|
||||
std::shared_ptr<ProjectDataManagement::Interface::Dtc> m_pdmDtc;
|
||||
std::shared_ptr<ProjectDataManagement::ForeignGuiInterface> m_pdmGuiIfc;
|
||||
std::shared_ptr<SituationMap::ForeignGuiInterface> m_sitmapGuIfc;
|
||||
std::shared_ptr<ParticipantManagement::ForeignGuiComboboxInterface> m_ppmGuiCbxIfc;
|
||||
};
|
||||
|
||||
} // namespace AreaEffectSimulation
|
||||
@@ -0,0 +1,356 @@
|
||||
/**
|
||||
* @RDE_HEADER@
|
||||
* AreaEffectManangement - Aes Item Overview Dialog Model Base Class to be inherited by the Area Types
|
||||
* $Id$
|
||||
* $HeadURL$
|
||||
* $Author$
|
||||
*
|
||||
* Created by Malte Diers, SLSE, 2016-09-26
|
||||
*/
|
||||
|
||||
#include "aes_base_model.h"
|
||||
|
||||
#include <LtsSession/lts_session_data.h>
|
||||
#include <LtsSession/lts_session.h>
|
||||
|
||||
#include <Plugins/ParticipantManagement/ppm_data_plugin_interface.h>
|
||||
#include <Plugins/ParticipantManagement/ppm_gui_combobox_plugin_interface.h>
|
||||
#include <Plugins/ProjectDataManagement/pdm_data_plugin_interface.h>
|
||||
#include <ParticipantManagement/ppm_translation.h>
|
||||
#include <PluginInterfaces/gui_plugin_interface.h>
|
||||
|
||||
#include <QLocale>
|
||||
|
||||
namespace AreaEffectSimulation
|
||||
{
|
||||
|
||||
//
|
||||
// AesGuiBasHelpers
|
||||
//
|
||||
AesGuiBasHelpers::AesGuiBasHelpers()
|
||||
: m_aesDtc(nullptr)
|
||||
, m_pdmDtc(nullptr)
|
||||
, m_ppmDtc(nullptr)
|
||||
, m_logger(getLogger("AesGuiBase"))
|
||||
{}
|
||||
|
||||
bool AesGuiBasHelpers::initModel(LtsSession::LtsSession *session)
|
||||
{
|
||||
if (m_aesDtc)
|
||||
{
|
||||
ERROR_LOG(m_logger) << "double init()!";
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!session->getDtc<AreaEffectSimulation::DataInterface>(m_aesDtc))
|
||||
return false;
|
||||
if (!session->getDtc<ProjectDataManagement::DataInterface>(m_pdmDtc))
|
||||
return false;
|
||||
if (!session->getDtc<ParticipantManagement::DataInterface>(m_ppmDtc))
|
||||
return false;
|
||||
session->getForeignGuiInterface<ParticipantManagement::ForeignGuiComboboxInterface>(m_ppmGuiCbxIfc);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
QVariant AesGuiBasHelpers::stringFromPartyId(const dds::core::optional<int> &id) const
|
||||
{
|
||||
if (!id.is_set())
|
||||
return QObject::tr("---");
|
||||
auto it = m_partyNames.find(id.get());
|
||||
if (it != m_partyNames.end())
|
||||
return it.value();
|
||||
const QString name = ParticipantManagement::trPartyName(m_ppmDtc->party(id.get()).name());
|
||||
m_partyNames.insert(id.get(), name);
|
||||
return name;
|
||||
}
|
||||
|
||||
QIcon AesGuiBasHelpers::iconFromPartyId(const dds::core::optional<int> &id) const
|
||||
{
|
||||
if (!id.is_set() || !m_ppmGuiCbxIfc)
|
||||
return QIcon();
|
||||
auto it = m_partyIcons.find(id.get());
|
||||
if (it != m_partyIcons.end())
|
||||
return it.value();
|
||||
const QRgb col = QRgb(m_ppmDtc->party(id.get()).color());
|
||||
const QIcon icon = m_ppmGuiCbxIfc->pixmapFromParty(col);
|
||||
m_partyIcons.insert(id.get(), icon);
|
||||
return icon;
|
||||
}
|
||||
|
||||
QVariant AesGuiBasHelpers::hierarchyFromParticipantId(const dds::core::optional<int> &id) const
|
||||
{
|
||||
if (!id.is_set())
|
||||
return QObject::tr("---");
|
||||
auto it = m_participantHierarchy.find(id.get());
|
||||
if (it != m_participantHierarchy.end())
|
||||
return it.value();
|
||||
const QString name = m_ppmDtc->hierarchyFromParticipant(id.get());
|
||||
m_participantHierarchy.insert(id.get(), name);
|
||||
return name;
|
||||
}
|
||||
|
||||
QVariant AesGuiBasHelpers::chargeTypeName(int chargeTypeId, bool shortName) const
|
||||
{
|
||||
if (shortName)
|
||||
{
|
||||
auto it = m_chargeTypeShortNames.find(chargeTypeId);
|
||||
if (it != m_chargeTypeShortNames.end())
|
||||
return it.value();
|
||||
const QString name = m_pdmDtc->trChargeTypeShortName(chargeTypeId, true);
|
||||
m_chargeTypeShortNames.insert(chargeTypeId, name);
|
||||
return name;
|
||||
}
|
||||
|
||||
auto it = m_chargeTypeNames.find(chargeTypeId);
|
||||
if (it != m_chargeTypeNames.end())
|
||||
return it.value();
|
||||
const QString name = m_pdmDtc->trChargeTypeName(chargeTypeId, true);
|
||||
m_chargeTypeNames.insert(chargeTypeId, name);
|
||||
return name;
|
||||
|
||||
}
|
||||
|
||||
QString AesGuiBasHelpers::simulationTypeText(bool isCentral)
|
||||
{
|
||||
return isCentral ? QObject::tr("central") : QObject::tr("peripheral");
|
||||
}
|
||||
|
||||
void AesGuiBasHelpers::updateEffectStateComboboxFilterData(bool bWithPause)
|
||||
{
|
||||
LtsWidgets::ComboboxFilterContent cfc;
|
||||
LtsWidgets::ComboboxFilterData cfd;
|
||||
const auto effectStates = {
|
||||
AesEffectState::EsExpired,
|
||||
AesEffectState::EsCreated,
|
||||
AesEffectState::EsPrepared,
|
||||
AesEffectState::EsActivated,
|
||||
AesEffectState::EsPaused,
|
||||
AesEffectState::EsFired,
|
||||
AesEffectState::EsReceived
|
||||
};
|
||||
for (const auto es : effectStates) {
|
||||
if (!bWithPause && es == AesEffectState::EsPaused)
|
||||
continue;
|
||||
cfd.data = es;
|
||||
cfd.text = AreaEffectSimulation::toString(es);
|
||||
cfc.data.push_back(cfd);
|
||||
}
|
||||
cfc.sortItems = false;
|
||||
m_cbxFilterEffectState = cfc.toVariant();
|
||||
}
|
||||
|
||||
void AesGuiBasHelpers::updateComboboxFilterData(const QSet<int> &availablePartyIds,
|
||||
const QSet<int> &availabelChargeIds)
|
||||
{
|
||||
LtsWidgets::ComboboxFilterContent cfc;
|
||||
LtsWidgets::ComboboxFilterData cfd;
|
||||
for (const int i : qAsConst(availabelChargeIds))
|
||||
{
|
||||
cfd.data = i;
|
||||
cfd.text = chargeTypeName(i).toString();
|
||||
cfc.data.push_back(cfd);
|
||||
}
|
||||
cfc.sortItems = true;
|
||||
m_cbxFilterChargeType = cfc.toVariant();
|
||||
|
||||
cfc.data.clear();
|
||||
for (const int i : qAsConst(availablePartyIds))
|
||||
{
|
||||
cfd.data = i;
|
||||
cfd.text = ParticipantManagement::trPartyName(m_ppmDtc->party(i).name());
|
||||
cfd.icon = iconFromPartyId(i);
|
||||
cfc.data.push_back(cfd);
|
||||
}
|
||||
cfc.sortItems = false;
|
||||
m_cbxFilterParty = cfc.toVariant();
|
||||
}
|
||||
|
||||
void AreaEffectSimulation::AesGuiBasHelpers::updateSimulationTypeComboboxFilterData()
|
||||
{
|
||||
LtsWidgets::ComboboxFilterContent cfc;
|
||||
LtsWidgets::ComboboxFilterData cfd;
|
||||
|
||||
cfd.text = simulationTypeText(true);
|
||||
cfd.data = cfd.text;
|
||||
cfc.data.push_back(cfd);
|
||||
|
||||
cfd.text = simulationTypeText(false);
|
||||
cfd.data = cfd.text;
|
||||
cfc.data.push_back(cfd);
|
||||
|
||||
cfc.sortItems = false;
|
||||
m_cbxFilterSimulationType = cfc.toVariant();
|
||||
}
|
||||
|
||||
void AesGuiBasHelpers::fillAvailableChargeIds(ProjectDataManagement::GearClass gc)
|
||||
{
|
||||
m_availableChargeIds.clear();
|
||||
const QVector<ProjectDataManagement::ChargeType> availableCharges = m_pdmDtc->chargesForGearClass(gc);
|
||||
for (const auto &charge : availableCharges)
|
||||
m_availableChargeIds += charge.id();
|
||||
// enable filter although no charges for this type are available
|
||||
if (m_availableChargeIds.isEmpty())
|
||||
m_availableChargeIds += 0;
|
||||
}
|
||||
|
||||
void AesGuiBasHelpers::fillAvailableChargeIds(const QVector<ProjectDataManagement::GearClass> &gcs)
|
||||
{
|
||||
m_availableChargeIds.clear();
|
||||
|
||||
for (auto gc : qAsConst(gcs))
|
||||
{
|
||||
const QVector<ProjectDataManagement::ChargeType> &availableCharges = m_pdmDtc->chargesForGearClass(gc);
|
||||
for (const auto &charge : qAsConst(availableCharges))
|
||||
m_availableChargeIds += charge.id();
|
||||
}
|
||||
// enable filter although no charges for this type are available
|
||||
if (m_availableChargeIds.isEmpty())
|
||||
m_availableChargeIds += 0;
|
||||
}
|
||||
|
||||
//
|
||||
// AesItemSortFilterProxyModel
|
||||
//
|
||||
AesItemSortFilterProxyModel::AesItemSortFilterProxyModel(LtsSession::LtsSession *session, QObject *parent)
|
||||
: LtsWidgets::LtsColumnFilterProxyModel(parent)
|
||||
, m_session(session)
|
||||
, m_showExpired(false)
|
||||
, m_offset(5 * 60 * 1000) // default: 5 minutes
|
||||
{
|
||||
std::shared_ptr<ParticipantManagement::Interface::Dtc> ppmDtc;
|
||||
if (m_session->getDtc<ParticipantManagement::DataInterface>(ppmDtc))
|
||||
{
|
||||
auto cb = [this](const ParticipantManagement::Party &party)
|
||||
{
|
||||
m_partyColors[party.id()] = QColor::fromRgb(QRgb(party.color()));
|
||||
};
|
||||
ppmDtc->partys(cb);
|
||||
}
|
||||
}
|
||||
|
||||
void AesItemSortFilterProxyModel::setShowExpired(bool showExpired)
|
||||
{
|
||||
if (m_showExpired == showExpired)
|
||||
return;
|
||||
|
||||
m_showExpired = showExpired;
|
||||
invalidateFilter();
|
||||
}
|
||||
|
||||
void AesItemSortFilterProxyModel::setOffset(int offsetMsecs)
|
||||
{
|
||||
if (m_offset == offsetMsecs)
|
||||
return;
|
||||
|
||||
m_offset = offsetMsecs;
|
||||
invalidateFilter();
|
||||
}
|
||||
|
||||
bool AesItemSortFilterProxyModel::filterAcceptsRow(int source_row, const QModelIndex &source_parent) const
|
||||
{
|
||||
bool bRet = checkFilter(source_row);
|
||||
if (!bRet)
|
||||
return false;
|
||||
return LtsWidgets::LtsColumnFilterProxyModel::filterAcceptsRow(source_row, source_parent);
|
||||
}
|
||||
|
||||
bool AesItemSortFilterProxyModel::lessThan(const QModelIndex &source_left, const QModelIndex &source_right) const
|
||||
{
|
||||
if (source_left.column() != source_right.column())
|
||||
return LtsWidgets::LtsColumnFilterProxyModel::lessThan(source_left, source_right);
|
||||
|
||||
switch (source_left.column())
|
||||
{
|
||||
case AesGuiBasHelpers::BcEffectStart:
|
||||
{
|
||||
const auto effectStartLeft = aesEffectStart(source_left.row());
|
||||
const auto effectStartRight = aesEffectStart(source_right.row());
|
||||
if (effectStartLeft.is_set() && effectStartRight.is_set())
|
||||
return effectStartLeft.get() < effectStartRight.get();
|
||||
if (effectStartRight.is_set())
|
||||
return true;
|
||||
if (effectStartLeft.is_set())
|
||||
return false;
|
||||
return aesId(source_left.row()) < aesId(source_right.row());
|
||||
}
|
||||
case AesGuiBasHelpers::BcEffectDuration:
|
||||
{
|
||||
const auto effectDurationLeft = aesEffectDuration(source_left.row());
|
||||
const auto effectDurationRight = aesEffectDuration(source_right.row());
|
||||
if (effectDurationLeft == effectDurationRight)
|
||||
return aesId(source_left.row()) < aesId(source_right.row());
|
||||
return effectDurationLeft < effectDurationRight;
|
||||
}
|
||||
case AesGuiBasHelpers::BcEffectState:
|
||||
{
|
||||
const auto effectStateLeft = aesEffectStateId(source_left.row());
|
||||
const auto effectStateRight = aesEffectStateId(source_right.row());
|
||||
if (effectStateLeft == effectStateRight)
|
||||
return aesId(source_left.row()) < aesId(source_right.row());
|
||||
return effectStateLeft < effectStateRight;
|
||||
}
|
||||
case AesGuiBasHelpers::BcEffectSource:
|
||||
{
|
||||
const auto effectSourceLeft = aesEffectSourceId(source_left.row());
|
||||
const auto effectSourceRight = aesEffectSourceId(source_right.row());
|
||||
if (effectSourceLeft == effectSourceRight)
|
||||
return aesId(source_left.row()) < aesId(source_right.row());
|
||||
return effectSourceLeft < effectSourceRight;
|
||||
}
|
||||
case AesGuiBasHelpers::BcParty:
|
||||
{
|
||||
const auto partyIdLeft = partyId(source_left.row());
|
||||
const auto partyIdRight = partyId(source_right.row());
|
||||
if (partyIdLeft == partyIdRight)
|
||||
return aesId(source_left.row()) < aesId(source_right.row());
|
||||
return partyIdLeft < partyIdRight;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return LtsWidgets::LtsColumnFilterProxyModel::lessThan(source_left, source_right);
|
||||
}
|
||||
|
||||
|
||||
bool AesItemSortFilterProxyModel::checkFilter(int source_row) const
|
||||
{
|
||||
int32_t party = partyId(source_row);
|
||||
if (party != -1 && !LtsSessionData::LtsSessionData::getInstance()->isVisibleParty(m_session->exerciseId(), party))
|
||||
return false;
|
||||
|
||||
const auto effectStateId = aesEffectStateId(source_row);
|
||||
if (effectStateId == AesEffectState_def::EsRemoved)
|
||||
return false;
|
||||
|
||||
// If showExpired: Show all
|
||||
if (showExpired())
|
||||
return true;
|
||||
|
||||
const int id = aesId(source_row);
|
||||
if (id <= 0)
|
||||
return false;
|
||||
|
||||
// If MA is not in state expired: Show
|
||||
if (effectStateId != AreaEffectSimulation::AesEffectState::EsExpired && effectStateId != AreaEffectSimulation::AesEffectState::EsRemoved)
|
||||
return true;
|
||||
|
||||
if (!m_session)
|
||||
{
|
||||
// Todo: Log
|
||||
return false;
|
||||
}
|
||||
|
||||
const auto effectStart = aesEffectStart(source_row);
|
||||
qint64 effectEnd = 0;
|
||||
if (effectStart.is_set())
|
||||
effectEnd = effectStart.get() + aesEffectDuration(source_row);
|
||||
|
||||
// Expired. Show only if younger than m_offset
|
||||
if (effectStart.is_set() &&
|
||||
effectEnd + m_offset > m_session->partitionTime())
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
} // namespace AreaEffectSimulation
|
||||
+375
@@ -0,0 +1,375 @@
|
||||
/**
|
||||
* @RDE_HEADER@
|
||||
* AreaEffectManangement - Overview Dialog Model Base
|
||||
* $Id$
|
||||
* $HeadURL$
|
||||
* $Author$
|
||||
*
|
||||
* Created by Mike Wille, SLSE, 2016-09-26
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "aes_base_exports.h"
|
||||
|
||||
|
||||
#include <AreaEffectSimulation/aes.hpp>
|
||||
#include <AreaEffectSimulation/aes_translation.h>
|
||||
#include <AreaEffectSimulation/aes_dtc.h>
|
||||
#include <AreaEffectSimulation/logger.h>
|
||||
#include <ProjectDataManagement/pdm_translation.h>
|
||||
|
||||
#include <QSet>
|
||||
#include <QVector>
|
||||
|
||||
#include <LtsWidgets/lts_abstract_table_model.h>
|
||||
#include <LtsWidgets/lts_column_filter_proxy_model.h>
|
||||
#include <ngltools/ngltools_dtg.h>
|
||||
#include <Plugins/AreaEffectSimulation/aes_data_plugin_interface.h>
|
||||
#include <ProjectDataManagement/pdm_enums.hpp>
|
||||
|
||||
const static int DEFAULT_EFFECT_DURATION = 777777;
|
||||
|
||||
namespace LtsSession
|
||||
{
|
||||
class LtsSession;
|
||||
}
|
||||
namespace ParticipantManagement
|
||||
{
|
||||
namespace Interface
|
||||
{
|
||||
class Dtc;
|
||||
}
|
||||
class ForeignGuiComboboxInterface;
|
||||
}
|
||||
namespace ProjectDataManagement
|
||||
{
|
||||
namespace Interface
|
||||
{
|
||||
class Dtc;
|
||||
}
|
||||
}
|
||||
|
||||
namespace AreaEffectSimulation
|
||||
{
|
||||
class AESBASEGUI_EXPORT AesGuiBasHelpers
|
||||
{
|
||||
public:
|
||||
enum BaseColumns
|
||||
{
|
||||
BcId,
|
||||
BcName,
|
||||
BcChargeType,
|
||||
BcEffectDuration,
|
||||
BcEffectStart,
|
||||
BcEffectState,
|
||||
BcParty,
|
||||
BcParticipant,
|
||||
BcIsCentral,
|
||||
BcEffectSource,
|
||||
BcCount
|
||||
};
|
||||
|
||||
protected:
|
||||
AesGuiBasHelpers();
|
||||
|
||||
virtual ~AesGuiBasHelpers() = default;
|
||||
|
||||
virtual bool initModel(LtsSession::LtsSession *session);
|
||||
|
||||
QVariant stringFromPartyId(const dds::core::optional<int> &id) const;
|
||||
QIcon iconFromPartyId(const dds::core::optional<int> &id) const;
|
||||
QVariant hierarchyFromParticipantId(const dds::core::optional<int> &id) const;
|
||||
QVariant chargeTypeName(int chargeTypeId, bool shortName = true) const;
|
||||
static QString simulationTypeText(bool isCentral);
|
||||
|
||||
void updateEffectStateComboboxFilterData(bool bWithPause);
|
||||
void updateComboboxFilterData(const QSet<int> &availablePartyIds,
|
||||
const QSet<int> &availabelChargeIds);
|
||||
void updateSimulationTypeComboboxFilterData();
|
||||
void fillAvailableChargeIds(ProjectDataManagement::GearClass gc);
|
||||
void fillAvailableChargeIds(const QVector<ProjectDataManagement::GearClass> &gcs);
|
||||
|
||||
protected:
|
||||
std::shared_ptr<AreaEffectSimulation::Interface::Dtc> m_aesDtc;
|
||||
std::shared_ptr<ProjectDataManagement::Interface::Dtc> m_pdmDtc;
|
||||
std::shared_ptr<ParticipantManagement::Interface::Dtc> m_ppmDtc;
|
||||
std::shared_ptr<ParticipantManagement::ForeignGuiComboboxInterface> m_ppmGuiCbxIfc;
|
||||
|
||||
QVariant m_cbxFilterChargeType;
|
||||
QVariant m_cbxFilterEffectState;
|
||||
QVariant m_cbxFilterParty;
|
||||
QVariant m_cbxFilterSimulationType;
|
||||
|
||||
QSet<int> m_availableChargeIds;
|
||||
LOGGER_T m_logger;
|
||||
|
||||
private:
|
||||
mutable QHash<int, QVariant> m_partyNames;
|
||||
mutable QHash<int, QIcon> m_partyIcons;
|
||||
mutable QHash<int, QVariant> m_participantHierarchy;
|
||||
mutable QHash<int, QVariant> m_chargeTypeNames;
|
||||
mutable QHash<int, QVariant> m_chargeTypeShortNames;
|
||||
};
|
||||
|
||||
template<class T>
|
||||
class AesGuiBaseModel : public LtsWidgets::LtsAbstractTableModel<T>, public AesGuiBasHelpers
|
||||
{
|
||||
protected:
|
||||
explicit AesGuiBaseModel(QObject *parent = nullptr, const QVector<QString> &vecAdditionalColumns = QVector<QString>())
|
||||
: LtsWidgets::LtsAbstractTableModel<T>({QObject::tr("Id"),
|
||||
QObject::tr("Name"),
|
||||
QObject::tr("Charge Type"),
|
||||
QObject::tr("Effect Duration"),
|
||||
QObject::tr("Effect Start"),
|
||||
QObject::tr("Effect State"),
|
||||
QObject::tr("Party"),
|
||||
QObject::tr("Participant"),
|
||||
QObject::tr("SimulationType"),
|
||||
QObject::tr("EffectSource")},
|
||||
parent)
|
||||
{
|
||||
LtsWidgets::LtsAbstractTableModel<T>::m_vecColumns.append(vecAdditionalColumns);
|
||||
QObject::connect(this, &AesGuiBaseModel::rowsInserted,
|
||||
this, &AesGuiBaseModel::onUpdateComboboxFilterData);
|
||||
QObject::connect(this, &AesGuiBaseModel::rowsRemoved,
|
||||
this, &AesGuiBaseModel::onUpdateComboboxFilterData);
|
||||
QObject::connect(this, &AesGuiBaseModel::modelReset,
|
||||
this, &AesGuiBaseModel::onUpdateComboboxFilterData);
|
||||
updateEffectStateComboboxFilterData(false);
|
||||
updateSimulationTypeComboboxFilterData();
|
||||
onUpdateComboboxFilterData();
|
||||
}
|
||||
|
||||
void onUpdateComboboxFilterData()
|
||||
{
|
||||
QSet<int> availabelChargeIds;
|
||||
QSet<int> availablePartyIds;
|
||||
for (const T &data : qAsConst(AesGuiBaseModel::m_vecData))
|
||||
{
|
||||
availabelChargeIds.insert(data.chargeStruct().chargeTypeId());
|
||||
if (data.partyId().is_set())
|
||||
availablePartyIds.insert(data.partyId().get());
|
||||
}
|
||||
updateComboboxFilterData(availablePartyIds, availabelChargeIds);
|
||||
}
|
||||
|
||||
int cntBaseColumns() const
|
||||
{
|
||||
return BcCount;
|
||||
}
|
||||
|
||||
QVariant headerData(int section, Qt::Orientation orientation, int role) const override
|
||||
{
|
||||
if (orientation == Qt::Horizontal && role == LtsWidgets::LtsColumnFilterProxyModel::ComboboxFilterRole)
|
||||
{
|
||||
switch (section)
|
||||
{
|
||||
case BcParty:
|
||||
return m_cbxFilterParty;
|
||||
case BcChargeType:
|
||||
return m_cbxFilterChargeType;
|
||||
case BcEffectState:
|
||||
return m_cbxFilterEffectState;
|
||||
case BcIsCentral:
|
||||
return m_cbxFilterSimulationType;
|
||||
default:
|
||||
return QVariant();
|
||||
}
|
||||
}
|
||||
return LtsWidgets::LtsAbstractTableModel<T>::headerData(section, orientation, role);
|
||||
}
|
||||
|
||||
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override
|
||||
{
|
||||
if (!LtsWidgets::LtsAbstractTableModel<T>::indexIsValid(index))
|
||||
return QVariant();
|
||||
const T &item = LtsWidgets::LtsAbstractTableModel<T>::m_vecData.at(index.row());
|
||||
return data(item, index.column(), role);
|
||||
}
|
||||
|
||||
|
||||
QVariant data(const T &item, int column, int role = Qt::DisplayRole) const
|
||||
{
|
||||
if (role == Qt::ToolTipRole)
|
||||
{
|
||||
switch (column)
|
||||
{
|
||||
case BcId:
|
||||
case BcName:
|
||||
case BcEffectStart:
|
||||
case BcIsCentral:
|
||||
return QVariant();
|
||||
case BcChargeType:
|
||||
return QObject::tr("Id: %1").arg(item.chargeStruct().chargeTypeId());
|
||||
case BcEffectDuration:
|
||||
{
|
||||
if (item.effectDuration() == DEFAULT_EFFECT_DURATION)
|
||||
return QStringLiteral("---");
|
||||
else
|
||||
return QObject::tr("%1 secs").arg(QString::number(item.effectDuration() / 1000.0, 'f', 3));
|
||||
}
|
||||
case BcEffectState:
|
||||
return QObject::tr("Id: %1").arg(item.effectStateId().underlying());
|
||||
case BcEffectSource:
|
||||
return QObject::tr("Id: %1").arg(item.effectSourceId().underlying());
|
||||
case BcParty:
|
||||
return QObject::tr("Id: %1").arg(item.partyId().is_set() ? item.partyId().get() : -1);
|
||||
case BcParticipant:
|
||||
return QObject::tr("Id: %1").arg(item.participantId().is_set() ? item.participantId().get() : -1);
|
||||
}
|
||||
}
|
||||
|
||||
if (role == Qt::DisplayRole)
|
||||
{
|
||||
switch (column)
|
||||
{
|
||||
case BcId:
|
||||
return item.id();
|
||||
case BcName:
|
||||
return QString::fromUtf8(item.name().c_str());
|
||||
case BcChargeType:
|
||||
return chargeTypeName(item.chargeStruct().chargeTypeId());
|
||||
case BcEffectDuration:
|
||||
if (item.effectDuration() == DEFAULT_EFFECT_DURATION)
|
||||
return QStringLiteral("---");
|
||||
else
|
||||
return LtsWidgets::readableDuration(item.effectDuration());
|
||||
case BcEffectStart:
|
||||
return item.effectStart().is_set() ? DTG::toStringMSec(item.effectStart().get()) : QObject::tr("---");
|
||||
case BcEffectState:
|
||||
return AreaEffectSimulation::toString(item.effectStateId());
|
||||
case BcEffectSource:
|
||||
return ProjectDataManagement::toString(item.effectSourceId());
|
||||
case BcParty:
|
||||
return stringFromPartyId(item.partyId());
|
||||
case BcParticipant:
|
||||
return hierarchyFromParticipantId(item.participantId());
|
||||
case BcIsCentral:
|
||||
return simulationTypeText(item.isCentral());
|
||||
}
|
||||
return QVariant();
|
||||
}
|
||||
|
||||
if (role == Qt::DecorationRole)
|
||||
{
|
||||
switch (column)
|
||||
{
|
||||
case BcParty:
|
||||
return iconFromPartyId(item.partyId());
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return QVariant();
|
||||
}
|
||||
|
||||
if (role == LtsWidgets::LtsColumnFilterProxyModel::ComboboxFilterRole)
|
||||
{
|
||||
switch (column)
|
||||
{
|
||||
case BcChargeType:
|
||||
return item.chargeStruct().chargeTypeId();
|
||||
case BcEffectState:
|
||||
return item.effectStateId().underlying();
|
||||
case BcParty:
|
||||
return item.partyId().is_set() ? item.partyId().get() : -1;
|
||||
case BcIsCentral:
|
||||
return simulationTypeText(item.isCentral());
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return QVariant();
|
||||
}
|
||||
|
||||
return QVariant();
|
||||
}
|
||||
|
||||
public:
|
||||
T aesItem(int row) const { return LtsWidgets::LtsAbstractTableModel<T>::getRowData(row); }
|
||||
|
||||
protected:
|
||||
bool isFiltered(const T &data, DataModification modType) const override
|
||||
{
|
||||
if (!m_availableChargeIds.isEmpty() && !m_availableChargeIds.contains(data.chargeStruct().chargeTypeId()))
|
||||
return true;
|
||||
return LtsWidgets::LtsAbstractTableModel<T>::isFiltered(data, modType);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
class AESBASEGUI_EXPORT AesItemSortFilterProxyModel : public LtsWidgets::LtsColumnFilterProxyModel
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit AesItemSortFilterProxyModel(LtsSession::LtsSession *session, QObject *parent = nullptr);
|
||||
~AesItemSortFilterProxyModel() = default;
|
||||
|
||||
bool showExpired() const { return m_showExpired; }
|
||||
int offset() const { return m_offset; }
|
||||
|
||||
virtual int aesId(int row) const = 0;
|
||||
virtual bool isExpired(int row) const = 0;
|
||||
virtual bool isExternal(int row) const = 0;
|
||||
virtual AesEffectState aesEffectStateId(int row) const = 0;
|
||||
virtual ProjectDataManagement::EffectSource aesEffectSourceId(int row) const = 0;
|
||||
virtual dds::core::optional<rti::core::int64> aesEffectStart(int row) const = 0;
|
||||
virtual int32_t aesEffectDuration(int row) const = 0;
|
||||
virtual int32_t partyId(int row) const = 0;
|
||||
QColor partyColor(int row) const { return m_partyColors.value(partyId(row), Qt::black); }
|
||||
|
||||
public slots:
|
||||
void setOffset(int offsetMsecs);
|
||||
void setShowExpired(bool showExpired);
|
||||
|
||||
protected:
|
||||
bool filterAcceptsRow(int source_row, const QModelIndex &source_parent) const override final;
|
||||
bool lessThan(const QModelIndex &source_left, const QModelIndex &source_right) const override final;
|
||||
|
||||
private:
|
||||
bool checkFilter(int source_row) const;
|
||||
private:
|
||||
LtsSession::LtsSession *m_session;
|
||||
bool m_showExpired;
|
||||
int m_offset;
|
||||
QMap<int, QColor> m_partyColors;
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
class AesItemSortFilterProxyModelTmpl : public AesItemSortFilterProxyModel
|
||||
{
|
||||
public:
|
||||
using AesItemSortFilterProxyModel::AesItemSortFilterProxyModel;
|
||||
|
||||
void setSourceModel(QAbstractItemModel *sm) override
|
||||
{
|
||||
m_sourceModel = dynamic_cast<AesGuiBaseModel<T>*>(sm);
|
||||
Q_ASSERT(m_sourceModel);
|
||||
AesItemSortFilterProxyModel::setSourceModel(sm);
|
||||
}
|
||||
T aesItem(int row) const { return m_sourceModel->aesItem(row); }
|
||||
|
||||
int aesId(int row) const override { return aesItem(row).id(); }
|
||||
bool isExpired(int row) const override
|
||||
{
|
||||
const auto es = aesItem(row).effectStateId();
|
||||
// alles andere wird als expired angesehen -> also nicht löschbar
|
||||
return es != AreaEffectSimulation::AesEffectState_def::EsCreated &&
|
||||
es != AreaEffectSimulation::AesEffectState_def::EsPrepared &&
|
||||
es != AreaEffectSimulation::AesEffectState_def::EsActivated &&
|
||||
es != AreaEffectSimulation::AesEffectState_def::EsPaused &&
|
||||
es != AreaEffectSimulation::AesEffectState_def::EsReceived;
|
||||
}
|
||||
bool isExternal(int row) const override
|
||||
{
|
||||
return aesItem(row).externalId() > 0;
|
||||
}
|
||||
protected:
|
||||
AesEffectState aesEffectStateId(int row) const override { return aesItem(row).effectStateId(); }
|
||||
ProjectDataManagement::EffectSource aesEffectSourceId(int row) const override { return aesItem(row).effectSourceId(); }
|
||||
dds::core::optional<rti::core::int64> aesEffectStart(int row) const override { return aesItem(row).effectStart(); }
|
||||
int32_t aesEffectDuration(int row) const override { return aesItem(row).effectDuration(); }
|
||||
virtual int32_t partyId(int row) const override { return aesItem(row).partyId().is_set()?aesItem(row).partyId().get():-1; }
|
||||
|
||||
AesGuiBaseModel<T> *m_sourceModel = nullptr;
|
||||
};
|
||||
} //namespace AreaEffectSimulation
|
||||
+307
@@ -0,0 +1,307 @@
|
||||
/**
|
||||
* @RDE_HEADER@
|
||||
* ContaminationManangement - Contamination Overview Dialog
|
||||
* $Id$
|
||||
* $HeadURL$
|
||||
* $Author$
|
||||
* Created by Patric Karwat, SLSE, 2016-07-07
|
||||
*/
|
||||
|
||||
#include "aes_itemlist.h"
|
||||
#include "aes_base_model.h"
|
||||
#include "ui_aes_itemlist.h"
|
||||
|
||||
#include <QCheckBox>
|
||||
#include <QKeyEvent>
|
||||
|
||||
#include <LtsSession/lts_session.h>
|
||||
#include <LtsUtilsGuiDds/request_helper.h>
|
||||
#include <PluginInterfaces/gui_plugin_interface.h>
|
||||
#include <Plugins/AreaEffectSimulation/aes_data_plugin_interface.h>
|
||||
#include <Plugins/SituationMapPlugin/situation_map_gui_plugin_interface.h>
|
||||
#include <Viewer/LtsDataView/lts_data_view.h>
|
||||
|
||||
#include <QJsonDocument>
|
||||
#include <QTreeView>
|
||||
#include <LtsPrinting/printing.h>
|
||||
|
||||
static const auto ADLER_BTN = LtsWidgets::DialogButton::Export;
|
||||
|
||||
namespace AreaEffectSimulation
|
||||
{
|
||||
|
||||
AesItemList::AesItemList(const QString &menuGroup, QWidget *parent)
|
||||
: LtsWidgets::LtsDialog(parent, LtsWidgets::ButtonCombination::CloseOnly)
|
||||
, m_ftc(nullptr)
|
||||
, m_dtc(nullptr)
|
||||
, m_menuGroup(menuGroup)
|
||||
, m_requestHelper(new LtsUtils::RequestHelper(this))
|
||||
, m_showExpired(false)
|
||||
, m_bHasAddEditOperatorRights(true)
|
||||
, m_bHasAddAdlerOperatorRights(false)
|
||||
, m_session(nullptr)
|
||||
, m_ui(new Ui::AesItemList)
|
||||
, m_logger(getLogger("AesItemList"))
|
||||
{
|
||||
m_ui->setupUi(this);
|
||||
|
||||
QCheckBox *cbExpired = new QCheckBox(tr("Show expired"), m_ui->widget);
|
||||
cbExpired->setProperty("const", true);
|
||||
m_ui->widget->setCustomWidget(cbExpired);
|
||||
connect(cbExpired, &QCheckBox::toggled, this, &AesItemList::setShowExpired);
|
||||
}
|
||||
|
||||
AesItemList::~AesItemList() { delete m_ui; }
|
||||
|
||||
bool AesItemList::init(LtsSession::LtsSession *session)
|
||||
{
|
||||
if (m_session)
|
||||
{
|
||||
ERROR_LOG(m_logger) << "double init()!";
|
||||
return false;
|
||||
}
|
||||
m_session = session;
|
||||
|
||||
if (!m_session->getFtc<AreaEffectSimulation::DataInterface>(m_ftc))
|
||||
return false;
|
||||
if (!m_session->getDtc<AreaEffectSimulation::DataInterface>(m_dtc))
|
||||
return false;
|
||||
m_buttonBox->connectButton(LtsWidgets::DialogButton::Print, this, &AesItemList::onPrint);
|
||||
if (m_session->app() != LtsAppDescriptor::App::OC)
|
||||
{
|
||||
m_buttonBox->connectButton(LtsWidgets::DialogButton::Add, this, &AesItemList::onAddAesItem);
|
||||
m_buttonBox->connectButton(LtsWidgets::DialogButton::Remove, this, &AesItemList::onRemoveAesItem);
|
||||
}
|
||||
|
||||
m_buttonBox->connectButton(LtsWidgets::DialogButton::Edit, this, &AesItemList::onEditAesItem);
|
||||
|
||||
m_buttonBox->getButton(LtsWidgets::DialogButton::Save)->setText(tr("Center on Map"));
|
||||
m_buttonBox->getButton(LtsWidgets::DialogButton::Save)->setIcon(QIcon(QStringLiteral("icon:center_to_object.svg")));
|
||||
m_buttonBox->connectButton(LtsWidgets::DialogButton::Save, this, &AesItemList::onCenterAesItem);
|
||||
m_buttonBox->getButton(ADLER_BTN)->hide();
|
||||
m_buttonBox->connectButton(ADLER_BTN, this, &AesItemList::onAdlerBtn);
|
||||
|
||||
QCheckBox *cb = qobject_cast<QCheckBox *>(m_ui->widget->customWidget());
|
||||
bool showExpired = (!cb || cb->isChecked());
|
||||
|
||||
createModel();
|
||||
model()->setShowExpired(showExpired);
|
||||
|
||||
connect(m_ui->widget, &LtsDataView::LtsDataView::signalSelectionChanged, this, &AesItemList::enaDisa);
|
||||
connect(m_session, &LtsSession::LtsSession::signalExerciseDataChanged, this, &AesItemList::enaDisa);
|
||||
connect(m_dtc.get(), &AreaEffectSimulation::Interface::Dtc::explosionClusterChanged, this, &AesItemList::onHandleAdler);
|
||||
connect(m_dtc.get(), &AreaEffectSimulation::Interface::Dtc::effectClusterChanged, this, &AesItemList::onHandleAdler);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void AesItemList::enaDisa()
|
||||
{
|
||||
const int curSelRow = currentRow();
|
||||
onHandleAdler();
|
||||
LtsWidgets::ExerciseStates allowedStates = LtsWidgets::ExerciseState::eCreated | LtsWidgets::ExerciseState::eStarted | LtsWidgets::ExerciseState::ePaused;
|
||||
bool bEnableEditRemove = false;
|
||||
bool bIsAllowedInState = allowedStates.testFlag(m_session->exerciseState());
|
||||
bool isOc = (m_session->app() == LtsAppDescriptor::App::OC);
|
||||
|
||||
m_buttonBox->setButtonEnabled(LtsWidgets::DialogButton::Save, !model()->isExpired(curSelRow));
|
||||
|
||||
if (curSelRow >= 0)
|
||||
bEnableEditRemove = !model()->isExpired(curSelRow) && !model()->isExternal(curSelRow);
|
||||
if (!m_bHasAddEditOperatorRights)
|
||||
{
|
||||
bEnableEditRemove = false;
|
||||
bIsAllowedInState = false;
|
||||
}
|
||||
|
||||
if (!m_session->isReplayPartition())
|
||||
{
|
||||
if (!model()->isExternal(curSelRow))
|
||||
{
|
||||
m_buttonBox->setText(LtsWidgets::DialogButton::Edit, tr("Edit"));
|
||||
m_buttonBox->setButtonEnabled(LtsWidgets::DialogButton::Edit, bEnableEditRemove && bIsAllowedInState);
|
||||
}
|
||||
else
|
||||
{
|
||||
m_buttonBox->setText(LtsWidgets::DialogButton::Edit, tr("Show Details"));
|
||||
m_buttonBox->setButtonEnabled(LtsWidgets::DialogButton::Edit, bIsAllowedInState);
|
||||
}
|
||||
|
||||
m_buttonBox->setButtonEnabled(LtsWidgets::DialogButton::Remove, bEnableEditRemove && bIsAllowedInState);
|
||||
|
||||
// Adler Add Button
|
||||
bool isEsAdler = false;
|
||||
if (curSelRow >= 0)
|
||||
{
|
||||
const ProjectDataManagement::EffectSource &es = model()->aesEffectSourceId(curSelRow);
|
||||
|
||||
if (es == ProjectDataManagement::EffectSource::ES_ADLER || es == ProjectDataManagement::EffectSource::ES_ADLER_STANDALONE)
|
||||
isEsAdler = true;
|
||||
|
||||
m_buttonBox->setButtonEnabled(LtsWidgets::DialogButton::Add, bIsAllowedInState && !isEsAdler);
|
||||
m_buttonBox->setButtonEnabled(LtsWidgets::DialogButton::Load, m_bHasAddAdlerOperatorRights && isEsAdler);
|
||||
m_buttonBox->setButtonVisible(LtsWidgets::DialogButton::Load, !isOc);
|
||||
}
|
||||
else
|
||||
{
|
||||
m_buttonBox->setButtonEnabled(LtsWidgets::DialogButton::Add, bIsAllowedInState);
|
||||
m_buttonBox->setButtonEnabled(LtsWidgets::DialogButton::Load, m_bHasAddAdlerOperatorRights);
|
||||
m_buttonBox->setButtonVisible(LtsWidgets::DialogButton::Load, !isOc);
|
||||
}
|
||||
m_buttonBox->getButton(LtsWidgets::DialogButton::Load)->setText(tr("Add ADLER"));
|
||||
}
|
||||
else
|
||||
{
|
||||
m_buttonBox->setButtonVisible(LtsWidgets::DialogButton::Add, false);
|
||||
m_buttonBox->setButtonVisible(LtsWidgets::DialogButton::Remove, false);
|
||||
|
||||
m_buttonBox->setText(LtsWidgets::DialogButton::Edit, tr("Show Details"));
|
||||
m_buttonBox->setButtonEnabled(LtsWidgets::DialogButton::Edit, bEnableEditRemove);
|
||||
}
|
||||
|
||||
if (bEnableEditRemove && bIsAllowedInState)
|
||||
{
|
||||
m_doubleClickConnection = connect(m_ui->widget, &LtsDataView::LtsDataView::signalDoubleClicked, this, &AesItemList::onEditAesItem, Qt::UniqueConnection);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (m_doubleClickConnection)
|
||||
disconnect(m_doubleClickConnection);
|
||||
}
|
||||
}
|
||||
|
||||
void AesItemList::onPrint() { LtsPrinting::printView(m_session, this, m_ui->widget->treeView()); }
|
||||
|
||||
void AesItemList::onAdlerBtn()
|
||||
{
|
||||
AesEffectState aesEffectState = model()->aesEffectStateId(currentRow());
|
||||
ProjectDataManagement::EffectSource effectSource = model()->aesEffectSourceId(currentRow());
|
||||
|
||||
DEBUG_LOG(m_logger) << "onAdlerBtn aesEffectState=" << aesEffectState;
|
||||
|
||||
switch (aesEffectState.underlying())
|
||||
{
|
||||
case AreaEffectSimulation::AesEffectState::EsReceived:
|
||||
{
|
||||
switch (effectSource.underlying())
|
||||
{
|
||||
case ProjectDataManagement::EffectSource::ES_ADLER:
|
||||
{
|
||||
AcknowledgeExternalAesItemRequest req;
|
||||
int aesId = model()->aesId(currentRow());
|
||||
req.aesId(aesId);
|
||||
m_requestHelper->startSingleRequest([req, this]() { return m_ftc->acknowledgeExternalAesItemRequest(req, this); });
|
||||
|
||||
break;
|
||||
}
|
||||
default:
|
||||
{
|
||||
ExplosionClusterReleaseReceivedRequest req;
|
||||
int aesId = model()->aesId(currentRow());
|
||||
req.id(aesId);
|
||||
m_requestHelper->startSingleRequest([req, this]() { return m_ftc->explosionClusterReleaseReceivedRequest(req, this); });
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
case AreaEffectSimulation::AesEffectState::EsCreated:
|
||||
case AreaEffectSimulation::AesEffectState::EsPrepared:
|
||||
{
|
||||
if (effectSource == ProjectDataManagement::EffectSource::ES_ADLER ||
|
||||
effectSource == ProjectDataManagement::EffectSource::ES_ADLER_STANDALONE)
|
||||
{
|
||||
AreaEffectSimulation::SetAesItemEffectorStateRequest req;
|
||||
req.aesId(model()->aesId(currentRow()));
|
||||
req.newEffectorState(AesEffectorState::EsReadyToFire);
|
||||
DEBUG_LOG(m_logger) << "Send setAesItemEffectorStateRequest with aesId: " << req.aesId() << ", AesEffectorState: " << req.newEffectorState();
|
||||
|
||||
m_requestHelper->startSingleRequest([req, this]() { return m_ftc->setAesItemEffectorStateRequest(req, this); });
|
||||
}
|
||||
break;
|
||||
}
|
||||
default:
|
||||
m_buttonBox->getButton(ADLER_BTN)->hide();
|
||||
}
|
||||
}
|
||||
|
||||
// enable Adler-Btn
|
||||
void AesItemList::onHandleAdler()
|
||||
{
|
||||
AesEffectState aesEffectState = model()->aesEffectStateId(currentRow());
|
||||
DEBUG_LOG(m_logger) << "onHandleAdler aesEffectState=" << aesEffectState;
|
||||
auto *adlerBtn = m_buttonBox->getButton(ADLER_BTN);
|
||||
|
||||
switch (aesEffectState.underlying())
|
||||
{
|
||||
case AreaEffectSimulation::AesEffectState::EsReceived:
|
||||
{
|
||||
adlerBtn->setText(tr("Mark received"));
|
||||
adlerBtn->setIcon(QIcon(QStringLiteral("icon:mortar_ammunition_administration.svg")));
|
||||
adlerBtn->show();
|
||||
break;
|
||||
}
|
||||
case AreaEffectSimulation::AesEffectState::EsCreated:
|
||||
case AreaEffectSimulation::AesEffectState::EsPrepared:
|
||||
{
|
||||
ProjectDataManagement::EffectSource effectSource = model()->aesEffectSourceId(currentRow());
|
||||
if (effectSource.underlying() == ProjectDataManagement::EffectSource::ES_ADLER ||
|
||||
effectSource.underlying() == ProjectDataManagement::EffectSource::ES_ADLER_STANDALONE)
|
||||
{
|
||||
const EffectCluster &ecData = m_dtc->effectCluster(model()->aesId(currentRow()));
|
||||
if (ecData.effectorState() == AreaEffectSimulation::AesEffectorState::EsNotReadyToFire)
|
||||
{
|
||||
adlerBtn->setText(tr("Ready To Fire"));
|
||||
adlerBtn->show();
|
||||
}
|
||||
else
|
||||
adlerBtn->hide();
|
||||
}
|
||||
break;
|
||||
}
|
||||
default:
|
||||
adlerBtn->hide();
|
||||
}
|
||||
}
|
||||
|
||||
void AesItemList::onCenterAesItem()
|
||||
{
|
||||
int aesId = model()->aesId(currentRow());
|
||||
std::shared_ptr<SituationMap::ForeignGuiInterface> ifc;
|
||||
if (m_session->getForeignGuiInterface<SituationMap::ForeignGuiInterface>(ifc))
|
||||
ifc->centerMapToAesObject(aesId);
|
||||
}
|
||||
|
||||
void AesItemList::hideColumn(int col) { m_ui->widget->hideColumn(col); }
|
||||
|
||||
void AesItemList::showColumn(int col) { m_ui->widget->showColumn(col); }
|
||||
|
||||
int AesItemList::currentRow() const
|
||||
{
|
||||
const auto selRows = m_ui->widget->selectedRows();
|
||||
if (selRows.count() != 1)
|
||||
return -1;
|
||||
return selRows.first().row();
|
||||
}
|
||||
|
||||
void AesItemList::setDataViewModel(QAbstractItemModel *model, const std::function<LtsDataView::AbstractDisplayWidget *()> &customDisplayWidgetCreator)
|
||||
{
|
||||
m_ui->widget->setModel(model, customDisplayWidgetCreator);
|
||||
}
|
||||
|
||||
void AesItemList::setDataViewModel(QAbstractItemModel *model) { m_ui->widget->setModel(model); }
|
||||
|
||||
void AesItemList::setShowExpired(bool show) { model()->setShowExpired(show); }
|
||||
|
||||
void AesItemList::setSortIndicator(int col) { m_ui->widget->setSortIndicator(col, Qt::AscendingOrder); }
|
||||
|
||||
void AesItemList::translateBase(const QString &windowTitle) { translate(m_ui, windowTitle); }
|
||||
|
||||
void AesItemList::tableColumnOrganiserSetting()
|
||||
{
|
||||
// LtsColumnOrganiser
|
||||
m_ui->widget->setColumnsOrganiserEnabled(identifier(), true);
|
||||
}
|
||||
|
||||
} // namespace AreaEffectSimulation
|
||||
+111
@@ -0,0 +1,111 @@
|
||||
/**
|
||||
* @RDE_HEADER@
|
||||
* AreaEffectSimulation - Contamination Overview Dialog
|
||||
* $Id$
|
||||
* $HeadURL$
|
||||
* $Author$
|
||||
* Created by Patric Karwat, SLSE, 2016-07-07
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "aes_base_exports.h"
|
||||
|
||||
#include <LtsWidgets/lts_dialog.h>
|
||||
#include <AreaEffectSimulation/aes_ftc.h>
|
||||
#include <AreaEffectSimulation/aes_dtc.h>
|
||||
#include <LtsUtilsGuiDds/request_helper.h>
|
||||
|
||||
|
||||
#include <AreaEffectSimulation/logger.h>
|
||||
|
||||
namespace Ui
|
||||
{
|
||||
class AesItemList;
|
||||
}
|
||||
namespace LtsSession
|
||||
{
|
||||
class LtsSession;
|
||||
}
|
||||
class QAbstractItemModel;
|
||||
namespace LtsDataView
|
||||
{
|
||||
class AbstractDisplayWidget;
|
||||
}
|
||||
|
||||
namespace AreaEffectSimulation
|
||||
{
|
||||
|
||||
class AesItemSortFilterProxyModel;
|
||||
template<typename T>
|
||||
class AesItemSortFilterProxyModelTmpl;
|
||||
|
||||
class AESBASEGUI_EXPORT AesItemList : public LtsWidgets::LtsDialog
|
||||
, protected AreaEffectSimulation::Interface::Ftc::MineResetReplyHandler
|
||||
, protected AreaEffectSimulation::Interface::Ftc::ExplosionClusterReleaseReceivedReplyHandler
|
||||
, protected AreaEffectSimulation::Interface::Ftc::AcknowledgeExternalAesItemReplyHandler
|
||||
, protected AreaEffectSimulation::Interface::Ftc::SetAesItemEffectorStateReplyHandler
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit AesItemList(const QString &menuGroup, QWidget *parent = nullptr);
|
||||
~AesItemList();
|
||||
|
||||
virtual bool init(LtsSession::LtsSession *session);
|
||||
bool isShowExpired() const { return m_showExpired; }
|
||||
void onMineResetReply(const Core::FunctionReplyObject &replyObject) override final { m_requestHelper->requestReply(replyObject); }
|
||||
void onExplosionClusterReleaseReceivedReply (const Core::FunctionReplyObject &replyObject) override final { m_requestHelper->requestReply(replyObject); }
|
||||
void onSetAesItemEffectorStateReply (const Core::FunctionReplyObject &replyObject) override final { m_requestHelper->requestReply(replyObject); }
|
||||
void onAcknowledgeExternalAesItemReply(const Core::FunctionReplyObject &replyObject) override final { m_requestHelper->requestReply(replyObject); }
|
||||
|
||||
public slots:
|
||||
void setShowExpired(bool show);
|
||||
|
||||
protected slots:
|
||||
void enaDisa();
|
||||
virtual void onPrint();
|
||||
virtual void onAddAesItem() = 0;
|
||||
virtual void onEditAesItem() = 0;
|
||||
virtual void onRemoveAesItem() = 0;
|
||||
virtual void onHandleAdler();
|
||||
void onAdlerBtn();
|
||||
void onCenterAesItem();
|
||||
void hideColumn(int col);
|
||||
void showColumn(int col);
|
||||
|
||||
protected:
|
||||
virtual void createModel() = 0;
|
||||
virtual AesItemSortFilterProxyModel *model() = 0;
|
||||
virtual const AesItemSortFilterProxyModel *model() const = 0;
|
||||
int currentRow() const; // the currently selected row (not current index!)
|
||||
void setDataViewModel(QAbstractItemModel *model, const std::function<LtsDataView::AbstractDisplayWidget*()> &customDisplayWidgetCreator);
|
||||
void setDataViewModel(QAbstractItemModel *model);
|
||||
void setSortIndicator(int col);
|
||||
void translateBase(const QString &windowTitle);
|
||||
void tableColumnOrganiserSetting() override;
|
||||
|
||||
std::shared_ptr<AreaEffectSimulation::Interface::Ftc> m_ftc;
|
||||
std::shared_ptr<AreaEffectSimulation::Interface::Dtc> m_dtc;
|
||||
QString m_menuGroup;
|
||||
LtsUtils::RequestHelper *m_requestHelper;
|
||||
bool m_showExpired;
|
||||
bool m_bHasAddEditOperatorRights;
|
||||
bool m_bHasAddAdlerOperatorRights;
|
||||
LtsSession::LtsSession *m_session;
|
||||
Ui::AesItemList *m_ui;
|
||||
QMetaObject::Connection m_doubleClickConnection;
|
||||
LOGGER_T m_logger;
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
class AesItemListTmpl : public AesItemList
|
||||
{
|
||||
public:
|
||||
using AesItemList::AesItemList;
|
||||
protected:
|
||||
AesItemSortFilterProxyModel *model() override { return m_model; }
|
||||
const AesItemSortFilterProxyModel *model() const override { return m_model; }
|
||||
|
||||
AesItemSortFilterProxyModelTmpl<T> *m_model = nullptr;
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>AesItemList</class>
|
||||
<widget class="QWidget" name="AesItemList">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>600</width>
|
||||
<height>500</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string notr="true">Aes Item List</string>
|
||||
</property>
|
||||
<property name="toolTip">
|
||||
<string/>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<item>
|
||||
<widget class="LtsDataView::LtsDataView" name="widget">
|
||||
<property name="toolTip">
|
||||
<string/>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<customwidgets>
|
||||
<customwidget>
|
||||
<class>LtsDataView::LtsDataView</class>
|
||||
<extends>QWidget</extends>
|
||||
<header>LtsDataView/lts_data_view.h</header>
|
||||
<container>1</container>
|
||||
</customwidget>
|
||||
</customwidgets>
|
||||
<resources/>
|
||||
<connections/>
|
||||
</ui>
|
||||
@@ -0,0 +1,94 @@
|
||||
/**
|
||||
* @RDE_HEADER@
|
||||
* AreaEffectSimulation - PixmapLabel
|
||||
* $Id$
|
||||
* $HeadURL$
|
||||
* $Author$
|
||||
* Created by Malte Schroeder, NLSE, 2018-05-09
|
||||
*/
|
||||
|
||||
#include "aes_pixmap_label.h"
|
||||
|
||||
#include <LtsCoordTrans/lts_coord_trans.h>
|
||||
|
||||
namespace AreaEffectSimulation
|
||||
{
|
||||
PixmapLabel::PixmapLabel(QWidget *parent)
|
||||
: QLabel(parent)
|
||||
, m_pixmap()
|
||||
{
|
||||
setMinimumSize(1, 1);
|
||||
setScaledContents(false);
|
||||
}
|
||||
|
||||
int PixmapLabel::heightForWidth(int width) const
|
||||
{
|
||||
return m_pixmap.isNull() ? this->height() : qRound(double(m_pixmap.height() * width)) / m_pixmap.width();
|
||||
}
|
||||
|
||||
QSize PixmapLabel::sizeHint() const
|
||||
{
|
||||
int w = this->width();
|
||||
return QSize(w, heightForWidth(w));
|
||||
}
|
||||
|
||||
QPixmap PixmapLabel::scaledPixmap(const QSize &size, const Qt::AspectRatioMode &aspectRatioMode, const Qt::TransformationMode &transformationMode) const
|
||||
{
|
||||
return m_pixmap.scaled(size, aspectRatioMode, transformationMode);
|
||||
}
|
||||
|
||||
Qt::BrushStyle PixmapLabel::checkForBrushStyle(const AesEffectState &state)
|
||||
{
|
||||
switch(state.underlying()) // Todo: change to correct BrushStyle?
|
||||
{
|
||||
case AesEffectState_def::EsUnknown:
|
||||
return Qt::BrushStyle::NoBrush;
|
||||
case AesEffectState_def::EsPrepared:
|
||||
case AesEffectState_def::EsFired:
|
||||
return Qt::BrushStyle::BDiagPattern;
|
||||
case AesEffectState_def::EsCreated:
|
||||
case AesEffectState_def::EsReceived:
|
||||
return Qt::BrushStyle::VerPattern;
|
||||
case AesEffectState_def::EsActivated:
|
||||
return Qt::BrushStyle::CrossPattern;
|
||||
case AesEffectState_def::EsRemoved:
|
||||
return Qt::BrushStyle::NoBrush;
|
||||
case AesEffectState_def::EsPaused:
|
||||
case AesEffectState_def::EsExpired:
|
||||
case AesEffectState_def::EsError:
|
||||
return Qt::BrushStyle::SolidPattern;
|
||||
}
|
||||
return Qt::BrushStyle::NoBrush;
|
||||
}
|
||||
|
||||
void PixmapLabel::setPixmap(const QPixmap &pixmap)
|
||||
{
|
||||
m_pixmap = pixmap;
|
||||
QLabel::setPixmap(scaledPixmap(this->size()));
|
||||
}
|
||||
|
||||
void PixmapLabel::resizeEvent(QResizeEvent *e)
|
||||
{
|
||||
QLabel::resizeEvent(e);
|
||||
|
||||
if(m_pixmap.isNull())
|
||||
return;
|
||||
QLabel::setPixmap(scaledPixmap(this->size()));
|
||||
}
|
||||
|
||||
QPolygonF PixmapLabel::geographic2Utm(const QPolygonF &poly)
|
||||
{
|
||||
if(poly.isEmpty())
|
||||
return QPolygonF();
|
||||
|
||||
QPolygonF polyOut;
|
||||
polyOut.reserve(poly.size());
|
||||
LtsCoordTrans::UtmCoordinate utmPos = LtsCoordTrans::UtmCoordinate::fromGeographic(poly.at(0));
|
||||
for(const QPointF &p : poly)
|
||||
{
|
||||
LtsCoordTrans::UtmCoordinate coord = LtsCoordTrans::UtmCoordinate::fromGeographic(p.x(), p.y(), utmPos.zone);
|
||||
polyOut.append(QPointF(coord.x, coord.y));
|
||||
}
|
||||
return polyOut;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
/**
|
||||
* @RDE_HEADER@
|
||||
* AreaEffectSimulation - PixmapLabel
|
||||
* $Id$
|
||||
* $HeadURL$
|
||||
* $Author$
|
||||
* Created by Malte Schroeder, NLSE, 2018-05-09
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <QLabel>
|
||||
#include <QPolygonF>
|
||||
#include "aes_base_exports.h"
|
||||
#include <AreaEffectSimulation/aes_enums.hpp>
|
||||
|
||||
namespace AreaEffectSimulation
|
||||
{
|
||||
constexpr int ICON_RESOLUTION = 256;
|
||||
|
||||
class AESBASEGUI_EXPORT PixmapLabel : public QLabel
|
||||
{
|
||||
public:
|
||||
explicit PixmapLabel(QWidget *parent = nullptr);
|
||||
|
||||
int heightForWidth(int width) const override;
|
||||
QSize sizeHint() const override;
|
||||
QPixmap scaledPixmap(const QSize &size,
|
||||
const Qt::AspectRatioMode &ratioMode = Qt::KeepAspectRatio,
|
||||
const Qt::TransformationMode &transformationMode = Qt::SmoothTransformation) const;
|
||||
|
||||
static Qt::BrushStyle checkForBrushStyle(const AreaEffectSimulation::AesEffectState &state);
|
||||
static QPolygonF geographic2Utm(const QPolygonF &poly);
|
||||
|
||||
public slots:
|
||||
void setPixmap(const QPixmap &pixmap);
|
||||
void resizeEvent(QResizeEvent *e) override;
|
||||
|
||||
private:
|
||||
QPixmap m_pixmap;
|
||||
};
|
||||
}
|
||||
Reference in new issue
Block a user