Add a 'human formatting' function for special-case/heuristic display

* For unsigned integers this notices UINT16/32/64_MAX and displays as
  a text string for easier consumption.
* Also for numbers over a given threshold we display them as hex instead
  of decimal.
This commit is contained in:
baldurk committed 2018-04-26 12:31:05 +01:00
1 parent 7dd4238eb0
commit 52af0722ee
2 files changed
+18 -1

No files matched your search

+17 -1
View File
@@ -716,7 +716,7 @@ void addStructuredObjects(RDTreeWidgetItem *parent, const StructuredObjectList &
case SDBasic::String: param = obj->data.str; break;
case SDBasic::Resource:
case SDBasic::Enum:
case SDBasic::UnsignedInteger: param = Formatter::Format(obj->data.basic.u); break;
case SDBasic::UnsignedInteger: param = Formatter::HumanFormat(obj->data.basic.u); break;
case SDBasic::SignedInteger: param = Formatter::Format(obj->data.basic.i); break;
case SDBasic::Float: param = Formatter::Format(obj->data.basic.d); break;
case SDBasic::Boolean: param = (obj->data.basic.b ? lit("True") : lit("False")); break;
@@ -1184,6 +1184,22 @@ QString Formatter::Format(double f, bool)
return ret;
}
QString Formatter::HumanFormat(uint64_t u)
{
if(u == UINT16_MAX)
return lit("UINT16_MAX");
if(u == UINT32_MAX)
return lit("UINT32_MAX");
if(u == UINT64_MAX)
return lit("UINT64_MAX");
// format as hex when over a certain threshold
if(u > 0xffffff)
return lit("0x") + Format(u, true);
return Format(u);
}
class RDProgressDialog : public QProgressDialog
{
public: