ui: fixed ui refresh crashes

* fixed thread based crashes on refresh by adding functors for the required functionality.
This commit is contained in:
malte_langkabel
2015-07-20 15:48:02 +02:00
parent 0f9e72d553
commit 336df76912
4 changed files with 27 additions and 10 deletions
+7 -2
View File
@@ -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"));
}
+4
View File
@@ -4,6 +4,7 @@
#include <QWidget>
#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<void> m_refreshFunctor;
QWidget* m_widget;
};
+14 -8
View File
@@ -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<QtGraphNode> QtGraphView::findNodeRecursive(const std::list<std::shared_ptr<QtGraphNode>>& nodes, Id tokenId)
{
for (const std::shared_ptr<QtGraphNode>& node : nodes)
+2
View File
@@ -53,6 +53,7 @@ private:
void doRebuildGraph(std::shared_ptr<Graph> graph, const std::vector<DummyNode>& nodes, const std::vector<DummyEdge>& edges);
void doClear();
void doResize();
void doRefreshView();
void doFocusIn(Id tokenId);
void doFocusOut(Id tokeId);
@@ -77,6 +78,7 @@ private:
QtThreadedFunctor<std::shared_ptr<Graph>, const std::vector<DummyNode>&, const std::vector<DummyEdge>&> m_rebuildGraphFunctor;
QtThreadedFunctor<void> m_clearFunctor;
QtThreadedFunctor<void> m_resizeFunctor;
QtThreadedFunctor<void> m_refreshFunctor;
QtThreadedFunctor<Id> m_focusInFunctor;
QtThreadedFunctor<Id> m_focusOutFunctor;