add formatters reinit (fix #102)

This commit is contained in:
Evgenii Alekseev 2016-07-26 15:11:52 +03:00
parent 064cd7e44f
commit 052d8a034c
3 changed files with 15 additions and 5 deletions

View File

@ -105,10 +105,10 @@ void AWKeys::initKeys(const QString currentPattern, const int interval,
m_threadPool->setMaxThreadCount(limit == 0 ? QThread::idealThreadCount() m_threadPool->setMaxThreadCount(limit == 0 ? QThread::idealThreadCount()
: limit); : limit);
// child objects // child objects
aggregator->initFormatters();
keyOperator->setPattern(currentPattern); keyOperator->setPattern(currentPattern);
keyOperator->updateCache(); keyOperator->updateCache();
dataEngineAggregator->clear(); dataEngineAggregator->clear();
dataEngineAggregator->initDataEngines(interval); dataEngineAggregator->initDataEngines(interval);
// timer // timer

View File

@ -48,8 +48,6 @@ AWKeysAggregator::AWKeysAggregator(QObject *parent)
m_formatter[QString("swap")] = FormatterType::Float; m_formatter[QString("swap")] = FormatterType::Float;
m_formatter[QString("swaptotmb")] = FormatterType::MemMBFormat; m_formatter[QString("swaptotmb")] = FormatterType::MemMBFormat;
m_formatter[QString("swaptotgb")] = FormatterType::MemGBFormat; m_formatter[QString("swaptotgb")] = FormatterType::MemGBFormat;
m_customFormatters = new AWFormatterHelper(nullptr);
} }
@ -61,6 +59,14 @@ AWKeysAggregator::~AWKeysAggregator()
} }
void AWKeysAggregator::initFormatters()
{
if (m_customFormatters)
delete m_customFormatters;
m_customFormatters = new AWFormatterHelper(nullptr);
}
QString AWKeysAggregator::formatter(const QVariant &data, QString AWKeysAggregator::formatter(const QVariant &data,
const QString &key) const const QString &key) const
{ {
@ -170,6 +176,7 @@ QString AWKeysAggregator::formatter(const QVariant &data,
output = data.toString(); output = data.toString();
break; break;
case FormatterType::Custom: case FormatterType::Custom:
if (m_customFormatters)
output = m_customFormatters->convert(data, key); output = m_customFormatters->convert(data, key);
break; break;
} }
@ -574,7 +581,9 @@ QStringList AWKeysAggregator::registerSource(const QString &source,
QStringList foundKeys = keysFromSource(source); QStringList foundKeys = keysFromSource(source);
// rewrite formatters for custom ones // rewrite formatters for custom ones
QStringList customFormattersKeys = m_customFormatters->definedFormatters(); QStringList customFormattersKeys;
if (m_customFormatters)
customFormattersKeys = m_customFormatters->definedFormatters();
qCInfo(LOG_AW) << "Looking for fprmatters" << foundKeys << "in" qCInfo(LOG_AW) << "Looking for fprmatters" << foundKeys << "in"
<< customFormattersKeys; << customFormattersKeys;
for (auto key : foundKeys) { for (auto key : foundKeys) {

View File

@ -69,6 +69,7 @@ class AWKeysAggregator : public QObject
public: public:
explicit AWKeysAggregator(QObject *parent = nullptr); explicit AWKeysAggregator(QObject *parent = nullptr);
virtual ~AWKeysAggregator(); virtual ~AWKeysAggregator();
void initFormatters();
// get methods // get methods
QString formatter(const QVariant &data, const QString &key) const; QString formatter(const QVariant &data, const QString &key) const;
QStringList keysFromSource(const QString &source) const; QStringList keysFromSource(const QString &source) const;