mirror of
https://github.com/arcan1s/awesome-widgets.git
synced 2025-04-24 23:47:20 +00:00
* Initial syntax is the following: * $template{{ some JS code here }} - simple template based on JS code inside. It works the same as lambda functions, but calculates only once. * aw_count(regex) - keys count found for given regex * aw_keys(regex, [separator]) - keys found for given regex and joined by using given separator * aw_names(regex, [separator]) - key names found for given regex and joined by using given separator (the same as previous but w\o $) The template and function syntax may be changed before release. * replace `foreach` to `for (auto foo : bar)` and update CONTRIBUTING.md accordingly
169 lines
6.5 KiB
C++
169 lines
6.5 KiB
C++
/***************************************************************************
|
|
* This file is part of awesome-widgets *
|
|
* *
|
|
* awesome-widgets is free software: you can redistribute it and/or *
|
|
* modify it under the terms of the GNU General Public License as *
|
|
* published by the Free Software Foundation, either version 3 of the *
|
|
* License, or (at your option) any later version. *
|
|
* *
|
|
* awesome-widgets is distributed in the hope that it will be useful, *
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
|
* GNU General Public License for more details. *
|
|
* *
|
|
* You should have received a copy of the GNU General Public License *
|
|
* along with awesome-widgets. If not, see http://www.gnu.org/licenses/ *
|
|
***************************************************************************/
|
|
|
|
|
|
#include "quotessource.h"
|
|
|
|
#include "awdebug.h"
|
|
#include "extquotes.h"
|
|
|
|
|
|
QuotesSource::QuotesSource(QObject *parent, const QStringList args)
|
|
: AbstractExtSysMonSource(parent, args)
|
|
{
|
|
Q_ASSERT(args.count() == 0);
|
|
qCDebug(LOG_ESM) << __PRETTY_FUNCTION__;
|
|
|
|
extQuotes = new ExtItemAggregator<ExtQuotes>(nullptr, QString("quotes"));
|
|
m_sources = getSources();
|
|
}
|
|
|
|
|
|
QuotesSource::~QuotesSource()
|
|
{
|
|
qCDebug(LOG_ESM) << __PRETTY_FUNCTION__;
|
|
|
|
delete extQuotes;
|
|
}
|
|
|
|
|
|
QVariant QuotesSource::data(QString source)
|
|
{
|
|
qCDebug(LOG_ESM) << "Source" << source;
|
|
|
|
if (source.startsWith(QString("quotes/percpricechg"))) {
|
|
QVariantHash data = extQuotes->itemByTagNumber(index(source))->run();
|
|
for (auto key : data.keys())
|
|
values[key] = data[key];
|
|
}
|
|
QString key = QString(source).remove(QString("quotes/"));
|
|
return values[key];
|
|
}
|
|
|
|
|
|
QVariantMap QuotesSource::initialData(QString source) const
|
|
{
|
|
qCDebug(LOG_ESM) << "Source" << source;
|
|
|
|
int ind = index(source);
|
|
QVariantMap data;
|
|
if (source.startsWith(QString("quotes/askchg"))) {
|
|
data[QString("min")] = 0.0;
|
|
data[QString("max")] = 0.0;
|
|
data[QString("name")]
|
|
= QString("Absolute ask changes for '%1'")
|
|
.arg(extQuotes->itemByTagNumber(ind)->uniq());
|
|
data[QString("type")] = QString("double");
|
|
data[QString("units")] = QString("");
|
|
} else if (source.startsWith(QString("quotes/ask"))) {
|
|
data[QString("min")] = 0.0;
|
|
data[QString("max")] = 0.0;
|
|
data[QString("name")]
|
|
= QString("Ask for '%1'")
|
|
.arg(extQuotes->itemByTagNumber(ind)->uniq());
|
|
data[QString("type")] = QString("double");
|
|
data[QString("units")] = QString("");
|
|
} else if (source.startsWith(QString("quotes/percaskchg"))) {
|
|
data[QString("min")] = -100.0;
|
|
data[QString("max")] = 100.0;
|
|
data[QString("name")]
|
|
= QString("Ask changes for '%1'")
|
|
.arg(extQuotes->itemByTagNumber(ind)->uniq());
|
|
data[QString("type")] = QString("double");
|
|
data[QString("units")] = QString("");
|
|
} else if (source.startsWith(QString("quotes/bidchg"))) {
|
|
data[QString("min")] = 0.0;
|
|
data[QString("max")] = 0.0;
|
|
data[QString("name")]
|
|
= QString("Absolute bid changes for '%1'")
|
|
.arg(extQuotes->itemByTagNumber(ind)->uniq());
|
|
data[QString("type")] = QString("double");
|
|
data[QString("units")] = QString("");
|
|
} else if (source.startsWith(QString("quotes/bid"))) {
|
|
data[QString("min")] = 0.0;
|
|
data[QString("max")] = 0.0;
|
|
data[QString("name")]
|
|
= QString("Bid for '%1'")
|
|
.arg(extQuotes->itemByTagNumber(ind)->uniq());
|
|
data[QString("type")] = QString("double");
|
|
data[QString("units")] = QString("");
|
|
} else if (source.startsWith(QString("quotes/percbidchg"))) {
|
|
data[QString("min")] = -100.0;
|
|
data[QString("max")] = 100.0;
|
|
data[QString("name")]
|
|
= QString("Bid changes for '%1'")
|
|
.arg(extQuotes->itemByTagNumber(ind)->uniq());
|
|
data[QString("type")] = QString("double");
|
|
data[QString("units")] = QString("");
|
|
} else if (source.startsWith(QString("quotes/pricechg"))) {
|
|
data[QString("min")] = 0.0;
|
|
data[QString("max")] = 0.0;
|
|
data[QString("name")]
|
|
= QString("Absolute prie changes for '%1'")
|
|
.arg(extQuotes->itemByTagNumber(ind)->uniq());
|
|
data[QString("type")] = QString("double");
|
|
data[QString("units")] = QString("");
|
|
} else if (source.startsWith(QString("quotes/price"))) {
|
|
data[QString("min")] = 0.0;
|
|
data[QString("max")] = 0.0;
|
|
data[QString("name")]
|
|
= QString("Price for '%1'")
|
|
.arg(extQuotes->itemByTagNumber(ind)->uniq());
|
|
data[QString("type")] = QString("double");
|
|
data[QString("units")] = QString("");
|
|
} else if (source.startsWith(QString("quotes/percpricechg"))) {
|
|
data[QString("min")] = -100.0;
|
|
data[QString("max")] = 100.0;
|
|
data[QString("name")]
|
|
= QString("Price changes for '%1'")
|
|
.arg(extQuotes->itemByTagNumber(ind)->uniq());
|
|
data[QString("type")] = QString("double");
|
|
data[QString("units")] = QString("");
|
|
}
|
|
|
|
return data;
|
|
}
|
|
|
|
|
|
QStringList QuotesSource::sources() const
|
|
{
|
|
return m_sources;
|
|
}
|
|
|
|
|
|
QStringList QuotesSource::getSources()
|
|
{
|
|
QStringList sources;
|
|
for (auto item : extQuotes->activeItems()) {
|
|
sources.append(QString("quotes/%1").arg(item->tag(QString("ask"))));
|
|
sources.append(QString("quotes/%1").arg(item->tag(QString("askchg"))));
|
|
sources.append(
|
|
QString("quotes/%1").arg(item->tag(QString("percaskchg"))));
|
|
sources.append(QString("quotes/%1").arg(item->tag(QString("bid"))));
|
|
sources.append(QString("quotes/%1").arg(item->tag(QString("bidchg"))));
|
|
sources.append(
|
|
QString("quotes/%1").arg(item->tag(QString("percbidchg"))));
|
|
sources.append(QString("quotes/%1").arg(item->tag(QString("price"))));
|
|
sources.append(
|
|
QString("quotes/%1").arg(item->tag(QString("pricechg"))));
|
|
sources.append(
|
|
QString("quotes/%1").arg(item->tag(QString("percpricechg"))));
|
|
}
|
|
|
|
return sources;
|
|
}
|