From fc969e2bae3a40d950e5cd6bfd83f4f1ff85fec9 Mon Sep 17 00:00:00 2001 From: jkriege2 Date: Mon, 14 Aug 2023 13:50:21 +0200 Subject: [PATCH] added JKQTPExampleApplication::addExportStepPlotFunctor() and JKQTPExampleApplication::addExportStepPlot() --- .../jkqtpexampleapplication.cpp | 132 +++++++++++------- .../libexampletools/jkqtpexampleapplication.h | 27 +++- 2 files changed, 105 insertions(+), 54 deletions(-) diff --git a/examples/libexampletools/jkqtpexampleapplication.cpp b/examples/libexampletools/jkqtpexampleapplication.cpp index 89fb2767c4..6a596de155 100644 --- a/examples/libexampletools/jkqtpexampleapplication.cpp +++ b/examples/libexampletools/jkqtpexampleapplication.cpp @@ -31,7 +31,17 @@ JKQTPExampleApplication::~JKQTPExampleApplication() void JKQTPExampleApplication::addExportStepFunctor(const std::function &f) { - functors< &fplot) +{ + functors<(w); + QString bn=screenshotBasename.value(iVisible, screenshotBasename.value(0)); + if (iVisible>0 && screenshotBasename.value(iVisible, "")=="") { + bn+=QString("_win%1").arg(iVisible, 2, 10, QLatin1Char('0')); + } + if (w) { + QPixmap pix_win=w->grab(); + /*QPixmap pix; + if (screenshotIncludeWindowTitle) { + pix=w->screen()->grabWindow(0, w->frameGeometry().x(), w->frameGeometry().y(), w->frameGeometry().width(), w->frameGeometry().height()); + } else { + pix=pix_win; + }*/ + if (saveScreenshot || (saveScreenshotPlot&&!plot)) { + if (scaleDownFromHighDPI && pix_win.devicePixelRatio()>1.0) { + pix_win.scaled((QSizeF(pix_win.size())/pix_win.devicePixelRatio()).toSize()).save(screenshotDir.absoluteFilePath(bn+".png")); + } else { + pix_win.save(screenshotDir.absoluteFilePath(bn+".png")); + } + } + if (saveSmallScreenshot || (saveSmallScreenshotPlot&&!plot)) { + QPixmap img=pix_win.scaledToWidth(150, Qt::SmoothTransformation); + img.save(screenshotDir.absoluteFilePath(bn+"_small.png")); + } + } + if (plot) { + QString bnp=bn+"_plot"; + QImage gr=plot->grabPixelImage(); + + if (saveScreenshotPlot) { + QString fn=bn+".png"; + if (saveScreenshot) fn=bnp+".png"; + if (scaleDownFromHighDPI && gr.devicePixelRatio()>1.0) { + gr.scaled((QSizeF(gr.size())/gr.devicePixelRatio()).toSize()).save(screenshotDir.absoluteFilePath(fn)); + } else { + gr.save(screenshotDir.absoluteFilePath(fn)); + } + } + if (saveSmallScreenshotPlot) { + QString fn=bn+"_small.png"; + if (saveSmallScreenshot) fn=bnp+"_small.png"; + QImage img=gr.scaledToWidth(150, Qt::SmoothTransformation); + img.save(screenshotDir.absoluteFilePath(fn)); + } + } +} int JKQTPExampleApplication::exec() { @@ -122,63 +180,31 @@ int JKQTPExampleApplication::exec() return a(w); - QString bn=screenshotBasename.value(iVisible, screenshotBasename.value(0)); - if (iVisible>0 && screenshotBasename.value(iVisible, "")=="") { - bn+=QString("_win%1").arg(iVisible, 2, 10, QLatin1Char('0')); - } - if (w) { - QPixmap pix_win=w->grab(); - /*QPixmap pix; - if (screenshotIncludeWindowTitle) { - pix=w->screen()->grabWindow(0, w->frameGeometry().x(), w->frameGeometry().y(), w->frameGeometry().width(), w->frameGeometry().height()); - } else { - pix=pix_win; - }*/ - if (saveScreenshot || (saveScreenshotPlot&&!plot)) { - if (scaleDownFromHighDPI && pix_win.devicePixelRatio()>1.0) { - pix_win.scaled((QSizeF(pix_win.size())/pix_win.devicePixelRatio()).toSize()).save(screenshotDir.absoluteFilePath(bn+".png")); - } else { - pix_win.save(screenshotDir.absoluteFilePath(bn+".png")); - } - } - if (saveSmallScreenshot || (saveSmallScreenshotPlot&&!plot)) { - QPixmap img=pix_win.scaledToWidth(150, Qt::SmoothTransformation); - img.save(screenshotDir.absoluteFilePath(bn+"_small.png")); - } - } - if (plot) { - QString bnp=bn+"_plot"; - QImage gr=plot->grabPixelImage(); - if (saveScreenshotPlot) { - QString fn=bn+".png"; - if (saveScreenshot) fn=bnp+".png"; - if (scaleDownFromHighDPI && gr.devicePixelRatio()>1.0) { - gr.scaled((QSizeF(gr.size())/gr.devicePixelRatio()).toSize()).save(screenshotDir.absoluteFilePath(fn)); - } else { - gr.save(screenshotDir.absoluteFilePath(fn)); - } - } - if (saveSmallScreenshotPlot) { - QString fn=bn+"_small.png"; - if (saveSmallScreenshot) fn=bnp+"_small.png"; - QImage img=gr.scaledToWidth(150, Qt::SmoothTransformation); - img.save(screenshotDir.absoluteFilePath(fn)); - } - } - }; if (iterateFunctorSteps) { - QVector> localfunctors=functors; - if (!iterateFunctorStepsSupressInitial) localfunctors.prepend([](){}); + QVector localfunctors=functors; + if (!iterateFunctorStepsSupressInitial) localfunctors.prepend(Data([](){})); int iVisible=0; //std::cout<isVisible()) { saveWidget(w, iVisible); iVisible++; diff --git a/examples/libexampletools/jkqtpexampleapplication.h b/examples/libexampletools/jkqtpexampleapplication.h index 8d4a5ffdfe..8e0a52f5da 100644 --- a/examples/libexampletools/jkqtpexampleapplication.h +++ b/examples/libexampletools/jkqtpexampleapplication.h @@ -14,6 +14,8 @@ public: virtual ~JKQTPExampleApplication(); void addExportStepFunctor(const std::function& f); + void addExportStepPlot(JKQTPlotter* plot); + void addExportStepPlotFunctor(const std::function& fplot); int exec(); public Q_SLOTS: void notifyReadyForScreenshot(); @@ -29,7 +31,30 @@ protected: bool iterateFunctorSteps; bool iterateFunctorStepsSupressInitial; QStringList screenshotBasename; - QVector> functors; + struct Data { + enum Type { + FunctorType, + PlotterType, + PlotterFunctorType + }; + Type type; + std::function f; + std::function plotf; + JKQTPlotter* p; + inline Data(const std::function& f_): + type(FunctorType), f(f_), p(nullptr), plotf() + {} + inline Data(JKQTPlotter* p_): + type(FunctorType), p(p_), f(), plotf() + {} + inline Data(std::function p_): + type(FunctorType), plotf(p_), f(), p(nullptr) + {} + }; + + QVector functors; void readCmdLine(); QRect getBoundsWithoutColor(QImage qImage, const QColor &exclusionColor = Qt::white); + + void saveWidget(QWidget* w, int iVisible);; };