added new JKQTPCALabelType element JKQTPCALTformat for general formatting with a std::format-format string (available for C++>=20 only!!!)

This commit is contained in:
jkriege2 2022-09-28 00:59:57 +02:00
parent c1b7f678c7
commit ce3f25e044
11 changed files with 103 additions and 7 deletions

View File

@ -25,6 +25,9 @@ endif()
if(NOT DEFINED JKQtPlotter_BUILD_WITH_PRECOMPILED_HEADERS)
option(JKQtPlotter_BUILD_WITH_PRECOMPILED_HEADERS "Build the library using precompiled headers to improve compile speed" ON)
endif()
if(NOT DEFINED JKQtPlotter_ENABLED_CXX20)
option(JKQtPlotter_ENABLED_CXX20 "Build the library using C++20" OFF)
endif()
if(NOT DEFINED CMAKE_INSTALL_PREFIX)
option(CMAKE_INSTALL_PREFIX "Install directory" ${CMAKE_CURRENT_SOURCE_DIR}/install)
endif()

View File

@ -43,4 +43,10 @@ else()
set(JKQtPlotter_QT_CXX_COMPILE_FEATURE cxx_std_17)
endif()
set(JKQtPlotter_QT_BINDIR $<TARGET_FILE_DIR:Qt${QT_VERSION_MAJOR}::qmake>) # ${QT_DIR}../../../../bin
if (JKQtPlotter_ENABLED_CXX20)
set(JKQtPlotter_QT_CXX_STANDARD 20)
set(JKQtPlotter_QT_CXX_STANDARD_REQUIRED TRUE)
set(JKQtPlotter_QT_CXX_COMPILE_FEATURE cxx_std_20)
endif(JKQtPlotter_ENABLED_CXX20)
set(JKQtPlotter_QT_BINDIR $<TARGET_FILE_DIR:Qt${QT_VERSION_MAJOR}::qmake>) # ${QT_DIR}../../../../bin

View File

