do not replace space to nbsp in some cases (#143)

This commit is contained in:
Evgenii Alekseev 2020-04-18 03:04:32 +03:00
parent 0f19bce80d
commit e525cb4742
12 changed files with 27 additions and 17 deletions

View File

@ -38,7 +38,7 @@ for more details. To avoid manual labor there is automatic cmake target named
* `Q_PROPERTY` macro is allowed and recommended for QObject based classes.
* Qt macros (e.g. `signals`, `slots`, `Q_OBJECT`, etc) are allowed. In other hand
`Q_FOREACH` (`foreach`) is not allowed use `for (auto &foo : bar)` instead.
* Current project standard is **C++11**.
* Current project standard is **C++17**.
* Do not use C-like code:
* C-like style iteration if possible. Use `for (auto &foo : bar)` and
`std::for_each` instead if possible. It is also recommended to use iterators.

View File

@ -39,6 +39,7 @@ Optional dependencies
* hddtemp
* smartmontools
* music player (mpd or MPRIS supported)
* wireless_tools
Make dependencies
-----------------

View File

@ -58,6 +58,13 @@ QStringList AWAbstractPairHelper::values() const
}
QSet<QString> AWAbstractPairHelper::valuesSet() const
{
auto values = m_pairs.values();
return QSet(values.cbegin(), values.cend());
}
void AWAbstractPairHelper::initItems()
{
m_pairs.clear();
@ -131,4 +138,4 @@ bool AWAbstractPairHelper::removeUnusedKeys(const QStringList &_keys) const
settings.sync();
return (settings.status() == QSettings::NoError);
}
}

View File

@ -30,6 +30,7 @@ public:
QStringList keys() const;
QHash<QString, QString> pairs() const;
QStringList values() const;
QSet<QString> valuesSet() const;
// read-write methods
virtual void initItems();
virtual bool writeItems(const QHash<QString, QString> &_configuration) const;

View File

@ -46,13 +46,13 @@ QString AWCustomKeysHelper::source(const QString &_key) const
QStringList AWCustomKeysHelper::sources() const
{
return QSet<QString>::fromList(values()).toList();
return valuesSet().values();
}
QStringList AWCustomKeysHelper::refinedSources() const
{
auto allSources = QSet<QString>::fromList(pairs().values());
auto allSources = valuesSet();
QSet<QString> output;
while (output != allSources) {
@ -62,7 +62,7 @@ QStringList AWCustomKeysHelper::refinedSources() const
allSources = output;
}
return output.toList();
return output.values();
}

View File

@ -83,9 +83,9 @@ QStringList AWKeyCache::getRequiredKeys(const QStringList &_keys, const QStringL
<< _tooltip;
// initial copy
QSet<QString> used = QSet<QString>::fromList(_keys);
used.unite(QSet<QString>::fromList(_bars));
used.unite(QSet<QString>::fromList(_userKeys));
QSet<QString> used(_keys.cbegin(), _keys.cend());
used.unite(QSet(_bars.cbegin(), _bars.cend()));
used.unite(QSet(_userKeys.cbegin(), _userKeys.cend()));
// insert keys from tooltip
for (auto &key : _tooltip.keys()) {
if ((key.endsWith("Tooltip")) && (_tooltip[key].toBool())) {
@ -155,7 +155,7 @@ QStringList AWKeyCache::getRequiredKeys(const QStringList &_keys, const QStringL
if (used.isEmpty())
used << "dummy";
return used.toList();
return used.values();
}

View File

@ -189,7 +189,7 @@ QString AWKeys::valueByKey(const QString &_key) const
QString trueKey = _key.startsWith("bar") ? m_keyOperator->infoByKey(_key) : _key;
return m_aggregator->formatter(m_values[trueKey], trueKey);
return m_aggregator->formatter(m_values[trueKey], trueKey, true);
}
@ -340,7 +340,7 @@ QString AWKeys::parsePattern(QString _pattern) const
// main keys
for (auto &key : m_foundKeys)
_pattern.replace(QString("$%1").arg(key), m_aggregator->formatter(m_values[key], key));
_pattern.replace(QString("$%1").arg(key), m_aggregator->formatter(m_values[key], key, true));
// bars
for (auto &bar : m_foundBars) {

View File

@ -55,7 +55,7 @@ void AWKeysAggregator::initFormatters()
}
QString AWKeysAggregator::formatter(const QVariant &_data, const QString &_key) const
QString AWKeysAggregator::formatter(const QVariant &_data, const QString &_key, bool replaceSpace) const
{
qCDebug(LOG_AW) << "Data" << _data << "for key" << _key;
@ -162,7 +162,8 @@ QString AWKeysAggregator::formatter(const QVariant &_data, const QString &_key)
}
// replace spaces to non-breakable ones
if (!_key.startsWith("custom") && (!_key.startsWith("weather")))
replaceSpace &= (!_key.startsWith("custom") && (!_key.startsWith("weather")));
if (replaceSpace)
output.replace(" ", "&nbsp;");
return output;

View File

@ -69,7 +69,7 @@ public:
~AWKeysAggregator() override;
void initFormatters();
// get methods
QString formatter(const QVariant &_data, const QString &_key) const;
QString formatter(const QVariant &_data, const QString &_key, bool replaceSpace) const;
QStringList keysFromSource(const QString &_source) const;
// set methods
void setAcOffline(const QString &_inactive);

View File

@ -36,7 +36,7 @@ QString AWPatternFunctions::expandLambdas(QString _code, AWKeysAggregator *_aggr
// parsed values
for (auto &lambdaKey : _usedKeys)
_code.replace(QString("$%1").arg(lambdaKey),
_aggregator->formatter(_metadata[lambdaKey], lambdaKey));
_aggregator->formatter(_metadata[lambdaKey], lambdaKey, false));
qCInfo(LOG_AW) << "Expression" << _code;
QJSValue result = engine.evaluate(_code);
if (result.isError()) {

View File

@ -17,7 +17,7 @@ else ()
endif ()
# some flags
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
# verbose output for debug builds

View File

@ -51,7 +51,7 @@ void TestAWTelemetryHandler::test_get()
QStringList output = plugin->get(telemetryGroup);
QVERIFY(!output.isEmpty());
QCOMPARE(QSet<QString>::fromList(output).count(), output.count());
QCOMPARE(QSet<QString>(output.cbegin(), output.cend()).count(), output.count());
QVERIFY(output.contains(telemetryData));
}