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
2018-04-26 12:31:05 +01:00
parent 7dd4238eb0
commit 52af0722ee
2 changed files with 18 additions and 1 deletions
+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:
+1
View File
@@ -166,6 +166,7 @@ struct Formatter
static void shutdown();
static QString Format(double f, bool hex = false);
static QString HumanFormat(uint64_t u);
static QString Format(uint64_t u, bool hex = false)
{
return QFormatStr("%1").arg(u, hex ? 16 : 0, hex ? 16 : 10, QLatin1Char('0')).toUpper();