mirror of
https://github.com/jkriege2/JKQtPlotter.git
synced 2024-12-24 09:31:40 +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 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: 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>
|
||||
|
||||
<li>JKQTMathText:<ul>
|
||||
|
@ -3851,58 +3851,57 @@ void JKQTBasePlotter::saveAsPixelImage(const QString& filename, bool displayPrev
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
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();
|
||||
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;
|
||||
}
|
||||
if (!showPreview||exportpreview(gridPrintingSize, false)) {
|
||||
|
||||
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();
|
||||
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;
|
||||
}
|
||||
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 (exportpreview(gridPrintingSize, false)) {
|
||||
if (!showPreview||exportpreview(gridPrintingSize, false)) {
|
||||
QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
|
||||
|
||||
//if (exportpreview(gridPrintingSize, false)) {
|
||||
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();
|
||||
}
|
||||
QByteArray svgdata;
|
||||
{
|
||||
|
||||
@ -3926,32 +3925,52 @@ 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();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
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();
|
||||
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();
|
||||
|
||||
|
||||
|
||||
|
||||
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 */
|
||||
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 */
|
||||
void copyPixelImage();
|
||||
/** \brief save the current plot as a pixel image into a QImage with the given size */
|
||||
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
|
||||
/** \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 */
|
||||
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:
|
||||
/** \brief set the current plot magnification */
|
||||
@ -1041,6 +1049,8 @@ class JKQTPLOTTER_LIB_EXPORT JKQTPlotter: public QWidget {
|
||||
inline void copyDataMatlab() {
|
||||
plotter->copyDataMatlab();
|
||||
}
|
||||
|
||||
|
||||
/** \brief this method zooms the graph so that all plotted datapoints are visible.
|
||||
*
|
||||
* \param zoomX if set \c true (default) zooms the x axis
|
||||
|
Loading…
Reference in New Issue
Block a user