31 #include <QFutureWatcher> 33 #include <QtConcurrentRun> 34 #include <QtConcurrentMap> 57 m_mappedRunning =
false;
59 m_progressBar =
new ProgressBar(
"Reading Control Nets");
64 connect(
m_watcher, SIGNAL(finished()),
this, SLOT(mappedFinished()));
86 ProgressBar *ConcurrentControlNetReader::progressBar() {
96 m_backlog.append(filename);
98 if (!m_progressBar.isNull()) {
99 m_progressBar->setRange(0, m_progressBar->maximum() + 1);
111 m_backlog.append(filenames);
113 if (!m_progressBar.isNull()) {
114 m_progressBar->setRange(0, m_progressBar->maximum() + filenames.size());
129 void ConcurrentControlNetReader::initProgress() {
131 m_progressBar->setVisible(
false);
132 m_progressBar->setRange(0, 100);
133 m_progressBar->setValue(0);
138 void ConcurrentControlNetReader::start() {
140 if (!m_backlog.isEmpty() && !m_mappedRunning) {
143 foreach (QString backlogFileName, m_backlog) {
144 Progress *progress =
new Progress;
145 progress->DisableAutomaticDisplay();
146 m_progress.append(progress);
148 functorInput.append(qMakePair(FileName(backlogFileName), progress));
151 QFuture<Control *> networks = QtConcurrent::mapped(functorInput,
152 FileNameToControlFunctor(QThread::currentThread()));
157 catch (IException &e) {
161 if (!m_progressBar.isNull()) {
162 m_progressBar->setVisible(
true);
165 delete m_progressUpdateTimer;
168 m_mappedRunning =
true;
171 m_progressUpdateTimer =
new QTimer;
172 connect(m_progressUpdateTimer, SIGNAL(timeout()),
173 this, SLOT(updateProgressValue()));
174 m_progressUpdateTimer->start(100);
179 void ConcurrentControlNetReader::updateProgressValue() {
180 if (!m_mappedRunning) {
181 foreach (Progress *progress, m_progress) {
189 int progressMax = (m_progress.count() + m_backlog.count()) * 1000;
190 int progressCurrent = 0;
192 foreach (Progress *progress, m_progress) {
193 if (progress->MaximumSteps()) {
194 if (progress->CurrentStep() < progress->MaximumSteps()) {
195 double progressPercent = progress->CurrentStep() / (double)progress->MaximumSteps();
197 progressCurrent += qFloor(progressPercent * 1000);
200 progressCurrent += 1000;
206 if (progressMax > 0) {
207 m_progressBar->setRange(progressMin, progressMax);
208 m_progressBar->setValue(progressCurrent);
211 m_progressBar->setRange(0, 100);
212 m_progressBar->setValue(100);
218 void ConcurrentControlNetReader::mappedFinished() {
219 m_mappedRunning =
false;
221 delete m_progressUpdateTimer;
222 updateProgressValue();
225 emit networksReady(networks);
227 if (!m_backlog.isEmpty()) {
236 ConcurrentControlNetReader::FileNameToControlFunctor::FileNameToControlFunctor(
238 m_targetThread = targetThread;
242 ConcurrentControlNetReader::FileNameToControlFunctor::FileNameToControlFunctor(
243 const FileNameToControlFunctor & other) {
244 m_targetThread = other.m_targetThread;
248 ConcurrentControlNetReader::FileNameToControlFunctor::~FileNameToControlFunctor() {
249 m_targetThread = NULL;
253 Control * ConcurrentControlNetReader::FileNameToControlFunctor::operator()(
256 QString fileNameString = fileNameAndProgress.first.expanded();
257 Progress *progress = fileNameAndProgress.second;
259 ControlNet *newCnet =
new ControlNet(fileNameString, progress);
260 Control *result =
new Control(newCnet, fileNameString);
262 newCnet->setParent(result);
263 result->moveToThread(m_targetThread);
269 ConcurrentControlNetReader::FileNameToControlFunctor &
270 ConcurrentControlNetReader::FileNameToControlFunctor::operator=(
271 const FileNameToControlFunctor &rhs) {
272 m_targetThread = rhs.m_targetThread;
void nullify()
Initializes members to NULL.
QFutureWatcher< Control * > * m_watcher
provides SIGNALS / SLOTS for FileNameToControlFunctor
ConcurrentControlNetReader()
Allocates memory at construction instead of as needed.
~ConcurrentControlNetReader()
This destructor will cancel all running threads and block.
void read(QString filename)
Namespace for ISIS/Bullet specific routines.