added JKQTPExampleApplication::addExportStepPlotFunctor() and JKQTPExampleApplication::addExportStepPlot()

This commit is contained in:
jkriege2 2023-08-14 13:50:21 +02:00
parent c2d6df29ef
commit fc969e2bae
2 changed files with 105 additions and 54 deletions

View File

@ -31,7 +31,17 @@ JKQTPExampleApplication::~JKQTPExampleApplication()
void JKQTPExampleApplication::addExportStepFunctor(const std::function<void ()> &f) void JKQTPExampleApplication::addExportStepFunctor(const std::function<void ()> &f)
{ {
functors<<f; functors<<Data(f);
}
void JKQTPExampleApplication::addExportStepPlot(JKQTPlotter *plot)
{
functors<<Data(plot);
}
void JKQTPExampleApplication::addExportStepPlotFunctor(const std::function<JKQTPlotter *()> &fplot)
{
functors<<Data(fplot);
} }
void JKQTPExampleApplication::readCmdLine() { void JKQTPExampleApplication::readCmdLine() {
@ -96,33 +106,9 @@ QRect JKQTPExampleApplication::getBoundsWithoutColor(QImage qImage, const QColor
ofTheKing.setCoords(minX, minY, maxX+1, maxY+1); ofTheKing.setCoords(minX, minY, maxX+1, maxY+1);
return ofTheKing; return ofTheKing;
} }
int JKQTPExampleApplication::exec() void JKQTPExampleApplication::saveWidget(QWidget *w, int iVisible) {
{
readCmdLine();
QList<JKQTPlotter*> 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<JKQTPlotter*>(w);
if (plot) plotterList<<plot;
}
QWidgetList widgets=topLevelWidgets();
std::sort(widgets.begin(), widgets.end(), [](const QWidget* a, const QWidget* b) {
if (a && b) return a->windowTitle().toLower()<b->windowTitle().toLower();
if (a) return true;
if (b) return false;
return a<b;
});
auto saveWidget=[&](QWidget* w, int iVisible) {
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,17 +154,57 @@ int JKQTPExampleApplication::exec()
img.save(screenshotDir.absoluteFilePath(fn)); img.save(screenshotDir.absoluteFilePath(fn));
} }
} }
}
int JKQTPExampleApplication::exec()
{
readCmdLine();
QList<JKQTPlotter*> 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<JKQTPlotter*>(w);
if (plot) plotterList<<plot;
}
QWidgetList widgets=topLevelWidgets();
std::sort(widgets.begin(), widgets.end(), [](const QWidget* a, const QWidget* b) {
if (a && b) return a->windowTitle().toLower()<b->windowTitle().toLower();
if (a) return true;
if (b) return false;
return a<b;
});
if (iterateFunctorSteps) { if (iterateFunctorSteps) {
QVector<std::function<void(void)>> localfunctors=functors; QVector<Data> localfunctors=functors;
if (!iterateFunctorStepsSupressInitial) localfunctors.prepend([](){}); if (!iterateFunctorStepsSupressInitial) localfunctors.prepend(Data([](){}));
int iVisible=0; int iVisible=0;
//std::cout<<localfunctors.size()<<" functors\n"; //std::cout<<localfunctors.size()<<" functors\n";
for (auto& f: localfunctors) { for (auto& f: localfunctors) {
//std::cout<<"iVisible="<<iVisible<<" f="<<std::boolalpha<<static_cast<bool>(f)<<"\n"; //std::cout<<"iVisible="<<iVisible<<" f="<<std::boolalpha<<static_cast<bool>(f)<<"\n";
if (f) f(); QWidgetList widgets_local=widgets;
switch(f.type) {
case Data::FunctorType:
if (f.f) f.f();
break;
case Data::PlotterType:
widgets_local.clear();
if (f.p) widgets_local<<f.p;
break;
case Data::PlotterFunctorType:
widgets_local.clear();
if (f.plotf) widgets_local<<f.plotf();
break;
}
//JKQTPlotter::setGlobalResizeDelay(10); //JKQTPlotter::setGlobalResizeDelay(10);
QElapsedTimer timer; QElapsedTimer timer;
timer.start(); timer.start();
@ -191,8 +217,8 @@ int JKQTPExampleApplication::exec()
QApplication::processEvents(); QApplication::processEvents();
QApplication::processEvents(); QApplication::processEvents();
} }
for (int i=0; i<widgets.size(); i++) { for (int i=0; i<widgets_local.size(); i++) {
QWidget* w=widgets[i]; QWidget* w=widgets_local[i];
if (w->isVisible()) { if (w->isVisible()) {
saveWidget(w, iVisible); saveWidget(w, iVisible);
iVisible++; iVisible++;

View File

@ -14,6 +14,8 @@ public:
virtual ~JKQTPExampleApplication(); virtual ~JKQTPExampleApplication();
void addExportStepFunctor(const std::function<void(void)>& f); void addExportStepFunctor(const std::function<void(void)>& f);
void addExportStepPlot(JKQTPlotter* plot);
void addExportStepPlotFunctor(const std::function<JKQTPlotter*(void)>& fplot);
int exec(); int exec();
public Q_SLOTS: public Q_SLOTS:
void notifyReadyForScreenshot(); void notifyReadyForScreenshot();
@ -29,7 +31,30 @@ protected:
bool iterateFunctorSteps; bool iterateFunctorSteps;
bool iterateFunctorStepsSupressInitial; bool iterateFunctorStepsSupressInitial;
QStringList screenshotBasename; QStringList screenshotBasename;
QVector<std::function<void(void)>> functors; struct Data {
enum Type {
FunctorType,
PlotterType,
PlotterFunctorType
};
Type type;
std::function<void(void)> f;
std::function<JKQTPlotter*(void)> plotf;
JKQTPlotter* p;
inline Data(const std::function<void(void)>& f_):
type(FunctorType), f(f_), p(nullptr), plotf()
{}
inline Data(JKQTPlotter* p_):
type(FunctorType), p(p_), f(), plotf()
{}
inline Data(std::function<JKQTPlotter*(void)> p_):
type(FunctorType), plotf(p_), f(), p(nullptr)
{}
};
QVector<Data> functors;
void readCmdLine(); void readCmdLine();
QRect getBoundsWithoutColor(QImage qImage, const QColor &exclusionColor = Qt::white); QRect getBoundsWithoutColor(QImage qImage, const QColor &exclusionColor = Qt::white);
void saveWidget(QWidget* w, int iVisible);;
}; };