@ -54,7 +54,9 @@ The CMake build system offers several configuration variables that you may set/c
- \c JKQtPlotter_BUILD_FORCE_NO_PRINTER_SUPPORT : switches off print-support (when set to \c ON ), even if the current platform supports it (default: \c OFF )
- \c JKQtPlotter_BUILD_DECORATE_LIBNAMES_WITH_BUILDTYPE : If set, the build-type is appended to the library name (default: \c ON )
- \c JKQtPlotter_BUILD_WITH_PRECOMPILED_HEADERS : If set, the build uses precompiled headers to speed up (a bit) (default: \c ON )
- \c JKQtPlotter_ENABLED_CXX20 : Build using C++20 (requires a compiler that supports this! (default: \c OFF )
- \c JKQtPlotter_BUILD_EXAMPLES : Build examples (default: \c ON )
- \c JKQtPlotter_BUILD_TOOLS : Build tools (default: \c ON )
- \c CMAKE_INSTALL_PREFIX : Install directory for the library
.

View File

@ -56,7 +56,8 @@ Changes, compared to \ref page_whatsnew_V4_0_0 "v4.0.0" include:
<li>NEW: Added signals JKQTBasePlotter::beforeExporting()/JKQTBasePlotter::afterExporting() and JKQTBasePlotterJKQTBasePlotter:beforePrinting()/JKQTBasePlotter::afterPrinting() which allow to modify the plot just before and just after an export/print</li>
<li>NEW: Added new JKQTPCALabelType elements (JKQTPCALTfrac...), so axis label ticks can be displayed as fractions 1/2 instead of 0.5<br>
JKQTPCALTscientific, so axis label ticks can be displayed as numbers in scientific notation like \c 1.2E-34<br>
JKQTPCALTprintf for general formatting with a printf-format string </li>
JKQTPCALTprintf for general formatting with a printf-format string <br>
JKQTPCALTformat for general formatting with a std::format-format string (available for C++>=20 only!!!)</li>
<li>NEW: all elements of a coordinate axis may have their own color now </li>
<li>NEW: added possibility to scale the axis ticks by a factor (e.g. pi) to generate axes with ticks <tt>0pi, 1pi, 2pi ...</tt> </li>
<li>NEW: added option to draw a zero axis to JKQTPCoordinateAxis, which draws an axis at the origin of the coordinate system </li>

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.1 KiB

View File

@ -26,6 +26,12 @@
#include <QDateTime>
#include <cfloat>
#include <QApplication>
#if __cplusplus >= 202002L
# include <version>
# ifdef __cpp_lib_format
# include <format>
# endif
#endif
//#undef SHOW_JKQTPLOTTER_DEBUG
@ -494,6 +500,15 @@ QString JKQTPCoordinateAxis::floattolabel(double data, int past_comma) const {
case JKQTPCALTprintf: {
return QString::asprintf(axisStyle.tickPrintfFormat.toLatin1().data(), data, tickUnitName.toStdString().c_str());
}; break;
#if __cplusplus >= 202002L
# ifdef __cpp_lib_format
case JKQTPCALTformat: {
return QString::fromStdString(std::vformat(axisStyle.tickFormatFormat.toStdString(), std::make_format_args(data, tickUnitName.toStdString())));
}; break;
/** \copydoc JKQTPCoordinateAxisStyle::tickFormatFormat */
void setTickFormatFormat(const QString& __value);
# endif
#endif
}
return QString();
}
@ -864,6 +879,19 @@ void JKQTPCoordinateAxis::setTickPrintfFormat(const QString& __value) {
this->paramsChanged=true;
redrawPlot();
}
#if __cplusplus >= 202002L
# ifdef __cpp_lib_format
void JKQTPCoordinateAxis::setTickFormatFormat(const QString &__value)
{
this->axisStyle.tickFormatFormat = __value;
this->paramsChanged=true;
redrawPlot();
}
# endif
#endif
void JKQTPCoordinateAxis::setTickLabelFontSize(double __value) {
this->axisStyle.tickLabelFontSize = __value;

View File

@ -329,6 +329,12 @@ class JKQTPLOTTER_LIB_EXPORT JKQTPCoordinateAxis: public QObject {
inline QString getTickPrintfFormat() const { return this->axisStyle.tickPrintfFormat; }
/** \copydoc JKQTPCoordinateAxisStyle::tickMode */
inline JKQTPLabelTickMode getTickMode() const { return this->axisStyle.tickMode; }
#if __cplusplus >= 202002L
# ifdef __cpp_lib_format
/** \copydoc JKQTPCoordinateAxisStyle::tickFormatFormat */
inline QString getTickFormatfFormat() const { return this->axisStyle.tickFormatFormat; }
# endif
#endif
/** \copydoc JKQTPCoordinateAxisStyle::drawMode0 */
inline JKQTPCADrawMode getDrawMode0() const { return this->axisStyle.drawMode0; }
@ -527,7 +533,12 @@ class JKQTPLOTTER_LIB_EXPORT JKQTPCoordinateAxis: public QObject {
/** \copydoc JKQTPCoordinateAxisStyle::tickPrintfFormat */
void setTickPrintfFormat(const QString& __value);
#if __cplusplus >= 202002L
# ifdef __cpp_lib_format
/** \copydoc JKQTPCoordinateAxisStyle::tickFormatFormat */
void setTickFormatFormat(const QString& __value);
# endif
#endif
/** \copydoc JKQTPCoordinateAxisStyle::tickLabelFontSize */
void setTickLabelFontSize (double __value);

View File

@ -57,7 +57,12 @@ JKQTPCoordinateAxisStyle::JKQTPCoordinateAxisStyle():
tickTimeFormat(QLocale().timeFormat(QLocale::NarrowFormat)),
tickDateFormat(QLocale().dateFormat(QLocale::NarrowFormat)),
tickDateTimeFormat(QLocale().dateTimeFormat(QLocale::NarrowFormat)),
tickPrintfFormat("%f"),
tickPrintfFormat("%f %s"),
#if __cplusplus >= 202002L
# ifdef __cpp_lib_format
tickFormatFormat("{}{}"),
# endif
#endif
minTicks(5),
minorTicks(1),
tickOutsideLength(3),
@ -104,6 +109,11 @@ void JKQTPCoordinateAxisStyle::loadSettings(const QSettings &settings, const QSt
tickDateFormat = settings.value(group+"ticks/date_format", defaultStyle.tickDateFormat).toString();
tickDateTimeFormat = settings.value(group+"ticks/datetime_format", defaultStyle.tickDateTimeFormat).toString();
tickPrintfFormat = settings.value(group+"ticks/printf_format", defaultStyle.tickPrintfFormat).toString();
#if __cplusplus >= 202002L
# ifdef __cpp_lib_format
tickFormatFormat = settings.value(group+"ticks/format_format", defaultStyle.tickFormatFormat).toString();
# endif
#endif
minTicks = settings.value(group+"min_ticks", defaultStyle.minTicks).toUInt();
minorTicks = settings.value(group+"minor_tick/count", defaultStyle.minorTicks).toUInt();
tickOutsideLength = settings.value(group+"ticks/outside_length", defaultStyle.tickOutsideLength).toDouble();
@ -158,6 +168,11 @@ void JKQTPCoordinateAxisStyle::saveSettings(QSettings &settings, const QString &
settings.setValue(group+"ticks/date_format", tickDateFormat);
settings.setValue(group+"ticks/datetime_format", tickDateTimeFormat);
settings.setValue(group+"ticks/printf_format", tickPrintfFormat);
#if __cplusplus >= 202002L
# ifdef __cpp_lib_format
settings.setValue(group+"ticks/format_format", tickFormatFormat);
# endif
#endif
settings.setValue(group+"ticks/inside_length", tickInsideLength);
settings.setValue(group+"ticks/label_distance", tickLabelDistance);
settings.setValue(group+"ticks/label_font_size", tickLabelFontSize);

View File

@ -26,6 +26,12 @@
#include "jkqtplotter/jkqtptools.h"
#include "jkqtplotter/jkqtplotter_imexport.h"
#include "jkqtplotter/jkqtplotter_configmacros.h"
#if __cplusplus >= 202002L
# include <version>
# ifdef __cpp_lib_format
# include <format>
# endif
#endif
class JKQTBasePlotterStyle; // forward
@ -167,8 +173,15 @@ class JKQTPLOTTER_LIB_EXPORT JKQTPCoordinateAxisStyle {
QString tickDateFormat;
/** \brief format string for datetime tick labels, see QDateTime::toString() documentation for details on format strings */
QString tickDateTimeFormat;
/** \brief format string for printf tick labels, see https://en.wikipedia.org/wiki/Printf_format_string documentation for details on format strings */
/** \brief format string for printf tick labels, see https://en.wikipedia.org/wiki/Printf_format_string documentation for details on format strings The first data parameter is the tick value as \c double an the second is tickUnitName as string. The following image shows an example for \c "y=%+.2f": \image html axisstyle/JKQTPCALTprintf.png */
QString tickPrintfFormat;
#if __cplusplus >= 202002L || DOXYGEN
#if defined(__cpp_lib_format) || DOXYGEN
/** \brief format string for std::format tick labels, (see e.g. https://en.cppreference.com/w/cpp/utility/format/formatter#Standard_format_specification ). The first data parameter is the tick value as \c double an the second is tickUnitName as string. The following image shows an example for \c "\\texttt{{ y={:*^+8.1f}}}": \image html axisstyle/JKQTPCALTformat.png
\note This option is only available for C++20 and above, use the CMake option \c JKQtPlotter_ENABLED_CXX20=ON if your compiler supports this.*/
QString tickFormatFormat;
# endif
#endif

View File

@ -50,6 +50,9 @@
#include "jkqtcommon/jkqtpmathtools.h"
#include "jkqtcommon_statistics_and_math/jkqtpalgorithms.h"
#include "jkqtcommon/jkqtpcodestructuring.h"
#if __cplusplus >= 202002L
# include <version>
#endif
@ -455,7 +458,10 @@ enum JKQTPCALabelType {
JKQTPCALTintfrac, /*!< \brief show numbers as integral+fraction, the number is first rounded to the given precision and then a fraction is calculated and displayed like \f$ -3\frac{1}{2} \f$ \image html axisstyle/JKQTPCALTintfrac.png */
JKQTPCALTintslashfrac, /*!< \brief show numbers as integral+fraction, the number is first rounded to the given precision and then a fraction is calculated and displayed like \c 1/2 \image html axisstyle/JKQTPCALTintslashfrac.png */
JKQTPCALTintsfrac, /*!< \brief show numbers as integral+fraction, the number is first rounded to the given precision and then a fraction is calculated and displayed using \c \\sfrac{1}{2} \image html axisstyle/JKQTPCALTintsfrac.png */
#if defined(__cpp_lib_format) || DOXYGEN
JKQTPCALTformat, /*!< \brief generate axis label from an arbitrary "std::format" formatting string (see e.g. https://en.cppreference.com/w/cpp/utility/format/formatter#Standard_format_specification ). The first data parameter is the tick value as \c double an the second is tickUnitName as string. The following image shows an example for \c "\\texttt{{ y={:*^+8.1f}}}": \image html axisstyle/JKQTPCALTformat.png
\b NOte: This option is only available for C++20 and above, use the CMake option \c JKQtPlotter_ENABLED_CXX20=ON if your compiler supports this. */
#endif
JKQTPCALTcount,
JKQTPCALTmax=JKQTPCALTcount-1
};

View File

@ -27,7 +27,12 @@
#include "jkqtplotter/jkqtpbaseplotter.h"
#include "jkqtplotter/graphs/jkqtplines.h"
#include <iostream>
#if __cplusplus >= 202002L
# include <version>
# ifdef __cpp_lib_format
# include <format>
# endif
#endif
void startPainting(QImage& img, JKQTPEnhancedPainter& p, int iconsizex, int iconsizey, QColor backgroundColor) {
img=QImage(QSize(iconsizex,iconsizey),QImage::Format_ARGB32_Premultiplied);
@ -257,6 +262,12 @@ void doListAxisStyling(const QDir& outputDir, int iconsize, QColor backgroundCol
plot.getYAxis()->setTickLabelType(JKQTPCALTprintf);
plot.getYAxis()->setTickPrintfFormat("y=%+.2f");
plot.grabPixelImage(QSize(plot.getWidth(),plot.getHeight()), false).copy(0,0,iconsize*2.5,plot.getHeight()).save(outputDir.absoluteFilePath("JKQTPCALTprintf.png"), "png");
#ifdef __cpp_lib_format
plot.setY(-1,1);
plot.getYAxis()->setTickLabelType(JKQTPCALTformat);
plot.getYAxis()->setTickFormatFormat("\\texttt{{ y={:*^+8.1f}}}");
plot.grabPixelImage(QSize(plot.getWidth(),plot.getHeight()), false).copy(0,0,iconsize*2.5,plot.getHeight()).save(outputDir.absoluteFilePath("JKQTPCALTformat.png"), "png");
#endif