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()
: limit);
// child objects
aggregator->initFormatters();
keyOperator->setPattern(currentPattern);
keyOperator->updateCache();
dataEngineAggregator->clear();
dataEngineAggregator->initDataEngines(interval);
// timer

View File

@ -48,8 +48,6 @@ AWKeysAggregator::AWKeysAggregator(QObject *parent)
m_formatter[QString("swap")] = FormatterType::Float;
m_formatter[QString("swaptotmb")] = FormatterType::MemMBFormat;
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,
const QString &key) const
{
@ -170,7 +176,8 @@ QString AWKeysAggregator::formatter(const QVariant &data,
output = data.toString();
break;
case FormatterType::Custom:
output = m_customFormatters->convert(data, key);
if (m_customFormatters)
output = m_customFormatters->convert(data, key);
break;
}
@ -574,7 +581,9 @@ QStringList AWKeysAggregator::registerSource(const QString &source,
QStringList foundKeys = keysFromSource(source);
// 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"
<< customFormattersKeys;
for (auto key : foundKeys) {

View File

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