diff options
author | José Fonseca <jose.r.fonseca@gmail.com> | 2011-12-11 10:33:55 +0000 |
---|---|---|
committer | José Fonseca <jose.r.fonseca@gmail.com> | 2011-12-11 10:33:55 +0000 |
commit | eb64451efcd8100d02ec89ff2ae6ea2c78c7645b (patch) | |
tree | 1c1a5917ec239ee7e433fb42d0f54b95982dcc17 /gui | |
parent | 00ea41c2384c7b9cc82dd3c68a474d7f82083f5a (diff) |
Trace enum signatures as a whole.
Diffstat (limited to 'gui')
-rw-r--r-- | gui/apitracecall.cpp | 39 | ||||
-rw-r--r-- | gui/apitracecall.h | 17 |
2 files changed, 37 insertions, 19 deletions
diff --git a/gui/apitracecall.cpp b/gui/apitracecall.cpp index bc88c3b4..57d2d86e 100644 --- a/gui/apitracecall.cpp +++ b/gui/apitracecall.cpp @@ -192,15 +192,13 @@ void VariantVisitor::visit(trace::Enum *e) sig = m_loader->enumSignature(e->sig->id); } if (!sig) { - sig = new ApiTraceEnumSignature( - QString::fromStdString(e->sig->name), - QVariant(e->sig->value)); + sig = new ApiTraceEnumSignature(e->sig); if (m_loader) { m_loader->addEnumSignature(e->sig->id, sig); } } - m_variant = QVariant::fromValue(ApiEnum(sig)); + m_variant = QVariant::fromValue(ApiEnum(sig, e->value)); } void VariantVisitor::visit(trace::Bitmask *bitmask) @@ -229,16 +227,39 @@ void VariantVisitor::visit(trace::Pointer *ptr) m_variant = QVariant::fromValue(ApiPointer(ptr->value)); } +ApiTraceEnumSignature::ApiTraceEnumSignature(const trace::EnumSig *sig) +{ + for (const trace::EnumValue *it = sig->values; + it != sig->values + sig->num_values; ++it) { + QPair<QString, signed long long> pair; + + pair.first = QString::fromStdString(it->name); + pair.second = it->value; + + m_names.append(pair); + } +} + +QString ApiTraceEnumSignature::name(signed long long value) const +{ + for (ValueList::const_iterator it = m_names.begin(); + it != m_names.end(); ++it) { + if (value == it->second) { + return it->first; + } + } + return QString::fromLatin1("%1").arg(value); +} -ApiEnum::ApiEnum(ApiTraceEnumSignature *sig) - : m_sig(sig) +ApiEnum::ApiEnum(ApiTraceEnumSignature *sig, signed long long value) + : m_sig(sig), m_value(value) { } QString ApiEnum::toString() const { if (m_sig) { - return m_sig->name(); + return m_sig->name(m_value); } Q_ASSERT(!"should never happen"); return QString(); @@ -247,7 +268,7 @@ QString ApiEnum::toString() const QVariant ApiEnum::value() const { if (m_sig) { - return m_sig->value(); + return QVariant::fromValue(m_value); } Q_ASSERT(!"should never happen"); return QVariant(); @@ -256,7 +277,7 @@ QVariant ApiEnum::value() const QString ApiEnum::name() const { if (m_sig) { - return m_sig->name(); + return m_sig->name(m_value); } Q_ASSERT(!"should never happen"); return QString(); diff --git a/gui/apitracecall.h b/gui/apitracecall.h index 784834b1..3a9faafd 100644 --- a/gui/apitracecall.h +++ b/gui/apitracecall.h @@ -54,23 +54,19 @@ struct ApiTraceError class ApiTraceEnumSignature { public: - ApiTraceEnumSignature(const QString &name = QString(), - const QVariant &val=QVariant())\ - : m_name(name), - m_value(val) - {} + ApiTraceEnumSignature(const trace::EnumSig *sig); + + QString name(signed long long value) const; - QVariant value() const { return m_value; } - QString name() const { return m_name; } private: - QString m_name; - QVariant m_value; + typedef QList<QPair<QString, signed long long> > ValueList; + ValueList m_names; }; class ApiEnum { public: - ApiEnum(ApiTraceEnumSignature *sig=0); + ApiEnum(ApiTraceEnumSignature *sig=0, signed long long value = 0); QString toString() const; @@ -78,6 +74,7 @@ public: QString name() const; private: ApiTraceEnumSignature *m_sig; + signed long long m_value; }; Q_DECLARE_METATYPE(ApiEnum); |