Initial commit
This commit is contained in:
commit
b7d90b9afe
16245 files changed
+3396666
No files matched your search
Executable
+146
@@ -0,0 +1,146 @@
|
||||
/**
|
||||
* @RDE_HEADER@
|
||||
* HMI Plugin for ParticipantManagement - Template Model
|
||||
* $Id$
|
||||
* $HeadURL$
|
||||
* $Author$
|
||||
* Created by Patric Karwat, SLSE, 2016-10-05
|
||||
*/
|
||||
|
||||
#include "participant_template_chooser_model.h"
|
||||
#include <Plugins/ParticipantManagement/ppm_mime_datas.h>
|
||||
#include <ParticipantManagement/ppm_translation.h>
|
||||
#include <LtsSession/lts_session_data_dds.h>
|
||||
#include <Plugins/AdvancedSymbology/asb_data_plugin_interface.h>
|
||||
|
||||
#include <QMimeData>
|
||||
|
||||
namespace ParticipantManagement
|
||||
{
|
||||
//---------------------------------
|
||||
// ParticipantTemplateChooserModel
|
||||
//---------------------------------
|
||||
ParticipantTemplateChooserModel::ParticipantTemplateChooserModel(bool asSupportService, QObject *parent)
|
||||
: LtsWidgets::LtsAbstractTableModel<ParticipantManagement::TemplateParticipant>({tr("Designator/Identifier"),
|
||||
tr("Type Class"),
|
||||
tr("Type")},
|
||||
parent)
|
||||
, AdvancedSymbology::TableModelSymbolRenderer<ParticipantTemplateChooserModel>(ColDesignatorIdentifier)
|
||||
, m_asSupportService(asSupportService)
|
||||
, m_dtc(nullptr)
|
||||
, m_logger(getLogger("ParticipantTemplateChooserModel"))
|
||||
{}
|
||||
|
||||
ParticipantTemplateChooserModel::~ParticipantTemplateChooserModel()
|
||||
{}
|
||||
|
||||
bool ParticipantTemplateChooserModel::initModel(LtsSession::LtsSessionDataDds *session,
|
||||
const std::shared_ptr<ParticipantManagement::Interface::Dtc> &dtc)
|
||||
{
|
||||
if (!dtc)
|
||||
return false;
|
||||
|
||||
// optional
|
||||
std::shared_ptr<AdvancedSymbology::ForeignDataInterface> asb;
|
||||
session->getForeignDataInterface<AdvancedSymbology::DataInterface>(asb);
|
||||
AdvancedSymbology::TableModelSymbolRenderer<ParticipantTemplateChooserModel>::init(asb, this);
|
||||
|
||||
m_dtc = dtc;
|
||||
|
||||
connect(m_dtc.get(), &ParticipantManagement::Interface::Dtc::templateParticipantChanged ,
|
||||
this, &ParticipantTemplateChooserModel::onTemplateChanged);
|
||||
|
||||
// insert Model
|
||||
auto cb = [this](const ParticipantManagement::TemplateParticipant &templateData)
|
||||
{
|
||||
if (insertRow(templateData))
|
||||
tryRenderSymbol(QString::fromStdString(templateData.symbol()), templateData.templateId());
|
||||
};
|
||||
m_dtc->templateParticipants(cb);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
QVariant ParticipantTemplateChooserModel::data(const QModelIndex &index, int role) const
|
||||
{
|
||||
if (!indexIsValid(index) || (role != Qt::DisplayRole && role != Qt::DecorationRole))
|
||||
return QVariant();
|
||||
|
||||
const ParticipantManagement::TemplateParticipant &templateData = m_vecData.at(index.row());
|
||||
if (role == Qt::DecorationRole)
|
||||
return decorationData(index, templateData.templateId());
|
||||
|
||||
switch (index.column())
|
||||
{
|
||||
case ColDesignatorIdentifier:
|
||||
{
|
||||
if (templateData.designator().size() == 0)
|
||||
return QString::fromStdString(templateData.tacticalIdentifier());
|
||||
return QString(QString::fromStdString(templateData.designator()) + QLatin1Char('/') +
|
||||
QString::fromStdString(templateData.tacticalIdentifier()));
|
||||
}
|
||||
case ColTypeClass:
|
||||
return ParticipantManagement::toString(m_dtc->type(templateData.typeId()).typeClass());
|
||||
case ColType:
|
||||
return ParticipantManagement::trTypeName(m_dtc->type(templateData.typeId()).name());
|
||||
}
|
||||
return QVariant();
|
||||
}
|
||||
|
||||
|
||||
Qt::ItemFlags ParticipantTemplateChooserModel::flags(const QModelIndex &index) const
|
||||
{
|
||||
Qt::ItemFlags retFlags = QAbstractTableModel::flags(index);
|
||||
retFlags |= Qt::ItemIsDragEnabled;
|
||||
|
||||
return retFlags;
|
||||
}
|
||||
|
||||
QMimeData *ParticipantTemplateChooserModel::mimeData(const QModelIndexList &indexes) const
|
||||
{
|
||||
QMimeData *mimeData = new QMimeData();
|
||||
for (const QModelIndex &index : indexes)
|
||||
{
|
||||
if (index.isValid())
|
||||
{
|
||||
QByteArray encodedData = QByteArray::number(getRowData(index.row()).templateId());
|
||||
mimeData->setData(ParticipantManagement::ParticipantTemplateRoot, encodedData);
|
||||
return mimeData;
|
||||
}
|
||||
}
|
||||
|
||||
return mimeData;
|
||||
}
|
||||
|
||||
|
||||
QStringList ParticipantManagement::ParticipantTemplateChooserModel::mimeTypes() const
|
||||
{
|
||||
return { ParticipantManagement::ParticipantTemplateRoot };
|
||||
}
|
||||
|
||||
|
||||
void ParticipantTemplateChooserModel::onTemplateChanged(const ParticipantManagement::TemplateParticipant &data,
|
||||
DataModification modType)
|
||||
{
|
||||
if (onDataChanged(data, modType) && modType != DataModification::eRemoved)
|
||||
tryRenderSymbol(QString::fromStdString(data.symbol()), data.templateId());
|
||||
}
|
||||
|
||||
|
||||
bool ParticipantTemplateChooserModel::isFiltered(const TemplateParticipant &data, DataModification modType) const
|
||||
{
|
||||
Q_UNUSED(modType);
|
||||
|
||||
if (data.superiorTemplateId() != 0)
|
||||
return true;
|
||||
const TypeClass &tc = m_dtc->type(data.typeId()).typeClass();
|
||||
|
||||
if (m_asSupportService)
|
||||
return (tc != TypeClass::SupportEntity && tc != TypeClass::SupportUnit);
|
||||
|
||||
return (tc == TypeClass::SupportEntity || tc == TypeClass::SupportUnit);
|
||||
}
|
||||
|
||||
} // namespace ParticipantManagement
|
||||
Reference in new issue
Block a user