Files
qt5-legatus-legacy/Lts/Plugins/AreaEffectSimulation/Gui/GasPipe/CustomView/aes_gas_pipe.cpp
T
2026-08-13 18:33:10 +02:00

75 lines
2.0 KiB
C++
Executable File

/**
* @RDE_HEADER@
* CustomView for AES GasPipe
* $Id$
* $HeadURL$
* $Author$
* Created by hjl, SLSE, 2017-06-20
*/
#include "aes_gas_pipe.h"
#include "ui_aes_gas_pipe.h"
#include "aes_gas_pipes_model.h"
#include <Services/AreaEffectSimulation/Utils/polygons.h>
namespace AreaEffectSimulation
{
CustomViewGasPipe::CustomViewGasPipe(QWidget *parent)
: AbstractDisplayWidget(parent)
, m_ui(new Ui::CustomViewGasPipe)
{
m_ui->setupUi(this);
}
CustomViewGasPipe::~CustomViewGasPipe()
{
delete m_ui;
}
bool CustomViewGasPipe::init(const QModelIndex &idx)
{
if (!idx.isValid())
return false;
m_ui->lblName->setText(rowData(idx, AreaEffectSimulation::GasPipesModel::BcName).toString());
m_ui->lblIcon->clear();
m_ui->lblIcon->setAutoFillBackground(true);
const AesItemSortFilterProxyModel *sfpm = qobject_cast<const AesItemSortFilterProxyModel*>(idx.model());
if (!sfpm)
return false;
const GasPipesModel *aesModel = qobject_cast<const GasPipesModel*>(sfpm->sourceModel());
if (!aesModel)
return false;
const auto srcIdx = sfpm->mapToSource(idx);
GasPipe gasPipe = aesModel->getRowData(srcIdx.row());
calculateIcon(gasPipe, sfpm->partyColor(idx.row()));
return true;
}
bool CustomViewGasPipe::calculateIcon(const AreaEffectSimulation::GasPipe &line, const QColor &color)
{
if (line.segments().size() == 0)
return false;
QVector<Database::AesGasPipeSegment> segments;
segments.reserve(line.segments().size());
int counter = 0;
for (const Core::GeoPosition2D &s : line.segments())
{
Database::AesGasPipeSegment segment;
segment.position = QPointF(s.lon(), s.lat());
segments.append(segment);
counter++;
}
QPolygonF poly = AreaEffectSimulation::Polygons::gasPipe(segments, line.width());
Qt::BrushStyle bStyle = Qt::BrushStyle::NoBrush;
const auto pix = Polygons::pixmapFromPolygon(poly, color, ICON_RESOLUTION, bStyle, true);
m_ui->lblIcon->setPixmap(pix);
return true;
}
} // namespace AreaEffectSimulation