Weather UI Models

refs #663
This commit is contained in:
Roland Winklmeier
2016-06-05 22:56:52 +02:00
parent 91728fe414
commit 099282d0aa
8 changed files with 412 additions and 0 deletions

View File

@@ -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

View File

@@ -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 <Qt>
#include <QtGlobal>
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>())
{
double rate = dataCVariant.value<double>();
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>())
{
CCloudLayer::Precipitation precipitation = dataCVariant.value<CCloudLayer::Precipitation>();
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>())
{
CCloudLayer::Clouds clouds = dataCVariant.value<CCloudLayer::Clouds>();
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>())
{
int coverage = dataCVariant.value<double>();
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

View File

@@ -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<BlackMisc::Weather::CCloudLayer, BlackMisc::Weather::CCloudLayerList, false>
{
public:
//! Constructor
explicit CCloudLayerListModel(QObject *parent = nullptr);
//! Destructor
virtual ~CCloudLayerListModel() {}
};
}
}
#endif // guard

View File

@@ -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 <QFlags>
@@ -769,5 +772,10 @@ namespace BlackGui
template class CListModelBase<BlackMisc::Simulation::CSimulatedAircraft, BlackMisc::Simulation::CSimulatedAircraftList, true>;
template class CListModelBase<BlackMisc::Simulation::CDistributor, BlackMisc::Simulation::CDistributorList, true>;
template class CListModelBase<BlackMisc::Weather::CCloudLayer, BlackMisc::Weather::CCloudLayerList, false>;
template class CListModelBase<BlackMisc::Weather::CTemperatureLayer, BlackMisc::Weather::CTemperatureLayerList, false>;
template class CListModelBase<BlackMisc::Weather::CWindLayer, BlackMisc::Weather::CWindLayerList, false>;
} // namespace
} // namespace

View 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

View File

@@ -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<BlackMisc::Weather::CTemperatureLayer, BlackMisc::Weather::CTemperatureLayerList, false>
{
public:
//! Constructor
explicit CTemperatureLayerListModel(QObject *parent = nullptr);
//! Destructor
virtual ~CTemperatureLayerListModel() {}
};
}
}
#endif // guard

View File

@@ -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 <Qt>
#include <QtGlobal>
using namespace BlackMisc;
using namespace BlackMisc::PhysicalQuantities;
using namespace BlackMisc::Weather;
namespace BlackGui
{
namespace Models
{
//! Speed
class CSpeedFormatter : public CPhysiqalQuantiyFormatter<BlackMisc::PhysicalQuantities::CSpeedUnit, BlackMisc::PhysicalQuantities::CSpeed>
{
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<BlackMisc::PhysicalQuantities::CSpeed>();
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

View File

@@ -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<BlackMisc::Weather::CWindLayer, BlackMisc::Weather::CWindLayerList, false>
{
public:
//! Constructor
explicit CWindLayerListModel(QObject *parent = nullptr);
//! Destructor
virtual ~CWindLayerListModel() {}
};
}
}
#endif // guard