diff --git a/sources/awesome-widget/plugin/awabstractpairconfig.cpp b/sources/awesome-widget/plugin/awabstractpairconfig.cpp index 61ef729..8f971f4 100644 --- a/sources/awesome-widget/plugin/awabstractpairconfig.cpp +++ b/sources/awesome-widget/plugin/awabstractpairconfig.cpp @@ -58,6 +58,12 @@ AWAbstractPairConfig::~AWAbstractPairConfig() } +void AWAbstractPairConfig::setHelper(std::unique_ptr _helper) +{ + m_helper = std::move(_helper); +} + + void AWAbstractPairConfig::showDialog() { // update dialog @@ -133,7 +139,7 @@ void AWAbstractPairConfig::execDialog() auto ret = exec(); QHash data; for (auto selector : m_selectors) { - QPair select = selector->current(); + auto select = selector->current(); if (select.first.isEmpty()) continue; data[select.first] = select.second; diff --git a/sources/awesome-widget/plugin/awabstractpairconfig.h b/sources/awesome-widget/plugin/awabstractpairconfig.h index 9a027ac..ee07585 100644 --- a/sources/awesome-widget/plugin/awabstractpairconfig.h +++ b/sources/awesome-widget/plugin/awabstractpairconfig.h @@ -35,12 +35,7 @@ class AWAbstractPairConfig : public QDialog public: explicit AWAbstractPairConfig(QWidget *_parent = nullptr, bool _hasEdit = false, QStringList _keys = {}); ~AWAbstractPairConfig() override; - template void initHelper() - { - - delete m_helper; - m_helper = new T(this); - } + void setHelper(std::unique_ptr _helper); void showDialog(); // properties void setEditable(bool _first, bool _second); @@ -52,7 +47,7 @@ private slots: private: QPushButton *m_editButton = nullptr; Ui::AWAbstractPairConfig *ui = nullptr; - AWAbstractPairHelper *m_helper = nullptr; + std::unique_ptr m_helper; QList m_selectors; // properties QPair m_editable = {false, false}; diff --git a/sources/awesome-widget/plugin/awcustomkeysconfig.cpp b/sources/awesome-widget/plugin/awcustomkeysconfig.cpp index 4871b66..743e6b3 100644 --- a/sources/awesome-widget/plugin/awcustomkeysconfig.cpp +++ b/sources/awesome-widget/plugin/awcustomkeysconfig.cpp @@ -27,5 +27,5 @@ AWCustomKeysConfig::AWCustomKeysConfig(QWidget *_parent, const QStringList &_key qCDebug(LOG_AW) << __PRETTY_FUNCTION__; setEditable(true, false); - initHelper(); + setHelper(std::make_unique()); } diff --git a/sources/awesome-widget/plugin/awdataaggregator.cpp b/sources/awesome-widget/plugin/awdataaggregator.cpp index 74e7d2b..c2f9109 100644 --- a/sources/awesome-widget/plugin/awdataaggregator.cpp +++ b/sources/awesome-widget/plugin/awdataaggregator.cpp @@ -50,7 +50,8 @@ AWDataAggregator::~AWDataAggregator() { qCDebug(LOG_AW) << __PRETTY_FUNCTION__; - delete m_toolTipScene; + m_toolTipView->deleteLater(); + m_toolTipScene->deleteLater(); } diff --git a/sources/awesome-widget/plugin/awformatterconfig.cpp b/sources/awesome-widget/plugin/awformatterconfig.cpp index d4eedda..fa8f3b7 100644 --- a/sources/awesome-widget/plugin/awformatterconfig.cpp +++ b/sources/awesome-widget/plugin/awformatterconfig.cpp @@ -27,5 +27,5 @@ AWFormatterConfig::AWFormatterConfig(QWidget *_parent, const QStringList &_keys) qCDebug(LOG_AW) << __PRETTY_FUNCTION__; setEditable(false, false); - initHelper(); + setHelper(std::make_unique()); } diff --git a/sources/awesome-widget/plugin/awkeys.cpp b/sources/awesome-widget/plugin/awkeys.cpp index a2b47e9..2042966 100644 --- a/sources/awesome-widget/plugin/awkeys.cpp +++ b/sources/awesome-widget/plugin/awkeys.cpp @@ -189,8 +189,10 @@ void AWKeys::dataUpdated(const QHash &_sensors, if (!_sensors.contains(data.sensorProperty)) continue; auto sensor = _sensors[data.sensorProperty]; - std::ignore = QtConcurrent::run(m_threadPool, &AWKeys::setDataBySource, this, data.sensorProperty, sensor, - data.payload); + setDataBySource(data.sensorProperty, sensor, data.payload); + // std::ignore = QtConcurrent::run(m_threadPool, &AWKeys::setDataBySource, this, data.sensorProperty, + // sensor, + // data.payload); } } diff --git a/sources/awesomewidgets/abstractextitem.cpp b/sources/awesomewidgets/abstractextitem.cpp index c2a0184..7c046c8 100644 --- a/sources/awesomewidgets/abstractextitem.cpp +++ b/sources/awesomewidgets/abstractextitem.cpp @@ -36,6 +36,12 @@ AbstractExtItem::AbstractExtItem(QObject *_parent, const QString &_filePath) qCDebug(LOG_LIB) << "Desktop name" << _filePath; m_name = m_filePath; + + m_scheduler = new QCronScheduler(this); + connect(m_scheduler, &QCronScheduler::activated, this, &AbstractExtItem::requestDataUpdate); + + m_socket = new QLocalServer(this); + connect(m_socket, &QLocalServer::newConnection, this, &AbstractExtItem::requestDataUpdate); } @@ -43,11 +49,11 @@ AbstractExtItem::~AbstractExtItem() { qCDebug(LOG_LIB) << __PRETTY_FUNCTION__; - if (m_socket) { - m_socket->close(); - QLocalServer::removeServer(socket()); - m_socket->deleteLater(); - } + m_scheduler->stop(); + m_scheduler->deleteLater(); + + m_socket->close(); + m_socket->deleteLater(); } @@ -203,20 +209,14 @@ void AbstractExtItem::setComment(const QString &_comment) void AbstractExtItem::setCron(const QString &_cron) { qCDebug(LOG_LIB) << "Cron string" << _cron; - // deinit module first - if (m_scheduler) { - disconnect(m_scheduler, &QCronScheduler::activated, this, &AbstractExtItem::requestDataUpdate); - delete m_scheduler; - } m_cron = _cron; - if (cron().isEmpty()) - return; - - // init scheduler - m_scheduler = new QCronScheduler(this); - m_scheduler->parse(cron()); - connect(m_scheduler, &QCronScheduler::activated, this, &AbstractExtItem::requestDataUpdate); + if (m_cron.isEmpty()) { // disable cron timer + m_scheduler->stop(); + } else { + m_scheduler->parse(m_cron); + m_scheduler->start(); + } } @@ -260,34 +260,18 @@ void AbstractExtItem::setNumber(int _number) void AbstractExtItem::setSocket(const QString &_socket) { qCDebug(LOG_LIB) << "Socket" << _socket; - // remove old socket first - deinitSocket(); m_socketFile = _socket; } -void AbstractExtItem::deinitSocket() -{ - if (!m_socket) - return; - - m_socket->close(); - QLocalServer::removeServer(socket()); - disconnect(m_socket, &QLocalServer::newConnection, this, &AbstractExtItem::requestDataUpdate); - delete m_socket; -} - - void AbstractExtItem::initSocket() { - // remove old socket first - deinitSocket(); + // reload local socket + m_socket->close(); - m_socket = new QLocalServer(this); - auto listening = m_socket->listen(socket()); - qCInfo(LOG_LIB) << "Server listening on" << socket() << listening; - connect(m_socket, &QLocalServer::newConnection, this, &AbstractExtItem::requestDataUpdate); + auto listening = m_socket->listen(m_socketFile); + qCInfo(LOG_LIB) << "Server listening on" << m_socketFile << listening; } diff --git a/sources/awesomewidgets/abstractextitem.h b/sources/awesomewidgets/abstractextitem.h index c11ce1d..e4537c0 100644 --- a/sources/awesomewidgets/abstractextitem.h +++ b/sources/awesomewidgets/abstractextitem.h @@ -75,7 +75,6 @@ signals: void requestDataUpdate(); public slots: - virtual void deinitSocket(); virtual void initSocket(); virtual void readConfiguration(); virtual QVariantHash run() = 0; diff --git a/sources/awesomewidgets/abstractquotesprovider.h b/sources/awesomewidgets/abstractquotesprovider.h index 409051f..bf13fa4 100644 --- a/sources/awesomewidgets/abstractquotesprovider.h +++ b/sources/awesomewidgets/abstractquotesprovider.h @@ -17,25 +17,15 @@ #pragma once -#include #include - -#include "abstractextitem.h" +#include -class AbstractQuotesProvider : public QObject +class AbstractQuotesProvider { - Q_OBJECT - public: - explicit AbstractQuotesProvider(QObject *_parent) - : QObject(_parent){}; - ~AbstractQuotesProvider() override = default; + virtual ~AbstractQuotesProvider() = default; virtual void initUrl(const QString &_asset) = 0; - [[nodiscard]] virtual QVariantHash parse(const QByteArray &_source, const QVariantHash &_oldValues) const = 0; - [[nodiscard]] QString tag(const QString &_type) const - { - return dynamic_cast(parent())->tag(_type); - }; + [[nodiscard]] virtual QVariantHash parse(const QByteArray &_source) = 0; [[nodiscard]] virtual QUrl url() const = 0; }; diff --git a/sources/awesomewidgets/abstractweatherprovider.h b/sources/awesomewidgets/abstractweatherprovider.h index 817c711..1e437f1 100644 --- a/sources/awesomewidgets/abstractweatherprovider.h +++ b/sources/awesomewidgets/abstractweatherprovider.h @@ -17,25 +17,15 @@ #pragma once -#include #include - -#include "abstractextitem.h" +#include -class AbstractWeatherProvider : public QObject +class AbstractWeatherProvider { - Q_OBJECT - public: - explicit AbstractWeatherProvider(QObject *_parent) - : QObject(_parent){}; - ~AbstractWeatherProvider() override = default; + virtual ~AbstractWeatherProvider() = default; virtual void initUrl(const QString &_city, const QString &_country, int _ts) = 0; [[nodiscard]] virtual QVariantHash parse(const QVariantMap &_json) const = 0; - [[nodiscard]] QString tag(const QString &_type) const - { - return dynamic_cast(parent())->tag(_type); - }; [[nodiscard]] virtual QUrl url() const = 0; }; diff --git a/sources/awesomewidgets/extquotes.cpp b/sources/awesomewidgets/extquotes.cpp index 8515e88..d482609 100644 --- a/sources/awesomewidgets/extquotes.cpp +++ b/sources/awesomewidgets/extquotes.cpp @@ -186,10 +186,9 @@ void ExtQuotes::quotesReplyReceived(QNetworkReply *_reply) auto text = _reply->readAll(); _reply->deleteLater(); - auto data = m_providerObject->parse(text, m_values); - if (data.isEmpty()) - return; - m_values = data; + auto data = m_providerObject->parse(text); + for (auto [key, value] : data.asKeyValueRange()) + m_values[tag(key)] = value; emit(dataReceived(m_values)); } @@ -205,10 +204,8 @@ void ExtQuotes::sendRequest() void ExtQuotes::initProvider() { - delete m_providerObject; - // in the future release it is possible to change provider here - m_providerObject = new StooqQuotesProvider(this); + m_providerObject = std::make_unique(); return m_providerObject->initUrl(ticker()); } diff --git a/sources/awesomewidgets/extquotes.h b/sources/awesomewidgets/extquotes.h index d6d7b02..d10288f 100644 --- a/sources/awesomewidgets/extquotes.h +++ b/sources/awesomewidgets/extquotes.h @@ -50,7 +50,7 @@ private slots: void sendRequest(); private: - AbstractQuotesProvider *m_providerObject = nullptr; + std::unique_ptr m_providerObject; QNetworkAccessManager *m_manager = nullptr; bool m_isRunning = false; void initProvider(); diff --git a/sources/awesomewidgets/extweather.cpp b/sources/awesomewidgets/extweather.cpp index 454eba3..cfdd853 100644 --- a/sources/awesomewidgets/extweather.cpp +++ b/sources/awesomewidgets/extweather.cpp @@ -354,9 +354,8 @@ void ExtWeather::weatherReplyReceived(QNetworkReply *_reply) } auto data = m_providerObject->parse(jsonDoc.toVariant().toMap()); - if (data.isEmpty()) - return; - m_values = data; + for (auto [key, value] : data.asKeyValueRange()) + m_values[tag(key)] = value; m_values[tag("weather")] = weatherFromInt(m_values[tag("weatherId")].toInt()); emit(dataReceived(m_values)); @@ -365,10 +364,8 @@ void ExtWeather::weatherReplyReceived(QNetworkReply *_reply) void ExtWeather::initProvider() { - delete m_providerObject; - // in the future release it is possible to change provider here - m_providerObject = new OWMWeatherProvider(this); + m_providerObject = std::make_unique(); return m_providerObject->initUrl(city(), country(), ts()); } diff --git a/sources/awesomewidgets/extweather.h b/sources/awesomewidgets/extweather.h index 40574d4..7231853 100644 --- a/sources/awesomewidgets/extweather.h +++ b/sources/awesomewidgets/extweather.h @@ -74,7 +74,7 @@ private slots: void weatherReplyReceived(QNetworkReply *_reply); private: - AbstractWeatherProvider *m_providerObject = nullptr; + std::unique_ptr m_providerObject; QNetworkAccessManager *m_manager = nullptr; bool m_isRunning = false; void initProvider(); diff --git a/sources/awesomewidgets/owmweatherprovider.cpp b/sources/awesomewidgets/owmweatherprovider.cpp index 9b54a84..4556c72 100644 --- a/sources/awesomewidgets/owmweatherprovider.cpp +++ b/sources/awesomewidgets/owmweatherprovider.cpp @@ -23,14 +23,8 @@ #include "awdebug.h" -OWMWeatherProvider::OWMWeatherProvider(QObject *_parent) - : AbstractWeatherProvider(_parent) -{ - qCDebug(LOG_LIB) << __PRETTY_FUNCTION__; -} - - -OWMWeatherProvider::~OWMWeatherProvider() +OWMWeatherProvider::OWMWeatherProvider() + : AbstractWeatherProvider() { qCDebug(LOG_LIB) << __PRETTY_FUNCTION__; } @@ -66,7 +60,7 @@ QVariantHash OWMWeatherProvider::parse(const QVariantMap &_json) const if (m_ts == 0) { return parseSingleJson(_json); } else { - QVariantList list = _json["list"].toList(); + auto list = _json["list"].toList(); return parseSingleJson(list.count() <= m_ts ? list.at(m_ts - 1).toMap() : list.last().toMap()); } } @@ -78,7 +72,7 @@ QUrl OWMWeatherProvider::url() const } -QVariantHash OWMWeatherProvider::parseSingleJson(const QVariantMap &_json) const +QVariantHash OWMWeatherProvider::parseSingleJson(const QVariantMap &_json) { qCDebug(LOG_LIB) << "Single json data" << _json; @@ -88,19 +82,19 @@ QVariantHash OWMWeatherProvider::parseSingleJson(const QVariantMap &_json) const auto weather = _json["weather"].toList(); if (!weather.isEmpty()) { int id = weather.first().toMap()["id"].toInt(); - output[tag("weatherId")] = id; + output["weatherId"] = id; } // main data auto mainWeather = _json["main"].toMap(); if (!weather.isEmpty()) { - output[tag("humidity")] = mainWeather["humidity"].toDouble(); - output[tag("pressure")] = mainWeather["pressure"].toDouble(); - output[tag("temperature")] = mainWeather["temp"].toDouble(); + output["humidity"] = mainWeather["humidity"].toDouble(); + output["pressure"] = mainWeather["pressure"].toDouble(); + output["temperature"] = mainWeather["temp"].toDouble(); } // timestamp - output[tag("timestamp")] = QDateTime::fromSecsSinceEpoch(_json["dt"].toUInt()).toUTC(); + output["timestamp"] = QDateTime::fromSecsSinceEpoch(_json["dt"].toUInt()).toUTC(); return output; } diff --git a/sources/awesomewidgets/owmweatherprovider.h b/sources/awesomewidgets/owmweatherprovider.h index af49e63..10e577b 100644 --- a/sources/awesomewidgets/owmweatherprovider.h +++ b/sources/awesomewidgets/owmweatherprovider.h @@ -22,22 +22,20 @@ class OWMWeatherProvider : public AbstractWeatherProvider { - Q_OBJECT - public: // we are using own server to pass requests to OpenWeatherMap because it // requires specific APPID which belongs to developer not user const char *OWM_WEATHER_URL = "https://arcanis.me/weather"; const char *OWM_FORECAST_URL = "https://arcanis.me/forecast"; - explicit OWMWeatherProvider(QObject *_parent); - ~OWMWeatherProvider() override; + explicit OWMWeatherProvider(); + ~OWMWeatherProvider() override = default; void initUrl(const QString &_city, const QString &_country, int) override; [[nodiscard]] QVariantHash parse(const QVariantMap &_json) const override; [[nodiscard]] QUrl url() const override; private: - [[nodiscard]] QVariantHash parseSingleJson(const QVariantMap &_json) const; + [[nodiscard]] static QVariantHash parseSingleJson(const QVariantMap &_json); int m_ts = 0; QUrl m_url; }; diff --git a/sources/awesomewidgets/qcronscheduler.cpp b/sources/awesomewidgets/qcronscheduler.cpp index f8f6215..400d366 100644 --- a/sources/awesomewidgets/qcronscheduler.cpp +++ b/sources/awesomewidgets/qcronscheduler.cpp @@ -34,8 +34,6 @@ QCronScheduler::QCronScheduler(QObject *_parent) m_timer->setInterval(60 * 1000); connect(m_timer, &QTimer::timeout, this, &QCronScheduler::expired); - - m_timer->start(); } @@ -44,6 +42,7 @@ QCronScheduler::~QCronScheduler() qCDebug(LOG_LIB) << __PRETTY_FUNCTION__; m_timer->stop(); + m_timer->deleteLater(); } @@ -63,6 +62,22 @@ void QCronScheduler::parse(const QString &_timer) } +void QCronScheduler::start() +{ + qCDebug(LOG_LIB) << "Start cron timer"; + + m_timer->start(); +} + + +void QCronScheduler::stop() +{ + qCDebug(LOG_LIB) << "Stop cron timer"; + + m_timer->stop(); +} + + void QCronScheduler::expired() { auto now = QDateTime::currentDateTime(); diff --git a/sources/awesomewidgets/qcronscheduler.h b/sources/awesomewidgets/qcronscheduler.h index 72a1599..a740087 100644 --- a/sources/awesomewidgets/qcronscheduler.h +++ b/sources/awesomewidgets/qcronscheduler.h @@ -39,12 +39,14 @@ public: int maxValue = -1; int div = 1; void fromRange(const QString &_range, int _min, int _max); - QList toList() const; + [[nodiscard]] QList toList() const; }; explicit QCronScheduler(QObject *_parent = nullptr); ~QCronScheduler() override; void parse(const QString &_timer); + void start(); + void stop(); signals: void activated(); diff --git a/sources/awesomewidgets/stooqquotesprovider.cpp b/sources/awesomewidgets/stooqquotesprovider.cpp index fc66b1e..a1156c1 100644 --- a/sources/awesomewidgets/stooqquotesprovider.cpp +++ b/sources/awesomewidgets/stooqquotesprovider.cpp @@ -22,14 +22,8 @@ #include "awdebug.h" -StooqQuotesProvider::StooqQuotesProvider(QObject *_parent) - : AbstractQuotesProvider(_parent) -{ - qCDebug(LOG_LIB) << __PRETTY_FUNCTION__; -} - - -StooqQuotesProvider::~StooqQuotesProvider() +StooqQuotesProvider::StooqQuotesProvider() + : AbstractQuotesProvider() { qCDebug(LOG_LIB) << __PRETTY_FUNCTION__; } @@ -49,7 +43,7 @@ void StooqQuotesProvider::initUrl(const QString &_asset) } -QVariantHash StooqQuotesProvider::parse(const QByteArray &_source, const QVariantHash &_oldValues) const +QVariantHash StooqQuotesProvider::parse(const QByteArray &_source) { qCDebug(LOG_LIB) << "Parse csv" << _source; @@ -61,20 +55,18 @@ QVariantHash StooqQuotesProvider::parse(const QByteArray &_source, const QVarian return values; } - // extract old data - auto oldPrice = _oldValues[tag("price")].toDouble(); - auto oldVolume = _oldValues[tag("volume")].toInt(); - // last trade auto price = sourceValues.at(0).toDouble(); - values[tag("pricechg")] = oldPrice == 0.0 ? 0.0 : price - oldPrice; - values[tag("percpricechg")] = 100.0 * values[tag("pricechg")].toDouble() / oldPrice; - values[tag("price")] = price; + values["pricechg"] = m_price == 0.0 ? 0.0 : price - m_price; + values["percpricechg"] = 100.0 * values["pricechg"].toDouble() / m_price; + values["price"] = price; + m_price = price; // volume auto volume = sourceValues.at(1).toInt(); - values[tag("volumechg")] = oldVolume == 0 ? 0 : volume - oldVolume; - values[tag("percvolumechg")] = 100.0 * values[tag("volumechg")].toDouble() / oldVolume; - values[tag("volume")] = volume; + values["volumechg"] = m_volume == 0 ? 0 : volume - m_volume; + values["percvolumechg"] = 100.0 * values["volumechg"].toDouble() / m_volume; + values["volume"] = volume; + m_volume = volume; return values; } diff --git a/sources/awesomewidgets/stooqquotesprovider.h b/sources/awesomewidgets/stooqquotesprovider.h index 19c1b81..fa3f034 100644 --- a/sources/awesomewidgets/stooqquotesprovider.h +++ b/sources/awesomewidgets/stooqquotesprovider.h @@ -22,17 +22,17 @@ class StooqQuotesProvider : public AbstractQuotesProvider { - Q_OBJECT - public: const char *STOOQ_QUOTES_URL = "https://stooq.com/q/l/"; - explicit StooqQuotesProvider(QObject *_parent); - ~StooqQuotesProvider() override; + explicit StooqQuotesProvider(); + ~StooqQuotesProvider() override = default; void initUrl(const QString &_asset) override; - [[nodiscard]] QVariantHash parse(const QByteArray &_source, const QVariantHash &_oldValues) const override; + [[nodiscard]] QVariantHash parse(const QByteArray &_source) override; [[nodiscard]] QUrl url() const override; private: + double m_price = 0.0; QUrl m_url; + int m_volume = 0; }; diff --git a/sources/awesomewidgets/yahooquotesprovider.cpp b/sources/awesomewidgets/yahooquotesprovider.cpp index 16b1aaf..35a4fbe 100644 --- a/sources/awesomewidgets/yahooquotesprovider.cpp +++ b/sources/awesomewidgets/yahooquotesprovider.cpp @@ -23,14 +23,8 @@ #include "awdebug.h" -YahooQuotesProvider::YahooQuotesProvider(QObject *_parent) - : AbstractQuotesProvider(_parent) -{ - qCDebug(LOG_LIB) << __PRETTY_FUNCTION__; -} - - -YahooQuotesProvider::~YahooQuotesProvider() +YahooQuotesProvider::YahooQuotesProvider() + : AbstractQuotesProvider() { qCDebug(LOG_LIB) << __PRETTY_FUNCTION__; } @@ -50,7 +44,7 @@ void YahooQuotesProvider::initUrl(const QString &_asset) } -QVariantHash YahooQuotesProvider::parse(const QByteArray &_source, const QVariantHash &_oldValues) const +QVariantHash YahooQuotesProvider::parse(const QByteArray &_source) { qCDebug(LOG_LIB) << "Parse json" << _source; @@ -65,18 +59,16 @@ QVariantHash YahooQuotesProvider::parse(const QByteArray &_source, const QVarian auto jsonQuotes = jsonDoc.toVariant().toMap()["query"].toMap(); jsonQuotes = jsonQuotes["results"].toMap()["quote"].toMap(); - // extract old data - auto oldPrice = _oldValues[tag("price")].toDouble(); - // last trade - auto value = jsonQuotes["LastTradePriceOnly"].toString().toDouble(); - values[tag("pricechg")] = oldPrice == 0.0 ? 0.0 : value - oldPrice; - values[tag("percpricechg")] = 100.0 * values[tag("pricechg")].toDouble() / value; - values[tag("price")] = value; + auto price = jsonQuotes["LastTradePriceOnly"].toString().toDouble(); + values["pricechg"] = m_price == 0.0 ? 0.0 : price - m_price; + values["percpricechg"] = 100.0 * values["pricechg"].toDouble() / price; + values["price"] = price; + m_price = price; // volume - values[tag("volume")] = 0; - values[tag("volumechg")] = 0; - values[tag("percvolumechg")] = 0.0; + values["volume"] = 0; + values["volumechg"] = 0; + values["percvolumechg"] = 0.0; return values; } diff --git a/sources/awesomewidgets/yahooquotesprovider.h b/sources/awesomewidgets/yahooquotesprovider.h index 32bf518..ddef0de 100644 --- a/sources/awesomewidgets/yahooquotesprovider.h +++ b/sources/awesomewidgets/yahooquotesprovider.h @@ -22,18 +22,17 @@ class YahooQuotesProvider : public AbstractQuotesProvider { - Q_OBJECT - public: const char *YAHOO_QUOTES_URL = "https://query.yahooapis.com/v1/public/yql"; const char *YAHOO_QUOTES_QUERY = "select * from yahoo.finance.quotes where symbol='%1'"; - explicit YahooQuotesProvider(QObject *_parent); - ~YahooQuotesProvider() override; + explicit YahooQuotesProvider(); + ~YahooQuotesProvider() override = default; void initUrl(const QString &_asset) override; - [[nodiscard]] QVariantHash parse(const QByteArray &_source, const QVariantHash &_oldValues) const override; + [[nodiscard]] QVariantHash parse(const QByteArray &_source) override; [[nodiscard]] QUrl url() const override; private: + double m_price = 0.0; QUrl m_url; }; diff --git a/sources/awesomewidgets/yahooweatherprovider.cpp b/sources/awesomewidgets/yahooweatherprovider.cpp index 3e81a96..1e54cc7 100644 --- a/sources/awesomewidgets/yahooweatherprovider.cpp +++ b/sources/awesomewidgets/yahooweatherprovider.cpp @@ -22,14 +22,8 @@ #include "awdebug.h" -YahooWeatherProvider::YahooWeatherProvider(QObject *_parent) - : AbstractWeatherProvider(_parent) -{ - qCDebug(LOG_LIB) << __PRETTY_FUNCTION__; -} - - -YahooWeatherProvider::~YahooWeatherProvider() +YahooWeatherProvider::YahooWeatherProvider() + : AbstractWeatherProvider() { qCDebug(LOG_LIB) << __PRETTY_FUNCTION__; } @@ -74,7 +68,7 @@ QUrl YahooWeatherProvider::url() const } -QVariantHash YahooWeatherProvider::parseCurrent(const QVariantMap &_json, const QVariantMap &_atmosphere) const +QVariantHash YahooWeatherProvider::parseCurrent(const QVariantMap &_json, const QVariantMap &_atmosphere) { qCDebug(LOG_LIB) << "Parse current weather from" << _json; @@ -82,12 +76,12 @@ QVariantHash YahooWeatherProvider::parseCurrent(const QVariantMap &_json, const QVariantHash values; auto id = _json["condition"].toMap()["code"].toInt(); - values[tag("weatherId")] = id; - values[tag("temperature")] = condition["temp"].toInt(); - values[tag("timestamp")] = condition["date"].toString(); - values[tag("humidity")] = _atmosphere["humidity"].toInt(); + values["weatherId"] = id; + values["temperature"] = condition["temp"].toInt(); + values["timestamp"] = condition["date"].toString(); + values["humidity"] = _atmosphere["humidity"].toInt(); // HACK temporary fix of invalid values on Yahoo! side - values[tag("pressure")] = static_cast(_atmosphere["pressure"].toDouble() / 33.863753); + values["pressure"] = static_cast(_atmosphere["pressure"].toDouble() / 33.863753); return values; } @@ -101,13 +95,13 @@ QVariantHash YahooWeatherProvider::parseForecast(const QVariantMap &_json) const auto weatherList = _json["forecast"].toList(); auto weatherMap = weatherList.count() < m_ts ? weatherList.last().toMap() : weatherList.at(m_ts).toMap(); auto id = weatherMap["code"].toInt(); - values[tag("weatherId")] = id; - values[tag("timestamp")] = weatherMap["date"].toString(); + values["weatherId"] = id; + values["timestamp"] = weatherMap["date"].toString(); // yahoo provides high and low temperatures. Lets calculate average one - values[tag("temperature")] = (weatherMap["high"].toDouble() + weatherMap["low"].toDouble()) / 2.0; + values["temperature"] = (weatherMap["high"].toDouble() + weatherMap["low"].toDouble()) / 2.0; // ... and no forecast data for humidity and pressure - values[tag("humidity")] = 0; - values[tag("pressure")] = 0.0; + values["humidity"] = 0; + values["pressure"] = 0.0; return values; } diff --git a/sources/awesomewidgets/yahooweatherprovider.h b/sources/awesomewidgets/yahooweatherprovider.h index 0da4330..9849544 100644 --- a/sources/awesomewidgets/yahooweatherprovider.h +++ b/sources/awesomewidgets/yahooweatherprovider.h @@ -22,22 +22,20 @@ class YahooWeatherProvider : public AbstractWeatherProvider { - Q_OBJECT - public: const char *YAHOO_WEATHER_URL = "https://query.yahooapis.com/v1/public/yql"; const char *YAHOO_WEATHER_QUERY = "select * from weather.forecast where " "u='c' and woeid in (select woeid from " "geo.places(1) where text='%1, %2')"; - explicit YahooWeatherProvider(QObject *_parent); - ~YahooWeatherProvider() override; + explicit YahooWeatherProvider(); + ~YahooWeatherProvider() override = default; void initUrl(const QString &_city, const QString &_country, int) override; [[nodiscard]] QVariantHash parse(const QVariantMap &_json) const override; [[nodiscard]] QUrl url() const override; private: - [[nodiscard]] QVariantHash parseCurrent(const QVariantMap &_json, const QVariantMap &_atmosphere) const; + [[nodiscard]] static QVariantHash parseCurrent(const QVariantMap &_json, const QVariantMap &_atmosphere); [[nodiscard]] QVariantHash parseForecast(const QVariantMap &_json) const; int m_ts = 0; QUrl m_url; diff --git a/sources/desktop-panel/plugin/dpadds.cpp b/sources/desktop-panel/plugin/dpadds.cpp index 772648e..9ca3948 100644 --- a/sources/desktop-panel/plugin/dpadds.cpp +++ b/sources/desktop-panel/plugin/dpadds.cpp @@ -136,7 +136,7 @@ QString DPAdds::toolTipImage(const int _desktop) const toolTipScene->addLine(width + 2.0 * margin, height + 2.0 * margin, width + 2.0 * margin, 0); toolTipScene->addLine(width + 2.0 * margin, 0, 0, 0); - // with wayland countours only are supported + // with wayland contours only are supported auto pen = QPen(); pen.setWidthF(2.0 * width / 400.0); pen.setColor(QColor(m_tooltipColor)); @@ -159,8 +159,8 @@ QString DPAdds::toolTipImage(const int _desktop) const QBuffer buffer(&byteArray); image.save(&buffer, "PNG"); - delete toolTipView; - delete toolTipScene; + toolTipView->deleteLater(); + toolTipScene->deleteLater(); return QString("").arg(QString(byteArray.toBase64())); }