Commit 0ffbaeb6 authored by Mike Kremer's avatar Mike Kremer

Suspended writing of application snapshots to asynchronous execution queue.

git-svn-id: http://www.openflipper.org/svnrepo/OpenFlipper/branches/Free@12228 383ad7c9-94d9-4d36-a494-682f7c89f535
parent ba9c3682
......@@ -82,6 +82,9 @@
#include <QToolBar>
#include <QStatusBar>
#include <QFuture>
#include <QFutureWatcher>
#include <QDockWidget>
#include <OpenFlipper/widgets/aboutWidget/aboutWidget.hh>
......@@ -926,6 +929,28 @@ public:
/** @} */
//===========================================================================
/** @name Thread-safe functions using QFuture
* @{ */
//===========================================================================
public:
void writeImageAsynchronously(QPixmap* _pixmap, const QString _name);
private:
void writeImage(QPixmap* _pixmap, const QString _name) const;
// Store pointers to QFuture and QFutureWatcher
std::map<QFutureWatcher<void>*,QFuture<void>*> watcher_garbage_;
private slots:
void delete_garbage();
/** @} */
//===========================================================================
/** @name StackWidget controls
* @{ */
......@@ -1368,7 +1393,6 @@ public:
void hidePopupMenus();
/** @} */
};
......
......@@ -462,9 +462,9 @@ void CoreWidget::applicationSnapshot() {
suggest += format;
QPixmap pic = QPixmap::grabWindow( winId() );
pic.save(suggest);
// Write image asynchronously
QPixmap* pic = new QPixmap(QPixmap::grabWindow( winId() ));
writeImageAsynchronously(pic, suggest);
}
......@@ -725,6 +725,39 @@ void CoreWidget::applicationSnapshotName(QString _name) {
snapshotCounter_ = 0;
}
void CoreWidget::writeImageAsynchronously(QPixmap* _pixmap, const QString _name) {
QFuture<void>* future = new QFuture<void>();
*future = QtConcurrent::run(this, &CoreWidget::writeImage, _pixmap, _name);
QFutureWatcher<void>* watcher = new QFutureWatcher<void>();
watcher->setFuture(*future);
watcher_garbage_.insert(std::pair<QFutureWatcher<void>*,QFuture<void>*>(watcher, future));
connect(watcher, SIGNAL(finished()), this, SLOT(delete_garbage()));
}
void CoreWidget::writeImage(QPixmap* _pixmap, const QString _name) const {
_pixmap->save(_name);
delete _pixmap;
}
void CoreWidget::delete_garbage() {
QObject* obj = QObject::sender();
QFutureWatcher<void>* watcher = dynamic_cast<QFutureWatcher<void>*>(obj);
if(!watcher) {
return;
}
std::map<QFutureWatcher<void>*,QFuture<void>*>::iterator f;
f = watcher_garbage_.find(watcher);
if(f != watcher_garbage_.end()) {
delete f->second;
delete f->first;
watcher_garbage_.erase(f);
}
}
void CoreWidget::slotPasteView( ) {
examiner_widgets_[PluginFunctions::activeExaminer()]->actionPasteView();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment