2015-07-11 18:56:02 +08:00
/*
2019-01-12 23:01:55 +08:00
Copyright ( c ) 2008 - 2019 Jan W . Krieger ( < jan @ jkrieger . de > , < j . krieger @ dkfz . de > )
2015-07-11 18:56:02 +08:00
2015-07-12 22:34:27 +08:00
2015-07-11 18:56:02 +08:00
This software is free software : you can redistribute it and / or modify
2019-02-08 00:24:46 +08:00
it under the terms of the GNU Lesser General Public License as published by
2015-07-11 18:56:02 +08:00
the Free Software Foundation , either version 3 of the License , or
( at your option ) any later version .
This program is distributed in the hope that it will be useful ,
but WITHOUT ANY WARRANTY ; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
2019-02-08 00:24:46 +08:00
GNU Lesser General Public License for more details .
2015-07-11 18:56:02 +08:00
2019-02-08 00:24:46 +08:00
You should have received a copy of the GNU Lesser General Public License
2015-07-11 18:56:02 +08:00
along with this program . If not , see < http : //www.gnu.org/licenses/>.
*/
# ifndef JKQTPTOOLS_H_INCLUDED
# define JKQTPTOOLS_H_INCLUDED
2018-11-26 03:25:44 +08:00
# include "jkqtplottertools/jkqtp_imexport.h"
2015-07-11 18:56:02 +08:00
# include <QString>
# include <QElapsedTimer>
2018-12-19 00:13:18 +08:00
# include <QLocale>
2015-07-11 18:56:02 +08:00
# include <QPainter>
# include <cfloat>
# include <QPrinter>
# include <sys/types.h>
# include <sys/stat.h>
# include <errno.h>
# include <string>
# include <iostream>
# include <fstream>
# include <sstream>
# include <cstdarg>
# include <cstdio>
# include <cstdlib>
# include <vector>
2018-12-19 00:13:18 +08:00
# include <ctime>
# include <cmath>
2019-05-06 01:31:20 +08:00
# include <limits>
2018-12-19 00:13:18 +08:00
# include <cstdint>
2015-07-11 18:56:02 +08:00
# include <stdexcept>
# include <cctype>
# ifndef __WINDOWS__
# if defined(WIN32) || defined(WIN64) || defined(_MSC_VER) || defined(_WIN32)
# define __WINDOWS__
# endif
# endif
# ifndef __LINUX__
# if defined(linux)
# define __LINUX__
# endif
# endif
# undef JKTOOLS_TIMER_USE_TIME
# if defined(__WINDOWS__)
# include <windows.h>
# elif defined(__LINUX__)
# include <sys/time.h>
# else
# define JKTOOLS_TIMER_USE_TIME
# endif
class JKQTPEnhancedPainter ; // forward
2019-01-20 17:49:29 +08:00
class JKQTBasePlotter ; // forward declaration
2015-07-11 18:56:02 +08:00
2019-05-11 21:56:11 +08:00
/** \brief double-value NotANumber
* \ ingroup jkqtptools_math
*/
# define JKQTP_DOUBLE_NAN (std::numeric_limits<double>::signaling_NaN())
/** \brief float-value NotANumber
* \ ingroup jkqtptools_math
*/
# define JKQTP_FLOAT_NAN (std::numeric_limits<float>::signaling_NaN())
/** \brief double-value NotANumber
* \ ingroup jkqtptools_math
*/
# define JKQTP_NAN JKQTP_DOUBLE_NAN
2019-02-08 00:24:46 +08:00
/** \brief C++11 finally construct
2019-01-19 16:40:52 +08:00
* \ ingroup jkqtptools
2019-02-08 00:24:46 +08:00
*
* \ see JKQTPFinally ( )
2019-01-13 01:53:16 +08:00
*/
2019-02-08 00:24:46 +08:00
template < class F >
class JKQTPFinalAct
{
public :
explicit JKQTPFinalAct ( F f ) noexcept
: f_ ( std : : move ( f ) ) , invoke_ ( true ) { }
JKQTPFinalAct ( JKQTPFinalAct & & other ) noexcept
: f_ ( std : : move ( other . f_ ) ) ,
invoke_ ( other . invoke_ )
{
other . invoke_ = false ;
}
JKQTPFinalAct ( const JKQTPFinalAct & ) = delete ;
JKQTPFinalAct & operator = ( const JKQTPFinalAct & ) = delete ;
~ JKQTPFinalAct ( ) noexcept
{
if ( invoke_ ) f_ ( ) ;
}
private :
F f_ ;
bool invoke_ ;
} ;
/** \brief C++11 finally construct
2019-05-11 21:56:11 +08:00
* \ ingroup jkqtptools_math
2019-02-08 00:24:46 +08:00
* \ see JKQTPFinalAct
*/
template < class F >
inline JKQTPFinalAct < F > JKQTPFinally ( const F & f ) noexcept
{
return JKQTPFinalAct < F > ( f ) ;
}
/** \brief C++11 finally construct
2019-05-11 21:56:11 +08:00
* \ ingroup jkqtptools_math
2019-02-08 00:24:46 +08:00
* \ see JKQTPFinalAct
*/
template < class F >
inline JKQTPFinalAct < F > JKQTPFinally ( F & & f ) noexcept
{
return JKQTPFinalAct < F > ( std : : forward < F > ( f ) ) ;
}
2015-07-11 18:56:02 +08:00
/** \brief check whether the dlotaing point number is OK (i.e. non-inf, non-NAN)
* \ ingroup jkqtptools
*/
2019-01-10 04:23:24 +08:00
template < typename T >
2019-01-20 23:15:10 +08:00
inline bool JKQTPIsOKFloat ( T v ) {
2019-01-10 04:23:24 +08:00
return std : : isfinite ( v ) & & ( ! std : : isinf ( v ) ) & & ( ! std : : isnan ( v ) ) ;
}
2015-07-11 18:56:02 +08:00
2019-05-06 01:31:20 +08:00
/** \brief Styles in which to mark single positions during user actions in JKQTPlotter
* \ ingroup jkqtptools
*/
enum JKQTPUserActionMarkerType {
jkqtpuamtCircle = 0 , /*!< \brief a small circle around the position to mark */
jkqtpuamtCrossHair = 1 , /*!< \brief a cross-hair to the position to mark */
jkqtpuamtCircleAndCrossHair = 2 , /*!< \brief a cross-hair to the position to mark, with a circle-marker around the actual target (i.e. combines jkqtpuamtCircle and jkqtpuamtCrossHair) */
} ;
/** \brief convert a JKQTPUserActionMarkerType to a <a href="http://doc.qt.io/qt-5/qstring.html">QString</a>
2019-05-11 21:56:11 +08:00
* \ ingroup jkqtptools_string
2019-05-06 01:31:20 +08:00
*
* \ see String2JKQTPUserActionMarkerType ( ) , JKQTPUserActionMarkerType
*/
JKQTP_LIB_EXPORT QString JKQTPUserActionMarkerType2String ( JKQTPUserActionMarkerType act ) ;
/** \brief convert a <a href="http://doc.qt.io/qt-5/qstring.html">QString</a> (created by JKQTPUserActionMarkerType2String() ) to JKQTPUserActionMarkerType
2019-05-11 21:56:11 +08:00
* \ ingroup jkqtptools_string
2019-05-06 01:31:20 +08:00
*
* \ see JKQTPUserActionMarkerType2String ( ) , JKQTPUserActionMarkerType
*/
JKQTP_LIB_EXPORT JKQTPUserActionMarkerType String2JKQTPUserActionMarkerType ( const QString & act ) ;
2019-02-08 00:24:46 +08:00
/** \brief Availble action this JKQtPlotter can perform when mouse events occur.
* This allows you to e . g . draw rectangles or lines over the plot and receive a signal , when the drawing finishes
* \ ingroup jkqtptools
2015-07-11 18:56:02 +08:00
2019-02-08 00:24:46 +08:00
*/
enum JKQTPMouseDragActions {
jkqtpmdaPanPlotOnMove = 0 , /*!< \brief the user can drag the current plot window while keeping the left mouse-button pushed down (=panning), the new widow is applied/displayed whenever the mouse moves \image html drag_viewport.gif "Drag the Plot Viewport" */
jkqtpmdaPanPlotOnRelease , /*!< \brief the user can drag the current plot window while keeping the left mouse-button pushed down (=panning), the new widow is applied/displayed when the left mouse button is released */
jkqtpmdaZoomByRectangle , /*!< \brief draw a rectangle and when finish zoom to that rectangle */
jkqtpmdaDrawRectangleForEvent , /*!< \brief draw a rectangle and when finished execute the signal JKQTPlotter::userRectangleFinished() \image html draw_rectangle.gif "Draw Rectangle User-Action" */
jkqtpmdaDrawCircleForEvent , /*!< \brief draw a circle and when finished execute the signal JKQTPlotter::userCircleFinished() \image html draw_circle.gif "Draw Circle User-Action" */
jkqtpmdaDrawEllipseForEvent , /*!< \brief draw an ellipse and when finished execute the signal JKQTPlotter::userEllipseFinished() \image html draw_ellipse.gif "Draw Ellipse User-Action" */
jkqtpmdaDrawLineForEvent , /*!< \brief draw a line and when finished execute the signal JKQTPlotter::userLineFinished() \image html draw_line.gif "Draw Lines User-Action" */
jkqtpmdaScribbleForEvents , /*!< \brief let the user scribble on the plot (left mouse button is kept pressed) and call JKQTPlotter::userScribbleClick() for each new position */
2019-05-06 01:31:20 +08:00
jkqtpmdaToolTipForClosestDataPoint , /*!< \brief shows a tooltip with data of the closest data-point in the plot \image html tooltiptool.gif */
jkqtpmdaRuler , /*!< \brief shows a ruler over the plot, which measures delta X, delta Y and sqrt(dx^2+dy^2) \image html rulertool.gif */
2019-02-08 00:24:46 +08:00
} ;
2019-05-06 01:31:20 +08:00
2019-02-08 00:24:46 +08:00
/** \brief convert a JKQTPMouseDragActions to a <a href="http://doc.qt.io/qt-5/qstring.html">QString</a>
2019-05-11 21:56:11 +08:00
* \ ingroup jkqtptools_string
2019-02-08 00:24:46 +08:00
*
* \ see String2JKQTPMouseDragActions ( ) , JKQTPMouseDragActions
*/
JKQTP_LIB_EXPORT QString JKQTPMouseDragActions2String ( JKQTPMouseDragActions act ) ;
/** \brief convert a <a href="http://doc.qt.io/qt-5/qstring.html">QString</a> (created by JKQTPMouseDragActions2String() ) to JKQTPMouseDragActions
2019-05-11 21:56:11 +08:00
* \ ingroup jkqtptools_string
2019-02-08 00:24:46 +08:00
*
* \ see JKQTPMouseDragActions2String ( ) , JKQTPMouseDragActions
*/
JKQTP_LIB_EXPORT JKQTPMouseDragActions String2JKQTPMouseDragActions ( const QString & button ) ;
/** \brief actions that can be bound to a double-click of the mouse
* \ ingroup jkqtptools
*/
enum JKQTPMouseDoubleClickActions {
jkqtpdcaClickZoomsIn = 0 , /*!< \brief a double-click zooms into the plot at the current mouse location */
jkqtpdcaClickZoomsOut , /*!< \brief a double-click zooms out of the plot at the current mouse location */
jkqtpdcaClickOpensContextMenu , /*!< \brief a double-click opens the context menu */
jkqtpdcaClickOpensSpecialContextMenu , /*!< \brief a double-click opens the special context menu \see setSpecialContextMenu() */
jkqtpdcaClickMovesViewport , /*!< \brief a double-click centers the x/y-range around the clicked position */
} ;
/** \brief convert a JKQTPMouseDoubleClickActions to a <a href="http://doc.qt.io/qt-5/qstring.html">QString</a>
2019-05-11 21:56:11 +08:00
* \ ingroup jkqtptools_string
2019-02-08 00:24:46 +08:00
*
* \ see String2JKQTPMouseDoubleClickActions ( ) , JKQTPMouseDoubleClickActions
*/
JKQTP_LIB_EXPORT QString JKQTPMouseDoubleClickActions2String ( JKQTPMouseDoubleClickActions act ) ;
/** \brief convert a <a href="http://doc.qt.io/qt-5/qstring.html">QString</a> (created by JKQTPMouseDoubleClickActions2String() ) to JKQTPMouseDoubleClickActions
2019-05-11 21:56:11 +08:00
* \ ingroup jkqtptools_string
2019-02-08 00:24:46 +08:00
*
* \ see JKQTPMouseDoubleClickActions2String ( ) , JKQTPMouseDoubleClickActions
*/
JKQTP_LIB_EXPORT JKQTPMouseDoubleClickActions String2JKQTPMouseDoubleClickActions ( const QString & act ) ;
/** \brief actions that can be bound to a mouse wheel event
* \ ingroup jkqtptools
*/
enum JKQTPMouseWheelActions {
jkqtpmwaZoomByWheel = 0 , /*!< \brief use the mouse-wheel for zooming */
jkqtpmwaPanByWheel , /*!< \brief use the mouse-wheel for panning the plot */
} ;
/** \brief convert a JKQTPMouseWheelActions to a <a href="http://doc.qt.io/qt-5/qstring.html">QString</a>
2019-05-11 21:56:11 +08:00
* \ ingroup jkqtptools_string
2019-02-08 00:24:46 +08:00
*
* \ see String2JKQTPMouseWheelActions ( ) , JKQTPMouseWheelActions
*/
JKQTP_LIB_EXPORT QString JKQTPMouseWheelActions2String ( JKQTPMouseWheelActions act ) ;
/** \brief convert a <a href="http://doc.qt.io/qt-5/qstring.html">QString</a> (created by JKQTPMouseWheelActions2String() ) to JKQTPMouseWheelActions
2019-05-11 21:56:11 +08:00
* \ ingroup jkqtptools_string
2019-02-08 00:24:46 +08:00
*
* \ see JKQTPMouseWheelActions2String ( ) , JKQTPMouseWheelActions
*/
JKQTP_LIB_EXPORT JKQTPMouseWheelActions String2JKQTPMouseWheelActions ( const QString & act ) ;
/** \brief modes for the context menu
* \ ingroup jkqtptools
*/
enum JKQTPContextMenuModes {
jkqtpcmmStandardContextMenu = 0 , /*!< \brief only show the standard context menu \image html zoomin_mouse_contextmenu.gif "Zooming with the mouse" */
jkqtpcmmSpecialContextMenu , /*!< \brief only show the special context menu \see setSpecialContextMenu() */
jkqtpcmmStandardAndSpecialContextMenu , /*!< \brief show the standard context menu, with the special context menu incorporated \see setSpecialContextMenu() */
jkqtpcmmNoContextMenu , /*!< \brief don't show a context menu at all */
} ;
/** \brief convert a JKQTPContextMenuModes to a <a href="http://doc.qt.io/qt-5/qstring.html">QString</a>
2019-05-11 21:56:11 +08:00
* \ ingroup jkqtptools_string
2019-02-08 00:24:46 +08:00
*
* \ see String2JKQTPContextMenuModes ( ) , JKQTPContextMenuModes
*/
JKQTP_LIB_EXPORT QString JKQTPContextMenuModes2String ( JKQTPContextMenuModes act ) ;
/** \brief convert a <a href="http://doc.qt.io/qt-5/qstring.html">QString</a> (created by JKQTPContextMenuModes2String() ) to JKQTPContextMenuModes
2019-05-11 21:56:11 +08:00
* \ ingroup jkqtptools_string
2019-02-08 00:24:46 +08:00
*
* \ see JKQTPContextMenuModes2String ( ) , JKQTPContextMenuModes
*/
JKQTP_LIB_EXPORT JKQTPContextMenuModes String2JKQTPContextMenuModes ( const QString & act ) ;
typedef QHash < QPair < Qt : : MouseButton , Qt : : KeyboardModifiers > , JKQTPMouseDragActions > JKQTPMouseDragActionsHashMap ;
typedef JKQTPMouseDragActionsHashMap : : const_iterator JKQTPMouseDragActionsHashMapIterator ;
typedef QHash < Qt : : KeyboardModifiers , JKQTPMouseWheelActions > JKQTPMouseWheelActionsHashMap ;
typedef JKQTPMouseWheelActionsHashMap : : const_iterator JKQTPMouseWheelActionsHashMapIterator ;
typedef QHash < QPair < Qt : : MouseButton , Qt : : KeyboardModifiers > , JKQTPMouseDoubleClickActions > JKQTPMouseDoubleClickActionsHashMap ;
typedef JKQTPMouseDoubleClickActionsHashMap : : const_iterator JKQTPMouseDoubleClickActionsHashMapIterator ;
2015-07-11 18:56:02 +08:00
/** \brief converts a QT::PenStyle into a string
2019-05-11 21:56:11 +08:00
* \ ingroup jkqtptools_string
2015-07-11 18:56:02 +08:00
*/
2019-02-03 21:04:48 +08:00
JKQTP_LIB_EXPORT QString jkqtp_QPenStyle2String ( Qt : : PenStyle style ) ;
2015-07-11 18:56:02 +08:00
/** \brief converts a QString into a Qt::PenStyle
2019-05-11 21:56:11 +08:00
* \ ingroup jkqtptools_string
2015-07-11 18:56:02 +08:00
*/
2019-02-03 21:04:48 +08:00
JKQTP_LIB_EXPORT Qt : : PenStyle jkqtp_String2QPenStyle ( const QString & style ) ;
2015-07-11 18:56:02 +08:00
/** \brief converts a QT::BrushStyle into a string
2019-05-11 21:56:11 +08:00
* \ ingroup jkqtptools_string
2015-07-11 18:56:02 +08:00
*/
2019-02-03 21:04:48 +08:00
JKQTP_LIB_EXPORT QString jkqtp_QBrushStyle2String ( Qt : : BrushStyle style ) ;
2015-07-11 18:56:02 +08:00
/** \brief converts a QString into a Qt::BrushStyle
2019-05-11 21:56:11 +08:00
* \ ingroup jkqtptools_string
2015-07-11 18:56:02 +08:00
*/
2019-02-03 21:04:48 +08:00
JKQTP_LIB_EXPORT Qt : : BrushStyle jkqtp_String2QBrushStyle ( const QString & style ) ;
2015-07-11 18:56:02 +08:00
2019-02-08 00:24:46 +08:00
/** \brief Specifies how a fill-color is derived from a given color
* \ ingroup jkqtptools
*/
enum JKQTPColorDerivationMode {
JKQTPFFCMSameColor , /*!< \brief fill with the same color */
JKQTPFFCMInvertedColor , /*!< \brief fill with the inverted color */
JKQTPFFCMLighterColor , /*!< \brief fill with the a lighter color */
JKQTPFFCMEvenLighterColor , /*!< \brief fill with the an even lighter color than JKQTPFFCMLighterColor */
JKQTPFFCMDarkerColor , /*!< \brief fill with the a darker color */
JKQTPFFCMEvenDarkerColor , /*!< \brief fill with the an even darker color than JKQTPFFCMDarkerColor */
JKQTPFFCMMoreTransparentColor , /*!< \brief fill with the a partly transparent color */
JKQTPFFCMEvenMoreTransparentColor , /*!< \brief fill with the a more transparent color than JKQTPFFCMMoreTransparentColor */
JKQTPFFCMLessTransparentColor , /*!< \brief fill with the a partly transparent color */
JKQTPFFCMEvenLessTransparentColor , /*!< \brief fill with the a more transparent color than JKQTPFFCMLessTransparentColor*/
} ;
/** \brief use a JKQTPColorDerivationMode to derive a color from \a col as specified
2019-05-11 21:56:11 +08:00
* \ ingroup jkqtptools_drawing
2019-02-08 00:24:46 +08:00
*
* \ see JKQTPColorDerivationMode
*/
JKQTP_LIB_EXPORT QColor JKQTPGetDerivedColor ( JKQTPColorDerivationMode mode , const QColor & col ) ;
2019-05-06 01:31:20 +08:00
/** \brief construct a QColor, based on the given \a color, but with alpha set to the specified value \a alphaF
2019-05-11 21:56:11 +08:00
* \ ingroup jkqtptools_drawing
2019-05-06 01:31:20 +08:00
* \ see QColorWithAlpha ( )
*/
inline QColor QColorWithAlphaF ( const QColor & color , qreal alphaF ) {
QColor c = color ;
c . setAlphaF ( alphaF ) ;
return c ;
}
/** \brief construct a QColor, based on the given \a color, but with alpha set to the specified value \a alpha
2019-05-11 21:56:11 +08:00
* \ ingroup jkqtptools_drawing
2019-05-06 01:31:20 +08:00
* \ see QColorWithAlphaF ( )
*/
inline QColor QColorWithAlpha ( const QColor & color , int alpha ) {
QColor c = color ;
c . setAlpha ( alpha ) ;
return c ;
}
2019-02-08 00:24:46 +08:00
/** \brief convert a JKQTPColorDerivationMode to a <a href="http://doc.qt.io/qt-5/qstring.html">QString</a>
2019-05-11 21:56:11 +08:00
* \ ingroup jkqtptools_string
2019-02-08 00:24:46 +08:00
*
* \ see String2JKQTPColorDerivationMode ( ) , JKQTPColorDerivationMode
*/
JKQTP_LIB_EXPORT QString JKQTPColorDerivationMode2String ( JKQTPColorDerivationMode mode ) ;
/** \brief convert a <a href="http://doc.qt.io/qt-5/qstring.html">QString</a> (created by JKQTPColorDerivationMode2String() ) to JKQTPColorDerivationMode
2019-05-11 21:56:11 +08:00
* \ ingroup jkqtptools_string
2019-02-08 00:24:46 +08:00
*
* \ see JKQTPColorDerivationMode2String ( ) , JKQTPColorDerivationMode
*/
JKQTP_LIB_EXPORT JKQTPColorDerivationMode String2JKQTPColorDerivationMode ( const QString & mode ) ;
2015-07-11 18:56:02 +08:00
/** \brief display mode for an axis
* \ ingroup jkqtptools */
2019-01-20 17:49:29 +08:00
enum JKQTPCADrawMode {
2015-07-11 18:56:02 +08:00
JKQTPCADMcomplete = 0 , /*!< \brief draw axis with ticks, ticklabels and axis label */
2019-02-08 00:24:46 +08:00
JKQTPCADMLineTicksTickLabels , /*!< \brief draw axis with ticks, line and tick labels */
JKQTPCADMLineTicks , /*!< \brief draw axis with ticks and line */
JKQTPCADMLine , /*!< \brief draw axis as thick line */
JKQTPCADMTicksTickLabelsAxisLabel , /*!< \brief draw axis with ticks, tick labels and axisLabel */
JKQTPCADMTicksTickLabels , /*!< \brief draw axis with ticks and tick labels */
JKQTPCADMTickLabelsAxisLabel , /*!< \brief draw axis tick labels and axisLabel */
JKQTPCADMTickLabels , /*!< \brief draw axis tick labels */
JKQTPCADMTicks , /*!< \brief draw axis with ticks */
2015-07-11 18:56:02 +08:00
JKQTPCADMnone /*!< \brief draw no axis */
} ;
2019-02-08 00:24:46 +08:00
/** \brief determines whether JKQTPCADrawMode has the line
2019-05-11 21:56:11 +08:00
* \ ingroup jkqtptools_string
2019-02-08 00:24:46 +08:00
*/
JKQTP_LIB_EXPORT bool JKQTPCADrawModeHasLine ( JKQTPCADrawMode pos ) ;
/** \brief determines whether JKQTPCADrawMode has ticks
2019-05-11 21:56:11 +08:00
* \ ingroup jkqtptools_string
2019-02-08 00:24:46 +08:00
*/
JKQTP_LIB_EXPORT bool JKQTPCADrawModeHasTicks ( JKQTPCADrawMode pos ) ;
/** \brief determines whether JKQTPCADrawMode has tick labels
2019-05-11 21:56:11 +08:00
* \ ingroup jkqtptools_string
2019-02-08 00:24:46 +08:00
*/
JKQTP_LIB_EXPORT bool JKQTPCADrawModeHasTickLabels ( JKQTPCADrawMode pos ) ;
/** \brief determines whether JKQTPCADrawMode has the axis label
2019-05-11 21:56:11 +08:00
* \ ingroup jkqtptools_string
2019-02-08 00:24:46 +08:00
*/
JKQTP_LIB_EXPORT bool JKQTPCADrawModeHasAxisLabel ( JKQTPCADrawMode pos ) ;
2019-01-20 17:49:29 +08:00
/** \brief converts a JKQTPCADrawMode variable into a human-readable string
2019-05-11 21:56:11 +08:00
* \ ingroup jkqtptools_string
2015-07-11 18:56:02 +08:00
*/
2019-02-03 21:04:48 +08:00
JKQTP_LIB_EXPORT QString JKQTPCADrawMode2String ( JKQTPCADrawMode pos ) ;
2015-07-11 18:56:02 +08:00
2019-01-20 17:49:29 +08:00
/** \brief converts a string into a JKQTPCADrawMode
2019-05-11 21:56:11 +08:00
* \ ingroup jkqtptools_string
2015-07-11 18:56:02 +08:00
*/
2019-02-03 21:04:48 +08:00
JKQTP_LIB_EXPORT JKQTPCADrawMode String2JKQTPCADrawMode ( const QString & pos ) ;
2015-07-11 18:56:02 +08:00
/** \brief display mode for the axis labels
* \ ingroup jkqtptools */
2019-01-20 17:49:29 +08:00
enum JKQTPCALabelType {
2019-01-27 03:12:54 +08:00
JKQTPCALTdefault , /*!< \brief simply print the numbers \image html JKQTPCALTdefault.png */
JKQTPCALTexponentCharacter , /*!< \brief print the numbers and show a unit character, i.e. \c 5<> for \f$ 5\cdot 10^{-6} \f$ , \cd 3k for \f$ 3\cdot 10^3 \f$ ... */
JKQTPCALTexponent , /*!< \brief show numbers in exponential for, e.g. \f$ 3\cdot 10^5 \f$ ... \image html JKQTPCALTexponent.png */
JKQTPCALTdate , /*!< \brief show numbers as dates \image html JKQTPCALTdate.png */
JKQTPCALTtime , /*!< \brief show numbers as times \image html JKQTPCALTtime.png*/
2015-07-11 18:56:02 +08:00
JKQTPCALTdatetime , /*!< \brief show numbers as times */
} ;
/** \brief mode of the axis ticks
* \ ingroup jkqtptools */
enum JKQTPLabelTickMode {
JKQTPLTMLinOrPower = 0 , /*!< \brief linear, or log, depending on whether the axis is log */
JKQTPLTMLin , /*!< \brief always linear (even for log-axes) */
JKQTPLTMPower , /*!< \brief powers (of the log-base) */
} ;
/** \brief converts a JKQTPLabelTickMode variable into a human-readable string
2019-05-11 21:56:11 +08:00
* \ ingroup jkqtptools_string
2015-07-11 18:56:02 +08:00
*/
2019-02-03 21:04:48 +08:00
JKQTP_LIB_EXPORT QString JKQTPLabelTickMode2String ( JKQTPLabelTickMode pos ) ;
2015-07-11 18:56:02 +08:00
/** \brief converts a string into a JKQTPLabelTickMode
2019-05-11 21:56:11 +08:00
* \ ingroup jkqtptools_string
2015-07-11 18:56:02 +08:00
*/
2019-02-03 21:04:48 +08:00
JKQTP_LIB_EXPORT JKQTPLabelTickMode String2JKQTPLabelTickMode ( const QString & pos ) ;
2015-07-11 18:56:02 +08:00
2019-01-20 17:49:29 +08:00
/** \brief converts a JKQTPCALabelType variable into a human-readable string
2019-05-11 21:56:11 +08:00
* \ ingroup jkqtptools_string
2015-07-11 18:56:02 +08:00
*/
2019-02-03 21:04:48 +08:00
JKQTP_LIB_EXPORT QString JKQTPCALabelType2String ( JKQTPCALabelType pos ) ;
2015-07-11 18:56:02 +08:00
2019-01-20 17:49:29 +08:00
/** \brief converts a string into a JKQTPCALabelType
2019-05-11 21:56:11 +08:00
* \ ingroup jkqtptools_string
2015-07-11 18:56:02 +08:00
*/
2019-02-03 21:04:48 +08:00
JKQTP_LIB_EXPORT JKQTPCALabelType String2JKQTPCALabelType ( const QString & pos ) ;
2015-07-11 18:56:02 +08:00
/** \brief position of the axis labels
* \ ingroup jkqtptools
*/
2019-01-20 17:49:29 +08:00
enum JKQTPLabelPosition {
JKQTPLabelMin = 0 , /*!< \brief the axis label is near the min value of the axis (left/bottom) */
2019-02-08 00:24:46 +08:00
JKQTPLabelMax , /*!< \brief the axis label is near the max value of the axis (right/top) */
JKQTPLabelCenter /*!< \brief the label is at the center of the axis */
2015-07-11 18:56:02 +08:00
} ;
2019-01-20 17:49:29 +08:00
/** \brief converts a JKQTPLabelPosition variable into a human-readable string
2019-05-11 21:56:11 +08:00
* \ ingroup jkqtptools_string
2015-07-11 18:56:02 +08:00
*/
2019-02-03 21:04:48 +08:00
JKQTP_LIB_EXPORT QString JKQTPLabelPosition2String ( JKQTPLabelPosition pos ) ;
2015-07-11 18:56:02 +08:00
2019-01-20 17:49:29 +08:00
/** \brief converts a string into a JKQTPLabelPosition
2019-05-11 21:56:11 +08:00
* \ ingroup jkqtptools_string
2015-07-11 18:56:02 +08:00
*/
2019-02-03 21:04:48 +08:00
JKQTP_LIB_EXPORT JKQTPLabelPosition String2JKQTPLabelPosition ( const QString & pos ) ;
2015-07-11 18:56:02 +08:00
/** \brief position of the key
* \ ingroup jkqtptools
*/
2019-01-20 17:49:29 +08:00
enum JKQTPKeyPosition {
JKQTPKeyOutsideTopRight = 0 , /*!< \brief the key is positioned on the right side of the graph */
JKQTPKeyOutsideTopLeft , /*!< \brief the key is positioned on the left side of the graph */
JKQTPKeyOutsideLeftTop , /*!< \brief the key is positioned above the graph */
JKQTPKeyOutsideLeftBottom , /*!< \brief the key is positioned below the graph */
JKQTPKeyOutsideRightBottom , /*!< \brief the key is positioned on the right side of the graph */
JKQTPKeyOutsideRightTop , /*!< \brief the key is positioned on the left side of the graph */
JKQTPKeyOutsideBottomLeft , /*!< \brief the key is positioned above the graph */
JKQTPKeyOutsideBottomRight , /*!< \brief the key is positioned below the graph */
JKQTPKeyInsideTopRight , /*!< \brief the key is positioned inside on the right side of the graph, but inside the graph*/
JKQTPKeyInsideTopLeft , /*!< \brief the key is positioned inside on the left side of the graph */
JKQTPKeyInsideBottomLeft , /*!< \brief the key is positioned inside on the upper bound of the graph */
JKQTPKeyInsideBottomRight /*!< \brief the key is positioned inside on the lower bound of the graph */
2015-07-11 18:56:02 +08:00
} ;
2019-01-20 17:49:29 +08:00
/** \brief converts a JKQTPLabelPosition variable into a human-readable string
2019-05-11 21:56:11 +08:00
* \ ingroup jkqjkqtptools_stringtptools
2015-07-11 18:56:02 +08:00
*/
2019-02-03 21:04:48 +08:00
JKQTP_LIB_EXPORT QString JKQTPKeyPosition2String ( JKQTPKeyPosition pos ) ;
2015-07-11 18:56:02 +08:00
2019-01-20 17:49:29 +08:00
/** \brief converts a string into a JKQTPLabelPosition
2019-05-11 21:56:11 +08:00
* \ ingroup jkqtptools_string
2015-07-11 18:56:02 +08:00
*/
2019-02-03 21:04:48 +08:00
JKQTP_LIB_EXPORT JKQTPKeyPosition String2JKQTPKeyPosition ( const QString & pos ) ;
2015-07-11 18:56:02 +08:00
/** \brief layout of the key
* \ ingroup jkqtptools
*/
2019-01-20 17:49:29 +08:00
enum JKQTPKeyLayout {
JKQTPKeyLayoutOneColumn , /*!< \brief the key consists of one column */
JKQTPKeyLayoutOneRow , /*!< \brief the key consists of one row */
JKQTPKeyLayoutMultiColumn , /*!< \brief the key consists of multiple columns */
2015-07-11 18:56:02 +08:00
} ;
2019-01-20 17:49:29 +08:00
/** \brief converts a JKQTPKeyLayout variable into a human-readable string
2019-05-11 21:56:11 +08:00
* \ ingroup jkqtptools_string
2015-07-11 18:56:02 +08:00
*/
2019-02-03 21:04:48 +08:00
JKQTP_LIB_EXPORT QString JKQTPKeyLayout2String ( JKQTPKeyLayout pos ) ;
2015-07-11 18:56:02 +08:00
2019-01-20 17:49:29 +08:00
/** \brief converts a String into a JKQTPKeyLayout
2019-05-11 21:56:11 +08:00
* \ ingroup jkqtptools_string
2015-07-11 18:56:02 +08:00
*/
2019-02-03 21:04:48 +08:00
JKQTP_LIB_EXPORT JKQTPKeyLayout String2JKQTPKeyLayout ( const QString & pos ) ;
2015-07-11 18:56:02 +08:00
/** \brief used to represent the position of other graphs in \ref jkqtplotter_base_saveprint
* \ ingroup jkqtptools
2019-01-20 17:49:29 +08:00
* \ internal
2015-07-11 18:56:02 +08:00
*/
2019-01-20 17:49:29 +08:00
struct JKQTPGridPrintingItem {
/** \brief logic x-position of a graph, relative to the current JKQtPlotter */
int x ;
/** \brief logic y-position of a graph, relative to the current JKQtPlotter */
int y ;
/** \brief JKQTBasePlotter */
JKQTBasePlotter * plotter ;
} ;
2015-07-11 18:56:02 +08:00
/** \brief plot styles for the error information
2019-01-13 01:53:16 +08:00
* \ ingroup jkqtptools
2015-07-11 18:56:02 +08:00
*/
2019-01-20 17:49:29 +08:00
enum JKQTPErrorPlotstyle {
2019-01-26 20:00:40 +08:00
JKQTPErrorEllipses = 10 , /*!< \brief an ellipse spanned by the errors \image html JKQTPErrorEllipses.png */
JKQTPErrorBoxes = 9 , /*!< \brief a box spanned by the errors \image html JKQTPErrorBoxes.png */
JKQTPErrorSimpleBarsPolygons = 8 , /*!< \brief simplified error barsand polygons for each data point \image html JKQTPErrorSimpleBarsPolygons.png */
JKQTPErrorSimpleBarsLines = 7 , /*!< \brief simplified error bars and line for each data point \image html JKQTPErrorSimpleBarsLines.png */
JKQTPErrorSimpleBars = 6 , /*!< \brief simplified error bars for each data point \image html JKQTPErrorSimpleBars.png */
JKQTPErrorLines = 5 , /*!< \brief a second and third graph line above and below the actual data which indicates the error value \image html JKQTPErrorLines.png */
JKQTPErrorBars = 4 , /*!< \brief error bars for each data point \image html JKQTPErrorBars.png */
JKQTPErrorPolygons = 3 , /*!< \brief line error lines, but with filled range in between \image html JKQTPErrorPolygons.png */
JKQTPErrorBarsLines = 2 , /*!< \brief error bars and lines for each data point \image html JKQTPErrorBarsLines.png */
JKQTPErrorBarsPolygons = 1 , /*!< \brief error bars and polygons for each data point \image html JKQTPErrorBarsPolygons.png */
JKQTPNoError = 0 /*!< \brief don't show error information \image html JKQTPNoError.png */
2015-07-11 18:56:02 +08:00
} ;
2019-01-20 17:49:29 +08:00
/** \brief converts a JKQTPErrorPlotstyle variable into a human-readable string
2019-05-11 21:56:11 +08:00
* \ ingroup jkqtptools_string
2015-07-11 18:56:02 +08:00
*/
2019-02-03 21:04:48 +08:00
JKQTP_LIB_EXPORT QString JKQTPErrorPlotstyle2String ( JKQTPErrorPlotstyle pos ) ;
2015-07-11 18:56:02 +08:00
2019-01-20 17:49:29 +08:00
/** \brief converts a String into a JKQTPErrorPlotstyle
2019-05-11 21:56:11 +08:00
* \ ingroup jkqtptools_string
2015-07-11 18:56:02 +08:00
*/
2019-02-03 21:04:48 +08:00
JKQTP_LIB_EXPORT JKQTPErrorPlotstyle String2JKQTPErrorPlotstyle ( const QString & pos ) ;
2015-07-11 18:56:02 +08:00
/** \brief plot styles for a graph
2019-01-13 01:53:16 +08:00
* \ ingroup jkqtptools
2015-07-11 18:56:02 +08:00
*/
2019-01-20 17:49:29 +08:00
enum JKQTPGraphPlotstyle {
2019-02-08 00:24:46 +08:00
JKQTPLines , /*!< \brief plot y=f(x), connect the datapoints by straight lines */
JKQTPFilledCurveX , /*!< \brief plot y=f(x), as filled curve (filled until the y=0/x-axis) */
JKQTPFilledCurveY , /*!< \brief plot x=f(y), as filled curve (filled until the x=0/y-axis) */
JKQTPPoints , /*!< \brief plot y=f(x), plot each datapoint with a symbol */
JKQTPLinesPoints , /*!< \brief plot y=f(x), plot each datapoint with a symbol and connect them by straight lines */
JKQTPImpulsesHorizontal , /*!< \brief plot y=f(x), plot each datapoint as a line from (x,0) to (x,f(x)) */
JKQTPImpulsesVertical , /*!< \brief plot x=f(y), plot each datapoint as a line from (0,f(x)) to (x,f(x)) */
JKQTPStepsX , /*!< \brief plot y=f(x), as a step curve */
JKQTPStepsY /*!< \brief plot x=f(y), as a step curve */
2015-07-11 18:56:02 +08:00
} ;
/** \brief symbols that can be used to plot a datapoint for a graph
2019-01-13 01:53:16 +08:00
* \ ingroup jkqtptools
2015-07-11 18:56:02 +08:00
*/
2019-01-20 17:49:29 +08:00
enum JKQTPGraphSymbols {
JKQTPNoSymbol = 0 , /*!< \brief plots no symbol at all (usefull together with error bars) */
2019-05-12 23:35:08 +08:00
JKQTPDot , /*!< \brief a small dot \image html symbols/symbol_dot.png */
JKQTPCross , /*!< \brief a X cross \image html symbols/symbol_cross.png */
JKQTPPlus , /*!< \brief a + cross \image html symbols/symbol_plus.png */
JKQTPCircle , /*!< \brief an unfilled circle \image html symbols/symbol_circle.png */
JKQTPFilledCircle , /*!< \brief a filled circle \image html symbols/symbol_filled_circle.png */
JKQTPRect , /*!< \brief an unfilled rectangle \image html symbols/symbol_rect.png */
JKQTPFilledRect , /*!< \brief a filled rectangle \image html symbols/symbol_filled_rect.png */
JKQTPTriangle , /*!< \brief an unfilled triangle (tip at top) \image html symbols/symbol_triangle.png */
JKQTPFilledTriangle , /*!< \brief a filled triangle (tip at top) \image html symbols/symbol_filled_triangle.png */
JKQTPDiamond , /*!< \brief an unfilled diamond \image html symbols/symbol_diamond.png */
JKQTPFilledDiamond , /*!< \brief a filled diamond \image html symbols/symbol_filled_diamond.png */
JKQTPstar , /*!< \brief an unfilled diamond \image html symbols/symbol_star.png */
JKQTPFilledStar , /*!< \brief a filled diamond \image html symbols/symbol_filled_star.png */
JKQTPPentagon , /*!< \brief an unfilled pentagon \image html symbols/symbol_pentagon.png */
JKQTPFilledPentagon , /*!< \brief a filled pentagon \image html symbols/symbol_filled_pentagon.png */
JKQTPAsterisc , /*!< \brief an asterisc star with 5 arms \image html symbols/symbol_asterisc.png */
JKQTPHourglass , /*!< \brief an hour glass symbol \image html symbols/symbol_hourglass.png */
JKQTPFilledHourglass , /*!< \brief a filled hour glass symbol \image html symbols/symbol_filled_hourglass.png */
JKQTPCurvedTriangle , /*!< \brief a curved triangle\image html symbols/symbol_tripod.png */
JKQTPFilledCurvedTriangle , /*!< \brief a filled curved triangle\image html symbols/symbol_filled_tripod.png */
JKQTPHexagon , /*!< \brief an unfilled hexagon \image html symbols/symbol_hexagon.png */
JKQTPFilledHexagon , /*!< \brief a filled hexagon \image html symbols/symbol_filled_hexagon.png */
JKQTPRectCross , /*!< \brief a square symbol with a cross inside \image html symbols/symbol_rect_cross.png */
JKQTPRectPlus , /*!< \brief a square symbol with a plus inside \image html symbols/symbol_rect_plus.png */
JKQTPRectTriangle , /*!< \brief a square symbol with a triangle inside \image html symbols/symbol_rect_triangle.png */
JKQTPRectDownTriangle , /*!< \brief a square symbol with a triangle (tip to the bottom) inside \image html symbols/symbol_rect_downtriangle.png */
JKQTPRectLeftTriangle , /*!< \brief a square symbol with a triangle (tip to the left) inside \image html symbols/symbol_rect_lefttriangle.png */
JKQTPRectRightTriangle , /*!< \brief a square symbol with a triangle (tip to the right) inside \image html symbols/symbol_rect_righttriangle.png */
JKQTPCircleCross , /*!< \brief a circle symbol with a cross inside \image html symbols/symbol_circle_cross.png */
JKQTPCirclePlus , /*!< \brief a circle symbol with a plus inside \image html symbols/symbol_circle_plus.png */
JKQTPCirclePeace , /*!< \brief a circled peace symbol \image html symbols/symbol_circle_peace.png */
JKQTPDiamondPlus , /*!< \brief a diamond symbol with a plus inside \image html symbols/symbol_diamond_plus.png */
JKQTPDiamondCross , /*!< \brief a diamond symbol with a cross inside \image html symbols/symbol_diamond_cross.png */
JKQTPTripod , /*!< \brief a tripod symbol \image html symbols/symbol_tripod.png */
JKQTPDownTripod , /*!< \brief a tripod symbol, pointing down \image html symbols/symbol_down_tripod.png */
JKQTPLeftTripod , /*!< \brief a tripod symbol, pointing to the left \image html symbols/symbol_left_tripod.png */
JKQTPRightTripod , /*!< \brief a tripod symbol, pointing to the right \image html symbols/symbol_right_tripod.png */
JKQTPAsterisc6 , /*!< \brief an asterisc star with 6 arms \image html symbols/symbol_asterisc6.png */
JKQTPAsterisc8 , /*!< \brief an asterisc star with 8 arms \image html symbols/symbol_asterisc8.png */
JKQTPPeace , /*!< \brief a peace symbol \image html symbols/symbol_peace.png */
JKQTPTarget , /*!< \brief a target symbol (circle with cross) \image html symbols/symbol_target.png */
JKQTPDownTriangle , /*!< \brief an unfilled triangle (tip at bottom) \image html symbols/symbol_down_triangle.png */
JKQTPFilledDownTriangle , /*!< \brief a filled triangle (tip at bottom) \image html symbols/symbol_filled_down_triangle.png */
JKQTPLeftTriangle , /*!< \brief an unfilled triangle (tip to the left) \image html symbols/symbol_left_triangle.png */
JKQTPFilledLeftTriangle , /*!< \brief a filled triangle (tip to the left) \image html symbols/symbol_filled_left_triangle.png */
JKQTPRightTriangle , /*!< \brief an unfilled triangle (tip to the right) \image html symbols/symbol_right_triangle.png */
JKQTPFilledRightTriangle , /*!< \brief a filled triangle (tip to the right) \image html symbols/symbol_filled_right_triangle.png */
JKQTPDownCurvedTriangle , /*!< \brief a curved triangle, pointing down \image html symbols/symbol_down_tripod.png */
JKQTPFilledDownCurvedTriangle , /*!< \brief a filled curved triangle, pointing down \image html symbols/symbol_filled_down_tripod.png */
JKQTPLeftCurvedTriangle , /*!< \brief a curved triangle, pointing to the left \image html symbols/symbol_left_tripod.png */
JKQTPFilledLeftCurvedTriangle , /*!< \brief a filled curved triangle, pointing to the left \image html symbols/symbol_filled_left_tripod.png */
JKQTPRightCurvedTriangle , /*!< \brief a curved triangle, pointing to the right \image html symbols/symbol_right_tripod.png */
JKQTPFilledRightCurvedTriangle , /*!< \brief a filled curved triangle, pointing to the right \image html symbols/symbol_filled_right_tripod.png */
JKQTPOctagon , /*!< \brief an unfilled octagon \image html symbols/symbol_octagon.png */
JKQTPFilledOctagon , /*!< \brief a filled octagon \image html symbols/symbol_filled_octagon.png */
JKQTPUpDownTriangle , /*!< \brief a overlay of an up and a down triangle symbol \image html symbols/symbol_updowntriangle.png */
JKQTPFilledUpDownTriangle , /*!< \brief a filled version of the overlay of an up and a down triangle \image html symbols/symbol_filled_updowntriangle.png */
JKQTPHorizontalHourglass , /*!< \brief a horizontal hour glass symbol \image html symbols/symbol_horizontal_hourglass.png */
JKQTPFilledHorizontalHourglass , /*!< \brief a filled horizontal hour glass symbol \image html symbols/symbol_filled_horizontal_hourglass.png */
JKQTPSantaClauseHouse , /*!< \brief a small house symbol ("Das is das haus vom Nicolaus") \image html symbols/symbol_santaclause.png */
JKQTPFilledSantaClauseHouse , /*!< \brief a filled small house symbol ("Das is das haus vom Nicolaus") \image html symbols/symbol_filled_santaclause.png */
JKQTPMale , /*!< \brief a male symbol \image html symbols/symbol_male.png */
JKQTPFemale , /*!< \brief a female symbol \image html symbols/symbol_female.png */
JKQTPSymbolCount , /*!< \brief can be used to iterate over all symbols using: <code>for (int i=0; i<static_cast<int>(JKQTPSymbolCount); i++) { JKQTPGraphSymbols s=static_cast<JKQTPGraphSymbols>(i); ... }</code> */
JKQTPMaxSymbolID = JKQTPSymbolCount - 1 , /*!< \brief points to the last available symbol, can be used to iterate over all symbols: <code>for (int i=0; i<=static_cast<int>(JKQTPMaxSymbolID); i++) { JKQTPGraphSymbols s=static_cast<JKQTPGraphSymbols>(i); ... }</code> */
JKQTPDefaultSymbol = JKQTPCross , /*!< \brief a default symbol used for plotting */
2015-07-11 18:56:02 +08:00
} ;
2019-01-20 17:49:29 +08:00
/** \brief converts a JKQTPGraphSymbols variable into a identifier string
2019-05-11 21:56:11 +08:00
* \ ingroup jkqtptools_string
2015-07-11 18:56:02 +08:00
*/
2019-02-03 21:04:48 +08:00
JKQTP_LIB_EXPORT QString JKQTPGraphSymbols2String ( JKQTPGraphSymbols pos ) ;
2019-01-20 17:49:29 +08:00
/** \brief converts a JKQTPGraphSymbols variable into a human-readable string
2019-05-11 21:56:11 +08:00
* \ ingroup jkqtptools_string
2015-07-11 18:56:02 +08:00
*/
2019-02-03 21:04:48 +08:00
JKQTP_LIB_EXPORT QString JKQTPGraphSymbols2NameString ( JKQTPGraphSymbols pos ) ;
2015-07-11 18:56:02 +08:00
2019-01-20 17:49:29 +08:00
/** \brief converts a String into a JKQTPGraphSymbols
2019-05-11 21:56:11 +08:00
* \ ingroup jkqtptools_string
2015-07-11 18:56:02 +08:00
*/
2019-02-03 21:04:48 +08:00
JKQTP_LIB_EXPORT JKQTPGraphSymbols String2JKQTPGraphSymbols ( const QString & pos ) ;
2015-07-11 18:56:02 +08:00
2019-01-10 04:23:24 +08:00
/** \brief convert a double to a string, using the loacle "C"
2019-05-11 21:56:11 +08:00
* \ ingroup jkqtptools_string
2019-01-10 04:23:24 +08:00
*/
2015-07-11 18:56:02 +08:00
inline QString JKQTPCDoubleToQString ( double value ) {
QLocale loc = QLocale : : c ( ) ;
loc . setNumberOptions ( QLocale : : OmitGroupSeparator ) ;
return loc . toString ( value , ' g ' , 18 ) ;
}
2019-01-10 04:23:24 +08:00
/** \brief convert a double to a string
2019-05-11 21:56:11 +08:00
* \ ingroup jkqtptools_string
2019-01-10 04:23:24 +08:00
*/
2015-07-11 18:56:02 +08:00
inline QString JKQTPDoubleToQString ( double value , int prec = 10 , char f = ' g ' , QChar decimalSeparator = ' . ' ) {
QLocale loc = QLocale : : c ( ) ;
loc . setNumberOptions ( QLocale : : OmitGroupSeparator ) ;
QString res = loc . toString ( value , f , prec ) ;
if ( loc . decimalPoint ( ) ! = decimalSeparator ) {
res = res . replace ( loc . decimalPoint ( ) , decimalSeparator ) ;
}
return res ;
}
2019-01-10 04:23:24 +08:00
/** \brief rotate a rectangle by given angle (rotates all points around the center of the rectangle and returns it as a QPolygonF)
2019-05-11 21:56:11 +08:00
* \ ingroup jkqtptools_math
2019-01-10 04:23:24 +08:00
*/
2019-02-03 21:04:48 +08:00
JKQTP_LIB_EXPORT QPolygonF jkqtpRotateRect ( QRectF r , double angle ) ;
2015-07-11 18:56:02 +08:00
/*! \brief swap two elements \a l and \a r in an array \a a
\ ingroup jkqtptools
*/
template < class T >
2018-12-16 21:59:39 +08:00
inline void jkqtpSwap ( T * a , int l , int r ) {
2015-07-11 18:56:02 +08:00
const T tmp = a [ l ] ;
a [ l ] = a [ r ] ;
a [ r ] = tmp ;
}
/*! \brief QuickSort (recursive implementation)
\ ingroup jkqtptools
implementation from http : //www.linux-related.de/index.html?/coding/sort/sort_quick.htm
*/
template < class T >
2018-12-16 21:59:39 +08:00
inline void jkqtpQuicksort ( T * a , int l , int r ) {
2015-07-11 18:56:02 +08:00
if ( r > l ) {
2018-12-16 21:59:39 +08:00
int i = l - 1 ;
int j = r ;
2015-07-11 18:56:02 +08:00
for ( ; ; ) {
while ( a [ + + i ] < a [ r ] ) ;
while ( a [ - - j ] > a [ r ] & & j > i ) ;
if ( i > = j ) break ;
jkqtpSwap < T > ( a , i , j ) ;
}
jkqtpSwap < T > ( a , i , r ) ;
jkqtpQuicksort ( a , l , i - 1 ) ;
jkqtpQuicksort ( a , i + 1 , r ) ;
}
}
/*! \brief QuickSort (recursive implementation), sorts \a a2 alongside \a a, using \a a as sort criterion
\ ingroup jkqtptools
implementation from http : //www.linux-related.de/index.html?/coding/sort/sort_quick.htm
*/
template < class T , class T2 >
2018-12-16 21:59:39 +08:00
inline void jkqtpQuicksort ( T * a , T2 * a2 , int l , int r ) {
2015-07-11 18:56:02 +08:00
if ( r > l ) {
2018-12-16 21:59:39 +08:00
int i = l - 1 ;
int j = r ;
2015-07-11 18:56:02 +08:00
for ( ; ; ) {
while ( a [ + + i ] < a [ r ] ) ;
while ( a [ - - j ] > a [ r ] & & j > i ) ;
if ( i > = j ) break ;
jkqtpSwap ( a , i , j ) ;
jkqtpSwap ( a2 , i , j ) ;
}
jkqtpSwap ( a , i , r ) ;
jkqtpSwap ( a2 , i , r ) ;
jkqtpQuicksort ( a , a2 , l , i - 1 ) ;
jkqtpQuicksort ( a , a2 , i + 1 , r ) ;
}
}
/*! \brief sort the given arrays, using \a input as sort criterion
\ ingroup jkqtptools
\ param input array to be sorted
\ param input2 array to be sorted
\ param N size of the array input
2018-11-18 18:59:30 +08:00
\ param output if \ c ! = nullptr data is written here ( the memory location pointed at by \ a output has to have at least the length \ a N ! ! ! ) ,
2015-07-11 18:56:02 +08:00
otherwise the array input is sorted inplace .
2018-11-18 18:59:30 +08:00
\ param output2 if \ c ! = nullptr data is written here ( the memory location pointed at by \ a output has to have at least the length \ a N ! ! ! ) ,
2015-07-11 18:56:02 +08:00
otherwise the array input is sorted inplace .
*/
template < class T , class T2 >
2018-12-16 21:59:39 +08:00
inline void jkqtpSort ( T * input , T2 * input2 , int N , T * output = nullptr , T2 * output2 = nullptr ) {
2015-07-11 18:56:02 +08:00
if ( ( ! input ) ) return ;
if ( N < = 0 ) return ;
T * data = input ;
2018-11-18 18:59:30 +08:00
if ( output ! = nullptr ) {
2015-07-11 18:56:02 +08:00
data = output ;
memcpy ( output , input , N * sizeof ( T ) ) ;
}
T2 * data2 = input2 ;
2018-11-18 18:59:30 +08:00
if ( output2 ! = nullptr & & input2 ! = nullptr ) {
2015-07-11 18:56:02 +08:00
data2 = output2 ;
memcpy ( output2 , input2 , N * sizeof ( T2 ) ) ;
}
jkqtpQuicksort ( data , data2 , 0 , N - 1 ) ;
}
2019-01-10 04:23:24 +08:00
/** \brief RAII construct that times its lifetime, outputting properly indented qDebug()-message
2019-01-13 01:53:16 +08:00
* \ ingroup jkqtptools_debugging
2019-01-10 04:23:24 +08:00
*/
2019-02-03 21:04:48 +08:00
class JKQTP_LIB_EXPORT JKQTPAutoOutputTimer : public QElapsedTimer
2015-07-11 18:56:02 +08:00
{
public :
explicit JKQTPAutoOutputTimer ( const QString & message ) ;
~ JKQTPAutoOutputTimer ( ) ;
void write ( const QString & message ) const ;
protected :
QString message ;
QString indent ;
static int global_indent ;
} ;
2019-01-10 04:23:24 +08:00
/** \brief convert a string to lower-case characters
2019-01-13 01:53:16 +08:00
* \ ingroup jkqtptools_string
2019-01-10 04:23:24 +08:00
*/
2019-02-03 21:04:48 +08:00
JKQTP_LIB_EXPORT std : : string jkqtp_tolower ( const std : : string & s ) ;
2015-07-11 18:56:02 +08:00
2019-01-10 04:23:24 +08:00
/** \brief convert a string to a boolean
2019-01-13 01:53:16 +08:00
* \ ingroup jkqtptools_string
2019-01-10 04:23:24 +08:00
*/
2019-02-03 21:04:48 +08:00
JKQTP_LIB_EXPORT bool jkqtp_strtobool ( const std : : string & data ) ;
2019-01-10 04:23:24 +08:00
/** \brief convert a string to upper-case
2019-01-13 01:53:16 +08:00
* \ ingroup jkqtptools_string
2019-01-10 04:23:24 +08:00
*/
2019-02-03 21:04:48 +08:00
JKQTP_LIB_EXPORT std : : string jkqtp_toupper ( const std : : string & s ) ;
2015-07-11 18:56:02 +08:00
2019-01-10 04:23:24 +08:00
/** \brief std::string wrapper around sprintf()
2019-01-13 01:53:16 +08:00
* \ ingroup jkqtptools_string
2019-01-10 04:23:24 +08:00
*/
2019-02-03 21:04:48 +08:00
JKQTP_LIB_EXPORT std : : string jkqtp_format ( const std : : string & templ , . . . ) ;
2015-07-11 18:56:02 +08:00
2019-01-10 04:23:24 +08:00
/** \brief convert a number of bytes to a string, formatting e.g. 1024 as 1kB, ...
2019-01-13 01:53:16 +08:00
* \ ingroup jkqtptools_string
2019-01-10 04:23:24 +08:00
*/
2019-02-03 21:04:48 +08:00
JKQTP_LIB_EXPORT std : : string jkqtp_bytestostr ( double bytes ) ;
2015-07-11 18:56:02 +08:00
2019-01-10 04:23:24 +08:00
/** \brief convert an integer to a string
2019-01-13 01:53:16 +08:00
* \ ingroup jkqtptools_string
2019-01-10 04:23:24 +08:00
*/
2019-02-03 21:04:48 +08:00
JKQTP_LIB_EXPORT std : : string jkqtp_inttostr ( long data ) ;
2015-07-11 18:56:02 +08:00
2019-01-10 04:23:24 +08:00
/** \brief convert an integer to a hex string
2019-01-13 01:53:16 +08:00
* \ ingroup jkqtptools_string
2019-01-10 04:23:24 +08:00
*/
2019-02-03 21:04:48 +08:00
JKQTP_LIB_EXPORT std : : string jkqtp_inttohex ( long data ) ;
2015-07-11 18:56:02 +08:00
2019-01-10 04:23:24 +08:00
/** \brief convert an unsigned int to a string
2019-01-13 01:53:16 +08:00
* \ ingroup jkqtptools_string
2019-01-10 04:23:24 +08:00
*/
2019-02-03 21:04:48 +08:00
JKQTP_LIB_EXPORT std : : string jkqtp_uinttostr ( unsigned long data ) ;
2015-07-11 18:56:02 +08:00
2019-01-10 04:23:24 +08:00
/** \brief convert a double to a string
2019-01-13 01:53:16 +08:00
* \ ingroup jkqtptools_string
2019-01-10 04:23:24 +08:00
*/
2019-02-03 21:04:48 +08:00
JKQTP_LIB_EXPORT std : : string jkqtp_floattostr ( double data , int past_comma = - 1 , bool remove_trail0 = false , double belowIsZero = 1e-16 ) ;
2015-07-11 18:56:02 +08:00
2019-01-10 04:23:24 +08:00
/** \brief convert a double to a string, encoding powers of ten as characters, e.g. \c jkqtp_floattounitstr(1000,"g") will result in "1kg"
2019-01-13 01:53:16 +08:00
* \ ingroup jkqtptools_string
2019-01-10 04:23:24 +08:00
*/
2019-02-03 21:04:48 +08:00
JKQTP_LIB_EXPORT std : : string jkqtp_floattounitstr ( double dataa , const std : : string & unitname ) ;
2019-01-10 04:23:24 +08:00
/** \brief convert a boolean to a string
2019-01-13 01:53:16 +08:00
* \ ingroup jkqtptools_string
2019-01-10 04:23:24 +08:00
*/
2019-02-03 21:04:48 +08:00
JKQTP_LIB_EXPORT std : : string jkqtp_booltostr ( bool data ) ;
2019-01-10 04:23:24 +08:00
/** \brief converts a RGBA color into a string
2019-01-13 01:53:16 +08:00
* \ ingroup jkqtptools_string
2019-01-10 04:23:24 +08:00
*
* This returns a QString which contains the name of named colors and the RGBA values in a QT readable form othertwise .
2019-02-08 00:24:46 +08:00
*
* \ param r red value of the color to convert
* \ param g green value of the color to convert
* \ param b blue value of the color to convert
* \ param a alpha value of the color to convert
* \ param useSpecialTransparencySyntax is set ( \ c true ) , the function uses a special syntax to denote color and transparency : \ c color , trans
2019-01-10 04:23:24 +08:00
*/
2019-02-08 00:24:46 +08:00
JKQTP_LIB_EXPORT QString jkqtp_rgbtostring ( unsigned char r , unsigned char g , unsigned char b , unsigned char a = 255 , bool useSpecialTransparencySyntax = true ) ;
2019-01-10 04:23:24 +08:00
/** \brief converts a QColor into a string using the jkqtp_rgbtostring() method.
2019-01-13 01:53:16 +08:00
* \ ingroup jkqtptools_string
2019-01-10 04:23:24 +08:00
*
* This returns a QString which contains the name of named colors and the RGBA values in a QT readable form othertwise .
*/
2019-02-08 00:24:46 +08:00
JKQTP_LIB_EXPORT QString jkqtp_QColor2String ( QColor color , bool useSpecialTransparencySyntax = true ) ;
/** \brief converts a QString into a QColor, compatible with jkqtp_QColor2String(QColor color);
* \ ingroup jkqtptools_string
*
* This returns a QString which contains the name of named colors and the RGBA values in a QT readable form othertwise .
*/
JKQTP_LIB_EXPORT QColor jkqtp_String2QColor ( const QString & color ) ;
2019-01-10 04:23:24 +08:00
/** \brief clean a string to be usable as a variable name, e.g. in an expression parser, or a C++-expression
2019-01-13 01:53:16 +08:00
* \ ingroup jkqtptools_string
2019-01-10 04:23:24 +08:00
*/
2019-02-03 21:04:48 +08:00
JKQTP_LIB_EXPORT std : : string jkqtp_to_valid_variable_name ( const std : : string & input ) ;
2015-07-11 18:56:02 +08:00
2019-01-10 04:23:24 +08:00
/** \brief convert a double to a string, encoding powers of ten as characters, e.g. \c jkqtp_floattounitstr(1000) will result in "1k"
2019-01-13 01:53:16 +08:00
* \ ingroup jkqtptools_string
2019-01-10 04:23:24 +08:00
*/
2019-02-03 21:04:48 +08:00
JKQTP_LIB_EXPORT std : : string jkqtp_floattounitstr ( double data , int past_comma = 5 , bool remove_trail0 = false ) ;
2019-01-13 01:53:16 +08:00
/** \brief convert a double to a string, encoding powers of ten as exponent in LaTeX notation (e.g. <code>-1.23\cdot 10^{-5}</code>)
* \ ingroup jkqtptools_string
2019-01-10 04:23:24 +08:00
*/
2019-02-03 21:04:48 +08:00
JKQTP_LIB_EXPORT std : : string jkqtp_floattolatexstr ( double data , int past_comma = 5 , bool remove_trail0 = false , double belowIsZero = 1e-16 , double minNoExponent = 1e-3 , double maxNoExponent = 1e4 ) ;
2019-01-10 04:23:24 +08:00
/** \brief convert a double to a string, encoding powers of ten as exponent with HTML tags
2019-01-13 01:53:16 +08:00
* \ ingroup jkqtptools_string
2019-01-10 04:23:24 +08:00
*/
2019-02-03 21:04:48 +08:00
JKQTP_LIB_EXPORT std : : string jkqtp_floattohtmlstr ( double data , int past_comma = 5 , bool remove_trail0 = false , double belowIsZero = 1e-16 , double minNoExponent = 1e-3 , double maxNoExponent = 1e4 ) ;
2019-01-10 04:23:24 +08:00
/** \brief convert a character to a string
2019-01-13 01:53:16 +08:00
* \ ingroup jkqtptools_string
2019-01-10 04:23:24 +08:00
*/
2019-02-03 21:04:48 +08:00
JKQTP_LIB_EXPORT std : : string jkqtp_chartostr ( char data ) ;
2018-11-18 18:59:30 +08:00
/** \brief wandelt einen Datentyp in einen double um, wird von JKQTPDatastore zur Wandlung benutzt
2019-05-11 21:56:11 +08:00
* \ ingroup jkqtptools_math
2018-11-18 18:59:30 +08:00
*
* Diese Funktion nutzt per default static_cast < double > ( ) , kann aber f <EFBFBD> r spezielle Datentypen <EFBFBD> berschrieben werden , etwa f <EFBFBD> r bool
*/
template < typename T >
inline constexpr double jkqtp_todouble ( const T & d ) {
return static_cast < double > ( d ) ;
}
/** \brief wandelt einen boolean in einen double um, wird von JKQTPDatastore zur Wandlung benutzt,
2019-01-13 01:53:16 +08:00
* Spezialisierung f <EFBFBD> r bool ( true - > 1.0 , false - > 0.0 )
2019-05-11 21:56:11 +08:00
* \ ingroup jkqtptools_math */
2018-11-18 18:59:30 +08:00
template < >
inline constexpr double jkqtp_todouble ( const bool & d ) {
return static_cast < double > ( ( d ) ? 1.0 : 0.0 ) ;
}
2018-12-07 04:41:35 +08:00
/** \brief plot styles for the error information
2019-01-13 01:53:16 +08:00
* \ ingroup jkqtptools
2019-01-26 20:00:40 +08:00
*
2019-04-22 19:27:50 +08:00
* \ see JKQTPSpecialLineTypeComboBox
2018-12-07 04:41:35 +08:00
*/
2019-04-22 19:27:50 +08:00
enum JKQTPSpecialLineType {
2019-01-26 20:00:40 +08:00
JKQTPStepLeft = 0 , /*!< \brief datapoint is on the left edge of the hor. step line \image html JKQTPStepLeft.png */
JKQTPStepCenter = 1 , /*!< \brief datapoint is centered on the hor. step line \image html JKQTPStepCenter.png */
JKQTPStepRight = 2 , /*!< \brief datapoint is on the right edge of the hor. step line \image html JKQTPStepRight.png */
2019-04-22 19:27:50 +08:00
JKQTPStepAverage = 3 , /*!< \brief horizontal line on the level of the average between two points + vertical lines to the points \image html JKQTPStepAverage.png */
JKQTPDirectLine = 4 , /*!< \brief no step, but connects the two datapoints with a straight line \image html JKQTPDirectLine.png */
2018-12-07 04:41:35 +08:00
} ;
2019-04-22 19:27:50 +08:00
/** \brief converts a JKQTPSpecialLineType variable into a human-readable string
2018-12-07 04:41:35 +08:00
* \ ingroup jkqtptools
*/
2019-04-22 19:27:50 +08:00
JKQTP_LIB_EXPORT QString JKQTPSpecialLineType2String ( JKQTPSpecialLineType pos ) ;
2018-12-07 04:41:35 +08:00
2019-04-22 19:27:50 +08:00
/** \brief converts a String into a JKQTPSpecialLineType
2018-12-07 04:41:35 +08:00
* \ ingroup jkqtptools
*/
2019-04-22 19:27:50 +08:00
JKQTP_LIB_EXPORT JKQTPSpecialLineType String2JKQTPSpecialLineType ( const QString & pos ) ;
2019-05-11 21:56:11 +08:00
/** \brief round a double using round() and convert it to a specified type T (static_cast!)
* \ ingroup jkqtptools_math */
2019-04-22 19:27:50 +08:00
template < typename T >
inline T jkqtp_roundTo ( const double & v ) {
return static_cast < T > ( round ( v ) ) ;
}
2018-12-07 04:41:35 +08:00
2019-05-06 01:31:20 +08:00
2019-05-11 21:56:11 +08:00
/** \brief compare two floats \a a and \a b for euqality, where any difference smaller than \a epsilon is seen as equality
* \ ingroup jkqtptools_math */
2019-05-06 01:31:20 +08:00
inline bool jkqtp_approximatelyEqual ( float a , float b , float epsilon = 2.0 * std : : numeric_limits < float > : : epsilon ( ) )
{
return fabsf ( a - b ) < = epsilon ;
}
2019-05-11 21:56:11 +08:00
/** \brief compare two doubles \a a and \a b for euqality, where any difference smaller than \a epsilon is seen as equality
* \ ingroup jkqtptools_math */
2019-05-06 01:31:20 +08:00
inline bool jkqtp_approximatelyEqual ( double a , double b , double epsilon = 2.0 * std : : numeric_limits < double > : : epsilon ( ) )
{
return fabs ( a - b ) < = epsilon ;
}
2019-05-11 21:56:11 +08:00
/** \brief returns the quare of the value \a v, i.e. \c v*v
* \ ingroup jkqtptools_math */
2019-05-06 01:31:20 +08:00
template < typename T >
inline T jkqtp_sqr ( const T & v ) {
return v * v ;
}
2015-07-11 18:56:02 +08:00
# endif // JKQTPTOOLS_H_INCLUDED