mirror of
https://github.com/jkriege2/JKQtPlotter.git
synced 2024-12-25 18:11:38 +08:00
moved two protected methods from JKQTPCoordinateAxis to jkqtpstringtools.h/.cpp
This commit is contained in:
parent
e63f053896
commit
0009ff8f64
@ -835,6 +835,31 @@ QString jkqtp_floattohtmlqstr(double data, int past_comma, bool remove_trail0, d
|
|||||||
return QString::fromStdString(jkqtp_floattohtmlstr(data, past_comma, remove_trail0, belowIsZero, minNoExponent, maxNoExponent));
|
return QString::fromStdString(jkqtp_floattohtmlstr(data, past_comma, remove_trail0, belowIsZero, minNoExponent, maxNoExponent));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QString jkqtp_floattoqstr(const QLocale & loc, double data, char format, int past_comma, bool remove_trail0)
|
||||||
|
{
|
||||||
|
QString res=loc.toString(data, format, past_comma);
|
||||||
|
if (remove_trail0 && res.contains(loc.decimalPoint())) {
|
||||||
|
QString expo="";
|
||||||
|
const int expIdx=res.toLower().indexOf('e');
|
||||||
|
if (expIdx>=0) {
|
||||||
|
expo=res.mid(expIdx);
|
||||||
|
res=res.left(expIdx);
|
||||||
|
}
|
||||||
|
while (res.size()>0 && res[res.size()-1]=='0') {
|
||||||
|
res=res.left(res.size()-1);
|
||||||
|
}
|
||||||
|
if (res.size()>0 && res[res.size()-1]==loc.decimalPoint()) res=res.left(res.size()-1);
|
||||||
|
res=res+expo;
|
||||||
|
}
|
||||||
|
return res;
|
||||||
|
|
||||||
|
}
|
||||||
|
QString jkqtp_floattoqstr(double data, char format, int past_comma, bool remove_trail0)
|
||||||
|
{
|
||||||
|
QLocale loc=QLocale::system();
|
||||||
|
loc.setNumberOptions(QLocale::OmitGroupSeparator);
|
||||||
|
return jkqtp_floattoqstr(loc, data, format, past_comma, remove_trail0);
|
||||||
|
}
|
||||||
|
|
||||||
QString jkVariantListToString(const QList<QVariant>& data, const QString& separator) {
|
QString jkVariantListToString(const QList<QVariant>& data, const QString& separator) {
|
||||||
QString r="";
|
QString r="";
|
||||||
@ -1184,3 +1209,8 @@ bool jkqtp_rxExactlyMatches(const QString& text, const QString ®ex, QStringLi
|
|||||||
return res;
|
return res;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QString jkqtp_floattolatexunitqstr(double data, int past_comma, bool remove_trail0, double belowIsZero)
|
||||||
|
{
|
||||||
|
return QString::fromStdString(jkqtp_floattolatexunitstr(data, past_comma, remove_trail0, belowIsZero));
|
||||||
|
}
|
||||||
|
@ -188,6 +188,16 @@ JKQTCOMMON_LIB_EXPORT std::string jkqtp_uinttostr(unsigned long data);
|
|||||||
*/
|
*/
|
||||||
JKQTCOMMON_LIB_EXPORT std::string jkqtp_floattostr(double data, int past_comma=-1, bool remove_trail0=false, double belowIsZero=1e-16);
|
JKQTCOMMON_LIB_EXPORT std::string jkqtp_floattostr(double data, int past_comma=-1, bool remove_trail0=false, double belowIsZero=1e-16);
|
||||||
|
|
||||||
|
/** \brief convert a float to a string using \a format (\c f|e|E|g|G ) with given number of decimals after comma \a past_comma and optional removal of trailing zeros behind decimal separator \a remove_trail0. Uses given QLocal \a loc .
|
||||||
|
* \ingroup jkqtptools_string
|
||||||
|
*/
|
||||||
|
JKQTCOMMON_LIB_EXPORT QString jkqtp_floattoqstr(const QLocale & loc, double data, char format='f', int past_comma=-1, bool remove_trail0=false);
|
||||||
|
|
||||||
|
/** \brief convert a float to a string using \a format (\c f|e|E|g|G ) with given number of decimals after comma \a past_comma and optional removal of trailing zeros behind decimal separator \a remove_trail0. Uses system local, disables not use Group-Separator
|
||||||
|
* \ingroup jkqtptools_string
|
||||||
|
*/
|
||||||
|
JKQTCOMMON_LIB_EXPORT QString jkqtp_floattoqstr(double data, char format='f', int past_comma=-1, bool remove_trail0=false);
|
||||||
|
|
||||||
/** \brief convert a boolean to a string
|
/** \brief convert a boolean to a string
|
||||||
* \ingroup jkqtptools_string
|
* \ingroup jkqtptools_string
|
||||||
*/
|
*/
|
||||||
@ -279,6 +289,10 @@ JKQTCOMMON_LIB_EXPORT QString jkqtp_floattolatexqstr(double data, int past_comma
|
|||||||
* \ingroup jkqtptools_string
|
* \ingroup jkqtptools_string
|
||||||
*/
|
*/
|
||||||
JKQTCOMMON_LIB_EXPORT QString jkqtp_floattohtmlqstr(double data, int past_comma=5, bool remove_trail0=false, double belowIsZero=1e-16, double minNoExponent=1e-3, double maxNoExponent=1e4);
|
JKQTCOMMON_LIB_EXPORT QString jkqtp_floattohtmlqstr(double data, int past_comma=5, bool remove_trail0=false, double belowIsZero=1e-16, double minNoExponent=1e-3, double maxNoExponent=1e4);
|
||||||
|
/** \brief convert a double to a LaTeX-encoded string, encoding powers of ten as characters, e.g. \c jkqtp_floattounitqstr(1000) will result in "1k"
|
||||||
|
* \ingroup jkqtptools_string
|
||||||
|
*/
|
||||||
|
JKQTCOMMON_LIB_EXPORT QString jkqtp_floattolatexunitqstr(double data, int past_comma=5, bool remove_trail0=false, double belowIsZero=std::numeric_limits<double>::min()*4);
|
||||||
|
|
||||||
/** \brief convert a character to a string
|
/** \brief convert a character to a string
|
||||||
* \ingroup jkqtptools_string
|
* \ingroup jkqtptools_string
|
||||||
|
@ -373,31 +373,6 @@ double JKQTPCoordinateAxis::calcLogTickSpacing() {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QString JKQTPCoordinateAxis::floattostringWithFormat(const QLocale & loc, double data, char format, int past_comma, bool remove_trail0) const
|
|
||||||
{
|
|
||||||
QString res=loc.toString(data, format, past_comma);
|
|
||||||
if (remove_trail0 && res.contains(QLocale::system().decimalPoint())) {
|
|
||||||
QString expo="";
|
|
||||||
const int expIdx=res.toLower().indexOf('e');
|
|
||||||
if (expIdx>=0) {
|
|
||||||
expo=res.mid(expIdx);
|
|
||||||
res=res.left(expIdx);
|
|
||||||
}
|
|
||||||
while (res.size()>0 && res[res.size()-1]=='0') {
|
|
||||||
res=res.left(res.size()-1);
|
|
||||||
}
|
|
||||||
if (res.size()>0 && res[res.size()-1]==loc.decimalPoint()) res=res.left(res.size()-1);
|
|
||||||
res=res+expo;
|
|
||||||
}
|
|
||||||
return res;
|
|
||||||
|
|
||||||
}
|
|
||||||
QString JKQTPCoordinateAxis::floattostringWithFormat(double data, char format, int past_comma, bool remove_trail0) const
|
|
||||||
{
|
|
||||||
QLocale loc=QLocale::system();
|
|
||||||
loc.setNumberOptions(QLocale::OmitGroupSeparator);
|
|
||||||
return floattostringWithFormat(loc, data, format, past_comma, remove_trail0);
|
|
||||||
}
|
|
||||||
|
|
||||||
QString JKQTPCoordinateAxis::floattolabel(double data) const {
|
QString JKQTPCoordinateAxis::floattolabel(double data) const {
|
||||||
const int past_comma=axisStyle.labelDigits;
|
const int past_comma=axisStyle.labelDigits;
|
||||||
@ -429,9 +404,9 @@ QString JKQTPCoordinateAxis::floattolabel(double data, int past_comma) const {
|
|||||||
case JKQTPCALTcount:
|
case JKQTPCALTcount:
|
||||||
return "";
|
return "";
|
||||||
case JKQTPCALTdefault:
|
case JKQTPCALTdefault:
|
||||||
return addTickUnit(floattostringWithFormat(loc, data, 'f', past_comma, remove_trail0));
|
return addTickUnit(jkqtp_floattoqstr(loc, data, 'f', past_comma, remove_trail0));
|
||||||
case JKQTPCALTscientific:
|
case JKQTPCALTscientific:
|
||||||
return addTickUnit(floattostringWithFormat(loc, data, 'e', past_comma, remove_trail0));
|
return addTickUnit(jkqtp_floattoqstr(loc, data, 'e', past_comma, remove_trail0));
|
||||||
case JKQTPCALTexponent:
|
case JKQTPCALTexponent:
|
||||||
return addTickUnit(QString(jkqtp_floattolatexstr(data, past_comma, remove_trail0, belowIsZero, pow(10.0, -static_cast<double>(past_comma)-0.0001), pow(10.0, static_cast<double>(past_comma)+1)).c_str()));
|
return addTickUnit(QString(jkqtp_floattolatexstr(data, past_comma, remove_trail0, belowIsZero, pow(10.0, -static_cast<double>(past_comma)-0.0001), pow(10.0, static_cast<double>(past_comma)+1)).c_str()));
|
||||||
case JKQTPCALTexponentCharacter:
|
case JKQTPCALTexponentCharacter:
|
||||||
|
@ -741,10 +741,6 @@ class JKQTPLOTTER_LIB_EXPORT JKQTPCoordinateAxis: public QObject {
|
|||||||
const JKQTMathText* getParentMathText() const;
|
const JKQTMathText* getParentMathText() const;
|
||||||
|
|
||||||
|
|
||||||
/** \brief convert a float to a string using \a format (\c f|e|E|g|G ) with given number of decimals after comma \a past_comma and optional removal of trailing zeros behind decimal separator \a remove_trail0. Uses current local, disables not use Group-Separator */
|
|
||||||
QString floattostringWithFormat(const QLocale & loc, double data, char format, int past_comma, bool remove_trail0=true) const;
|
|
||||||
/** \brief convert a float to a string using \a format (\c f|e|E|g|G ) with given number of decimals after comma \a past_comma and optional removal of trailing zeros behind decimal separator \a remove_trail0. Uses current local, disables not use Group-Separator */
|
|
||||||
QString floattostringWithFormat(double data, char format, int past_comma, bool remove_trail0=true) const;
|
|
||||||
/** \brief convert a float to a tick label string */
|
/** \brief convert a float to a tick label string */
|
||||||
QString floattolabel(double data) const;
|
QString floattolabel(double data) const;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user