51 lines
1.5 KiB
C++
51 lines
1.5 KiB
C++
#include "Global.h"
|
|
#include <QApplication>
|
|
#include "Plot_p.h"
|
|
|
|
namespace YSG {
|
|
|
|
TimerThread::TimerThread() {
|
|
connect(QApplication::instance(), &QApplication::aboutToQuit, [&]() {
|
|
if (isRunning()) {
|
|
quit();
|
|
wait();
|
|
}
|
|
delete this;
|
|
});
|
|
}
|
|
|
|
void TimerThread::run() {
|
|
for (auto &plot: mPlots) {
|
|
plot->d->mTimer = new QTimer;
|
|
plot->d->mTimer->setTimerType(Qt::PreciseTimer);
|
|
plot->d->mTimerThread = this;
|
|
connect(plot->d->mTimer, &QTimer::timeout, plot, &Plot::render, Qt::DirectConnection);
|
|
// show里的调用可能比这个 线程开启提前, 那是 timer是nullptr
|
|
if (plot->isVisible()) plot->startRender();
|
|
}
|
|
exec();
|
|
for (auto &plot: mPlots) {
|
|
plot->d->mTimer->stop();
|
|
delete plot->d->mTimer;
|
|
}
|
|
}
|
|
|
|
void Global::startAllTimeThread() {
|
|
for (auto &thread: mTimerThreadMap) {
|
|
//qDebug() << "startAllTimeThread == " << thread->objectName();
|
|
thread->start();
|
|
}
|
|
mTimerId = startTimer(10);
|
|
}
|
|
|
|
void Global::timerEvent(QTimerEvent* event) {
|
|
if (event->timerId() != mTimerId) return;
|
|
for (TimerThread *t: mTimerThreadMap) {
|
|
for (Plot *plot: t->mPlots) {
|
|
if (plot->d->mPlotState.loadAcquire() != PlotPrivate::PlotState::NeedToPaint) continue;
|
|
plot->repaint();
|
|
}
|
|
}
|
|
}
|
|
}
|