Commit db1dc359 authored by Nicolas Fella's avatar Nicolas Fella Committed by Devin Lin
Browse files

Run clang-format and add commit hook

parent 819b3572
Pipeline #73116 passed with stage
in 17 seconds
......@@ -30,6 +30,7 @@ include(KDEInstallDirs)
include(KDECMakeSettings)
include(ECMPoQmTools)
include(KDECompilerSettings NO_POLICY_SCOPE)
include(KDEGitCommitHooks)
ecm_setup_version(${PROJECT_VERSION}
VARIABLE_PREFIX KWEATHER
......@@ -81,3 +82,5 @@ feature_summary(WHAT ALL INCLUDE_QUIET_PACKAGES FATAL_ON_MISSING_REQUIRED_PACKAG
include(KDEClangFormat)
file(GLOB_RECURSE ALL_CLANG_FORMAT_SOURCE_FILES src/*.cpp src/*.h)
kde_clang_format(${ALL_CLANG_FORMAT_SOURCE_FILES})
kde_configure_git_pre_commit_hook(CHECKS CLANG_FORMAT)
......@@ -23,8 +23,9 @@ static double convertTemp(double temp)
}
};
static QString tempConverter(double temp) {
return QString::number(qRound(convertTemp(temp))) + "°";
static QString tempConverter(double temp)
{
return QString::number(qRound(convertTemp(temp))) + "°";
}
enum class WindDirection { N, NW, W, SW, S, SE, E, NE };
......
......@@ -22,9 +22,10 @@ int LocationQueryModel::rowCount(const QModelIndex &parent) const
return m_results.size();
}
static QString buildResultName(const KWeatherCore::LocationQueryResult &result) {
static QString buildResultName(const KWeatherCore::LocationQueryResult &result)
{
const auto &countryCode = result.countryCode();
if(result.subdivision() && countryCode == "US") {
if (result.subdivision() && countryCode == "US") {
return result.toponymName() + ", " + *result.subdivision() + " | " + result.countryName();
}
return result.toponymName() + " | " + result.countryName();
......
......@@ -26,12 +26,12 @@
#include "kweathersettings.h"
#include "locationquerymodel.h"
#include "version.h"
#include "weatherdaymodel.h"
#include "weatherforecastmanager.h"
#include "weatherhourmodel.h"
#include "weatherlocation.h"
#include "weatherlocationmodel.h"
#include "version.h"
class AbstractHourlyWeatherForecast;
class AbstractDailyWeatherForecast;
......@@ -45,7 +45,7 @@ Q_DECL_EXPORT int main(int argc, char *argv[])
QQuickStyle::setStyle(QStringLiteral("Material"));
#else
QApplication app(argc, argv);
if(qEnvironmentVariableIsEmpty("QT_QUICK_CONTROLS_STYLE")) {
if (qEnvironmentVariableIsEmpty("QT_QUICK_CONTROLS_STYLE")) {
QQuickStyle::setStyle(QStringLiteral("org.kde.desktop"));
}
#endif
......@@ -53,7 +53,12 @@ Q_DECL_EXPORT int main(int argc, char *argv[])
KLocalizedString::setApplicationDomain("kweather");
engine.rootContext()->setContextObject(new KLocalizedContext(&engine));
KAboutData aboutData("kweather", i18n("Weather"), QStringLiteral(KWEATHER_VERSION_STRING), i18n("A convergent weather application for Plasma"), KAboutLicense::GPL, i18n("© 2020-2021 Plasma Development Team"));
KAboutData aboutData("kweather",
i18n("Weather"),
QStringLiteral(KWEATHER_VERSION_STRING),
i18n("A convergent weather application for Plasma"),
KAboutLicense::GPL,
i18n("© 2020-2021 Plasma Development Team"));
aboutData.addAuthor(i18n("Han Young"), QString(), QStringLiteral("hanyoung@protonmail.com"));
aboutData.addAuthor(i18n("Devin Lin"), QString(), QStringLiteral("espidev@gmail.com"), QStringLiteral("https://espi.dev"));
KAboutData::setApplicationData(aboutData);
......
......@@ -31,8 +31,7 @@ int HourlyModel::rowCount(const QModelIndex &index) const
}
QHash<int, QByteArray> HourlyModel::roleNames() const
{
return {{Time, "time"}, {Icon, "weatherIcon"}, {Description, "description"},
{Temperature, "temperature"}, {Precipitation, "precipitation"}};
return {{Time, "time"}, {Icon, "weatherIcon"}, {Description, "description"}, {Temperature, "temperature"}, {Precipitation, "precipitation"}};
}
void HourlyModel::loadForecast(KWeatherCore::WeatherForecast forecast)
{
......@@ -43,8 +42,8 @@ void HourlyModel::loadForecast(KWeatherCore::WeatherForecast forecast)
}
const KWeatherCore::HourlyWeatherForecast &HourlyModel::getNthHour(int index) const
{
auto dayIndex {0};
auto hourIndex {0};
auto dayIndex{0};
auto hourIndex{0};
for (const auto &day : m_location.dailyWeatherForecast()) {
if ((int)day.hourlyWeatherForecast().size() - 1 < index) {
index -= day.hourlyWeatherForecast().size();
......
......@@ -5,8 +5,8 @@
#ifndef HOURLYMODEL_H
#define HOURLYMODEL_H
#include <QAbstractListModel>
#include <KWeatherCore/WeatherForecast>
#include <QAbstractListModel>
class HourlyModel : public QAbstractListModel
{
Q_OBJECT
......@@ -14,7 +14,7 @@ class HourlyModel : public QAbstractListModel
Q_PROPERTY(QString currentTemperature READ currentTemperature NOTIFY reseted)
Q_PROPERTY(QString currentDescription READ currentDescription NOTIFY reseted)
public:
enum HourlyRole {Time = Qt::UserRole + 1, Icon, Description, Temperature, Precipitation};
enum HourlyRole { Time = Qt::UserRole + 1, Icon, Description, Temperature, Precipitation };
virtual QVariant data(const QModelIndex &index, int role) const override;
virtual int rowCount(const QModelIndex &index) const override;
virtual QHash<int, QByteArray> roleNames() const override;
......@@ -26,6 +26,7 @@ public Q_SLOTS:
void loadForecast(KWeatherCore::WeatherForecast);
Q_SIGNALS:
void reseted();
private:
const KWeatherCore::HourlyWeatherForecast &getNthHour(int index) const;
KWeatherCore::WeatherForecast m_location;
......
......@@ -2,12 +2,12 @@
SPDX-FileCopyrightText: 2020 HanY <hanyoung@protonmail.com>
SPDX-License-Identifier: LGPL-2.1-or-later
*/
#include <QQmlApplicationEngine>
#include "kweather_1x4.h"
#include "kweathersettings.h"
#include "hourlymodel.h"
#include <KWeatherCore/WeatherForecastSource>
#include "kweathersettings.h"
#include <KSharedConfig>
#include <KWeatherCore/WeatherForecastSource>
#include <QQmlApplicationEngine>
KWeather_1x4::KWeather_1x4(QObject *parent, const QVariantList &args)
: Plasma::Applet(parent, args)
, m_hourlyModel(new HourlyModel())
......@@ -17,13 +17,13 @@ KWeather_1x4::KWeather_1x4(QObject *parent, const QVariantList &args)
auto group = config->group("general");
QString locationID = group.readEntry("locationID");
if (!locationID.isEmpty()) {
auto m_config = KWeatherSettings(this).sharedConfig()->group("WeatherLocations");
auto m_group = m_config.group(locationID);
m_location = m_group.readEntry("locationName");
m_latitude = m_group.readEntry("latitude").toDouble();
m_longitude = m_group.readEntry("longitude").toDouble();
m_needLocation = false;
update();
auto m_config = KWeatherSettings(this).sharedConfig()->group("WeatherLocations");
auto m_group = m_config.group(locationID);
m_location = m_group.readEntry("locationName");
m_latitude = m_group.readEntry("latitude").toDouble();
m_longitude = m_group.readEntry("longitude").toDouble();
m_needLocation = false;
update();
}
}
......
......@@ -18,7 +18,7 @@ class KWeather_1x4 : public Plasma::Applet
Q_PROPERTY(QString weatherIcon READ weatherIcon NOTIFY updated)
Q_PROPERTY(qreal humidity READ humidity NOTIFY updated)
Q_PROPERTY(qreal precipitation READ precipitation NOTIFY updated)
Q_PROPERTY(HourlyModel* hourlyModel READ hourlyModel NOTIFY hourlyModelChanged)
Q_PROPERTY(HourlyModel *hourlyModel READ hourlyModel NOTIFY hourlyModelChanged)
public:
KWeather_1x4(QObject *parent, const QVariantList &args);
QString location() const;
......@@ -27,10 +27,12 @@ public:
QString weatherIcon() const;
qreal humidity() const;
qreal precipitation() const;
bool needLocation() const {
bool needLocation() const
{
return m_needLocation;
}
HourlyModel *hourlyModel() const {
HourlyModel *hourlyModel() const
{
return m_hourlyModel;
}
......@@ -41,6 +43,7 @@ signals:
void updated();
void needLocationChanged();
void hourlyModelChanged();
private:
void update();
bool hasForecast() const;
......
......@@ -7,20 +7,20 @@
#include "weatherlocation.h"
#include "global.h"
#include "kweathersettings.h"
#include "locationquerymodel.h"
#include "weatherdaymodel.h"
#include "kweathersettings.h"
#include <QAbstractSeries>
#include <QDateTimeAxis>
#include <QDir>
#include <QTimer>
#include <QFile>
#include <QJsonArray>
#include <QQmlEngine>
#include <QTimeZone>
#include <utility>
#include <QAbstractSeries>
#include <QDateTimeAxis>
#include <QSplineSeries>
#include <QTimeZone>
#include <QTimer>
#include <QValueAxis>
#include <utility>
WeatherLocation::WeatherLocation()
{
......@@ -32,7 +32,12 @@ WeatherLocation::WeatherLocation()
this->m_timer->start(60 - QDateTime::currentDateTime().currentMSecsSinceEpoch() % 60);
}
WeatherLocation::WeatherLocation(QString locationId, QString locationName, QString timeZone, float latitude, float longitude, KWeatherCore::WeatherForecast forecast)
WeatherLocation::WeatherLocation(QString locationId,
QString locationName,
QString timeZone,
float latitude,
float longitude,
KWeatherCore::WeatherForecast forecast)
: m_forecast(forecast)
, m_locationName(std::move(locationName))
, m_locationId(std::move(locationId))
......@@ -58,8 +63,11 @@ WeatherLocation *WeatherLocation::load(const QString &groupName)
{
auto config = KWeatherSettings().sharedConfig()->group(Kweather::WEATHER_LOCATIONS_CFG_GROUP).group(groupName);
if (config.isValid()) {
return new WeatherLocation(groupName, config.readEntry("locationName"), config.readEntry("timezone"), config.readEntry("latitude").toFloat(),
config.readEntry("longitude").toFloat());
return new WeatherLocation(groupName,
config.readEntry("locationName"),
config.readEntry("timezone"),
config.readEntry("latitude").toFloat(),
config.readEntry("longitude").toFloat());
} else {
return nullptr;
}
......@@ -220,7 +228,7 @@ void WeatherLocation::updateSeries()
double minTemp = std::numeric_limits<double>::max(), maxTemp = std::numeric_limits<double>::min();
for (const auto &d : m_forecast.dailyWeatherForecast()) {
const auto dayMinTemp = Kweather::convertTemp(d.minTemp()), dayMaxTemp = Kweather::convertTemp(d.maxTemp());
m_vector.append(QPointF(d.date().startOfDay().toMSecsSinceEpoch(), dayMaxTemp));
minTemp = std::min<double>(dayMinTemp, minTemp);
maxTemp = std::max<double>(dayMaxTemp, maxTemp);
......@@ -246,7 +254,8 @@ void WeatherLocation::initAxes(QObject *axisX, QObject *axisY)
}
}
void WeatherLocation::updateAxes()
{}
{
}
void WeatherLocation::updateCurrentDateTime()
{
m_timer->setInterval(60000);
......
......@@ -48,8 +48,6 @@ class WeatherLocation : public QObject
Q_PROPERTY(double maxTempLimit READ maxTempLimit NOTIFY currentForecastChange)
Q_PROPERTY(double minTempLimit READ minTempLimit NOTIFY currentForecastChange)
public:
WeatherLocation();
explicit WeatherLocation(QString locationId,
......@@ -157,7 +155,6 @@ public:
Q_INVOKABLE void initSeries(QtCharts::QAbstractSeries *series);
Q_INVOKABLE void initAxes(QObject *axisX, QObject *axisY);
// for restore order of locations
void saveOrder(int index);
int index();
......@@ -188,12 +185,10 @@ private:
// chart related fields
QtCharts::QSplineSeries *m_series = nullptr;
QVector<QPointF> m_vector;
double m_maxTempLimit {100};
double m_minTempLimit {0};
QtCharts::QDateTimeAxis *m_axisX {nullptr};
QtCharts::QValueAxis *m_axisY {nullptr};
double m_maxTempLimit{100};
double m_minTempLimit{0};
QtCharts::QDateTimeAxis *m_axisX{nullptr};
QtCharts::QValueAxis *m_axisY{nullptr};
// background related fields
QColor m_backgroundColor;
......
......@@ -32,7 +32,7 @@ void WeatherLocationListModel::load()
m_locations.push_back(location_ptr);
}
auto i {0};
auto i{0};
for (auto loc : m_locations) {
auto index = loc->index();
while (index != i) {
......@@ -55,7 +55,7 @@ void WeatherLocationListModel::load()
void WeatherLocationListModel::saveOrder()
{
auto i {0};
auto i{0};
for (auto loc : m_locations) {
loc->saveOrder(i);
i++;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment