diff --git a/src/blackgui/models/allmodels.h b/src/blackgui/models/allmodels.h index 74c50b5ca..f1ac491a7 100644 --- a/src/blackgui/models/allmodels.h +++ b/src/blackgui/models/allmodels.h @@ -18,6 +18,7 @@ #include "blackgui/models/airportlistmodel.h" #include "blackgui/models/atcstationlistmodel.h" #include "blackgui/models/clientlistmodel.h" +#include "blackgui/models/cloudlayerlistmodel.h" #include "blackgui/models/countrylistmodel.h" #include "blackgui/models/distributorlistmodel.h" #include "blackgui/models/identifierlistmodel.h" @@ -26,7 +27,9 @@ #include "blackgui/models/serverlistmodel.h" #include "blackgui/models/simulatedaircraftlistmodel.h" #include "blackgui/models/statusmessagelistmodel.h" +#include "blackgui/models/temperaturelayerlistmodel.h" #include "blackgui/models/textmessagelistmodel.h" #include "blackgui/models/userlistmodel.h" +#include "blackgui/models/windlayerlistmodel.h" #endif // guard diff --git a/src/blackgui/models/cloudlayerlistmodel.cpp b/src/blackgui/models/cloudlayerlistmodel.cpp new file mode 100644 index 000000000..04590bd19 --- /dev/null +++ b/src/blackgui/models/cloudlayerlistmodel.cpp @@ -0,0 +1,144 @@ +/* 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/cloudlayerlistmodel.h" +#include "blackgui/models/columnformatters.h" + +#include +#include + +using namespace BlackMisc; +using namespace BlackMisc::PhysicalQuantities; +using namespace BlackMisc::Weather; + +namespace BlackGui +{ + namespace Models + { + + //! Relative Humidity + class CPrecipitationRateFormatter : public CDefaultFormatter + { + public: + //! Constructor + CPrecipitationRateFormatter(int alignment = alignDefault()) : CDefaultFormatter(alignment, false, roleDisplay()) {} + + //! \copydoc CDefaultFormatter::displayRole + virtual CVariant displayRole(const CVariant &dataCVariant) const override + { + if (dataCVariant.canConvert()) + { + double rate = dataCVariant.value(); + QString formattedString = QString::number(rate) + " mm/s"; + return formattedString; + } + Q_ASSERT_X(false, "CPrecipitationRateFormatter", "no double value"); + return CVariant(); + } + }; + + //! Precipitation + class CPrecipitationFormatter : public CDefaultFormatter + { + public: + //! Constructor + CPrecipitationFormatter(int alignment = alignDefault()) : CDefaultFormatter(alignment, false, roleDisplay()) {} + + //! \copydoc CDefaultFormatter::displayRole + virtual CVariant displayRole(const CVariant &dataCVariant) const override + { + if (dataCVariant.canConvert()) + { + CCloudLayer::Precipitation precipitation = dataCVariant.value(); + switch (precipitation) + { + case CCloudLayer::PrecipitationUnknown: return QString("Unknown"); + case CCloudLayer::NoPrecipitation: return QString("None"); + case CCloudLayer::Rain: return QString("Rain"); + case CCloudLayer::Snow: return QString("Snow"); + } + } + Q_ASSERT_X(false, "CPrecipitationFormatter", "no CCloudLayer::Precipitation value"); + return CVariant(); + } + }; + + //! Clouds + class CCloudsFormatter : public CDefaultFormatter + { + public: + //! Constructor + CCloudsFormatter(int alignment = alignDefault()) : CDefaultFormatter(alignment, false, roleDisplay()) {} + + //! \copydoc CDefaultFormatter::displayRole + virtual CVariant displayRole(const CVariant &dataCVariant) const override + { + if (dataCVariant.canConvert()) + { + CCloudLayer::Clouds clouds = dataCVariant.value(); + switch (clouds) + { + case CCloudLayer::NoClouds: return QString("None"); + case CCloudLayer::Cirrus: return QString("Cirrus"); + case CCloudLayer::Stratus: return QString("Stratus"); + case CCloudLayer::Cumulus: return QString("Cumulus"); + case CCloudLayer::Thunderstorm: return QString("Thunderstorm"); + case CCloudLayer::CloudsUnknown: return QString("N/A"); + } + } + Q_ASSERT_X(false, "CCloudsFormatter", "no CCloudLayer::Clouds value"); + return CVariant(); + } + }; + + //! Relative Humidity + class CCoverageFormatter : public CDefaultFormatter + { + public: + //! Constructor + CCoverageFormatter(int alignment = alignDefault()) : CDefaultFormatter(alignment, false, roleDisplay()) {} + + //! \copydoc CDefaultFormatter::displayRole + virtual CVariant displayRole(const CVariant &dataCVariant) const override + { + if (dataCVariant.canConvert()) + { + int coverage = dataCVariant.value(); + QString formattedString = QString::number(coverage) + " %"; + return formattedString; + } + Q_ASSERT_X(false, "CCoverageFormatter", "no int value"); + return CVariant(); + } + }; + + CCloudLayerListModel::CCloudLayerListModel(QObject *parent) : + CListModelBase("CloudLayerListModel", parent) + { + this->m_columns.addColumn(CColumn("base", CCloudLayer::IndexBase, new CAltitudeFormatter())); + this->m_columns.addColumn(CColumn("top", CCloudLayer::IndexTop, new CAltitudeFormatter())); + this->m_columns.addColumn(CColumn("precipitation rate", CCloudLayer::IndexPrecipitationRate, new CPrecipitationRateFormatter())); + this->m_columns.addColumn(CColumn("precipitation", CCloudLayer::IndexPrecipitation, new CPrecipitationFormatter())); + this->m_columns.addColumn(CColumn("clouds", CCloudLayer::IndexClouds, new CCloudsFormatter())); + this->m_columns.addColumn(CColumn("coverage", CCloudLayer::IndexCoveragePercent, new CCoverageFormatter())); + + // default sort order + this->setSortColumnByPropertyIndex(CCloudLayer::IndexBase); + this->m_sortOrder = Qt::AscendingOrder; + + // force strings for translation in resource files + (void)QT_TRANSLATE_NOOP("ModelCloudLayerList", "base"); + (void)QT_TRANSLATE_NOOP("ModelCloudLayerList", "top"); + (void)QT_TRANSLATE_NOOP("ModelCloudLayerList", "precipitation rate"); + (void)QT_TRANSLATE_NOOP("ModelCloudLayerList", "precipitation"); + (void)QT_TRANSLATE_NOOP("ModelCloudLayerList", "clouds"); + (void)QT_TRANSLATE_NOOP("ModelCloudLayerList", "coverage"); + } + } // ns +} // ns diff --git a/src/blackgui/models/cloudlayerlistmodel.h b/src/blackgui/models/cloudlayerlistmodel.h new file mode 100644 index 000000000..25ccaf8b6 --- /dev/null +++ b/src/blackgui/models/cloudlayerlistmodel.h @@ -0,0 +1,39 @@ +/* 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. + */ + +//! \file + +#ifndef BLACKGUI_CLOUDLAYERLISTMODEL_H +#define BLACKGUI_CLOUDLAYERLISTMODEL_H + +#include "blackgui/blackguiexport.h" +#include "blackgui/models/listmodelbase.h" +#include "blackmisc/weather/cloudlayer.h" +#include "blackmisc/weather/cloudlayerlist.h" + +class QObject; + +namespace BlackGui +{ + namespace Models + { + //! Cloud layer list model + class BLACKGUI_EXPORT CCloudLayerListModel : + public CListModelBase + { + public: + //! Constructor + explicit CCloudLayerListModel(QObject *parent = nullptr); + + //! Destructor + virtual ~CCloudLayerListModel() {} + }; + } +} +#endif // guard diff --git a/src/blackgui/models/listmodelbase.cpp b/src/blackgui/models/listmodelbase.cpp index 848436aab..53bac3c5b 100644 --- a/src/blackgui/models/listmodelbase.cpp +++ b/src/blackgui/models/listmodelbase.cpp @@ -51,6 +51,9 @@ #include "blackmisc/statusmessagelist.h" #include "blackmisc/variant.h" #include "blackmisc/verify.h" +#include "blackmisc/weather/cloudlayerlist.h" +#include "blackmisc/weather/temperaturelayerlist.h" +#include "blackmisc/weather/windlayerlist.h" #include "blackmisc/worker.h" #include @@ -769,5 +772,10 @@ namespace BlackGui template class CListModelBase; template class CListModelBase; + template class CListModelBase; + template class CListModelBase; + template class CListModelBase; + + } // namespace } // namespace diff --git a/src/blackgui/models/temperaturelayerlistmodel.cpp b/src/blackgui/models/temperaturelayerlistmodel.cpp new file mode 100644 index 000000000..735a08647 --- /dev/null +++ b/src/blackgui/models/temperaturelayerlistmodel.cpp @@ -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 +#include + +using namespace BlackMisc; +using namespace BlackMisc::PhysicalQuantities; +using namespace BlackMisc::Weather; + +namespace BlackGui +{ + namespace Models + { + + //! Temperature in degrees + class CTemperatureFormatter : public CPhysiqalQuantiyFormatter + { + 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()) + { + int rh = dataCVariant.value(); + 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 diff --git a/src/blackgui/models/temperaturelayerlistmodel.h b/src/blackgui/models/temperaturelayerlistmodel.h new file mode 100644 index 000000000..333ab6012 --- /dev/null +++ b/src/blackgui/models/temperaturelayerlistmodel.h @@ -0,0 +1,39 @@ +/* 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. + */ + +//! \file + +#ifndef BLACKGUI_TEMPERATURELAYERLISTMODEL_H +#define BLACKGUI_TEMPERATURELAYERLISTMODEL_H + +#include "blackgui/blackguiexport.h" +#include "blackgui/models/listmodelbase.h" +#include "blackmisc/weather/temperaturelayer.h" +#include "blackmisc/weather/temperaturelayerlist.h" + +class QObject; + +namespace BlackGui +{ + namespace Models + { + //! Temperature layer list model + class BLACKGUI_EXPORT CTemperatureLayerListModel : + public CListModelBase + { + public: + //! Constructor + explicit CTemperatureLayerListModel(QObject *parent = nullptr); + + //! Destructor + virtual ~CTemperatureLayerListModel() {} + }; + } +} +#endif // guard diff --git a/src/blackgui/models/windlayerlistmodel.cpp b/src/blackgui/models/windlayerlistmodel.cpp new file mode 100644 index 000000000..1374fcc35 --- /dev/null +++ b/src/blackgui/models/windlayerlistmodel.cpp @@ -0,0 +1,67 @@ +/* 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/windlayerlistmodel.h" +#include "blackgui/models/columnformatters.h" + +#include +#include + +using namespace BlackMisc; +using namespace BlackMisc::PhysicalQuantities; +using namespace BlackMisc::Weather; + +namespace BlackGui +{ + namespace Models + { + + //! Speed + class CSpeedFormatter : public CPhysiqalQuantiyFormatter + { + public: + //! Constructor + CSpeedFormatter(int alignment = alignRightVCenter(), bool withUnit = true, bool i18n = true) : CPhysiqalQuantiyFormatter(BlackMisc::PhysicalQuantities::CSpeedUnit::kts(), 0, alignment, withUnit, i18n) {} + + //! \copydoc CDefaultFormatter::displayRole + virtual CVariant displayRole(const CVariant &dataCVariant) const override + { + // special treatment for some cases + BlackMisc::PhysicalQuantities::CSpeed s = dataCVariant.value(); + if (!s.isNull() && (s.isPositiveWithEpsilonConsidered() || s.isZeroEpsilonConsidered())) + { + return CPhysiqalQuantiyFormatter::displayRole(dataCVariant); + } + else + { + return ""; + } + } + }; + + CWindLayerListModel::CWindLayerListModel(QObject *parent) : + CListModelBase("WindLayerListModel", parent) + { + this->m_columns.addColumn(CColumn("level", CWindLayer::IndexLevel, new CAltitudeFormatter())); + this->m_columns.addColumn(CColumn("direction", CWindLayer::IndexDirection, new CAngleDegreeFormatter())); + this->m_columns.addColumn(CColumn("speed", CWindLayer::IndexSpeed, new CSpeedFormatter())); + this->m_columns.addColumn(CColumn("gust speed", CWindLayer::IndexGustSpeed, new CSpeedFormatter())); + + // default sort order + this->setSortColumnByPropertyIndex(CWindLayer::IndexLevel); + this->m_sortOrder = Qt::AscendingOrder; + + // force strings for translation in resource files + (void)QT_TRANSLATE_NOOP("ModelWindLayerList", "level"); + (void)QT_TRANSLATE_NOOP("ModelWindLayerList", "direction"); + (void)QT_TRANSLATE_NOOP("ModelWindLayerList", "speed"); + (void)QT_TRANSLATE_NOOP("ModelWindLayerList", "gust speed"); + } + } // ns +} // ns diff --git a/src/blackgui/models/windlayerlistmodel.h b/src/blackgui/models/windlayerlistmodel.h new file mode 100644 index 000000000..8abbfce8c --- /dev/null +++ b/src/blackgui/models/windlayerlistmodel.h @@ -0,0 +1,39 @@ +/* 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. + */ + +//! \file + +#ifndef BLACKGUI_WINDLAYERLISTMODEL_H +#define BLACKGUI_WINDLAYERLISTMODEL_H + +#include "blackgui/blackguiexport.h" +#include "blackgui/models/listmodelbase.h" +#include "blackmisc/weather/windlayer.h" +#include "blackmisc/weather/windlayerlist.h" + +class QObject; + +namespace BlackGui +{ + namespace Models + { + //! Wind layer list model + class BLACKGUI_EXPORT CWindLayerListModel : + public CListModelBase + { + public: + //! Constructor + explicit CWindLayerListModel(QObject *parent = nullptr); + + //! Destructor + virtual ~CWindLayerListModel() {} + }; + } +} +#endif // guard