mirror of
https://github.com/baldurk/renderdoc.git
synced 2026-05-04 17:10:47 +00:00
Implement float formatting rules
This commit is contained in:
@@ -160,12 +160,9 @@ void PersistantConfig::applyValues(const QVariantMap &values)
|
||||
|
||||
void PersistantConfig::SetupFormatting()
|
||||
{
|
||||
Formatter::setParams(Formatter_MinFigures, Formatter_MaxFigures, Formatter_NegExp,
|
||||
Formatter_PosExp);
|
||||
/*
|
||||
Formatter.MinFigures = Formatter_MinFigures;
|
||||
Formatter.MaxFigures = Formatter_MaxFigures;
|
||||
Formatter.ExponentialNegCutoff = Formatter_NegExp;
|
||||
Formatter.ExponentialPosCutoff = Formatter_PosExp;
|
||||
|
||||
PreferredFont = Font_PreferMonospaced
|
||||
? new System.Drawing.Font("Consolas", 9.25F, System.Drawing.FontStyle.Regular,
|
||||
System.Drawing.GraphicsUnit.Point, ((byte)(0)))
|
||||
|
||||
@@ -30,6 +30,7 @@
|
||||
#include <QMenu>
|
||||
#include <QMetaMethod>
|
||||
#include <QTreeWidget>
|
||||
#include <QtMath>
|
||||
|
||||
QString ToQStr(const ResourceUsage usage, const GraphicsAPI apitype)
|
||||
{
|
||||
@@ -501,3 +502,45 @@ QTreeWidgetItem *makeTreeNode(const QVariantList &values)
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int Formatter::m_minFigures = 2, Formatter::m_maxFigures = 5, Formatter::m_expNegCutoff = 5,
|
||||
Formatter::m_expPosCutoff = 7;
|
||||
double Formatter::m_expNegValue = 0.00001; // 10^(-5)
|
||||
double Formatter::m_expPosValue = 10000000.0; // 10^7
|
||||
|
||||
void Formatter::setParams(int minFigures, int maxFigures, int expNegCutoff, int expPosCutoff)
|
||||
{
|
||||
m_minFigures = qMax(0, minFigures);
|
||||
m_maxFigures = qMax(2, maxFigures);
|
||||
m_expNegCutoff = qMax(0, expNegCutoff);
|
||||
m_expPosCutoff = qMax(0, expPosCutoff);
|
||||
|
||||
m_expNegValue = qPow(10.0, -m_expNegCutoff);
|
||||
m_expPosValue = qPow(10.0, m_expPosCutoff);
|
||||
}
|
||||
|
||||
QString Formatter::Format(double f, bool)
|
||||
{
|
||||
if(f != 0.0 && (qAbs(f) < m_expNegValue || qAbs(f) > m_expPosValue))
|
||||
return QString("%1").arg(f, -m_minFigures, 'E', m_maxFigures);
|
||||
|
||||
QString ret = QString("%1").arg(f, 0, 'f', m_maxFigures);
|
||||
|
||||
// trim excess trailing 0s
|
||||
int decimal = ret.lastIndexOf(QChar('.'));
|
||||
if(decimal > 0)
|
||||
{
|
||||
decimal += m_minFigures;
|
||||
|
||||
const int len = ret.count();
|
||||
|
||||
int remove = 0;
|
||||
while(len - remove - 1 > decimal && ret.at(len - remove - 1) == QChar('0'))
|
||||
remove++;
|
||||
|
||||
if(remove > 0)
|
||||
ret.chop(remove);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -349,11 +349,21 @@ QString RowTypeString(const ShaderVariable &v);
|
||||
|
||||
struct Formatter
|
||||
{
|
||||
static QString Format(float f) { return QString::number(f); }
|
||||
static QString Format(double d) { return QString::number(d); }
|
||||
static QString Format(uint32_t u) { return QString::number(u); }
|
||||
static QString Format(uint16_t u) { return QString::number(u); }
|
||||
static QString Format(int32_t i) { return QString::number(i); }
|
||||
static void setParams(int minFigures, int maxFigures, int expNegCutoff, int expPosCutoff);
|
||||
|
||||
static QString Format(double f, bool hex = false);
|
||||
static QString Format(uint32_t u, bool hex = false)
|
||||
{
|
||||
return QString("%1").arg(u, hex ? 8 : 0, hex ? 16 : 10, QChar('0'));
|
||||
}
|
||||
static QString Format(uint16_t u, bool hex = false)
|
||||
{
|
||||
return QString("%1").arg(u, hex ? 8 : 0, hex ? 16 : 10, QChar('0'));
|
||||
}
|
||||
static QString Format(int32_t i, bool hex = false) { return QString::number(i); }
|
||||
private:
|
||||
static int m_minFigures, m_maxFigures, m_expNegCutoff, m_expPosCutoff;
|
||||
static double m_expNegValue, m_expPosValue;
|
||||
};
|
||||
|
||||
bool SaveToJSON(QVariantMap &data, QIODevice &f, const char *magicIdentifier, uint32_t magicVersion);
|
||||
|
||||
Reference in New Issue
Block a user