mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-04 08:36:52 +08:00
73
src/blackgui/models/temperaturelayerlistmodel.cpp
Normal file
73
src/blackgui/models/temperaturelayerlistmodel.cpp
Normal file
@@ -0,0 +1,73 @@
|
||||
/* Copyright (C) 2016
|
||||
* Swift Project Community / Contributors
|
||||
*
|
||||
* This file is part of swift Project. It is subject to the license terms in the LICENSE file found in the top-level
|
||||
* directory of this distribution and at http://www.swift-project.org/license.html. No part of swift project,
|
||||
* including this file, may be copied, modified, propagated, or distributed except according to the terms
|
||||
* contained in the LICENSE file.
|
||||
*/
|
||||
|
||||
#include "blackgui/models/temperaturelayerlistmodel.h"
|
||||
#include "blackgui/models/columnformatters.h"
|
||||
|
||||
#include <Qt>
|
||||
#include <QtGlobal>
|
||||
|
||||
using namespace BlackMisc;
|
||||
using namespace BlackMisc::PhysicalQuantities;
|
||||
using namespace BlackMisc::Weather;
|
||||
|
||||
namespace BlackGui
|
||||
{
|
||||
namespace Models
|
||||
{
|
||||
|
||||
//! Temperature in degrees
|
||||
class CTemperatureFormatter : public CPhysiqalQuantiyFormatter<CTemperatureUnit, CTemperature>
|
||||
{
|
||||
public:
|
||||
//! Constructor
|
||||
CTemperatureFormatter(int alignment = alignRightVCenter(), bool withUnit = true, bool i18n = true) : CPhysiqalQuantiyFormatter(CTemperatureUnit::C(), 0, alignment, withUnit, i18n) {}
|
||||
};
|
||||
|
||||
//! Relative Humidity
|
||||
class CRelativeHumidityFormatter : public CDefaultFormatter
|
||||
{
|
||||
public:
|
||||
//! Constructor
|
||||
CRelativeHumidityFormatter(int alignment = alignDefault()) : CDefaultFormatter(alignment, false, roleDisplay()) {}
|
||||
|
||||
//! \copydoc CDefaultFormatter::displayRole
|
||||
virtual CVariant displayRole(const CVariant &dataCVariant) const override
|
||||
{
|
||||
if (dataCVariant.canConvert<double>())
|
||||
{
|
||||
int rh = dataCVariant.value<double>();
|
||||
QString formattedString = QString::number(rh) + " %";
|
||||
return formattedString;
|
||||
}
|
||||
Q_ASSERT_X(false, "CRelativeHumidityFormatter", "no double value");
|
||||
return CVariant();
|
||||
}
|
||||
};
|
||||
|
||||
CTemperatureLayerListModel::CTemperatureLayerListModel(QObject *parent) :
|
||||
CListModelBase("TemperatureLayerListModel", parent)
|
||||
{
|
||||
this->m_columns.addColumn(CColumn("level", CTemperatureLayer::IndexLevel, new CAltitudeFormatter()));
|
||||
this->m_columns.addColumn(CColumn("temperature", CTemperatureLayer::IndexTemperature, new CTemperatureFormatter()));
|
||||
this->m_columns.addColumn(CColumn("dew point", CTemperatureLayer::IndexDewPoint, new CTemperatureFormatter()));
|
||||
this->m_columns.addColumn(CColumn("relative humidity", CTemperatureLayer::IndexRelativeHumidity, new CRelativeHumidityFormatter()));
|
||||
|
||||
// default sort order
|
||||
this->setSortColumnByPropertyIndex(CTemperatureLayer::IndexLevel);
|
||||
this->m_sortOrder = Qt::AscendingOrder;
|
||||
|
||||
// force strings for translation in resource files
|
||||
(void)QT_TRANSLATE_NOOP("ModelTemperatureLayerList", "level");
|
||||
(void)QT_TRANSLATE_NOOP("ModelTemperatureLayerList", "temperature");
|
||||
(void)QT_TRANSLATE_NOOP("ModelTemperatureLayerList", "dew point");
|
||||
(void)QT_TRANSLATE_NOOP("ModelTemperatureLayerList", "relative humidity");
|
||||
}
|
||||
} // ns
|
||||
} // ns
|
||||
Reference in New Issue
Block a user