src: Switched all Qt..View implementations to use QtThreadedLambdaFunctor

This commit is contained in:
Eberhard Graether
2017-09-21 01:37:17 +02:00
parent 49caaa1b0b
commit 1e7d934cb8
14 changed files with 340 additions and 462 deletions
+5 -8
View File
@@ -8,7 +8,6 @@
QtCompositeView::QtCompositeView(ViewLayout* viewLayout, CompositeDirection direction, const std::string& name)
: CompositeView(viewLayout, direction, name)
, m_refreshFunctor(std::bind(&QtCompositeView::doRefreshView, this))
{
QBoxLayout* layout;
if (getDirection() == CompositeView::DIRECTION_HORIZONTAL)
@@ -27,7 +26,7 @@ QtCompositeView::QtCompositeView(ViewLayout* viewLayout, CompositeDirection dire
m_widget = new QWidget();
m_widget->setLayout(layout);
doRefreshView();
refreshView();
}
QtCompositeView::~QtCompositeView()
@@ -45,12 +44,10 @@ void QtCompositeView::initView()
void QtCompositeView::refreshView()
{
m_refreshFunctor();
}
void QtCompositeView::doRefreshView()
{
utility::setWidgetBackgroundColor(m_widget, ColorScheme::getInstance()->getColor("search/background"));
m_onQtThread([=]()
{
utility::setWidgetBackgroundColor(m_widget, ColorScheme::getInstance()->getColor("search/background"));
});
}
void QtCompositeView::addViewWidget(View* view)
+1 -3
View File
@@ -22,9 +22,7 @@ public:
virtual void addViewWidget(View* view);
private:
void doRefreshView();
QtThreadedFunctor<void> m_refreshFunctor;
QtThreadedLambdaFunctor m_onQtThread;
QWidget* m_widget;
};
+53 -67
View File
@@ -13,19 +13,19 @@
#include <QStandardItem>
#include <QStyledItemDelegate>
#include "qt/utility/utilityQt.h"
#include "qt/element/QtTable.h"
#include "qt/utility/utilityQt.h"
#include "qt/view/QtViewWidgetWrapper.h"
#include "settings/ColorScheme.h"
#include "utility/messaging/type/MessageErrorFilterChanged.h"
#include "utility/messaging/type/MessageProjectEdit.h"
#include "utility/messaging/type/MessageShowErrors.h"
#include "utility/ResourcePaths.h"
#include "qt/view/QtViewWidgetWrapper.h"
QIcon QtErrorView::s_errorIcon;
class SelectableDelegate : public QStyledItemDelegate
class SelectableDelegate
: public QStyledItemDelegate
{
QWidget* createEditor(QWidget* parent, const QStyleOptionViewItem &option, const QModelIndex &index) const;
};
@@ -46,10 +46,6 @@ QWidget* SelectableDelegate::createEditor(
QtErrorView::QtErrorView(ViewLayout* viewLayout)
: ErrorView(viewLayout)
, m_clearFunctor(std::bind(&QtErrorView::doClear, this))
, m_refreshFunctor(std::bind(&QtErrorView::doRefreshView, this))
, m_addErrorsFunctor(std::bind(&QtErrorView::doAddErrors, this, std::placeholders::_1, std::placeholders::_2))
, m_setErrorIdFunctor(std::bind(&QtErrorView::doSetErrorId, this, std::placeholders::_1))
, m_ignoreRowSelection(false)
{
s_errorIcon = QIcon(QString((ResourcePaths::getGuiPath().str() + "/indexing_dialog/error.png").c_str()));
@@ -163,41 +159,76 @@ void QtErrorView::initView()
layout->addLayout(checkboxes);
doRefreshView();
setStyleSheet();
}
void QtErrorView::refreshView()
{
m_refreshFunctor();
m_onQtThread([=]()
{
setStyleSheet();
});
}
void QtErrorView::clear()
{
m_clearFunctor();
m_onQtThread([=]()
{
if (!m_model->index(0, 0).data(Qt::DisplayRole).toString().isEmpty())
{
m_model->removeRows(0, m_model->rowCount());
}
m_table->updateRows();
});
}
void QtErrorView::addErrors(const std::vector<ErrorInfo>& errors, bool scrollTo)
{
m_addErrorsFunctor(errors, scrollTo);
m_onQtThread([=]()
{
for (const ErrorInfo& error : errors)
{
addErrorToTable(error);
}
m_table->updateRows();
if (scrollTo)
{
m_table->showLastRow();
}
else
{
m_table->showFirstRow();
}
});
}
void QtErrorView::setErrorId(Id errorId)
{
m_setErrorIdFunctor(errorId);
m_onQtThread([=]()
{
QList<QStandardItem*> items = m_model->findItems(QString::number(errorId), Qt::MatchExactly, COLUMN::ID);
if (items.size() == 1)
{
m_ignoreRowSelection = true;
m_table->selectRow(items.at(0)->row());
m_ignoreRowSelection = false;
}
});
}
void QtErrorView::setErrorCount(ErrorCountInfo info)
{
m_onQtThread(
[=]()
{
m_allLabel->setVisible(m_errorFilter.limit > 0 && info.total > m_errorFilter.limit);
m_allButton->setVisible(m_errorFilter.limit > 0 && info.total > m_errorFilter.limit);
m_onQtThread([=]()
{
m_allLabel->setVisible(m_errorFilter.limit > 0 && info.total > m_errorFilter.limit);
m_allButton->setVisible(m_errorFilter.limit > 0 && info.total > m_errorFilter.limit);
m_allLabel->setText("<b>Only showing first " + QString::number(m_errorFilter.limit) + " errors</b>");
m_allButton->setText("Show all " + QString::number(info.total));
}
);
m_allLabel->setText("<b>Only showing first " + QString::number(m_errorFilter.limit) + " errors</b>");
m_allButton->setText("Show all " + QString::number(info.total));
});
}
void QtErrorView::resetErrorLimit()
@@ -225,51 +256,6 @@ void QtErrorView::errorFilterChanged(int i, bool showErrors)
MessageErrorFilterChanged(m_errorFilter, showErrors).dispatch();
}
void QtErrorView::doRefreshView()
{
setStyleSheet();
}
void QtErrorView::doClear()
{
if (!m_model->index(0, 0).data(Qt::DisplayRole).toString().isEmpty())
{
m_model->removeRows(0, m_model->rowCount());
}
m_table->updateRows();
}
void QtErrorView::doAddErrors(const std::vector<ErrorInfo>& errors, bool scrollTo)
{
for (const ErrorInfo& error : errors)
{
addErrorToTable(error);
}
m_table->updateRows();
if (scrollTo)
{
m_table->showLastRow();
}
else
{
m_table->showFirstRow();
}
}
void QtErrorView::doSetErrorId(Id errorId)
{
QList<QStandardItem*> items = m_model->findItems(QString::number(errorId), Qt::MatchExactly, COLUMN::ID);
if (items.size() == 1)
{
m_ignoreRowSelection = true;
m_table->selectRow(items.at(0)->row());
m_ignoreRowSelection = false;
}
}
void QtErrorView::setStyleSheet() const
{
QWidget* widget = QtViewWidgetWrapper::getWidgetOfView(this);
-10
View File
@@ -52,11 +52,6 @@ private:
ID = 6
};
void doRefreshView();
void doClear();
void doAddErrors(const std::vector<ErrorInfo>& errors, bool scrollTo);
void doSetErrorId(Id errorId);
void setStyleSheet() const;
void addErrorToTable(const ErrorInfo& error);
@@ -66,11 +61,6 @@ private:
static QIcon s_errorIcon;
QtThreadedFunctor<void> m_clearFunctor;
QtThreadedFunctor<void> m_refreshFunctor;
QtThreadedFunctor<const std::vector<ErrorInfo>&, bool> m_addErrorsFunctor;
QtThreadedFunctor<Id> m_setErrorIdFunctor;
QtThreadedLambdaFunctor m_onQtThread;
ErrorFilter m_errorFilter;
+180 -199
View File
@@ -38,14 +38,6 @@
QtGraphView::QtGraphView(ViewLayout* viewLayout)
: GraphView(viewLayout)
, m_rebuildGraphFunctor(
std::bind(&QtGraphView::doRebuildGraph, this,
std::placeholders::_1, std::placeholders::_2, std::placeholders::_3, std::placeholders::_4))
, 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))
, m_centerActiveNode(false)
, m_scrollToTop(false)
, m_restoreScroll(false)
@@ -158,14 +150,36 @@ void QtGraphView::initView()
trailDepthChanged(0);
}
doRefreshView();
refreshView();
}
void QtGraphView::refreshView()
{
m_refreshFunctor();
m_onQtThread([this]()
{
doResize();
getView()->refreshStyle();
QtGraphicsView* view = getView();
std::string css = utility::getStyleSheet(ResourcePaths::getGuiPath().concat(FilePath("graph_view/graph_view.css")));
view->setStyleSheet(css.c_str());
view->setAppZoomFactor(GraphViewStyle::getZoomFactor());
view->refreshStyle();
m_trailWidget->setStyleSheet(css.c_str());
m_expandButton->setIcon(utility::createButtonIcon(
ResourcePaths::getGuiPath().str() + "graph_view/images/graph.png",
"search/button"
));
m_collapseButton->setIcon(utility::createButtonIcon(
ResourcePaths::getGuiPath().str() + "graph_view/images/graph_arrow.png",
"search/button"
));
updateTrailButtons();
});
}
bool QtGraphView::isVisible() const
@@ -248,17 +262,169 @@ void QtGraphView::rebuildGraph(
const std::vector<std::shared_ptr<DummyEdge>>& edges,
const GraphParams params
){
m_rebuildGraphFunctor(graph, nodes, edges, params);
m_onQtThread([=]()
{
if (m_transition && m_transition->currentTime() < m_transition->totalDuration())
{
m_transition->stop();
finishedTransition();
}
if (graph)
{
m_graph = graph;
}
m_matchedNodes.clear();
QGraphicsView* view = getView();
// create nodes
size_t activeNodeCount = 0;
for (unsigned int i = 0; i < nodes.size(); i++)
{
activeNodeCount += nodes[i]->getActiveSubNodeCount();
}
m_nodes.clear();
m_activeNodes.clear();
m_oldActiveNode.reset();
m_virtualNodeRects.clear();
for (unsigned int i = 0; i < nodes.size(); i++)
{
std::shared_ptr<QtGraphNode> node = createNodeRecursive(view, NULL, nodes[i].get(), activeNodeCount > 1);
if (node)
{
m_nodes.push_back(node);
}
}
// move graph to center
QPointF center = itemsBoundingRect(m_nodes).center();
Vec2i o = GraphViewStyle::alignOnRaster(Vec2i(center.x(), center.y()));
QPointF offset = QPointF(o.x, o.y);
m_sceneRectOffset = offset - center;
for (const std::shared_ptr<QtGraphNode>& node : m_nodes)
{
node->setPos(node->pos() - offset);
}
m_edges.clear();
// create edges
Graph::TrailMode trailMode = m_graph ? m_graph->getTrailMode() : Graph::TRAIL_NONE;
std::set<Id> visibleEdgeIds;
for (const std::shared_ptr<DummyEdge>& edge : edges)
{
if (!edge->data || !edge->data->isType(Edge::EDGE_AGGREGATION))
{
createEdge(view, edge.get(), &visibleEdgeIds, trailMode, offset, params.bezierEdges);
}
}
for (const std::shared_ptr<DummyEdge>& edge : edges)
{
if (edge->data && edge->data->isType(Edge::EDGE_AGGREGATION))
{
createAggregationEdge(view, edge.get(), &visibleEdgeIds);
}
}
m_centerActiveNode = params.centerActiveNode;
m_scrollToTop = params.scrollToTop;
m_isIndexedList = params.isIndexedList;
if (params.animatedTransition && ApplicationSettings::getInstance()->getUseAnimations())
{
createTransition();
}
else
{
switchToNewGraphData();
}
});
}
void QtGraphView::clear()
{
m_clearFunctor();
m_onQtThread([this]()
{
m_oldActiveNode.reset();
m_activeNodes.clear();
m_nodes.clear();
m_edges.clear();
m_oldNodes.clear();
m_oldEdges.clear();
m_graph.reset();
m_oldGraph.reset();
m_matchedNodes.clear();
});
}
void QtGraphView::focusTokenIds(const std::vector<Id>& focusedTokenIds)
{
m_onQtThread([=]()
{
for (const Id& tokenId : focusedTokenIds)
{
std::shared_ptr<QtGraphNode> node = findNodeRecursive(m_oldNodes, tokenId);
if (node)
{
node->focusIn();
continue;
}
for (std::shared_ptr<QtGraphEdge> edge : m_oldEdges)
{
if (edge->getData() && edge->getData()->getId() == tokenId)
{
edge->focusIn();
break;
}
}
}
});
}
void QtGraphView::defocusTokenIds(const std::vector<Id>& defocusedTokenIds)
{
m_onQtThread([=]()
{
for (const Id& tokenId : defocusedTokenIds)
{
std::shared_ptr<QtGraphNode> node = findNodeRecursive(m_oldNodes, tokenId);
if (node && node->isDataNode())
{
node->focusOut();
continue;
}
for (std::shared_ptr<QtGraphEdge> edge : m_oldEdges)
{
if (edge->getData() && edge->getData()->getId() == tokenId)
{
edge->focusOut();
break;
}
}
}
});
}
void QtGraphView::resizeView()
{
m_resizeFunctor();
m_onQtThread([this]()
{
doResize();
});
}
Vec2i QtGraphView::getViewSize() const
@@ -656,142 +822,11 @@ QtGraphicsView* QtGraphView::getView() const
return view;
}
void QtGraphView::doRebuildGraph(
std::shared_ptr<Graph> graph,
const std::vector<std::shared_ptr<DummyNode>>& nodes,
const std::vector<std::shared_ptr<DummyEdge>>& edges,
const GraphParams params
){
if (m_transition && m_transition->currentTime() < m_transition->totalDuration())
{
m_transition->stop();
finishedTransition();
}
if (graph)
{
m_graph = graph;
}
m_matchedNodes.clear();
QGraphicsView* view = getView();
// create nodes
size_t activeNodeCount = 0;
for (unsigned int i = 0; i < nodes.size(); i++)
{
activeNodeCount += nodes[i]->getActiveSubNodeCount();
}
m_nodes.clear();
m_activeNodes.clear();
m_oldActiveNode.reset();
m_virtualNodeRects.clear();
for (unsigned int i = 0; i < nodes.size(); i++)
{
std::shared_ptr<QtGraphNode> node = createNodeRecursive(view, NULL, nodes[i].get(), activeNodeCount > 1);
if (node)
{
m_nodes.push_back(node);
}
}
// move graph to center
QPointF center = itemsBoundingRect(m_nodes).center();
Vec2i o = GraphViewStyle::alignOnRaster(Vec2i(center.x(), center.y()));
QPointF offset = QPointF(o.x, o.y);
m_sceneRectOffset = offset - center;
for (const std::shared_ptr<QtGraphNode>& node : m_nodes)
{
node->setPos(node->pos() - offset);
}
m_edges.clear();
// create edges
Graph::TrailMode trailMode = m_graph ? m_graph->getTrailMode() : Graph::TRAIL_NONE;
std::set<Id> visibleEdgeIds;
for (const std::shared_ptr<DummyEdge>& edge : edges)
{
if (!edge->data || !edge->data->isType(Edge::EDGE_AGGREGATION))
{
createEdge(view, edge.get(), &visibleEdgeIds, trailMode, offset, params.bezierEdges);
}
}
for (const std::shared_ptr<DummyEdge>& edge : edges)
{
if (edge->data && edge->data->isType(Edge::EDGE_AGGREGATION))
{
createAggregationEdge(view, edge.get(), &visibleEdgeIds);
}
}
m_centerActiveNode = params.centerActiveNode;
m_scrollToTop = params.scrollToTop;
m_isIndexedList = params.isIndexedList;
if (params.animatedTransition && ApplicationSettings::getInstance()->getUseAnimations())
{
createTransition();
}
else
{
switchToNewGraphData();
}
}
void QtGraphView::doClear()
{
m_oldActiveNode.reset();
m_activeNodes.clear();
m_nodes.clear();
m_edges.clear();
m_oldNodes.clear();
m_oldEdges.clear();
m_graph.reset();
m_oldGraph.reset();
m_matchedNodes.clear();
}
void QtGraphView::doResize()
{
getView()->setSceneRect(getSceneRect(m_oldNodes));
}
void QtGraphView::doRefreshView()
{
doResize();
QtGraphicsView* view = getView();
std::string css = utility::getStyleSheet(ResourcePaths::getGuiPath().concat(FilePath("graph_view/graph_view.css")));
view->setStyleSheet(css.c_str());
view->setAppZoomFactor(GraphViewStyle::getZoomFactor());
m_trailWidget->setStyleSheet(css.c_str());
m_expandButton->setIcon(utility::createButtonIcon(
ResourcePaths::getGuiPath().str() + "graph_view/images/graph.png",
"search/button"
));
m_collapseButton->setIcon(utility::createButtonIcon(
ResourcePaths::getGuiPath().str() + "graph_view/images/graph_arrow.png",
"search/button"
));
updateTrailButtons();
}
std::shared_ptr<QtGraphNode> QtGraphView::findNodeRecursive(const std::list<std::shared_ptr<QtGraphNode>>& nodes, Id tokenId)
{
for (const std::shared_ptr<QtGraphNode>& node : nodes)
@@ -1202,57 +1237,3 @@ void QtGraphView::createTransition()
connect(m_transition.get(), &QPropertyAnimation::finished, this, &QtGraphView::finishedTransition);
m_transition->start();
}
void QtGraphView::focusTokenIds(const std::vector<Id>& focusedTokenIds)
{
m_focusInFunctor(focusedTokenIds);
}
void QtGraphView::doFocusIn(const std::vector<Id>& tokenIds)
{
for (const Id& tokenId : tokenIds)
{
std::shared_ptr<QtGraphNode> node = findNodeRecursive(m_oldNodes, tokenId);
if (node)
{
node->focusIn();
continue;
}
for (std::shared_ptr<QtGraphEdge> edge : m_oldEdges)
{
if (edge->getData() && edge->getData()->getId() == tokenId)
{
edge->focusIn();
break;
}
}
}
}
void QtGraphView::defocusTokenIds(const std::vector<Id>& defocusedTokenIds)
{
m_focusOutFunctor(defocusedTokenIds);
}
void QtGraphView::doFocusOut(const std::vector<Id>& tokenIds)
{
for (const Id& tokenId : tokenIds)
{
std::shared_ptr<QtGraphNode> node = findNodeRecursive(m_oldNodes, tokenId);
if (node && node->isDataNode())
{
node->focusOut();
continue;
}
for (std::shared_ptr<QtGraphEdge> edge : m_oldEdges)
{
if (edge->getData() && edge->getData()->getId() == tokenId)
{
edge->focusOut();
break;
}
}
}
}
-21
View File
@@ -91,17 +91,7 @@ private:
QtGraphicsView* getView() const;
void doRebuildGraph(
std::shared_ptr<Graph> graph,
const std::vector<std::shared_ptr<DummyNode>>& nodes,
const std::vector<std::shared_ptr<DummyEdge>>& edges,
const GraphParams params);
void doClear();
void doResize();
void doRefreshView();
void doFocusIn(const std::vector<Id>& tokenIds);
void doFocusOut(const std::vector<Id>& tokenIds);
std::shared_ptr<QtGraphNode> findNodeRecursive(const std::list<std::shared_ptr<QtGraphNode>>& nodes, Id tokenId);
@@ -126,17 +116,6 @@ private:
void createTransition();
QtThreadedFunctor<
std::shared_ptr<Graph>,
const std::vector<std::shared_ptr<DummyNode>>&,
const std::vector<std::shared_ptr<DummyEdge>>&,
const GraphParams
> m_rebuildGraphFunctor;
QtThreadedFunctor<void> m_clearFunctor;
QtThreadedFunctor<void> m_resizeFunctor;
QtThreadedFunctor<void> m_refreshFunctor;
QtThreadedFunctor<const std::vector<Id>&> m_focusInFunctor;
QtThreadedFunctor<const std::vector<Id>&> m_focusOutFunctor;
QtThreadedLambdaFunctor m_onQtThread;
std::shared_ptr<Graph> m_graph;
+9 -13
View File
@@ -1,15 +1,12 @@
#include "qt/view/QtRefreshView.h"
#include "qt/utility/utilityQt.h"
#include "utility/ResourcePaths.h"
#include "component/controller/RefreshController.h"
#include "qt/utility/utilityQt.h"
#include "qt/view/QtViewWidgetWrapper.h"
#include "utility/ResourcePaths.h"
QtRefreshView::QtRefreshView(ViewLayout* viewLayout)
: RefreshView(viewLayout)
, m_refreshViewFunctor(std::bind(&QtRefreshView::doRefreshView, this))
{
m_widget = new QtRefreshBar();
setStyleSheet();
@@ -30,16 +27,15 @@ void QtRefreshView::initView()
void QtRefreshView::refreshView()
{
m_refreshViewFunctor();
}
void QtRefreshView::doRefreshView()
{
setStyleSheet();
m_widget->refreshStyle();
m_onQtThread([this]()
{
setStyleSheet();
m_widget->refreshStyle();
});
}
void QtRefreshView::setStyleSheet()
{
m_widget->setStyleSheet(utility::getStyleSheet(ResourcePaths::getGuiPath().concat(FilePath("refresh_view/refresh_view.css"))).c_str());
m_widget->setStyleSheet(utility::getStyleSheet(
ResourcePaths::getGuiPath().concat(FilePath("refresh_view/refresh_view.css"))).c_str());
}
+1 -5
View File
@@ -1,8 +1,6 @@
#ifndef QT_REFRESH_VIEW_H
#define QT_REFRESH_VIEW_H
#include <QWidget>
#include "component/view/RefreshView.h"
#include "qt/element/QtRefreshBar.h"
#include "qt/utility/QtThreadedFunctor.h"
@@ -22,11 +20,9 @@ public:
// RefreshView implementation
private:
void doRefreshView();
void setStyleSheet();
QtThreadedFunctor<> m_refreshViewFunctor;
QtThreadedLambdaFunctor m_onQtThread;
QtRefreshBar* m_widget;
};
+24 -39
View File
@@ -9,11 +9,6 @@
QtSearchView::QtSearchView(ViewLayout* viewLayout)
: SearchView(viewLayout)
, m_refreshViewFunctor(std::bind(&QtSearchView::doRefreshView, this))
, m_setMatchesFunctor(std::bind(&QtSearchView::doSetMatches, this, std::placeholders::_1))
, m_setFocusFunctor(std::bind(&QtSearchView::doSetFocus, this))
, m_findFulltextFunctor(std::bind(&QtSearchView::doFindFulltext, this))
, m_setAutocompletionListFunctor(std::bind(&QtSearchView::doSetAutocompletionList, this, std::placeholders::_1))
{
m_widget = new QtSearchBar();
setStyleSheet();
@@ -34,7 +29,11 @@ void QtSearchView::initView()
void QtSearchView::refreshView()
{
m_refreshViewFunctor();
m_onQtThread([this]()
{
setStyleSheet();
m_widget->refreshStyle();
});
}
std::string QtSearchView::getQuery() const
@@ -44,51 +43,37 @@ std::string QtSearchView::getQuery() const
void QtSearchView::setMatches(const std::vector<SearchMatch>& matches)
{
m_setMatchesFunctor(matches);
m_onQtThread([=]()
{
m_widget->setMatches(matches);
});
}
void QtSearchView::setFocus()
{
m_setFocusFunctor();
m_onQtThread([this]()
{
getViewLayout()->showView(this);
m_widget->setFocus();
});
}
void QtSearchView::findFulltext()
{
m_findFulltextFunctor();
m_onQtThread([this]()
{
getViewLayout()->showView(this);
m_widget->findFulltext();
});
}
void QtSearchView::setAutocompletionList(const std::vector<SearchMatch>& autocompletionList)
{
m_setAutocompletionListFunctor(autocompletionList);
}
void QtSearchView::doRefreshView()
{
setStyleSheet();
m_widget->refreshStyle();
}
void QtSearchView::doSetMatches(const std::vector<SearchMatch>& matches)
{
m_widget->setMatches(matches);
}
void QtSearchView::doSetFocus()
{
getViewLayout()->showView(this);
m_widget->setFocus();
}
void QtSearchView::doFindFulltext()
{
getViewLayout()->showView(this);
m_widget->findFulltext();
}
void QtSearchView::doSetAutocompletionList(const std::vector<SearchMatch>& autocompletionList)
{
m_widget->setAutocompletionList(autocompletionList);
setStyleSheet();
m_onQtThread([=]()
{
m_widget->setAutocompletionList(autocompletionList);
setStyleSheet();
});
}
void QtSearchView::setStyleSheet()
+1 -5
View File
@@ -34,11 +34,7 @@ private:
void setStyleSheet();
QtThreadedFunctor<> m_refreshViewFunctor;
QtThreadedFunctor<const std::vector<SearchMatch>&> m_setMatchesFunctor;
QtThreadedFunctor<> m_setFocusFunctor;
QtThreadedFunctor<> m_findFulltextFunctor;
QtThreadedFunctor<const std::vector<SearchMatch>&> m_setAutocompletionListFunctor;
QtThreadedLambdaFunctor m_onQtThread;
QtSearchBar* m_widget;
};
+56 -71
View File
@@ -2,7 +2,6 @@
#include <QBoxLayout>
#include <QFrame>
#include <QLabel>
#include <QCheckBox>
#include <QPushButton>
#include <QStandardItemModel>
@@ -17,9 +16,6 @@
QtStatusView::QtStatusView(ViewLayout* viewLayout)
: StatusView(viewLayout)
, m_addStatusFunctor(std::bind(&QtStatusView::doAddStatus, this, std::placeholders::_1))
, m_clearFunctor(std::bind(&QtStatusView::doClear, this))
, m_refreshFunctor(std::bind(&QtStatusView::doRefreshView, this))
{
}
@@ -79,7 +75,62 @@ void QtStatusView::initView()
layout->addLayout(filters);
doRefreshView();
refreshView();
}
void QtStatusView::refreshView()
{
m_onQtThread([this]()
{
QWidget* widget = QtViewWidgetWrapper::getWidgetOfView(this);
utility::setWidgetBackgroundColor(widget, ColorScheme::getInstance()->getColor("error/background"));
QPalette palette(m_showErrors->palette());
palette.setColor(QPalette::WindowText, QColor(ColorScheme::getInstance()->getColor("error/text/normal").c_str()));
m_table->updateRows();
});
}
void QtStatusView::clear()
{
m_onQtThread([this]()
{
if (!m_model->index(0, 0).data(Qt::DisplayRole).toString().isEmpty())
{
m_model->removeRows(0, m_model->rowCount());
}
m_table->showFirstRow();
m_status.clear();
});
}
void QtStatusView::addStatus(const std::vector<Status>& status)
{
m_onQtThread([=]()
{
for (const Status& s : status)
{
const int rowNumber = m_table->getFilledRowCount();
if (rowNumber < m_model->rowCount())
{
m_model->insertRow(rowNumber);
}
QString statusType = (s.type == StatusType::STATUS_ERROR ? "ERROR" : "INFO");
m_model->setItem(rowNumber, STATUSVIEW_COLUMN::TYPE, new QStandardItem(statusType));
m_model->setItem(rowNumber, STATUSVIEW_COLUMN::STATUS, new QStandardItem(s.message.c_str()));
}
m_table->updateRows();
if (!m_table->hasSelection())
{
m_table->showLastRow();
}
});
}
QCheckBox* QtStatusView::createFilterCheckbox(const QString& name, QBoxLayout* layout, bool checked)
@@ -104,69 +155,3 @@ QCheckBox* QtStatusView::createFilterCheckbox(const QString& name, QBoxLayout* l
return checkbox;
}
void QtStatusView::refreshView()
{
m_refreshFunctor();
}
void QtStatusView::clear()
{
m_clearFunctor();
}
void QtStatusView::addStatus(const std::vector<Status>& status)
{
m_addStatusFunctor(status);
}
void QtStatusView::doClear()
{
if (!m_model->index(0, 0).data(Qt::DisplayRole).toString().isEmpty())
{
m_model->removeRows(0, m_model->rowCount());
}
m_table->showFirstRow();
m_status.clear();
}
void QtStatusView::doRefreshView()
{
setStyleSheet();
}
void QtStatusView::doAddStatus(const std::vector<Status>& status)
{
for (const Status& s : status)
{
const int rowNumber = m_table->getFilledRowCount();
if (rowNumber < m_model->rowCount())
{
m_model->insertRow(rowNumber);
}
QString statusType = (s.type == StatusType::STATUS_ERROR ? "ERROR" : "INFO");
m_model->setItem(rowNumber, STATUSVIEW_COLUMN::TYPE, new QStandardItem(statusType));
m_model->setItem(rowNumber, STATUSVIEW_COLUMN::STATUS, new QStandardItem(s.message.c_str()));
}
m_table->updateRows();
if (!m_table->hasSelection())
{
m_table->showLastRow();
}
}
void QtStatusView::setStyleSheet() const
{
QWidget* widget = QtViewWidgetWrapper::getWidgetOfView(this);
utility::setWidgetBackgroundColor(widget, ColorScheme::getInstance()->getColor("error/background"));
QPalette palette(m_showErrors->palette());
palette.setColor(QPalette::WindowText, QColor(ColorScheme::getInstance()->getColor("error/text/normal").c_str()));
m_table->updateRows();
}
+2 -9
View File
@@ -16,6 +16,7 @@ class QtStatusView
, public StatusView
{
Q_OBJECT
public:
QtStatusView(ViewLayout* viewLayout);
virtual ~QtStatusView();
@@ -36,17 +37,9 @@ private:
STATUS = 1,
};
void doClear();
void doRefreshView();
void doAddStatus(const std::vector<Status>& status);
QCheckBox* createFilterCheckbox(const QString& name, QBoxLayout* layout, bool checked = false);
void setStyleSheet() const;
QtThreadedFunctor<const std::vector<Status>&> m_addStatusFunctor;
QtThreadedFunctor<void> m_clearFunctor;
QtThreadedFunctor<void> m_refreshFunctor;
QtThreadedLambdaFunctor m_onQtThread;
QtTable* m_table;
QStandardItemModel* m_model;
+7 -10
View File
@@ -10,10 +10,8 @@
#include "settings/ColorScheme.h"
#include "utility/ResourcePaths.h"
QtTabbedView::QtTabbedView(ViewLayout* viewLayout, const std::string& name)
: TabbedView(viewLayout, name)
, m_refreshFunctor(std::bind(&QtTabbedView::doRefreshView, this))
{
}
@@ -41,19 +39,17 @@ void QtTabbedView::initView()
void QtTabbedView::refreshView()
{
m_refreshFunctor();
}
void QtTabbedView::doRefreshView()
{
setStyleSheet();
m_onQtThread([=]()
{
setStyleSheet();
});
}
void QtTabbedView::addViewWidget(View* view)
{
m_widget->addTab(QtViewWidgetWrapper::getWidgetOfView(view), view->getName().c_str());
doRefreshView();
setStyleSheet();
}
void QtTabbedView::showView(View* view)
@@ -65,7 +61,8 @@ void QtTabbedView::showView(View* view)
void QtTabbedView::setStyleSheet()
{
utility::setWidgetBackgroundColor(QtViewWidgetWrapper::getWidgetOfView(this), ColorScheme::getInstance()->getColor("tab/background"));
utility::setWidgetBackgroundColor(
QtViewWidgetWrapper::getWidgetOfView(this), ColorScheme::getInstance()->getColor("tab/background"));
m_widget->setStyleSheet(
utility::getStyleSheet(ResourcePaths::getGuiPath().concat(FilePath("tabbed_view/tabbed_view.css"))).c_str()
+1 -2
View File
@@ -24,9 +24,8 @@ public:
private:
void setStyleSheet();
void doRefreshView();
QtThreadedFunctor<void> m_refreshFunctor;
QtThreadedLambdaFunctor m_onQtThread;
QTabWidget* m_widget;
};