From d82e20fd3346594aa1c18ed20615d750856d5142 Mon Sep 17 00:00:00 2001 From: jkriege2 Date: Mon, 26 Sep 2022 02:07:07 +0200 Subject: [PATCH] added command-line option to tests that allows to modify a graph with a list of functors --- .../jkqtpexampleapplication.cpp | 182 ++++++++++++------ .../libexampletools/jkqtpexampleapplication.h | 6 +- 2 files changed, 123 insertions(+), 65 deletions(-) diff --git a/examples/libexampletools/jkqtpexampleapplication.cpp b/examples/libexampletools/jkqtpexampleapplication.cpp index 3b5779098c..18d47e3dc6 100644 --- a/examples/libexampletools/jkqtpexampleapplication.cpp +++ b/examples/libexampletools/jkqtpexampleapplication.cpp @@ -16,9 +16,12 @@ JKQTPExampleApplication::JKQTPExampleApplication(int &argc, char **argv, bool _w saveScreenshotPlot(false), saveSmallScreenshotPlot(false), scaleDownFromHighDPI(false), + iterateFunctorSteps(false), + iterateFunctorStepsSupressInitial(false), screenshotBasename("screenshot") { screenshotDir=QDir::current(); + //for (int i=0; i &f) +{ + functors< plotterList; - auto checkPlottersResizeDone=[plotterList]() { - if (plotterList.isEmpty()) return true; - for (JKQTPlotter* p: plotterList) { - if (p->isResizeTimerRunning()) return false; - } - return true; - }; - for (QWidget* w: allWidgets()) { - JKQTPlotter* plot=dynamic_cast(w); - if (plot) plotterList< plotterList; + auto checkPlottersResizeDone=[plotterList]() { + if (plotterList.isEmpty()) return true; + for (JKQTPlotter* p: plotterList) { + if (p->isResizeTimerRunning()) return false; } - QWidgetList widgets=topLevelWidgets(); - std::sort(widgets.begin(), widgets.end(), [](const QWidget* a, const QWidget* b) { - if (a && b) return a->windowTitle().toLower()windowTitle().toLower(); - if (a) return true; - if (b) return false; - return a(w); + if (plot) plotterList<windowTitle().toLower()windowTitle().toLower(); + if (a) return true; + if (b) return false; + 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([](){}); + int iVisible=0; + //std::cout<isVisible()) { + saveWidget(w, iVisible); + } + + } + iVisible++; + } + return 0; + } else if (saveScreenshot||saveSmallScreenshot||saveScreenshotPlot||saveSmallScreenshotPlot) { + + //std::cout<<"non-functor-mode\n"; //JKQTPlotter::setGlobalResizeDelay(10); QElapsedTimer timer; timer.start(); @@ -123,53 +220,10 @@ int JKQTPExampleApplication::exec() for (int i=0; iisVisible()) { - JKQTPlotter* plot=dynamic_cast(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)); - } - } + saveWidget(w, iVisible); iVisible++; } + } return 0; } else { diff --git a/examples/libexampletools/jkqtpexampleapplication.h b/examples/libexampletools/jkqtpexampleapplication.h index a9e7a84f80..859e35011e 100644 --- a/examples/libexampletools/jkqtpexampleapplication.h +++ b/examples/libexampletools/jkqtpexampleapplication.h @@ -3,6 +3,7 @@ #include "jkqtplotter/jkqtplotter.h" #include "jkqtpappsettingcontroller.h" #include +#include @@ -12,7 +13,7 @@ public: JKQTPExampleApplication(int &argc, char **argv, bool waitForScreenshotReady=false); virtual ~JKQTPExampleApplication(); - + void addExportStepFunctor(const std::function& f); int exec(); public slots: void notifyReadyForScreenshot(); @@ -25,7 +26,10 @@ protected: bool saveScreenshotPlot; bool saveSmallScreenshotPlot; bool scaleDownFromHighDPI; + bool iterateFunctorSteps; + bool iterateFunctorStepsSupressInitial; QStringList screenshotBasename; + QVector> functors; void readCmdLine(); QRect getBoundsWithoutColor(QImage qImage, const QColor &exclusionColor = Qt::white); };