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)
{
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() {
@ -98,31 +108,7 @@ QRect JKQTPExampleApplication::getBoundsWithoutColor(QImage qImage, const QColor
return ofTheKing;
}
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;
});
auto saveWidget=[&](QWidget* w, int iVisible) {
void JKQTPExampleApplication::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,17 +154,57 @@ int JKQTPExampleApplication::exec()
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) {
QVector<std::function<void(void)>> localfunctors=functors;
if (!iterateFunctorStepsSupressInitial) localfunctors.prepend([](){});
QVector<Data> localfunctors=functors;
if (!iterateFunctorStepsSupressInitial) localfunctors.prepend(Data([](){}));
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();
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);
QElapsedTimer timer;
timer.start();
@ -191,8 +217,8 @@ int JKQTPExampleApplication::exec()
QApplication::processEvents();
QApplication::processEvents();
}
for (int i=0; i<widgets.size(); i++) {
QWidget* w=widgets[i];
for (int i=0; i<widgets_local.size(); i++) {
QWidget* w=widgets_local[i];
if (w->isVisible()) {
saveWidget(w, iVisible);
iVisible++;

View File

@ -14,6 +14,8 @@ public:
virtual ~JKQTPExampleApplication();
void addExportStepFunctor(const std::function<void(void)>& f);
void addExportStepPlot(JKQTPlotter* plot);
void addExportStepPlotFunctor(const std::function<JKQTPlotter*(void)>& fplot);
int exec();
public Q_SLOTS:
void notifyReadyForScreenshot();
@ -29,7 +31,30 @@ protected:
bool iterateFunctorSteps;
bool iterateFunctorStepsSupressInitial;
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();
QRect getBoundsWithoutColor(QImage qImage, const QColor &exclusionColor = Qt::white);
void saveWidget(QWidget* w, int iVisible);;
};