mirror of
https://github.com/jkriege2/JKQtPlotter.git
synced 2024-12-25 10:01: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),
|
||||
saveSmallScreenshotPlot(false),
|
||||
scaleDownFromHighDPI(false),
|
||||
iterateFunctorSteps(false),
|
||||
iterateFunctorStepsSupressInitial(false),
|
||||
screenshotBasename("screenshot")
|
||||
{
|
||||
screenshotDir=QDir::current();
|
||||
//for (int i=0; i<argc; i++) std::cout<<" argv["<<i<<"]="<<argv[i]<<"\n";
|
||||
}
|
||||
|
||||
JKQTPExampleApplication::~JKQTPExampleApplication()
|
||||
@ -26,6 +29,11 @@ JKQTPExampleApplication::~JKQTPExampleApplication()
|
||||
|
||||
}
|
||||
|
||||
void JKQTPExampleApplication::addExportStepFunctor(const std::function<void ()> &f)
|
||||
{
|
||||
functors<<f;
|
||||
}
|
||||
|
||||
void JKQTPExampleApplication::readCmdLine() {
|
||||
QCommandLineParser parser;
|
||||
parser.setApplicationDescription(QString("JKQTPlotter example program '%1'").arg(applicationName()));
|
||||
@ -47,6 +55,10 @@ void JKQTPExampleApplication::readCmdLine() {
|
||||
parser.addOption(scaleDownFromHighDPIOption);
|
||||
QCommandLineOption disablehighdpiOption(QStringList()<<"disablehighdpi", "idisable high-dpi support.");
|
||||
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);
|
||||
|
||||
@ -57,6 +69,8 @@ void JKQTPExampleApplication::readCmdLine() {
|
||||
saveScreenshotPlot = parser.isSet(screenshotPlotOption);
|
||||
saveSmallScreenshotPlot = parser.isSet(smallscreenshotPlotOption);
|
||||
scaleDownFromHighDPI = parser.isSet(scaleDownFromHighDPIOption);
|
||||
iterateFunctorSteps = parser.isSet(iterateFunctorStepsOption);
|
||||
iterateFunctorStepsSupressInitial = parser.isSet(iterateFunctorStepsSupressInitialOption);
|
||||
}
|
||||
|
||||
QRect JKQTPExampleApplication::getBoundsWithoutColor(QImage qImage, const QColor &exclusionColor)
|
||||
@ -87,7 +101,7 @@ QRect JKQTPExampleApplication::getBoundsWithoutColor(QImage qImage, const QColor
|
||||
int JKQTPExampleApplication::exec()
|
||||
{
|
||||
readCmdLine();
|
||||
if (saveScreenshot||saveSmallScreenshot||saveScreenshotPlot||saveSmallScreenshotPlot) {
|
||||
|
||||
QList<JKQTPlotter*> plotterList;
|
||||
auto checkPlottersResizeDone=[plotterList]() {
|
||||
if (plotterList.isEmpty()) return true;
|
||||
@ -107,22 +121,8 @@ int JKQTPExampleApplication::exec()
|
||||
if (b) return false;
|
||||
return a<b;
|
||||
});
|
||||
//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()) {
|
||||
|
||||
auto saveWidget=[&](QWidget* w, int iVisible) {
|
||||
JKQTPlotter* plot=dynamic_cast<JKQTPlotter*>(w);
|
||||
QString bn=screenshotBasename.value(iVisible, screenshotBasename.value(0));
|
||||
if (iVisible>0 && screenshotBasename.value(iVisible, "")=="") {
|
||||
@ -168,8 +168,62 @@ int JKQTPExampleApplication::exec()
|
||||
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++;
|
||||
}
|
||||
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;
|
||||
} else {
|
||||
|
@ -3,6 +3,7 @@
|
||||
#include "jkqtplotter/jkqtplotter.h"
|
||||
#include "jkqtpappsettingcontroller.h"
|
||||
#include <QDir>
|
||||
#include <functional>
|
||||
|
||||
|
||||
|
||||
@ -12,7 +13,7 @@ public:
|
||||
JKQTPExampleApplication(int &argc, char **argv, bool waitForScreenshotReady=false);
|
||||
|
||||
virtual ~JKQTPExampleApplication();
|
||||
|
||||
void addExportStepFunctor(const std::function<void(void)>& 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<std::function<void(void)>> functors;
|
||||
void readCmdLine();
|
||||
QRect getBoundsWithoutColor(QImage qImage, const QColor &exclusionColor = Qt::white);
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user