2015-07-11 18:56:02 +08:00
/*
2022-07-19 19:40:43 +08:00
Copyright ( c ) 2008 - 2022 Jan W . Krieger ( < jan @ jkrieger . 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
it under the terms of the GNU Lesser General Public License ( LGPL ) as published by
2019-02-08 00:24:46 +08:00
the Free Software Foundation , either version 2.1 of the License , or
2015-07-11 18:56:02 +08:00
( 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
GNU Lesser General Public License ( LGPL ) for more details .
You should have received a copy of the GNU Lesser General Public License ( LGPL )
along with this program . If not , see < http : //www.gnu.org/licenses/>.
*/
# include <QFileInfo>
# if (QT_VERSION >= QT_VERSION_CHECK(5, 0, 0))
# include <QtGlobal>
# include <QtWidgets>
# else
# include <QtGui>
# endif
# include <QSvgGenerator>
# include <QDebug>
# include <QElapsedTimer>
# include <QDialog>
2018-11-26 03:25:44 +08:00
# include "jkqtplotter/jkqtpbaseplotter.h"
2019-06-20 21:18:58 +08:00
# include "jkqtplotter/gui/jkqtpgraphsmodel.h"
# include "jkqtplotter/gui/jkqtpenhancedtableview.h"
2022-07-19 05:33:20 +08:00
# ifndef JKQTPLOTTER_COMPILE_WITHOUT_PRINTSUPPORT
# include <QPrintDialog>
# include <QPrinter>
# include <QPrinterInfo>
# include <QtPrintSupport / QPrintPreviewWidget>
# endif
2015-07-11 18:56:02 +08:00
# include <QGridLayout>
# include <QCheckBox>
# include <QDialogButtonBox>
# include <QApplication>
# include <QFileDialog>
# include <QInputDialog>
# include <QVBoxLayout>
2015-08-04 23:38:29 +08:00
# ifdef QFWIDLIB_LIBRARY
# include "qftools.h"
# endif
2019-06-20 22:06:31 +08:00
# include "jkqtplotter/graphs/jkqtpimage.h"
# include "jkqtplotter/graphs/jkqtpimagergb.h"
2022-06-03 03:02:23 +08:00
# include "jkqtmathtext/jkqtmathtext.h"
2023-03-23 20:55:18 +08:00
# include <algorithm>
2015-07-11 18:56:02 +08:00
static QString globalUserSettigsFilename = " " ;
static QString globalUserSettigsPrefix = " " ;
2019-01-26 03:16:04 +08:00
static QList < JKQTPPaintDeviceAdapter * > jkqtpPaintDeviceAdapters ;
static QList < JKQTPSaveDataAdapter * > jkqtpSaveDataAdapters ;
2015-07-11 18:56:02 +08:00
2018-12-03 01:30:12 +08:00
2019-02-08 00:24:46 +08:00
2019-01-20 17:49:29 +08:00
void initJKQTBasePlotterResources ( )
2018-12-03 01:30:12 +08:00
{
Q_INIT_RESOURCE ( jkqtpbaseplotter ) ;
2019-01-20 17:49:29 +08:00
initJKQTMathTextResources ( ) ;
2018-12-03 01:30:12 +08:00
}
2019-01-26 19:28:44 +08:00
void JKQTBasePlotter : : setDefaultJKQTBasePrinterUserSettings ( QString userSettigsFilename , const QString & userSettigsPrefix )
2015-07-11 18:56:02 +08:00
{
globalUserSettigsFilename = userSettigsFilename ;
globalUserSettigsPrefix = userSettigsPrefix ;
}
2019-01-26 03:16:04 +08:00
void JKQTBasePlotter : : registerPaintDeviceAdapter ( JKQTPPaintDeviceAdapter * adapter )
2015-07-11 18:56:02 +08:00
{
jkqtpPaintDeviceAdapters . append ( adapter ) ;
}
2019-01-26 03:16:04 +08:00
void JKQTBasePlotter : : deregisterPaintDeviceAdapter ( JKQTPPaintDeviceAdapter * adapter )
2015-07-11 18:56:02 +08:00
{
if ( jkqtpPaintDeviceAdapters . contains ( adapter ) ) jkqtpPaintDeviceAdapters . removeAll ( adapter ) ;
}
2019-01-26 03:16:04 +08:00
bool JKQTBasePlotter : : registerSaveDataAdapter ( JKQTPSaveDataAdapter * adapter )
2015-07-11 18:56:02 +08:00
{
if ( adapter ) {
QString format = adapter - > getFilter ( ) ;
for ( int i = 0 ; i < jkqtpSaveDataAdapters . size ( ) ; i + + ) {
if ( jkqtpSaveDataAdapters [ i ] & & jkqtpSaveDataAdapters [ i ] - > getFilter ( ) = = format ) {
return false ;
}
}
jkqtpSaveDataAdapters . append ( adapter ) ;
return true ;
}
return false ;
}
2019-01-26 03:16:04 +08:00
bool JKQTBasePlotter : : deregisterSaveDataAdapter ( JKQTPSaveDataAdapter * adapter )
2015-07-11 18:56:02 +08:00
{
if ( jkqtpSaveDataAdapters . contains ( adapter ) ) jkqtpSaveDataAdapters . removeAll ( adapter ) ;
return true ;
}
2019-01-20 17:49:29 +08:00
JKQTBasePlotter : : textSizeData JKQTBasePlotter : : getTextSizeDetail ( const QFont & fm , const QString & text , QPainter & painter )
2015-07-11 18:56:02 +08:00
{
return getTextSizeDetail ( fm . family ( ) , fm . pointSizeF ( ) , text , painter ) ;
}
2019-01-20 17:49:29 +08:00
JKQTBasePlotter : : textSizeData JKQTBasePlotter : : getTextSizeDetail ( const QString & fontName , double fontSize , const QString & text , QPainter & painter )
2015-07-11 18:56:02 +08:00
{
2019-01-20 17:49:29 +08:00
JKQTBasePlotter : : textSizeKey dh ( fontName , fontSize , text , painter . device ( ) ) ;
2019-02-08 00:24:46 +08:00
if ( s_TextSizeDataCache . contains ( dh ) ) return s_TextSizeDataCache [ dh ] ;
2019-01-20 17:49:29 +08:00
JKQTBasePlotter : : textSizeData d ;
2022-09-01 20:36:34 +08:00
mathText . setFontSpecial ( fontName ) ;
2019-01-26 03:16:04 +08:00
mathText . setFontSize ( fontSize ) ;
2015-07-11 18:56:02 +08:00
mathText . parse ( text ) ;
mathText . getSizeDetail ( painter , d . width , d . ascent , d . descent , d . strikeoutPos ) ;
2019-02-08 00:24:46 +08:00
s_TextSizeDataCache [ dh ] = d ;
2015-07-11 18:56:02 +08:00
//qDebug()<<"+++ textsize hash size: "<<tbrh.size();
return d ;
}
2019-01-20 17:49:29 +08:00
void JKQTBasePlotter : : getTextSizeDetail ( const QString & fontName , double fontSize , const QString & text , QPainter & painter , double & width , double & ascent , double & descent , double & strikeoutPos )
2015-07-11 18:56:02 +08:00
{
2019-02-08 00:24:46 +08:00
if ( ! text . isEmpty ( ) ) {
JKQTBasePlotter : : textSizeData d = getTextSizeDetail ( fontName , fontSize , text , painter ) ;
width = d . width ;
ascent = d . ascent ;
descent = d . descent ;
strikeoutPos = d . strikeoutPos ;
} else {
width = 0 ;
ascent = 0 ;
descent = 0 ;
strikeoutPos = 0 ;
}
2015-07-11 18:56:02 +08:00
}
2019-01-20 17:49:29 +08:00
void JKQTBasePlotter : : getTextSizeDetail ( const QFont & fm , const QString & text , QPainter & painter , double & width , double & ascent , double & descent , double & strikeoutPos )
2015-07-11 18:56:02 +08:00
{
getTextSizeDetail ( fm . family ( ) , fm . pointSizeF ( ) , text , painter , width , ascent , descent , strikeoutPos ) ;
}
2019-01-20 17:49:29 +08:00
QSizeF JKQTBasePlotter : : getTextSizeSize ( const QFont & fm , const QString & text , QPainter & painter )
2015-07-11 18:56:02 +08:00
{
return getTextSizeSize ( fm . family ( ) , fm . pointSizeF ( ) , text , painter ) ;
}
2019-01-20 17:49:29 +08:00
QSizeF JKQTBasePlotter : : getTextSizeSize ( const QString & fontName , double fontSize , const QString & text , QPainter & painter )
2015-07-11 18:56:02 +08:00
{
2019-02-08 00:24:46 +08:00
if ( text . isEmpty ( ) ) return QSizeF ( 0 , 0 ) ;
2019-01-20 17:49:29 +08:00
JKQTBasePlotter : : textSizeData d = getTextSizeDetail ( fontName , fontSize , text , painter ) ;
2015-07-11 18:56:02 +08:00
return QSizeF ( d . width , d . ascent + d . descent ) ;
}
// define this to get timing information about painting on the debug output
//#define JKQTBP_DEBUGTIMING
# undef JKQTBP_DEBUGTIMING
/**************************************************************************************************************************
2019-01-26 03:16:04 +08:00
* JKQTBasePlotter
2015-07-11 18:56:02 +08:00
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2019-01-20 17:49:29 +08:00
JKQTBasePlotter : : JKQTBasePlotter ( bool datastore_internal , QObject * parent , JKQTPDatastore * datast ) :
2019-02-08 00:24:46 +08:00
QObject ( parent ) , plotterStyle ( JKQTPGetSystemDefaultBaseStyle ( ) ) , m_plotsModel ( nullptr ) , xAxis ( nullptr ) , yAxis ( nullptr )
2015-07-11 18:56:02 +08:00
{
2019-02-08 00:24:46 +08:00
initJKQTBasePlotterResources ( ) ;
2018-11-18 18:59:30 +08:00
dataColumnsListWidget = nullptr ;
2015-07-11 18:56:02 +08:00
printMagnification = 1.0 ;
printZoomFactor = 1.0 ;
printSizeX_Millimeter = 1.0 ;
printSizeY_Millimeter = 1.0 ;
paintMagnification = 1.0 ;
printDoUpdate = true ;
emitPlotSignals = true ;
2019-02-03 21:04:48 +08:00
masterPlotterX = nullptr ;
masterPlotterY = nullptr ;
2015-07-11 18:56:02 +08:00
masterSynchronizeWidth = false ;
masterSynchronizeHeight = false ;
fontSizePrintMultiplier = 1 ;
lineWidthPrintMultiplier = 1 ;
fontSizeMultiplier = 1 ;
lineWidthMultiplier = 1 ;
userSettigsFilename = globalUserSettigsFilename ;
userSettigsPrefix = globalUserSettigsPrefix ;
2022-07-19 05:33:20 +08:00
# ifndef JKQTPLOTTER_COMPILE_WITHOUT_PRINTSUPPORT
2015-07-11 18:56:02 +08:00
currentPrinter = QPrinterInfo : : defaultPrinter ( ) . printerName ( ) ;
2022-07-19 05:33:20 +08:00
# endif
2015-07-11 18:56:02 +08:00
if ( datastore_internal ) {
2019-01-20 17:49:29 +08:00
datastore = new JKQTPDatastore ( ) ;
2015-07-11 18:56:02 +08:00
datastoreInternal = true ;
} else {
datastore = datast ;
datastoreInternal = false ;
}
2019-05-06 01:31:20 +08:00
// some fonts that are know to deliver bad rendering quality
mathText . addReplacementFont ( " MS Shell Dlg 2 " , " Arial " ) ;
mathText . addReplacementFont ( " MS Shell Dlg " , " Arial " ) ;
mathText . addReplacementFont ( " MS Sans Serif " , " Arial " ) ;
mathText . addReplacementFont ( " MS Serif " , " Times New Roman " ) ;
mathText . addReplacementFont ( " MS Sans Serif Standard " , " Arial " ) ;
mathText . addReplacementFont ( " MS Serif Standard " , " Times New Roman " ) ;
2019-01-20 17:49:29 +08:00
xAxis = new JKQTPHorizontalAxis ( this ) ;
yAxis = new JKQTPVerticalAxis ( this ) ;
m_plotsModel = new JKQTPGraphsModel ( this ) ;
2018-08-19 23:03:46 +08:00
connect ( this , SIGNAL ( plotUpdated ( ) ) , m_plotsModel , SLOT ( plotUpdated ( ) ) ) ;
2015-07-11 18:56:02 +08:00
emitSignals = false ;
2019-02-08 00:24:46 +08:00
setWidgetSize ( 400 , 300 ) ;
internalPlotWidth = 400 ;
internalPlotHeight = 300 ;
2015-07-11 18:56:02 +08:00
initSettings ( ) ;
emitSignals = true ;
2019-05-06 01:31:20 +08:00
actSavePlot = new QAction ( QIcon ( " :/JKQTPlotter/jkqtp_saveplot.png " ) , tr ( " Save Plot " ) , this ) ;
actSavePlot - > setToolTip ( tr ( " Save plot as image file (PDF, PS; PNG, ...). " ) ) ;
actSaveData = new QAction ( QIcon ( " :/JKQTPlotter/jkqtp_savedata.png " ) , tr ( " Save Data " ) , this ) ;
actSaveData - > setToolTip ( tr ( " Save Data of the plot as file (CSV, ...). " ) ) ;
actCopyData = new QAction ( QIcon ( " :/JKQTPlotter/jkqtp_copydata.png " ) , tr ( " Copy Data " ) , this ) ;
actCopyData - > setToolTip ( tr ( " Copy Data of the plot to the clipboard to be pasted into Excel etc. " ) ) ;
actCopyMatlab = new QAction ( QIcon ( " :/JKQTPlotter/jkqtp_copymatlab.png " ) , tr ( " Copy Data to Matlab " ) , this ) ;
actCopyMatlab - > setToolTip ( tr ( " Copy Data of the plot to the clipboard in Matlab script format. " ) ) ;
actCopyPixelImage = new QAction ( QIcon ( " :/JKQTPlotter/jkqtp_copyimg.png " ) , tr ( " Copy Image " ) , this ) ;
actCopyPixelImage - > setToolTip ( tr ( " Copy the plot as a pixel image to the clipboard " ) ) ;
2015-07-11 18:56:02 +08:00
2022-07-19 05:33:20 +08:00
# ifndef JKQTPLOTTER_COMPILE_WITHOUT_PRINTSUPPORT
2019-05-06 01:31:20 +08:00
actSavePDF = new QAction ( QIcon ( " :/JKQTPlotter/jkqtp_savepdf.png " ) , tr ( " Save P&DF " ) , this ) ;
actSavePDF - > setToolTip ( tr ( " Save as PDF " ) ) ;
2015-07-11 18:56:02 +08:00
//toolbar->addAction(actSavePDF);
2019-05-06 01:31:20 +08:00
actSaveSVG = new QAction ( QIcon ( " :/JKQTPlotter/jkqtp_savesvg.png " ) , tr ( " Save S&VG " ) , this ) ;
actSaveSVG - > setToolTip ( tr ( " Save as Scalable Vector Graphics (SVG) " ) ) ;
2015-07-11 18:56:02 +08:00
//toolbar->addAction(actSaveSVG);
2022-07-19 05:33:20 +08:00
# endif
2019-05-06 01:31:20 +08:00
actSavePix = new QAction ( QIcon ( " :/JKQTPlotter/jkqtp_savepix.png " ) , tr ( " Save &Image " ) , this ) ;
actSavePix - > setToolTip ( tr ( " Save as Pixel Image (PNG, JPEG, TIFF ...) " ) ) ;
2015-07-11 18:56:02 +08:00
//toolbar->addAction(actSavePix);
2022-07-19 05:33:20 +08:00
# ifndef JKQTPLOTTER_COMPILE_WITHOUT_PRINTSUPPORT
2019-05-06 01:31:20 +08:00
actPrint = new QAction ( QIcon ( " :/JKQTPlotter/jkqtp_print.png " ) , tr ( " &Print " ) , this ) ;
2015-07-11 18:56:02 +08:00
actPrint - > setToolTip ( " Print " ) ;
2022-07-19 05:33:20 +08:00
# endif
2015-07-11 18:56:02 +08:00
//toolbar->addSeparator();
2019-05-06 01:31:20 +08:00
actSaveCSV = new QAction ( QIcon ( " :/JKQTPlotter/jkqtp_savecsv.png " ) , tr ( " Save &CSV " ) , this ) ;
actSaveCSV - > setToolTip ( tr ( " Save the data which is used for the plot as Comma Separated Values (CSV) " ) ) ;
2015-07-11 18:56:02 +08:00
//toolbar->addAction(actSaveCSV);
//toolbar->addSeparator();
2019-05-06 01:31:20 +08:00
actZoomAll = new QAction ( QIcon ( " :/JKQTPlotter/jkqtp_zoomall.png " ) , tr ( " Zoom &All " ) , this ) ;
actZoomAll - > setToolTip ( tr ( " Zoom to view all data " ) ) ;
actZoomIn = new QAction ( QIcon ( " :/JKQTPlotter/jkqtp_zoomin.png " ) , tr ( " Zoom &In " ) , this ) ;
actZoomIn - > setToolTip ( tr ( " Zoom in around the center of the plot " ) ) ;
actZoomOut = new QAction ( QIcon ( " :/JKQTPlotter/jkqtp_zoomout.png " ) , tr ( " Zoom &Out " ) , this ) ;
actZoomOut - > setToolTip ( tr ( " Zoom out " ) ) ;
2015-07-11 18:56:02 +08:00
2019-05-06 01:31:20 +08:00
actShowPlotData = new QAction ( QIcon ( " :/JKQTPlotter/jkqtp_showplotdata.png " ) , tr ( " &Show Plot Data " ) , this ) ;
actShowPlotData - > setToolTip ( tr ( " Opens a dialog that contains all data used for the plot in a table. " ) ) ;
2015-07-11 18:56:02 +08:00
connect ( actSavePlot , SIGNAL ( triggered ( ) ) , this , SLOT ( saveImage ( ) ) ) ;
connect ( actSaveData , SIGNAL ( triggered ( ) ) , this , SLOT ( saveData ( ) ) ) ;
connect ( actCopyData , SIGNAL ( triggered ( ) ) , this , SLOT ( copyData ( ) ) ) ;
connect ( actCopyPixelImage , SIGNAL ( triggered ( ) ) , this , SLOT ( copyPixelImage ( ) ) ) ;
connect ( actCopyMatlab , SIGNAL ( triggered ( ) ) , this , SLOT ( copyDataMatlab ( ) ) ) ;
connect ( actShowPlotData , SIGNAL ( triggered ( ) ) , this , SLOT ( showPlotData ( ) ) ) ;
2022-07-19 05:33:20 +08:00
# ifndef JKQTPLOTTER_COMPILE_WITHOUT_PRINTSUPPORT
connect ( actPrint , SIGNAL ( triggered ( ) ) , this , SLOT ( print ( ) ) ) ;
2015-07-11 18:56:02 +08:00
connect ( actSaveSVG , SIGNAL ( triggered ( ) ) , this , SLOT ( saveAsSVG ( ) ) ) ;
2022-07-19 05:33:20 +08:00
connect ( actSavePDF , SIGNAL ( triggered ( ) ) , this , SLOT ( saveAsPDF ( ) ) ) ;
# endif
2015-07-11 18:56:02 +08:00
connect ( actSavePix , SIGNAL ( triggered ( ) ) , this , SLOT ( saveAsPixelImage ( ) ) ) ;
connect ( actSaveCSV , SIGNAL ( triggered ( ) ) , this , SLOT ( saveAsCSV ( ) ) ) ;
connect ( actZoomAll , SIGNAL ( triggered ( ) ) , this , SLOT ( zoomToFit ( ) ) ) ;
connect ( actZoomIn , SIGNAL ( triggered ( ) ) , this , SLOT ( zoomIn ( ) ) ) ;
connect ( actZoomOut , SIGNAL ( triggered ( ) ) , this , SLOT ( zoomOut ( ) ) ) ;
2019-02-08 00:24:46 +08:00
setWidgetSize ( 400 , 300 ) ;
2015-07-11 18:56:02 +08:00
}
2019-01-20 17:49:29 +08:00
JKQTBasePlotter : : ~ JKQTBasePlotter ( ) {
2015-07-11 18:56:02 +08:00
clearGraphs ( false ) ;
2018-11-18 18:59:30 +08:00
if ( datastoreInternal & & datastore ! = nullptr ) delete datastore ;
2015-07-11 18:56:02 +08:00
delete xAxis ;
delete yAxis ;
2023-03-23 20:55:18 +08:00
for ( const auto & ax : qAsConst ( secondaryYAxis ) ) {
delete ax ;
}
secondaryYAxis . clear ( ) ;
for ( const auto & ax : qAsConst ( secondaryXAxis ) ) {
delete ax ;
}
secondaryXAxis . clear ( ) ;
2015-07-11 18:56:02 +08:00
}
2019-01-20 17:49:29 +08:00
void JKQTBasePlotter : : setGrid ( bool val ) {
2019-01-26 20:00:40 +08:00
xAxis - > setDrawGrid ( val ) ;
yAxis - > setDrawGrid ( val ) ;
2019-06-12 19:00:28 +08:00
}
2019-06-16 19:27:02 +08:00
void JKQTBasePlotter : : setGridColor ( QColor color )
{
xAxis - > setGridColor ( color ) ;
yAxis - > setGridColor ( color ) ;
}
void JKQTBasePlotter : : setMinorGridColor ( QColor color )
{
xAxis - > setMinorGridColor ( color ) ;
yAxis - > setMinorGridColor ( color ) ;
}
void JKQTBasePlotter : : setGridWidth ( double __value )
{
xAxis - > setGridWidth ( __value ) ;
yAxis - > setGridWidth ( __value ) ;
}
void JKQTBasePlotter : : setMinorGridWidth ( double __value )
{
xAxis - > setMinorGridWidth ( __value ) ;
yAxis - > setMinorGridWidth ( __value ) ;
}
void JKQTBasePlotter : : setGridStyle ( Qt : : PenStyle __value )
{
xAxis - > setGridStyle ( __value ) ;
yAxis - > setGridStyle ( __value ) ;
}
void JKQTBasePlotter : : setMinorGridStyle ( Qt : : PenStyle __value )
{
xAxis - > setMinorGridStyle ( __value ) ;
yAxis - > setMinorGridStyle ( __value ) ;
}
2019-06-12 19:00:28 +08:00
void JKQTBasePlotter : : setShowZeroAxes ( bool showX , bool showY ) {
2023-03-23 20:55:18 +08:00
xAxis - > setShowZeroAxis ( showX ) ;
yAxis - > setShowZeroAxis ( showY ) ;
2019-06-12 19:00:28 +08:00
}
void JKQTBasePlotter : : setShowZeroAxes ( bool showXY ) {
setShowZeroAxes ( showXY , showXY ) ;
}
2015-07-11 18:56:02 +08:00
2019-01-20 17:49:29 +08:00
void JKQTBasePlotter : : useExternalDatastore ( JKQTPDatastore * newStore ) {
2018-11-18 18:59:30 +08:00
if ( datastoreInternal & & datastore ! = nullptr ) {
2015-07-11 18:56:02 +08:00
delete datastore ;
2018-11-18 18:59:30 +08:00
datastore = nullptr ;
2015-07-11 18:56:02 +08:00
}
datastore = newStore ;
datastoreInternal = false ;
} ;
2019-01-20 17:49:29 +08:00
void JKQTBasePlotter : : useAsInternalDatastore ( JKQTPDatastore * newStore ) {
2018-11-18 18:59:30 +08:00
if ( datastoreInternal & & datastore ! = nullptr ) {
2015-07-11 18:56:02 +08:00
delete datastore ;
2018-11-18 18:59:30 +08:00
datastore = nullptr ;
2015-07-11 18:56:02 +08:00
}
datastore = newStore ;
datastoreInternal = true ;
2023-05-28 05:46:45 +08:00
redrawPlot ( ) ;
2015-07-11 18:56:02 +08:00
}
2019-01-20 17:49:29 +08:00
void JKQTBasePlotter : : useInternalDatastore ( ) {
2015-07-11 18:56:02 +08:00
if ( ! datastoreInternal ) {
2019-01-20 17:49:29 +08:00
datastore = new JKQTPDatastore ( ) ;
2015-07-11 18:56:02 +08:00
datastoreInternal = true ;
}
2023-05-28 05:46:45 +08:00
redrawPlot ( ) ;
2015-07-11 18:56:02 +08:00
}
2019-01-20 17:49:29 +08:00
void JKQTBasePlotter : : forceInternalDatastore ( ) {
2018-11-18 18:59:30 +08:00
if ( datastoreInternal & & datastore ! = nullptr ) {
2015-07-11 18:56:02 +08:00
delete datastore ;
2018-11-18 18:59:30 +08:00
datastore = nullptr ;
2015-07-11 18:56:02 +08:00
}
2019-01-20 17:49:29 +08:00
datastore = new JKQTPDatastore ( ) ;
2015-07-11 18:56:02 +08:00
datastoreInternal = true ;
2023-05-28 05:46:45 +08:00
redrawPlot ( ) ;
2015-07-11 18:56:02 +08:00
}
2019-01-26 19:28:44 +08:00
bool JKQTBasePlotter : : isEmittingSignalsEnabled ( ) const {
return this - > emitSignals ;
}
2019-01-20 17:49:29 +08:00
void JKQTBasePlotter : : initSettings ( ) {
2015-07-11 18:56:02 +08:00
useClipping = true ;
//doDrawing=true;
2019-02-08 00:24:46 +08:00
maintainAspectRatio = false ;
aspectRatio = 1 ;
2015-07-11 18:56:02 +08:00
2019-02-08 00:24:46 +08:00
maintainAxisAspectRatio = false ;
axisAspectRatio = 1 ;
2015-07-11 18:56:02 +08:00
gridPrinting = false ;
gridPrintingList . clear ( ) ;
gridPrintingCurrentX = 0 ;
gridPrintingCurrentY = 0 ;
2023-03-23 20:55:18 +08:00
internalPlotBorderLeft_notIncludingAxisAndOutsidePlotSections = internalPlotBorderLeft_notIncludingOutsidePlotSections = internalPlotBorderLeft = plotterStyle . plotBorderLeft ;
internalPlotBorderRight_notIncludingAxisAndOutsidePlotSections = internalPlotBorderRight_notIncludingOutsidePlotSections = internalPlotBorderRight = plotterStyle . plotBorderRight ;
internalPlotBorderTop_notIncludingAxisAndOutsidePlotSections = internalPlotBorderTop_notIncludingOutsidePlotSections = internalPlotBorderTop = plotterStyle . plotBorderTop ;
internalPlotBorderBottom_notIncludingAxisAndOutsidePlotSections = internalPlotBorderBottom_notIncludingOutsidePlotSections = internalPlotBorderBottom = plotterStyle . plotBorderBottom ;
2015-07-11 18:56:02 +08:00
//plotWidth=700;
//plotHeight=150;
xAxis - > setRange ( - 10 , 10 ) ;
yAxis - > setRange ( - 10 , 10 ) ;
plotLabel = " " ;
2023-05-28 05:46:45 +08:00
redrawPlot ( ) ;
2015-07-11 18:56:02 +08:00
}
2018-12-03 01:30:12 +08:00
2019-01-20 17:49:29 +08:00
void JKQTBasePlotter : : zoomIn ( double factor ) {
2015-07-11 18:56:02 +08:00
//std::cout<<(double)event->delta()/120.0<<": "<<factor<<std::endl;
2023-03-23 20:55:18 +08:00
for ( auto ax : getXAxes ( true ) ) {
const double xmin = ax - > p2x ( static_cast < long > ( round ( static_cast < double > ( internalPlotWidth ) / 2.0 - static_cast < double > ( internalPlotWidth ) / ( 2.0 * factor ) ) ) ) ;
const double xmax = ax - > p2x ( static_cast < long > ( round ( static_cast < double > ( internalPlotWidth ) / 2.0 + static_cast < double > ( internalPlotWidth ) / ( 2.0 * factor ) ) ) ) ;
ax - > setRange ( xmin , xmax ) ;
}
for ( auto ax : getYAxes ( true ) ) {
const double ymin = ax - > p2x ( static_cast < long > ( round ( static_cast < double > ( internalPlotHeight ) / 2.0 + static_cast < double > ( internalPlotHeight ) / ( 2.0 * factor ) ) ) ) ;
const double ymax = ax - > p2x ( static_cast < long > ( round ( static_cast < double > ( internalPlotHeight ) / 2.0 - static_cast < double > ( internalPlotHeight ) / ( 2.0 * factor ) ) ) ) ;
ax - > setRange ( ymin , ymax ) ;
}
2015-07-11 18:56:02 +08:00
2023-05-28 05:46:45 +08:00
redrawPlot ( ) ;
2015-07-11 18:56:02 +08:00
if ( emitSignals ) emit zoomChangedLocally ( xAxis - > getMin ( ) , xAxis - > getMax ( ) , yAxis - > getMin ( ) , yAxis - > getMax ( ) , this ) ;
}
2019-02-08 00:24:46 +08:00
void JKQTBasePlotter : : zoomOut ( double factor ) {
zoomIn ( 1.0 / factor ) ;
}
void JKQTBasePlotter : : setMaintainAspectRatio ( bool value ) {
maintainAspectRatio = value ;
2020-09-12 05:19:31 +08:00
setAspectRatio ( aspectRatio ) ;
2019-02-08 00:24:46 +08:00
redrawPlot ( ) ;
}
void JKQTBasePlotter : : setMaintainAxisAspectRatio ( bool value ) {
maintainAxisAspectRatio = value ;
2022-09-25 21:34:05 +08:00
setAspectRatio ( aspectRatio ) ;
2019-02-08 00:24:46 +08:00
redrawPlot ( ) ;
}
2019-01-20 17:49:29 +08:00
void JKQTBasePlotter : : zoom ( double nxmin , double nxmax , double nymin , double nymax ) {
2015-07-11 18:56:02 +08:00
// only react on double clicks inside event
double xmin = nxmin ;
double xmax = nxmax ;
double ymin = nymin ;
double ymax = nymax ;
xAxis - > setRange ( xmin , xmax ) ;
yAxis - > setRange ( ymin , ymax ) ;
2023-05-28 05:46:45 +08:00
redrawPlot ( ) ;
2015-07-11 18:56:02 +08:00
if ( emitSignals ) emit zoomChangedLocally ( xAxis - > getMin ( ) , xAxis - > getMax ( ) , yAxis - > getMin ( ) , yAxis - > getMax ( ) , this ) ;
}
2019-01-26 19:28:44 +08:00
2019-02-08 00:24:46 +08:00
void JKQTBasePlotter : : setWidgetSize ( int wid , int heigh ) {
2015-07-11 18:56:02 +08:00
widgetWidth = wid ;
widgetHeight = heigh ;
2023-05-28 05:46:45 +08:00
redrawPlot ( ) ;
2015-07-11 18:56:02 +08:00
}
2019-02-08 00:24:46 +08:00
int JKQTBasePlotter : : getWidth ( ) {
return widgetWidth ;
}
int JKQTBasePlotter : : getHeight ( ) {
return widgetHeight ;
}
double JKQTBasePlotter : : getXMin ( ) const {
return xAxis - > getMin ( ) ;
}
double JKQTBasePlotter : : getXMax ( ) const {
return xAxis - > getMax ( ) ;
}
double JKQTBasePlotter : : getYMin ( ) const {
return yAxis - > getMin ( ) ;
}
double JKQTBasePlotter : : getYMax ( ) const {
return yAxis - > getMax ( ) ;
}
double JKQTBasePlotter : : getAbsoluteXMin ( ) const {
return xAxis - > getAbsoluteMin ( ) ;
}
double JKQTBasePlotter : : getAbsoluteXMax ( ) const {
return xAxis - > getAbsoluteMax ( ) ;
}
double JKQTBasePlotter : : getAbsoluteYMin ( ) const {
return yAxis - > getAbsoluteMin ( ) ;
}
double JKQTBasePlotter : : getAbsoluteYMax ( ) const {
return yAxis - > getAbsoluteMax ( ) ;
}
void JKQTBasePlotter : : addGridPrintingPlotter ( size_t x , size_t y , JKQTBasePlotter * plotter ) {
JKQTPGridPrintingItem i ;
i . x = x ;
i . y = y ;
i . plotter = plotter ;
gridPrintingList . push_back ( i ) ;
}
void JKQTBasePlotter : : clearGridPrintingPlotters ( ) {
gridPrintingList . clear ( ) ;
}
2015-07-11 18:56:02 +08:00
2019-02-08 00:24:46 +08:00
void JKQTBasePlotter : : setWidgetWidth ( int wid ) {
2015-07-11 18:56:02 +08:00
widgetWidth = wid ;
2023-05-28 05:46:45 +08:00
redrawPlot ( ) ;
2015-07-11 18:56:02 +08:00
}
2019-02-08 00:24:46 +08:00
void JKQTBasePlotter : : setWidgetHeight ( int heigh ) {
2015-07-11 18:56:02 +08:00
widgetHeight = heigh ;
2023-05-28 05:46:45 +08:00
redrawPlot ( ) ;
2015-07-11 18:56:02 +08:00
}
2019-01-26 19:28:44 +08:00
void JKQTBasePlotter : : saveSettings ( QSettings & settings , const QString & group ) const {
2015-07-11 18:56:02 +08:00
2019-02-08 00:24:46 +08:00
plotterStyle . saveSettings ( settings , group ) ;
settings . setValue ( group + " apect_ratio " , aspectRatio ) ;
settings . setValue ( group + " maintain_apect_ratio " , maintainAspectRatio ) ;
settings . setValue ( group + " axis_apect_ratio " , axisAspectRatio ) ;
settings . setValue ( group + " maintain_axis_apect_ratio " , maintainAxisAspectRatio ) ;
mathText . saveSettings ( settings , group + " math_text. " ) ;
xAxis - > saveSettings ( settings , group + " xaxis_ " ) ;
yAxis - > saveSettings ( settings , group + " yaxis_ " ) ;
saveUserSettings ( ) ;
}
const JKQTBasePlotterStyle & JKQTBasePlotter : : getCurrentPlotterStyle ( ) const
{
return plotterStyle ;
}
void JKQTBasePlotter : : setCurrentPlotterStyle ( const JKQTBasePlotterStyle & style )
{
plotterStyle = style ;
propagateStyle ( ) ;
}
void JKQTBasePlotter : : propagateStyle ( ) {
bool old = emitPlotSignals ;
emitPlotSignals = false ;
xAxis - > setCurrentAxisStyle ( plotterStyle . xAxisStyle ) ;
yAxis - > setCurrentAxisStyle ( plotterStyle . yAxisStyle ) ;
for ( int i = 0 ; i < graphs . size ( ) ; i + + ) {
2019-05-30 04:40:02 +08:00
JKQTPColorPaletteStyleAndToolsMixin * palTools = dynamic_cast < JKQTPColorPaletteStyleAndToolsMixin * > ( graphs [ i ] ) ;
2019-02-08 00:24:46 +08:00
if ( palTools ) {
palTools - > getColorBarRightAxis ( ) - > setCurrentAxisStyle ( plotterStyle . rightColorbarAxisStyle ) ;
palTools - > getColorBarTopAxis ( ) - > setCurrentAxisStyle ( plotterStyle . topColorbarAxisStyle ) ;
2015-07-11 18:56:02 +08:00
}
2019-02-08 00:24:46 +08:00
JKQTPMathImage * matImg = dynamic_cast < JKQTPMathImage * > ( graphs [ i ] ) ;
if ( matImg ) {
matImg - > getColorBarRightAxis ( ) - > setCurrentAxisStyle ( plotterStyle . rightColorbarAxisStyle ) ;
matImg - > getColorBarTopAxis ( ) - > setCurrentAxisStyle ( plotterStyle . topColorbarAxisStyle ) ;
matImg - > getModifierColorBarRightAxis ( ) - > setCurrentAxisStyle ( plotterStyle . rightColorbarAxisStyle ) ;
matImg - > getModifierColorBarTopAxis ( ) - > setCurrentAxisStyle ( plotterStyle . topColorbarAxisStyle ) ;
}
JKQTPRGBMathImage * matImgRGB = dynamic_cast < JKQTPRGBMathImage * > ( graphs [ i ] ) ;
if ( matImgRGB ) {
matImgRGB - > getColorBarRightAxis ( ) - > setCurrentAxisStyle ( plotterStyle . rightColorbarAxisStyle ) ;
matImgRGB - > getColorBarTopAxis ( ) - > setCurrentAxisStyle ( plotterStyle . topColorbarAxisStyle ) ;
matImgRGB - > getColorBarRightAxisG ( ) - > setCurrentAxisStyle ( plotterStyle . rightColorbarAxisStyle ) ;
matImgRGB - > getColorBarTopAxisG ( ) - > setCurrentAxisStyle ( plotterStyle . topColorbarAxisStyle ) ;
matImgRGB - > getColorBarRightAxisB ( ) - > setCurrentAxisStyle ( plotterStyle . rightColorbarAxisStyle ) ;
matImgRGB - > getColorBarTopAxisB ( ) - > setCurrentAxisStyle ( plotterStyle . topColorbarAxisStyle ) ;
2015-07-11 18:56:02 +08:00
}
}
2019-02-08 00:24:46 +08:00
emitPlotSignals = old ;
2023-05-28 05:46:45 +08:00
redrawPlot ( ) ;
2019-02-08 00:24:46 +08:00
}
2015-07-11 18:56:02 +08:00
2019-02-08 00:24:46 +08:00
void JKQTBasePlotter : : loadCurrentPlotterStyle ( const QSettings & settings , const QString & group )
{
plotterStyle . loadSettings ( settings , group ) ;
propagateStyle ( ) ;
}
2015-07-11 18:56:02 +08:00
2019-02-08 00:24:46 +08:00
void JKQTBasePlotter : : saveCurrentPlotterStyle ( QSettings & settings , const QString & group ) const
{
plotterStyle . saveSettings ( settings , group ) ;
2015-07-11 18:56:02 +08:00
}
2019-01-26 19:28:44 +08:00
void JKQTBasePlotter : : loadUserSettings ( const QSettings & settings , const QString & group ) {
2015-07-11 18:56:02 +08:00
currentSaveDirectory = settings . value ( group + " currentSaveDirectory " , currentSaveDirectory ) . toString ( ) ;
currentFileFormat = settings . value ( group + " currentFileFormat " , currentFileFormat ) . toString ( ) ;
currentDataFileFormat = settings . value ( group + " currentDataFileFormat " , currentFileFormat ) . toString ( ) ;
printZoomFactor = settings . value ( group + " printZoomFactor " , printZoomFactor ) . toDouble ( ) ;
printSizeX_Millimeter = settings . value ( group + " printSizeX " , printSizeX_Millimeter ) . toDouble ( ) ;
printSizeY_Millimeter = settings . value ( group + " printSizeY " , printSizeY_Millimeter ) . toDouble ( ) ;
printMagnification = settings . value ( group + " printMagnification " , printMagnification ) . toDouble ( ) ;
printSetAbsolutePageSize = settings . value ( group + " printSetAbsoluteSize " , printSetAbsolutePageSize ) . toBool ( ) ;
printAspect = settings . value ( group + " printAspect " , printAspect ) . toDouble ( ) ;
fontSizePrintMultiplier = settings . value ( group + " fontSizePrintMultiplier " , fontSizePrintMultiplier ) . toDouble ( ) ;
lineWidthPrintMultiplier = settings . value ( group + " lineWidthPrintMultiplier " , lineWidthPrintMultiplier ) . toDouble ( ) ;
printKeepAspect = settings . value ( group + " printKeepAspect " , printKeepAspect ) . toBool ( ) ;
exportUnitInMM = settings . value ( group + " exportUnitInMM " , exportUnitInMM ) . toBool ( ) ;
currentPrinter = settings . value ( group + " printer " , currentPrinter ) . toString ( ) ;
2019-02-08 00:24:46 +08:00
int count = settings . value ( group + " selections/count " , 0 ) . toInt ( ) ;
2015-07-11 18:56:02 +08:00
getDataColumnsByUserSaved . clear ( ) ;
for ( int i = 0 ; i < count ; i + + ) {
2019-01-26 19:28:44 +08:00
const QString itg = QString ( " item%1 " ) . arg ( i ) ;
2019-02-08 00:24:46 +08:00
QString n = settings . value ( group + " selections/ " + itg + " /name " , " " ) . toString ( ) ;
QStringList item = settings . value ( group + " selections/ " + itg + " /items " , QStringList ( ) ) . toStringList ( ) ;
2015-07-11 18:56:02 +08:00
if ( ! n . isEmpty ( ) ) {
getDataColumnsByUserSaved [ n ] = item ;
}
}
}
2019-01-26 19:28:44 +08:00
void JKQTBasePlotter : : saveUserSettings ( QSettings & settings , const QString & group ) const {
2015-07-11 18:56:02 +08:00
settings . setValue ( group + " printer " , currentPrinter ) ;
//qDebug()<<settings.fileName()<<group<<currentSaveDirectory<<QDir(currentSaveDirectory).absolutePath();
settings . setValue ( group + " currentSaveDirectory " , QDir ( currentSaveDirectory ) . absolutePath ( ) ) ;
settings . setValue ( group + " currentFileFormat " , currentFileFormat ) ;
settings . setValue ( group + " currentDataFileFormat " , currentDataFileFormat ) ;
settings . setValue ( group + " printZoomFactor " , printZoomFactor ) ;
settings . setValue ( group + " printSizeX " , printSizeX_Millimeter ) ;
settings . setValue ( group + " printSizeY " , printSizeY_Millimeter ) ;
settings . setValue ( group + " printMagnification " , printMagnification ) ;
settings . setValue ( group + " printSetAbsoluteSize " , printSetAbsolutePageSize ) ;
settings . setValue ( group + " printAspect " , printAspect ) ;
settings . setValue ( group + " printKeepAspect " , printKeepAspect ) ;
settings . setValue ( group + " fontSizePrintMultiplier " , fontSizePrintMultiplier ) ;
settings . setValue ( group + " lineWidthPrintMultiplier " , lineWidthPrintMultiplier ) ;
settings . setValue ( group + " exportUnitInMM " , exportUnitInMM ) ;
//settings.setValue(group+"", );
settings . beginGroup ( group + " selections " ) ;
QStringList keys = getDataColumnsByUserSaved . keys ( ) ;
settings . setValue ( " count " , keys . size ( ) ) ;
for ( int i = 0 ; i < keys . size ( ) ; i + + ) {
settings . beginGroup ( QString ( " item%1 " ) . arg ( i ) ) ;
settings . setValue ( " name " , keys [ i ] ) ;
settings . setValue ( " items " , getDataColumnsByUserSaved [ keys [ i ] ] ) ;
settings . endGroup ( ) ;
}
settings . endGroup ( ) ;
}
2019-01-26 19:28:44 +08:00
void JKQTBasePlotter : : loadSettings ( const QSettings & settings , const QString & group ) {
2015-07-11 18:56:02 +08:00
QString g = group + " / " ;
if ( group . isEmpty ( ) ) g = " " ;
2019-02-08 00:24:46 +08:00
plotterStyle . loadSettings ( settings , group ) ;
propagateStyle ( ) ;
2015-07-11 18:56:02 +08:00
aspectRatio = settings . value ( g + " apect_ratio " , aspectRatio ) . toDouble ( ) ;
maintainAspectRatio = settings . value ( g + " maintain_apect_ratio " , maintainAspectRatio ) . toBool ( ) ;
axisAspectRatio = settings . value ( g + " axis_apect_ratio " , axisAspectRatio ) . toDouble ( ) ;
maintainAxisAspectRatio = settings . value ( g + " maintain_axis_apect_ratio " , maintainAxisAspectRatio ) . toBool ( ) ;
2019-02-08 00:24:46 +08:00
mathText . loadSettings ( settings , g + " math_text/ " ) ;
2015-07-11 18:56:02 +08:00
xAxis - > loadSettings ( settings , g + " xaxis_ " ) ;
yAxis - > loadSettings ( settings , g + " yaxis_ " ) ;
loadUserSettings ( ) ;
2023-05-28 05:46:45 +08:00
redrawPlot ( ) ;
2015-07-11 18:56:02 +08:00
}
2020-09-12 05:19:31 +08:00
void JKQTBasePlotter : : correctXYRangeForAspectRatio ( double & xminn , double & xmaxx , double & yminn , double & ymaxx ) const {
if ( xminn > xmaxx ) std : : swap ( xminn , xmaxx ) ;
if ( yminn > ymaxx ) std : : swap ( yminn , ymaxx ) ;
if ( maintainAspectRatio ) {
2020-09-09 02:15:33 +08:00
if ( xAxis - > isLinearAxis ( ) & & yAxis - > isLinearAxis ( ) ) {
2020-09-12 05:19:31 +08:00
const double mid = ( yminn + ymaxx ) / 2.0 ;
const double w = fabs ( xmaxx - xminn ) / aspectRatio ;
//qDebug()<<"mod y from "<<yminn<<"..."<<ymaxx<<" to "<<mid-w/2.0<<"..."<<mid+w/2.0;
yminn = mid - w / 2.0 ;
ymaxx = mid + w / 2.0 ;
2020-09-09 02:15:33 +08:00
} else if ( xAxis - > isLogAxis ( ) & & yAxis - > isLogAxis ( ) ) {
2020-09-12 05:19:31 +08:00
const double mid = ( log ( yminn ) + log ( ymaxx ) ) / 2.0 ;
const double w = fabs ( log ( xmaxx ) - log ( xminn ) ) / aspectRatio ;
yminn = exp ( mid - w / 2.0 ) ;
ymaxx = exp ( mid + w / 2.0 ) ;
2020-09-09 02:15:33 +08:00
}
2015-07-11 18:56:02 +08:00
}
}
2020-09-12 05:19:31 +08:00
2023-03-23 20:55:18 +08:00
void JKQTBasePlotter : : setXY ( double xminn , double xmaxx , double yminn , double ymaxx , bool affectsSecondaryAxes ) {
2020-09-12 05:19:31 +08:00
correctXYRangeForAspectRatio ( xminn , xmaxx , yminn , ymaxx ) ;
2023-03-23 20:55:18 +08:00
const double xminpix = xAxis - > x2p ( xminn ) ;
const double xmaxpix = xAxis - > x2p ( xmaxx ) ;
const double yminpix = yAxis - > x2p ( yminn ) ;
const double ymaxpix = yAxis - > x2p ( ymaxx ) ;
2015-07-11 18:56:02 +08:00
xAxis - > setRange ( xminn , xmaxx ) ;
2020-09-12 05:19:31 +08:00
yAxis - > setRange ( yminn , ymaxx ) ;
2023-03-23 20:55:18 +08:00
if ( affectsSecondaryAxes ) {
for ( auto ax : getXAxes ( false ) ) {
ax - > setRange ( ax - > p2x ( xminpix ) , ax - > p2x ( xmaxpix ) ) ;
}
for ( auto ax : getYAxes ( false ) ) {
ax - > setRange ( ax - > p2x ( yminpix ) , ax - > p2x ( ymaxpix ) ) ;
}
}
2019-02-03 21:04:48 +08:00
if ( emitSignals ) emit zoomChangedLocally ( xAxis - > getMin ( ) , xAxis - > getMax ( ) , yAxis - > getMin ( ) , yAxis - > getMax ( ) , this ) ;
2015-07-11 18:56:02 +08:00
}
2023-03-23 20:55:18 +08:00
void JKQTBasePlotter : : setX ( double xminn , double xmaxx , bool affectsSecondaryAxes ) {
setXY ( xminn , xmaxx , yAxis - > getMin ( ) , yAxis - > getMax ( ) , affectsSecondaryAxes ) ;
2020-09-12 05:19:31 +08:00
}
2023-03-23 20:55:18 +08:00
void JKQTBasePlotter : : setY ( double yminn , double ymaxx , bool affectsSecondaryAxes ) {
setXY ( xAxis - > getMin ( ) , xAxis - > getMax ( ) , yminn , ymaxx , affectsSecondaryAxes ) ;
2015-07-11 18:56:02 +08:00
}
2019-01-20 17:49:29 +08:00
void JKQTBasePlotter : : setAbsoluteX ( double xminn , double xmaxx ) {
2015-07-11 18:56:02 +08:00
xAxis - > setAbsoluteRange ( xminn , xmaxx ) ;
2019-02-03 21:04:48 +08:00
if ( emitSignals ) emit zoomChangedLocally ( xAxis - > getMin ( ) , xAxis - > getMax ( ) , yAxis - > getMin ( ) , yAxis - > getMax ( ) , this ) ;
2015-07-11 18:56:02 +08:00
}
2019-01-20 17:49:29 +08:00
void JKQTBasePlotter : : setAbsoluteY ( double yminn , double ymaxx ) {
2015-07-11 18:56:02 +08:00
yAxis - > setAbsoluteRange ( yminn , ymaxx ) ;
2019-02-03 21:04:48 +08:00
if ( emitSignals ) emit zoomChangedLocally ( xAxis - > getMin ( ) , xAxis - > getMax ( ) , yAxis - > getMin ( ) , yAxis - > getMax ( ) , this ) ;
2015-07-11 18:56:02 +08:00
}
2019-01-20 17:49:29 +08:00
void JKQTBasePlotter : : setAbsoluteXY ( double xminn , double xmaxx , double yminn , double ymaxx ) {
2015-07-11 18:56:02 +08:00
xAxis - > setAbsoluteRange ( xminn , xmaxx ) ;
yAxis - > setAbsoluteRange ( yminn , ymaxx ) ;
2019-02-03 21:04:48 +08:00
if ( emitSignals ) emit zoomChangedLocally ( xAxis - > getMin ( ) , xAxis - > getMax ( ) , yAxis - > getMin ( ) , yAxis - > getMax ( ) , this ) ;
2015-07-11 18:56:02 +08:00
}
2019-01-20 17:49:29 +08:00
void JKQTBasePlotter : : calcPlotScaling ( JKQTPEnhancedPainter & painter ) {
2015-07-11 18:56:02 +08:00
# ifdef JKQTBP_AUTOTIMER
2019-01-20 17:49:29 +08:00
JKQTPAutoOutputTimer jkaat ( QString ( " JKQTBasePlotter[%1]::calcPlotScaling() " ).arg(objectName())) ;
2015-07-11 18:56:02 +08:00
# endif
2019-02-03 21:04:48 +08:00
//qDebug()<<"this="<<this<<" --> calcPlotScaling()";
2015-07-11 18:56:02 +08:00
if ( emitSignals ) emit beforePlotScalingRecalculate ( ) ;
2019-01-26 03:16:04 +08:00
//qDebug()<<"start JKQTBasePlotter::calcPlotScaling";
2015-07-11 18:56:02 +08:00
// if the key is plotted outside , then we have to add place for it (i.e. change the plotBorders
2019-02-08 00:24:46 +08:00
internalPlotBorderBottom = plotterStyle . plotBorderBottom ;
internalPlotBorderLeft = plotterStyle . plotBorderLeft ;
internalPlotBorderRight = plotterStyle . plotBorderRight ;
internalPlotBorderTop = plotterStyle . plotBorderTop ;
internalTitleHeight = 0 ;
2015-07-11 18:56:02 +08:00
if ( ! plotLabel . isEmpty ( ) ) {
2019-02-08 00:24:46 +08:00
QSizeF s = getTextSizeSize ( plotterStyle . plotLabelFontName , plotterStyle . plotLabelFontSize * fontSizeMultiplier , plotLabel , painter ) ;
internalPlotBorderTop + = s . height ( ) * 1.2 ;
internalTitleHeight = s . height ( ) * 1.2 ;
2015-07-11 18:56:02 +08:00
}
double keyWidth , keyHeight ;
QFont f = painter . font ( ) ;
2022-06-03 03:02:23 +08:00
f . setFamily ( JKQTMathTextFontSpecifier : : fromFontSpec ( plotterStyle . defaultFontName ) . fontName ( ) ) ;
2019-02-08 00:24:46 +08:00
f . setPointSizeF ( plotterStyle . keyStyle . fontSize * fontSizeMultiplier ) ;
2015-07-11 18:56:02 +08:00
QFontMetricsF kfm ( f ) ;
getKeyExtent ( painter , & keyWidth , & keyHeight ) ;
2019-02-08 00:24:46 +08:00
internalPlotKeyBorderTop = 0 ;
internalPlotKeyBorderBottom = 0 ;
internalPlotKeyBorderLeft = 0 ;
internalPlotKeyBorderRight = 0 ;
2022-04-22 19:27:31 +08:00
const qreal Xwid = kfm . boundingRect ( ' X ' ) . width ( ) ;
2019-02-08 00:24:46 +08:00
if ( plotterStyle . keyStyle . position = = JKQTPKeyOutsideTopRight ) {
2022-04-22 19:27:31 +08:00
internalPlotKeyBorderTop = keyHeight + 2 * plotterStyle . keyStyle . yMargin * Xwid + ceil ( 2 * plotterStyle . keyStyle . frameWidth ) + plotterStyle . keyStyle . yOffset * Xwid + 2 ;
2019-02-08 00:24:46 +08:00
internalPlotBorderTop = internalPlotBorderTop + internalPlotKeyBorderTop ;
} else if ( plotterStyle . keyStyle . position = = JKQTPKeyOutsideTopLeft ) {
2022-04-22 19:27:31 +08:00
internalPlotKeyBorderTop = keyHeight + 2 * plotterStyle . keyStyle . yMargin * Xwid + ceil ( 2 * plotterStyle . keyStyle . frameWidth ) + plotterStyle . keyStyle . yOffset * Xwid + 2 ;
2019-02-08 00:24:46 +08:00
internalPlotBorderTop = internalPlotBorderTop + internalPlotKeyBorderTop ;
} else if ( plotterStyle . keyStyle . position = = JKQTPKeyOutsideLeftTop ) {
2022-04-22 19:27:31 +08:00
internalPlotKeyBorderLeft = keyWidth + 2 * plotterStyle . keyStyle . xMargin * Xwid + ceil ( 2 * plotterStyle . keyStyle . frameWidth ) + plotterStyle . keyStyle . xOffset * Xwid + 2 ;
2019-02-08 00:24:46 +08:00
internalPlotBorderLeft = internalPlotBorderLeft + internalPlotKeyBorderLeft ;
} else if ( plotterStyle . keyStyle . position = = JKQTPKeyOutsideLeftBottom ) {
2022-04-22 19:27:31 +08:00
internalPlotKeyBorderLeft = keyWidth + 2 * plotterStyle . keyStyle . xMargin * Xwid + ceil ( 2 * plotterStyle . keyStyle . frameWidth ) + plotterStyle . keyStyle . xOffset * Xwid + 2 ;
2019-02-08 00:24:46 +08:00
internalPlotBorderLeft = internalPlotBorderLeft + internalPlotKeyBorderLeft ;
} else if ( plotterStyle . keyStyle . position = = JKQTPKeyOutsideBottomRight ) {
2022-04-22 19:27:31 +08:00
internalPlotKeyBorderBottom = keyHeight + 2 * plotterStyle . keyStyle . yMargin * Xwid + ceil ( 2 * plotterStyle . keyStyle . frameWidth ) + plotterStyle . keyStyle . yOffset * Xwid + 2 ;
2019-02-08 00:24:46 +08:00
internalPlotBorderBottom = internalPlotBorderBottom + internalPlotKeyBorderBottom ;
} else if ( plotterStyle . keyStyle . position = = JKQTPKeyOutsideBottomLeft ) {
2022-04-22 19:27:31 +08:00
internalPlotKeyBorderBottom = keyHeight + 2 * plotterStyle . keyStyle . yMargin * Xwid + ceil ( 2 * plotterStyle . keyStyle . frameWidth ) + plotterStyle . keyStyle . yOffset * Xwid + 2 ;
2019-02-08 00:24:46 +08:00
internalPlotBorderBottom = internalPlotBorderBottom + internalPlotKeyBorderBottom ;
} else if ( plotterStyle . keyStyle . position = = JKQTPKeyOutsideRightTop ) {
2022-04-22 19:27:31 +08:00
internalPlotKeyBorderRight = keyWidth + 2 * plotterStyle . keyStyle . xMargin * Xwid + ceil ( 2 * plotterStyle . keyStyle . frameWidth ) + plotterStyle . keyStyle . xOffset * Xwid + 2 ;
2019-02-08 00:24:46 +08:00
internalPlotBorderRight = internalPlotBorderRight + internalPlotKeyBorderRight ;
} else if ( plotterStyle . keyStyle . position = = JKQTPKeyOutsideRightBottom ) {
2022-04-22 19:27:31 +08:00
internalPlotKeyBorderRight = keyWidth + 2 * plotterStyle . keyStyle . xMargin * Xwid + ceil ( 2 * plotterStyle . keyStyle . frameWidth ) + plotterStyle . keyStyle . xOffset * Xwid + 2 ;
2019-02-08 00:24:46 +08:00
internalPlotBorderRight = internalPlotBorderRight + internalPlotKeyBorderRight ;
2015-07-11 18:56:02 +08:00
}
/*if (displayMousePosition) {
QFontMetrics fm = fontMetrics ( ) ;
2023-03-23 20:55:18 +08:00
QString test = " Aquator " ;
2015-07-11 18:56:02 +08:00
int labelHeight = fm . size ( Qt : : TextSingleLine , test ) . height ( ) * 1.5 ;
2018-11-18 18:59:30 +08:00
//if (mousePosLabel!=nullptr) labelHeight=mousePosLabel->height();
2019-02-08 00:24:46 +08:00
internalPlotBorderTop = internalPlotBorderTop + ( labelHeight - plotBorderTop ) * 1.1 ;
2015-07-11 18:56:02 +08:00
} */
// read additional size required for coordinate axes
QSizeF s = xAxis - > getSize1 ( painter ) ;
2019-02-08 00:24:46 +08:00
internalPlotBorderBottom + = s . height ( ) ;
2015-07-11 18:56:02 +08:00
s = xAxis - > getSize2 ( painter ) ;
2019-02-08 00:24:46 +08:00
internalPlotBorderTop + = s . height ( ) ;
2015-07-11 18:56:02 +08:00
s = yAxis - > getSize1 ( painter ) ;
2019-02-08 00:24:46 +08:00
internalPlotBorderLeft + = s . width ( ) ;
2015-07-11 18:56:02 +08:00
s = yAxis - > getSize2 ( painter ) ;
2019-02-08 00:24:46 +08:00
internalPlotBorderRight + = s . width ( ) ;
2015-07-11 18:56:02 +08:00
2023-03-23 20:55:18 +08:00
internalPlotBorderTop_notIncludingAxisAndOutsidePlotSections = internalPlotBorderTop ;
internalPlotBorderLeft_notIncludingAxisAndOutsidePlotSections = internalPlotBorderLeft ;
internalPlotBorderBottom_notIncludingAxisAndOutsidePlotSections = internalPlotBorderBottom ;
internalPlotBorderRight_notIncludingAxisAndOutsidePlotSections = internalPlotBorderRight ;
// read size required by secondary axes
for ( const auto & ax : qAsConst ( secondaryYAxis ) ) {
internalPlotBorderLeft + = ax - > getSize1 ( painter ) . width ( ) + plotterStyle . secondaryAxisSeparation ;
internalPlotBorderRight + = ax - > getSize2 ( painter ) . width ( ) + plotterStyle . secondaryAxisSeparation ;
}
for ( const auto & ax : qAsConst ( secondaryXAxis ) ) {
internalPlotBorderBottom + = ax - > getSize1 ( painter ) . height ( ) + plotterStyle . secondaryAxisSeparation ;
internalPlotBorderTop + = ax - > getSize2 ( painter ) . height ( ) + plotterStyle . secondaryAxisSeparation ;
}
2019-02-08 00:24:46 +08:00
internalPlotBorderTop_notIncludingOutsidePlotSections = internalPlotBorderTop ;
internalPlotBorderLeft_notIncludingOutsidePlotSections = internalPlotBorderLeft ;
internalPlotBorderBottom_notIncludingOutsidePlotSections = internalPlotBorderBottom ;
internalPlotBorderRight_notIncludingOutsidePlotSections = internalPlotBorderRight ;
2015-07-11 18:56:02 +08:00
// read additional space required by graphs
for ( int i = 0 ; i < graphs . size ( ) ; i + + ) {
2019-02-03 21:04:48 +08:00
if ( graphs [ i ] - > isVisible ( ) ) {
2015-07-11 18:56:02 +08:00
int leftSpace , rightSpace , topSpace , bottomSpace ;
graphs [ i ] - > getOutsideSize ( painter , leftSpace , rightSpace , topSpace , bottomSpace ) ;
2019-02-08 00:24:46 +08:00
internalPlotBorderBottom + = bottomSpace ;
internalPlotBorderTop + = topSpace ;
internalPlotBorderLeft + = leftSpace ;
internalPlotBorderRight + = rightSpace ;
2015-07-11 18:56:02 +08:00
}
}
2019-01-26 03:16:04 +08:00
//qDebug()<<" end JKQTBasePlotter::calcPlotScaling";
2015-07-11 18:56:02 +08:00
// synchronize to a master-plotter
2019-02-03 21:04:48 +08:00
if ( masterPlotterX ) {
2015-07-11 18:56:02 +08:00
if ( masterSynchronizeWidth ) {
2019-02-08 00:24:46 +08:00
internalPlotBorderLeft = masterPlotterX - > internalPlotBorderLeft ;
internalPlotBorderRight = masterPlotterX - > internalPlotBorderRight ;
2015-07-11 18:56:02 +08:00
}
2019-02-03 21:04:48 +08:00
}
if ( masterPlotterY ) {
2015-07-11 18:56:02 +08:00
if ( masterSynchronizeHeight ) {
2019-02-08 00:24:46 +08:00
internalPlotBorderTop = masterPlotterY - > internalPlotBorderTop ;
internalPlotBorderBottom = masterPlotterY - > internalPlotBorderBottom ;
2015-07-11 18:56:02 +08:00
}
}
// first we calculate the width and height of the plot from the widget dimensions and
// the supplied border sizes
2019-06-21 21:46:53 +08:00
internalPlotWidth = jkqtp_roundTo < int > ( static_cast < double > ( widgetWidth ) / paintMagnification - internalPlotBorderLeft - internalPlotBorderRight ) ;
internalPlotHeight = jkqtp_roundTo < int > ( static_cast < double > ( widgetHeight ) / paintMagnification - internalPlotBorderTop - internalPlotBorderBottom ) ;
2015-07-11 18:56:02 +08:00
////////////////////////////////////////////////////////////////////
// ENSURE ASPECT RATIO (if activated)
////////////////////////////////////////////////////////////////////
if ( maintainAspectRatio & & ( ! xAxis - > isLogAxis ( ) ) & & ( ! xAxis - > isLogAxis ( ) ) ) {
2019-02-08 00:24:46 +08:00
double currRatio = static_cast < double > ( internalPlotWidth ) / static_cast < double > ( internalPlotHeight ) ;
double newPlotWidth = internalPlotWidth ;
double newPlotHeight = internalPlotHeight ;
2015-07-11 18:56:02 +08:00
double dx = 0 ;
double dy = 0 ;
2019-06-21 21:46:53 +08:00
if ( jkqtp_approximatelyUnequal ( currRatio , aspectRatio ) ) {
2015-07-11 18:56:02 +08:00
if ( aspectRatio > = currRatio ) {
2019-02-08 00:24:46 +08:00
newPlotWidth = aspectRatio * static_cast < double > ( internalPlotHeight ) ;
2015-07-11 18:56:02 +08:00
} else {
2019-02-08 00:24:46 +08:00
newPlotHeight = static_cast < double > ( internalPlotWidth ) / aspectRatio ;
2015-07-11 18:56:02 +08:00
}
2019-02-08 00:24:46 +08:00
dx = internalPlotWidth - newPlotWidth ;
dy = internalPlotHeight - newPlotHeight ;
2015-07-11 18:56:02 +08:00
if ( dx < 0 ) {
2019-02-08 00:24:46 +08:00
newPlotWidth = internalPlotWidth ;
newPlotHeight = static_cast < double > ( internalPlotWidth ) / aspectRatio ;
2015-07-11 18:56:02 +08:00
} else if ( dy < 0 ) {
2019-02-08 00:24:46 +08:00
newPlotWidth = aspectRatio * static_cast < double > ( internalPlotHeight ) ;
newPlotHeight = internalPlotHeight ;
2015-07-11 18:56:02 +08:00
}
2019-02-08 00:24:46 +08:00
dx = internalPlotWidth - newPlotWidth ;
dy = internalPlotHeight - newPlotHeight ;
2015-07-11 18:56:02 +08:00
if ( ( dx < 0 ) | | ( dy < 0 ) ) {
2019-02-08 00:24:46 +08:00
newPlotWidth = internalPlotWidth ;
newPlotHeight = internalPlotHeight ;
2015-07-11 18:56:02 +08:00
}
}
2019-02-08 00:24:46 +08:00
//if (newPlotWidth>widgetWidth-internalPlotBorderLeft-internalPlotBorderRight) newPlotWidth=widgetWidth-internalPlotBorderLeft-internalPlotBorderRight;
//if (newPlotHeight>widgetHeight-internalPlotBorderTop-internalPlotBorderBottom) newPlotHeight=widgetHeight-internalPlotBorderTop-internalPlotBorderBottom;
dx = internalPlotWidth - newPlotWidth ;
dy = internalPlotHeight - newPlotHeight ;
internalPlotBorderBottom + = dy / 2.0 ;
internalPlotBorderTop + = dy / 2.0 ;
internalPlotBorderLeft + = dx / 2.0 ;
internalPlotBorderRight + = dx / 2.0 ;
2019-06-21 21:46:53 +08:00
internalPlotWidth = jkqtp_roundTo < int > ( static_cast < double > ( widgetWidth ) / paintMagnification - internalPlotBorderLeft - internalPlotBorderRight ) ;
internalPlotHeight = jkqtp_roundTo < int > ( static_cast < double > ( widgetHeight ) / paintMagnification - internalPlotBorderTop - internalPlotBorderBottom ) ;
2015-07-11 18:56:02 +08:00
}
2023-03-23 20:55:18 +08:00
for ( auto ax : getAxes ( true ) ) {
ax - > calcPlotScaling ( true ) ;
}
2015-07-11 18:56:02 +08:00
////////////////////////////////////////////////////////////////////
// ENSURE ASPECT RATIO OF PLOT 1x1 PIXELS (if activated)
////////////////////////////////////////////////////////////////////
if ( maintainAxisAspectRatio & & ( ! xAxis - > isLogAxis ( ) ) & & ( ! xAxis - > isLogAxis ( ) ) ) {
double cplotWidth = fabs ( xAxis - > getMax ( ) - xAxis - > getMin ( ) ) ;
double newPlotWidth = cplotWidth ;
double xmid = ( xAxis - > getMax ( ) + xAxis - > getMin ( ) ) / 2.0 ;
double cplotHeight = fabs ( yAxis - > getMax ( ) - yAxis - > getMin ( ) ) ;
double newPlotHeight = cplotHeight ;
double ymid = ( yAxis - > getMax ( ) + yAxis - > getMin ( ) ) / 2.0 ;
double currRatio = fabs ( cplotWidth / cplotHeight ) ;
2019-06-21 21:46:53 +08:00
if ( jkqtp_approximatelyUnequal ( currRatio , axisAspectRatio ) ) {
2015-07-11 18:56:02 +08:00
//if (axisAspectRatio<=currRatio) {
newPlotWidth = axisAspectRatio * cplotHeight ;
//} else {
// newPlotHeight=cplotWidth/axisAspectRatio;
//}
}
xAxis - > setRange ( xmid - newPlotWidth / 2.0 , xmid + newPlotWidth / 2.0 ) ;
yAxis - > setRange ( ymid - newPlotHeight / 2.0 , ymid + newPlotHeight / 2.0 ) ;
2023-03-23 20:55:18 +08:00
for ( auto ax : getAxes ( true ) ) {
ax - > calcPlotScaling ( true ) ;
}
2015-07-11 18:56:02 +08:00
}
2019-02-03 21:04:48 +08:00
//if (emitPlotSignals) emit plotScalingRecalculated();
emit plotScalingRecalculated ( ) ;
2015-07-11 18:56:02 +08:00
}
2019-02-08 00:24:46 +08:00
void JKQTBasePlotter : : drawSystemGrid ( JKQTPEnhancedPainter & painter ) {
2015-07-11 18:56:02 +08:00
# ifdef JKQTBP_AUTOTIMER
2019-02-08 00:24:46 +08:00
JKQTPAutoOutputTimer jkaaot ( " JKQTBasePlotter::drawSystemGrid " ) ;
2015-07-11 18:56:02 +08:00
# endif
2019-02-08 00:24:46 +08:00
//qDebug()<<"start JKQTBasePlotter::drawSystemGrid";
2023-03-23 20:55:18 +08:00
for ( auto ax : getAxes ( true ) ) {
ax - > drawGrids ( painter ) ;
}
2019-02-08 00:24:46 +08:00
//qDebug()<<" end JKQTBasePlotter::drawSystemGrid";
2015-07-11 18:56:02 +08:00
}
2019-02-08 00:24:46 +08:00
void JKQTBasePlotter : : drawSystemXAxis ( JKQTPEnhancedPainter & painter ) {
2015-07-11 18:56:02 +08:00
# ifdef JKQTBP_AUTOTIMER
2019-02-08 00:24:46 +08:00
JKQTPAutoOutputTimer jkaaot ( " JKQTBasePlotter::drawSystemXAxis " ) ;
2015-07-11 18:56:02 +08:00
# endif
2023-03-23 20:55:18 +08:00
//qDebug()<<"start JKQTBasePlotter::drawSystemXAxis";
2015-07-11 18:56:02 +08:00
xAxis - > drawAxes ( painter ) ;
2019-02-08 00:24:46 +08:00
//qDebug()<<" end JKQTBasePlotter::drawSystemXAxis";
2023-03-23 20:55:18 +08:00
if ( secondaryXAxis . size ( ) > 0 ) {
double ibMove1 = xAxis - > getSize1 ( painter ) . height ( ) ;
if ( ibMove1 > 0 ) ibMove1 + = plotterStyle . secondaryAxisSeparation ;
double ibMove2 = xAxis - > getSize2 ( painter ) . height ( ) ;
if ( ibMove2 > 0 ) ibMove1 + = plotterStyle . secondaryAxisSeparation ;
for ( auto & ax : secondaryXAxis ) {
ax - > drawAxes ( painter , ibMove1 , ibMove2 ) ;
const double add1 = ax - > getSize1 ( painter ) . height ( ) ;
const double add2 = ax - > getSize2 ( painter ) . height ( ) ;
if ( add1 > 0 ) ibMove1 + = add1 + plotterStyle . secondaryAxisSeparation ;
if ( add2 > 0 ) ibMove2 + = add2 + plotterStyle . secondaryAxisSeparation ;
}
}
2015-07-11 18:56:02 +08:00
}
2019-02-08 00:24:46 +08:00
void JKQTBasePlotter : : drawSystemYAxis ( JKQTPEnhancedPainter & painter ) {
2015-07-11 18:56:02 +08:00
# ifdef JKQTBP_AUTOTIMER
2019-02-08 00:24:46 +08:00
JKQTPAutoOutputTimer jkaaot ( " JKQTBasePlotter::drawSystemYAxis " ) ;
2015-07-11 18:56:02 +08:00
# endif
2019-02-08 00:24:46 +08:00
//qDebug()<<"start JKQTBasePlotter::drawSystemYAxis";
2015-07-11 18:56:02 +08:00
yAxis - > drawAxes ( painter ) ;
2019-02-08 00:24:46 +08:00
//qDebug()<<" end JKQTBasePlotter::drawSystemYAxis";
2023-03-23 20:55:18 +08:00
if ( secondaryYAxis . size ( ) > 0 ) {
double ibMove1 = yAxis - > getSize1 ( painter ) . width ( ) ;
if ( ibMove1 > 0 ) ibMove1 + = plotterStyle . secondaryAxisSeparation ;
double ibMove2 = yAxis - > getSize2 ( painter ) . width ( ) ;
if ( ibMove2 > 0 ) ibMove1 + = plotterStyle . secondaryAxisSeparation ;
for ( auto & ax : secondaryYAxis ) {
ax - > drawAxes ( painter , ibMove1 , ibMove2 ) ;
const double add1 = ax - > getSize1 ( painter ) . width ( ) ;
const double add2 = ax - > getSize2 ( painter ) . width ( ) ;
if ( add1 > 0 ) ibMove1 + = add1 + plotterStyle . secondaryAxisSeparation ;
if ( add2 > 0 ) ibMove2 + = add2 + plotterStyle . secondaryAxisSeparation ;
}
}
2015-07-11 18:56:02 +08:00
}
2020-09-26 21:58:58 +08:00
JKQTBasePlotter : : JKQTPPen JKQTBasePlotter : : getPlotStyle ( int i , JKQTPPlotStyleType type ) const {
2015-07-11 18:56:02 +08:00
int colorI = - 1 ;
int styleI = 0 ;
2019-02-08 00:24:46 +08:00
int symbolI = 0 ;
int brushI = 0 ;
2015-07-11 18:56:02 +08:00
for ( int k = 0 ; k < = i ; k + + ) {
colorI + + ;
2020-09-26 21:58:58 +08:00
if ( colorI > = plotterStyle . graphsStyle . defaultGraphColors . size ( ) ) {
2015-07-11 18:56:02 +08:00
styleI + + ;
2019-02-08 00:24:46 +08:00
brushI + + ;
2015-07-11 18:56:02 +08:00
colorI = 0 ;
2020-09-26 21:58:58 +08:00
if ( styleI > = plotterStyle . graphsStyle . defaultGraphPenStyles . size ( ) ) styleI = 0 ;
if ( brushI > = plotterStyle . graphsStyle . defaultGraphFillStyles . size ( ) ) brushI = 0 ;
2019-02-08 00:24:46 +08:00
}
symbolI + + ;
2020-09-26 21:58:58 +08:00
if ( symbolI > = plotterStyle . graphsStyle . defaultGraphSymbols . size ( ) ) {
2019-02-08 00:24:46 +08:00
symbolI = 0 ;
2015-07-11 18:56:02 +08:00
}
}
JKQTPPen p ;
//std::cout<<"plotstyle "<<i<<std::endl;
//std::cout<<"color "<<colorI<<std::endl;
//std::cout<<"style "<<styleI<<std::endl;
2020-09-26 21:58:58 +08:00
const JKQTGraphsSpecificStyleProperties & baseProps = plotterStyle . graphsStyle . getGraphStyleByType ( type ) ;
Qt : : PenStyle basePenStyle = plotterStyle . graphsStyle . defaultGraphPenStyles [ styleI ] ;
Qt : : BrushStyle basebrushStyle = plotterStyle . graphsStyle . defaultGraphFillStyles [ brushI ] ;
JKQTPGraphSymbols baseSymbol = plotterStyle . graphsStyle . defaultGraphSymbols [ symbolI ] ;
QColor baseColor = plotterStyle . graphsStyle . defaultGraphColors [ colorI ] ;
2022-09-26 08:08:01 +08:00
double baseWidth = baseProps . defaultLineWidth ;
2020-09-26 21:58:58 +08:00
if ( type = = JKQTPPlotStyleType : : Annotation | | type = = JKQTPPlotStyleType : : Geometric ) {
baseColor = plotterStyle . graphsStyle . annotationStyle . defaultColor ;
basePenStyle = plotterStyle . graphsStyle . annotationStyle . defaultLineStyle ;
basebrushStyle = plotterStyle . graphsStyle . annotationStyle . defaultFillStyle ;
baseSymbol = plotterStyle . graphsStyle . annotationStyle . defaultSymbol ;
}
2020-09-27 22:11:58 +08:00
if ( type = = JKQTPPlotStyleType : : Barchart | | type = = JKQTPPlotStyleType : : Boxplot | | type = = JKQTPPlotStyleType : : Impulses ) {
basePenStyle = Qt : : SolidLine ;
}
2022-09-26 08:08:01 +08:00
if ( type = = JKQTPPlotStyleType : : Barchart ) {
basebrushStyle = Qt : : SolidPattern ;
}
2020-09-28 21:37:45 +08:00
if ( type = = JKQTPPlotStyleType : : Boxplot ) {
basebrushStyle = Qt : : SolidPattern ;
}
2022-09-26 08:08:01 +08:00
if ( type = = JKQTPPlotStyleType : : Impulses ) {
}
2020-09-26 21:58:58 +08:00
const QColor lineColor = JKQTPGetDerivedColor ( baseProps . graphColorDerivationMode , baseColor ) ;
const QColor errorColor = JKQTPGetDerivedColor ( baseProps . errorColorDerivationMode , baseColor ) ;
p . setColor ( lineColor ) ;
p . setStyle ( basePenStyle ) ;
p . setSymbolType ( baseSymbol ) ;
p . setFillStyle ( basebrushStyle ) ;
2020-09-27 22:11:58 +08:00
p . setErrorFillStyle ( Qt : : SolidPattern ) ;
2022-09-26 08:08:01 +08:00
p . setWidthF ( qMax ( JKQTPlotterDrawingTools : : ABS_MIN_LINEWIDTH , baseWidth ) ) ;
2020-09-26 21:58:58 +08:00
p . setFillColor ( JKQTPGetDerivedColor ( baseProps . fillColorDerivationMode , baseColor ) ) ;
p . setErrorLineColor ( errorColor ) ;
p . setErrorFillColor ( JKQTPGetDerivedColor ( baseProps . errorFillColorDerivationMode , baseColor ) ) ;
2020-09-27 22:11:58 +08:00
//qDebug()<<"baseColor="<<baseColor<<"/"<<baseColor.alphaF()*100.0<<"% --> ErrorFillColor="<<p.errorFillColor()<<"/"<<p.errorFillColor().alphaF()*100.0<<"%";
2020-09-26 21:58:58 +08:00
p . setErrorLineWidth ( qMax ( JKQTPlotterDrawingTools : : ABS_MIN_LINEWIDTH , baseProps . defaultErrorIndicatorWidth ) ) ;
p . setSymbolSize ( qMax ( JKQTPlotterDrawingTools : : ABS_MIN_LINEWIDTH , baseProps . defaultSymbolSize ) ) ;
p . setSymbolFillColor ( JKQTPGetDerivedColor ( baseProps . symbolFillColorDerivationMode , baseColor ) ) ;
2020-09-27 22:11:58 +08:00
p . setSymbolLineWidthF ( qMax ( JKQTPlotterDrawingTools : : ABS_MIN_LINEWIDTH , baseProps . defaultSymbolLineWidth ) ) ;
2015-07-11 18:56:02 +08:00
return p ;
}
2019-01-20 17:49:29 +08:00
int JKQTBasePlotter : : getNextStyle ( ) {
2015-07-11 18:56:02 +08:00
int res = 0 ;
while ( usedStyles . contains ( res ) ) res + + ;
//std::cout<<res<<std::endl;
usedStyles . push_back ( res ) ;
return res ;
} ;
2019-02-08 00:24:46 +08:00
void JKQTBasePlotter : : drawKey ( JKQTPEnhancedPainter & painter ) {
2015-07-11 18:56:02 +08:00
# ifdef JKQTBP_AUTOTIMER
2019-01-20 17:49:29 +08:00
JKQTPAutoOutputTimer jkaaot ( " JKQTBasePlotter::plotKey " ) ;
2015-07-11 18:56:02 +08:00
# endif
2019-01-26 03:16:04 +08:00
//qDebug()<<"start JKQTBasePlotter::plotKey";
2015-07-11 18:56:02 +08:00
2022-06-03 03:02:23 +08:00
QFont kf ( JKQTMathTextFontSpecifier : : fromFontSpec ( plotterStyle . defaultFontName ) . fontName ( ) , 10 ) ;
2019-06-21 21:46:53 +08:00
kf . setPointSizeF ( plotterStyle . keyStyle . fontSize * fontSizeMultiplier ) ;
2015-07-11 18:56:02 +08:00
QFontMetricsF kfm ( kf ) ;
2022-04-22 19:27:31 +08:00
const qreal Xwid = kfm . boundingRect ( ' X ' ) . width ( ) ;
2015-07-11 18:56:02 +08:00
// get the size of the key and if keyWidth>0 && keyHeight>0 draw the frame and the contents
double keyWidth = 0 ;
double keyHeight = 0 ;
getKeyExtent ( painter , & keyWidth , & keyHeight ) ;
2022-04-22 19:27:31 +08:00
double keyRectangleWidth = keyWidth + 2.0 * plotterStyle . keyStyle . xMargin * Xwid + 2.0 * plotterStyle . keyStyle . frameWidth * lineWidthPrintMultiplier ;
double keyRectangleHeight = keyHeight + 2.0 * plotterStyle . keyStyle . yMargin * Xwid + 2.0 * plotterStyle . keyStyle . frameWidth * lineWidthPrintMultiplier ;
2015-07-11 18:56:02 +08:00
if ( ( keyWidth > 0 ) & & ( keyHeight > 0 ) ) {
// key position
2019-06-21 21:46:53 +08:00
//double x0,y0; // Position without plotterStyle.keyStyle.xOffset/plotterStyle.keyStyle.yOffset
//double x,y; // position of the key rectangle (=x0+plotterStyle.keyStyle.xOffset, y0+plotterStyle.keyStyle.yOffset)
// default: inside top-right
double x0 = internalPlotBorderLeft + internalPlotWidth - keyRectangleWidth ;
2022-04-22 19:27:31 +08:00
double x = x0 - plotterStyle . keyStyle . xOffset * Xwid ;
2019-06-21 21:46:53 +08:00
double y0 = internalPlotBorderTop ;
2022-04-22 19:27:31 +08:00
double y = y0 + plotterStyle . keyStyle . yOffset * Xwid ;
2019-06-21 21:46:53 +08:00
2019-02-08 00:24:46 +08:00
switch ( plotterStyle . keyStyle . position ) {
2019-01-20 17:49:29 +08:00
case JKQTPKeyOutsideTopRight :
2019-02-08 00:24:46 +08:00
x0 = internalPlotBorderLeft + internalPlotWidth + internalPlotBorderRight - keyRectangleWidth ;
2022-04-22 19:27:31 +08:00
x = x0 - plotterStyle . keyStyle . xOffset * Xwid ;
2019-02-08 00:24:46 +08:00
y0 = internalTitleHeight ;
2022-04-22 19:27:31 +08:00
y = y0 + plotterStyle . keyStyle . yOffset * Xwid ;
2015-07-11 18:56:02 +08:00
break ;
2019-01-20 17:49:29 +08:00
case JKQTPKeyOutsideTopLeft :
2019-02-08 00:24:46 +08:00
x0 = internalPlotBorderLeft ;
2022-04-22 19:27:31 +08:00
x = x0 + plotterStyle . keyStyle . xOffset * Xwid ;
2019-02-08 00:24:46 +08:00
y0 = internalTitleHeight ;
2022-04-22 19:27:31 +08:00
y = y0 + plotterStyle . keyStyle . yOffset * Xwid ;
2015-07-11 18:56:02 +08:00
break ;
2019-01-20 17:49:29 +08:00
case JKQTPKeyOutsideBottomRight :
2019-02-08 00:24:46 +08:00
x0 = internalPlotBorderLeft + internalPlotWidth - keyRectangleWidth ;
2022-04-22 19:27:31 +08:00
x = x0 - plotterStyle . keyStyle . xOffset * Xwid ;
2019-02-08 00:24:46 +08:00
y0 = internalPlotBorderTop + internalPlotHeight + internalPlotBorderBottom - keyRectangleHeight ;
2022-04-22 19:27:31 +08:00
y = y0 - plotterStyle . keyStyle . yOffset * Xwid ;
2015-07-11 18:56:02 +08:00
break ;
2019-01-20 17:49:29 +08:00
case JKQTPKeyOutsideBottomLeft :
2019-02-08 00:24:46 +08:00
x0 = internalPlotBorderLeft ;
2022-04-22 19:27:31 +08:00
x = x0 + plotterStyle . keyStyle . xOffset * Xwid ;
2019-02-08 00:24:46 +08:00
y0 = internalPlotBorderTop + internalPlotHeight + internalPlotBorderBottom - keyRectangleHeight ;
2022-04-22 19:27:31 +08:00
y = y0 - plotterStyle . keyStyle . yOffset * Xwid ;
2015-07-11 18:56:02 +08:00
break ;
2019-01-20 17:49:29 +08:00
case JKQTPKeyOutsideRightTop :
2019-02-08 00:24:46 +08:00
x0 = internalPlotBorderLeft + internalPlotWidth + internalPlotBorderRight - keyRectangleWidth ;
2022-04-22 19:27:31 +08:00
x = x0 - plotterStyle . keyStyle . xOffset * Xwid ;
2019-02-08 00:24:46 +08:00
y0 = internalPlotBorderTop ;
2022-04-22 19:27:31 +08:00
y = y0 + plotterStyle . keyStyle . yOffset * Xwid ;
2015-07-11 18:56:02 +08:00
break ;
2019-01-20 17:49:29 +08:00
case JKQTPKeyOutsideRightBottom :
2019-02-08 00:24:46 +08:00
x0 = internalPlotBorderLeft + internalPlotWidth + internalPlotBorderRight - keyRectangleWidth ;
2022-04-22 19:27:31 +08:00
x = x0 - plotterStyle . keyStyle . xOffset * Xwid ;
2019-02-08 00:24:46 +08:00
y0 = internalPlotBorderTop + internalPlotHeight - keyRectangleHeight ;
2022-04-22 19:27:31 +08:00
y = y0 - plotterStyle . keyStyle . yOffset * Xwid ;
2015-07-11 18:56:02 +08:00
break ;
2019-01-20 17:49:29 +08:00
case JKQTPKeyOutsideLeftTop :
2019-02-08 00:24:46 +08:00
x0 = 0 ;
2022-04-22 19:27:31 +08:00
x = x0 + plotterStyle . keyStyle . xOffset * Xwid ;
2019-02-08 00:24:46 +08:00
y0 = internalPlotBorderTop ;
2022-04-22 19:27:31 +08:00
y = y0 + plotterStyle . keyStyle . yOffset * Xwid ;
2015-07-11 18:56:02 +08:00
break ;
2019-01-20 17:49:29 +08:00
case JKQTPKeyOutsideLeftBottom :
2019-02-08 00:24:46 +08:00
x0 = 0 ;
2022-04-22 19:27:31 +08:00
x = x0 + plotterStyle . keyStyle . xOffset * Xwid ;
2019-02-08 00:24:46 +08:00
y0 = internalPlotBorderTop + internalPlotHeight - keyRectangleHeight ;
2022-04-22 19:27:31 +08:00
y = y0 - plotterStyle . keyStyle . yOffset * Xwid ;
2015-07-11 18:56:02 +08:00
break ;
2019-01-20 17:49:29 +08:00
case JKQTPKeyInsideBottomRight :
2019-02-08 00:24:46 +08:00
x0 = internalPlotBorderLeft + internalPlotWidth - keyRectangleWidth ;
2022-04-22 19:27:31 +08:00
x = x0 - plotterStyle . keyStyle . xOffset * Xwid ;
2019-02-08 00:24:46 +08:00
y0 = internalPlotBorderTop + internalPlotHeight - keyRectangleHeight ;
2022-04-22 19:27:31 +08:00
y = y0 - plotterStyle . keyStyle . yOffset * Xwid ;
2015-07-11 18:56:02 +08:00
break ;
2019-01-20 17:49:29 +08:00
case JKQTPKeyInsideBottomLeft :
2019-02-08 00:24:46 +08:00
x0 = internalPlotBorderLeft ;
2022-04-22 19:27:31 +08:00
x = x0 + plotterStyle . keyStyle . xOffset * Xwid ;
2019-02-08 00:24:46 +08:00
y0 = internalPlotBorderTop + internalPlotHeight - keyRectangleHeight ;
2022-04-22 19:27:31 +08:00
y = y0 - plotterStyle . keyStyle . yOffset * Xwid ;
2015-07-11 18:56:02 +08:00
break ;
2019-01-20 17:49:29 +08:00
case JKQTPKeyInsideTopLeft :
2019-02-08 00:24:46 +08:00
x0 = internalPlotBorderLeft ;
2022-04-22 19:27:31 +08:00
x = x0 + plotterStyle . keyStyle . xOffset * Xwid ;
2019-02-08 00:24:46 +08:00
y0 = internalPlotBorderTop ;
2022-04-22 19:27:31 +08:00
y = y0 + plotterStyle . keyStyle . yOffset * Xwid ;
2015-07-11 18:56:02 +08:00
break ;
2019-01-20 17:49:29 +08:00
case JKQTPKeyInsideTopRight :
2019-02-08 00:24:46 +08:00
x0 = internalPlotBorderLeft + internalPlotWidth - keyRectangleWidth ;
2022-04-22 19:27:31 +08:00
x = x0 - plotterStyle . keyStyle . xOffset * Xwid ;
2019-02-08 00:24:46 +08:00
y0 = internalPlotBorderTop ;
2022-04-22 19:27:31 +08:00
y = y0 + plotterStyle . keyStyle . yOffset * Xwid ;
2015-07-11 18:56:02 +08:00
break ;
}
2019-02-08 00:24:46 +08:00
QRectF rectKey ;
{
// save old brushes and pens
painter . save ( ) ; auto __finalpaint = JKQTPFinally ( [ & painter ] ( ) { painter . restore ( ) ; } ) ;
QPen pf = painter . pen ( ) ;
pf . setColor ( plotterStyle . keyStyle . frameColor ) ;
2019-05-13 04:22:48 +08:00
pf . setWidthF ( qMax ( JKQTPlotterDrawingTools : : ABS_MIN_LINEWIDTH , pt2px ( painter , plotterStyle . keyStyle . frameWidth * lineWidthMultiplier ) ) ) ;
2019-02-08 00:24:46 +08:00
pf . setStyle ( Qt : : SolidLine ) ;
2019-04-25 01:33:51 +08:00
painter . setBrush ( plotterStyle . keyStyle . backgroundBrush ) ;
2019-02-08 00:24:46 +08:00
if ( ! plotterStyle . keyStyle . frameVisible ) {
2019-04-25 01:33:51 +08:00
painter . setPen ( Qt : : NoPen ) ;
2019-02-08 00:24:46 +08:00
} else {
painter . setPen ( pf ) ;
}
2015-07-11 18:56:02 +08:00
2019-02-08 00:24:46 +08:00
rectKey = QRectF ( x , y , keyRectangleWidth , keyRectangleHeight ) ;
if ( plotterStyle . keyStyle . frameRounding < = 0 ) {
painter . drawRect ( rectKey ) ;
} else {
painter . drawRoundedRect ( rectKey , pt2px ( painter , plotterStyle . keyStyle . frameRounding ) , pt2px ( painter , plotterStyle . keyStyle . frameRounding ) ) ;
}
2022-04-22 19:27:31 +08:00
y = y + plotterStyle . keyStyle . yMargin * Xwid + plotterStyle . keyStyle . frameWidth * lineWidthMultiplier / 2.0 ;
x = x + plotterStyle . keyStyle . xMargin * Xwid + plotterStyle . keyStyle . frameWidth * lineWidthMultiplier / 2.0 ;
2015-07-11 18:56:02 +08:00
2019-02-08 00:24:46 +08:00
painter . setPen ( pf ) ;
2015-07-11 18:56:02 +08:00
2019-02-08 00:24:46 +08:00
if ( useClipping ) {
2019-06-21 21:46:53 +08:00
QRegion cregion ( static_cast < int > ( x ) , static_cast < int > ( y ) , static_cast < int > ( keyRectangleWidth ) , static_cast < int > ( keyRectangleHeight ) ) ;
2019-02-08 00:24:46 +08:00
painter . setClipping ( true ) ;
painter . setClipRegion ( cregion ) ;
painter . setClipping ( true ) ;
}
2015-07-11 18:56:02 +08:00
2019-02-08 00:24:46 +08:00
drawKeyContents ( painter , x , y , keyWidth , keyHeight ) ;
2015-07-11 18:56:02 +08:00
2019-02-08 00:24:46 +08:00
if ( useClipping ) painter . setClipping ( false ) ;
2015-07-11 18:56:02 +08:00
}
2019-02-08 00:24:46 +08:00
if ( plotterStyle . debugShowRegionBoxes ) {
painter . save ( ) ; auto __finalpaint = JKQTPFinally ( [ & painter ] ( ) { painter . restore ( ) ; } ) ;
QPen p ( " orange " ) ;
2022-07-23 22:05:13 +08:00
QColor col = p . color ( ) ; col . setAlphaF ( 0.8f ) ; p . setColor ( col ) ;
2019-02-08 00:24:46 +08:00
p . setWidthF ( plotterStyle . debugRegionLineWidth ) ;
p . setStyle ( Qt : : DashLine ) ;
painter . setPen ( p ) ;
painter . setBrush ( QBrush ( QColor ( Qt : : transparent ) ) ) ;
painter . drawRect ( rectKey ) ;
p . setStyle ( Qt : : SolidLine ) ;
painter . setPen ( p ) ;
2019-06-21 21:46:53 +08:00
painter . drawLine ( QLineF ( x0 , y0 , rectKey . x ( ) , rectKey . y ( ) ) ) ;
2015-07-11 18:56:02 +08:00
2019-02-08 00:24:46 +08:00
}
2015-07-11 18:56:02 +08:00
}
2019-02-08 00:24:46 +08:00
//qDebug()<<" end JKQTBasePlotter::plotKey";
2015-07-11 18:56:02 +08:00
}
2020-09-09 17:26:04 +08:00
void JKQTBasePlotter : : drawPlot ( JKQTPEnhancedPainter & painter ) {
2015-07-11 18:56:02 +08:00
# ifdef JKQTBP_AUTOTIMER
2019-01-20 17:49:29 +08:00
JKQTPAutoOutputTimer jkaaot ( " JKQTBasePlotter::paintPlot " ) ;
2015-07-11 18:56:02 +08:00
# endif
2019-01-26 03:16:04 +08:00
//qDebug()<<"start JKQTBasePlotter::paintPlot";
2015-07-11 18:56:02 +08:00
// draw background
2019-02-08 00:24:46 +08:00
{
painter . save ( ) ; auto __finalpaint = JKQTPFinally ( [ & painter ] ( ) { painter . restore ( ) ; } ) ;
2019-04-25 01:33:51 +08:00
painter . setPen ( Qt : : NoPen ) ;
if ( plotterStyle . widgetBackgroundBrush ! = QBrush ( Qt : : transparent ) ) painter . fillRect ( QRectF ( 0 , 0 , widgetWidth / paintMagnification , widgetHeight / paintMagnification ) , plotterStyle . widgetBackgroundBrush ) ;
2019-02-08 00:24:46 +08:00
}
QRectF rPlotBack ( internalPlotBorderLeft , internalPlotBorderTop , internalPlotWidth , internalPlotHeight ) ;
2022-04-22 19:27:31 +08:00
# if QT_VERSION<QT_VERSION_CHECK(6,0,0)
2015-07-11 18:56:02 +08:00
painter . setRenderHint ( JKQTPEnhancedPainter : : NonCosmeticDefaultPen , true ) ;
2022-04-22 19:27:31 +08:00
# endif
2019-02-08 00:24:46 +08:00
painter . setRenderHint ( JKQTPEnhancedPainter : : Antialiasing , plotterStyle . useAntiAliasingForSystem ) ;
painter . setRenderHint ( JKQTPEnhancedPainter : : TextAntialiasing , plotterStyle . useAntiAliasingForText ) ;
if ( plotterStyle . plotFrameVisible ) {
painter . save ( ) ; auto __finalpaint = JKQTPFinally ( [ & painter ] ( ) { painter . restore ( ) ; } ) ;
QPen p ( plotterStyle . plotFrameColor ) ;
2019-05-13 04:22:48 +08:00
p . setWidthF ( qMax ( JKQTPlotterDrawingTools : : ABS_MIN_LINEWIDTH , pt2px ( painter , plotterStyle . plotFrameWidth * lineWidthMultiplier ) ) ) ;
2019-02-08 00:24:46 +08:00
painter . setPen ( p ) ;
2019-04-25 01:33:51 +08:00
painter . setBrush ( plotterStyle . plotBackgroundBrush ) ;
2019-02-08 00:24:46 +08:00
if ( plotterStyle . plotFrameRounding < = 0 ) {
painter . drawRect ( rPlotBack ) ;
} else {
painter . drawRoundedRect ( rPlotBack , pt2px ( painter , plotterStyle . plotFrameRounding ) , pt2px ( painter , plotterStyle . plotFrameRounding ) ) ;
}
} else {
painter . save ( ) ; auto __finalpaint = JKQTPFinally ( [ & painter ] ( ) { painter . restore ( ) ; } ) ;
2019-04-25 01:33:51 +08:00
painter . setBrush ( plotterStyle . plotBackgroundBrush ) ;
painter . setPen ( Qt : : NoPen ) ;
2019-02-08 00:24:46 +08:00
if ( plotterStyle . plotFrameRounding < = 0 ) {
painter . drawRect ( rPlotBack ) ;
} else {
painter . drawRoundedRect ( rPlotBack , pt2px ( painter , plotterStyle . plotFrameRounding ) , pt2px ( painter , plotterStyle . plotFrameRounding ) ) ;
}
}
drawSystemGrid ( painter ) ;
2015-07-11 18:56:02 +08:00
if ( ! plotLabel . isEmpty ( ) ) {
2019-02-08 00:24:46 +08:00
mathText . setFontSize ( plotterStyle . plotLabelFontSize * fontSizeMultiplier ) ;
2022-09-01 20:36:34 +08:00
mathText . setFontSpecial ( plotterStyle . plotLabelFontName ) ;
2015-07-11 18:56:02 +08:00
mathText . parse ( plotLabel ) ;
double a = 0 , d = 0 , so = 0 , w = 0 ;
2019-02-08 00:24:46 +08:00
getTextSizeDetail ( plotterStyle . plotLabelFontName , plotterStyle . plotLabelFontSize * fontSizeMultiplier , plotLabel , painter , w , a , d , so ) ;
2015-07-11 18:56:02 +08:00
QSizeF s = QSizeF ( w , a + d ) ;
2022-06-03 05:05:58 +08:00
mathText . draw ( painter , internalPlotBorderLeft + ( internalPlotWidth - s . width ( ) ) / 2.0 , plotterStyle . plotBorderTop + a * 1.2 , plotterStyle . debugShowTextBoxes ) ;
2019-02-08 00:24:46 +08:00
if ( plotterStyle . debugShowRegionBoxes ) {
painter . save ( ) ; auto __finalpaint = JKQTPFinally ( [ & painter ] ( ) { painter . restore ( ) ; } ) ;
QPen p ( " blue " ) ;
2022-07-23 22:05:13 +08:00
QColor col = p . color ( ) ; col . setAlphaF ( 0.8f ) ; p . setColor ( col ) ;
2019-02-08 00:24:46 +08:00
p . setWidthF ( plotterStyle . debugRegionLineWidth ) ;
painter . setBrush ( QBrush ( QColor ( Qt : : transparent ) ) ) ;
painter . setPen ( p ) ;
2019-06-21 21:46:53 +08:00
painter . drawRect ( QRectF ( internalPlotBorderLeft , plotterStyle . plotBorderTop , internalPlotWidth , s . height ( ) ) ) ;
2019-02-08 00:24:46 +08:00
}
}
2020-09-26 21:58:58 +08:00
painter . setRenderHint ( JKQTPEnhancedPainter : : Antialiasing , plotterStyle . graphsStyle . useAntiAliasingForGraphs ) ;
2019-02-08 00:24:46 +08:00
painter . setRenderHint ( JKQTPEnhancedPainter : : TextAntialiasing , plotterStyle . useAntiAliasingForText ) ;
{
painter . save ( ) ; auto __finalpaint = JKQTPFinally ( [ & painter ] ( ) { painter . restore ( ) ; } ) ;
drawGraphs ( painter ) ;
}
painter . setRenderHint ( JKQTPEnhancedPainter : : Antialiasing , plotterStyle . useAntiAliasingForSystem ) ;
painter . setRenderHint ( JKQTPEnhancedPainter : : TextAntialiasing , plotterStyle . useAntiAliasingForText ) ;
drawSystemXAxis ( painter ) ;
drawSystemYAxis ( painter ) ;
2020-09-26 21:58:58 +08:00
painter . setRenderHint ( JKQTPEnhancedPainter : : Antialiasing , plotterStyle . graphsStyle . useAntiAliasingForGraphs ) ;
2019-02-08 00:24:46 +08:00
painter . setRenderHint ( JKQTPEnhancedPainter : : TextAntialiasing , plotterStyle . useAntiAliasingForText ) ;
if ( plotterStyle . keyStyle . visible ) drawKey ( painter ) ;
painter . setRenderHint ( JKQTPEnhancedPainter : : TextAntialiasing , plotterStyle . useAntiAliasingForText ) ;
if ( plotterStyle . debugShowRegionBoxes ) {
painter . save ( ) ; auto __finalpaint = JKQTPFinally ( [ & painter ] ( ) { painter . restore ( ) ; } ) ;
QPen p ( " red " ) ;
2022-07-23 22:05:13 +08:00
QColor col = p . color ( ) ; col . setAlphaF ( 0.8f ) ; p . setColor ( col ) ;
2019-02-08 00:24:46 +08:00
p . setWidthF ( plotterStyle . debugRegionLineWidth ) ;
p . setStyle ( Qt : : DashLine ) ;
painter . setPen ( p ) ;
painter . setBrush ( QBrush ( QColor ( Qt : : transparent ) ) ) ;
2019-06-21 21:46:53 +08:00
painter . drawRect ( QRectF ( internalPlotBorderLeft , internalPlotBorderTop , internalPlotWidth , internalPlotHeight ) ) ;
2019-02-08 00:24:46 +08:00
p . setColor ( QColor ( " maroon " ) ) ;
2022-07-23 22:05:13 +08:00
col = p . color ( ) ; col . setAlphaF ( 0.8f ) ; p . setColor ( col ) ;
2019-02-08 00:24:46 +08:00
p . setWidthF ( plotterStyle . debugRegionLineWidth ) ;
p . setStyle ( Qt : : DotLine ) ;
painter . setPen ( p ) ;
2019-06-21 21:46:53 +08:00
painter . drawRect ( QRectF ( internalPlotBorderLeft_notIncludingOutsidePlotSections , internalPlotBorderTop_notIncludingOutsidePlotSections , widgetWidth - internalPlotBorderLeft_notIncludingOutsidePlotSections - internalPlotBorderRight_notIncludingOutsidePlotSections , widgetHeight - internalPlotBorderTop_notIncludingOutsidePlotSections - internalPlotBorderBottom_notIncludingOutsidePlotSections ) ) ;
2023-03-23 20:55:18 +08:00
p . setColor ( QColor ( " goldenrod " ) ) ;
col = p . color ( ) ; col . setAlphaF ( 0.8f ) ; p . setColor ( col ) ;
p . setWidthF ( plotterStyle . debugRegionLineWidth ) ;
p . setStyle ( Qt : : DotLine ) ;
painter . setPen ( p ) ;
painter . drawRect ( QRectF ( internalPlotBorderLeft_notIncludingAxisAndOutsidePlotSections , internalPlotBorderTop_notIncludingAxisAndOutsidePlotSections , widgetWidth - internalPlotBorderLeft_notIncludingAxisAndOutsidePlotSections - internalPlotBorderRight_notIncludingAxisAndOutsidePlotSections , widgetHeight - internalPlotBorderTop_notIncludingAxisAndOutsidePlotSections - internalPlotBorderBottom_notIncludingAxisAndOutsidePlotSections ) ) ;
2019-02-08 00:24:46 +08:00
p . setColor ( QColor ( " yellow " ) ) ;
2022-07-23 22:05:13 +08:00
col = p . color ( ) ; col . setAlphaF ( 0.8f ) ; p . setColor ( col ) ;
2019-02-08 00:24:46 +08:00
p . setWidthF ( plotterStyle . debugRegionLineWidth ) ;
p . setStyle ( Qt : : SolidLine ) ;
painter . setPen ( p ) ;
painter . drawRect ( 0 , 0 , widgetWidth , widgetHeight ) ;
}
2019-01-26 03:16:04 +08:00
//qDebug()<<" end JKQTBasePlotter::paintPlot";
2015-07-11 18:56:02 +08:00
}
2019-01-20 17:49:29 +08:00
void JKQTBasePlotter : : gridPrintingCalc ( ) {
2015-07-11 18:56:02 +08:00
gridPrintingRows . clear ( ) ;
gridPrintingColumns . clear ( ) ;
if ( ! gridPrinting ) {
2019-06-21 21:46:53 +08:00
gridPrintingSize = QSize ( static_cast < int > ( widgetWidth / paintMagnification ) , static_cast < int > ( widgetHeight / paintMagnification ) ) ;
gridPrintingRows . push_back ( static_cast < size_t > ( widgetHeight / paintMagnification ) ) ;
gridPrintingColumns . push_back ( static_cast < size_t > ( widgetWidth / paintMagnification ) ) ;
2015-07-11 18:56:02 +08:00
} else {
// first find min and max columns/rows
size_t cmin = gridPrintingCurrentX ;
size_t cmax = gridPrintingCurrentX ;
size_t rmin = gridPrintingCurrentY ;
size_t rmax = gridPrintingCurrentY ;
for ( int i = 0 ; i < gridPrintingList . size ( ) ; i + + ) {
size_t c = gridPrintingList [ i ] . x ;
size_t r = gridPrintingList [ i ] . y ;
if ( c < cmin ) cmin = c ;
if ( c > cmax ) cmax = c ;
if ( r < rmin ) rmin = r ;
if ( r > rmax ) rmax = r ;
}
// fill gridPrintingRows and gridPrintingColumns
for ( size_t i = 0 ; i < = cmax ; i + + ) { gridPrintingColumns . push_back ( 0 ) ; }
for ( size_t i = 0 ; i < = rmax ; i + + ) { gridPrintingRows . push_back ( 0 ) ; }
2019-06-21 21:46:53 +08:00
gridPrintingColumns [ static_cast < int > ( gridPrintingCurrentX ) ] = static_cast < size_t > ( widgetWidth / paintMagnification ) ;
gridPrintingRows [ static_cast < int > ( gridPrintingCurrentY ) ] = static_cast < size_t > ( widgetHeight / paintMagnification ) ;
2015-07-11 18:56:02 +08:00
for ( int i = 0 ; i < gridPrintingList . size ( ) ; i + + ) {
2019-06-21 21:46:53 +08:00
size_t cw = static_cast < size_t > ( gridPrintingList [ i ] . plotter - > widgetWidth / paintMagnification ) ;
size_t ch = static_cast < size_t > ( gridPrintingList [ i ] . plotter - > widgetHeight / paintMagnification ) ;
2015-07-11 18:56:02 +08:00
size_t c = gridPrintingList [ i ] . x ;
size_t r = gridPrintingList [ i ] . y ;
2019-06-21 21:46:53 +08:00
if ( cw > gridPrintingColumns [ static_cast < int > ( c ) ] ) gridPrintingColumns [ static_cast < int > ( c ) ] = cw ;
if ( ch > gridPrintingRows [ static_cast < int > ( r ) ] ) gridPrintingRows [ static_cast < int > ( r ) ] = ch ;
2015-07-11 18:56:02 +08:00
}
int w = 0 ;
int h = 0 ;
2019-06-22 20:21:32 +08:00
for ( int i = 0 ; i < gridPrintingColumns . size ( ) ; i + + ) { w + = static_cast < int > ( gridPrintingColumns [ i ] ) ; } ;
for ( int i = 0 ; i < gridPrintingRows . size ( ) ; i + + ) { h + = static_cast < int > ( gridPrintingRows [ i ] ) ; } ;
2015-07-11 18:56:02 +08:00
gridPrintingSize = QSize ( w , h ) ;
}
}
2020-09-09 17:26:04 +08:00
void JKQTBasePlotter : : gridPaint ( JKQTPEnhancedPainter & painter , QSizeF pageRect , bool scaleIfTooLarge , bool scaleIfTooSmall ) {
2015-07-11 18:56:02 +08:00
# ifdef JKQTBP_AUTOTIMER
2019-01-20 17:49:29 +08:00
JKQTPAutoOutputTimer jkaaot ( " JKQTBasePlotter::gridPaint " ) ;
2015-07-11 18:56:02 +08:00
# endif
calcPlotScaling ( painter ) ;
if ( ! gridPrinting ) {
2019-01-26 20:00:40 +08:00
double scale = static_cast < double > ( pageRect . width ( ) ) / static_cast < double > ( widgetWidth ) * paintMagnification ;
if ( /*(scale*static_cast<double>(widgetWidth)>static_cast<double>(pageRect.width())) ||*/ ( scale * static_cast < double > ( widgetHeight ) / paintMagnification > static_cast < double > ( pageRect . height ( ) ) ) & & scaleIfTooLarge ) {
scale = static_cast < double > ( pageRect . height ( ) ) / static_cast < double > ( widgetHeight ) * paintMagnification ;
2015-07-11 18:56:02 +08:00
}
if ( ! scaleIfTooSmall & & scale > 1.0 ) scale = 1.0 ;
if ( ! scaleIfTooLarge & & ! scaleIfTooSmall ) scale = 1.0 ;
# ifdef SHOW_JKQTPLOTTER_DEBUG
qDebug ( ) < < " gridPaint: scale= " < < scale ;
# endif
2019-02-08 00:24:46 +08:00
painter . save ( ) ; auto __finalpaint = JKQTPFinally ( [ & painter ] ( ) { painter . restore ( ) ; } ) ;
2015-07-11 18:56:02 +08:00
// scale the plot so it fits on the page
painter . scale ( scale , scale ) ;
2020-09-09 17:26:04 +08:00
drawPlot ( painter ) ;
2019-02-08 00:24:46 +08:00
2015-07-11 18:56:02 +08:00
} else {
QList < double > fsm , lwm , pm ;
2019-04-25 01:33:51 +08:00
QList < QBrush > backg ;
2015-07-11 18:56:02 +08:00
for ( int i = 0 ; i < gridPrintingList . size ( ) ; i + + ) {
2019-01-26 03:16:04 +08:00
fsm . append ( gridPrintingList [ i ] . plotter - > getFontSizeMultiplier ( ) ) ;
lwm . append ( gridPrintingList [ i ] . plotter - > getLineWidthMultiplier ( ) ) ;
2019-01-26 20:00:40 +08:00
pm . append ( gridPrintingList [ i ] . plotter - > getPaintMagnification ( ) ) ;
2019-04-25 01:33:51 +08:00
backg . append ( gridPrintingList [ i ] . plotter - > getExportBackgroundBrush ( ) ) ;
2019-01-26 03:16:04 +08:00
gridPrintingList [ i ] . plotter - > setFontSizeMultiplier ( fontSizeMultiplier ) ;
gridPrintingList [ i ] . plotter - > setLineWidthMultiplier ( lineWidthMultiplier ) ;
2019-01-26 20:00:40 +08:00
gridPrintingList [ i ] . plotter - > setPaintMagnification ( paintMagnification ) ;
2019-04-25 01:33:51 +08:00
gridPrintingList [ i ] . plotter - > setBackgroundBrush ( gridPrintingList [ i ] . plotter - > getExportBackgroundBrush ( ) ) ;
2015-07-11 18:56:02 +08:00
gridPrintingList [ i ] . plotter - > calcPlotScaling ( painter ) ;
}
gridPrintingCalc ( ) ; // ensure the grid plot has been calculated
// scale the plot so it fits on the page
2019-01-26 20:00:40 +08:00
double scale = static_cast < double > ( pageRect . width ( ) ) / static_cast < double > ( gridPrintingSize . width ( ) ) ;
if ( /*(scale*static_cast<double>(gridPrintingSize.width())>static_cast<double>(pageRect.width())) ||*/ ( scale * static_cast < double > ( gridPrintingSize . height ( ) ) > static_cast < double > ( pageRect . height ( ) ) ) & & scaleIfTooLarge ) {
scale = static_cast < double > ( pageRect . height ( ) ) / static_cast < double > ( gridPrintingSize . height ( ) ) ;
2015-07-11 18:56:02 +08:00
}
if ( ! scaleIfTooSmall & & scale > 1.0 ) scale = 1.0 ;
if ( ! scaleIfTooLarge & & ! scaleIfTooSmall ) scale = 1.0 ;
# ifdef SHOW_JKQTPLOTTER_DEBUG
qDebug ( ) < < " gridPaint: scale= " < < scale ;
# endif
2019-02-08 00:24:46 +08:00
painter . save ( ) ; auto __finalpaint = JKQTPFinally ( [ & painter ] ( ) { painter . restore ( ) ; } ) ;
2015-07-11 18:56:02 +08:00
painter . scale ( scale , scale ) ;
2019-02-08 00:24:46 +08:00
{
// plot this plotter
2020-08-26 17:00:25 +08:00
painter . save ( ) ; auto __finalpaintinner = JKQTPFinally ( [ & painter ] ( ) { painter . restore ( ) ; } ) ;
2015-07-11 18:56:02 +08:00
int t_x = 0 ;
int t_y = 0 ;
2019-02-08 00:24:46 +08:00
//std::cout<<"printing this ...\n";
2019-06-22 20:21:32 +08:00
for ( size_t i = 0 ; i < gridPrintingCurrentX ; i + + ) { t_x + = static_cast < int > ( gridPrintingColumns [ static_cast < int > ( i ) ] ) ; }
for ( size_t i = 0 ; i < gridPrintingCurrentY ; i + + ) { t_y + = static_cast < int > ( gridPrintingRows [ static_cast < int > ( i ) ] ) ; }
2019-02-08 00:24:46 +08:00
//std::cout<<"printing this @ "<<t_x<<", "<<t_y<<" ...\n";
2015-07-11 18:56:02 +08:00
painter . translate ( t_x , t_y ) ;
2020-09-09 17:26:04 +08:00
drawPlot ( painter ) ;
2019-02-08 00:24:46 +08:00
//std::cout<<"this printed ...\n";
// plot all the other plotters
for ( int i = 0 ; i < gridPrintingList . size ( ) ; i + + ) {
//std::cout<<"printing "<<i<<" ...\n";
2020-08-26 17:00:25 +08:00
painter . save ( ) ; auto __finalpaintinnerloop = JKQTPFinally ( [ & painter ] ( ) { painter . restore ( ) ; } ) ;
2020-09-09 02:15:33 +08:00
int gt_x = 0 ;
int gt_y = 0 ;
2019-02-08 00:24:46 +08:00
//std::cout<<"printing "<<i<<" @g "<<gridPrintingList[i].x<<", "<<gridPrintingList[i].y<<" ...\n";
//std::cout<<"colrowlistsizes "<<gridPrintingColumns.size()<<", "<<gridPrintingRows.size()<<" ...\n";
2020-09-09 02:15:33 +08:00
for ( size_t j = 0 ; j < gridPrintingList [ i ] . x ; j + + ) { gt_x + = static_cast < int > ( gridPrintingColumns [ static_cast < int > ( j ) ] ) ; }
for ( size_t j = 0 ; j < gridPrintingList [ i ] . y ; j + + ) { gt_y + = static_cast < int > ( gridPrintingRows [ static_cast < int > ( j ) ] ) ; }
2019-02-08 00:24:46 +08:00
//std::cout<<"printing "<<i<<" @ "<<t_x<<", "<<t_y<<" ...\n";
2020-09-09 02:15:33 +08:00
painter . translate ( gt_x , gt_y ) ;
2020-09-09 17:26:04 +08:00
gridPrintingList [ i ] . plotter - > drawPlot ( painter ) ;
2019-02-08 00:24:46 +08:00
}
2015-07-11 18:56:02 +08:00
2019-02-08 00:24:46 +08:00
for ( int i = 0 ; i < gridPrintingList . size ( ) ; i + + ) {
gridPrintingList [ i ] . plotter - > setFontSizeMultiplier ( fsm [ i ] ) ;
gridPrintingList [ i ] . plotter - > setLineWidthMultiplier ( lwm [ i ] ) ;
gridPrintingList [ i ] . plotter - > setPaintMagnification ( pm [ i ] ) ;
2019-04-25 01:33:51 +08:00
gridPrintingList [ i ] . plotter - > setBackgroundBrush ( backg [ i ] ) ;
2019-02-08 00:24:46 +08:00
gridPrintingList [ i ] . plotter - > redrawPlot ( ) ;
}
2015-07-11 18:56:02 +08:00
}
}
}
2022-07-19 05:33:20 +08:00
# ifndef JKQTPLOTTER_COMPILE_WITHOUT_PRINTSUPPORT
2019-01-20 17:49:29 +08:00
void JKQTBasePlotter : : print ( QPrinter * printer , bool displayPreview ) {
2015-07-11 18:56:02 +08:00
loadUserSettings ( ) ;
QPrinter * p = printer ;
bool delP = false ;
// select a printer
2018-11-18 18:59:30 +08:00
if ( p = = nullptr ) {
2015-07-11 18:56:02 +08:00
p = new QPrinter ( ) ;
p - > setPrinterName ( currentPrinter ) ;
delP = true ;
2018-11-18 18:59:30 +08:00
QPrintDialog * dialog = new QPrintDialog ( p , nullptr ) ;
2015-07-11 18:56:02 +08:00
dialog - > setWindowTitle ( tr ( " Print Plot " ) ) ;
if ( dialog - > exec ( ) ! = QDialog : : Accepted ) {
delete p ;
2019-02-08 00:24:46 +08:00
delete dialog ;
2015-07-11 18:56:02 +08:00
return ;
}
currentPrinter = p - > printerName ( ) ;
2019-02-08 00:24:46 +08:00
delete dialog ;
2015-07-11 18:56:02 +08:00
}
2022-04-19 04:45:02 +08:00
p - > setPageMargins ( QMarginsF ( 10 , 10 , 10 , 10 ) , QPageLayout : : Millimeter ) ;
2015-07-11 18:56:02 +08:00
if ( widgetWidth > widgetHeight ) {
2022-04-19 04:45:02 +08:00
p - > setPageOrientation ( QPageLayout : : Landscape ) ;
2015-07-11 18:56:02 +08:00
} else {
2022-04-19 04:45:02 +08:00
p - > setPageOrientation ( QPageLayout : : Portrait ) ;
2015-07-11 18:56:02 +08:00
}
2022-09-12 06:34:36 +08:00
emit beforeExporting ( ) ; ; auto __finalpaint = JKQTPFinally ( [ & ] ( ) { emit afterExporting ( ) ; } ) ;
2015-07-11 18:56:02 +08:00
printpreviewNew ( p , false , - 1.0 , - 1.0 , displayPreview ) ;
if ( delP ) delete p ;
saveUserSettings ( ) ;
}
2022-07-19 05:33:20 +08:00
# endif
2015-07-11 18:56:02 +08:00
2019-01-20 17:49:29 +08:00
bool JKQTBasePlotter : : printpreviewNew ( QPaintDevice * paintDevice , bool setAbsolutePaperSize , double printsizeX_inMM , double printsizeY_inMM , bool displayPreview ) {
2022-07-19 05:33:20 +08:00
# ifndef JKQTPLOTTER_COMPILE_WITHOUT_PRINTSUPPORT
2015-07-11 18:56:02 +08:00
QPrinter * printer = dynamic_cast < QPrinter * > ( paintDevice ) ;
QSvgGenerator * svg = dynamic_cast < QSvgGenerator * > ( paintDevice ) ;
2022-07-19 05:33:20 +08:00
# endif
2015-07-11 18:56:02 +08:00
double lw = lineWidthMultiplier ;
double fs = fontSizeMultiplier ;
double oldP = paintMagnification ;
2019-04-25 01:33:51 +08:00
QBrush bc = plotterStyle . widgetBackgroundBrush ;
plotterStyle . widgetBackgroundBrush = plotterStyle . exportBackgroundBrush ;
2015-07-11 18:56:02 +08:00
lineWidthMultiplier = lineWidthPrintMultiplier ;
fontSizeMultiplier = fontSizePrintMultiplier ;
2018-11-18 18:59:30 +08:00
exportPreviewLabel = nullptr ;
2015-07-11 18:56:02 +08:00
printMagnification = 1.0 ;
paintMagnification = 1.0 ;
gridPrintingCalc ( ) ;
printAspect = gridPrintingSize . height ( ) / gridPrintingSize . width ( ) ;
2022-07-19 05:33:20 +08:00
# ifndef JKQTPLOTTER_COMPILE_WITHOUT_PRINTSUPPORT
2022-04-19 04:45:02 +08:00
if ( printer ) printPageSizeMM = printer - > pageLayout ( ) . pageSize ( ) . size ( QPageSize : : Millimeter ) ;
else if ( paintDevice ) printPageSizeMM = QSizeF ( paintDevice - > widthMM ( ) , paintDevice - > heightMM ( ) ) ;
2022-07-19 05:33:20 +08:00
# else
if ( paintDevice ) printPageSizeMM = QSizeF ( paintDevice - > widthMM ( ) , paintDevice - > heightMM ( ) ) ;
# endif
2019-01-20 23:15:10 +08:00
printSizeX_Millimeter = double ( gridPrintingSize . width ( ) ) / 96.0 * 25.4 ; //double(resolution)*25.4; // convert current widget size in pt to millimeters, assuming 96dpi (default screen resolution)
2015-07-11 18:56:02 +08:00
printSizeY_Millimeter = double ( gridPrintingSize . height ( ) ) / 96.0 * 25.4 ; //double(resolution)*25.4;
if ( printsizeX_inMM > 0 ) printSizeX_Millimeter = printsizeX_inMM ;
if ( printsizeY_inMM > 0 ) printSizeY_Millimeter = printsizeY_inMM ;
bool startWithMagnification = false ;
if ( ! setAbsolutePaperSize ) {
if ( printSizeX_Millimeter > printPageSizeMM . width ( ) | | printSizeY_Millimeter > printPageSizeMM . height ( ) ) {
startWithMagnification = true ;
printMagnification = qMin ( printPageSizeMM . width ( ) / printSizeX_Millimeter , printPageSizeMM . height ( ) / printSizeY_Millimeter ) ;
}
}
printKeepAspect = true ;
printSetAbsolutePageSize = setAbsolutePaperSize ;
printKeepAbsoluteFontSizes = true ;
printScaleToPagesize = false ;
2018-11-18 18:59:30 +08:00
QDialog * dlg = new QDialog ( nullptr , Qt : : WindowMinMaxButtonsHint ) ;
2015-07-11 18:56:02 +08:00
dlg - > setSizeGripEnabled ( true ) ;
//printZoomFactor=0.95;
//printMagnification=1.5;
QGridLayout * layout = new QGridLayout ( ) ;
dlg - > setLayout ( layout ) ;
dlg - > setWindowTitle ( tr ( " Graph print/export preview ... " ) ) ;
2019-01-20 23:15:10 +08:00
dlg - > setWindowIcon ( QIcon ( " :/JKQTPlotter/jkqtp_exportprintpreview.png " ) ) ;
2015-07-11 18:56:02 +08:00
2022-07-19 05:33:20 +08:00
# ifndef JKQTPLOTTER_COMPILE_WITHOUT_PRINTSUPPORT
2015-07-11 18:56:02 +08:00
bool delPrinter = false ;
if ( svg ) {
printer = new QPrinter ( ) ;
printer - > setColorMode ( QPrinter : : Color ) ;
printer - > setOutputFormat ( QPrinter : : PdfFormat ) ;
printer - > setResolution ( svg - > logicalDpiX ( ) ) ;
2022-04-19 04:45:02 +08:00
printer - > setPageMargins ( QMarginsF ( 0 , 0 , 0 , 0 ) , QPageLayout : : Millimeter ) ;
2015-07-11 18:56:02 +08:00
printer - > setColorMode ( QPrinter : : Color ) ;
delPrinter = true ;
} else if ( ! printer ) {
printer = new QPrinter ( ) ;
printer - > setOutputFormat ( QPrinter : : PdfFormat ) ;
printer - > setResolution ( paintDevice - > logicalDpiX ( ) ) ;
2022-04-19 04:45:02 +08:00
printer - > setPageMargins ( QMarginsF ( 0 , 0 , 0 , 0 ) , QPageLayout : : Millimeter ) ;
2015-07-11 18:56:02 +08:00
printer - > setColorMode ( QPrinter : : Color ) ;
delPrinter = true ;
}
printPreview = new QPrintPreviewWidget ( printer , dlg ) ;
2022-07-19 05:33:20 +08:00
connect ( printPreview , SIGNAL ( paintRequested ( QPrinter * ) ) , this , SLOT ( printpreviewPaintRequestedNewPrinter ( QPrinter * ) ) ) ;
# endif
2015-07-11 18:56:02 +08:00
spinSizeX = new JKQTPEnhancedDoubleSpinBox ( dlg ) ;
spinSizeX - > setRange ( 10 , 100000 ) ;
spinSizeX - > setValue ( printSizeX_Millimeter ) ;
spinSizeX - > setSingleStep ( 10 ) ;
spinSizeX - > setDecimals ( 1 ) ;
spinSizeX - > setSuffix ( tr ( " mm " ) ) ;
spinSizeX - > setToolTip ( tr ( " set the size of the output in millimeters " ) ) ;
connect ( spinSizeX , SIGNAL ( valueChanged ( double ) ) , this , SLOT ( printpreviewSetSizeXNew ( double ) ) ) ;
connect ( spinSizeX , SIGNAL ( editingFinished ( ) ) , this , SLOT ( printpreviewUpdate ( ) ) ) ;
spinSizeY = new JKQTPEnhancedDoubleSpinBox ( dlg ) ;
spinSizeY - > setRange ( 10 , 100000 ) ;
spinSizeY - > setValue ( printSizeY_Millimeter ) ;
spinSizeY - > setSingleStep ( 10 ) ;
spinSizeY - > setDecimals ( 1 ) ;
spinSizeY - > setSuffix ( tr ( " mm " ) ) ;
spinSizeY - > setToolTip ( tr ( " set the size of the output in millimeters " ) ) ;
spinSizeY - > setEnabled ( false ) ;
connect ( spinSizeY , SIGNAL ( valueChanged ( double ) ) , this , SLOT ( printpreviewSetSizeYNew ( double ) ) ) ;
connect ( spinSizeY , SIGNAL ( editingFinished ( ) ) , this , SLOT ( printpreviewUpdate ( ) ) ) ;
QCheckBox * chkAspect = new QCheckBox ( tr ( " keep aspect ratio " ) , dlg ) ;
chkAspect - > setChecked ( true ) ;
chkAspect - > setToolTip ( tr ( " choose whether to keep the aspect ratio for the print/export, as on the screen. " ) ) ;
connect ( chkAspect , SIGNAL ( toggled ( bool ) ) , spinSizeY , SLOT ( setDisabled ( bool ) ) ) ;
connect ( chkAspect , SIGNAL ( toggled ( bool ) ) , this , SLOT ( printpreviewSetAspectRatio ( bool ) ) ) ;
if ( setAbsolutePaperSize ) {
layout - > addWidget ( new QLabel ( tr ( " paper/plot size: " ) ) , 0 , layout - > columnCount ( ) ) ;
2022-07-19 05:33:20 +08:00
# ifndef JKQTPLOTTER_COMPILE_WITHOUT_PRINTSUPPORT
2015-07-11 18:56:02 +08:00
} else if ( printer & & ! svg ) {
int y = layout - > columnCount ( ) ;
layout - > addWidget ( new QLabel ( tr ( " plot size: " ) ) , 0 , y ) ;
2022-07-19 05:33:20 +08:00
# endif
2015-07-11 18:56:02 +08:00
} else {
int y = layout - > columnCount ( ) ;
layout - > addWidget ( new QLabel ( tr ( " paper size: " ) ) , 1 , y ) ;
layout - > addWidget ( new QLabel ( tr ( " plot size: " ) ) , 0 , y ) ;
}
layout - > addWidget ( spinSizeX , 0 , layout - > columnCount ( ) ) ;
layout - > addWidget ( new QLabel ( tr ( " x " ) ) , 0 , layout - > columnCount ( ) ) ;
layout - > addWidget ( spinSizeY , 0 , layout - > columnCount ( ) ) ;
layout - > addWidget ( chkAspect , 0 , layout - > columnCount ( ) ) ;
2022-07-19 05:33:20 +08:00
# ifndef JKQTPLOTTER_COMPILE_WITHOUT_PRINTSUPPORT
2015-07-11 18:56:02 +08:00
if ( ! setAbsolutePaperSize & & printer & & ! svg ) {
2022-04-19 04:45:02 +08:00
layout - > addWidget ( new QLabel ( tr ( " %1x%2 mm^2 " ) . arg ( printer - > pageLayout ( ) . pageSize ( ) . size ( QPageSize : : Millimeter ) . width ( ) ) . arg ( printer - > pageLayout ( ) . pageSize ( ) . size ( QPageSize : : Millimeter ) . height ( ) ) ) , 1 , layout - > columnCount ( ) - 4 , 1 , 4 ) ;
2015-07-11 18:56:02 +08:00
QCheckBox * chkSetMagnification = new QCheckBox ( tr ( " set by magnification: " ) , dlg ) ;
chkSetMagnification - > setChecked ( false ) ;
spinMagnification = new JKQTPEnhancedDoubleSpinBox ( dlg ) ;
spinMagnification - > setEnabled ( false ) ;
spinMagnification - > setRange ( 1 , 1000 ) ;
spinMagnification - > setValue ( printMagnification * 100.0 ) ;
spinMagnification - > setSingleStep ( 10 ) ;
spinMagnification - > setDecimals ( 0 ) ;
spinMagnification - > setSuffix ( tr ( " % " ) ) ;
spinMagnification - > setToolTip ( tr ( " use this to change the base size of the plot<br> "
" This will not change the size of the plot on<br> "
" the page, only it's appearance. A magn. of 100%<br> "
" will print the plot in the same proportions as<br> "
" on the screen, whereas 50% will use twice as much<br> "
" space for the plot, as on the screen. <i>This mainly<br> "
" influences the relative font size!</i> " ) ) ;
connect ( spinMagnification , SIGNAL ( valueChanged ( double ) ) , this , SLOT ( printpreviewSetMagnificationNew ( double ) ) ) ;
connect ( chkSetMagnification , SIGNAL ( toggled ( bool ) ) , spinMagnification , SLOT ( setEnabled ( bool ) ) ) ;
connect ( chkSetMagnification , SIGNAL ( toggled ( bool ) ) , spinSizeX , SLOT ( setDisabled ( bool ) ) ) ;
connect ( chkSetMagnification , SIGNAL ( toggled ( bool ) ) , spinSizeY , SLOT ( setDisabled ( bool ) ) ) ;
connect ( chkSetMagnification , SIGNAL ( toggled ( bool ) ) , chkAspect , SLOT ( setDisabled ( bool ) ) ) ;
connect ( spinMagnification , SIGNAL ( editingFinished ( ) ) , this , SLOT ( printpreviewUpdate ( ) ) ) ;
connect ( chkSetMagnification , SIGNAL ( toggled ( bool ) ) , this , SLOT ( printpreviewToggleMagnification ( bool ) ) ) ;
spinMagnification - > setEnabled ( startWithMagnification ) ;
chkSetMagnification - > setChecked ( startWithMagnification ) ;
layout - > addWidget ( chkSetMagnification , 0 , layout - > columnCount ( ) ) ;
layout - > addWidget ( spinMagnification , 0 , layout - > columnCount ( ) ) ;
}
2022-07-19 05:33:20 +08:00
# endif
2015-07-11 18:56:02 +08:00
JKQTPEnhancedDoubleSpinBox * spinLineWidthMult = new JKQTPEnhancedDoubleSpinBox ( dlg ) ;
spinLineWidthMult - > setRange ( 1 , 1000 ) ;
spinLineWidthMult - > setValue ( lineWidthPrintMultiplier * 100.0 ) ;
spinLineWidthMult - > setSingleStep ( 10 ) ;
spinLineWidthMult - > setDecimals ( 0 ) ;
spinLineWidthMult - > setSuffix ( tr ( " % " ) ) ;
spinLineWidthMult - > setToolTip ( tr ( " use this to change the relative width of the lines \n "
" in the exported/printed plot. " ) ) ;
connect ( spinLineWidthMult , SIGNAL ( editingFinished ( double ) ) , this , SLOT ( printpreviewSetLineWidthMultiplier ( double ) ) ) ;
QCheckBox * chkKeepAbsoluteFontSize = new QCheckBox ( tr ( " keep abs. fontsize " ) , dlg ) ;
chkKeepAbsoluteFontSize - > setChecked ( true ) ;
connect ( chkKeepAbsoluteFontSize , SIGNAL ( toggled ( bool ) ) , this , SLOT ( printpreviewSetKeepAbsFontsize ( bool ) ) ) ;
JKQTPEnhancedDoubleSpinBox * spinFontSizeMult = new JKQTPEnhancedDoubleSpinBox ( dlg ) ;
spinFontSizeMult - > setEnabled ( false ) ;
spinFontSizeMult - > setRange ( 1 , 1000 ) ;
spinFontSizeMult - > setValue ( fontSizePrintMultiplier * 100.0 ) ;
spinFontSizeMult - > setSingleStep ( 10 ) ;
spinFontSizeMult - > setDecimals ( 0 ) ;
spinFontSizeMult - > setSuffix ( tr ( " % " ) ) ;
spinFontSizeMult - > setToolTip ( tr ( " use this to change the relative size of the text fonts \n "
" in the exported/printed plot. " ) ) ;
connect ( spinFontSizeMult , SIGNAL ( editingFinished ( double ) ) , this , SLOT ( printpreviewSetFontSizeMultiplier ( double ) ) ) ;
connect ( chkKeepAbsoluteFontSize , SIGNAL ( toggled ( bool ) ) , spinFontSizeMult , SLOT ( setDisabled ( bool ) ) ) ;
layout - > addWidget ( new QLabel ( tr ( " linewidth mult.: " ) ) , 0 , layout - > columnCount ( ) ) ;
layout - > addWidget ( spinLineWidthMult , 0 , layout - > columnCount ( ) ) ;
int gpos = layout - > columnCount ( ) ;
layout - > addWidget ( chkKeepAbsoluteFontSize , 0 , gpos , 1 , 2 ) ;
layout - > addWidget ( new QLabel ( tr ( " font size mult.: " ) ) , 1 , gpos ) ;
layout - > addWidget ( spinFontSizeMult , 1 , gpos + 1 ) ;
layout - > addWidget ( new QWidget ( ) , 0 , layout - > columnCount ( ) ) ;
layout - > setColumnStretch ( layout - > columnCount ( ) - 1 , 1 ) ;
2022-07-19 05:33:20 +08:00
# ifndef JKQTPLOTTER_COMPILE_WITHOUT_PRINTSUPPORT
2015-07-11 18:56:02 +08:00
layout - > addWidget ( printPreview , layout - > rowCount ( ) , 0 , 1 , layout - > columnCount ( ) ) ;
2022-07-19 05:33:20 +08:00
# endif
2015-07-11 18:56:02 +08:00
QDialogButtonBox * buttonBox = new QDialogButtonBox ( QDialogButtonBox : : Ok | QDialogButtonBox : : Cancel ) ;
connect ( buttonBox , SIGNAL ( accepted ( ) ) , dlg , SLOT ( accept ( ) ) ) ;
connect ( buttonBox , SIGNAL ( rejected ( ) ) , dlg , SLOT ( reject ( ) ) ) ;
layout - > addWidget ( buttonBox , layout - > rowCount ( ) , 0 , 1 , layout - > columnCount ( ) ) ;
dlg - > resize ( 800 , 500 ) ;
bool res = false ;
2022-07-19 05:33:20 +08:00
# ifndef JKQTPLOTTER_COMPILE_WITHOUT_PRINTSUPPORT
2015-07-11 18:56:02 +08:00
if ( printer ) {
if ( ! displayPreview | | dlg - > exec ( ) = = QDialog : : Accepted ) {
2020-09-09 02:15:33 +08:00
//qDebug()<<svg<<printer<<delPrinter;
2015-07-11 18:56:02 +08:00
if ( svg ) {
2022-07-19 05:33:20 +08:00
printpreviewPaintRequestedNewPaintDevice ( svg ) ;
2020-09-09 02:15:33 +08:00
} else if ( ! delPrinter ) {
2022-07-19 05:33:20 +08:00
printpreviewPaintRequestedNewPrinter ( printer ) ;
2015-07-11 18:56:02 +08:00
} else {
2022-07-19 05:33:20 +08:00
printpreviewPaintRequestedNewPaintDevice ( paintDevice ) ;
2015-07-11 18:56:02 +08:00
}
res = true ;
}
}
if ( ( svg | | delPrinter ) & & printer ) {
delete printer ;
}
2022-07-19 05:33:20 +08:00
# endif
2015-07-11 18:56:02 +08:00
delete dlg ;
2022-07-19 05:33:20 +08:00
# ifndef JKQTPLOTTER_COMPILE_WITHOUT_PRINTSUPPORT
2018-11-18 18:59:30 +08:00
printPreview = nullptr ;
2022-07-19 05:33:20 +08:00
# endif
2015-07-11 18:56:02 +08:00
lineWidthMultiplier = lw ;
fontSizeMultiplier = fs ;
2019-04-25 01:33:51 +08:00
plotterStyle . widgetBackgroundBrush = bc ;
2015-07-11 18:56:02 +08:00
paintMagnification = oldP ;
return res ;
}
2019-01-20 17:49:29 +08:00
bool JKQTBasePlotter : : exportpreview ( QSizeF pageSize , bool unitIsMM ) {
2022-07-19 05:33:20 +08:00
# ifndef JKQTPLOTTER_COMPILE_WITHOUT_PRINTSUPPORT
2018-11-18 18:59:30 +08:00
printPreview = nullptr ;
2022-07-19 05:33:20 +08:00
# endif
2015-07-11 18:56:02 +08:00
printSizeX_Millimeter = pageSize . width ( ) ;
printSizeY_Millimeter = pageSize . height ( ) ;
printAspect = 1 ;
printKeepAspect = false ;
exportUnitInMM = unitIsMM ;
printSetAbsolutePageSize = true ;
printScaleToPagesize = false ;
printKeepAbsoluteFontSizes = true ;
2018-11-18 18:59:30 +08:00
QDialog * dlg = new QDialog ( nullptr , Qt : : WindowMinMaxButtonsHint ) ;
2015-07-11 18:56:02 +08:00
dlg - > setSizeGripEnabled ( true ) ;
//printZoomFactor=0.95;
//printMagnification=1.5;
QGridLayout * layout = new QGridLayout ( ) ;
dlg - > setLayout ( layout ) ;
dlg - > setWindowTitle ( tr ( " Graph export preview ... " ) ) ;
2019-01-20 23:15:10 +08:00
dlg - > setWindowIcon ( QIcon ( " :/JKQTPlotter/jkqtp_exportprintpreview.png " ) ) ;
2015-07-11 18:56:02 +08:00
QScrollArea * scroll = new QScrollArea ( dlg ) ;
{
QPalette p ( scroll - > palette ( ) ) ;
// Set background colour to black
2022-04-22 19:27:31 +08:00
p . setColor ( QPalette : : Window , Qt : : darkGray ) ;
2015-07-11 18:56:02 +08:00
scroll - > setPalette ( p ) ;
}
exportPreviewLabel = new QLabel ( scroll ) ;
exportPreviewLabel - > setMargin ( 10 ) ;
scroll - > setWidget ( exportPreviewLabel ) ;
{
QPalette p ( exportPreviewLabel - > palette ( ) ) ;
// Set background colour to black
2022-04-22 19:27:31 +08:00
p . setColor ( QPalette : : Window , Qt : : darkGray ) ;
2015-07-11 18:56:02 +08:00
exportPreviewLabel - > setPalette ( p ) ;
}
printAspect = double ( widgetHeight ) / double ( widgetWidth ) ;
if ( gridPrinting ) {
gridPrintingCalc ( ) ;
printAspect = double ( gridPrintingSize . height ( ) ) / double ( gridPrintingSize . width ( ) ) ;
}
printSizeY_Millimeter = printSizeX_Millimeter * printAspect ;
printKeepAspect = true ;
JKQTPEnhancedDoubleSpinBox * spinSizeX = new JKQTPEnhancedDoubleSpinBox ( dlg ) ;
spinSizeX - > setRange ( 1 , 10000 ) ;
spinSizeX - > setValue ( printSizeX_Millimeter ) ;
spinSizeX - > setSingleStep ( 10 ) ;
if ( unitIsMM ) spinSizeX - > setDecimals ( 1 ) ;
else spinSizeX - > setDecimals ( 0 ) ;
if ( unitIsMM ) spinSizeX - > setSuffix ( tr ( " mm " ) ) ;
spinSizeX - > setToolTip ( tr ( " set the size of the output page " ) ) ;
connect ( spinSizeX , SIGNAL ( editingFinished ( double ) ) , this , SLOT ( printpreviewSetSizeX ( double ) ) ) ;
spinSizeY = new JKQTPEnhancedDoubleSpinBox ( dlg ) ;
spinSizeY - > setRange ( 1 , 10000 ) ;
spinSizeY - > setValue ( printSizeY_Millimeter ) ;
spinSizeY - > setSingleStep ( 10 ) ;
if ( unitIsMM ) spinSizeY - > setDecimals ( 1 ) ;
else spinSizeY - > setDecimals ( 0 ) ;
if ( unitIsMM ) spinSizeY - > setSuffix ( tr ( " mm " ) ) ;
spinSizeY - > setToolTip ( tr ( " set the size of the output page " ) ) ;
spinSizeY - > setEnabled ( false ) ;
connect ( spinSizeY , SIGNAL ( editingFinished ( double ) ) , this , SLOT ( printpreviewSetSizeY ( double ) ) ) ;
QCheckBox * chkAspect = new QCheckBox ( tr ( " keep aspect ratio " ) , dlg ) ;
chkAspect - > setChecked ( true ) ;
chkAspect - > setToolTip ( tr ( " choose whether to keep the aspect ratio for the print/export, as on the screen. " ) ) ;
connect ( chkAspect , SIGNAL ( toggled ( bool ) ) , spinSizeY , SLOT ( setDisabled ( bool ) ) ) ;
connect ( chkAspect , SIGNAL ( toggled ( bool ) ) , this , SLOT ( printpreviewSetAspectRatio ( bool ) ) ) ;
layout - > addWidget ( new QLabel ( tr ( " page size: " ) ) , 0 , layout - > columnCount ( ) ) ;
layout - > addWidget ( spinSizeX , 0 , layout - > columnCount ( ) ) ;
layout - > addWidget ( new QLabel ( tr ( " x " ) ) , 0 , layout - > columnCount ( ) ) ;
layout - > addWidget ( spinSizeY , 0 , layout - > columnCount ( ) ) ;
layout - > addWidget ( chkAspect , 0 , layout - > columnCount ( ) ) ;
JKQTPEnhancedDoubleSpinBox * spinMagnification = new JKQTPEnhancedDoubleSpinBox ( dlg ) ;
spinMagnification - > setRange ( 1 , 1000 ) ;
spinMagnification - > setValue ( printMagnification * 100.0 ) ;
spinMagnification - > setSingleStep ( 10 ) ;
spinMagnification - > setDecimals ( 0 ) ;
spinMagnification - > setSuffix ( tr ( " % " ) ) ;
spinMagnification - > setToolTip ( tr ( " use this to change the base size of the plot<br> "
" This will not change the size of the plot on<br> "
" the page, only it's appearance. A magn. of 100%<br> "
" will print the plot in the same proportions as<br> "
" on the screen, whereas 50% will use twice as much<br> "
" space for the plot, as on the screen. <i>This mainly<br> "
" influences the relative font size!</i> " ) ) ;
connect ( spinMagnification , SIGNAL ( editingFinished ( double ) ) , this , SLOT ( printpreviewSetMagnification ( double ) ) ) ;
layout - > addWidget ( new QLabel ( tr ( " magnification: " ) ) , 0 , layout - > columnCount ( ) ) ;
layout - > addWidget ( spinMagnification , 0 , layout - > columnCount ( ) ) ;
JKQTPEnhancedDoubleSpinBox * spinLineWidthMult = new JKQTPEnhancedDoubleSpinBox ( dlg ) ;
spinLineWidthMult - > setRange ( 1 , 1000 ) ;
spinLineWidthMult - > setValue ( lineWidthPrintMultiplier * 100.0 ) ;
spinLineWidthMult - > setSingleStep ( 10 ) ;
spinLineWidthMult - > setDecimals ( 0 ) ;
spinLineWidthMult - > setSuffix ( tr ( " % " ) ) ;
spinLineWidthMult - > setToolTip ( tr ( " use this to change the relative width of the lines \n "
" in the exported/printed plot. " ) ) ;
connect ( spinLineWidthMult , SIGNAL ( editingFinished ( double ) ) , this , SLOT ( printpreviewSetLineWidthMultiplier ( double ) ) ) ;
JKQTPEnhancedDoubleSpinBox * spinFontSizeMult = new JKQTPEnhancedDoubleSpinBox ( dlg ) ;
spinFontSizeMult - > setRange ( 1 , 1000 ) ;
spinFontSizeMult - > setValue ( fontSizePrintMultiplier * 100.0 ) ;
spinFontSizeMult - > setSingleStep ( 10 ) ;
spinFontSizeMult - > setDecimals ( 0 ) ;
spinFontSizeMult - > setSuffix ( tr ( " % " ) ) ;
spinFontSizeMult - > setToolTip ( tr ( " use this to change the relative size of the text fonts \n "
" in the exported/printed plot. " ) ) ;
connect ( spinFontSizeMult , SIGNAL ( editingFinished ( double ) ) , this , SLOT ( printpreviewSetFontSizeMultiplier ( double ) ) ) ;
layout - > addWidget ( new QLabel ( tr ( " magnification: " ) ) , 0 , layout - > columnCount ( ) ) ;
layout - > addWidget ( spinMagnification , 0 , layout - > columnCount ( ) ) ;
layout - > addWidget ( new QLabel ( tr ( " linewidth mult.: " ) ) , 0 , layout - > columnCount ( ) ) ;
layout - > addWidget ( spinLineWidthMult , 0 , layout - > columnCount ( ) ) ;
layout - > addWidget ( new QLabel ( tr ( " font size mult.: " ) ) , 0 , layout - > columnCount ( ) ) ;
layout - > addWidget ( spinFontSizeMult , 0 , layout - > columnCount ( ) ) ;
layout - > addWidget ( new QWidget ( ) , 0 , layout - > columnCount ( ) ) ;
layout - > setColumnStretch ( layout - > columnCount ( ) - 1 , 1 ) ;
layout - > addWidget ( scroll , layout - > rowCount ( ) , 0 , 1 , layout - > columnCount ( ) ) ;
QDialogButtonBox * buttonBox = new QDialogButtonBox ( QDialogButtonBox : : Ok | QDialogButtonBox : : Cancel ) ;
connect ( buttonBox , SIGNAL ( accepted ( ) ) , dlg , SLOT ( accept ( ) ) ) ;
connect ( buttonBox , SIGNAL ( rejected ( ) ) , dlg , SLOT ( reject ( ) ) ) ;
layout - > addWidget ( buttonBox , layout - > rowCount ( ) , 0 , 1 , layout - > columnCount ( ) ) ;
dlg - > resize ( 800 , 500 ) ;
updatePreviewLabel ( ) ;
bool result = false ;
if ( dlg - > exec ( ) = = QDialog : : Accepted ) {
result = true ;
}
return result ;
}
2019-02-08 00:24:46 +08:00
void JKQTBasePlotter : : setFontSizeMultiplier ( double __value )
{
this - > fontSizeMultiplier = __value ;
}
void JKQTBasePlotter : : setLineWidthMultiplier ( double __value )
{
this - > lineWidthMultiplier = __value ;
}
void JKQTBasePlotter : : setPrintMagnification ( double __value )
{
this - > printMagnification = __value ;
}
double JKQTBasePlotter : : getPrintMagnification ( ) const
{
return this - > printMagnification ;
}
void JKQTBasePlotter : : setPaintMagnification ( double __value )
{
this - > paintMagnification = __value ;
}
double JKQTBasePlotter : : getPaintMagnification ( ) const
{
return this - > paintMagnification ;
}
void JKQTBasePlotter : : updatePreviewLabel ( ) {
double factor = 1 ;
if ( exportUnitInMM ) factor = 600.0 / double ( printSizeX_Millimeter ) ;
2019-06-21 21:46:53 +08:00
QImage pix ( jkqtp_roundTo < int > ( double ( printSizeX_Millimeter ) * factor * 1.1 ) , jkqtp_roundTo < int > ( double ( printSizeY_Millimeter ) * factor * 1.1 ) , QImage : : Format_ARGB32 ) ;
2019-02-08 00:24:46 +08:00
pix . fill ( Qt : : transparent ) ;
JKQTPEnhancedPainter painter ;
painter . begin ( & pix ) ;
2019-06-21 21:46:53 +08:00
exportpreviewPaintRequested ( painter , QSize ( jkqtp_roundTo < int > ( double ( printSizeX_Millimeter ) * factor ) , jkqtp_roundTo < int > ( double ( printSizeY_Millimeter ) * factor ) ) ) ;
2019-02-08 00:24:46 +08:00
painter . end ( ) ;
if ( exportPreviewLabel ) {
QPixmap pm ;
pm . convertFromImage ( pix ) ;
2015-07-11 18:56:02 +08:00
exportPreviewLabel - > setPixmap ( pm ) ;
exportPreviewLabel - > resize ( pm . size ( ) ) ;
}
}
2022-07-19 05:33:20 +08:00
# ifndef JKQTPLOTTER_COMPILE_WITHOUT_PRINTSUPPORT
2019-01-20 17:49:29 +08:00
void JKQTBasePlotter : : printpreviewPaintRequested ( QPrinter * printer ) {
2015-07-11 18:56:02 +08:00
double lw = lineWidthMultiplier ;
double fs = fontSizeMultiplier ;
2019-04-25 01:33:51 +08:00
QBrush bc = plotterStyle . widgetBackgroundBrush ;
plotterStyle . widgetBackgroundBrush = plotterStyle . exportBackgroundBrush ;
2015-07-11 18:56:02 +08:00
lineWidthMultiplier = lineWidthPrintMultiplier ;
fontSizeMultiplier = fontSizePrintMultiplier ;
bool oldEmitPlotSignals = emitPlotSignals ;
emitPlotSignals = false ;
QApplication : : setOverrideCursor ( QCursor ( Qt : : WaitCursor ) ) ;
QApplication : : processEvents ( ) ;
int oldWidgetWidth = widgetWidth ;
int oldWidgetHeight = widgetHeight ;
//widgetWidth=widgetWidth/printMagnification;
//widgetHeight=widgetHeight/printMagnification;
double oldpm = paintMagnification ;
paintMagnification = printMagnification ;
if ( printSetAbsolutePageSize ) {
# ifdef SHOW_JKQTPLOTTER_DEBUG
qDebug ( ) < < " set printing abs. size to " < < QSizeF ( printSizeX_Millimeter , printSizeY_Millimeter ) < < " mm^2 " ;
# endif
2022-04-19 04:45:02 +08:00
//printer->setPageSize(QPrinter::Custom);
printer - > setPageOrientation ( QPageLayout : : Portrait ) ;
printer - > setPageSize ( QPageSize ( QSizeF ( printSizeX_Millimeter , printSizeY_Millimeter ) , QPageSize : : Millimeter ) ) ;
2019-06-21 21:46:53 +08:00
if ( ! gridPrinting ) widgetHeight = jkqtp_roundTo < int > ( widgetWidth * printSizeY_Millimeter / printSizeX_Millimeter ) ;
2015-07-11 18:56:02 +08:00
}
JKQTPEnhancedPainter painter ;
2022-08-31 04:24:24 +08:00
painter . setPainterFlag ( JKQTPEnhancedPainter : : VectorPainting ) ;
2015-07-11 18:56:02 +08:00
painter . begin ( printer ) ;
if ( ! printSetAbsolutePageSize ) {
# ifdef SHOW_JKQTPLOTTER_DEBUG
qDebug ( ) < < " scale printing to " < < printZoomFactor ;
# endif
painter . scale ( printZoomFactor , printZoomFactor ) ;
}
if ( printKeepAbsoluteFontSizes ) {
if ( printZoomFactor ! = 1.0 ) {
fontSizeMultiplier = 1.0 / printZoomFactor ;
}
}
# ifdef SHOW_JKQTPLOTTER_DEBUG
qDebug ( ) < < " printSetAbsoluteSize = " < < printSetAbsolutePageSize ;
qDebug ( ) < < " printScaleToPagesize = " < < printScaleToPagesize ;
qDebug ( ) < < " printKeepAbsoluteFontSizes = " < < printKeepAbsoluteFontSizes ;
qDebug ( ) < < " print with widget size " < < widgetWidth < < widgetHeight ;
2022-04-19 04:45:02 +08:00
qDebug ( ) < < " print with paper size " < < printer - > pageLayout ( ) . paintRectPixels ( printer - > resolution ( ) ) . size ( ) < < " " ;
QSizeF sl = QSizeF ( QSizeF ( printer - > pageLayout ( ) . paintRectPixels ( printer - > resolution ( ) ) . size ( ) ) . width ( ) / printer - > logicalDpiX ( ) * 25.4 , QSizeF ( printer - > pageLayout ( ) . paintRectPixels ( printer - > resolution ( ) ) . size ( ) ) . height ( ) / printer - > logicalDpiY ( ) * 25.4 ) ;
2015-07-11 18:56:02 +08:00
qDebug ( ) < < " print with paper size " < < sl < < " mm^2 " ;
qDebug ( ) < < " paintMagnification = " < < paintMagnification ;
qDebug ( ) < < " lineWidthMultiplier = " < < lineWidthMultiplier ;
qDebug ( ) < < " fontSizeMultiplier = " < < fontSizeMultiplier ;
qDebug ( ) < < " printer resolution = " < < printer - > resolution ( ) < < " dpi " ;
2019-02-08 00:24:46 +08:00
qDebug ( ) < < " \n plotLabelFontSize = " < < plotterStyle . plotLabelFontSize < < " pt " ;
qDebug ( ) < < " plotterStyle.keyStyle.fontSize = " < < plotterStyle . keyStyle . fontSize < < " pt " ;
2019-01-26 20:00:40 +08:00
qDebug ( ) < < " x-axis label fontsize = " < < xAxis - > getLabelFontSize ( ) < < " pt " ;
qDebug ( ) < < " y-axis label fontsize = " < < yAxis - > getLabelFontSize ( ) < < " pt " ;
2015-07-11 18:56:02 +08:00
# endif
2022-04-19 04:45:02 +08:00
gridPaint ( painter , printer - > pageLayout ( ) . paintRectPixels ( printer - > resolution ( ) ) . size ( ) , printScaleToPagesize , printScaleToPagesize ) ;
2015-07-11 18:56:02 +08:00
painter . end ( ) ;
widgetWidth = oldWidgetWidth ;
widgetHeight = oldWidgetHeight ;
QApplication : : restoreOverrideCursor ( ) ;
QApplication : : processEvents ( ) ;
emitPlotSignals = oldEmitPlotSignals ;
lineWidthMultiplier = lw ;
fontSizeMultiplier = fs ;
paintMagnification = oldpm ;
2019-04-25 01:33:51 +08:00
plotterStyle . widgetBackgroundBrush = bc ;
2015-07-11 18:56:02 +08:00
}
2022-07-19 05:33:20 +08:00
void JKQTBasePlotter : : printpreviewPaintRequestedNewPrinter ( QPrinter * printer ) {
2015-07-11 18:56:02 +08:00
QPaintDevice * paintDevice = dynamic_cast < QPaintDevice * > ( printer ) ;
2022-07-19 05:33:20 +08:00
printpreviewPaintRequestedNewPaintDevice ( paintDevice ) ;
2015-07-11 18:56:02 +08:00
}
2022-07-19 05:33:20 +08:00
# endif
2015-07-11 18:56:02 +08:00
2022-07-19 05:33:20 +08:00
void JKQTBasePlotter : : printpreviewPaintRequestedNewPaintDevice ( QPaintDevice * paintDevice )
2015-07-11 18:56:02 +08:00
{
//QPaintDevice* paintDevice=dynamic_cast<QPaintDevice*>(printer);
2022-07-19 05:33:20 +08:00
# ifndef JKQTPLOTTER_COMPILE_WITHOUT_PRINTSUPPORT
2015-07-11 18:56:02 +08:00
QPrinter * printer = dynamic_cast < QPrinter * > ( paintDevice ) ;
QSvgGenerator * svg = dynamic_cast < QSvgGenerator * > ( paintDevice ) ;
2022-07-19 05:33:20 +08:00
# endif
2015-07-11 18:56:02 +08:00
double lw = lineWidthMultiplier ;
double fs = fontSizeMultiplier ;
2019-04-25 01:33:51 +08:00
QBrush bc = plotterStyle . widgetBackgroundBrush ;
plotterStyle . widgetBackgroundBrush = plotterStyle . exportBackgroundBrush ;
2015-07-11 18:56:02 +08:00
lineWidthMultiplier = lineWidthPrintMultiplier ;
fontSizeMultiplier = fontSizePrintMultiplier ;
bool oldEmitPlotSignals = emitPlotSignals ;
emitPlotSignals = false ;
QApplication : : setOverrideCursor ( QCursor ( Qt : : WaitCursor ) ) ;
QApplication : : processEvents ( ) ;
int oldWidgetWidth = widgetWidth ;
int oldWidgetHeight = widgetHeight ;
double oldpm = paintMagnification ;
paintMagnification = 1.0 ;
gridPrintingCalc ( ) ;
if ( printSetAbsolutePageSize ) {
# ifdef SHOW_JKQTPLOTTER_DEBUG
qDebug ( ) < < " set printing abs. size to " < < QSizeF ( printSizeX_Millimeter , printSizeY_Millimeter ) < < " mm^2 " ;
# endif
2022-07-19 05:33:20 +08:00
# ifndef JKQTPLOTTER_COMPILE_WITHOUT_PRINTSUPPORT
2015-07-11 18:56:02 +08:00
if ( printer ) {
2022-04-19 04:45:02 +08:00
printer - > setPageOrientation ( QPageLayout : : Portrait ) ;
printer - > setPageSize ( QPageSize ( QSizeF ( printSizeX_Millimeter , printSizeY_Millimeter ) , QPageSize : : Millimeter ) ) ;
2015-07-11 18:56:02 +08:00
} else if ( svg ) {
QRectF siz = QRectF ( 0 , 0 , printSizeX_Millimeter , printSizeY_Millimeter ) ;
2019-06-21 21:46:53 +08:00
svg - > setSize ( QSizeF ( ceil ( siz . width ( ) * svg - > resolution ( ) / 25.4 ) , ceil ( siz . height ( ) * svg - > resolution ( ) / 25.4 ) ) . toSize ( ) ) ;
2015-07-11 18:56:02 +08:00
svg - > setViewBox ( QRect ( 0 , 0 , - 1 , - 1 ) ) ; //*25.4/double(svg->resolution()), printSizeY_Millimeter*25.4/double(svg->resolution())));
}
2022-07-19 05:33:20 +08:00
# endif
2015-07-11 18:56:02 +08:00
}
paintMagnification = gridPrintingSize . width ( ) / ( printSizeX_Millimeter / 25.4 * double ( paintDevice - > logicalDpiX ( ) ) ) ;
2019-06-21 21:46:53 +08:00
if ( ! gridPrinting ) widgetHeight = jkqtp_roundTo < int > ( widgetWidth * printSizeY_Millimeter / printSizeX_Millimeter ) ;
2015-07-11 18:56:02 +08:00
JKQTPEnhancedPainter painter ;
2022-07-19 05:33:20 +08:00
# ifndef JKQTPLOTTER_COMPILE_WITHOUT_PRINTSUPPORT
2015-07-11 18:56:02 +08:00
if ( printer ) painter . begin ( printer ) ;
else if ( svg ) painter . begin ( svg ) ;
else painter . begin ( paintDevice ) ;
2022-08-31 04:24:24 +08:00
if ( printer | | svg ) painter . setPainterFlag ( JKQTPEnhancedPainter : : VectorPainting ) ;
2022-07-19 05:33:20 +08:00
# else
painter . begin ( paintDevice ) ;
# endif
2015-07-11 18:56:02 +08:00
if ( printKeepAbsoluteFontSizes ) {
fontSizeMultiplier = 1.0 ; //1.0/paintMagnification;
}
2022-07-19 05:33:20 +08:00
# ifndef JKQTPLOTTER_COMPILE_WITHOUT_PRINTSUPPORT
2015-07-11 18:56:02 +08:00
if ( svg ) {
lineWidthMultiplier = lineWidthMultiplier * 72.0 / 96.0 ;
fontSizeMultiplier = fontSizeMultiplier * 72.0 / 96.0 ;
}
2022-07-19 05:33:20 +08:00
# endif
2015-07-11 18:56:02 +08:00
# ifdef SHOW_JKQTPLOTTER_DEBUG
qDebug ( ) < < " \n \n \n ========================================================================== " ;
qDebug ( ) < < " printAspect = " < < printAspect ;
qDebug ( ) < < " printKeepAspect = " < < printKeepAspect ;
qDebug ( ) < < " printSetAbsoluteSize = " < < printSetAbsolutePageSize ;
qDebug ( ) < < " printScaleToPagesize = " < < printScaleToPagesize ;
qDebug ( ) < < " printKeepAbsoluteFontSizes = " < < printKeepAbsoluteFontSizes ;
qDebug ( ) < < " print with widget size " < < widgetWidth < < widgetHeight ;
if ( printer ) {
2022-04-19 04:45:02 +08:00
qDebug ( ) < < " print with paper size " < < printer - > pageLayout ( ) . paintRectPixels ( printer - > resolution ( ) ) . size ( ) < < " " ;
QSizeF sl = QSizeF ( QSizeF ( printer - > pageLayout ( ) . paintRectPixels ( printer - > resolution ( ) ) . size ( ) ) . width ( ) / printer - > logicalDpiX ( ) * 25.4 , QSizeF ( printer - > pageLayout ( ) . paintRectPixels ( printer - > resolution ( ) ) . size ( ) ) . height ( ) / printer - > logicalDpiY ( ) * 25.4 ) ;
2015-07-11 18:56:02 +08:00
qDebug ( ) < < " print with paper size " < < sl < < " mm^2 " ;
} else if ( svg ) {
qDebug ( ) < < " print with paper size " < < svg - > size ( ) < < " " ;
QSizeF sl = QSizeF ( QSizeF ( svg - > viewBoxF ( ) . size ( ) ) . width ( ) / svg - > resolution ( ) * 25.4 , QSizeF ( svg - > size ( ) ) . height ( ) / svg - > resolution ( ) * 25.4 ) ;
qDebug ( ) < < " print with paper size " < < sl < < " mm^2 " ;
}
qDebug ( ) < < " plot size " < < printSizeX_Millimeter < < printSizeY_Millimeter < < " mm^2 " ;
qDebug ( ) < < " paintMagnification = " < < paintMagnification ;
qDebug ( ) < < " lineWidthMultiplier = " < < lineWidthMultiplier ;
qDebug ( ) < < " fontSizeMultiplier = " < < fontSizeMultiplier ;
qDebug ( ) < < " printer resolution = " < < paintDevice - > logicalDpiX ( ) < < " dpi " ;
2019-02-08 00:24:46 +08:00
qDebug ( ) < < " \n plotLabelFontSize = " < < plotterStyle . plotLabelFontSize < < " pt " ;
qDebug ( ) < < " plotterStyle.keyStyle.fontSize = " < < plotterStyle . keyStyle . fontSize < < " pt " ;
2019-01-26 20:00:40 +08:00
qDebug ( ) < < " x-axis label fontsize = " < < xAxis - > getLabelFontSize ( ) < < " pt " ;
qDebug ( ) < < " y-axis label fontsize = " < < yAxis - > getLabelFontSize ( ) < < " pt " ;
2015-07-11 18:56:02 +08:00
# endif
2022-07-19 05:33:20 +08:00
# ifndef JKQTPLOTTER_COMPILE_WITHOUT_PRINTSUPPORT
2022-04-19 04:45:02 +08:00
if ( printer ) gridPaint ( painter , printer - > pageLayout ( ) . paintRectPixels ( printer - > resolution ( ) ) . size ( ) , printScaleToPagesize , printScaleToPagesize ) ;
2020-09-09 17:26:04 +08:00
else if ( svg ) gridPaint ( painter , svg - > size ( ) , printScaleToPagesize , printScaleToPagesize ) ;
else gridPaint ( painter , QSizeF ( paintDevice - > width ( ) , paintDevice - > height ( ) ) , printScaleToPagesize , printScaleToPagesize ) ;
2022-07-19 05:33:20 +08:00
# else
gridPaint ( painter , QSizeF ( paintDevice - > width ( ) , paintDevice - > height ( ) ) , printScaleToPagesize , printScaleToPagesize ) ;
# endif
2015-07-11 18:56:02 +08:00
painter . end ( ) ;
widgetWidth = oldWidgetWidth ;
widgetHeight = oldWidgetHeight ;
QApplication : : restoreOverrideCursor ( ) ;
QApplication : : processEvents ( ) ;
emitPlotSignals = oldEmitPlotSignals ;
lineWidthMultiplier = lw ;
fontSizeMultiplier = fs ;
paintMagnification = oldpm ;
2019-04-25 01:33:51 +08:00
plotterStyle . widgetBackgroundBrush = bc ;
2015-07-11 18:56:02 +08:00
}
2019-01-20 17:49:29 +08:00
void JKQTBasePlotter : : exportpreviewPaintRequested ( JKQTPEnhancedPainter & painter , QSize size ) {
2015-07-11 18:56:02 +08:00
double lw = lineWidthMultiplier ;
double fs = fontSizeMultiplier ;
2019-04-25 01:33:51 +08:00
QBrush bc = plotterStyle . widgetBackgroundBrush ;
plotterStyle . widgetBackgroundBrush = plotterStyle . exportBackgroundBrush ;
2015-07-11 18:56:02 +08:00
lineWidthMultiplier = lineWidthPrintMultiplier ;
fontSizeMultiplier = fontSizePrintMultiplier ;
bool oldEmitPlotSignals = emitPlotSignals ;
emitPlotSignals = false ;
QApplication : : setOverrideCursor ( QCursor ( Qt : : WaitCursor ) ) ;
QApplication : : processEvents ( ) ;
int oldWidgetWidth = widgetWidth ;
int oldWidgetHeight = widgetHeight ;
widgetWidth = size . width ( ) ;
widgetHeight = size . height ( ) ;
gridPaint ( painter , size ) ;
widgetWidth = oldWidgetWidth ;
widgetHeight = oldWidgetHeight ;
QApplication : : restoreOverrideCursor ( ) ;
QApplication : : processEvents ( ) ;
emitPlotSignals = oldEmitPlotSignals ;
lineWidthMultiplier = lw ;
fontSizeMultiplier = fs ;
2019-04-25 01:33:51 +08:00
plotterStyle . widgetBackgroundBrush = bc ;
2015-07-11 18:56:02 +08:00
}
2019-01-20 17:49:29 +08:00
void JKQTBasePlotter : : printpreviewSetZoom ( double value ) {
2015-07-11 18:56:02 +08:00
printZoomFactor = value / 100.0 ;
2022-07-19 05:33:20 +08:00
# ifndef JKQTPLOTTER_COMPILE_WITHOUT_PRINTSUPPORT
2015-07-11 18:56:02 +08:00
if ( printPreview ) printPreview - > updatePreview ( ) ;
2022-07-19 05:33:20 +08:00
# endif
2015-07-11 18:56:02 +08:00
if ( exportPreviewLabel ) updatePreviewLabel ( ) ;
}
2019-01-20 17:49:29 +08:00
void JKQTBasePlotter : : printpreviewSetSizeX ( double value ) {
2015-07-11 18:56:02 +08:00
printSizeX_Millimeter = value ;
if ( printKeepAspect ) {
printSizeY_Millimeter = printSizeX_Millimeter * printAspect ;
spinSizeY - > setValue ( printSizeY_Millimeter ) ;
}
if ( printDoUpdate ) {
2022-07-19 05:33:20 +08:00
# ifndef JKQTPLOTTER_COMPILE_WITHOUT_PRINTSUPPORT
2015-07-11 18:56:02 +08:00
if ( printPreview ) printPreview - > updatePreview ( ) ;
2022-07-19 05:33:20 +08:00
# endif
2015-07-11 18:56:02 +08:00
if ( exportPreviewLabel ) updatePreviewLabel ( ) ;
}
}
2022-07-19 05:33:20 +08:00
2019-01-20 17:49:29 +08:00
void JKQTBasePlotter : : printpreviewSetSizeY ( double value ) {
2015-07-11 18:56:02 +08:00
if ( printKeepAspect ) return ;
printSizeY_Millimeter = value ;
if ( printDoUpdate ) {
2022-07-19 05:33:20 +08:00
# ifndef JKQTPLOTTER_COMPILE_WITHOUT_PRINTSUPPORT
2015-07-11 18:56:02 +08:00
if ( printPreview ) printPreview - > updatePreview ( ) ;
2022-07-19 05:33:20 +08:00
# endif
2015-07-11 18:56:02 +08:00
if ( exportPreviewLabel ) updatePreviewLabel ( ) ;
}
}
2019-01-20 17:49:29 +08:00
void JKQTBasePlotter : : printpreviewSetSizeXNew ( double value ) {
2015-07-11 18:56:02 +08:00
printSizeX_Millimeter = value ;
if ( printKeepAspect ) {
printSizeY_Millimeter = printSizeX_Millimeter * printAspect ;
spinSizeY - > setValue ( printSizeY_Millimeter ) ;
}
}
2022-07-19 05:33:20 +08:00
2019-01-20 17:49:29 +08:00
void JKQTBasePlotter : : printpreviewSetSizeYNew ( double value ) {
2015-07-11 18:56:02 +08:00
printSizeY_Millimeter = value ;
}
2019-01-20 17:49:29 +08:00
void JKQTBasePlotter : : printpreviewSetMagnification ( double value ) {
2015-07-11 18:56:02 +08:00
printMagnification = value / 100.0 ;
2022-07-19 05:33:20 +08:00
# ifndef JKQTPLOTTER_COMPILE_WITHOUT_PRINTSUPPORT
2015-07-11 18:56:02 +08:00
if ( printPreview ) printPreview - > updatePreview ( ) ;
2022-07-19 05:33:20 +08:00
# endif
2015-07-11 18:56:02 +08:00
if ( exportPreviewLabel ) updatePreviewLabel ( ) ;
}
2019-01-20 17:49:29 +08:00
void JKQTBasePlotter : : printpreviewSetMagnificationNew ( double value )
2015-07-11 18:56:02 +08:00
{
printMagnification = value / 100.0 ;
printDoUpdate = false ;
if ( spinSizeY ) {
spinSizeY - > setValue ( printMagnification * printPageSizeMM . height ( ) ) ;
}
if ( spinSizeX ) {
spinSizeX - > setValue ( printMagnification * printPageSizeMM . width ( ) ) ;
}
printDoUpdate = true ;
}
2019-01-20 17:49:29 +08:00
void JKQTBasePlotter : : printpreviewSetAspectRatio ( bool checked ) {
2015-07-11 18:56:02 +08:00
printKeepAspect = checked ;
if ( printKeepAspect ) {
printSizeY_Millimeter = printSizeX_Millimeter * printAspect ;
spinSizeY - > setValue ( printSizeY_Millimeter ) ;
}
2022-07-19 05:33:20 +08:00
# ifndef JKQTPLOTTER_COMPILE_WITHOUT_PRINTSUPPORT
2015-07-11 18:56:02 +08:00
if ( printPreview ) printPreview - > updatePreview ( ) ;
2022-07-19 05:33:20 +08:00
# endif
2015-07-11 18:56:02 +08:00
if ( exportPreviewLabel ) updatePreviewLabel ( ) ;
}
2019-01-20 17:49:29 +08:00
void JKQTBasePlotter : : printpreviewSetKeepAbsFontsize ( bool checked )
2015-07-11 18:56:02 +08:00
{
printKeepAbsoluteFontSizes = checked ;
2022-07-19 05:33:20 +08:00
# ifndef JKQTPLOTTER_COMPILE_WITHOUT_PRINTSUPPORT
2015-07-11 18:56:02 +08:00
if ( printPreview ) printPreview - > updatePreview ( ) ;
2022-07-19 05:33:20 +08:00
# endif
2015-07-11 18:56:02 +08:00
if ( exportPreviewLabel ) updatePreviewLabel ( ) ;
}
2019-01-20 17:49:29 +08:00
void JKQTBasePlotter : : printpreviewToggleMagnification ( bool checked )
2015-07-11 18:56:02 +08:00
{
if ( checked ) {
if ( spinMagnification ) printpreviewSetMagnificationNew ( spinMagnification - > value ( ) ) ;
}
printpreviewUpdate ( ) ;
}
2019-01-20 17:49:29 +08:00
void JKQTBasePlotter : : printpreviewSetLineWidthMultiplier ( double value ) {
2015-07-11 18:56:02 +08:00
lineWidthPrintMultiplier = value / 100.0 ;
2022-07-19 05:33:20 +08:00
# ifndef JKQTPLOTTER_COMPILE_WITHOUT_PRINTSUPPORT
2015-07-11 18:56:02 +08:00
if ( printPreview ) printPreview - > updatePreview ( ) ;
2022-07-19 05:33:20 +08:00
# endif
2015-07-11 18:56:02 +08:00
if ( exportPreviewLabel ) updatePreviewLabel ( ) ;
}
2019-01-20 17:49:29 +08:00
void JKQTBasePlotter : : printpreviewSetFontSizeMultiplier ( double value ) {
2015-07-11 18:56:02 +08:00
fontSizePrintMultiplier = value / 100.0 ;
2022-07-19 05:33:20 +08:00
# ifndef JKQTPLOTTER_COMPILE_WITHOUT_PRINTSUPPORT
2015-07-11 18:56:02 +08:00
if ( printPreview ) printPreview - > updatePreview ( ) ;
2022-07-19 05:33:20 +08:00
# endif
2015-07-11 18:56:02 +08:00
if ( exportPreviewLabel ) updatePreviewLabel ( ) ;
}
2019-01-20 17:49:29 +08:00
void JKQTBasePlotter : : printpreviewUpdate ( )
2015-07-11 18:56:02 +08:00
{
if ( printDoUpdate ) {
2022-07-19 05:33:20 +08:00
# ifndef JKQTPLOTTER_COMPILE_WITHOUT_PRINTSUPPORT
2015-07-11 18:56:02 +08:00
if ( printPreview ) printPreview - > updatePreview ( ) ;
2022-07-19 05:33:20 +08:00
# endif
2015-07-11 18:56:02 +08:00
if ( exportPreviewLabel ) updatePreviewLabel ( ) ;
}
}
2020-09-09 17:26:04 +08:00
void JKQTBasePlotter : : draw ( JKQTPEnhancedPainter & painter , const QRect & rect ) {
2015-07-11 18:56:02 +08:00
# ifdef JKQTBP_AUTOTIMER
2020-09-09 17:26:04 +08:00
JKQTPAutoOutputTimer jkaaot ( QString ( " JKQTBasePlotter::draw(rect, %1) " )) ;
2015-07-11 18:56:02 +08:00
# endif
bool oldEmitPlotSignals = emitPlotSignals ;
emitPlotSignals = false ;
# ifdef JKQTBP_DEBUGTIMING
QString on = objectName ( ) ;
if ( on . isEmpty ( ) & & parent ( ) ) on = parent ( ) - > objectName ( ) ;
qDebug ( ) < < on < < " ::draw ... " ;
QElapsedTimer timeAll ;
timeAll . start ( ) ;
# endif
//resize(rect.width(), rect.height());
2019-02-08 00:24:46 +08:00
{
painter . save ( ) ; auto __finalpaint = JKQTPFinally ( [ & painter ] ( ) { painter . restore ( ) ; } ) ;
painter . translate ( rect . topLeft ( ) ) ;
# ifdef JKQTBP_DEBUGTIMING
QElapsedTimer time ;
time . start ( ) ;
# endif
2020-09-09 17:26:04 +08:00
gridPaint ( painter , rect . size ( ) ) ;
2019-02-08 00:24:46 +08:00
# ifdef JKQTBP_DEBUGTIMING
qDebug ( ) < < on < < " ::draw ... gridPaint = " < < time . nsecsElapsed ( ) / 1000 < < " usecs = " < < static_cast < double > ( time . nsecsElapsed ( ) ) / 1000000.0 < < " msecs " ;
# endif
}
2015-07-11 18:56:02 +08:00
emitPlotSignals = oldEmitPlotSignals ;
}
2020-09-09 17:26:04 +08:00
void JKQTBasePlotter : : draw ( JKQTPEnhancedPainter & painter , const QPoint & pos ) {
2015-07-11 18:56:02 +08:00
# ifdef JKQTBP_AUTOTIMER
2020-09-09 17:26:04 +08:00
JKQTPAutoOutputTimer jkaaot ( QString ( " JKQTBasePlotter::draw(pos, %1) " )) ;
2015-07-11 18:56:02 +08:00
# endif
bool oldEmitPlotSignals = emitPlotSignals ;
emitPlotSignals = false ;
# ifdef JKQTBP_DEBUGTIMING
QString on = objectName ( ) ;
if ( on . isEmpty ( ) & & parent ( ) ) on = parent ( ) - > objectName ( ) ;
qDebug ( ) < < on < < " ::draw ... " ;
QElapsedTimer timeAll ;
timeAll . start ( ) ;
# endif
2019-06-21 21:46:53 +08:00
QRectF rect ( pos , QSizeF ( widgetWidth / paintMagnification , widgetHeight / paintMagnification ) ) ;
2019-02-08 00:24:46 +08:00
{
painter . save ( ) ; auto __finalpaint = JKQTPFinally ( [ & painter ] ( ) { painter . restore ( ) ; } ) ;
painter . translate ( rect . topLeft ( ) ) ;
# ifdef JKQTBP_DEBUGTIMING
QElapsedTimer time ;
time . start ( ) ;
# endif
2020-09-09 17:26:04 +08:00
gridPaint ( painter , rect . size ( ) ) ;
2019-02-08 00:24:46 +08:00
# ifdef JKQTBP_DEBUGTIMING
qDebug ( ) < < on < < " ::draw ... gridPaint = " < < time . nsecsElapsed ( ) / 1000 < < " usecs = " < < static_cast < double > ( time . nsecsElapsed ( ) ) / 1000000.0 < < " msecs " ;
# endif
}
2015-07-11 18:56:02 +08:00
emitPlotSignals = oldEmitPlotSignals ;
}
2020-09-09 17:26:04 +08:00
void JKQTBasePlotter : : drawNonGrid ( JKQTPEnhancedPainter & painter , const QRect & rect ) {
2015-07-11 18:56:02 +08:00
# ifdef JKQTBP_AUTOTIMER
2020-09-09 17:26:04 +08:00
JKQTPAutoOutputTimer jkaaot ( QString ( " JKQTBasePlotter::drawNonGrid(rect, %1) " )) ;
2015-07-11 18:56:02 +08:00
# endif
bool oldEmitPlotSignals = emitPlotSignals ;
emitPlotSignals = false ;
# ifdef JKQTBP_DEBUGTIMING
QString on = objectName ( ) ;
if ( on . isEmpty ( ) & & parent ( ) ) on = parent ( ) - > objectName ( ) ;
qDebug ( ) < < on < < " ::drawNonGrid ... " ;
QElapsedTimer timeAll ;
timeAll . start ( ) ;
# endif
2019-02-08 00:24:46 +08:00
painter . save ( ) ; auto __finalpaint = JKQTPFinally ( [ & painter ] ( ) { painter . restore ( ) ; } ) ;
2015-07-11 18:56:02 +08:00
painter . translate ( rect . topLeft ( ) ) ;
# ifdef JKQTBP_DEBUGTIMING
QElapsedTimer time ;
time . start ( ) ;
# endif
calcPlotScaling ( painter ) ;
# ifdef JKQTBP_DEBUGTIMING
2019-01-26 20:00:40 +08:00
qDebug ( ) < < on < < " ::drawNonGrid ... calcPlotScaling = " < < time . nsecsElapsed ( ) / 1000 < < " usecs = " < < static_cast < double > ( time . nsecsElapsed ( ) ) / 1000000.0 < < " msecs " ;
2015-07-11 18:56:02 +08:00
# endif
2019-02-08 00:24:46 +08:00
{
double scale = static_cast < double > ( rect . width ( ) ) / static_cast < double > ( widgetWidth ) * paintMagnification ;
if ( ( scale * static_cast < double > ( widgetWidth ) / paintMagnification > static_cast < double > ( rect . width ( ) ) ) | | ( scale * static_cast < double > ( widgetHeight ) / paintMagnification > static_cast < double > ( rect . height ( ) ) ) ) {
scale = static_cast < double > ( rect . height ( ) ) / static_cast < double > ( widgetHeight ) * paintMagnification ;
}
2020-09-09 02:15:33 +08:00
painter . save ( ) ; auto __finalpaintinner = JKQTPFinally ( [ & painter ] ( ) { painter . restore ( ) ; } ) ;
2019-02-08 00:24:46 +08:00
// scale the plot so it fits on the page
painter . scale ( scale , scale ) ;
# ifdef JKQTBP_DEBUGTIMING
time . start ( ) ;
# endif
2020-09-09 17:26:04 +08:00
drawPlot ( painter ) ;
2019-02-08 00:24:46 +08:00
# ifdef JKQTBP_DEBUGTIMING
qDebug ( ) < < on < < " ::drawNonGrid ... paintPlot = " < < time . nsecsElapsed ( ) / 1000 < < " usecs = " < < static_cast < double > ( time . nsecsElapsed ( ) ) / 1000000.0 < < " msecs " ;
# endif
# ifdef JKQTBP_DEBUGTIMING
qDebug ( ) < < on < < " ::drawNonGrid ... DONE = " < < timeAll . nsecsElapsed ( ) / 1000 < < " usecs = " < < static_cast < double > ( timeAll . nsecsElapsed ( ) ) / 1000000.0 < < " msecs " ;
# endif
2015-07-11 18:56:02 +08:00
}
emitPlotSignals = oldEmitPlotSignals ;
}
2020-09-09 17:26:04 +08:00
void JKQTBasePlotter : : drawNonGrid ( JKQTPEnhancedPainter & painter , const QPoint & pos ) {
2015-07-11 18:56:02 +08:00
# ifdef JKQTBP_AUTOTIMER
2020-09-09 17:26:04 +08:00
JKQTPAutoOutputTimer jkaaot ( QString ( " JKQTBasePlotter::drawNonGrid(pos) " )) ;
2015-07-11 18:56:02 +08:00
# endif
bool oldEmitPlotSignals = emitPlotSignals ;
emitPlotSignals = false ;
# ifdef JKQTBP_DEBUGTIMING
QString on = objectName ( ) ;
if ( on . isEmpty ( ) & & parent ( ) ) on = parent ( ) - > objectName ( ) ;
qDebug ( ) < < on < < " ::drawNonGrid ... " ;
QElapsedTimer timeAll ;
timeAll . start ( ) ;
# endif
2019-06-21 21:46:53 +08:00
QRectF rect ( pos , QSizeF ( widgetWidth / paintMagnification , widgetHeight / paintMagnification ) ) ;
2019-02-08 00:24:46 +08:00
painter . save ( ) ; auto __finalpaint = JKQTPFinally ( [ & painter ] ( ) { painter . restore ( ) ; } ) ;
2015-07-11 18:56:02 +08:00
painter . translate ( rect . topLeft ( ) ) ;
# ifdef JKQTBP_DEBUGTIMING
QElapsedTimer time ;
time . start ( ) ;
# endif
calcPlotScaling ( painter ) ;
# ifdef JKQTBP_DEBUGTIMING
2019-01-26 20:00:40 +08:00
qDebug ( ) < < on < < " ::drawNonGrid ... calcPlotScaling = " < < time . nsecsElapsed ( ) / 1000 < < " usecs = " < < static_cast < double > ( time . nsecsElapsed ( ) ) / 1000000.0 < < " msecs " ;
2015-07-11 18:56:02 +08:00
# endif
2019-02-08 00:24:46 +08:00
{
double scale = static_cast < double > ( rect . width ( ) ) / static_cast < double > ( widgetWidth ) * paintMagnification ;
if ( ( scale * static_cast < double > ( widgetWidth ) / paintMagnification > static_cast < double > ( rect . width ( ) ) ) | | ( scale * static_cast < double > ( widgetHeight ) / paintMagnification > static_cast < double > ( rect . height ( ) ) ) ) {
scale = static_cast < double > ( rect . height ( ) ) / static_cast < double > ( widgetHeight ) * paintMagnification ;
}
2020-08-26 17:00:25 +08:00
painter . save ( ) ; auto __finalpaintinner = JKQTPFinally ( [ & painter ] ( ) { painter . restore ( ) ; } ) ;
2019-02-08 00:24:46 +08:00
// scale the plot so it fits on the page
painter . scale ( scale , scale ) ;
# ifdef JKQTBP_DEBUGTIMING
time . start ( ) ;
# endif
2020-09-09 17:26:04 +08:00
drawPlot ( painter ) ;
2019-02-08 00:24:46 +08:00
# ifdef JKQTBP_DEBUGTIMING
qDebug ( ) < < on < < " ::drawNonGrid ... paintPlot = " < < time . nsecsElapsed ( ) / 1000 < < " usecs = " < < static_cast < double > ( time . nsecsElapsed ( ) ) / 1000000.0 < < " msecs " ;
# endif
}
# ifdef JKQTBP_DEBUGTIMING
qDebug ( ) < < on < < " ::drawNonGrid ... DONE = " < < timeAll . nsecsElapsed ( ) / 1000 < < " usecs = " < < static_cast < double > ( timeAll . nsecsElapsed ( ) ) / 1000000.0 < < " msecs " ;
# endif
emitPlotSignals = oldEmitPlotSignals ;
}
2023-03-23 20:55:18 +08:00
void JKQTBasePlotter : : updateSecondaryAxes ( )
{
}
2019-02-08 00:24:46 +08:00
void JKQTBasePlotter : : setEmittingPlotSignalsEnabled ( bool __value )
{
this - > emitPlotSignals = __value ;
}
bool JKQTBasePlotter : : isEmittingPlotSignalsEnabled ( ) const
{
return this - > emitPlotSignals ;
}
2020-08-26 17:00:25 +08:00
int JKQTBasePlotter : : getPlotBorderTop ( ) const {
return this - > plotterStyle . plotBorderTop ;
}
2019-02-08 00:24:46 +08:00
2020-08-26 17:00:25 +08:00
int JKQTBasePlotter : : getPlotBorderLeft ( ) const {
return this - > plotterStyle . plotBorderLeft ;
}
2019-02-08 00:24:46 +08:00
2020-08-26 17:00:25 +08:00
int JKQTBasePlotter : : getPlotBorderBottom ( ) const {
return this - > plotterStyle . plotBorderBottom ;
}
2019-02-08 00:24:46 +08:00
2020-08-26 17:00:25 +08:00
int JKQTBasePlotter : : getPlotBorderRight ( ) const {
return this - > plotterStyle . plotBorderRight ;
}
2019-02-08 00:24:46 +08:00
2020-08-26 17:00:25 +08:00
bool JKQTBasePlotter : : doesMaintainAspectRatio ( ) const {
return this - > maintainAspectRatio ;
}
2019-02-08 00:24:46 +08:00
void JKQTBasePlotter : : setAspectRatio ( double __value )
{
2019-06-21 21:46:53 +08:00
if ( jkqtp_approximatelyUnequal ( this - > aspectRatio , __value ) ) {
2019-02-08 00:24:46 +08:00
this - > aspectRatio = __value ;
2020-09-12 05:19:31 +08:00
setXY ( getXMin ( ) , getXMax ( ) , getYMin ( ) , getYMax ( ) ) ;
2019-02-08 00:24:46 +08:00
redrawPlot ( ) ;
}
}
double JKQTBasePlotter : : getAspectRatio ( ) const
{
return this - > aspectRatio ;
}
2020-08-26 17:00:25 +08:00
bool JKQTBasePlotter : : doesMaintainAxisAspectRatio ( ) const {
return this - > maintainAxisAspectRatio ;
}
2019-02-08 00:24:46 +08:00
double JKQTBasePlotter : : getAxisAspectRatio ( ) const
{
return this - > axisAspectRatio ;
}
bool JKQTBasePlotter : : isUsingAntiAliasingForSystem ( ) const
{
return this - > plotterStyle . useAntiAliasingForSystem ;
}
bool JKQTBasePlotter : : isUsingAntiAliasingForGraphs ( ) const
{
2020-09-26 21:58:58 +08:00
return this - > plotterStyle . graphsStyle . useAntiAliasingForGraphs ;
2019-02-08 00:24:46 +08:00
}
bool JKQTBasePlotter : : isUsingAntiAliasingForText ( ) const
{
return this - > plotterStyle . useAntiAliasingForText ;
}
void JKQTBasePlotter : : setBackgroundColor ( const QColor & __value )
{
2019-04-25 01:33:51 +08:00
if ( this - > plotterStyle . widgetBackgroundBrush ! = QBrush ( __value ) ) {
this - > plotterStyle . widgetBackgroundBrush = QBrush ( __value ) ;
2019-02-08 00:24:46 +08:00
redrawPlot ( ) ;
}
}
QColor JKQTBasePlotter : : getBackgroundColor ( ) const
{
2019-04-25 01:33:51 +08:00
return this - > plotterStyle . widgetBackgroundBrush . color ( ) ;
2019-02-08 00:24:46 +08:00
}
void JKQTBasePlotter : : setExportBackgroundColor ( const QColor & __value )
{
2019-04-25 01:33:51 +08:00
if ( this - > plotterStyle . exportBackgroundBrush ! = QBrush ( __value ) ) {
this - > plotterStyle . exportBackgroundBrush = QBrush ( __value ) ;
2019-02-08 00:24:46 +08:00
redrawPlot ( ) ;
}
}
QColor JKQTBasePlotter : : getExportBackgroundColor ( ) const
{
2019-04-25 01:33:51 +08:00
return this - > plotterStyle . exportBackgroundBrush . color ( ) ;
2019-02-08 00:24:46 +08:00
}
QColor JKQTBasePlotter : : getPlotBackgroundColor ( ) const
{
2019-04-25 01:33:51 +08:00
return this - > plotterStyle . plotBackgroundBrush . color ( ) ;
}
QBrush JKQTBasePlotter : : getBackgroundBrush ( ) const
{
return this - > plotterStyle . widgetBackgroundBrush ;
}
QBrush JKQTBasePlotter : : getExportBackgroundBrush ( ) const
{
return this - > plotterStyle . exportBackgroundBrush ;
}
QBrush JKQTBasePlotter : : getPlotBackgroundBrush ( ) const
{
return this - > plotterStyle . plotBackgroundBrush ;
2019-02-08 00:24:46 +08:00
}
void JKQTBasePlotter : : setKeyFontSize ( double __value )
{
2019-06-21 21:46:53 +08:00
if ( jkqtp_approximatelyUnequal ( this - > plotterStyle . keyStyle . fontSize , __value ) ) {
2019-02-08 00:24:46 +08:00
this - > plotterStyle . keyStyle . fontSize = __value ;
redrawPlot ( ) ;
}
}
double JKQTBasePlotter : : getKeyFontSize ( ) const
{
return this - > plotterStyle . keyStyle . fontSize ;
}
void JKQTBasePlotter : : setKeyTextColor ( const QColor & __value )
{
if ( this - > plotterStyle . keyStyle . textColor ! = __value ) {
this - > plotterStyle . keyStyle . textColor = __value ;
redrawPlot ( ) ;
}
}
QColor JKQTBasePlotter : : getKeyTextColor ( ) const
{
return this - > plotterStyle . keyStyle . textColor ;
}
void JKQTBasePlotter : : setKeyItemWidth ( double __value )
{
2019-06-21 21:46:53 +08:00
if ( jkqtp_approximatelyUnequal ( this - > plotterStyle . keyStyle . itemWidth , __value ) ) {
2019-02-08 00:24:46 +08:00
this - > plotterStyle . keyStyle . itemWidth = __value ;
redrawPlot ( ) ;
}
}
double JKQTBasePlotter : : getKeyItemWidth ( ) const
{
return this - > plotterStyle . keyStyle . itemWidth ;
}
void JKQTBasePlotter : : setKeyItemHeight ( double __value )
{
2019-06-21 21:46:53 +08:00
if ( jkqtp_approximatelyUnequal ( this - > plotterStyle . keyStyle . itemHeight , __value ) ) {
2019-02-08 00:24:46 +08:00
this - > plotterStyle . keyStyle . itemHeight = __value ;
redrawPlot ( ) ;
}
}
double JKQTBasePlotter : : getKeyItemHeight ( ) const
{
return this - > plotterStyle . keyStyle . itemHeight ;
}
void JKQTBasePlotter : : setKeyYSeparation ( double __value )
{
2019-06-21 21:46:53 +08:00
if ( jkqtp_approximatelyUnequal ( this - > plotterStyle . keyStyle . ySeparation , __value ) ) {
2019-02-08 00:24:46 +08:00
this - > plotterStyle . keyStyle . ySeparation = __value ;
redrawPlot ( ) ;
}
}
double JKQTBasePlotter : : getKeyYSeparation ( ) const
{
return this - > plotterStyle . keyStyle . ySeparation ;
}
void JKQTBasePlotter : : setKeyLineLength ( double __value )
{
2019-06-21 21:46:53 +08:00
if ( jkqtp_approximatelyUnequal ( this - > plotterStyle . keyStyle . sampleLineLength , __value ) ) {
2019-02-08 00:24:46 +08:00
this - > plotterStyle . keyStyle . sampleLineLength = __value ;
redrawPlot ( ) ;
}
}
double JKQTBasePlotter : : getKeyLineLength ( ) const
{
return this - > plotterStyle . keyStyle . sampleLineLength ;
}
void JKQTBasePlotter : : setKeyXMargin ( double __value )
{
2019-06-21 21:46:53 +08:00
if ( jkqtp_approximatelyUnequal ( this - > plotterStyle . keyStyle . xMargin , __value ) ) {
2019-02-08 00:24:46 +08:00
this - > plotterStyle . keyStyle . xMargin = __value ;
redrawPlot ( ) ;
}
}
double JKQTBasePlotter : : getKeyXMargin ( ) const
{
return this - > plotterStyle . keyStyle . xMargin ;
}
void JKQTBasePlotter : : setKeyYMargin ( double __value )
{
2019-06-21 21:46:53 +08:00
if ( jkqtp_approximatelyUnequal ( this - > plotterStyle . keyStyle . yMargin , __value ) ) {
2019-02-08 00:24:46 +08:00
this - > plotterStyle . keyStyle . yMargin = __value ;
redrawPlot ( ) ;
}
}
double JKQTBasePlotter : : getKeyYMargin ( ) const
{
return this - > plotterStyle . keyStyle . yMargin ;
}
void JKQTBasePlotter : : setKeyXSeparation ( double __value )
{
2019-06-21 21:46:53 +08:00
if ( jkqtp_approximatelyUnequal ( this - > plotterStyle . keyStyle . xSeparation , __value ) ) {
2019-02-08 00:24:46 +08:00
this - > plotterStyle . keyStyle . xSeparation = __value ;
redrawPlot ( ) ;
}
}
double JKQTBasePlotter : : getKeyXSeparation ( ) const
{
return this - > plotterStyle . keyStyle . xSeparation ;
}
void JKQTBasePlotter : : setKeyXOffset ( double __value )
{
2019-06-21 21:46:53 +08:00
if ( jkqtp_approximatelyUnequal ( this - > plotterStyle . keyStyle . xOffset , __value ) ) {
2019-02-08 00:24:46 +08:00
this - > plotterStyle . keyStyle . xOffset = __value ;
redrawPlot ( ) ;
}
}
double JKQTBasePlotter : : getKeyXOffset ( ) const
{
return this - > plotterStyle . keyStyle . xOffset ;
}
void JKQTBasePlotter : : setKeyYOffset ( double __value )
{
2019-06-21 21:46:53 +08:00
if ( jkqtp_approximatelyUnequal ( this - > plotterStyle . keyStyle . yOffset , __value ) ) {
2019-02-08 00:24:46 +08:00
this - > plotterStyle . keyStyle . yOffset = __value ;
redrawPlot ( ) ;
}
}
double JKQTBasePlotter : : getKeyYOffset ( ) const
{
return this - > plotterStyle . keyStyle . yOffset ;
}
void JKQTBasePlotter : : setShowKey ( bool __value )
{
if ( this - > plotterStyle . keyStyle . visible ! = __value ) {
this - > plotterStyle . keyStyle . visible = __value ;
redrawPlot ( ) ;
}
}
bool JKQTBasePlotter : : getShowKey ( ) const
{
return this - > plotterStyle . keyStyle . visible ;
}
void JKQTBasePlotter : : setShowKeyFrame ( bool __value )
{
if ( this - > plotterStyle . keyStyle . frameVisible ! = __value ) {
this - > plotterStyle . keyStyle . frameVisible = __value ;
redrawPlot ( ) ;
}
}
bool JKQTBasePlotter : : getShowKeyFrame ( ) const
{
return this - > plotterStyle . keyStyle . frameVisible ;
}
void JKQTBasePlotter : : setKeyFrameColor ( const QColor & __value )
{
if ( this - > plotterStyle . keyStyle . frameColor ! = __value ) {
this - > plotterStyle . keyStyle . frameColor = __value ;
redrawPlot ( ) ;
}
}
QColor JKQTBasePlotter : : getKeyFrameColor ( ) const
{
return this - > plotterStyle . keyStyle . frameColor ;
}
2019-04-25 01:33:51 +08:00
void JKQTBasePlotter : : setKeyBackgroundColor ( const QColor & __value , Qt : : BrushStyle __style )
{
if ( this - > plotterStyle . keyStyle . backgroundBrush ! = QBrush ( __value , __style ) ) {
this - > plotterStyle . keyStyle . backgroundBrush = QBrush ( __value , __style ) ;
redrawPlot ( ) ;
}
}
void JKQTBasePlotter : : setKeyBackgroundBrush ( const QBrush & __value )
{
if ( this - > plotterStyle . keyStyle . backgroundBrush ! = __value ) {
this - > plotterStyle . keyStyle . backgroundBrush = __value ;
redrawPlot ( ) ;
}
}
void JKQTBasePlotter : : setKeyBackgroundGradient ( const QGradient & __value )
{
if ( this - > plotterStyle . keyStyle . backgroundBrush ! = QBrush ( __value ) ) {
this - > plotterStyle . keyStyle . backgroundBrush = QBrush ( __value ) ;
redrawPlot ( ) ;
}
}
void JKQTBasePlotter : : setKeyBackgroundTexture ( const QImage & __value )
{
if ( this - > plotterStyle . keyStyle . backgroundBrush ! = QBrush ( __value ) ) {
this - > plotterStyle . keyStyle . backgroundBrush = QBrush ( __value ) ;
redrawPlot ( ) ;
}
}
void JKQTBasePlotter : : setKeyBackgroundTexture ( const QPixmap & __value )
2019-02-08 00:24:46 +08:00
{
2019-04-25 01:33:51 +08:00
if ( this - > plotterStyle . keyStyle . backgroundBrush ! = QBrush ( __value ) ) {
this - > plotterStyle . keyStyle . backgroundBrush = QBrush ( __value ) ;
2019-02-08 00:24:46 +08:00
redrawPlot ( ) ;
}
}
2019-04-25 01:33:51 +08:00
2019-02-08 00:24:46 +08:00
void JKQTBasePlotter : : setKeyFrameWidth ( double __value )
{
2019-06-21 21:46:53 +08:00
if ( jkqtp_approximatelyUnequal ( this - > plotterStyle . keyStyle . frameWidth , __value ) ) {
2019-02-08 00:24:46 +08:00
this - > plotterStyle . keyStyle . frameWidth = __value ;
redrawPlot ( ) ;
}
}
void JKQTBasePlotter : : setKeyFrameRounding ( double __value )
{
2019-06-21 21:46:53 +08:00
if ( jkqtp_approximatelyUnequal ( this - > plotterStyle . keyStyle . frameRounding , __value ) ) {
2019-02-08 00:24:46 +08:00
this - > plotterStyle . keyStyle . frameRounding = __value ;
redrawPlot ( ) ;
}
}
double JKQTBasePlotter : : getKeyFrameWidth ( ) const
{
return this - > plotterStyle . keyStyle . frameWidth ;
}
double JKQTBasePlotter : : getKeyFrameRounding ( ) const
{
return this - > plotterStyle . keyStyle . frameRounding ;
}
void JKQTBasePlotter : : setKeyAutosize ( bool __value )
{
if ( this - > plotterStyle . keyStyle . autosize ! = __value ) {
this - > plotterStyle . keyStyle . autosize = __value ;
redrawPlot ( ) ;
}
}
bool JKQTBasePlotter : : getKeyAutosize ( ) const
{
return this - > plotterStyle . keyStyle . autosize ;
}
void JKQTBasePlotter : : setKeyPosition ( const JKQTPKeyPosition & __value )
{
if ( this - > plotterStyle . keyStyle . position ! = __value ) {
this - > plotterStyle . keyStyle . position = __value ;
redrawPlot ( ) ;
}
}
JKQTPKeyPosition JKQTBasePlotter : : getKeyPosition ( ) const
{
return this - > plotterStyle . keyStyle . position ;
}
void JKQTBasePlotter : : setKeyLayout ( const JKQTPKeyLayout & __value )
{
if ( this - > plotterStyle . keyStyle . layout ! = __value ) {
this - > plotterStyle . keyStyle . layout = __value ;
redrawPlot ( ) ;
}
}
JKQTPKeyLayout JKQTBasePlotter : : getKeyLayout ( ) const
{
return this - > plotterStyle . keyStyle . layout ;
}
QColor JKQTBasePlotter : : getDefaultTextColor ( ) const
{
return this - > plotterStyle . defaultTextColor ;
}
double JKQTBasePlotter : : getDefaultTextSize ( ) const
{
return this - > plotterStyle . defaultFontSize ;
}
QString JKQTBasePlotter : : getDefaultTextFontName ( ) const
{
return this - > plotterStyle . defaultFontName ;
}
void JKQTBasePlotter : : setDefaultTextColor ( QColor __value )
{
if ( this - > plotterStyle . defaultTextColor ! = __value ) {
this - > plotterStyle . defaultTextColor = __value ;
redrawPlot ( ) ;
}
}
2019-06-21 21:46:53 +08:00
void JKQTBasePlotter : : setDefaultTextSize ( double __value )
2019-02-08 00:24:46 +08:00
{
2019-06-21 21:46:53 +08:00
if ( jkqtp_approximatelyUnequal ( this - > plotterStyle . defaultFontSize , __value ) ) {
2019-02-08 00:24:46 +08:00
this - > plotterStyle . defaultFontSize = __value ;
redrawPlot ( ) ;
}
}
void JKQTBasePlotter : : setDefaultTextFontName ( const QString & __value )
{
if ( this - > plotterStyle . defaultFontName ! = __value ) {
this - > plotterStyle . defaultFontName = __value ;
redrawPlot ( ) ;
}
}
void JKQTBasePlotter : : setPlotLabelFontSize ( double __value )
{
2019-06-21 21:46:53 +08:00
if ( jkqtp_approximatelyUnequal ( this - > plotterStyle . plotLabelFontSize , __value ) ) {
2019-02-08 00:24:46 +08:00
this - > plotterStyle . plotLabelFontSize = __value ;
redrawPlot ( ) ;
}
}
double JKQTBasePlotter : : getPlotLabelFontSize ( ) const
{
return this - > plotterStyle . plotLabelFontSize ;
}
void JKQTBasePlotter : : setplotLabelFontName ( const QString & __value )
{
if ( this - > plotterStyle . plotLabelFontName ! = __value ) {
this - > plotterStyle . plotLabelFontName = __value ;
redrawPlot ( ) ;
}
}
QString JKQTBasePlotter : : getplotLabelFontName ( ) const
{
return this - > plotterStyle . plotLabelFontName ;
}
void JKQTBasePlotter : : setPlotLabel ( const QString & __value )
{
if ( this - > plotLabel ! = __value ) {
this - > plotLabel = __value ;
redrawPlot ( ) ;
}
}
QString JKQTBasePlotter : : getPlotLabel ( ) const
{
return this - > plotLabel ;
}
QColor JKQTBasePlotter : : getKeyBackgroundColor ( ) const
{
2019-04-25 01:33:51 +08:00
return this - > plotterStyle . keyStyle . backgroundBrush . color ( ) ;
}
QBrush JKQTBasePlotter : : getKeyBackgroundBrush ( ) const
{
return this - > plotterStyle . keyStyle . backgroundBrush ;
2019-02-08 00:24:46 +08:00
}
void JKQTBasePlotter : : setPlotBackgroundColor ( const QColor & __value )
{
2019-04-25 01:33:51 +08:00
if ( this - > plotterStyle . plotBackgroundBrush ! = QBrush ( __value ) ) {
this - > plotterStyle . plotBackgroundBrush = QBrush ( __value ) ;
redrawPlot ( ) ;
}
}
void JKQTBasePlotter : : setBackgroundBrush ( const QBrush & __value )
{
if ( this - > plotterStyle . widgetBackgroundBrush ! = ( __value ) ) {
this - > plotterStyle . widgetBackgroundBrush = ( __value ) ;
redrawPlot ( ) ;
}
}
void JKQTBasePlotter : : setExportBackgroundBrush ( const QBrush & __value )
{
if ( this - > plotterStyle . exportBackgroundBrush ! = ( __value ) ) {
this - > plotterStyle . exportBackgroundBrush = ( __value ) ;
redrawPlot ( ) ;
}
}
void JKQTBasePlotter : : setPlotBackgroundBrush ( const QBrush & __value )
{
if ( this - > plotterStyle . plotBackgroundBrush ! = ( __value ) ) {
this - > plotterStyle . plotBackgroundBrush = ( __value ) ;
redrawPlot ( ) ;
}
}
void JKQTBasePlotter : : setBackgroundGradient ( const QGradient & __value )
{
if ( this - > plotterStyle . widgetBackgroundBrush ! = QBrush ( __value ) ) {
this - > plotterStyle . widgetBackgroundBrush = QBrush ( __value ) ;
redrawPlot ( ) ;
}
}
void JKQTBasePlotter : : setExportBackgroundGradient ( const QGradient & __value )
{
if ( this - > plotterStyle . exportBackgroundBrush ! = QBrush ( __value ) ) {
this - > plotterStyle . exportBackgroundBrush = QBrush ( __value ) ;
redrawPlot ( ) ;
}
}
void JKQTBasePlotter : : setPlotBackgroundGradient ( const QGradient & __value )
{
if ( this - > plotterStyle . plotBackgroundBrush ! = QBrush ( __value ) ) {
this - > plotterStyle . plotBackgroundBrush = QBrush ( __value ) ;
redrawPlot ( ) ;
}
}
void JKQTBasePlotter : : setBackgroundTexture ( const QPixmap & __value )
{
if ( this - > plotterStyle . widgetBackgroundBrush ! = QBrush ( __value ) ) {
this - > plotterStyle . widgetBackgroundBrush = QBrush ( __value ) ;
redrawPlot ( ) ;
}
}
void JKQTBasePlotter : : setExportBackgroundTexture ( const QPixmap & __value )
{
if ( this - > plotterStyle . exportBackgroundBrush ! = QBrush ( __value ) ) {
this - > plotterStyle . exportBackgroundBrush = QBrush ( __value ) ;
redrawPlot ( ) ;
}
}
void JKQTBasePlotter : : setPlotBackgroundTexture ( const QPixmap & __value )
{
if ( this - > plotterStyle . plotBackgroundBrush ! = QBrush ( __value ) ) {
this - > plotterStyle . plotBackgroundBrush = QBrush ( __value ) ;
redrawPlot ( ) ;
}
}
void JKQTBasePlotter : : setBackgroundTexture ( const QImage & __value )
{
if ( this - > plotterStyle . widgetBackgroundBrush ! = QBrush ( __value ) ) {
this - > plotterStyle . widgetBackgroundBrush = QBrush ( __value ) ;
redrawPlot ( ) ;
}
}
void JKQTBasePlotter : : setExportBackgroundTexture ( const QImage & __value )
{
if ( this - > plotterStyle . exportBackgroundBrush ! = QBrush ( __value ) ) {
this - > plotterStyle . exportBackgroundBrush = QBrush ( __value ) ;
redrawPlot ( ) ;
}
}
void JKQTBasePlotter : : setPlotBackgroundTexture ( const QImage & __value )
{
if ( this - > plotterStyle . plotBackgroundBrush ! = QBrush ( __value ) ) {
this - > plotterStyle . plotBackgroundBrush = QBrush ( __value ) ;
2019-02-08 00:24:46 +08:00
redrawPlot ( ) ;
}
}
bool JKQTBasePlotter : : isPlotFrameVisible ( ) const
{
return plotterStyle . plotFrameVisible ;
}
QColor JKQTBasePlotter : : getPlotFrameColor ( ) const
{
return plotterStyle . plotFrameColor ;
}
double JKQTBasePlotter : : getPlotFrameWidth ( ) const
{
return plotterStyle . plotFrameWidth ;
}
double JKQTBasePlotter : : getPlotFrameRounding ( ) const
{
return plotterStyle . plotFrameRounding ;
}
void JKQTBasePlotter : : setPlotFrameWidth ( double __value )
{
2019-06-21 21:46:53 +08:00
if ( jkqtp_approximatelyUnequal ( this - > plotterStyle . plotFrameWidth , __value ) ) {
2019-02-08 00:24:46 +08:00
this - > plotterStyle . plotFrameWidth = __value ;
redrawPlot ( ) ;
}
2015-07-11 18:56:02 +08:00
}
2019-02-08 00:24:46 +08:00
void JKQTBasePlotter : : setPlotFrameRounding ( double __value )
{
2019-06-21 21:46:53 +08:00
if ( jkqtp_approximatelyUnequal ( this - > plotterStyle . plotFrameRounding , __value ) ) {
2019-02-08 00:24:46 +08:00
this - > plotterStyle . plotFrameRounding = __value ;
redrawPlot ( ) ;
2015-07-11 18:56:02 +08:00
}
}
2019-02-08 00:24:46 +08:00
void JKQTBasePlotter : : setPlotFrameColor ( QColor __value )
2019-01-26 19:28:44 +08:00
{
2019-02-08 00:24:46 +08:00
if ( this - > plotterStyle . plotFrameColor ! = __value ) {
this - > plotterStyle . plotFrameColor = __value ;
redrawPlot ( ) ;
}
2019-01-26 19:28:44 +08:00
}
2019-02-08 00:24:46 +08:00
void JKQTBasePlotter : : setPlotFrameVisible ( bool __value )
2019-01-26 19:28:44 +08:00
{
2019-02-08 00:24:46 +08:00
if ( this - > plotterStyle . plotFrameVisible ! = __value ) {
this - > plotterStyle . plotFrameVisible = __value ;
redrawPlot ( ) ;
}
}
void JKQTBasePlotter : : setUseAntiAliasingForText ( bool __value )
{
if ( this - > plotterStyle . useAntiAliasingForText ! = __value ) {
this - > plotterStyle . useAntiAliasingForText = __value ;
redrawPlot ( ) ;
}
}
void JKQTBasePlotter : : setUseAntiAliasingForGraphs ( bool __value )
{
2020-09-26 21:58:58 +08:00
if ( this - > plotterStyle . graphsStyle . useAntiAliasingForGraphs ! = __value ) {
this - > plotterStyle . graphsStyle . useAntiAliasingForGraphs = __value ;
2019-02-08 00:24:46 +08:00
redrawPlot ( ) ;
}
}
void JKQTBasePlotter : : setUseAntiAliasingForSystem ( bool __value )
{
if ( this - > plotterStyle . useAntiAliasingForSystem ! = __value ) {
this - > plotterStyle . useAntiAliasingForSystem = __value ;
redrawPlot ( ) ;
}
}
void JKQTBasePlotter : : setAxisAspectRatio ( double __value )
{
2019-06-21 21:46:53 +08:00
if ( jkqtp_approximatelyUnequal ( this - > axisAspectRatio , __value ) ) {
2019-02-08 00:24:46 +08:00
this - > axisAspectRatio = __value ;
redrawPlot ( ) ;
}
2019-01-26 19:28:44 +08:00
}
2019-01-29 05:14:27 +08:00
void JKQTBasePlotter : : setGridPrinting ( bool __value )
{
this - > gridPrinting = __value ;
}
bool JKQTBasePlotter : : getGridPrinting ( ) const
{
return this - > gridPrinting ;
}
void JKQTBasePlotter : : setGridPrintingCurrentX ( size_t __value )
{
this - > gridPrintingCurrentX = __value ;
}
size_t JKQTBasePlotter : : getGridPrintingCurrentX ( ) const
{
return this - > gridPrintingCurrentX ;
}
void JKQTBasePlotter : : setGridPrintingCurrentY ( size_t __value )
{
this - > gridPrintingCurrentY = __value ;
}
size_t JKQTBasePlotter : : getGridPrintingCurrentY ( ) const
{
return this - > gridPrintingCurrentY ;
}
void JKQTBasePlotter : : setGridPrintingCurrentPos ( size_t x , size_t y )
{
gridPrintingCurrentX = x ;
gridPrintingCurrentY = y ;
}
2019-02-08 00:24:46 +08:00
void JKQTBasePlotter : : setCurrentSaveDirectory ( const QString & __value )
{
this - > currentSaveDirectory = __value ;
}
QString JKQTBasePlotter : : getCurrentSaveDirectory ( ) const
{
return this - > currentSaveDirectory ;
}
void JKQTBasePlotter : : setCurrentFileFormat ( const QString & __value )
{
this - > currentFileFormat = __value ;
}
QString JKQTBasePlotter : : getCurrentFileFormat ( ) const
{
return this - > currentFileFormat ;
}
void JKQTBasePlotter : : setCSVdecimalSeparator ( const QString & __value )
{
plotterStyle . CSVdecimalSeparator = __value ;
}
void JKQTBasePlotter : : setCSVcommentInitializer ( const QString & __value )
{
plotterStyle . CSVcommentInitializer = __value ;
}
void JKQTBasePlotter : : enableDebugShowRegionBoxes ( bool enabled )
{
if ( plotterStyle . debugShowRegionBoxes ! = enabled ) {
plotterStyle . debugShowRegionBoxes = enabled ;
redrawPlot ( ) ;
}
}
2022-06-03 05:05:58 +08:00
void JKQTBasePlotter : : enableDebugShowTextBoxes ( bool enabled )
{
if ( plotterStyle . debugShowTextBoxes ! = enabled ) {
plotterStyle . debugShowTextBoxes = enabled ;
redrawPlot ( ) ;
}
}
2019-02-08 00:24:46 +08:00
bool JKQTBasePlotter : : isDebugShowRegionBoxesEnabled ( ) const
{
return plotterStyle . debugShowRegionBoxes ;
}
2022-06-03 05:05:58 +08:00
bool JKQTBasePlotter : : isDebugShowTextBoxesEnabled ( ) const
{
return plotterStyle . debugShowTextBoxes ;
}
2019-02-08 00:24:46 +08:00
QString JKQTBasePlotter : : getCSVcommentInitializer ( ) const
{
return plotterStyle . CSVcommentInitializer ;
}
JKQTMathText * JKQTBasePlotter : : getMathText ( ) {
return & mathText ;
}
const JKQTMathText * JKQTBasePlotter : : getMathText ( ) const {
return & mathText ;
}
2023-03-23 20:55:18 +08:00
JKQTPHorizontalAxisBase * JKQTBasePlotter : : getXAxis ( JKQTPCoordinateAxisRef axis ) {
if ( axis = = JKQTPPrimaryAxis ) return xAxis ;
else return secondaryXAxis [ axis ] ;
2019-02-08 00:24:46 +08:00
}
2023-03-23 20:55:18 +08:00
JKQTPVerticalAxisBase * JKQTBasePlotter : : getYAxis ( JKQTPCoordinateAxisRef axis ) {
if ( axis = = JKQTPPrimaryAxis ) return yAxis ;
else return secondaryYAxis [ axis ] ;
2019-02-08 00:24:46 +08:00
}
2023-03-23 20:55:18 +08:00
const JKQTPHorizontalAxisBase * JKQTBasePlotter : : getXAxis ( JKQTPCoordinateAxisRef axis ) const {
if ( axis = = JKQTPPrimaryAxis ) return xAxis ;
else return secondaryXAxis [ axis ] ;
2019-02-08 00:24:46 +08:00
}
2023-03-23 20:55:18 +08:00
const JKQTPVerticalAxisBase * JKQTBasePlotter : : getYAxis ( JKQTPCoordinateAxisRef axis ) const {
if ( axis = = JKQTPPrimaryAxis ) return yAxis ;
else return secondaryYAxis [ axis ] ;
}
bool JKQTBasePlotter : : hasXAxis ( JKQTPCoordinateAxisRef axis ) const
{
return secondaryXAxis . contains ( axis ) ;
}
bool JKQTBasePlotter : : hasYAxis ( JKQTPCoordinateAxisRef axis ) const
{
return secondaryYAxis . contains ( axis ) ;
}
QSet < JKQTPCoordinateAxisRef > JKQTBasePlotter : : getAvailableXAxisRefs ( bool includePrimary ) const
{
2023-03-23 21:53:23 +08:00
QSet < JKQTPCoordinateAxisRef > res ;
for ( auto it = secondaryXAxis . begin ( ) ; it ! = secondaryXAxis . end ( ) ; + + it ) {
res . insert ( it . key ( ) ) ;
}
2023-03-23 20:55:18 +08:00
if ( includePrimary ) res . insert ( JKQTPPrimaryAxis ) ;
return res ;
}
QSet < JKQTPCoordinateAxisRef > JKQTBasePlotter : : getAvailableYAxisRefs ( bool includePrimary ) const
{
2023-03-23 21:53:23 +08:00
QSet < JKQTPCoordinateAxisRef > res ;
for ( auto it = secondaryYAxis . begin ( ) ; it ! = secondaryYAxis . end ( ) ; + + it ) {
res . insert ( it . key ( ) ) ;
}
2023-03-23 20:55:18 +08:00
if ( includePrimary ) res . insert ( JKQTPPrimaryAxis ) ;
return res ;
}
QMap < JKQTPCoordinateAxisRef , JKQTPHorizontalAxisBase * > JKQTBasePlotter : : getXAxes ( bool includePrimary )
{
QMap < JKQTPCoordinateAxisRef , JKQTPHorizontalAxisBase * > res = secondaryXAxis ;
if ( includePrimary ) res [ JKQTPPrimaryAxis ] = xAxis ;
return res ;
}
QMap < JKQTPCoordinateAxisRef , JKQTPVerticalAxisBase * > JKQTBasePlotter : : getYAxes ( bool includePrimary )
{
QMap < JKQTPCoordinateAxisRef , JKQTPVerticalAxisBase * > res = secondaryYAxis ;
if ( includePrimary ) res [ JKQTPPrimaryAxis ] = yAxis ;
return res ;
}
QList < JKQTPCoordinateAxis * > JKQTBasePlotter : : getAxes ( bool includePrimaries )
{
QList < JKQTPCoordinateAxis * > res ;
if ( includePrimaries ) res < < xAxis < < yAxis ;
for ( auto & ax : secondaryXAxis ) res < < ax ;
for ( auto & ax : secondaryYAxis ) res < < ax ;
return res ;
}
JKQTPCoordinateAxisRef JKQTBasePlotter : : addSecondaryXAxis ( JKQTPHorizontalAxisBase * axis )
{
const auto keys = secondaryXAxis . keys ( ) ;
JKQTPCoordinateAxisRef ref = JKQTPSecondaryAxis ;
if ( keys . size ( ) > 0 ) {
ref = static_cast < JKQTPCoordinateAxisRef > ( static_cast < int > ( * std : : max_element ( keys . begin ( ) , keys . end ( ) ) ) + 1 ) ;
}
secondaryXAxis [ ref ] = axis ;
axis - > setParent ( this ) ;
return ref ;
}
JKQTPCoordinateAxisRef JKQTBasePlotter : : addSecondaryYAxis ( JKQTPVerticalAxisBase * axis )
{
const auto keys = secondaryYAxis . keys ( ) ;
JKQTPCoordinateAxisRef ref = JKQTPSecondaryAxis ;
if ( keys . size ( ) > 0 ) {
ref = static_cast < JKQTPCoordinateAxisRef > ( static_cast < int > ( * std : : max_element ( keys . begin ( ) , keys . end ( ) ) ) + 1 ) ;
}
secondaryYAxis [ ref ] = axis ;
axis - > setParent ( this ) ;
return ref ;
2019-02-08 00:24:46 +08:00
}
2019-06-21 21:46:53 +08:00
QAction * JKQTBasePlotter : : getActionSavePlot ( ) const {
return this - > actSavePlot ;
}
2019-02-08 00:24:46 +08:00
2019-06-21 21:46:53 +08:00
QAction * JKQTBasePlotter : : getActionSaveData ( ) const {
return this - > actSaveData ;
}
2019-02-08 00:24:46 +08:00
2019-06-21 21:46:53 +08:00
QAction * JKQTBasePlotter : : getActionCopyData ( ) const {
return this - > actCopyData ;
}
2019-02-08 00:24:46 +08:00
2019-06-21 21:46:53 +08:00
QAction * JKQTBasePlotter : : getActionCopyPixelImage ( ) const {
return this - > actCopyPixelImage ;
}
2019-02-08 00:24:46 +08:00
2019-06-21 21:46:53 +08:00
QAction * JKQTBasePlotter : : getActionCopyMatlab ( ) const {
return this - > actCopyMatlab ;
}
2019-02-08 00:24:46 +08:00
2022-07-19 05:33:20 +08:00
# ifndef JKQTPLOTTER_COMPILE_WITHOUT_PRINTSUPPORT
2019-06-21 21:46:53 +08:00
QAction * JKQTBasePlotter : : getActionSaveSVG ( ) const {
return this - > actSaveSVG ;
}
2019-02-08 00:24:46 +08:00
2019-06-21 21:46:53 +08:00
QAction * JKQTBasePlotter : : getActionPrint ( ) const {
return this - > actPrint ;
}
2019-02-08 00:24:46 +08:00
2022-07-19 05:33:20 +08:00
QAction * JKQTBasePlotter : : getActionSavePDF ( ) const {
return this - > actSavePDF ;
}
# endif
QAction * JKQTBasePlotter : : getActionSavePix ( ) const {
return this - > actSavePix ;
}
2019-06-21 21:46:53 +08:00
QAction * JKQTBasePlotter : : getActionSaveCSV ( ) const {
return this - > actSaveCSV ;
}
2019-02-08 00:24:46 +08:00
2019-06-21 21:46:53 +08:00
QAction * JKQTBasePlotter : : getActionZoomAll ( ) const {
return this - > actZoomAll ;
}
2019-02-08 00:24:46 +08:00
2019-06-21 21:46:53 +08:00
QAction * JKQTBasePlotter : : getActionZoomIn ( ) const {
return this - > actZoomIn ;
}
2019-02-08 00:24:46 +08:00
2019-06-21 21:46:53 +08:00
QAction * JKQTBasePlotter : : getActionZoomOut ( ) const {
return this - > actZoomOut ;
}
2019-02-08 00:24:46 +08:00
2019-06-21 21:46:53 +08:00
QAction * JKQTBasePlotter : : getActionShowPlotData ( ) const {
return this - > actShowPlotData ;
}
2019-02-08 00:24:46 +08:00
2019-06-21 21:46:53 +08:00
JKQTBasePlotter : : AdditionalActionsMap JKQTBasePlotter : : getLstAdditionalPlotterActions ( ) const {
return this - > lstAdditionalPlotterActions ;
}
2019-02-08 00:24:46 +08:00
QString JKQTBasePlotter : : getCSVdecimalSeparator ( ) const
{
return plotterStyle . CSVdecimalSeparator ;
}
2019-01-20 17:49:29 +08:00
void JKQTBasePlotter : : registerAdditionalAction ( const QString & key , QAction * act )
2015-07-11 18:56:02 +08:00
{
if ( ! lstAdditionalPlotterActions . contains ( key ) ) {
QList < QPointer < QAction > > l ;
lstAdditionalPlotterActions . insert ( key , l ) ;
}
lstAdditionalPlotterActions [ key ] . append ( act ) ;
AdditionalActionsMapIterator it ( lstAdditionalPlotterActions ) ;
while ( it . hasNext ( ) ) {
it . next ( ) ;
for ( int i = it . value ( ) . size ( ) - 1 ; i > = 0 ; i - - ) {
if ( ! it . value ( ) . at ( i ) ) {
lstAdditionalPlotterActions [ it . key ( ) ] . removeAt ( i ) ;
}
}
}
}
2019-01-20 17:49:29 +08:00
void JKQTBasePlotter : : deregisterAdditionalAction ( QAction * act )
2015-07-11 18:56:02 +08:00
{
AdditionalActionsMapIterator it ( lstAdditionalPlotterActions ) ;
while ( it . hasNext ( ) ) {
it . next ( ) ;
for ( int i = it . value ( ) . size ( ) - 1 ; i > = 0 ; i - - ) {
if ( it . value ( ) . at ( i ) = = act ) {
lstAdditionalPlotterActions [ it . key ( ) ] . removeAt ( i ) ;
}
}
}
}
2019-06-21 21:46:53 +08:00
bool JKQTBasePlotter : : getMasterSynchronizeWidth ( ) const {
return this - > masterSynchronizeWidth ;
}
2019-02-08 00:24:46 +08:00
2019-06-21 21:46:53 +08:00
bool JKQTBasePlotter : : getMasterSynchronizeHeight ( ) const {
return this - > masterSynchronizeHeight ;
}
2019-02-08 00:24:46 +08:00
void JKQTBasePlotter : : setFontSizePrintMultiplier ( double __value )
{
this - > fontSizePrintMultiplier = __value ;
}
double JKQTBasePlotter : : getFontSizePrintMultiplier ( ) const
{
return this - > fontSizePrintMultiplier ;
}
void JKQTBasePlotter : : setLineWidthPrintMultiplier ( double __value )
{
this - > lineWidthPrintMultiplier = __value ;
}
double JKQTBasePlotter : : getLineWidthPrintMultiplier ( ) const
{
return this - > lineWidthPrintMultiplier ;
}
2019-06-21 21:46:53 +08:00
double JKQTBasePlotter : : getFontSizeMultiplier ( ) const {
return this - > fontSizeMultiplier ;
}
2019-02-08 00:24:46 +08:00
2019-06-21 21:46:53 +08:00
double JKQTBasePlotter : : getLineWidthMultiplier ( ) const {
return this - > lineWidthMultiplier ;
}
2019-02-08 00:24:46 +08:00
2019-01-20 17:49:29 +08:00
void JKQTBasePlotter : : copyData ( ) {
2015-07-11 18:56:02 +08:00
loadUserSettings ( ) ;
QString result = " " ;
QString qfresult ;
QSet < int > cols = getDataColumnsByUser ( ) ;
{
QTextStream txt ( & result ) ;
QLocale loc = QLocale : : system ( ) ;
loc . setNumberOptions ( QLocale : : OmitGroupSeparator ) ;
2022-04-22 19:27:31 +08:00
const auto dp = loc . decimalPoint ( ) ;
const QString sep = " \t " ;
2015-07-11 18:56:02 +08:00
datastore - > saveCSV ( txt , cols , sep , QString ( dp ) , " " , " \" " ) ;
txt . flush ( ) ;
}
{
QTextStream txt ( & qfresult ) ;
datastore - > saveCSV ( txt , cols , " , " , " . " , " #! " , " \" " ) ;
txt . flush ( ) ;
}
QClipboard * clipboard = QApplication : : clipboard ( ) ;
QMimeData * mime = new QMimeData ( ) ;
mime - > setText ( result ) ;
mime - > setData ( " jkqtplotter/csv " , qfresult . toUtf8 ( ) ) ;
clipboard - > setMimeData ( mime ) ;
//clipboard->setText(result);
saveUserSettings ( ) ;
}
2019-01-20 17:49:29 +08:00
void JKQTBasePlotter : : copyDataMatlab ( ) {
2015-07-11 18:56:02 +08:00
loadUserSettings ( ) ;
QString result = " " ;
{
QTextStream txt ( & result ) ;
datastore - > saveMatlab ( txt , getDataColumnsByUser ( ) ) ;
txt . flush ( ) ;
}
QClipboard * clipboard = QApplication : : clipboard ( ) ;
clipboard - > setText ( result ) ;
saveUserSettings ( ) ;
}
2019-01-26 19:28:44 +08:00
void JKQTBasePlotter : : saveData ( const QString & filename , const QString & format ) {
2015-07-11 18:56:02 +08:00
loadUserSettings ( ) ;
QStringList fileformats ;
QStringList fileformatIDs ;
fileformats < < tr ( " Comma Separated Values (*.csv *.dat) " ) ;
fileformatIDs < < " csv " ;
fileformats < < tr ( " Tab Separated Values (*.txt) " ) ;
fileformatIDs < < " tab " ;
fileformats < < tr ( " Semicolon Separated Values [German Excel] (*.csv *.dat *.txt) " ) ;
fileformatIDs < < " gex " ;
fileformats < < tr ( " Semicolon Separated Values (*.csv *.dat *.txt) " ) ;
fileformatIDs < < " sem " ;
fileformats < < tr ( " SYLK spreadsheet (*.slk) " ) ;
fileformatIDs < < " slk " ;
fileformats < < tr ( " DIF: Data Interchange Format (*.dif) " ) ;
fileformatIDs < < " dif " ;
fileformats < < tr ( " Matlab Script (*.m) " ) ;
fileformatIDs < < " m " ;
for ( int i = 0 ; i < jkqtpSaveDataAdapters . size ( ) ; i + + ) {
fileformats < < jkqtpSaveDataAdapters [ i ] - > getFilter ( ) ;
fileformatIDs < < QString ( " custom%1 " ) . arg ( i ) ;
}
QString fn = filename ;
QString fmt = format . toLower ( ) ;
if ( fmt . isEmpty ( ) ) {
QString e = QFileInfo ( filename ) . suffix ( ) . toLower ( ) ; // jkqtp_tolower(extract_file_ext(fn.toStdString()));
if ( e = = " csv " | | e = = " dat " ) {
fmt = " csv " ;
} else if ( e = = " txt " ) {
fmt = " tab " ;
} else if ( ( e = = " slk " ) | | ( e = = " sylk " ) ) {
fmt = " slk " ;
} else if ( e = = " dif " ) {
fmt = " dif " ;
} else if ( e = = " m " ) {
fmt = " m " ;
}
}
if ( fn . isEmpty ( ) ) {
QString selectedFilter = currentDataFileFormat ;
//qDebug()<<"before: currentSaveDirectory="<<currentSaveDirectory;
2018-11-18 18:59:30 +08:00
fn = QFileDialog : : getSaveFileName ( nullptr , tr ( " Save Plot Data " ) ,
2015-07-11 18:56:02 +08:00
currentSaveDirectory ,
fileformats . join ( " ;; " ) ,
& selectedFilter ) ;
if ( ! fn . isEmpty ( ) ) {
currentSaveDirectory = QFileInfo ( fn ) . absolutePath ( ) ;
currentDataFileFormat = selectedFilter ;
}
//qDebug()<<"after: currentSaveDirectory="<<currentSaveDirectory;
fmt = " csv " ;
for ( int i = 0 ; i < fileformats . size ( ) ; i + + ) {
if ( selectedFilter . contains ( fileformats [ i ] ) ) {
fmt = fileformatIDs [ i ] ;
}
}
}
saveUserSettings ( ) ;
if ( ! fn . isEmpty ( ) ) {
if ( fmt = = " csv " ) {
saveAsCSV ( fn ) ;
} else if ( fmt = = " tab " ) {
saveAsTabSV ( fn ) ;
} else if ( fmt = = " gex " ) {
saveAsGerExcelCSV ( fn ) ;
} else if ( fmt = = " sem " ) {
saveAsSemicolonSV ( fn ) ;
} else if ( fmt = = " slk " ) {
saveAsSYLK ( fn ) ;
} else if ( fmt = = " dif " ) {
saveAsDIF ( fn ) ;
} else if ( fmt = = " m " ) {
saveAsMatlab ( fn ) ;
} else if ( fmt . startsWith ( " custom " ) ) {
QString fidx = fmt ;
fidx = fidx . remove ( 0 , 6 ) ;
int idx = fidx . toInt ( ) ;
if ( idx > = 0 & & idx < jkqtpSaveDataAdapters . size ( ) & & jkqtpSaveDataAdapters [ idx ] ) {
QStringList cn ;
QList < QVector < double > > dataset = datastore - > getData ( & cn ) ;
jkqtpSaveDataAdapters [ idx ] - > saveJKQTPData ( fn , dataset , cn ) ;
}
}
}
}
2019-01-26 19:28:44 +08:00
void JKQTBasePlotter : : saveAsCSV ( const QString & filename ) {
2019-02-08 00:24:46 +08:00
saveAsCSV ( filename , plotterStyle . CSVdecimalSeparator , plotterStyle . CSVcommentInitializer ) ;
}
void JKQTBasePlotter : : saveAsCSV ( const QString & filename , const QString & decimalSeparator , const QString & commentInitializer )
{
2015-07-11 18:56:02 +08:00
loadUserSettings ( ) ;
QString fn = filename ;
if ( fn . isEmpty ( ) ) {
2018-11-18 18:59:30 +08:00
fn = QFileDialog : : getSaveFileName ( nullptr , tr ( " Save Plot Data " ) ,
2015-07-11 18:56:02 +08:00
currentSaveDirectory ,
tr ( " Comma Separated Values (*.csv *.dat) " ) ) ;
if ( ! fn . isEmpty ( ) ) currentSaveDirectory = QFileInfo ( fn ) . absolutePath ( ) ;
}
if ( ! fn . isEmpty ( ) ) {
2019-02-08 00:24:46 +08:00
datastore - > saveCSV ( fn , getDataColumnsByUser ( ) , " , " , decimalSeparator , commentInitializer ) ;
2015-07-11 18:56:02 +08:00
}
saveUserSettings ( ) ;
2019-02-08 00:24:46 +08:00
}
void JKQTBasePlotter : : saveAsSemicolonSV ( const QString & filename ) {
saveAsSemicolonSV ( filename , plotterStyle . CSVdecimalSeparator , plotterStyle . CSVcommentInitializer ) ;
2015-07-11 18:56:02 +08:00
}
2019-02-08 00:24:46 +08:00
void JKQTBasePlotter : : saveAsSemicolonSV ( const QString & filename , const QString & decimalSeparator , const QString & commentInitializer ) {
2015-07-11 18:56:02 +08:00
loadUserSettings ( ) ;
QString fn = filename ;
if ( fn . isEmpty ( ) ) {
2018-11-18 18:59:30 +08:00
fn = QFileDialog : : getSaveFileName ( nullptr , tr ( " Save Plot Data " ) ,
2015-07-11 18:56:02 +08:00
currentSaveDirectory ,
2019-02-08 00:24:46 +08:00
tr ( " Comma Separated Values (*.csv *.dat) " ) ) ;
2015-07-11 18:56:02 +08:00
if ( ! fn . isEmpty ( ) ) currentSaveDirectory = QFileInfo ( fn ) . absolutePath ( ) ;
}
if ( ! fn . isEmpty ( ) ) {
2019-02-08 00:24:46 +08:00
datastore - > saveCSV ( fn , getDataColumnsByUser ( ) , " ; " , decimalSeparator , commentInitializer ) ;
2015-07-11 18:56:02 +08:00
}
saveUserSettings ( ) ;
}
2019-02-08 00:24:46 +08:00
void JKQTBasePlotter : : saveAsTabSV ( const QString & filename ) {
saveAsTabSV ( filename , plotterStyle . CSVdecimalSeparator , plotterStyle . CSVcommentInitializer ) ;
}
void JKQTBasePlotter : : saveAsTabSV ( const QString & filename , const QString & decimalSeparator , const QString & commentInitializer ) {
2015-07-11 18:56:02 +08:00
loadUserSettings ( ) ;
QString fn = filename ;
if ( fn . isEmpty ( ) ) {
2018-11-18 18:59:30 +08:00
fn = QFileDialog : : getSaveFileName ( nullptr , tr ( " Save Plot Data " ) ,
2015-07-11 18:56:02 +08:00
currentSaveDirectory ,
2019-02-08 00:24:46 +08:00
tr ( " Tabulator Separated Values (*.txt) " ) ) ;
2015-07-11 18:56:02 +08:00
if ( ! fn . isEmpty ( ) ) currentSaveDirectory = QFileInfo ( fn ) . absolutePath ( ) ;
}
if ( ! fn . isEmpty ( ) ) {
2019-02-08 00:24:46 +08:00
datastore - > saveCSV ( fn , getDataColumnsByUser ( ) , " \t " , decimalSeparator , commentInitializer ) ;
2015-07-11 18:56:02 +08:00
}
saveUserSettings ( ) ;
}
2019-02-08 00:24:46 +08:00
void JKQTBasePlotter : : saveAsSYLK ( const QString & filename ) {
2015-07-11 18:56:02 +08:00
loadUserSettings ( ) ;
QString fn = filename ;
if ( fn . isEmpty ( ) ) {
2018-11-18 18:59:30 +08:00
fn = QFileDialog : : getSaveFileName ( nullptr , tr ( " Save Plot Data " ) ,
2015-07-11 18:56:02 +08:00
currentSaveDirectory ,
2019-02-08 00:24:46 +08:00
tr ( " SYLK spreadsheet (*.slk) " ) ) ;
2015-07-11 18:56:02 +08:00
if ( ! fn . isEmpty ( ) ) currentSaveDirectory = QFileInfo ( fn ) . absolutePath ( ) ;
}
if ( ! fn . isEmpty ( ) ) {
2019-02-08 00:24:46 +08:00
datastore - > saveSYLK ( fn , getDataColumnsByUser ( ) ) ;
2015-07-11 18:56:02 +08:00
}
saveUserSettings ( ) ;
}
2019-02-08 00:24:46 +08:00
void JKQTBasePlotter : : saveAsMatlab ( const QString & filename ) {
2015-07-11 18:56:02 +08:00
loadUserSettings ( ) ;
QString fn = filename ;
if ( fn . isEmpty ( ) ) {
2018-11-18 18:59:30 +08:00
fn = QFileDialog : : getSaveFileName ( nullptr , tr ( " Save Plot Data " ) ,
2015-07-11 18:56:02 +08:00
currentSaveDirectory ,
2019-02-08 00:24:46 +08:00
tr ( " Matlab Script (*.m) " ) ) ;
2015-07-11 18:56:02 +08:00
if ( ! fn . isEmpty ( ) ) currentSaveDirectory = QFileInfo ( fn ) . absolutePath ( ) ;
}
if ( ! fn . isEmpty ( ) ) {
2019-02-08 00:24:46 +08:00
datastore - > saveMatlab ( fn , getDataColumnsByUser ( ) ) ;
2015-07-11 18:56:02 +08:00
}
saveUserSettings ( ) ;
}
2019-02-08 00:24:46 +08:00
void JKQTBasePlotter : : saveAsDIF ( const QString & filename ) {
2015-07-11 18:56:02 +08:00
loadUserSettings ( ) ;
QString fn = filename ;
if ( fn . isEmpty ( ) ) {
2018-11-18 18:59:30 +08:00
fn = QFileDialog : : getSaveFileName ( nullptr , tr ( " Save Plot Data " ) ,
2015-07-11 18:56:02 +08:00
currentSaveDirectory ,
2019-02-08 00:24:46 +08:00
tr ( " DIF: Data Interchange Format (*.dif) " ) ) ;
2015-07-11 18:56:02 +08:00
if ( ! fn . isEmpty ( ) ) currentSaveDirectory = QFileInfo ( fn ) . absolutePath ( ) ;
}
if ( ! fn . isEmpty ( ) ) {
2019-02-08 00:24:46 +08:00
datastore - > saveDIF ( fn , getDataColumnsByUser ( ) ) ;
2015-07-11 18:56:02 +08:00
}
saveUserSettings ( ) ;
}
2019-02-08 00:24:46 +08:00
2019-01-26 19:28:44 +08:00
void JKQTBasePlotter : : saveAsGerExcelCSV ( const QString & filename ) {
2015-07-11 18:56:02 +08:00
loadUserSettings ( ) ;
QString fn = filename ;
if ( fn . isEmpty ( ) ) {
2018-11-18 18:59:30 +08:00
fn = QFileDialog : : getSaveFileName ( nullptr , tr ( " Save Plot Data " ) ,
2015-07-11 18:56:02 +08:00
currentSaveDirectory ,
tr ( " Tabulator Separated Values (*.txt) " ) ) ;
if ( ! fn . isEmpty ( ) ) currentSaveDirectory = QFileInfo ( fn ) . absolutePath ( ) ;
}
if ( ! fn . isEmpty ( ) ) {
datastore - > saveCSV ( fn , getDataColumnsByUser ( ) , " ; " , " , " , " " , " \" " ) ;
}
saveUserSettings ( ) ;
}
2022-07-19 05:33:20 +08:00
# ifndef JKQTPLOTTER_COMPILE_WITHOUT_PRINTSUPPORT
2019-01-26 19:28:44 +08:00
void JKQTBasePlotter : : saveAsPDF ( const QString & filename , bool displayPreview ) {
2015-07-11 18:56:02 +08:00
loadUserSettings ( ) ;
QString fn = filename ;
if ( fn . isEmpty ( ) ) {
2018-11-18 18:59:30 +08:00
fn = QFileDialog : : getSaveFileName ( nullptr , tr ( " Save Plot " ) ,
2015-07-11 18:56:02 +08:00
currentSaveDirectory ,
tr ( " PDF File (*.pdf) " ) ) ;
if ( ! fn . isEmpty ( ) ) currentSaveDirectory = QFileInfo ( fn ) . absolutePath ( ) ;
}
if ( ! fn . isEmpty ( ) ) {
2022-09-12 06:34:36 +08:00
emit beforeExporting ( ) ; ; auto __finalpaint = JKQTPFinally ( [ & ] ( ) { emit afterExporting ( ) ; } ) ;
2015-07-11 18:56:02 +08:00
QPrinter * printer = new QPrinter ;
bool doLandscape = widgetWidth > widgetHeight ;
if ( gridPrinting ) {
gridPrintingCalc ( ) ;
doLandscape = gridPrintingSize . width ( ) > gridPrintingSize . height ( ) ;
}
if ( doLandscape ) {
2022-04-19 04:45:02 +08:00
printer - > setPageOrientation ( QPageLayout : : Landscape ) ;
2015-07-11 18:56:02 +08:00
} else {
2022-04-19 04:45:02 +08:00
printer - > setPageOrientation ( QPageLayout : : Portrait ) ;
2015-07-11 18:56:02 +08:00
}
printer - > setOutputFormat ( QPrinter : : PdfFormat ) ;
printer - > setColorMode ( QPrinter : : Color ) ;
printer - > setOutputFileName ( fn ) ;
2022-04-19 04:45:02 +08:00
printer - > setPageMargins ( QMarginsF ( 0 , 0 , 0 , 0 ) , QPageLayout : : Millimeter ) ;
2015-07-11 18:56:02 +08:00
printer - > setColorMode ( QPrinter : : Color ) ;
printpreviewNew ( printer , true , - 1.0 , - 1.0 , displayPreview ) ;
delete printer ;
}
saveUserSettings ( ) ;
}
2022-07-19 05:33:20 +08:00
# endif
2015-07-11 18:56:02 +08:00
2019-01-26 19:28:44 +08:00
void JKQTBasePlotter : : saveImage ( const QString & filename , bool displayPreview ) {
2015-07-11 18:56:02 +08:00
loadUserSettings ( ) ;
QString fn = filename ;
QStringList filt ;
2022-07-19 05:33:20 +08:00
# ifndef JKQTPLOTTER_COMPILE_WITHOUT_PRINTSUPPORT
2015-07-11 18:56:02 +08:00
filt < < tr ( " Portable Document Format PDF [Qt] (*.pdf) " ) ;
filt < < tr ( " Scalable Vector Graphics [Qt] (*.svg) " ) ;
2022-07-19 05:33:20 +08:00
# endif
2015-07-11 18:56:02 +08:00
filt < < tr ( " PNG Image [Qt] (*.png) " ) ;
filt < < tr ( " BMP Image [Qt] (*.bmp) " ) ;
filt < < tr ( " TIFF Image [Qt] (*.tif *.tiff) " ) ;
filt < < tr ( " JPEG Image [Qt] (*.jpg *.jpeg) " ) ;
const int filtStartSize = filt . size ( ) ;
for ( int i = 0 ; i < jkqtpPaintDeviceAdapters . size ( ) ; i + + ) {
filt < < jkqtpPaintDeviceAdapters [ i ] - > getFilter ( ) ;
}
int qtwritersidx = filt . size ( ) ;
QList < QByteArray > writerformats = QImageWriter : : supportedImageFormats ( ) ;
for ( int i = 0 ; i < writerformats . size ( ) ; i + + ) {
filt < < QString ( " %1 Image (*.%2) " ) . arg ( QString ( writerformats [ i ] ) . toUpper ( ) ) . arg ( QString ( writerformats [ i ] . toLower ( ) ) ) ;
}
QString selFormat = " " ;
if ( fn . isEmpty ( ) ) {
selFormat = currentFileFormat ;
2018-11-18 18:59:30 +08:00
fn = QFileDialog : : getSaveFileName ( nullptr , tr ( " Save Plot " ) ,
2015-07-11 18:56:02 +08:00
currentSaveDirectory ,
filt . join ( " ;; " ) , & selFormat ) ;
if ( ! fn . isEmpty ( ) ) {
currentSaveDirectory = QFileInfo ( fn ) . absolutePath ( ) ;
currentFileFormat = selFormat ;
}
}
//qDebug()<<"fn="<<fn<<" selFormat="<<selFormat;
saveUserSettings ( ) ;
if ( ! fn . isEmpty ( ) ) {
int filtID = filt . indexOf ( selFormat ) ;
bool isWithSpecialDeviceAdapter = filtID > = filtStartSize & & filtID < filtStartSize + jkqtpPaintDeviceAdapters . size ( ) ;
int adapterID = filtID - filtStartSize ;
QString e = QFileInfo ( filename ) . suffix ( ) . toLower ( ) ;
if ( ! isWithSpecialDeviceAdapter ) {
for ( int i = 0 ; i < jkqtpPaintDeviceAdapters . size ( ) ; i + + ) {
if ( jkqtpPaintDeviceAdapters [ i ] - > getFileExtension ( ) . contains ( e ) ) {
adapterID = i ;
isWithSpecialDeviceAdapter = true ;
break ;
}
}
}
//qDebug()<<"filtID="<<filtID<<" isWithSpecialDeviceAdapter="<<isWithSpecialDeviceAdapter<<" adapterID="<<adapterID;
2022-07-19 05:33:20 +08:00
# ifndef JKQTPLOTTER_COMPILE_WITHOUT_PRINTSUPPORT
2020-09-09 02:15:33 +08:00
if ( filtID = = 0 ) {
2015-07-11 18:56:02 +08:00
saveAsPDF ( fn , displayPreview ) ;
2022-07-19 05:33:20 +08:00
return ;
}
if ( filtID = = 1 ) {
2015-07-11 18:56:02 +08:00
saveAsSVG ( fn , displayPreview ) ;
2022-07-19 05:33:20 +08:00
return ;
}
# endif
if ( isWithSpecialDeviceAdapter & & adapterID > = 0 & & adapterID < jkqtpPaintDeviceAdapters . size ( ) ) {
2015-07-11 18:56:02 +08:00
QString tempFM = " " ;
if ( QFile : : exists ( fn ) ) {
2015-08-04 23:38:29 +08:00
# ifdef QFWIDLIB_LIBRARY
QFTemporaryFile * tf = new QFTemporaryFile ( ) ;
# else
2015-07-11 18:56:02 +08:00
QTemporaryFile * tf = new QTemporaryFile ( ) ;
2015-08-04 23:38:29 +08:00
# endif
2015-07-11 18:56:02 +08:00
tf - > open ( ) ;
tempFM = tf - > fileName ( ) ;
tf - > close ( ) ;
delete tf ;
QFile : : copy ( fn , tempFM ) ;
}
2022-09-12 06:34:36 +08:00
emit beforeExporting ( ) ; ; auto __finalpaint = JKQTPFinally ( [ & ] ( ) { emit afterExporting ( ) ; } ) ;
2015-07-11 18:56:02 +08:00
gridPrintingCalc ( ) ;
2022-07-19 05:33:20 +08:00
QPaintDevice * paintDevice = jkqtpPaintDeviceAdapters [ adapterID ] - > createPaintdevice ( fn , jkqtp_roundTo < int > ( gridPrintingSize . width ( ) ) , jkqtp_roundTo < int > ( gridPrintingSize . height ( ) ) ) ;
2015-07-11 18:56:02 +08:00
2022-07-19 05:33:20 +08:00
# ifndef JKQTPLOTTER_COMPILE_WITHOUT_PRINTSUPPORT
if ( ! printpreviewNew ( paintDevice , jkqtpPaintDeviceAdapters [ adapterID ] - > getSetAbsolutePaperSize ( ) , jkqtpPaintDeviceAdapters [ adapterID ] - > getPrintSizeXInMM ( ) , jkqtpPaintDeviceAdapters [ adapterID ] - > getPrintSizeYInMM ( ) , displayPreview ) ) {
delete paintDevice ;
2015-07-11 18:56:02 +08:00
if ( QFile : : exists ( tempFM ) ) {
QFile : : copy ( tempFM , fn ) ;
QFile : : remove ( tempFM ) ;
}
} else {
2022-07-19 05:33:20 +08:00
# else
{
# endif
delete paintDevice ;
paintDevice = jkqtpPaintDeviceAdapters [ adapterID ] - > createPaintdeviceMM ( fn , printSizeX_Millimeter , printSizeY_Millimeter ) ;
printpreviewPaintRequestedNewPaintDevice ( paintDevice ) ;
delete paintDevice ;
2015-07-11 18:56:02 +08:00
}
} else {
saveAsPixelImage ( fn , displayPreview , writerformats . value ( filtID - qtwritersidx , QByteArray ( ) ) ) ;
}
}
}
2019-01-26 19:28:44 +08:00
void JKQTBasePlotter : : saveAsPixelImage ( const QString & filename , bool displayPreview , const QByteArray & outputFormat ) {
2015-07-11 18:56:02 +08:00
loadUserSettings ( ) ;
QString fn = filename ;
QStringList filt ;
QList < QByteArray > writerformats = QImageWriter : : supportedImageFormats ( ) ;
for ( int i = 0 ; i < writerformats . size ( ) ; i + + ) {
filt < < QString ( " %1 Image (*.%2) " ) . arg ( QString ( writerformats [ i ] ) . toUpper ( ) ) . arg ( QString ( writerformats [ i ] . toLower ( ) ) ) ;
}
QString selFormat ;
if ( fn . isEmpty ( ) ) {
selFormat = currentFileFormat ;
2018-11-18 18:59:30 +08:00
fn = QFileDialog : : getSaveFileName ( nullptr , tr ( " Save Plot " ) ,
2015-07-11 18:56:02 +08:00
currentSaveDirectory ,
filt . join ( " ;; " ) , & selFormat ) ;
if ( ! fn . isEmpty ( ) ) currentSaveDirectory = QFileInfo ( fn ) . absolutePath ( ) ;
}
saveUserSettings ( ) ;
if ( ! fn . isEmpty ( ) ) {
int filtID = filt . indexOf ( selFormat ) ;
//QString ext=tolower(extract_file_ext(fn.toStdString()));
QString form = " NONE " ;
if ( filtID > = 0 & & filtID < writerformats . size ( ) ) {
form = writerformats [ filtID ] ;
}
if ( outputFormat . size ( ) > 0 ) {
form = outputFormat ;
}
/*if (filtID==2 || ext=="tif" || ext=="tiff") { // currentFileFormat
form = " TIFF " ;
} else if ( filtID = = 0 | | ext = = " png " ) {
form = " PNG " ;
} else if ( filtID = = 1 | | ext = = " bmp " ) {
form = " BMP " ;
} else if ( filtID = = 3 | | ext = = " jpg " | | ext = = " jpeg " ) {
form = " JPEG " ;
} else if ( ext = = " ppm " ) {
form = " PPM " ;
} else if ( filtID = = 4 | | ext = = " xbm " ) {
form = " XBM " ;
} else if ( filtID = = 5 | | ext = = " xpm " ) {
form = " XPM " ;
} */
2022-09-12 06:34:36 +08:00
emit beforeExporting ( ) ; ; auto __finalpaint = JKQTPFinally ( [ & ] ( ) { emit afterExporting ( ) ; } ) ;
2015-07-11 18:56:02 +08:00
gridPrintingCalc ( ) ;
//std::cout<<gridPrintingSize.width()<<", "<<gridPrintingSize.height()<<std::endl;
if ( ! displayPreview ) {
printSizeX_Millimeter = widgetWidth ;
printSizeY_Millimeter = widgetHeight ;
}
if ( ! displayPreview | | exportpreview ( gridPrintingSize , false ) ) {
2019-06-21 21:46:53 +08:00
QImage png ( QSizeF ( double ( printSizeX_Millimeter ) * 1.1 , double ( printSizeY_Millimeter ) * 1.1 ) . toSize ( ) , QImage : : Format_ARGB32 ) ;
2015-07-11 18:56:02 +08:00
png . fill ( Qt : : transparent ) ;
JKQTPEnhancedPainter painter ;
painter . begin ( & png ) ;
painter . setRenderHint ( JKQTPEnhancedPainter : : Antialiasing ) ;
painter . setRenderHint ( JKQTPEnhancedPainter : : TextAntialiasing ) ;
painter . setRenderHint ( JKQTPEnhancedPainter : : SmoothPixmapTransform ) ;
2022-04-21 16:57:24 +08:00
# if (QT_VERSION<QT_VERSION_CHECK(6, 0, 0))
painter . setRenderHint ( JKQTPEnhancedPainter : : NonCosmeticDefaultPen , true ) ;
2015-07-11 18:56:02 +08:00
painter . setRenderHint ( JKQTPEnhancedPainter : : HighQualityAntialiasing ) ;
2022-04-21 16:57:24 +08:00
# endif
2015-07-11 18:56:02 +08:00
/*calcPlotScaling(painter);
gridPaint ( painter , png . rect ( ) . size ( ) ) ; */ \
//qDebug()<<QSize(printSizeX_Millimeter, printSizeY_Millimeter);
2019-06-21 21:46:53 +08:00
exportpreviewPaintRequested ( painter , QSize ( jkqtp_roundTo < int > ( printSizeX_Millimeter ) , jkqtp_roundTo < int > ( printSizeY_Millimeter ) ) ) ;
2015-07-11 18:56:02 +08:00
painter . end ( ) ;
if ( form = = " NONE " ) png . save ( fn ) ;
else png . save ( fn , form . toLatin1 ( ) . data ( ) ) ;
}
2022-09-12 06:34:36 +08:00
2015-07-11 18:56:02 +08:00
}
}
2022-08-26 18:28:06 +08:00
QImage JKQTBasePlotter : : grabPixelImage ( QSize size , bool showPreview )
{
gridPrintingCalc ( ) ;
//std::cout<<gridPrintingSize.width()<<", "<<gridPrintingSize.height()<<std::endl;
printSizeX_Millimeter = gridPrintingSize . width ( ) ;
printSizeY_Millimeter = gridPrintingSize . height ( ) ;
if ( ! showPreview ) {
printSizeX_Millimeter = widgetWidth ;
printSizeY_Millimeter = widgetHeight ;
}
2022-09-12 06:34:36 +08:00
emit beforeExporting ( ) ; ; auto __finalpaint = JKQTPFinally ( [ & ] ( ) { emit afterExporting ( ) ; } ) ;
2022-08-26 18:28:06 +08:00
if ( ! showPreview | | exportpreview ( gridPrintingSize , false ) ) {
2015-07-11 18:56:02 +08:00
2022-08-26 18:28:06 +08:00
QApplication : : setOverrideCursor ( QCursor ( Qt : : WaitCursor ) ) ;
if ( size . isEmpty ( ) | | size . isNull ( ) | | ! size . isValid ( ) | | size . width ( ) * size . height ( ) = = 0 ) size = QSizeF ( double ( printSizeX_Millimeter ) , double ( printSizeY_Millimeter ) ) . toSize ( ) ;
QImage png ( size , QImage : : Format_ARGB32 ) ;
{
png . fill ( Qt : : transparent ) ;
JKQTPEnhancedPainter painter ;
painter . begin ( & png ) ;
painter . setRenderHint ( JKQTPEnhancedPainter : : Antialiasing ) ;
painter . setRenderHint ( JKQTPEnhancedPainter : : TextAntialiasing ) ;
painter . setRenderHint ( JKQTPEnhancedPainter : : SmoothPixmapTransform ) ;
# if (QT_VERSION<QT_VERSION_CHECK(6, 0, 0))
painter . setRenderHint ( JKQTPEnhancedPainter : : NonCosmeticDefaultPen , true ) ;
painter . setRenderHint ( JKQTPEnhancedPainter : : HighQualityAntialiasing ) ;
# endif
/*calcPlotScaling(painter);
gridPaint ( painter , png . rect ( ) . size ( ) ) ; */
exportpreviewPaintRequested ( painter , QSizeF ( printSizeX_Millimeter , printSizeY_Millimeter ) . toSize ( ) ) ;
painter . end ( ) ;
}
QApplication : : restoreOverrideCursor ( ) ;
return png ;
2015-07-11 18:56:02 +08:00
}
2022-08-26 18:28:06 +08:00
return QImage ( ) ;
2015-07-11 18:56:02 +08:00
2022-08-26 18:28:06 +08:00
}
2015-07-11 18:56:02 +08:00
2022-08-26 18:28:06 +08:00
void JKQTBasePlotter : : copyPixelImage ( bool showPreview ) {
2015-07-11 18:56:02 +08:00
gridPrintingCalc ( ) ;
//std::cout<<gridPrintingSize.width()<<", "<<gridPrintingSize.height()<<std::endl;
printSizeX_Millimeter = gridPrintingSize . width ( ) ;
printSizeY_Millimeter = gridPrintingSize . height ( ) ;
2022-09-12 06:34:36 +08:00
emit beforeExporting ( ) ; ; auto __finalpaint = JKQTPFinally ( [ & ] ( ) { emit afterExporting ( ) ; } ) ;
2022-08-26 18:28:06 +08:00
if ( ! showPreview | | exportpreview ( gridPrintingSize , false ) ) {
2015-07-11 18:56:02 +08:00
QApplication : : setOverrideCursor ( QCursor ( Qt : : WaitCursor ) ) ;
QByteArray svgdata ;
{
QBuffer buffer ( & svgdata ) ;
QSvgGenerator * svg = new QSvgGenerator ;
svg - > setResolution ( 96 ) ;
//svg->setResolution(300);
2019-06-21 21:46:53 +08:00
QSize size = QSizeF ( printSizeX_Millimeter , printSizeX_Millimeter ) . toSize ( ) ;
2015-07-11 18:56:02 +08:00
double factor = double ( size . width ( ) ) / double ( widgetWidth ) * paintMagnification ;
// TODO: CORRECT THIS
//qDebug()<<size;
svg - > setSize ( size ) ;
svg - > setOutputDevice ( & buffer ) ;
JKQTPEnhancedPainter painter ;
2022-08-31 04:24:24 +08:00
painter . setPainterFlag ( JKQTPEnhancedPainter : : VectorPainting ) ;
2015-07-11 18:56:02 +08:00
painter . begin ( svg ) ;
painter . scale ( factor , factor ) ;
printAspect = printSizeY_Millimeter / printSizeX_Millimeter ;
2019-06-21 21:46:53 +08:00
exportpreviewPaintRequested ( painter , QSizeF ( widgetWidth / paintMagnification , widgetWidth / paintMagnification * printAspect ) . toSize ( ) ) ;
2015-07-11 18:56:02 +08:00
painter . end ( ) ;
delete svg ;
}
2022-08-26 18:28:06 +08:00
if ( ! showPreview ) {
printSizeX_Millimeter = widgetWidth ;
printSizeY_Millimeter = widgetHeight ;
}
QImage png ( QSizeF ( double ( printSizeX_Millimeter ) , double ( printSizeY_Millimeter ) ) . toSize ( ) , QImage : : Format_ARGB32 ) ;
{
png . fill ( Qt : : transparent ) ;
JKQTPEnhancedPainter painter ;
painter . begin ( & png ) ;
painter . setRenderHint ( JKQTPEnhancedPainter : : Antialiasing ) ;
painter . setRenderHint ( JKQTPEnhancedPainter : : TextAntialiasing ) ;
painter . setRenderHint ( JKQTPEnhancedPainter : : SmoothPixmapTransform ) ;
# if (QT_VERSION<QT_VERSION_CHECK(6, 0, 0))
painter . setRenderHint ( JKQTPEnhancedPainter : : NonCosmeticDefaultPen , true ) ;
painter . setRenderHint ( JKQTPEnhancedPainter : : HighQualityAntialiasing ) ;
# endif
2015-07-11 18:56:02 +08:00
2022-08-26 18:28:06 +08:00
/*calcPlotScaling(painter);
gridPaint ( painter , png . rect ( ) . size ( ) ) ; */
exportpreviewPaintRequested ( painter , QSizeF ( printSizeX_Millimeter , printSizeY_Millimeter ) . toSize ( ) ) ;
painter . end ( ) ;
}
2015-07-11 18:56:02 +08:00
2022-08-26 18:28:06 +08:00
QClipboard * clipboard = QApplication : : clipboard ( ) ;
//qDebug()<<"clipboard before adding content:\n"<<clipboard->mimeData()->formats();
//clipboard->setImage(png);
clipboard - > clear ( ) ;
clipboard - > setPixmap ( QPixmap : : fromImage ( png ) ) ;
QMimeData * mime = new QMimeData ( ) ;
mime - > setImageData ( QPixmap : : fromImage ( png ) ) ;
QBuffer pngbuf ;
png . save ( & pngbuf , " png " ) ;
mime - > setData ( " image/x-png " , pngbuf . data ( ) ) ;
png . save ( & pngbuf , " bmp " ) ;
mime - > setData ( " image/bmp " , pngbuf . data ( ) ) ;
mime - > setData ( " image/svg+xml " , svgdata ) ;
clipboard - > setMimeData ( mime ) ;
//qDebug()<<"clipboard after adding content:\n"<<clipboard->mimeData()->formats();
2015-07-11 18:56:02 +08:00
2022-08-26 18:28:06 +08:00
QApplication : : restoreOverrideCursor ( ) ;
2015-07-11 18:56:02 +08:00
}
}
2022-07-19 05:33:20 +08:00
# ifndef JKQTPLOTTER_COMPILE_WITHOUT_PRINTSUPPORT
2019-01-26 19:28:44 +08:00
void JKQTBasePlotter : : saveAsSVG ( const QString & filename , bool displayPreview ) {
2015-07-11 18:56:02 +08:00
loadUserSettings ( ) ;
QString fn = filename ;
if ( fn . isEmpty ( ) ) {
2018-11-18 18:59:30 +08:00
fn = QFileDialog : : getSaveFileName ( nullptr , tr ( " Save Plot " ) ,
2015-07-11 18:56:02 +08:00
currentSaveDirectory ,
tr ( " SVG Image (*.svg) " ) ) ;
if ( ! fn . isEmpty ( ) ) currentSaveDirectory = QFileInfo ( fn ) . absolutePath ( ) ;
}
if ( ! fn . isEmpty ( ) ) {
QString tempFM = " " ;
if ( QFile : : exists ( fn ) ) {
2015-08-04 23:38:29 +08:00
# ifdef QFWIDLIB_LIBRARY
QFTemporaryFile * tf = new QFTemporaryFile ( ) ;
# else
QTemporaryFile * tf = new QTemporaryFile ( ) ;
# endif
2015-07-11 18:56:02 +08:00
tf - > open ( ) ;
tempFM = tf - > fileName ( ) ;
tf - > close ( ) ;
delete tf ;
QFile : : copy ( fn , tempFM ) ;
}
2022-09-12 06:34:36 +08:00
emit beforeExporting ( ) ; ; auto __finalpaint = JKQTPFinally ( [ & ] ( ) { emit afterExporting ( ) ; } ) ;
2015-07-11 18:56:02 +08:00
gridPrintingCalc ( ) ;
QSvgGenerator * svg = new QSvgGenerator ;
svg - > setResolution ( 96 ) ;
2019-06-21 21:46:53 +08:00
QSize size = QSizeF ( gridPrintingSize . width ( ) * 25.4 / svg - > resolution ( ) , gridPrintingSize . height ( ) * 25.4 / svg - > resolution ( ) ) . toSize ( ) ;
2015-07-11 18:56:02 +08:00
svg - > setSize ( size ) ;
svg - > setFileName ( fn ) ;
if ( ! printpreviewNew ( svg , true , - 1.0 , - 1.0 , displayPreview ) ) {
if ( QFile : : exists ( tempFM ) ) {
QFile : : copy ( tempFM , fn ) ;
QFile : : remove ( tempFM ) ;
}
}
delete svg ;
}
saveUserSettings ( ) ;
}
2022-07-19 05:33:20 +08:00
# endif
2015-07-11 18:56:02 +08:00
2019-02-08 00:24:46 +08:00
void JKQTBasePlotter : : setPlotBorder ( int left , int right , int top , int bottom ) {
plotterStyle . plotBorderTop = top ;
plotterStyle . plotBorderLeft = left ;
plotterStyle . plotBorderBottom = bottom ;
plotterStyle . plotBorderRight = right ;
2015-07-11 18:56:02 +08:00
//updateGeometry();
2023-05-28 05:46:45 +08:00
redrawPlot ( ) ;
2015-07-11 18:56:02 +08:00
}
2019-02-08 00:24:46 +08:00
void JKQTBasePlotter : : setPlotBorderLeft ( int left )
{
plotterStyle . plotBorderLeft = left ;
2023-05-28 05:46:45 +08:00
redrawPlot ( ) ;
2019-02-08 00:24:46 +08:00
}
void JKQTBasePlotter : : setPlotBorderRight ( int right )
{
plotterStyle . plotBorderRight = right ;
2023-05-28 05:46:45 +08:00
redrawPlot ( ) ;
2019-02-08 00:24:46 +08:00
}
void JKQTBasePlotter : : setPlotBorderTop ( int top )
{
plotterStyle . plotBorderTop = top ;
2023-05-28 05:46:45 +08:00
redrawPlot ( ) ;
2019-02-08 00:24:46 +08:00
}
void JKQTBasePlotter : : setPlotBorderBottom ( int bottom )
{
plotterStyle . plotBorderBottom = bottom ;
2023-05-28 05:46:45 +08:00
redrawPlot ( ) ;
2019-02-08 00:24:46 +08:00
}
2019-02-03 21:04:48 +08:00
void JKQTBasePlotter : : synchronizeToMaster ( JKQTBasePlotter * master , SynchronizationDirection synchronizeDirection , bool synchronizeAxisLength , bool synchronizeZoomingMasterToSlave , bool synchronizeZoomingSlaveToMaster ) {
// remove old connections
if ( masterPlotterX & & ( synchronizeDirection = = sdXAxis | | synchronizeDirection = = sdXYAxes ) ) {
disconnect ( masterPlotterX , SIGNAL ( zoomChangedLocally ( double , double , double , double , JKQTBasePlotter * ) ) ,
this , SLOT ( synchronizeXAxis ( double , double , double , double , JKQTBasePlotter * ) ) ) ;
2019-01-20 17:49:29 +08:00
disconnect ( this , SIGNAL ( zoomChangedLocally ( double , double , double , double , JKQTBasePlotter * ) ) ,
2019-02-03 21:04:48 +08:00
masterPlotterX , SLOT ( synchronizeXAxis ( double , double , double , double , JKQTBasePlotter * ) ) ) ;
2018-12-14 05:29:30 +08:00
}
2019-02-03 21:04:48 +08:00
if ( masterPlotterY & & ( synchronizeDirection = = sdYAxis | | synchronizeDirection = = sdXYAxes ) ) {
disconnect ( masterPlotterY , SIGNAL ( zoomChangedLocally ( double , double , double , double , JKQTBasePlotter * ) ) ,
this , SLOT ( synchronizeYAxis ( double , double , double , double , JKQTBasePlotter * ) ) ) ;
2019-01-20 17:49:29 +08:00
disconnect ( this , SIGNAL ( zoomChangedLocally ( double , double , double , double , JKQTBasePlotter * ) ) ,
2019-02-03 21:04:48 +08:00
masterPlotterY , SLOT ( synchronizeYAxis ( double , double , double , double , JKQTBasePlotter * ) ) ) ;
2018-12-14 05:29:30 +08:00
}
2019-02-03 21:04:48 +08:00
// store new connection settings
if ( synchronizeDirection = = sdXAxis | | synchronizeDirection = = sdXYAxes ) {
masterPlotterX = master ;
masterSynchronizeWidth = synchronizeAxisLength ;
}
if ( synchronizeDirection = = sdYAxis | | synchronizeDirection = = sdXYAxes ) {
masterPlotterY = master ;
masterSynchronizeHeight = synchronizeAxisLength ;
2018-12-14 05:29:30 +08:00
}
2019-02-03 21:04:48 +08:00
// connect widgets (if required)
if ( master ) {
if ( synchronizeDirection = = sdXAxis | | synchronizeDirection = = sdXYAxes ) {
if ( synchronizeZoomingMasterToSlave ) {
connect ( masterPlotterX , SIGNAL ( zoomChangedLocally ( double , double , double , double , JKQTBasePlotter * ) ) ,
this , SLOT ( synchronizeXAxis ( double , double , double , double , JKQTBasePlotter * ) ) ) ;
}
if ( synchronizeZoomingSlaveToMaster ) {
connect ( this , SIGNAL ( zoomChangedLocally ( double , double , double , double , JKQTBasePlotter * ) ) ,
masterPlotterX , SLOT ( synchronizeXAxis ( double , double , double , double , JKQTBasePlotter * ) ) ) ;
}
2018-12-14 05:29:30 +08:00
}
2019-02-03 21:04:48 +08:00
if ( synchronizeDirection = = sdYAxis | | synchronizeDirection = = sdXYAxes ) {
if ( synchronizeZoomingMasterToSlave ) {
connect ( masterPlotterY , SIGNAL ( zoomChangedLocally ( double , double , double , double , JKQTBasePlotter * ) ) ,
this , SLOT ( synchronizeYAxis ( double , double , double , double , JKQTBasePlotter * ) ) ) ;
}
if ( synchronizeZoomingSlaveToMaster ) {
connect ( this , SIGNAL ( zoomChangedLocally ( double , double , double , double , JKQTBasePlotter * ) ) ,
masterPlotterY , SLOT ( synchronizeYAxis ( double , double , double , double , JKQTBasePlotter * ) ) ) ;
2018-12-14 05:29:30 +08:00
2019-02-03 21:04:48 +08:00
}
2018-12-14 05:29:30 +08:00
}
}
2019-02-03 21:04:48 +08:00
2015-07-11 18:56:02 +08:00
}
2019-02-03 21:04:48 +08:00
void JKQTBasePlotter : : synchronizeXToMaster ( JKQTBasePlotter * master , bool synchronizeAxisLength , bool synchronizeZoomingMasterToSlave , bool synchronizeZoomingSlaveToMaster )
{
synchronizeToMaster ( master , sdXAxis , synchronizeAxisLength , synchronizeZoomingMasterToSlave , synchronizeZoomingSlaveToMaster ) ;
}
2018-12-14 05:29:30 +08:00
2019-02-03 21:04:48 +08:00
void JKQTBasePlotter : : synchronizeYToMaster ( JKQTBasePlotter * master , bool synchronizeAxisLength , bool synchronizeZoomingMasterToSlave , bool synchronizeZoomingSlaveToMaster )
{
synchronizeToMaster ( master , sdYAxis , synchronizeAxisLength , synchronizeZoomingMasterToSlave , synchronizeZoomingSlaveToMaster ) ;
}
void JKQTBasePlotter : : resetMasterSynchronization ( JKQTBasePlotter : : SynchronizationDirection synchronizeDirection ) {
synchronizeToMaster ( nullptr , synchronizeDirection , false , false , false ) ;
2018-12-14 05:29:30 +08:00
}
2019-01-20 17:49:29 +08:00
void JKQTBasePlotter : : synchronizeXAxis ( double newxmin , double newxmax , double /*newymin*/ , double /*newymax*/ , JKQTBasePlotter * /*sender*/ ) {
2019-02-03 21:04:48 +08:00
bool oldemitSignals = emitSignals ;
emitSignals = false ;
2018-12-14 05:29:30 +08:00
setX ( newxmin , newxmax ) ;
2019-02-03 21:04:48 +08:00
emitSignals = oldemitSignals ;
2015-07-11 18:56:02 +08:00
}
2019-01-20 17:49:29 +08:00
void JKQTBasePlotter : : synchronizeYAxis ( double /*newxmin*/ , double /*newxmax*/ , double newymin , double newymax , JKQTBasePlotter * /*sender*/ ) {
2019-02-03 21:04:48 +08:00
bool oldemitSignals = emitSignals ;
emitSignals = false ;
2018-12-14 05:29:30 +08:00
setY ( newymin , newymax ) ;
2019-02-03 21:04:48 +08:00
emitSignals = oldemitSignals ;
2018-12-14 05:29:30 +08:00
}
2015-07-11 18:56:02 +08:00
2019-01-20 17:49:29 +08:00
void JKQTBasePlotter : : synchronizeXYAxis ( double newxmin , double newxmax , double newymin , double newymax , JKQTBasePlotter * /*sender*/ ) {
2019-02-03 21:04:48 +08:00
bool oldemitSignals = emitSignals ;
emitSignals = false ;
2018-12-14 05:29:30 +08:00
setXY ( newxmin , newxmax , newymin , newymax ) ;
2019-02-03 21:04:48 +08:00
emitSignals = oldemitSignals ;
2018-12-14 05:29:30 +08:00
}
2015-07-11 18:56:02 +08:00
2019-02-08 00:24:46 +08:00
void JKQTBasePlotter : : drawGraphs ( JKQTPEnhancedPainter & painter ) {
2015-07-11 18:56:02 +08:00
# ifdef JKQTBP_AUTOTIMER
2019-01-20 17:49:29 +08:00
JKQTPAutoOutputTimer jkaaot ( QString ( " JKQTBasePlotter::plotGraphs " ) ) ;
2015-07-11 18:56:02 +08:00
# endif
2018-11-18 18:59:30 +08:00
if ( datastore = = nullptr | | graphs . isEmpty ( ) ) return ;
2019-01-26 03:16:04 +08:00
//qDebug()<<"start JKQTBasePlotter::plotGraphs()";
2015-07-11 18:56:02 +08:00
if ( useClipping ) {
2019-06-21 21:46:53 +08:00
QRegion cregion ( jkqtp_roundTo < int > ( internalPlotBorderLeft ) , jkqtp_roundTo < int > ( internalPlotBorderTop ) , jkqtp_roundTo < int > ( internalPlotWidth ) , jkqtp_roundTo < int > ( internalPlotHeight ) ) ;
2015-07-11 18:56:02 +08:00
painter . setClipping ( true ) ;
painter . setClipRegion ( cregion ) ;
}
2019-06-21 21:46:53 +08:00
int ibTop = jkqtp_roundTo < int > ( internalPlotBorderTop_notIncludingOutsidePlotSections - plotterStyle . plotBorderTop - internalTitleHeight ) ;
int ibLeft = jkqtp_roundTo < int > ( internalPlotBorderLeft_notIncludingOutsidePlotSections - plotterStyle . plotBorderLeft ) ;
int ibBottom = jkqtp_roundTo < int > ( internalPlotBorderBottom_notIncludingOutsidePlotSections - plotterStyle . plotBorderBottom ) ;
int ibRight = jkqtp_roundTo < int > ( internalPlotBorderRight_notIncludingOutsidePlotSections - plotterStyle . plotBorderRight ) ;
2015-07-11 18:56:02 +08:00
for ( int j = 0 ; j < graphs . size ( ) ; j + + ) {
2019-01-20 17:49:29 +08:00
JKQTPPlotElement * g = graphs [ j ] ;
2019-02-03 21:04:48 +08:00
if ( g - > isVisible ( ) ) g - > draw ( painter ) ;
2015-07-11 18:56:02 +08:00
}
if ( useClipping ) {
painter . setClipping ( false ) ;
}
for ( int j = 0 ; j < graphs . size ( ) ; j + + ) {
2019-01-20 17:49:29 +08:00
JKQTPPlotElement * g = graphs [ j ] ;
2019-02-03 21:04:48 +08:00
if ( g - > isVisible ( ) ) {
2020-09-09 02:15:33 +08:00
int leftSpace , rightSpace , topSpace , bottomSpace ;
2015-07-11 18:56:02 +08:00
g - > getOutsideSize ( painter , leftSpace , rightSpace , topSpace , bottomSpace ) ;
ibTop + = topSpace ;
ibLeft + = leftSpace ;
2019-06-21 21:46:53 +08:00
QRectF rleft ( internalPlotBorderLeft + internalPlotKeyBorderLeft - ibLeft , internalPlotBorderTop , leftSpace , internalPlotHeight ) ;
QRectF rright ( internalPlotBorderLeft + internalPlotWidth + ibRight - internalPlotKeyBorderRight , internalPlotBorderTop , rightSpace , internalPlotHeight ) ;
QRectF rtop ( internalPlotBorderLeft , internalPlotBorderTop - ibTop + internalPlotKeyBorderTop , internalPlotWidth , topSpace ) ;
QRectF rbottom ( internalPlotBorderLeft , internalPlotBorderTop + internalPlotHeight + ibBottom , internalPlotWidth , bottomSpace ) ;
g - > drawOutside ( painter , rleft . toRect ( ) , rright . toRect ( ) , rtop . toRect ( ) , rbottom . toRect ( ) ) ;
2019-02-08 00:24:46 +08:00
if ( plotterStyle . debugShowRegionBoxes ) {
painter . save ( ) ; auto __finalpaint = JKQTPFinally ( [ & painter ] ( ) { painter . restore ( ) ; } ) ;
QPen p ( " green " ) ;
p . setWidthF ( plotterStyle . debugRegionLineWidth ) ;
2022-07-23 22:05:13 +08:00
QColor col = p . color ( ) ; col . setAlphaF ( 0.8f ) ; p . setColor ( col ) ;
2019-02-08 00:24:46 +08:00
painter . setPen ( p ) ;
painter . setBrush ( QBrush ( QColor ( Qt : : transparent ) ) ) ;
if ( rleft . width ( ) > 0 & & rleft . height ( ) > 0 ) painter . drawRect ( rleft ) ;
if ( rright . width ( ) > 0 & & rright . height ( ) > 0 ) painter . drawRect ( rright ) ;
if ( rtop . width ( ) > 0 & & rtop . height ( ) > 0 ) painter . drawRect ( rtop ) ;
if ( rbottom . width ( ) > 0 & & rbottom . height ( ) > 0 ) painter . drawRect ( rbottom ) ;
}
2015-07-11 18:56:02 +08:00
ibRight + = rightSpace ;
ibBottom + = bottomSpace ;
}
}
2019-01-26 03:16:04 +08:00
//qDebug()<<" end JKQTBasePlotter::plotGraphs()";
2015-07-11 18:56:02 +08:00
}
2019-04-22 19:27:50 +08:00
void JKQTBasePlotter : : drawKeyContents ( JKQTPEnhancedPainter & painter , double x , double y , double /*width*/ , double /*height*/ ) {
2015-07-11 18:56:02 +08:00
# ifdef JKQTBP_AUTOTIMER
2019-01-20 17:49:29 +08:00
JKQTPAutoOutputTimer jkaaot ( QString ( " JKQTBasePlotter::plotKeyContents(%1, %2, %3, %4) " ).arg(x).arg(y).arg(width).arg(height)) ;
2015-07-11 18:56:02 +08:00
# endif
2019-02-08 00:24:46 +08:00
painter . save ( ) ; auto __finalpaint = JKQTPFinally ( [ & painter ] ( ) { painter . restore ( ) ; } ) ;
2015-07-11 18:56:02 +08:00
double key_text_width = 0 ;
double key_text_height = 0 ;
double dw , dh ;
int columns = 1 ;
int lines = 1 ;
getKeyExtent ( painter , & dw , & dh , & key_text_width , & key_text_height , & columns , & lines ) ;
# ifdef SHOW_JKQTPLOTTER_DEBUG
qDebug ( ) < < " key_item_height= " < < key_item_height ;
2019-02-08 00:24:46 +08:00
qDebug ( ) < < " plotKey(): dw= " < < dw < < " dh= " < < dh < < " key_text_width= " < < key_text_width < < " key_text_height= " < < key_text_height < < " columns= " < < columns < < " lines= " < < lines < < " plotterStyle.keyStyle.layout= " < < plotterStyle . keyStyle . layout ;
2015-07-11 18:56:02 +08:00
# endif
2022-06-03 03:02:23 +08:00
QFont kf ( JKQTMathTextFontSpecifier : : fromFontSpec ( plotterStyle . defaultFontName ) . fontName ( ) , 10 ) ;
2019-06-21 21:46:53 +08:00
kf . setPointSizeF ( plotterStyle . keyStyle . fontSize * fontSizeMultiplier ) ;
2015-07-11 18:56:02 +08:00
QFontMetricsF kfm ( kf ) ;
2019-02-08 00:24:46 +08:00
if ( plotterStyle . keyStyle . layout = = JKQTPKeyLayoutOneColumn ) {
2015-07-11 18:56:02 +08:00
for ( int i = 0 ; i < graphs . size ( ) ; i + + ) {
2019-01-20 17:49:29 +08:00
JKQTPPlotElement * g = graphs [ i ] ;
2015-07-11 18:56:02 +08:00
# ifdef JKQTBP_AUTOTIMER
2019-01-26 20:00:40 +08:00
jkaaot . write ( QString ( " one-col: graph %1: %2 " ) . arg ( i ) . arg ( g - > getTitle ( ) ) ) ;
2015-07-11 18:56:02 +08:00
# endif
2022-04-22 19:27:31 +08:00
const auto Xwid = kfm . boundingRect ( ' X ' ) . width ( ) ;
2019-02-03 21:04:48 +08:00
if ( ! g - > getTitle ( ) . isEmpty ( ) & & g - > isVisible ( ) ) {
2019-02-08 00:24:46 +08:00
QSizeF fs = getTextSizeSize ( plotterStyle . defaultFontName , plotterStyle . keyStyle . fontSize * fontSizeMultiplier , g - > getTitle ( ) , painter ) ; // mt.getSize(painter);
2022-04-22 19:27:31 +08:00
double itheight = qMax ( plotterStyle . keyStyle . itemHeight * Xwid , fs . height ( ) ) ;
QRectF markerRect ( x , y + 1.5 * lineWidthMultiplier , plotterStyle . keyStyle . sampleLineLength * Xwid , itheight - 3.0 * lineWidthMultiplier ) ;
2019-02-08 00:24:46 +08:00
g - > drawKeyMarker ( painter , markerRect ) ;
mathText . setFontColor ( plotterStyle . keyStyle . textColor ) ;
mathText . setFontSize ( plotterStyle . keyStyle . fontSize * fontSizeMultiplier ) ;
2022-09-01 20:36:34 +08:00
mathText . setFontSpecial ( plotterStyle . defaultFontName ) ;
2015-07-11 18:56:02 +08:00
2019-01-26 20:00:40 +08:00
mathText . parse ( g - > getTitle ( ) ) ;
2022-04-22 19:27:31 +08:00
QRectF txtRect ( x + ( plotterStyle . keyStyle . sampleLineLength + plotterStyle . keyStyle . xSeparation ) * Xwid , y , key_text_width , itheight ) ;
2022-06-03 05:05:58 +08:00
mathText . draw ( painter , Qt : : AlignLeft | Qt : : AlignVCenter , txtRect , plotterStyle . debugShowTextBoxes ) ;
2015-07-11 18:56:02 +08:00
//if (itheight<key_item_height*kfm.height()) itheight=key_item_height*kfm.height();
2019-02-08 00:24:46 +08:00
//y=y+itheight+(plotterStyle.keyStyle.ySeparation)*kfm.height();
2022-04-22 19:27:31 +08:00
y = y + key_text_height + ( plotterStyle . keyStyle . ySeparation ) * Xwid ;
2019-02-08 00:24:46 +08:00
if ( plotterStyle . debugShowRegionBoxes ) {
2020-08-26 17:00:25 +08:00
painter . save ( ) ; auto __finalpaintinner = JKQTPFinally ( [ & painter ] ( ) { painter . restore ( ) ; } ) ;
2019-02-08 00:24:46 +08:00
QPen p ( " orange " ) ;
2022-07-23 22:05:13 +08:00
QColor col = p . color ( ) ; col . setAlphaF ( 0.8f ) ; p . setColor ( col ) ;
2019-02-08 00:24:46 +08:00
p . setWidthF ( plotterStyle . debugRegionLineWidth / 2.0 ) ;
p . setStyle ( Qt : : DashLine ) ;
painter . setPen ( p ) ;
painter . setBrush ( QBrush ( QColor ( Qt : : transparent ) ) ) ;
painter . drawRect ( txtRect ) ;
painter . drawRect ( markerRect ) ;
}
2015-07-11 18:56:02 +08:00
}
}
2019-02-08 00:24:46 +08:00
} else if ( plotterStyle . keyStyle . layout = = JKQTPKeyLayoutOneRow ) {
2015-07-11 18:56:02 +08:00
for ( int i = 0 ; i < graphs . size ( ) ; i + + ) {
2019-01-20 17:49:29 +08:00
JKQTPPlotElement * g = graphs [ i ] ;
2015-07-11 18:56:02 +08:00
# ifdef JKQTBP_AUTOTIMER
2019-01-26 20:00:40 +08:00
jkaaot . write ( QString ( " one-row: graph %1: %2 " ) . arg ( i ) . arg ( g - > getTitle ( ) ) ) ;
2015-07-11 18:56:02 +08:00
# endif
2019-02-03 21:04:48 +08:00
if ( ! g - > getTitle ( ) . isEmpty ( ) & & g - > isVisible ( ) ) {
2022-04-22 19:27:31 +08:00
const auto Xwid = kfm . boundingRect ( ' X ' ) . width ( ) ;
2019-02-08 00:24:46 +08:00
QSizeF fs = getTextSizeSize ( plotterStyle . defaultFontName , plotterStyle . keyStyle . fontSize * fontSizeMultiplier , g - > getTitle ( ) , painter ) ; // mt.getSize(painter);
2022-04-22 19:27:31 +08:00
double itheight = qMax ( plotterStyle . keyStyle . itemHeight * Xwid , fs . height ( ) ) ;
QRectF markerRect ( x , y + 1.5 * lineWidthMultiplier , plotterStyle . keyStyle . sampleLineLength * Xwid , itheight - 3.0 * lineWidthMultiplier ) ;
2019-02-08 00:24:46 +08:00
g - > drawKeyMarker ( painter , markerRect ) ;
mathText . setFontColor ( plotterStyle . keyStyle . textColor ) ;
mathText . setFontSize ( plotterStyle . keyStyle . fontSize * fontSizeMultiplier ) ;
2022-09-01 20:36:34 +08:00
mathText . setFontSpecial ( plotterStyle . defaultFontName ) ;
2015-07-11 18:56:02 +08:00
2019-01-26 20:00:40 +08:00
mathText . parse ( g - > getTitle ( ) ) ;
2022-04-22 19:27:31 +08:00
QRectF txtRect ( x + ( plotterStyle . keyStyle . sampleLineLength + plotterStyle . keyStyle . xSeparation ) * Xwid , y , fs . width ( ) , itheight ) ;
2022-06-03 05:05:58 +08:00
mathText . draw ( painter , Qt : : AlignLeft | Qt : : AlignVCenter , txtRect , plotterStyle . debugShowTextBoxes ) ;
2019-02-08 00:24:46 +08:00
if ( plotterStyle . debugShowRegionBoxes ) {
2020-08-26 17:00:25 +08:00
painter . save ( ) ; auto __finalpaintinner = JKQTPFinally ( [ & painter ] ( ) { painter . restore ( ) ; } ) ;
2019-02-08 00:24:46 +08:00
QPen p ( " orange " ) ;
2022-07-23 22:05:13 +08:00
QColor col = p . color ( ) ; col . setAlphaF ( 0.8f ) ; p . setColor ( col ) ;
2019-02-08 00:24:46 +08:00
p . setWidthF ( plotterStyle . debugRegionLineWidth / 2.0 ) ;
p . setStyle ( Qt : : DashLine ) ;
painter . setPen ( p ) ;
painter . setBrush ( QBrush ( QColor ( Qt : : transparent ) ) ) ;
painter . drawRect ( txtRect ) ;
painter . drawRect ( markerRect ) ;
}
2015-07-11 18:56:02 +08:00
//if (itheight<key_item_height*kfm.height()) itheight=key_item_height*kfm.height();
2019-02-08 00:24:46 +08:00
//y=y+itheight+(plotterStyle.keyStyle.ySeparation)*kfm.height();
2022-04-22 19:27:31 +08:00
x = x + fs . width ( ) + ( 2.0 * plotterStyle . keyStyle . xSeparation + plotterStyle . keyStyle . sampleLineLength ) * Xwid ;
2015-07-11 18:56:02 +08:00
}
}
2019-02-08 00:24:46 +08:00
} else if ( plotterStyle . keyStyle . layout = = JKQTPKeyLayoutMultiColumn ) {
2022-04-22 19:27:31 +08:00
//int columns=floor(static_cast<double>(plotWidth)/static_cast<double>(key_item_width*Xwid));
2015-07-11 18:56:02 +08:00
bool colfirst = true ;
2019-02-08 00:24:46 +08:00
if ( plotterStyle . keyStyle . position = = JKQTPKeyInsideTopLeft | | plotterStyle . keyStyle . position = = JKQTPKeyInsideTopRight
| | plotterStyle . keyStyle . position = = JKQTPKeyOutsideTopLeft | | plotterStyle . keyStyle . position = = JKQTPKeyOutsideTopRight ) {
2015-07-11 18:56:02 +08:00
colfirst = false ;
}
int l = 1 ;
int c = 1 ;
double xx = x ;
double yy = y ;
2022-04-22 19:27:31 +08:00
const auto Xwid = kfm . boundingRect ( ' X ' ) . width ( ) ;
2015-07-11 18:56:02 +08:00
for ( int i = 0 ; i < graphs . size ( ) ; i + + ) {
2019-01-20 17:49:29 +08:00
JKQTPPlotElement * g = graphs [ i ] ;
2015-07-11 18:56:02 +08:00
# ifdef JKQTBP_AUTOTIMER
2019-01-26 20:00:40 +08:00
jkaaot . write ( QString ( " multi-col: graph %1: %2 " ) . arg ( i ) . arg ( g - > getTitle ( ) ) ) ;
2015-07-11 18:56:02 +08:00
# endif
2019-02-03 21:04:48 +08:00
if ( ! g - > getTitle ( ) . isEmpty ( ) & & g - > isVisible ( ) ) {
2019-02-08 00:24:46 +08:00
//QSizeF fs=getTextSizeSize(plotterStyle.defaultFontName,plotterStyle.keyStyle.fontSize*fontSizeMultiplier,g->getTitle(),painter);// mt.getSize(painter);
2022-04-22 19:27:31 +08:00
double itheight = qMax ( plotterStyle . keyStyle . itemHeight * Xwid , key_text_height ) ;
QRectF markerRect ( xx , yy + 1.5 * lineWidthMultiplier , plotterStyle . keyStyle . sampleLineLength * Xwid , itheight - 3.0 * lineWidthMultiplier ) ;
2019-02-08 00:24:46 +08:00
g - > drawKeyMarker ( painter , markerRect ) ;
mathText . setFontColor ( plotterStyle . keyStyle . textColor ) ;
mathText . setFontSize ( plotterStyle . keyStyle . fontSize * fontSizeMultiplier ) ;
2022-09-01 20:36:34 +08:00
mathText . setFontSpecial ( plotterStyle . defaultFontName ) ;
2019-01-26 20:00:40 +08:00
mathText . parse ( g - > getTitle ( ) ) ;
2015-07-11 18:56:02 +08:00
//QSizeF fs=mt.getSize(painter);
2022-04-22 19:27:31 +08:00
QRectF txtRect ( xx + ( plotterStyle . keyStyle . sampleLineLength + plotterStyle . keyStyle . xSeparation ) * Xwid , yy , key_text_width , key_text_height ) ;
2022-06-03 05:05:58 +08:00
mathText . draw ( painter , Qt : : AlignLeft | Qt : : AlignVCenter , txtRect , plotterStyle . debugShowTextBoxes ) ;
2019-02-08 00:24:46 +08:00
if ( plotterStyle . debugShowRegionBoxes ) {
2020-08-26 17:00:25 +08:00
painter . save ( ) ; auto __finalpaintinner = JKQTPFinally ( [ & painter ] ( ) { painter . restore ( ) ; } ) ;
2019-02-08 00:24:46 +08:00
QPen p ( " orange " ) ;
2022-07-23 22:05:13 +08:00
QColor col = p . color ( ) ; col . setAlphaF ( 0.8f ) ; p . setColor ( col ) ;
2019-02-08 00:24:46 +08:00
p . setWidthF ( plotterStyle . debugRegionLineWidth / 2.0 ) ;
p . setStyle ( Qt : : DashLine ) ;
painter . setPen ( p ) ;
painter . setBrush ( QBrush ( QColor ( Qt : : transparent ) ) ) ;
painter . drawRect ( txtRect ) ;
painter . drawRect ( markerRect ) ;
}
2015-07-11 18:56:02 +08:00
if ( colfirst ) {
2022-04-22 19:27:31 +08:00
yy = yy + key_text_height + ( plotterStyle . keyStyle . ySeparation ) * Xwid ;
2015-07-11 18:56:02 +08:00
l + + ;
if ( l > lines ) {
l = 1 ;
c + + ;
2022-04-22 19:27:31 +08:00
xx = xx + key_text_width + ( plotterStyle . keyStyle . sampleLineLength + 2.0 * plotterStyle . keyStyle . xSeparation ) * Xwid ;
/*if (plotterStyle.keyStyle.autosize) xx=xx+key_text_width+(key_line_length+3.0*plotterStyle.keyStyle.xSeparation)*Xwid;
else xx = xx + ( key_item_width + 2.0 * plotterStyle . keyStyle . xSeparation ) * Xwid ; */
2015-07-11 18:56:02 +08:00
yy = y ;
}
} else {
2022-04-22 19:27:31 +08:00
/*if (plotterStyle.keyStyle.autosize) xx=xx+key_text_width+(key_line_length+3.0*plotterStyle.keyStyle.xSeparation)*Xwid;
else xx = xx + ( key_item_width + 2.0 * plotterStyle . keyStyle . xSeparation ) * Xwid ; */
xx = xx + key_text_width + ( plotterStyle . keyStyle . sampleLineLength + 2.0 * plotterStyle . keyStyle . xSeparation ) * Xwid ;
2015-07-11 18:56:02 +08:00
c + + ;
if ( c > columns ) {
c = 1 ;
l + + ;
2019-02-08 00:24:46 +08:00
//yy=yy+(key_item_height+plotterStyle.keyStyle.ySeparation)*kfm.height();
2022-04-22 19:27:31 +08:00
yy = yy + itheight + ( plotterStyle . keyStyle . ySeparation ) * Xwid ;
2015-07-11 18:56:02 +08:00
xx = x ;
}
}
}
}
}
/*painter.setPen(pold);
painter . setBrush ( bold ) ; */
2019-02-08 00:24:46 +08:00
2015-07-11 18:56:02 +08:00
}
2019-01-20 17:49:29 +08:00
void JKQTBasePlotter : : getKeyExtent ( JKQTPEnhancedPainter & painter , double * width , double * height , double * text_width , double * text_height , int * columns_count , int * lines_count ) {
2015-07-11 18:56:02 +08:00
# ifdef JKQTBP_AUTOTIMER
2019-01-20 17:49:29 +08:00
JKQTPAutoOutputTimer jkaaot ( " JKQTBasePlotter::getKeyExtent " ) ;
2015-07-11 18:56:02 +08:00
# endif
QFont f = painter . font ( ) ;
2022-06-03 03:02:23 +08:00
f . setFamily ( JKQTMathTextFontSpecifier : : fromFontSpec ( plotterStyle . defaultFontName ) . fontName ( ) ) ;
2019-02-08 00:24:46 +08:00
f . setPointSizeF ( plotterStyle . keyStyle . fontSize * fontSizeMultiplier ) ;
2015-07-11 18:56:02 +08:00
QFontMetricsF kfm ( f ) ;
2022-04-22 19:27:31 +08:00
const qreal Xwid = kfm . boundingRect ( ' X ' ) . width ( ) ;
if ( text_height ! = nullptr ) * text_height = plotterStyle . keyStyle . itemHeight * Xwid ;
2019-02-08 00:24:46 +08:00
if ( plotterStyle . keyStyle . layout = = JKQTPKeyLayoutOneColumn ) {
2015-07-11 18:56:02 +08:00
int keyHeight = graphs . size ( ) ;
double w = 0 ;
double h = 0 ;
painter . setFont ( f ) ;
2018-11-18 18:59:30 +08:00
if ( text_height ! = nullptr ) * text_height = 0 ;
2015-07-11 18:56:02 +08:00
for ( int i = 0 ; i < graphs . size ( ) ; i + + ) {
2019-02-03 21:04:48 +08:00
if ( graphs [ i ] - > getTitle ( ) . isEmpty ( ) | | ! graphs [ i ] - > isVisible ( ) ) {
2015-07-11 18:56:02 +08:00
keyHeight - - ;
} else {
2019-01-26 20:00:40 +08:00
//mt.parse(graphs[i]->getTitle());
2015-07-11 18:56:02 +08:00
//QSizeF fs=mt.getSize(painter);
2019-02-08 00:24:46 +08:00
QSizeF fs = getTextSizeSize ( plotterStyle . defaultFontName , plotterStyle . keyStyle . fontSize * fontSizeMultiplier , graphs [ i ] - > getTitle ( ) , painter ) ;
2015-07-11 18:56:02 +08:00
if ( fs . width ( ) > w ) w = fs . width ( ) ;
if ( text_height & & fs . height ( ) > * text_height ) * text_height = fs . height ( ) ;
2022-04-22 19:27:31 +08:00
h = h + qMax ( plotterStyle . keyStyle . itemHeight * Xwid , fs . height ( ) ) + plotterStyle . keyStyle . ySeparation * Xwid ;
2015-07-11 18:56:02 +08:00
}
}
2019-02-08 00:24:46 +08:00
if ( plotterStyle . keyStyle . autosize ) {
2022-04-22 19:27:31 +08:00
if ( width ) * width = w + ( plotterStyle . keyStyle . sampleLineLength + 2.0 * plotterStyle . keyStyle . xSeparation ) * Xwid ;
if ( text_width ! = nullptr ) * text_width = w + 2.0 * Xwid ;
2015-07-11 18:56:02 +08:00
} else {
2022-04-22 19:27:31 +08:00
if ( width ) * width = plotterStyle . keyStyle . itemWidth * Xwid ;
if ( text_width ! = nullptr ) * text_width = ( plotterStyle . keyStyle . itemWidth - ( plotterStyle . keyStyle . sampleLineLength + plotterStyle . keyStyle . xSeparation ) ) * Xwid ;
2015-07-11 18:56:02 +08:00
}
2022-04-22 19:27:31 +08:00
if ( h > plotterStyle . keyStyle . ySeparation * Xwid ) h = h - plotterStyle . keyStyle . ySeparation * Xwid ;
if ( height ) * height = h ; //keyHeight*key_item_height*Xwid;
2015-07-11 18:56:02 +08:00
if ( columns_count ) * columns_count = 1 ;
if ( lines_count ) * lines_count = keyHeight ;
2019-02-08 00:24:46 +08:00
} else if ( plotterStyle . keyStyle . layout = = JKQTPKeyLayoutOneRow ) {
2015-07-11 18:56:02 +08:00
int keyWidth = graphs . size ( ) ;
double w = 0 ;
double h = 0 ;
painter . setFont ( f ) ;
2018-11-18 18:59:30 +08:00
if ( text_width ! = nullptr ) * text_width = 0 ;
2015-07-11 18:56:02 +08:00
for ( int i = 0 ; i < graphs . size ( ) ; i + + ) {
2019-02-03 21:04:48 +08:00
if ( graphs [ i ] - > getTitle ( ) . isEmpty ( ) | | ! graphs [ i ] - > isVisible ( ) ) {
2015-07-11 18:56:02 +08:00
keyWidth - - ;
} else {
2019-01-26 20:00:40 +08:00
//mt.parse(graphs[i]->getTitle());
2015-07-11 18:56:02 +08:00
//QSizeF fs=mt.getSize(painter);
2019-02-08 00:24:46 +08:00
QSizeF fs = getTextSizeSize ( plotterStyle . defaultFontName , plotterStyle . keyStyle . fontSize * fontSizeMultiplier , graphs [ i ] - > getTitle ( ) , painter ) ;
2015-07-11 18:56:02 +08:00
if ( fs . height ( ) > h ) h = fs . height ( ) ;
if ( text_width & & fs . width ( ) > * text_width ) * text_width = fs . width ( ) ;
2022-04-22 19:27:31 +08:00
w = w + fs . width ( ) + ( plotterStyle . keyStyle . sampleLineLength + 2.0 * plotterStyle . keyStyle . xSeparation ) * Xwid ;
2015-07-11 18:56:02 +08:00
}
}
2022-04-22 19:27:31 +08:00
if ( h < plotterStyle . keyStyle . itemHeight * Xwid ) h = plotterStyle . keyStyle . itemHeight * Xwid ;
2019-02-08 00:24:46 +08:00
if ( plotterStyle . keyStyle . autosize ) {
2015-07-11 18:56:02 +08:00
if ( height ) * height = h ;
2018-11-18 18:59:30 +08:00
if ( text_height ! = nullptr ) * text_height = h ;
2015-07-11 18:56:02 +08:00
} else {
if ( height ) * height = h ;
2022-04-22 19:27:31 +08:00
if ( text_height ! = nullptr ) * text_height = ( plotterStyle . keyStyle . itemHeight - ( plotterStyle . keyStyle . ySeparation ) ) * Xwid ;
2015-07-11 18:56:02 +08:00
}
2022-04-22 19:27:31 +08:00
if ( w > ( plotterStyle . keyStyle . xSeparation ) * Xwid ) w = w - ( plotterStyle . keyStyle . xSeparation ) * Xwid ;
if ( width ) * width = w ; //keyHeight*key_item_height*Xwid;
2015-07-11 18:56:02 +08:00
if ( columns_count ) * columns_count = keyWidth ;
if ( lines_count ) * lines_count = 1 ;
2019-02-08 00:24:46 +08:00
} else if ( plotterStyle . keyStyle . layout = = JKQTPKeyLayoutMultiColumn ) {
2015-07-11 18:56:02 +08:00
// copied code in plotKeyContents()!!!
double keyHeight = graphs . size ( ) ;
double w = 0 ;
double txtH = 0 ;
2020-09-09 02:15:33 +08:00
QFont floc = painter . font ( ) ;
2022-06-03 03:02:23 +08:00
floc . setFamily ( JKQTMathTextFontSpecifier : : fromFontSpec ( plotterStyle . defaultFontName ) . fontName ( ) ) ;
2020-09-09 02:15:33 +08:00
floc . setPointSizeF ( plotterStyle . keyStyle . fontSize * fontSizeMultiplier ) ;
painter . setFont ( floc ) ;
2015-07-11 18:56:02 +08:00
for ( int i = 0 ; i < graphs . size ( ) ; i + + ) {
2019-02-03 21:04:48 +08:00
if ( graphs [ i ] - > getTitle ( ) . isEmpty ( ) | | ! graphs [ i ] - > isVisible ( ) ) {
2015-07-11 18:56:02 +08:00
keyHeight - - ;
} else {
2019-01-26 20:00:40 +08:00
//mt.parse(graphs[i]->getTitle());
2015-07-11 18:56:02 +08:00
//QSizeF fs=mt.getSize(painter);
2019-02-08 00:24:46 +08:00
QSizeF fs = getTextSizeSize ( plotterStyle . defaultFontName , plotterStyle . keyStyle . fontSize * fontSizeMultiplier , graphs [ i ] - > getTitle ( ) , painter ) ;
2015-07-11 18:56:02 +08:00
if ( fs . width ( ) > w ) w = fs . width ( ) ;
if ( fs . height ( ) > txtH ) txtH = fs . height ( ) ;
}
}
if ( text_height ) {
2019-02-08 00:24:46 +08:00
if ( plotterStyle . keyStyle . autosize ) * text_height = txtH ;
2022-04-22 19:27:31 +08:00
else * text_height = plotterStyle . keyStyle . itemHeight * Xwid ;
2015-07-11 18:56:02 +08:00
}
2022-04-22 19:27:31 +08:00
double columns = floor ( double ( internalPlotWidth ) / ( w + ( 2.0 * plotterStyle . keyStyle . xSeparation + plotterStyle . keyStyle . sampleLineLength ) * Xwid ) ) ;
if ( ! plotterStyle . keyStyle . autosize ) columns = floor ( double ( internalPlotWidth ) / ( ( plotterStyle . keyStyle . itemWidth + 2.0 * plotterStyle . keyStyle . xSeparation + plotterStyle . keyStyle . sampleLineLength ) * Xwid ) ) ;
2015-07-11 18:56:02 +08:00
columns = qMin ( columns , keyHeight ) ;
2019-01-26 20:00:40 +08:00
int lines = static_cast < int > ( ceil ( static_cast < double > ( keyHeight ) / static_cast < double > ( columns ) ) ) ;
2019-06-21 21:46:53 +08:00
lines = jkqtp_roundTo < int > ( qMin ( static_cast < double > ( lines ) , keyHeight ) ) ;
2015-07-11 18:56:02 +08:00
2019-02-08 00:24:46 +08:00
if ( plotterStyle . keyStyle . position = = JKQTPKeyInsideTopLeft | | plotterStyle . keyStyle . position = = JKQTPKeyInsideTopRight
| | plotterStyle . keyStyle . position = = JKQTPKeyOutsideTopLeft | | plotterStyle . keyStyle . position = = JKQTPKeyOutsideTopRight ) {
if ( plotterStyle . keyStyle . autosize ) {
2022-04-22 19:27:31 +08:00
lines = static_cast < int > ( floor ( static_cast < double > ( internalPlotHeight ) / static_cast < double > ( txtH + ( plotterStyle . keyStyle . ySeparation ) * Xwid ) ) ) ;
2015-07-11 18:56:02 +08:00
} else {
2022-04-22 19:27:31 +08:00
lines = static_cast < int > ( floor ( static_cast < double > ( internalPlotHeight ) / static_cast < double > ( ( plotterStyle . keyStyle . itemHeight + plotterStyle . keyStyle . ySeparation ) * Xwid ) ) ) ;
2015-07-11 18:56:02 +08:00
}
2019-01-26 20:00:40 +08:00
columns = static_cast < int > ( ceil ( static_cast < double > ( keyHeight ) / static_cast < double > ( lines ) ) ) ;
2019-06-21 21:46:53 +08:00
lines = jkqtp_roundTo < int > ( qMin ( static_cast < double > ( lines ) , keyHeight ) ) ;
2015-07-11 18:56:02 +08:00
}
2019-06-21 21:46:53 +08:00
if ( columns_count ) * columns_count = jkqtp_roundTo < int > ( columns ) ;
2015-07-11 18:56:02 +08:00
if ( lines_count ) * lines_count = lines ;
2019-02-08 00:24:46 +08:00
if ( plotterStyle . keyStyle . autosize ) {
2022-04-22 19:27:31 +08:00
if ( width ) * width = ( w + ( plotterStyle . keyStyle . sampleLineLength + 3.0 * plotterStyle . keyStyle . xSeparation ) * Xwid ) * columns ;
if ( height ) * height = lines * ( txtH + plotterStyle . keyStyle . ySeparation * Xwid ) ;
if ( lines > 0 ) * height = * height - plotterStyle . keyStyle . ySeparation * Xwid ;
2018-11-18 18:59:30 +08:00
if ( text_width ! = nullptr ) * text_width = w ;
2015-07-11 18:56:02 +08:00
} else {
2022-04-22 19:27:31 +08:00
if ( width ) * width = ( plotterStyle . keyStyle . itemWidth + 2.0 * plotterStyle . keyStyle . xSeparation ) * Xwid * columns ;
if ( height ) * height = lines * ( plotterStyle . keyStyle . itemHeight + plotterStyle . keyStyle . ySeparation ) * Xwid ;
if ( lines > 0 ) * height = * height - plotterStyle . keyStyle . ySeparation * Xwid ;
if ( text_width ! = nullptr ) * text_width = ( plotterStyle . keyStyle . itemWidth - ( plotterStyle . keyStyle . sampleLineLength + plotterStyle . keyStyle . xSeparation ) ) * Xwid ;
2015-07-11 18:56:02 +08:00
}
# ifdef SHOW_JKQTPLOTTER_DEBUG
qDebug ( ) < < " getKeyExtent(): mult-column: columns= " < < columns < < " lines= " < < lines ;
# endif
}
}
2019-01-20 17:49:29 +08:00
void JKQTBasePlotter : : loadUserSettings ( )
2015-07-11 18:56:02 +08:00
{
if ( ! userSettigsFilename . isEmpty ( ) ) {
QSettings set ( userSettigsFilename , QSettings : : IniFormat ) ;
set . sync ( ) ;
loadUserSettings ( set , userSettigsPrefix ) ;
}
}
2019-01-26 19:28:44 +08:00
void JKQTBasePlotter : : saveUserSettings ( ) const
2015-07-11 18:56:02 +08:00
{
if ( ! userSettigsFilename . isEmpty ( ) ) {
QSettings set ( userSettigsFilename , QSettings : : IniFormat ) ;
saveUserSettings ( set , userSettigsPrefix ) ;
set . sync ( ) ;
}
}
2023-03-23 20:55:18 +08:00
bool JKQTBasePlotter : : getGraphsXMinMax ( double & minx , double & maxx , double & smallestGreaterZero , const PlotElementPreciate & predicate ) {
2015-07-11 18:56:02 +08:00
bool start = true ;
minx = 0 ;
maxx = 0 ;
smallestGreaterZero = 0 ;
2023-03-23 20:55:18 +08:00
size_t count = 0 ;
2015-07-11 18:56:02 +08:00
for ( int i = 0 ; i < graphs . size ( ) ; i + + ) {
2023-03-23 20:55:18 +08:00
if ( graphs [ i ] - > isVisible ( ) & & predicate ( graphs [ i ] ) ) {
2019-06-21 21:46:53 +08:00
2015-07-11 18:56:02 +08:00
double gminx = 0 ;
double gmaxx = 0 ;
double gsmallestGreaterZero = 0 ;
if ( graphs [ i ] - > getXMinMax ( gminx , gmaxx , gsmallestGreaterZero ) ) {
2019-06-21 21:46:53 +08:00
// std::cout<<" -> "<<i<<": "<<graphs[i]->getTitle().toStdString()<<": "<<gminx<<"..."<<gmaxx<<std::endl;
2015-07-11 18:56:02 +08:00
if ( ( gminx < minx ) | | start ) minx = gminx ;
if ( ( gmaxx > maxx ) | | start ) maxx = gmaxx ;
double xvsgz ;
xvsgz = gsmallestGreaterZero ; if ( ( xvsgz > 10.0 * DBL_MIN ) & & ( ( smallestGreaterZero < 10.0 * DBL_MIN ) | | ( xvsgz < smallestGreaterZero ) ) ) smallestGreaterZero = xvsgz ;
xvsgz = gmaxx ; if ( ( xvsgz > 10.0 * DBL_MIN ) & & ( ( smallestGreaterZero < 10.0 * DBL_MIN ) | | ( xvsgz < smallestGreaterZero ) ) ) smallestGreaterZero = xvsgz ;
xvsgz = gminx ; if ( ( xvsgz > 10.0 * DBL_MIN ) & & ( ( smallestGreaterZero < 10.0 * DBL_MIN ) | | ( xvsgz < smallestGreaterZero ) ) ) smallestGreaterZero = xvsgz ;
2019-06-21 21:46:53 +08:00
//std::cout<<" "<<i<<": gminx="<<gminx<<" gmaxx="<<gmaxx<<" minx="<<minx<<" maxx="<<maxx<<std::endl;
2015-07-11 18:56:02 +08:00
start = false ;
2023-03-23 20:55:18 +08:00
count + + ;
2019-06-21 21:46:53 +08:00
} else {
//std::cout<<" -> "<<i<<": "<<graphs[i]->getTitle().toStdString()<<": FALSE"<<std::endl;
2015-07-11 18:56:02 +08:00
}
2019-06-21 21:46:53 +08:00
} else {
//std::cout<<" -> "<<i<<": "<<graphs[i]->getTitle().toStdString()<<": INVISIBLE"<<std::endl;
2015-07-11 18:56:02 +08:00
}
}
2023-03-23 20:55:18 +08:00
return count > 0 ;
2015-07-11 18:56:02 +08:00
}
2023-03-23 20:55:18 +08:00
bool JKQTBasePlotter : : getGraphsYMinMax ( double & miny , double & maxy , double & smallestGreaterZero , const PlotElementPreciate & predicate ) {
2015-07-11 18:56:02 +08:00
bool start = true ;
miny = 0 ;
maxy = 0 ;
smallestGreaterZero = 0 ;
2023-03-23 20:55:18 +08:00
size_t count = 0 ;
2015-07-11 18:56:02 +08:00
for ( int i = 0 ; i < graphs . size ( ) ; i + + ) {
2023-03-23 20:55:18 +08:00
if ( graphs [ i ] - > isVisible ( ) & & predicate ( graphs [ i ] ) ) {
2015-07-11 18:56:02 +08:00
double gminy = 0 ;
double gmaxy = 0 ;
double gsmallestGreaterZero = 0 ;
if ( graphs [ i ] - > getYMinMax ( gminy , gmaxy , gsmallestGreaterZero ) ) {
if ( ( gminy < miny ) | | start ) miny = gminy ;
if ( ( gmaxy > maxy ) | | start ) maxy = gmaxy ;
double xvsgz ;
xvsgz = gsmallestGreaterZero ; if ( ( xvsgz > 10.0 * DBL_MIN ) & & ( ( smallestGreaterZero < 10.0 * DBL_MIN ) | | ( xvsgz < smallestGreaterZero ) ) ) smallestGreaterZero = xvsgz ;
xvsgz = gmaxy ; if ( ( xvsgz > 10.0 * DBL_MIN ) & & ( ( smallestGreaterZero < 10.0 * DBL_MIN ) | | ( xvsgz < smallestGreaterZero ) ) ) smallestGreaterZero = xvsgz ;
xvsgz = gminy ; if ( ( xvsgz > 10.0 * DBL_MIN ) & & ( ( smallestGreaterZero < 10.0 * DBL_MIN ) | | ( xvsgz < smallestGreaterZero ) ) ) smallestGreaterZero = xvsgz ;
start = false ;
2023-03-23 20:55:18 +08:00
count + + ;
2015-07-11 18:56:02 +08:00
}
}
}
2023-03-23 20:55:18 +08:00
return count > 0 ;
2015-07-11 18:56:02 +08:00
}
2019-01-20 17:49:29 +08:00
void JKQTBasePlotter : : zoomToFit ( bool zoomX , bool zoomY , bool includeX0 , bool includeY0 , double scaleX , double scaleY ) {
2019-06-21 21:46:53 +08:00
// std::cout<<"JKQTBasePlotter::zoomToFit():\n";
2015-07-11 18:56:02 +08:00
if ( graphs . size ( ) < = 0 ) return ;
2023-03-23 20:55:18 +08:00
auto calcLocScaling = [ ] ( JKQTPCoordinateAxis * axis , double & xxmin , double & xxmax , double & xsmallestGreaterZero , bool include0 , double scale ) - > bool {
2015-07-11 18:56:02 +08:00
if ( JKQTPIsOKFloat ( xxmin ) & & JKQTPIsOKFloat ( xxmax ) ) {
bool doScale = true ;
if ( fabs ( xxmin - xxmax ) < 1e-305 ) {
2023-03-23 20:55:18 +08:00
xxmin = axis - > getMin ( ) ;
xxmax = axis - > getMax ( ) ;
2015-07-11 18:56:02 +08:00
doScale = false ;
}
2023-03-23 20:55:18 +08:00
if ( axis - > isLogAxis ( ) ) {
2015-07-11 18:56:02 +08:00
if ( ( xxmin < = 1e-305 ) & & ( xxmax < = 1e-305 ) ) { xxmin = 0.1 ; xxmax = 1.0 ; }
else if ( ( xxmin < = 1e-305 ) & & ( xxmax > 0 ) ) {
if ( xsmallestGreaterZero > 10.0 * DBL_MIN ) xxmin = xsmallestGreaterZero ;
2023-03-23 20:55:18 +08:00
else xxmin = xxmax / axis - > getLogAxisBase ( ) ;
2015-07-11 18:56:02 +08:00
}
if ( doScale ) {
2023-03-23 20:55:18 +08:00
double d = scale * ( log ( xxmax ) - log ( xxmin ) ) ; // new width
2015-07-11 18:56:02 +08:00
double c = ( log ( xxmax ) + log ( xxmin ) ) / 2.0 ; // center of interval
xxmin = exp ( c - d / 2.0 ) ;
xxmax = exp ( c + d / 2.0 ) ;
}
} else if ( doScale ) {
2023-03-23 20:55:18 +08:00
double d = scale * ( xxmax - xxmin ) ; // new width
2015-07-11 18:56:02 +08:00
double c = ( xxmax + xxmin ) / 2.0 ; // center of interval
xxmin = c - d / 2.0 ;
xxmax = c + d / 2.0 ;
}
2023-03-23 20:55:18 +08:00
if ( include0 & & ! axis - > isLogAxis ( ) ) {
2015-07-11 18:56:02 +08:00
if ( xxmin > 0 ) xxmin = 0 ;
else if ( xxmax < 0 ) xxmax = 0 ;
}
2023-03-23 20:55:18 +08:00
2015-07-11 18:56:02 +08:00
if ( JKQTPIsOKFloat ( xxmin ) & & JKQTPIsOKFloat ( xxmax ) ) {
2023-03-23 20:55:18 +08:00
axis - > setRange ( xxmin , xxmax ) ;
2015-07-11 18:56:02 +08:00
} else if ( ! JKQTPIsOKFloat ( xxmin ) & & JKQTPIsOKFloat ( xxmax ) ) {
2023-03-23 20:55:18 +08:00
axis - > setRange ( axis - > getMin ( ) , xxmax ) ;
2015-07-11 18:56:02 +08:00
} else if ( JKQTPIsOKFloat ( xxmin ) & & ! JKQTPIsOKFloat ( xxmax ) ) {
2023-03-23 20:55:18 +08:00
axis - > setRange ( xxmin , axis - > getMax ( ) ) ;
}
return doScale ;
}
return false ;
} ;
if ( zoomX ) {
const auto axes = getXAxes ( ) ;
for ( auto it = axes . begin ( ) ; it ! = axes . end ( ) ; + + it ) {
double xxmin = 0 ;
double xxmax = 0 ;
double xsmallestGreaterZero = 0 ;
if ( getGraphsXMinMax ( xxmin , xxmax , xsmallestGreaterZero , filterPlotElementByXAxis ( it . key ( ) ) ) ) {
calcLocScaling ( it . value ( ) , xxmin , xxmax , xsmallestGreaterZero , includeX0 , scaleX ) ;
2015-07-11 18:56:02 +08:00
}
}
}
if ( zoomY ) {
2023-03-23 20:55:18 +08:00
const auto axes = getYAxes ( ) ;
for ( auto it = axes . begin ( ) ; it ! = axes . end ( ) ; + + it ) {
double xxmin = 0 ;
double xxmax = 0 ;
double xsmallestGreaterZero = 0 ;
if ( getGraphsYMinMax ( xxmin , xxmax , xsmallestGreaterZero , filterPlotElementByYAxis ( it . key ( ) ) ) ) {
calcLocScaling ( it . value ( ) , xxmin , xxmax , xsmallestGreaterZero , includeY0 , scaleY ) ;
2015-07-11 18:56:02 +08:00
}
}
}
//std::cout<<"end of zoomToFit\n";
//setXY(xxmin, xxmax, yymin, yymax);
if ( emitSignals ) emit zoomChangedLocally ( xAxis - > getMin ( ) , xAxis - > getMax ( ) , yAxis - > getMin ( ) , yAxis - > getMax ( ) , this ) ;
}
2019-01-20 17:49:29 +08:00
JKQTPPlotElement * JKQTBasePlotter : : getGraph ( size_t i ) {
2019-06-21 21:46:53 +08:00
return graphs [ static_cast < int > ( i ) ] ;
2015-07-11 18:56:02 +08:00
} ;
2023-05-28 05:46:45 +08:00
const JKQTPPlotElement * JKQTBasePlotter : : getGraph ( size_t i ) const {
return graphs [ static_cast < int > ( i ) ] ;
} ;
size_t JKQTBasePlotter : : getGraphCount ( ) const {
2019-06-21 21:46:53 +08:00
return static_cast < size_t > ( graphs . size ( ) ) ;
2015-07-11 18:56:02 +08:00
} ;
2019-01-20 17:49:29 +08:00
void JKQTBasePlotter : : deleteGraph ( size_t i , bool deletegraph ) {
2015-07-11 18:56:02 +08:00
if ( long ( i ) < 0 | | long ( i ) > = graphs . size ( ) ) return ;
2019-06-21 21:46:53 +08:00
JKQTPPlotElement * g = graphs [ static_cast < int > ( i ) ] ;
graphs . removeAt ( static_cast < int > ( i ) ) ;
2015-07-11 18:56:02 +08:00
if ( deletegraph & & g ) delete g ;
2023-05-28 05:46:45 +08:00
redrawPlot ( ) ;
2015-07-11 18:56:02 +08:00
} ;
2019-01-20 17:49:29 +08:00
void JKQTBasePlotter : : deleteGraph ( JKQTPPlotElement * gr , bool deletegraph ) {
2023-05-28 05:46:45 +08:00
int i = indexOfGraph ( gr ) ;
2015-07-11 18:56:02 +08:00
while ( i > = 0 ) {
graphs . removeAt ( i ) ;
2023-05-28 05:46:45 +08:00
i = indexOfGraph ( gr ) ;
2015-07-11 18:56:02 +08:00
}
if ( deletegraph & & gr ) delete gr ;
2023-05-28 05:46:45 +08:00
redrawPlot ( ) ;
2015-07-11 18:56:02 +08:00
}
2019-01-20 17:49:29 +08:00
void JKQTBasePlotter : : clearGraphs ( bool deleteGraphs ) {
2015-07-11 18:56:02 +08:00
for ( int i = 0 ; i < graphs . size ( ) ; i + + ) {
2019-01-20 17:49:29 +08:00
JKQTPPlotElement * g = graphs [ i ] ;
2015-07-11 18:56:02 +08:00
if ( g & & deleteGraphs ) delete g ;
}
graphs . clear ( ) ;
usedStyles . clear ( ) ;
2023-05-28 05:46:45 +08:00
redrawPlot ( ) ;
2015-07-11 18:56:02 +08:00
}
2019-01-20 17:49:29 +08:00
void JKQTBasePlotter : : setAllGraphsInvisible ( )
2015-07-11 18:56:02 +08:00
{
for ( int i = 0 ; i < graphs . size ( ) ; i + + ) {
2019-01-20 17:49:29 +08:00
JKQTPPlotElement * g = graphs [ i ] ;
2019-01-26 20:00:40 +08:00
g - > setVisible ( false ) ;
2015-07-11 18:56:02 +08:00
}
2023-05-28 05:46:45 +08:00
redrawPlot ( ) ;
2015-07-11 18:56:02 +08:00
}
2019-01-20 17:49:29 +08:00
void JKQTBasePlotter : : setAllGraphsVisible ( )
2015-07-11 18:56:02 +08:00
{
for ( int i = 0 ; i < graphs . size ( ) ; i + + ) {
2019-01-20 17:49:29 +08:00
JKQTPPlotElement * g = graphs [ i ] ;
2019-01-26 20:00:40 +08:00
g - > setVisible ( true ) ;
2015-07-11 18:56:02 +08:00
}
2023-05-28 05:46:45 +08:00
redrawPlot ( ) ;
2015-07-11 18:56:02 +08:00
}
2019-01-20 17:49:29 +08:00
void JKQTBasePlotter : : setGraphVisible ( int i , bool visible )
2015-07-11 18:56:02 +08:00
{
2019-01-20 17:49:29 +08:00
JKQTPPlotElement * g = graphs . value ( i , nullptr ) ;
2019-01-26 20:00:40 +08:00
if ( g ) g - > setVisible ( visible ) ;
2023-05-28 05:46:45 +08:00
redrawPlot ( ) ;
}
void JKQTBasePlotter : : setGraphInvisible ( int i )
{
setGraphVisible ( i , false ) ;
2015-07-11 18:56:02 +08:00
}
2019-01-20 17:49:29 +08:00
void JKQTBasePlotter : : setOnlyGraphVisible ( int gr )
2015-07-11 18:56:02 +08:00
{
for ( int i = 0 ; i < graphs . size ( ) ; i + + ) {
2019-01-20 17:49:29 +08:00
JKQTPPlotElement * g = graphs [ i ] ;
2019-01-26 20:00:40 +08:00
g - > setVisible ( false ) ;
2015-07-11 18:56:02 +08:00
}
2019-01-20 17:49:29 +08:00
JKQTPPlotElement * g = graphs . value ( gr , nullptr ) ;
2019-01-26 20:00:40 +08:00
if ( g ) g - > setVisible ( true ) ;
2023-05-28 05:46:45 +08:00
redrawPlot ( ) ;
2015-07-11 18:56:02 +08:00
}
2019-01-20 17:49:29 +08:00
void JKQTBasePlotter : : setOnlyNthGraphsVisible ( int start , int n )
2015-07-11 18:56:02 +08:00
{
for ( int i = 0 ; i < graphs . size ( ) ; i + + ) {
2019-01-20 17:49:29 +08:00
JKQTPPlotElement * g = graphs [ i ] ;
2019-01-26 20:00:40 +08:00
g - > setVisible ( false ) ;
2015-07-11 18:56:02 +08:00
}
for ( int i = start ; i < graphs . size ( ) ; i + = n ) {
2019-01-20 17:49:29 +08:00
JKQTPPlotElement * g = graphs . value ( i , nullptr ) ;
2019-01-26 20:00:40 +08:00
if ( g ) g - > setVisible ( true ) ;
2015-07-11 18:56:02 +08:00
}
2023-05-28 05:46:45 +08:00
redrawPlot ( ) ;
2015-07-11 18:56:02 +08:00
}
2023-05-28 05:46:45 +08:00
size_t JKQTBasePlotter : : addGraphOnTop ( JKQTPPlotElement * gr ) {
2015-07-11 18:56:02 +08:00
gr - > setParent ( this ) ;
2023-05-28 05:46:45 +08:00
const int indexGR = indexOfGraph ( gr ) ;
if ( indexGR > = 0 ) {
graphs . removeAt ( indexGR ) ;
2015-07-11 18:56:02 +08:00
}
graphs . push_back ( gr ) ;
2023-05-28 05:46:45 +08:00
redrawPlot ( ) ;
2019-06-21 21:46:53 +08:00
return static_cast < size_t > ( graphs . size ( ) - 1 ) ;
2023-05-28 05:46:45 +08:00
}
2015-07-11 18:56:02 +08:00
2023-05-28 05:46:45 +08:00
size_t JKQTBasePlotter : : addGraphAtBottom ( JKQTPPlotElement * gr ) {
2015-07-11 18:56:02 +08:00
gr - > setParent ( this ) ;
2023-05-28 05:46:45 +08:00
const int indexGR = indexOfGraph ( gr ) ;
if ( indexGR > = 0 ) {
graphs . removeAt ( indexGR ) ;
}
graphs . push_front ( gr ) ;
redrawPlot ( ) ;
return static_cast < size_t > ( 0 ) ;
}
void JKQTBasePlotter : : moveGraphTop ( int idx ) {
if ( idx > = 0 & & idx < graphs . size ( ) ) {
JKQTPPlotElement * g = graphs [ idx ] ;
graphs . removeAt ( idx ) ;
graphs . push_back ( g ) ;
redrawPlot ( ) ;
} else {
throw std : : out_of_range ( " index out of range in JKQTBasePlotter::moveGraphTop() " ) ;
}
}
void JKQTBasePlotter : : moveGraphBottom ( int idx )
{
if ( idx > = 0 & & idx < graphs . size ( ) ) {
JKQTPPlotElement * g = graphs [ idx ] ;
graphs . removeAt ( idx ) ;
graphs . push_front ( g ) ;
redrawPlot ( ) ;
} else {
throw std : : out_of_range ( " index out of range in JKQTBasePlotter::moveGraphBottom() " ) ;
}
}
int JKQTBasePlotter : : indexOfGraph ( const JKQTPPlotElement * gr ) const
{
2015-07-11 18:56:02 +08:00
for ( int i = 0 ; i < graphs . size ( ) ; i + + ) {
2023-05-28 05:46:45 +08:00
if ( graphs [ i ] = = gr ) return i ;
}
return - 1 ;
}
void JKQTBasePlotter : : moveGraphUp ( int idx )
{
if ( idx > = 0 & & idx < graphs . size ( ) ) {
if ( idx + 1 < graphs . size ( ) ) {
graphs . move ( idx , idx + 1 ) ;
redrawPlot ( ) ;
2015-07-11 18:56:02 +08:00
}
2023-05-28 05:46:45 +08:00
} else {
throw std : : out_of_range ( " index out of range in JKQTBasePlotter::moveGraphUp() " ) ;
2015-07-11 18:56:02 +08:00
}
}
2023-05-28 05:46:45 +08:00
void JKQTBasePlotter : : moveGraphDown ( int idx )
2015-07-11 18:56:02 +08:00
{
2023-05-28 05:46:45 +08:00
if ( idx > = 0 & & idx < graphs . size ( ) ) {
if ( idx - 1 > = 0 ) {
graphs . move ( idx - 1 , idx ) ;
redrawPlot ( ) ;
2015-07-11 18:56:02 +08:00
}
2023-05-28 05:46:45 +08:00
} else {
throw std : : out_of_range ( " index out of range in JKQTBasePlotter::moveGraphDown() " ) ;
2015-07-11 18:56:02 +08:00
}
2023-05-28 05:46:45 +08:00
}
void JKQTBasePlotter : : moveGraphUp ( const JKQTPPlotElement * gr ) {
moveGraphUp ( indexOfGraph ( gr ) ) ;
}
void JKQTBasePlotter : : moveGraphDown ( const JKQTPPlotElement * gr )
{
moveGraphDown ( indexOfGraph ( gr ) ) ;
}
void JKQTBasePlotter : : moveGraphTop ( const JKQTPPlotElement * gr ) {
moveGraphTop ( indexOfGraph ( gr ) ) ;
}
void JKQTBasePlotter : : moveGraphBottom ( const JKQTPPlotElement * gr )
{
moveGraphBottom ( indexOfGraph ( gr ) ) ;
}
void JKQTBasePlotter : : modifyGraphs ( const std : : function < void ( JKQTPPlotElement * ) > & func )
{
if ( ! func ) return ;
for ( int i = 0 ; i < graphs . size ( ) ; i + + ) {
func ( graphs [ i ] ) ;
}
redrawPlot ( ) ;
}
void JKQTBasePlotter : : sortGraphs ( const std : : function < bool ( const JKQTPPlotElement * , const JKQTPPlotElement * ) > & compareLess )
{
if ( ! compareLess ) return ;
std : : sort ( graphs . begin ( ) , graphs . end ( ) , compareLess ) ;
redrawPlot ( ) ;
2015-07-11 18:56:02 +08:00
} ;
2023-05-28 05:46:45 +08:00
bool JKQTBasePlotter : : containsGraph ( const JKQTPPlotElement * gr ) const {
2015-07-11 18:56:02 +08:00
for ( int i = 0 ; i < graphs . size ( ) ; i + + ) {
if ( graphs [ i ] = = gr ) {
return true ;
}
}
return false ;
} ;
2019-01-26 03:16:04 +08:00
void JKQTBasePlotter : : setUserSettigsFilename ( const QString & filename , const QString & prefix )
2015-07-11 18:56:02 +08:00
{
userSettigsFilename = filename ;
userSettigsPrefix = prefix ;
}
2019-01-26 03:16:04 +08:00
void JKQTBasePlotter : : setUserSettigsFilename ( const QString & filename )
2015-07-11 18:56:02 +08:00
{
userSettigsFilename = filename ;
}
2019-01-26 03:16:04 +08:00
void JKQTBasePlotter : : setUserSettigsPrefix ( const QString & prefix )
2015-07-11 18:56:02 +08:00
{
userSettigsPrefix = prefix ;
}
2019-01-26 03:16:04 +08:00
QString JKQTBasePlotter : : getUserSettigsFilename ( ) const
2015-07-11 18:56:02 +08:00
{
return userSettigsFilename ;
}
2019-01-26 03:16:04 +08:00
QString JKQTBasePlotter : : getUserSettigsPrefix ( ) const
2015-07-11 18:56:02 +08:00
{
return userSettigsPrefix ;
}
2019-01-20 17:49:29 +08:00
QSet < int > JKQTBasePlotter : : getDataColumnsByUser ( ) {
2015-07-11 18:56:02 +08:00
loadUserSettings ( ) ;
QSet < int > set ;
QStringList cols = getDatastore ( ) - > getColumnNames ( ) ;
2018-11-18 18:59:30 +08:00
QDialog * dlg = new QDialog ( nullptr , Qt : : WindowMinMaxButtonsHint ) ;
2015-07-11 18:56:02 +08:00
dlg - > setSizeGripEnabled ( true ) ;
//printZoomFactor=0.95;
//printMagnification=1.5;
QGridLayout * layout = new QGridLayout ( ) ;
dlg - > setLayout ( layout ) ;
dlg - > setWindowTitle ( tr ( " Select columns to export ... " ) ) ;
dlg - > setWindowIcon ( QIcon ( ) ) ;
QLabel * lab = new QLabel ( tr ( " <center><b>Please check the columns that should be exported in the list!</b><br> "
" You may also save a selection to reuse it in future, by clicking \" Save \" . "
" A stored selection can be used by selecting its name in the dropdown field "
" above the list widget.</center> " ) , dlg ) ;
lab - > setWordWrap ( true ) ;
layout - > addWidget ( lab , 0 , 0 , 1 , 2 ) ;
dataColumnsCombobox = new QComboBox ( dlg ) ;
dataColumnsCombobox - > addItems ( getDataColumnsByUserSaved . keys ( ) ) ;
connect ( dataColumnsCombobox , SIGNAL ( currentIndexChanged ( QString ) ) , this , SLOT ( getDataColumnsByUserComboBoxSelected ( QString ) ) ) ;
layout - > addWidget ( dataColumnsCombobox , 1 , 0 ) ;
QPushButton * btn = new QPushButton ( tr ( " &save " ) , dlg ) ;
connect ( btn , SIGNAL ( clicked ( ) ) , this , SLOT ( getDataColumnsByUserSave ( ) ) ) ;
layout - > addWidget ( btn , 1 , 1 ) ;
dataColumnsListWidget = new QListWidget ( dlg ) ;
for ( int i = 0 ; i < cols . size ( ) ; i + + ) {
QListWidgetItem * item = new QListWidgetItem ( cols [ i ] , dataColumnsListWidget ) ;
item - > setCheckState ( Qt : : Checked ) ;
item - > setFlags ( Qt : : ItemIsSelectable | Qt : : ItemIsUserCheckable | Qt : : ItemIsEnabled ) ;
dataColumnsListWidget - > addItem ( item ) ;
}
connect ( dataColumnsListWidget , SIGNAL ( itemChanged ( QListWidgetItem * ) ) , this , SLOT ( getDataColumnsByUserItemChanged ( QListWidgetItem * ) ) ) ;
layout - > addWidget ( dataColumnsListWidget , 2 , 0 , 5 , 1 ) ;
btn = new QPushButton ( tr ( " select &all " ) , dlg ) ;
connect ( btn , SIGNAL ( clicked ( ) ) , this , SLOT ( getDataColumnsByUserCheckAll ( ) ) ) ;
layout - > addWidget ( btn , 2 , 1 ) ;
btn = new QPushButton ( tr ( " select &none " ) , dlg ) ;
connect ( btn , SIGNAL ( clicked ( ) ) , this , SLOT ( getDataColumnsByUserCheckNone ( ) ) ) ;
layout - > addWidget ( btn , 3 , 1 ) ;
QDialogButtonBox * buttonBox = new QDialogButtonBox ( QDialogButtonBox : : Ok | QDialogButtonBox : : Cancel ) ;
connect ( buttonBox , SIGNAL ( accepted ( ) ) , dlg , SLOT ( accept ( ) ) ) ;
connect ( buttonBox , SIGNAL ( rejected ( ) ) , dlg , SLOT ( reject ( ) ) ) ;
layout - > addWidget ( buttonBox , layout - > rowCount ( ) , 0 , 1 , layout - > columnCount ( ) ) ;
layout - > setRowStretch ( layout - > rowCount ( ) - 2 , 1 ) ;
layout - > setColumnStretch ( 0 , 1 ) ;
dlg - > resize ( 350 , 500 ) ;
dataColumnsCombobox - > setCurrentIndex ( - 1 ) ;
if ( dlg - > exec ( ) = = QDialog : : Accepted ) {
for ( int i = 0 ; i < dataColumnsListWidget - > count ( ) ; i + + ) {
if ( dataColumnsListWidget - > item ( i ) - > checkState ( ) = = Qt : : Checked ) {
set . insert ( i ) ;
}
}
}
delete dlg ;
2018-11-18 18:59:30 +08:00
dataColumnsListWidget = nullptr ;
2015-07-11 18:56:02 +08:00
saveUserSettings ( ) ;
return set ;
}
2019-01-20 17:49:29 +08:00
void JKQTBasePlotter : : getDataColumnsByUserCheckAll ( ) {
2015-07-11 18:56:02 +08:00
if ( ! dataColumnsListWidget ) return ;
for ( int i = 0 ; i < dataColumnsListWidget - > count ( ) ; i + + ) {
dataColumnsListWidget - > item ( i ) - > setCheckState ( Qt : : Checked ) ;
}
}
2019-01-20 17:49:29 +08:00
void JKQTBasePlotter : : getDataColumnsByUserCheckNone ( ) {
2015-07-11 18:56:02 +08:00
if ( ! dataColumnsListWidget ) return ;
for ( int i = 0 ; i < dataColumnsListWidget - > count ( ) ; i + + ) {
dataColumnsListWidget - > item ( i ) - > setCheckState ( Qt : : Unchecked ) ;
}
}
2019-01-20 17:49:29 +08:00
void JKQTBasePlotter : : getDataColumnsByUserSave ( ) {
2015-07-11 18:56:02 +08:00
if ( ! dataColumnsListWidget ) return ;
QString name = tr ( " my selection name " ) ;
QStringList items = getDataColumnsByUserSaved . keys ( ) ;
items < < name ;
bool ok = false ;
2018-11-18 18:59:30 +08:00
name = QInputDialog : : getItem ( nullptr , tr ( " save columns selection " ) , tr ( " name for new selection: " ) , items , items . size ( ) - 1 , true , & ok ) ;
2015-07-11 18:56:02 +08:00
if ( ok ) {
QStringList data ;
for ( int i = 0 ; i < dataColumnsListWidget - > count ( ) ; i + + ) {
if ( dataColumnsListWidget - > item ( i ) - > checkState ( ) = = Qt : : Checked ) data . append ( dataColumnsListWidget - > item ( i ) - > text ( ) ) ;
}
data . sort ( ) ;
getDataColumnsByUserSaved [ name ] = data ;
disconnect ( dataColumnsCombobox , SIGNAL ( currentIndexChanged ( QString ) ) , this , SLOT ( getDataColumnsByUserComboBoxSelected ( QString ) ) ) ;
dataColumnsCombobox - > clear ( ) ;
dataColumnsCombobox - > addItems ( getDataColumnsByUserSaved . keys ( ) ) ;
dataColumnsCombobox - > setCurrentIndex ( dataColumnsCombobox - > findText ( name ) ) ;
connect ( dataColumnsCombobox , SIGNAL ( currentIndexChanged ( QString ) ) , this , SLOT ( getDataColumnsByUserComboBoxSelected ( QString ) ) ) ;
}
}
2019-01-20 17:49:29 +08:00
void JKQTBasePlotter : : getDataColumnsByUserComboBoxSelected ( const QString & name ) {
2015-07-11 18:56:02 +08:00
if ( ! dataColumnsListWidget ) return ;
QStringList newItems = getDataColumnsByUserSaved . value ( name , QStringList ( ) ) ;
if ( getDataColumnsByUserSaved . contains ( name ) ) {
for ( int i = 0 ; i < dataColumnsListWidget - > count ( ) ; i + + ) {
if ( newItems . contains ( dataColumnsListWidget - > item ( i ) - > text ( ) ) & & ( ! dataColumnsListWidget - > item ( i ) - > text ( ) . isEmpty ( ) ) ) {
dataColumnsListWidget - > item ( i ) - > setCheckState ( Qt : : Checked ) ;
} else {
dataColumnsListWidget - > item ( i ) - > setCheckState ( Qt : : Unchecked ) ;
}
}
}
}
2019-01-20 17:49:29 +08:00
void JKQTBasePlotter : : getDataColumnsByUserItemChanged ( QListWidgetItem * /*widgetitem*/ ) {
2015-07-11 18:56:02 +08:00
if ( ! dataColumnsListWidget ) return ;
QStringList data ;
for ( int i = 0 ; i < dataColumnsListWidget - > count ( ) ; i + + ) {
if ( dataColumnsListWidget - > item ( i ) - > checkState ( ) = = Qt : : Checked ) data . append ( dataColumnsListWidget - > item ( i ) - > text ( ) ) ;
}
data . sort ( ) ;
QMapIterator < QString , QStringList > it ( getDataColumnsByUserSaved ) ;
QString item = " " ;
while ( it . hasNext ( ) ) {
it . next ( ) ;
QStringList ld = it . value ( ) ;
ld . sort ( ) ;
if ( data = = ld ) {
item = it . key ( ) ;
}
}
disconnect ( dataColumnsCombobox , SIGNAL ( currentIndexChanged ( QString ) ) , this , SLOT ( getDataColumnsByUserComboBoxSelected ( QString ) ) ) ;
dataColumnsCombobox - > setCurrentIndex ( dataColumnsCombobox - > findText ( item ) ) ;
connect ( dataColumnsCombobox , SIGNAL ( currentIndexChanged ( QString ) ) , this , SLOT ( getDataColumnsByUserComboBoxSelected ( QString ) ) ) ;
}
2019-01-20 17:49:29 +08:00
void JKQTBasePlotter : : showPlotData ( ) {
2018-11-18 18:59:30 +08:00
QDialog * dlg = new QDialog ( nullptr , Qt : : Dialog | Qt : : WindowCloseButtonHint | Qt : : WindowMinMaxButtonsHint ) ;
2015-07-11 18:56:02 +08:00
dlg - > setWindowTitle ( tr ( " Plot data table " ) ) ;
dlg - > setSizeGripEnabled ( true ) ;
QVBoxLayout * layout = new QVBoxLayout ( ) ;
dlg - > setLayout ( layout ) ;
QToolBar * tb = new QToolBar ( " toolbar " , dlg ) ;
2019-01-20 23:15:10 +08:00
QAction * actClose = new QAction ( QIcon ( " :/JKQTPlotter/jkqtp_exit.png " ) , tr ( " &Close Window " ) , dlg ) ;
2015-07-11 18:56:02 +08:00
connect ( actClose , SIGNAL ( triggered ( ) ) , dlg , SLOT ( accept ( ) ) ) ;
tb - > addAction ( actClose ) ;
tb - > addSeparator ( ) ;
tb - > addAction ( actSaveData ) ;
tb - > addAction ( actCopyData ) ;
tb - > addAction ( actCopyMatlab ) ;
layout - > addWidget ( tb ) ;
JKQTPEnhancedTableView * tv = new JKQTPEnhancedTableView ( dlg ) ;
layout - > addWidget ( tv ) ;
2022-07-19 05:33:20 +08:00
# ifndef JKQTPLOTTER_COMPILE_WITHOUT_PRINTSUPPORT
2019-01-26 03:16:04 +08:00
tb - > addAction ( tv - > getActionPrint ( ) ) ;
2022-07-19 05:33:20 +08:00
# endif
2015-07-11 18:56:02 +08:00
2019-01-20 17:49:29 +08:00
JKQTPDatastoreModel * model = new JKQTPDatastoreModel ( getDatastore ( ) , this ) ;
2015-07-11 18:56:02 +08:00
tv - > setModel ( model ) ;
tv - > resizeColumnsToContents ( ) ;
tv - > resizeRowsToContents ( ) ;
dlg - > exec ( ) ;
delete dlg ;
}
2019-01-26 03:16:04 +08:00
void JKQTBasePlotter : : setEmittingSignalsEnabled ( bool enabled )
2015-07-11 18:56:02 +08:00
{
emitSignals = enabled ;
2023-03-23 20:55:18 +08:00
for ( auto ax : getAxes ( true ) ) {
ax - > setDoUpdateScaling ( enabled ) ;
}
2015-07-11 18:56:02 +08:00
}
2019-02-08 00:24:46 +08:00
QHash < JKQTBasePlotter : : textSizeKey , JKQTBasePlotter : : textSizeData > JKQTBasePlotter : : s_TextSizeDataCache = QHash < JKQTBasePlotter : : textSizeKey , JKQTBasePlotter : : textSizeData > ( ) ;
2015-07-11 18:56:02 +08:00
2019-06-21 21:46:53 +08:00
JKQTBasePlotter : : textSizeKey : : textSizeKey ( const QFont & f , const QString & text , QPaintDevice * pd ) :
text ( ) , f ( ) , ldpiX ( 0 ) , ldpiY ( 0 ) , pdpiX ( 0 ) , pdpiY ( 0 )
2015-07-11 18:56:02 +08:00
{
this - > text = text ;
this - > f = f ;
if ( pd ) {
ldpiX = pd - > logicalDpiX ( ) ;
ldpiY = pd - > logicalDpiY ( ) ;
pdpiX = pd - > physicalDpiX ( ) ;
pdpiY = pd - > physicalDpiY ( ) ;
} else {
ldpiX = 0 ;
ldpiY = 0 ;
pdpiX = 0 ;
pdpiY = 0 ;
}
}
2019-06-21 21:46:53 +08:00
JKQTBasePlotter : : textSizeKey : : textSizeKey ( const QString & fontName , double fontSize , const QString & text , QPaintDevice * pd ) :
text ( ) , f ( ) , ldpiX ( 0 ) , ldpiY ( 0 ) , pdpiX ( 0 ) , pdpiY ( 0 )
2015-07-11 18:56:02 +08:00
{
QFont f ;
2022-06-03 03:02:23 +08:00
f . setFamily ( JKQTMathTextFontSpecifier : : fromFontSpec ( fontName ) . fontName ( ) ) ;
2015-07-11 18:56:02 +08:00
f . setPointSizeF ( fontSize ) ;
this - > text = text ;
this - > f = f ;
if ( pd ) {
ldpiX = pd - > logicalDpiX ( ) ;
ldpiY = pd - > logicalDpiY ( ) ;
pdpiX = pd - > physicalDpiX ( ) ;
pdpiY = pd - > physicalDpiY ( ) ;
} else {
ldpiX = 0 ;
ldpiY = 0 ;
pdpiX = 0 ;
pdpiY = 0 ;
}
}
2019-01-20 17:49:29 +08:00
bool JKQTBasePlotter : : textSizeKey : : operator = = ( const JKQTBasePlotter : : textSizeKey & other ) const
2015-07-11 18:56:02 +08:00
{
return ldpiX = = other . ldpiX & & ldpiY = = other . ldpiY & & text = = other . text & & f = = other . f ;
}
2019-06-21 21:46:53 +08:00
JKQTBasePlotter : : textSizeData : : textSizeData ( ) :
ascent ( 0 ) , descent ( 0 ) , width ( 0 ) , strikeoutPos ( 0 )
2015-07-11 18:56:02 +08:00
{
2019-06-21 21:46:53 +08:00
2015-07-11 18:56:02 +08:00
}
2019-01-26 03:16:04 +08:00
QPaintDevice * JKQTPPaintDeviceAdapter : : createPaintdeviceMM ( const QString & filename , double widthMM , double heightMM ) const
2015-07-11 18:56:02 +08:00
{
2022-04-22 19:27:31 +08:00
# if QT_VERSION>=QT_VERSION_CHECK(6,0,0)
const qreal dpix = qGuiApp - > primaryScreen ( ) - > logicalDotsPerInchX ( ) ;
const qreal dpiy = qGuiApp - > primaryScreen ( ) - > logicalDotsPerInchY ( ) ;
# else
const qreal dpix = QApplication : : desktop ( ) - > logicalDpiX ( ) ;
const qreal dpiy = QApplication : : desktop ( ) - > logicalDpiY ( ) ;
# endif
return createPaintdevice ( filename , jkqtp_roundTo < int > ( widthMM / 25.4 * dpix ) , jkqtp_roundTo < int > ( heightMM / 25.4 * dpiy ) ) ;
2015-07-11 18:56:02 +08:00
}
2019-01-09 04:00:25 +08:00
2019-01-26 19:28:44 +08:00
JKQTPSaveDataAdapter : : ~ JKQTPSaveDataAdapter ( ) = default ;
2019-02-08 00:24:46 +08:00
JKQTBasePlotter : : JKQTPPen : : JKQTPPen ( ) :
m_color ( QColor ( " red " ) ) ,
m_fillColor ( QColor ( " red " ) . lighter ( ) ) ,
2019-04-22 19:27:50 +08:00
m_symbolFillColor ( QColor ( " red " ) . lighter ( ) ) ,
2019-02-08 00:24:46 +08:00
m_errorColor ( m_color . darker ( ) ) ,
m_errorFillColor ( m_color . lighter ( ) ) ,
m_width ( 2 ) ,
m_errorWidth ( 2 ) ,
m_symbolLineWidth ( 1 ) ,
m_style ( Qt : : SolidLine ) ,
m_symbolSize ( 12 ) ,
m_fillStyle ( Qt : : SolidPattern ) ,
m_errorFillStyle ( Qt : : SolidPattern ) ,
m_symbol ( JKQTPCross )
{
}
void JKQTBasePlotter : : JKQTPPen : : setSymbolSize ( double w )
{
m_symbolSize = w ;
}
void JKQTBasePlotter : : JKQTPPen : : setSymbolLineWidthF ( double w )
{
m_symbolLineWidth = w ;
}
void JKQTBasePlotter : : JKQTPPen : : setWidthF ( double w ) {
m_width = w ;
}
void JKQTBasePlotter : : JKQTPPen : : setWidth ( double w ) {
m_width = w ;
}
2019-05-06 01:31:20 +08:00
void JKQTBasePlotter : : JKQTPPen : : setErrorLineWidth ( double w )
2019-02-08 00:24:46 +08:00
{
m_errorWidth = w ;
}
double JKQTBasePlotter : : JKQTPPen : : width ( ) const {
return m_width ;
}
double JKQTBasePlotter : : JKQTPPen : : widthF ( ) const {
return m_width ;
}
double JKQTBasePlotter : : JKQTPPen : : errorWidthF ( ) const {
return m_errorWidth ;
}
double JKQTBasePlotter : : JKQTPPen : : symbolLineWidthF ( ) const
{
return m_symbolLineWidth ;
}
double JKQTBasePlotter : : JKQTPPen : : symbolSize ( ) const
{
return m_symbolSize ;
}
QColor JKQTBasePlotter : : JKQTPPen : : color ( ) const {
return m_color ;
}
2019-04-22 19:27:50 +08:00
QColor JKQTBasePlotter : : JKQTPPen : : symbolFillColor ( ) const {
return m_symbolFillColor ;
}
2019-02-08 00:24:46 +08:00
QColor JKQTBasePlotter : : JKQTPPen : : errorColor ( ) const {
return m_errorColor ;
}
void JKQTBasePlotter : : JKQTPPen : : setColor ( const QColor & col ) {
m_color = col ;
}
Qt : : PenStyle JKQTBasePlotter : : JKQTPPen : : style ( ) const {
return m_style ;
}
Qt : : PenStyle JKQTBasePlotter : : JKQTPPen : : errorStyle ( ) const {
return Qt : : SolidLine ;
}
void JKQTBasePlotter : : JKQTPPen : : setStyle ( Qt : : PenStyle s ) {
m_style = s ;
}
QColor JKQTBasePlotter : : JKQTPPen : : fillColor ( ) const {
return m_fillColor ;
}
QColor JKQTBasePlotter : : JKQTPPen : : errorFillColor ( ) const {
return m_errorFillColor ;
}
void JKQTBasePlotter : : JKQTPPen : : setFillColor ( const QColor & col ) {
m_fillColor = col ;
}
void JKQTBasePlotter : : JKQTPPen : : setErrorFillColor ( const QColor & col )
{
m_errorFillColor = col ;
}
2019-05-06 01:31:20 +08:00
void JKQTBasePlotter : : JKQTPPen : : setErrorLineColor ( const QColor & col )
2019-02-08 00:24:46 +08:00
{
m_errorColor = col ;
}
void JKQTBasePlotter : : JKQTPPen : : setFillStyle ( Qt : : BrushStyle s ) {
m_fillStyle = s ;
}
void JKQTBasePlotter : : JKQTPPen : : setErrorFillStyle ( Qt : : BrushStyle s ) {
m_errorFillStyle = s ;
}
2019-04-22 19:27:50 +08:00
void JKQTBasePlotter : : JKQTPPen : : setSymbolFillColor ( QColor c ) {
m_symbolFillColor = c ;
}
2019-02-08 00:24:46 +08:00
Qt : : BrushStyle JKQTBasePlotter : : JKQTPPen : : fillStyle ( ) const {
return m_fillStyle ;
}
Qt : : BrushStyle JKQTBasePlotter : : JKQTPPen : : errorFillStyle ( ) const
{
return m_errorFillStyle ;
}
JKQTPGraphSymbols JKQTBasePlotter : : JKQTPPen : : symbol ( ) const
{
return m_symbol ;
}
2019-04-22 19:27:50 +08:00
void JKQTBasePlotter : : JKQTPPen : : setSymbolType ( JKQTPGraphSymbols symbol )
2019-02-08 00:24:46 +08:00
{
m_symbol = symbol ;
}
2023-03-23 20:55:18 +08:00
bool JKQTBasePlotter : : filterPlotElementByXAxis : : operator ( ) ( const JKQTPPlotElement * el ) const { return el - > getXAxisRef ( ) = = ref ; }
bool JKQTBasePlotter : : filterPlotElementByYAxis : : operator ( ) ( const JKQTPPlotElement * el ) const { return el - > getYAxisRef ( ) = = ref ; }