From 336df769122db8c148d2c43b7f92f7224c985f3f Mon Sep 17 00:00:00 2001 From: malte_langkabel Date: Mon, 20 Jul 2015 15:48:02 +0200 Subject: [PATCH] ui: fixed ui refresh crashes * fixed thread based crashes on refresh by adding functors for the required functionality. --- src/app/qt/view/QtCompositeView.cpp | 9 +++++++-- src/app/qt/view/QtCompositeView.h | 4 ++++ src/app/qt/view/QtGraphView.cpp | 22 ++++++++++++++-------- src/app/qt/view/QtGraphView.h | 2 ++ 4 files changed, 27 insertions(+), 10 deletions(-) diff --git a/src/app/qt/view/QtCompositeView.cpp b/src/app/qt/view/QtCompositeView.cpp index f6afb06a..84fe87da 100644 --- a/src/app/qt/view/QtCompositeView.cpp +++ b/src/app/qt/view/QtCompositeView.cpp @@ -8,6 +8,7 @@ QtCompositeView::QtCompositeView(ViewLayout* viewLayout, CompositeDirection direction) : CompositeView(viewLayout, direction) + , m_refreshFunctor(std::bind(&QtCompositeView::doRefreshView, this)) { QBoxLayout* layout; if (getDirection() == CompositeView::DIRECTION_HORIZONTAL) @@ -26,7 +27,7 @@ QtCompositeView::QtCompositeView(ViewLayout* viewLayout, CompositeDirection dire m_widget = new QWidget(); m_widget->setLayout(layout); - refreshView(); + doRefreshView(); } QtCompositeView::~QtCompositeView() @@ -40,10 +41,14 @@ void QtCompositeView::createWidgetWrapper() void QtCompositeView::initView() { - } void QtCompositeView::refreshView() +{ + m_refreshFunctor(); +} + +void QtCompositeView::doRefreshView() { utility::setWidgetBackgroundColor(m_widget, ColorScheme::getInstance()->getColor("search/background")); } diff --git a/src/app/qt/view/QtCompositeView.h b/src/app/qt/view/QtCompositeView.h index 6dc764c6..69bb063b 100644 --- a/src/app/qt/view/QtCompositeView.h +++ b/src/app/qt/view/QtCompositeView.h @@ -4,6 +4,7 @@ #include #include "component/view/CompositeView.h" +#include "qt/utility/QtThreadedFunctor.h" class QtCompositeView : public CompositeView @@ -21,6 +22,9 @@ public: virtual void addViewWidget(View* view); private: + void doRefreshView(); + + QtThreadedFunctor m_refreshFunctor; QWidget* m_widget; }; diff --git a/src/app/qt/view/QtGraphView.cpp b/src/app/qt/view/QtGraphView.cpp index 8681cd1a..a2db41ba 100644 --- a/src/app/qt/view/QtGraphView.cpp +++ b/src/app/qt/view/QtGraphView.cpp @@ -31,6 +31,7 @@ QtGraphView::QtGraphView(ViewLayout* viewLayout) std::bind(&QtGraphView::doRebuildGraph, this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3)) , m_clearFunctor(std::bind(&QtGraphView::doClear, this)) , m_resizeFunctor(std::bind(&QtGraphView::doResize, this)) + , m_refreshFunctor(std::bind(&QtGraphView::doRefreshView, this)) , m_focusInFunctor(std::bind(&QtGraphView::doFocusIn, this, std::placeholders::_1)) , m_focusOutFunctor(std::bind(&QtGraphView::doFocusOut, this, std::placeholders::_1)) { @@ -62,18 +63,12 @@ void QtGraphView::initView() widget->layout()->addWidget(view); - refreshView(); + doRefreshView(); } void QtGraphView::refreshView() { - clear(); - resizeView(); - - std::string backgroundColor = ColorScheme::getInstance()->getColor("graph/background"); - - utility::setWidgetBackgroundColor(QtViewWidgetWrapper::getWidgetOfView(this), backgroundColor); - utility::setWidgetBackgroundColor(getView(), backgroundColor); + m_refreshFunctor(); } void QtGraphView::rebuildGraph( @@ -242,6 +237,17 @@ void QtGraphView::doResize() getView()->setSceneRect(getSceneRect(m_oldNodes)); } +void QtGraphView::doRefreshView() +{ + doClear(); + doResize(); + + std::string backgroundColor = ColorScheme::getInstance()->getColor("graph/background"); + + utility::setWidgetBackgroundColor(QtViewWidgetWrapper::getWidgetOfView(this), backgroundColor); + utility::setWidgetBackgroundColor(getView(), backgroundColor); +} + std::shared_ptr QtGraphView::findNodeRecursive(const std::list>& nodes, Id tokenId) { for (const std::shared_ptr& node : nodes) diff --git a/src/app/qt/view/QtGraphView.h b/src/app/qt/view/QtGraphView.h index 43191aa2..f54387eb 100644 --- a/src/app/qt/view/QtGraphView.h +++ b/src/app/qt/view/QtGraphView.h @@ -53,6 +53,7 @@ private: void doRebuildGraph(std::shared_ptr graph, const std::vector& nodes, const std::vector& edges); void doClear(); void doResize(); + void doRefreshView(); void doFocusIn(Id tokenId); void doFocusOut(Id tokeId); @@ -77,6 +78,7 @@ private: QtThreadedFunctor, const std::vector&, const std::vector&> m_rebuildGraphFunctor; QtThreadedFunctor m_clearFunctor; QtThreadedFunctor m_resizeFunctor; + QtThreadedFunctor m_refreshFunctor; QtThreadedFunctor m_focusInFunctor; QtThreadedFunctor m_focusOutFunctor;