Advertisement
Guest User

Untitled

a guest
Mar 28th, 2013
225
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.81 KB | None | 0 0
  1. /*!
  2.   Sets the number format for the numbers drawn as tick labels (if tick label type is \ref
  3.   ltNumber). This \a formatCode is an extended version of the format code used e.g. by
  4.   QString::number() and QLocale::toString(). For reference about that, see the "Argument Formats"
  5.   section in the detailed description of the QString class. \a formatCode is a string of one, two
  6.   or three characters. The first character is identical to the normal format code used by Qt. In
  7.   short, this means: 'e'/'E' scientific format, 'f' fixed format, 'g'/'G' scientific or fixed,
  8.   whichever is shorter.
  9.  
  10.   The second and third characters are optional and specific to QCustomPlot:\n
  11.   If the first char was 'e' or 'g', numbers are/might be displayed in the scientific format, e.g.
  12.   "5.5e9", which is ugly in a plot. So when the second char of \a formatCode is set to 'b' (for
  13.   "beautiful"), those exponential numbers are formatted in a more natural way, i.e. "5.5
  14.   [multiplication sign] 10 [superscript] 9". By default, the multiplication sign is a centered dot.
  15.   If instead a cross should be shown (as is usual in the USA), the third char of \a formatCode can
  16.   be set to 'c'. The inserted multiplication signs are the UTF-8 characters 215 (0xD7) for the
  17.   cross and 183 (0xB7) for the dot.
  18.  
  19.   If the scale type (\ref setScaleType) is \ref stLogarithmic and the \a formatCode uses the 'b'
  20.   option (beautifully typeset decimal powers), the display usually is "1 [multiplication sign] 10
  21.   [superscript] n", which looks unnatural for logarithmic scaling (the "1 [multiplication sign]"
  22.   part). To only display the decimal power, set the number precision to zero with \ref
  23.   setNumberPrecision.
  24.  
  25.   Examples for \a formatCode:
  26.   \li \c g normal format code behaviour. If number is small, fixed format is used, if number is large,
  27.   normal scientific format is used
  28.   \li \c gb If number is small, fixed format is used, if number is large, scientific format is used with
  29.   beautifully typeset decimal powers and a dot as multiplication sign
  30.   \li \c ebc All numbers are in scientific format with beautifully typeset decimal power and a cross as
  31.   multiplication sign
  32.   \li \c fb illegal format code, since fixed format doesn't support (or need) beautifully typeset decimal
  33.   powers. Format code will be reduced to 'f'.
  34.   \li \c hello illegal format code, since first char is not 'e', 'E', 'f', 'g' or 'G'. Current format
  35.   code will not be changed.
  36. */
  37. void QCPAxis::setNumberFormat(const QString &formatCode)
  38. {
  39.   if (formatCode.length() < 1) return;
  40.  
  41.   // interpret first char as number format char:
  42.   QString allowedFormatChars = "eEfgG";
  43.   if (allowedFormatChars.contains(formatCode.at(0)))
  44.   {
  45.     mNumberFormatChar = formatCode.at(0).toAscii();
  46.   } else
  47.   {
  48.     qDebug() << Q_FUNC_INFO << "Invalid number format code (first char not in 'eEfgG'):" << formatCode;
  49.     return;
  50.   }
  51.   if (formatCode.length() < 2)
  52.   {
  53.     mNumberBeautifulPowers = false;
  54.     mNumberMultiplyCross = false;
  55.     return;
  56.   }
  57.  
  58.   // interpret second char as indicator for beautiful decimal powers:
  59.   if (formatCode.at(1) == 'b' && (mNumberFormatChar == 'e' || mNumberFormatChar == 'g'))
  60.   {
  61.     mNumberBeautifulPowers = true;
  62.   } else
  63.   {
  64.     qDebug() << Q_FUNC_INFO << "Invalid number format code (second char not 'b' or first char neither 'e' nor 'g'):" << formatCode;
  65.     return;
  66.   }
  67.   if (formatCode.length() < 3)
  68.   {
  69.     mNumberMultiplyCross = false;
  70.     return;
  71.   }
  72.  
  73.   // interpret third char as indicator for dot or cross multiplication symbol:
  74.   if (formatCode.at(2) == 'c')
  75.   {
  76.     mNumberMultiplyCross = true;
  77.   } else if (formatCode.at(2) == 'd')
  78.   {
  79.     mNumberMultiplyCross = false;
  80.   } else
  81.   {
  82.     qDebug() << Q_FUNC_INFO << "Invalid number format code (third char neither 'c' nor 'd'):" << formatCode;
  83.     return;
  84.   }
  85. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement