mirror of
https://github.com/jkriege2/JKQtPlotter.git
synced 2024-12-25 18:11:38 +08:00
added command-line option to tests that allows to modify a graph with a list of functors
This commit is contained in:
parent
465583b48d
commit
d82e20fd33
@ -16,9 +16,12 @@ JKQTPExampleApplication::JKQTPExampleApplication(int &argc, char **argv, bool _w
|
|||||||
saveScreenshotPlot(false),
|
saveScreenshotPlot(false),
|
||||||
saveSmallScreenshotPlot(false),
|
saveSmallScreenshotPlot(false),
|
||||||
scaleDownFromHighDPI(false),
|
scaleDownFromHighDPI(false),
|
||||||
|
iterateFunctorSteps(false),
|
||||||
|
iterateFunctorStepsSupressInitial(false),
|
||||||
screenshotBasename("screenshot")
|
screenshotBasename("screenshot")
|
||||||
{
|
{
|
||||||
screenshotDir=QDir::current();
|
screenshotDir=QDir::current();
|
||||||
|
//for (int i=0; i<argc; i++) std::cout<<" argv["<<i<<"]="<<argv[i]<<"\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
JKQTPExampleApplication::~JKQTPExampleApplication()
|
JKQTPExampleApplication::~JKQTPExampleApplication()
|
||||||
@ -26,6 +29,11 @@ JKQTPExampleApplication::~JKQTPExampleApplication()
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void JKQTPExampleApplication::addExportStepFunctor(const std::function<void ()> &f)
|
||||||
|
{
|
||||||
|
functors<<f;
|
||||||
|
}
|
||||||
|
|
||||||
void JKQTPExampleApplication::readCmdLine() {
|
void JKQTPExampleApplication::readCmdLine() {
|
||||||
QCommandLineParser parser;
|
QCommandLineParser parser;
|
||||||
parser.setApplicationDescription(QString("JKQTPlotter example program '%1'").arg(applicationName()));
|
parser.setApplicationDescription(QString("JKQTPlotter example program '%1'").arg(applicationName()));
|
||||||
@ -47,6 +55,10 @@ void JKQTPExampleApplication::readCmdLine() {
|
|||||||
parser.addOption(scaleDownFromHighDPIOption);
|
parser.addOption(scaleDownFromHighDPIOption);
|
||||||
QCommandLineOption disablehighdpiOption(QStringList()<<"disablehighdpi", "idisable high-dpi support.");
|
QCommandLineOption disablehighdpiOption(QStringList()<<"disablehighdpi", "idisable high-dpi support.");
|
||||||
parser.addOption(disablehighdpiOption);
|
parser.addOption(disablehighdpiOption);
|
||||||
|
QCommandLineOption iterateFunctorStepsOption(QStringList()<<"iteratefunctorsteps", "iterate over steps defined by addExportStepFunctor() in code.");
|
||||||
|
parser.addOption(iterateFunctorStepsOption);
|
||||||
|
QCommandLineOption iterateFunctorStepsSupressInitialOption(QStringList()<<"iteratefunctorsteps_suppressinitial", "iterate over steps defined by addExportStepFunctor() in code.");
|
||||||
|
parser.addOption(iterateFunctorStepsSupressInitialOption);
|
||||||
|
|
||||||
parser.process(*this);
|
parser.process(*this);
|
||||||
|
|
||||||
@ -57,6 +69,8 @@ void JKQTPExampleApplication::readCmdLine() {
|
|||||||
saveScreenshotPlot = parser.isSet(screenshotPlotOption);
|
saveScreenshotPlot = parser.isSet(screenshotPlotOption);
|
||||||
saveSmallScreenshotPlot = parser.isSet(smallscreenshotPlotOption);
|
saveSmallScreenshotPlot = parser.isSet(smallscreenshotPlotOption);
|
||||||
scaleDownFromHighDPI = parser.isSet(scaleDownFromHighDPIOption);
|
scaleDownFromHighDPI = parser.isSet(scaleDownFromHighDPIOption);
|
||||||
|
iterateFunctorSteps = parser.isSet(iterateFunctorStepsOption);
|
||||||
|
iterateFunctorStepsSupressInitial = parser.isSet(iterateFunctorStepsSupressInitialOption);
|
||||||
}
|
}
|
||||||
|
|
||||||
QRect JKQTPExampleApplication::getBoundsWithoutColor(QImage qImage, const QColor &exclusionColor)
|
QRect JKQTPExampleApplication::getBoundsWithoutColor(QImage qImage, const QColor &exclusionColor)
|
||||||
@ -87,7 +101,7 @@ QRect JKQTPExampleApplication::getBoundsWithoutColor(QImage qImage, const QColor
|
|||||||
int JKQTPExampleApplication::exec()
|
int JKQTPExampleApplication::exec()
|
||||||
{
|
{
|
||||||
readCmdLine();
|
readCmdLine();
|
||||||
if (saveScreenshot||saveSmallScreenshot||saveScreenshotPlot||saveSmallScreenshotPlot) {
|
|
||||||
QList<JKQTPlotter*> plotterList;
|
QList<JKQTPlotter*> plotterList;
|
||||||
auto checkPlottersResizeDone=[plotterList]() {
|
auto checkPlottersResizeDone=[plotterList]() {
|
||||||
if (plotterList.isEmpty()) return true;
|
if (plotterList.isEmpty()) return true;
|
||||||
@ -107,22 +121,8 @@ int JKQTPExampleApplication::exec()
|
|||||||
if (b) return false;
|
if (b) return false;
|
||||||
return a<b;
|
return a<b;
|
||||||
});
|
});
|
||||||
//JKQTPlotter::setGlobalResizeDelay(10);
|
|
||||||
QElapsedTimer timer;
|
auto saveWidget=[&](QWidget* w, int iVisible) {
|
||||||
timer.start();
|
|
||||||
while(timer.elapsed()<JKQTPlotter::getGlobalResizeDelay()*3/2 || !readyForScreenshot || !checkPlottersResizeDone()) {
|
|
||||||
QApplication::processEvents();
|
|
||||||
QApplication::processEvents();
|
|
||||||
}
|
|
||||||
timer.start();
|
|
||||||
while(timer.elapsed()<50) {
|
|
||||||
QApplication::processEvents();
|
|
||||||
QApplication::processEvents();
|
|
||||||
}
|
|
||||||
int iVisible=0;
|
|
||||||
for (int i=0; i<widgets.size(); i++) {
|
|
||||||
QWidget* w=widgets[i];
|
|
||||||
if (w->isVisible()) {
|
|
||||||
JKQTPlotter* plot=dynamic_cast<JKQTPlotter*>(w);
|
JKQTPlotter* plot=dynamic_cast<JKQTPlotter*>(w);
|
||||||
QString bn=screenshotBasename.value(iVisible, screenshotBasename.value(0));
|
QString bn=screenshotBasename.value(iVisible, screenshotBasename.value(0));
|
||||||
if (iVisible>0 && screenshotBasename.value(iVisible, "")=="") {
|
if (iVisible>0 && screenshotBasename.value(iVisible, "")=="") {
|
||||||
@ -168,8 +168,62 @@ int JKQTPExampleApplication::exec()
|
|||||||
img.save(screenshotDir.absoluteFilePath(fn));
|
img.save(screenshotDir.absoluteFilePath(fn));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
if (iterateFunctorSteps) {
|
||||||
|
QVector<std::function<void(void)>> localfunctors=functors;
|
||||||
|
if (!iterateFunctorStepsSupressInitial) localfunctors.prepend([](){});
|
||||||
|
int iVisible=0;
|
||||||
|
//std::cout<<localfunctors.size()<<" functors\n";
|
||||||
|
for (auto& f: localfunctors) {
|
||||||
|
//std::cout<<"iVisible="<<iVisible<<" f="<<std::boolalpha<<static_cast<bool>(f)<<"\n";
|
||||||
|
if (f) f();
|
||||||
|
//JKQTPlotter::setGlobalResizeDelay(10);
|
||||||
|
QElapsedTimer timer;
|
||||||
|
timer.start();
|
||||||
|
while(timer.elapsed()<JKQTPlotter::getGlobalResizeDelay()*3/2 || !readyForScreenshot || !checkPlottersResizeDone()) {
|
||||||
|
QApplication::processEvents();
|
||||||
|
QApplication::processEvents();
|
||||||
|
}
|
||||||
|
timer.start();
|
||||||
|
while(timer.elapsed()<50) {
|
||||||
|
QApplication::processEvents();
|
||||||
|
QApplication::processEvents();
|
||||||
|
}
|
||||||
|
for (int i=0; i<widgets.size(); i++) {
|
||||||
|
QWidget* w=widgets[i];
|
||||||
|
if (w->isVisible()) {
|
||||||
|
saveWidget(w, iVisible);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
iVisible++;
|
iVisible++;
|
||||||
}
|
}
|
||||||
|
return 0;
|
||||||
|
} else if (saveScreenshot||saveSmallScreenshot||saveScreenshotPlot||saveSmallScreenshotPlot) {
|
||||||
|
|
||||||
|
//std::cout<<"non-functor-mode\n";
|
||||||
|
//JKQTPlotter::setGlobalResizeDelay(10);
|
||||||
|
QElapsedTimer timer;
|
||||||
|
timer.start();
|
||||||
|
while(timer.elapsed()<JKQTPlotter::getGlobalResizeDelay()*3/2 || !readyForScreenshot || !checkPlottersResizeDone()) {
|
||||||
|
QApplication::processEvents();
|
||||||
|
QApplication::processEvents();
|
||||||
|
}
|
||||||
|
timer.start();
|
||||||
|
while(timer.elapsed()<50) {
|
||||||
|
QApplication::processEvents();
|
||||||
|
QApplication::processEvents();
|
||||||
|
}
|
||||||
|
int iVisible=0;
|
||||||
|
for (int i=0; i<widgets.size(); i++) {
|
||||||
|
QWidget* w=widgets[i];
|
||||||
|
if (w->isVisible()) {
|
||||||
|
saveWidget(w, iVisible);
|
||||||
|
iVisible++;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
} else {
|
} else {
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
#include "jkqtplotter/jkqtplotter.h"
|
#include "jkqtplotter/jkqtplotter.h"
|
||||||
#include "jkqtpappsettingcontroller.h"
|
#include "jkqtpappsettingcontroller.h"
|
||||||
#include <QDir>
|
#include <QDir>
|
||||||
|
#include <functional>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -12,7 +13,7 @@ public:
|
|||||||
JKQTPExampleApplication(int &argc, char **argv, bool waitForScreenshotReady=false);
|
JKQTPExampleApplication(int &argc, char **argv, bool waitForScreenshotReady=false);
|
||||||
|
|
||||||
virtual ~JKQTPExampleApplication();
|
virtual ~JKQTPExampleApplication();
|
||||||
|
void addExportStepFunctor(const std::function<void(void)>& f);
|
||||||
int exec();
|
int exec();
|
||||||
public slots:
|
public slots:
|
||||||
void notifyReadyForScreenshot();
|
void notifyReadyForScreenshot();
|
||||||
@ -25,7 +26,10 @@ protected:
|
|||||||
bool saveScreenshotPlot;
|
bool saveScreenshotPlot;
|
||||||
bool saveSmallScreenshotPlot;
|
bool saveSmallScreenshotPlot;
|
||||||
bool scaleDownFromHighDPI;
|
bool scaleDownFromHighDPI;
|
||||||
|
bool iterateFunctorSteps;
|
||||||
|
bool iterateFunctorStepsSupressInitial;
|
||||||
QStringList screenshotBasename;
|
QStringList screenshotBasename;
|
||||||
|
QVector<std::function<void(void)>> functors;
|
||||||
void readCmdLine();
|
void readCmdLine();
|
||||||
QRect getBoundsWithoutColor(QImage qImage, const QColor &exclusionColor = Qt::white);
|
QRect getBoundsWithoutColor(QImage qImage, const QColor &exclusionColor = Qt::white);
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user