Files
qt5-legatus-legacy/Lts/Plugins/MeteoDataManagement/Gui/MeteoData/mdm_meteo_data_model.cpp
T
2026-08-13 18:33:10 +02:00

88 lines
2.9 KiB
C++
Executable File

/**
* @RDE_HEADER@
* HMI Plugin for MeteoDataManagement - Weather Station Overview Dialog Model
* $Id$
* $HeadURL$
* $Author$
* Created by Patric Karwat, SLSE, 2016-10.05
*/
#include "mdm_meteo_data_model.h"
#include <QCoreApplication>
#include <QColor>
namespace MeteoDataManagement
{
//---------------------------------
// MeteoDataModel
//---------------------------------
MeteoDataModel::MeteoDataModel(QObject *parent)
: LtsWidgets::LtsAbstractTableModel<MeteoDataManagement::MeteoData>({tr("Id"),
tr("Description"),
tr("Wind Direction [°]"),
tr("Wind Speed [m/s]"),
tr("Temperature [°C]"),
tr("Pressure [hPa]"),
tr("Humidity [%]")},
parent)
, m_dtc(nullptr)
, m_logger(getLogger("MeteoDataModel"))
{}
bool MeteoDataModel::initModel(const std::shared_ptr<MeteoDataManagement::Interface::Dtc> &dtc)
{
m_dtc = dtc;
connect(m_dtc.get(), &MeteoDataManagement::Interface::Dtc::meteoDataChanged,
this, &MeteoDataModel::onDataChanged);
// insert Model
m_dtc->meteoDatas([this](const MeteoDataManagement::MeteoData &meteoData) { insertRow(meteoData); });
return true;
}
QVariant MeteoDataModel::data(const QModelIndex &index, int role) const
{
if ((role != Qt::DisplayRole && role != Qt::BackgroundRole) || !indexIsValid(index))
return QVariant();
const MeteoDataManagement::MeteoData &meteoData = m_vecData.at(index.row());
if (role == Qt::BackgroundRole )
{
if (meteoData.isStaticMeteoData())
return QVariant();
if (index.column() == WindDirection || index.column() == WindSpeed)
return meteoData.windOk() ? QVariant() : QColor(Qt::red);
if (index.column() == Temperature || index.column() == Pressure || index.column() == Humidity)
return meteoData.climateOk() ? QVariant() : QColor(Qt::red);
return QVariant();
}
switch (index.column())
{
case Id:
return meteoData.weatherStationId();
case Note:
if (meteoData.isStaticMeteoData())
return QCoreApplication::translate("dds", meteoData.note().c_str());
return QString::fromStdString(meteoData.note());
case WindDirection:
return qRound((meteoData.windDirection() * 100.0)) / 100.0;
case WindSpeed:
return qRound(meteoData.windSpeed());
case Temperature:
return meteoData.temperature();
case Pressure:
return meteoData.pressure();
case Humidity:
return meteoData.humidity();
}
return QVariant();
}
} // namespace MeteoDataManagement