mirror of
https://github.com/jkriege2/JKQtPlotter.git
synced 2024-12-25 10:01:38 +08:00
NEW: added JKQTBasePlotter::grabPixelImage() and JKQTPlotter::grabPixelImage(), which grab the plotter into a QImage
NEW: added option to not display the preview dialog to JKQTBasePlotter::copyPixelImage() and JKQTPlotter::copyPixelImage()
This commit is contained in:
parent
d283f6b294
commit
7030475568
@ -35,6 +35,8 @@ Changes, compared to \ref page_whatsnew_V4_0_0 "v4.0.0" include:
|
|||||||
<li>NEW: improved plotting speed for line-graphs by a compression algorithm (see JKQTPGraphLinesCompressionMixin) that removes overlaying lines (e.g. in JKQTPXYLineGraph)</li>
|
<li>NEW: improved plotting speed for line-graphs by a compression algorithm (see JKQTPGraphLinesCompressionMixin) that removes overlaying lines (e.g. in JKQTPXYLineGraph)</li>
|
||||||
<li>NEW: improved plotting speed for line-graphs by a clipping algorithm (applies to JKQTPXYLineGraph, JKQTPGraphErrorStyleMixin, JKQTPSpecialLineHorizontalGraph, JKQTPSpecialLineVerticalGraph and others)</li>
|
<li>NEW: improved plotting speed for line-graphs by a clipping algorithm (applies to JKQTPXYLineGraph, JKQTPGraphErrorStyleMixin, JKQTPSpecialLineHorizontalGraph, JKQTPSpecialLineVerticalGraph and others)</li>
|
||||||
<li>NEW: improved plotting speed for scatter-graphs by not calling draw functions for symbols outside the plot window (e.g. in JKQTPXYLineGraph)</li>
|
<li>NEW: improved plotting speed for scatter-graphs by not calling draw functions for symbols outside the plot window (e.g. in JKQTPXYLineGraph)</li>
|
||||||
|
<li>NEW: added JKQTBasePlotter::grabPixelImage() and JKQTPlotter::grabPixelImage(), which grab the plotter into a QImage</li>
|
||||||
|
<li>NEW: added option to not display the preview dialog to JKQTBasePlotter::copyPixelImage() and JKQTPlotter::copyPixelImage()</li>
|
||||||
</ul></li>
|
</ul></li>
|
||||||
|
|
||||||
<li>JKQTMathText:<ul>
|
<li>JKQTMathText:<ul>
|
||||||
|
@ -3851,41 +3851,21 @@ void JKQTBasePlotter::saveAsPixelImage(const QString& filename, bool displayPrev
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QImage JKQTBasePlotter::grabPixelImage(QSize size, bool showPreview)
|
||||||
void JKQTBasePlotter::copyPixelImage() {
|
|
||||||
/*qDebug()<<gridPrintingSize.width()<<", "<<gridPrintingSize.height();
|
|
||||||
qDebug()<<widgetWidth<<", "<<widgetHeight;
|
|
||||||
qDebug()<<paintMagnification;*/
|
|
||||||
/* QImage png(gridPrintingSize, QImage::Format_ARGB32);
|
|
||||||
{
|
{
|
||||||
JKQTPEnhancedPainter painter;
|
|
||||||
painter.begin(&png);
|
|
||||||
painter.setRenderHint(JKQTPEnhancedPainter::Antialiasing);
|
|
||||||
painter.setRenderHint(JKQTPEnhancedPainter::TextAntialiasing);
|
|
||||||
painter.setRenderHint(JKQTPEnhancedPainter::SmoothPixmapTransform);
|
|
||||||
painter.setRenderHint(JKQTPEnhancedPainter::HighQualityAntialiasing);
|
|
||||||
//calcPlotScaling(painter);
|
|
||||||
gridPaint(painter, gridPrintingSize);
|
|
||||||
painter.end();
|
|
||||||
}
|
|
||||||
|
|
||||||
QClipboard *clipboard = QApplication::clipboard();
|
|
||||||
qDebug()<<"clipboard before adding content:\n"<<clipboard->mimeData()->formats();
|
|
||||||
clipboard->setImage(png);
|
|
||||||
qDebug()<<"clipboard after adding content:\n"<<clipboard->mimeData()->formats();
|
|
||||||
|
|
||||||
*/
|
|
||||||
|
|
||||||
gridPrintingCalc();
|
gridPrintingCalc();
|
||||||
//std::cout<<gridPrintingSize.width()<<", "<<gridPrintingSize.height()<<std::endl;
|
//std::cout<<gridPrintingSize.width()<<", "<<gridPrintingSize.height()<<std::endl;
|
||||||
printSizeX_Millimeter=gridPrintingSize.width();
|
printSizeX_Millimeter=gridPrintingSize.width();
|
||||||
printSizeY_Millimeter=gridPrintingSize.height();
|
printSizeY_Millimeter=gridPrintingSize.height();
|
||||||
|
if (!showPreview) {
|
||||||
|
printSizeX_Millimeter=widgetWidth;
|
||||||
|
printSizeY_Millimeter=widgetHeight;
|
||||||
|
}
|
||||||
|
if (!showPreview||exportpreview(gridPrintingSize, false)) {
|
||||||
|
|
||||||
if (exportpreview(gridPrintingSize, false)) {
|
|
||||||
QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
|
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();
|
||||||
//if (exportpreview(gridPrintingSize, false)) {
|
QImage png(size, QImage::Format_ARGB32);
|
||||||
QImage png(QSizeF(double(printSizeX_Millimeter), double(printSizeY_Millimeter)).toSize(), QImage::Format_ARGB32);
|
|
||||||
{
|
{
|
||||||
png.fill(Qt::transparent);
|
png.fill(Qt::transparent);
|
||||||
JKQTPEnhancedPainter painter;
|
JKQTPEnhancedPainter painter;
|
||||||
@ -3903,6 +3883,25 @@ void JKQTBasePlotter::copyPixelImage() {
|
|||||||
exportpreviewPaintRequested(painter, QSizeF(printSizeX_Millimeter, printSizeY_Millimeter).toSize());
|
exportpreviewPaintRequested(painter, QSizeF(printSizeX_Millimeter, printSizeY_Millimeter).toSize());
|
||||||
painter.end();
|
painter.end();
|
||||||
}
|
}
|
||||||
|
QApplication::restoreOverrideCursor();
|
||||||
|
|
||||||
|
return png;
|
||||||
|
}
|
||||||
|
return QImage();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void JKQTBasePlotter::copyPixelImage(bool showPreview) {
|
||||||
|
|
||||||
|
gridPrintingCalc();
|
||||||
|
//std::cout<<gridPrintingSize.width()<<", "<<gridPrintingSize.height()<<std::endl;
|
||||||
|
printSizeX_Millimeter=gridPrintingSize.width();
|
||||||
|
printSizeY_Millimeter=gridPrintingSize.height();
|
||||||
|
|
||||||
|
if (!showPreview||exportpreview(gridPrintingSize, false)) {
|
||||||
|
QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
|
||||||
|
|
||||||
QByteArray svgdata;
|
QByteArray svgdata;
|
||||||
{
|
{
|
||||||
|
|
||||||
@ -3926,6 +3925,28 @@ void JKQTBasePlotter::copyPixelImage() {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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
|
||||||
|
|
||||||
|
/*calcPlotScaling(painter);
|
||||||
|
gridPaint(painter, png.rect().size());*/
|
||||||
|
exportpreviewPaintRequested(painter, QSizeF(printSizeX_Millimeter, printSizeY_Millimeter).toSize());
|
||||||
|
painter.end();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -3950,8 +3971,6 @@ void JKQTBasePlotter::copyPixelImage() {
|
|||||||
|
|
||||||
|
|
||||||
QApplication::restoreOverrideCursor();
|
QApplication::restoreOverrideCursor();
|
||||||
|
|
||||||
//}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -1314,8 +1314,10 @@ class JKQTPLOTTER_LIB_EXPORT JKQTBasePlotter: public QObject {
|
|||||||
/** \brief save the current plot as a pixel image image (PNG ...), if filename is empty a file selection dialog is displayed */
|
/** \brief save the current plot as a pixel image image (PNG ...), if filename is empty a file selection dialog is displayed */
|
||||||
void saveAsPixelImage(const QString& filename=QString(""), bool displayPreview=true, const QByteArray &outputFormat=QByteArray());
|
void saveAsPixelImage(const QString& filename=QString(""), bool displayPreview=true, const QByteArray &outputFormat=QByteArray());
|
||||||
|
|
||||||
/** \brief copy the current plot as a pixel image to the clipboard */
|
/** \brief save the current plot as a pixel image into a QImage with the given size */
|
||||||
void copyPixelImage();
|
QImage grabPixelImage(QSize size=QSize(), bool showPreview=false);
|
||||||
|
/** \brief copy the current plot as a pixel+svg image to the clipboard */
|
||||||
|
void copyPixelImage(bool showPreview=true);
|
||||||
|
|
||||||
#ifndef JKQTPLOTTER_COMPILE_WITHOUT_PRINTSUPPORT
|
#ifndef JKQTPLOTTER_COMPILE_WITHOUT_PRINTSUPPORT
|
||||||
/** \brief save the current plot as a SVG file, with the current widget aspect ratio, if filename is empty a file selection dialog is displayed
|
/** \brief save the current plot as a SVG file, with the current widget aspect ratio, if filename is empty a file selection dialog is displayed
|
||||||
|
@ -937,6 +937,14 @@ class JKQTPLOTTER_LIB_EXPORT JKQTPlotter: public QWidget {
|
|||||||
/** \brief \copydoc actMouseLeftAsPanView */
|
/** \brief \copydoc actMouseLeftAsPanView */
|
||||||
const QAction *getActMouseLeftAsPanView() const;
|
const QAction *getActMouseLeftAsPanView() const;
|
||||||
|
|
||||||
|
/** \brief save the current plot as a pixel image into a QImage with the given size */
|
||||||
|
inline QImage grabPixelImage(QSize size=QSize(), bool showPreview=false) {
|
||||||
|
return plotter->grabPixelImage(size,showPreview);
|
||||||
|
}
|
||||||
|
/** \brief copy the current plot as a pixel+svg image to the clipboard */
|
||||||
|
inline void copyPixelImage(bool showPreview=true) {
|
||||||
|
plotter->copyPixelImage(showPreview);
|
||||||
|
}
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
/** \brief set the current plot magnification */
|
/** \brief set the current plot magnification */
|
||||||
@ -1041,6 +1049,8 @@ class JKQTPLOTTER_LIB_EXPORT JKQTPlotter: public QWidget {
|
|||||||
inline void copyDataMatlab() {
|
inline void copyDataMatlab() {
|
||||||
plotter->copyDataMatlab();
|
plotter->copyDataMatlab();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/** \brief this method zooms the graph so that all plotted datapoints are visible.
|
/** \brief this method zooms the graph so that all plotted datapoints are visible.
|
||||||
*
|
*
|
||||||
* \param zoomX if set \c true (default) zooms the x axis
|
* \param zoomX if set \c true (default) zooms the x axis
|
||||||
|
Loading…
Reference in New Issue
Block a user