Skip to content

Commit

Permalink
MRView: changes to allow use of progress bar from different threads
Browse files Browse the repository at this point in the history
Should get around issues #295 & #298. Also this seems to magically fix
the issue with the background being cleared to grey when the ProgressBar
is displayed (see previous commit), which is a nice bonus...
  • Loading branch information
jdtournier committed Jul 20, 2015
1 parent a8a7202 commit 73b21ad
Show file tree
Hide file tree
Showing 3 changed files with 448 additions and 431 deletions.
55 changes: 5 additions & 50 deletions src/gui/dialog/progress.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,6 @@ namespace MR

namespace {
QWidget* main_window = nullptr;
struct Data {
Data () : dialog (nullptr) { }
QProgressDialog* dialog;
Timer timer;
};
}

void set_main_window (QWidget* window) {
Expand All @@ -49,61 +44,21 @@ namespace MR
{
if (!p.data) {
INFO (App::NAME + ": " + p.text);
main_window->setUpdatesEnabled (false);
p.data = new Data;
QMetaObject::invokeMethod (main_window, "startProgressBar");
p.data = new Timer;
}
else {
#if QT_VERSION >= 0x050400
QOpenGLContext* context = QOpenGLContext::currentContext();
QSurface* surface = context ? context->surface() : nullptr;
#endif
Data* data = reinterpret_cast<Data*> (p.data);
if (!data->dialog) {
if (data->timer.elapsed() > 1.0) {
data->dialog = new QProgressDialog (p.text.c_str(), "Cancel", 0, p.multiplier ? 100 : 0);
data->dialog->setWindowModality (Qt::ApplicationModal);
data->dialog->show();
qApp->processEvents();
}
}
else {
data->dialog->setValue (p.value);
qApp->processEvents();
}

#if QT_VERSION >= 0x050400
if (context) {
assert (surface);
context->makeCurrent (surface);
}
#endif
if (reinterpret_cast<Timer*>(p.data)->elapsed() > 1.0)
QMetaObject::invokeMethod (main_window, "displayProgressBar", Q_ARG (ProgressInfo&, p));
}
}


void done (ProgressInfo& p)
{
INFO (App::NAME + ": " + p.text + " [done]");
if (p.data) {
Data* data = reinterpret_cast<Data*> (p.data);
if (data->dialog) {
#if QT_VERSION >= 0x050400
QOpenGLContext* context = QOpenGLContext::currentContext();
QSurface* surface = context ? context->surface() : nullptr;
#endif
delete data->dialog;

#if QT_VERSION >= 0x050400
if (context) {
assert (surface);
context->makeCurrent (surface);
}
#endif
}
delete data;
}
QMetaObject::invokeMethod (main_window, "doneProgressBar");
p.data = nullptr;
main_window->setUpdatesEnabled (true);
}

}
Expand Down

0 comments on commit 73b21ad

Please sign in to comment.