diff --git a/profiler_gui/CMakeLists.txt b/profiler_gui/CMakeLists.txt index 0d76064..c931d8a 100644 --- a/profiler_gui/CMakeLists.txt +++ b/profiler_gui/CMakeLists.txt @@ -42,6 +42,10 @@ if (Qt5Widgets_FOUND) graphics_slider_area.cpp main_window.h main_window.cpp + thread_pool.h + thread_pool.cpp + thread_pool_task.h + thread_pool_task.cpp tree_widget_item.h tree_widget_item.cpp tree_widget_loader.h diff --git a/profiler_gui/arbitrary_value_inspector.cpp b/profiler_gui/arbitrary_value_inspector.cpp index 5121129..ae9064b 100644 --- a/profiler_gui/arbitrary_value_inspector.cpp +++ b/profiler_gui/arbitrary_value_inspector.cpp @@ -71,6 +71,9 @@ ////////////////////////////////////////////////////////////////////////// +EASY_CONSTEXPR int ChartBound = 2; ///< Top and bottom bounds for chart +EASY_CONSTEXPR int ChartBounds = ChartBound << 1; + void getChartPoints(const ArbitraryValuesCollection& _collection, Points& _points, qreal& _minValue, qreal& _maxValue) { _minValue = 1e300; @@ -151,7 +154,7 @@ ArbitraryValuesCollection::ArbitraryValuesCollection() ArbitraryValuesCollection::~ArbitraryValuesCollection() { - join(); + } const ArbitraryValuesMap& ArbitraryValuesCollection::valuesMap() const @@ -196,9 +199,13 @@ void ArbitraryValuesCollection::collectValues(profiler::thread_id_t _threadId, p m_jobType = ValuesJob; if (_valueId == 0) - m_collectorThread = std::thread(&This::collectByName, this, _threadId, _valueName); + { + m_worker.enqueue([this, _threadId, _valueName] { collectByName(_threadId, _valueName); }, m_bInterrupt); + } else - m_collectorThread = std::thread(&This::collectById, this, _threadId, _valueId); + { + m_worker.enqueue([this, _threadId, _valueId] { collectById(_threadId, _valueId); }, m_bInterrupt); + } } void ArbitraryValuesCollection::collectValues(profiler::thread_id_t _threadId, profiler::vin_t _valueId, const char* _valueName, profiler::timestamp_t _beginTime) @@ -213,9 +220,13 @@ void ArbitraryValuesCollection::collectValues(profiler::thread_id_t _threadId, p m_jobType = ValuesJob | PointsJob; if (_valueId == 0) - m_collectorThread = std::thread(&This::collectByName, this, _threadId, _valueName); + { + m_worker.enqueue([this, _threadId, _valueName] { collectByName(_threadId, _valueName); }, m_bInterrupt); + } else - m_collectorThread = std::thread(&This::collectById, this, _threadId, _valueId); + { + m_worker.enqueue([this, _threadId, _valueId] { collectById(_threadId, _valueId); }, m_bInterrupt); + } } bool ArbitraryValuesCollection::calculatePoints(profiler::timestamp_t _beginTime) @@ -223,8 +234,7 @@ bool ArbitraryValuesCollection::calculatePoints(profiler::timestamp_t _beginTime if (status() != Ready || m_values.empty()) return false; - if (m_collectorThread.joinable()) - m_collectorThread.join(); + m_worker.dequeue(); setStatus(InProgress); m_points.clear(); @@ -233,37 +243,21 @@ bool ArbitraryValuesCollection::calculatePoints(profiler::timestamp_t _beginTime m_maxValue = -1e300; m_jobType = PointsJob; - m_collectorThread = std::thread([this] + m_worker.enqueue([this] { getChartPoints(*this, m_points, m_minValue, m_maxValue); setStatus(Ready); - }); + }, m_bInterrupt); return true; } void ArbitraryValuesCollection::interrupt() { - if (m_collectorThread.joinable()) - { - m_bInterrupt.store(true, std::memory_order_release); - m_collectorThread.join(); - m_bInterrupt.store(false, std::memory_order_release); - - setStatus(Idle); - m_jobType = None; - m_values.clear(); - } -} - -void ArbitraryValuesCollection::join() -{ - if (m_collectorThread.joinable()) - { - m_bInterrupt.store(true, std::memory_order_release); - m_collectorThread.join(); - m_bInterrupt.store(false, std::memory_order_release); - } + m_worker.dequeue(); + setStatus(Idle); + m_jobType = None; + m_values.clear(); } void ArbitraryValuesCollection::setStatus(JobStatus _status) @@ -438,8 +432,8 @@ void ArbitraryValuesChartItem::paint(QPainter* _painter, const QStyleOptionGraph if (!EASY_GLOBALS.scene.empty) { const auto range = bindMode ? widget->sliderWidth() : widget->range(); - paintMouseIndicator(_painter, m_boundingRect.top(), bottom, width, m_boundingRect.height(), font_h, - widget->value(), range); + paintMouseIndicator(_painter, m_boundingRect.top(), bottom, width, + m_boundingRect.height(), font_h, widget->value(), range); } _painter->setPen(Qt::darkGray); @@ -456,21 +450,25 @@ void ArbitraryValuesChartItem::paintMouseIndicator(QPainter* _painter, qreal _to return; const auto x = m_mousePos.x(); - const auto y = m_mousePos.y(); + auto y = m_mousePos.y(); // Horizontal const bool visibleY = (_top < y && y < _bottom); - if (visibleY) + y = estd::clamp(_top, y, _bottom); + //if (visibleY) { + _height -= ChartBounds; + const int half_font_h = _font_h >> 1; - const auto value = m_minValue + ((_bottom - 2 - y) / (_height - 4)) * (m_maxValue - m_minValue); + const auto yvalue = estd::clamp(_top + ChartBound, y, _bottom - ChartBound); + const auto value = m_minValue + ((_bottom - ChartBound - yvalue) / _height) * (m_maxValue - m_minValue); const auto mouseStr = QString::number(value, 'f', 3); const int textWidth = _painter->fontMetrics().width(mouseStr) + 3; - const QRectF rect(0, y - _font_h - 2, _width, 4 + (_font_h << 1)); + const QRectF rect(0, y - _font_h - 2, _width - 3, 4 + (_font_h << 1)); _painter->setPen(Qt::blue); - qreal left = 0, right = _width; + qreal left = 0, right = _width - 3; const Qt::AlignmentFlag alignment = x < textWidth ? Qt::AlignRight : Qt::AlignLeft; if (y > _bottom - half_font_h) @@ -485,12 +483,13 @@ void ArbitraryValuesChartItem::paintMouseIndicator(QPainter* _painter, qreal _to { _painter->drawText(rect, alignment | Qt::AlignVCenter, mouseStr); if (x < textWidth) - right = _width - textWidth; + right = _width - textWidth - 3; else left = textWidth; } - _painter->drawLine(QLineF(left, y, right, y)); + if (visibleY) + _painter->drawLine(QLineF(left, y, right, y)); } // Vertical @@ -507,8 +506,8 @@ void ArbitraryValuesChartItem::paintMouseIndicator(QPainter* _painter, qreal _to else if (x > (_width - textWidthHalf)) left = _width - textWidth; - if (!visibleY) - _painter->setPen(Qt::blue); + //if (!visibleY) + // _painter->setPen(Qt::blue); const QRectF rect(left, _bottom + 2, textWidth, _font_h); _painter->drawText(rect, Qt::AlignCenter, mouseStr); @@ -526,9 +525,21 @@ bool ArbitraryValuesChartItem::updateImage() m_imageScaleUpdate = widget->range() / widget->sliderWidth(); m_imageOriginUpdate = widget->bindMode() ? (widget->value() - widget->sliderWidth() * 3) : widget->minimum(); - m_workerThread = std::thread(&This::updateImageAsync, this, m_boundingRect, widget->getWindowScale(), - widget->minimum(), widget->maximum(), widget->range(), widget->value(), widget->sliderWidth(), - widget->bindMode(), EASY_GLOBALS.begin_time, EASY_GLOBALS.auto_adjust_chart_height); + // Ugly, but doen't use exceeded count of threads + const auto rect = m_boundingRect; + const auto scale = widget->getWindowScale(); + const auto left = widget->minimum(); + const auto right = widget->maximum(); + const auto value = widget->value(); + const auto window = widget->sliderWidth(); + const auto bindMode = widget->bindMode(); + const auto beginTime = EASY_GLOBALS.begin_time; + const auto autoHeight = EASY_GLOBALS.auto_adjust_chart_height; + m_worker.enqueue([this, rect, scale, left, right, value, window, bindMode, beginTime, autoHeight] + { + updateImageAsync(rect, scale, left, right, right - left, value, window, bindMode, + beginTime, autoHeight); + }, m_bReady); return true; } @@ -708,8 +719,8 @@ void ArbitraryValuesChartItem::updateImageAsync(QRectF _boundingRect, qreal _cur { y = maxValue - y; y /= height; - y *= _boundingRect.height() - 4; - y += 2; + y *= _boundingRect.height() - ChartBounds; + y += ChartBound; } return y; @@ -878,7 +889,7 @@ GraphicsChart::GraphicsChart(QWidget* _parent) m_chartItem->setPos(0, 0); m_chartItem->setBoundingRect(0, rect.top() + margin(), scene()->width(), rect.height() - margins() - 1); - connect(&EASY_GLOBALS.events, &profiler_gui::EasyGlobalSignals::autoAdjustChartChanged, this, &This::onAutoAdjustChartChanged); + connect(&EASY_GLOBALS.events, &profiler_gui::GlobalSignals::autoAdjustChartChanged, this, &This::onAutoAdjustChartChanged); m_chartItem->updateImage(); } @@ -1040,7 +1051,7 @@ ArbitraryValuesWidget::ArbitraryValuesWidget(QWidget* _parent) //m_treeWidget->setSortingEnabled(false); m_treeWidget->setColumnCount(int_cast(ArbitraryColumns::Count)); m_treeWidget->setSelectionBehavior(QAbstractItemView::SelectRows); - m_treeWidget->setItemDelegateForColumn(0, new EasyTreeViewFirstColumnItemDelegate(this)); + m_treeWidget->setItemDelegateForColumn(0, new TreeViewFirstColumnItemDelegate(this)); auto headerItem = new QTreeWidgetItem(); headerItem->setText(int_cast(ArbitraryColumns::Type), "Type"); @@ -1056,9 +1067,9 @@ ArbitraryValuesWidget::ArbitraryValuesWidget(QWidget* _parent) connect(m_treeWidget, &QTreeWidget::currentItemChanged, this, &This::onCurrentItemChanged); auto globalEvents = &EASY_GLOBALS.events; - connect(globalEvents, &profiler_gui::EasyGlobalSignals::selectedBlockChanged, this, &This::onSelectedBlockChanged); - connect(globalEvents, &profiler_gui::EasyGlobalSignals::selectedBlockIdChanged, this, &This::onSelectedBlockIdChanged); - connect(globalEvents, &profiler_gui::EasyGlobalSignals::fileOpened, this, &This::rebuild); + connect(globalEvents, &profiler_gui::GlobalSignals::selectedBlockChanged, this, &This::onSelectedBlockChanged); + connect(globalEvents, &profiler_gui::GlobalSignals::selectedBlockIdChanged, this, &This::onSelectedBlockIdChanged); + connect(globalEvents, &profiler_gui::GlobalSignals::fileOpened, this, &This::rebuild); loadSettings(); @@ -1182,7 +1193,6 @@ void ArbitraryValuesWidget::onCollectionsTimeout() { if (item->collection()->status() != ArbitraryValuesCollection::InProgress) { - item->collection()->join(); collections.push_back(CollectionPaintData {item->collection(), item->color(), ChartType::Line, item == m_treeWidget->currentItem()}); } diff --git a/profiler_gui/arbitrary_value_inspector.h b/profiler_gui/arbitrary_value_inspector.h index 1b265fc..5bb8d67 100644 --- a/profiler_gui/arbitrary_value_inspector.h +++ b/profiler_gui/arbitrary_value_inspector.h @@ -67,10 +67,10 @@ #include #include #include -#include #include #include #include "graphics_slider_area.h" +#include "thread_pool_task.h" ////////////////////////////////////////////////////////////////////////// @@ -89,15 +89,15 @@ private: using This = ArbitraryValuesCollection; - ArbitraryValuesMap m_values; - Points m_points; - std::thread m_collectorThread; - profiler::timestamp_t m_beginTime; - qreal m_minValue; - qreal m_maxValue; - std::atomic m_status; - std::atomic_bool m_bInterrupt; - uint8_t m_jobType; + ArbitraryValuesMap m_values; + Points m_points; + ThreadPoolTask m_worker; + profiler::timestamp_t m_beginTime; + qreal m_minValue; + qreal m_maxValue; + std::atomic m_status; + std::atomic_bool m_bInterrupt; + uint8_t m_jobType; public: @@ -116,7 +116,6 @@ public: void collectValues(profiler::thread_id_t _threadId, profiler::vin_t _valueId, const char* _valueName, profiler::timestamp_t _beginTime); bool calculatePoints(profiler::timestamp_t _beginTime); void interrupt(); - void join(); private: diff --git a/profiler_gui/blocks_graphics_view.cpp b/profiler_gui/blocks_graphics_view.cpp index 2f93869..53ee5b8 100644 --- a/profiler_gui/blocks_graphics_view.cpp +++ b/profiler_gui/blocks_graphics_view.cpp @@ -19,7 +19,7 @@ * : * : * 2016/06/30 Victor Zarubkin: Replaced doubles with floats (in ProfBlockItem) for less memory consumption. * : -* : * 2016/09/15 Victor Zarubkin: Moved sources of EasyGraphicsItem and EasyChronometerItem to separate files. +* : * 2016/09/15 Victor Zarubkin: Moved sources of BlocksGraphicsItem and GraphicsRulerItem to separate files. * : * : * * ----------------- : @@ -116,23 +116,23 @@ using estd::clamp; ////////////////////////////////////////////////////////////////////////// -EasyBoldLabel::EasyBoldLabel(const QString& _text, QWidget* _parent) : QLabel(_text, _parent) +BoldLabel::BoldLabel(const QString& _text, QWidget* _parent) : QLabel(_text, _parent) { auto f = font(); f.setBold(true); setFont(f); } -EasyBoldLabel::~EasyBoldLabel() +BoldLabel::~BoldLabel() { } ////////////////////////////////////////////////////////////////////////// -void EasyBackgroundItem::paint(QPainter* _painter, const QStyleOptionGraphicsItem*, QWidget*) +void BackgroundItem::paint(QPainter* _painter, const QStyleOptionGraphicsItem*, QWidget*) { - auto const sceneView = static_cast(scene()->parent()); + auto const sceneView = static_cast(scene()->parent()); const auto visibleSceneRect = sceneView->visibleSceneRect(); const auto currentScale = sceneView->scale(); const auto offset = sceneView->offset(); @@ -251,9 +251,9 @@ void EasyBackgroundItem::paint(QPainter* _painter, const QStyleOptionGraphicsIte ////////////////////////////////////////////////////////////////////////// -void EasyTimelineIndicatorItem::paint(QPainter* _painter, const QStyleOptionGraphicsItem*, QWidget*) +void TimelineIndicatorItem::paint(QPainter* _painter, const QStyleOptionGraphicsItem*, QWidget*) { - const auto sceneView = static_cast(scene()->parent()); + const auto sceneView = static_cast(scene()->parent()); const auto visibleSceneRect = sceneView->visibleSceneRect(); const auto step = sceneView->timelineStep() * sceneView->scale(); const QString text = ::profiler_gui::autoTimeStringInt(units2microseconds(sceneView->timelineStep())); // Displayed text @@ -283,7 +283,7 @@ void EasyTimelineIndicatorItem::paint(QPainter* _painter, const QStyleOptionGrap ////////////////////////////////////////////////////////////////////////// -EasyGraphicsView::EasyGraphicsView(QWidget* _parent) +BlocksGraphicsView::BlocksGraphicsView(QWidget* _parent) : Parent(_parent) , m_beginTime(::std::numeric_limits::max()) , m_sceneWidth(0) @@ -294,8 +294,8 @@ EasyGraphicsView::EasyGraphicsView(QWidget* _parent) , m_idleTime(0) , m_mouseButtons(Qt::NoButton) , m_pScrollbar(nullptr) - , m_chronometerItem(nullptr) - , m_chronometerItemAux(nullptr) + , m_selectionItem(nullptr) + , m_rulerItem(nullptr) , m_popupWidget(nullptr) , m_flickerSpeedX(0) , m_flickerSpeedY(0) @@ -310,13 +310,13 @@ EasyGraphicsView::EasyGraphicsView(QWidget* _parent) updateVisibleSceneRect(); } -EasyGraphicsView::~EasyGraphicsView() +BlocksGraphicsView::~BlocksGraphicsView() { } ////////////////////////////////////////////////////////////////////////// -void EasyGraphicsView::removePopup(bool _removeFromScene) +void BlocksGraphicsView::removePopup(bool _removeFromScene) { if (m_popupWidget != nullptr) { @@ -334,26 +334,26 @@ void EasyGraphicsView::removePopup(bool _removeFromScene) ////////////////////////////////////////////////////////////////////////// -qreal EasyGraphicsView::sceneWidth() const +qreal BlocksGraphicsView::sceneWidth() const { return m_sceneWidth; } -qreal EasyGraphicsView::chronoTime() const +qreal BlocksGraphicsView::chronoTime() const { - return m_chronometerItem->width(); + return m_selectionItem->width(); } -qreal EasyGraphicsView::chronoTimeAux() const +qreal BlocksGraphicsView::chronoTimeAux() const { - return m_chronometerItemAux->width(); + return m_rulerItem->width(); } ////////////////////////////////////////////////////////////////////////// -EasyChronometerItem* EasyGraphicsView::createChronometer(bool _main) +GraphicsRulerItem* BlocksGraphicsView::createChronometer(bool _main) { - auto chronoItem = new EasyChronometerItem(_main); + auto chronoItem = new GraphicsRulerItem(_main); chronoItem->setColor(_main ? ::profiler_gui::CHRONOMETER_COLOR : ::profiler_gui::CHRONOMETER_COLOR2); chronoItem->setBoundingRect(sceneRect()); chronoItem->hide(); @@ -364,7 +364,7 @@ EasyChronometerItem* EasyGraphicsView::createChronometer(bool _main) ////////////////////////////////////////////////////////////////////////// -void EasyGraphicsView::clear() +void BlocksGraphicsView::clear() { const QSignalBlocker blocker(this), sceneBlocker(scene()); // block all scene signals (otherwise clear() would be extremely slow!) @@ -410,40 +410,40 @@ void EasyGraphicsView::clear() emit EASY_GLOBALS.events.selectedThreadChanged(0); } -void EasyGraphicsView::notifySceneSizeChange() +void BlocksGraphicsView::notifySceneSizeChange() { EASY_GLOBALS.scene.left = 0; EASY_GLOBALS.scene.right = m_sceneWidth; emit EASY_GLOBALS.events.sceneSizeChanged(0, m_sceneWidth); } -void EasyGraphicsView::notifyVisibleRegionSizeChange() +void BlocksGraphicsView::notifyVisibleRegionSizeChange() { auto vbar = verticalScrollBar(); const int vbar_width = (vbar != nullptr && vbar->isVisible() ? vbar->width() + 2 : 0); notifyVisibleRegionSizeChange((m_visibleSceneRect.width() + vbar_width) / m_scale); } -void EasyGraphicsView::notifyVisibleRegionSizeChange(qreal _size) +void BlocksGraphicsView::notifyVisibleRegionSizeChange(qreal _size) { m_visibleRegionWidth = _size; EASY_GLOBALS.scene.window = _size; emit EASY_GLOBALS.events.sceneVisibleRegionSizeChanged(_size); } -void EasyGraphicsView::notifyVisibleRegionPosChange() +void BlocksGraphicsView::notifyVisibleRegionPosChange() { EASY_GLOBALS.scene.offset = m_offset; emit EASY_GLOBALS.events.sceneVisibleRegionPosChanged(m_offset); } -void EasyGraphicsView::notifyVisibleRegionPosChange(qreal _pos) +void BlocksGraphicsView::notifyVisibleRegionPosChange(qreal _pos) { m_offset = estd::clamp(0., _pos, m_sceneWidth - m_visibleRegionWidth); notifyVisibleRegionPosChange(); } -void EasyGraphicsView::setTree(const ::profiler::thread_blocks_tree_t& _blocksTree) +void BlocksGraphicsView::setTree(const ::profiler::thread_blocks_tree_t& _blocksTree) { // clear scene clear(); @@ -452,7 +452,7 @@ void EasyGraphicsView::setTree(const ::profiler::thread_blocks_tree_t& _blocksTr if (_blocksTree.empty()) return; - auto bgItem = new EasyBackgroundItem(); + auto bgItem = new BackgroundItem(); scene()->addItem(bgItem); // set new blocks tree @@ -510,12 +510,12 @@ void EasyGraphicsView::setTree(const ::profiler::thread_blocks_tree_t& _blocksTr // Filling scene with items m_items.reserve(_blocksTree.size()); qreal y = TIMELINE_ROW_SIZE; - const EasyGraphicsItem *longestItem = nullptr, *mainThreadItem = nullptr; + const BlocksGraphicsItem *longestItem = nullptr, *mainThreadItem = nullptr; for (const ::profiler::BlocksTreeRoot& t : sorted_roots) { if (m_items.size() == 0xff) { - qWarning() << "Warning: Maximum threads number (255 threads) exceeded! See EasyGraphicsView::setTree() : " << __LINE__ << " in file " << __FILE__; + qWarning() << "Warning: Maximum threads number (255 threads) exceeded! See BlocksGraphicsView::setTree() : " << __LINE__ << " in file " << __FILE__; break; } @@ -527,7 +527,7 @@ void EasyGraphicsView::setTree(const ::profiler::thread_blocks_tree_t& _blocksTr else if (!t.sync.empty()) x = time2position(easyBlocksTree(t.sync.front()).node->begin()); - auto item = new EasyGraphicsItem(static_cast(m_items.size()), t); + auto item = new BlocksGraphicsItem(static_cast(m_items.size()), t); if (t.depth) item->setLevels(t.depth); item->setPos(0, y); @@ -573,11 +573,11 @@ void EasyGraphicsView::setTree(const ::profiler::thread_blocks_tree_t& _blocksTr // Create new chronometer item (previous item was destroyed by scene on scene()->clear()). // It will be shown on mouse right button click. - m_chronometerItemAux = createChronometer(false); - m_chronometerItem = createChronometer(true); + m_rulerItem = createChronometer(false); + m_selectionItem = createChronometer(true); bgItem->setBoundingRect(0, 0, m_sceneWidth, y); - auto indicator = new EasyTimelineIndicatorItem(); + auto indicator = new TimelineIndicatorItem(); indicator->setBoundingRect(0, 0, m_sceneWidth, y); scene()->addItem(indicator); @@ -606,12 +606,12 @@ void EasyGraphicsView::setTree(const ::profiler::thread_blocks_tree_t& _blocksTr m_idleTimer.start(IDLE_TIMER_INTERVAL); } -const EasyGraphicsView::Items &EasyGraphicsView::getItems() const +const BlocksGraphicsView::Items &BlocksGraphicsView::getItems() const { return m_items; } -qreal EasyGraphicsView::setTree(EasyGraphicsItem* _item, const ::profiler::BlocksTree::children_t& _children, qreal& _height, uint32_t& _maxDepthChild, qreal _y, short _level) +qreal BlocksGraphicsView::setTree(BlocksGraphicsItem* _item, const ::profiler::BlocksTree::children_t& _children, qreal& _height, uint32_t& _maxDepthChild, qreal _y, short _level) { if (_children.empty()) { @@ -685,7 +685,7 @@ qreal EasyGraphicsView::setTree(EasyGraphicsItem* _item, const ::profiler::Block else if (!child.children.empty() && !warned) { warned = true; - qWarning() << "Warning: Maximum blocks depth (255) exceeded! See EasyGraphicsView::setTree() : " << __LINE__ << " in file " << __FILE__; + qWarning() << "Warning: Maximum blocks depth (255) exceeded! See BlocksGraphicsView::setTree() : " << __LINE__ << " in file " << __FILE__; } if (duration < children_duration) @@ -723,13 +723,13 @@ qreal EasyGraphicsView::setTree(EasyGraphicsItem* _item, const ::profiler::Block ////////////////////////////////////////////////////////////////////////// -void EasyGraphicsView::setScrollbar(EasyGraphicsScrollbar* _scrollbar) +void BlocksGraphicsView::setScrollbar(BlocksGraphicsScrollbar* _scrollbar) { auto const prevScrollbar = m_pScrollbar; const bool makeConnect = prevScrollbar == nullptr || prevScrollbar != _scrollbar; - disconnect(&EASY_GLOBALS.events, &profiler_gui::EasyGlobalSignals::chartSliderChanged, this, &This::onGraphicsScrollbarValueChange); - disconnect(&EASY_GLOBALS.events, &profiler_gui::EasyGlobalSignals::chartWheeled, this, &This::onGraphicsScrollbarWheel); + disconnect(&EASY_GLOBALS.events, &profiler_gui::GlobalSignals::chartSliderChanged, this, &This::onGraphicsScrollbarValueChange); + disconnect(&EASY_GLOBALS.events, &profiler_gui::GlobalSignals::chartWheeled, this, &This::onGraphicsScrollbarWheel); m_pScrollbar = _scrollbar; m_pScrollbar->clear(); @@ -739,8 +739,8 @@ void EasyGraphicsView::setScrollbar(EasyGraphicsScrollbar* _scrollbar) const int vbar_width = (vbar != nullptr && vbar->isVisible() ? vbar->width() + 2 : 0); m_pScrollbar->setSliderWidth(m_visibleSceneRect.width() + vbar_width); - connect(&EASY_GLOBALS.events, &profiler_gui::EasyGlobalSignals::chartSliderChanged, this, &This::onGraphicsScrollbarValueChange); - connect(&EASY_GLOBALS.events, &profiler_gui::EasyGlobalSignals::chartWheeled, this, &This::onGraphicsScrollbarWheel); + connect(&EASY_GLOBALS.events, &profiler_gui::GlobalSignals::chartSliderChanged, this, &This::onGraphicsScrollbarValueChange); + connect(&EASY_GLOBALS.events, &profiler_gui::GlobalSignals::chartWheeled, this, &This::onGraphicsScrollbarWheel); EASY_GLOBALS.selected_thread = 0; emit EASY_GLOBALS.events.selectedThreadChanged(0); @@ -748,7 +748,7 @@ void EasyGraphicsView::setScrollbar(EasyGraphicsScrollbar* _scrollbar) ////////////////////////////////////////////////////////////////////////// -int EasyGraphicsView::updateVisibleSceneRect() +int BlocksGraphicsView::updateVisibleSceneRect() { m_visibleSceneRect = mapToScene(rect()).boundingRect(); @@ -763,7 +763,7 @@ int EasyGraphicsView::updateVisibleSceneRect() return vbar_width; } -void EasyGraphicsView::updateTimelineStep(qreal _windowWidth) +void BlocksGraphicsView::updateTimelineStep(qreal _windowWidth) { const auto time = units2microseconds(_windowWidth); if (time < 100) @@ -785,7 +785,7 @@ void EasyGraphicsView::updateTimelineStep(qreal _windowWidth) m_timelineStep = microseconds2units(m_timelineStep); } -void EasyGraphicsView::repaintScene() +void BlocksGraphicsView::repaintScene() { scene()->update(m_visibleSceneRect); emit sceneUpdated(); @@ -793,7 +793,7 @@ void EasyGraphicsView::repaintScene() ////////////////////////////////////////////////////////////////////////// -void EasyGraphicsView::scaleTo(qreal _scale) +void BlocksGraphicsView::scaleTo(qreal _scale) { if (m_bEmpty) { @@ -813,7 +813,7 @@ void EasyGraphicsView::scaleTo(qreal _scale) repaintScene(); } -void EasyGraphicsView::wheelEvent(QWheelEvent* _event) +void BlocksGraphicsView::wheelEvent(QWheelEvent* _event) { m_idleTime = 0; if (!m_bEmpty) @@ -821,7 +821,7 @@ void EasyGraphicsView::wheelEvent(QWheelEvent* _event) _event->accept(); } -void EasyGraphicsView::onGraphicsScrollbarWheel(qreal _scenePos, int _wheelDelta) +void BlocksGraphicsView::onGraphicsScrollbarWheel(qreal _scenePos, int _wheelDelta) { m_idleTime = 0; @@ -837,7 +837,7 @@ void EasyGraphicsView::onGraphicsScrollbarWheel(qreal _scenePos, int _wheelDelta onWheel(_scenePos, _wheelDelta); } -void EasyGraphicsView::scrollTo(const EasyGraphicsItem* _item) +void BlocksGraphicsView::scrollTo(const BlocksGraphicsItem* _item) { m_bUpdatingRect = true; auto vbar = verticalScrollBar(); @@ -845,12 +845,12 @@ void EasyGraphicsView::scrollTo(const EasyGraphicsItem* _item) m_bUpdatingRect = false; } -qreal EasyGraphicsView::mapToDiagram(qreal x) const +qreal BlocksGraphicsView::mapToDiagram(qreal x) const { return m_offset + x / m_scale; } -void EasyGraphicsView::onWheel(qreal _scenePos, int _wheelDelta) +void BlocksGraphicsView::onWheel(qreal _scenePos, int _wheelDelta) { const decltype(m_scale) scaleCoeff = _wheelDelta > 0 ? ::profiler_gui::SCALING_COEFFICIENT : ::profiler_gui::SCALING_COEFFICIENT_INV; @@ -884,7 +884,7 @@ void EasyGraphicsView::onWheel(qreal _scenePos, int _wheelDelta) ////////////////////////////////////////////////////////////////////////// -void EasyGraphicsView::mousePressEvent(QMouseEvent* _event) +void BlocksGraphicsView::mousePressEvent(QMouseEvent* _event) { m_idleTime = 0; @@ -899,14 +899,14 @@ void EasyGraphicsView::mousePressEvent(QMouseEvent* _event) if (m_mouseButtons & Qt::LeftButton) { - if (m_chronometerItemAux->isVisible() && (m_chronometerItemAux->hoverLeft() || m_chronometerItemAux->hoverRight())) + if (m_rulerItem->isVisible() && (m_rulerItem->hoverLeft() || m_rulerItem->hoverRight())) { - m_chronometerItemAux->setReverse(m_chronometerItemAux->hoverLeft()); + m_rulerItem->setReverse(m_rulerItem->hoverLeft()); m_bDoubleClick = true; } - else if (m_chronometerItem->isVisible() && (m_chronometerItem->hoverLeft() || m_chronometerItem->hoverRight())) + else if (m_selectionItem->isVisible() && (m_selectionItem->hoverLeft() || m_selectionItem->hoverRight())) { - m_chronometerItem->setReverse(m_chronometerItem->hoverLeft()); + m_selectionItem->setReverse(m_selectionItem->hoverLeft()); m_mouseButtons = Qt::RightButton; return; } @@ -914,15 +914,15 @@ void EasyGraphicsView::mousePressEvent(QMouseEvent* _event) if (m_mouseButtons & Qt::RightButton) { - if (m_chronometerItem->isVisible() && (m_chronometerItem->hoverLeft() || m_chronometerItem->hoverRight())) + if (m_selectionItem->isVisible() && (m_selectionItem->hoverLeft() || m_selectionItem->hoverRight())) { - m_chronometerItem->setReverse(m_chronometerItem->hoverLeft()); + m_selectionItem->setReverse(m_selectionItem->hoverLeft()); } else { const auto mouseX = m_offset + mapToScene(m_mousePressPos).x() / m_scale; - m_chronometerItem->setLeftRight(mouseX, mouseX); - m_chronometerItem->hide(); + m_selectionItem->setLeftRight(mouseX, mouseX); + m_selectionItem->hide(); m_pScrollbar->hideSelectionIndicator(); } } @@ -930,7 +930,7 @@ void EasyGraphicsView::mousePressEvent(QMouseEvent* _event) _event->accept(); } -void EasyGraphicsView::mouseDoubleClickEvent(QMouseEvent* _event) +void BlocksGraphicsView::mouseDoubleClickEvent(QMouseEvent* _event) { m_idleTime = 0; @@ -947,8 +947,8 @@ void EasyGraphicsView::mouseDoubleClickEvent(QMouseEvent* _event) if (m_mouseButtons & Qt::LeftButton) { const auto mouseX = m_offset + mapToScene(m_mousePressPos).x() / m_scale; - m_chronometerItemAux->setLeftRight(mouseX, mouseX); - m_chronometerItemAux->hide(); + m_rulerItem->setLeftRight(mouseX, mouseX); + m_rulerItem->hide(); emit sceneUpdated(); } @@ -957,7 +957,7 @@ void EasyGraphicsView::mouseDoubleClickEvent(QMouseEvent* _event) ////////////////////////////////////////////////////////////////////////// -void EasyGraphicsView::mouseReleaseEvent(QMouseEvent* _event) +void BlocksGraphicsView::mouseReleaseEvent(QMouseEvent* _event) { m_idleTime = 0; @@ -971,9 +971,9 @@ void EasyGraphicsView::mouseReleaseEvent(QMouseEvent* _event) bool changedSelection = false, changedSelectedItem = false; if (m_mouseButtons & Qt::RightButton) { - if (m_chronometerItem->isVisible() && m_chronometerItem->width() < 1e-6) + if (m_selectionItem->isVisible() && m_selectionItem->width() < 1e-6) { - m_chronometerItem->hide(); + m_selectionItem->hide(); m_pScrollbar->hideSelectionIndicator(); } @@ -983,14 +983,14 @@ void EasyGraphicsView::mouseReleaseEvent(QMouseEvent* _event) m_selectedBlocks.clear(); } - if (m_chronometerItem->isVisible()) + if (m_selectionItem->isVisible()) { - //printf("INTERVAL: {%lf, %lf} ms\n", m_chronometerItem->left(), m_chronometerItem->right()); + //printf("INTERVAL: {%lf, %lf} ms\n", m_selectionItem->left(), m_selectionItem->right()); for (auto item : m_items) { if (!EASY_GLOBALS.only_current_thread_hierarchy || item->threadId() == EASY_GLOBALS.selected_thread) - item->getBlocks(m_chronometerItem->left(), m_chronometerItem->right(), m_selectedBlocks); + item->getBlocks(m_selectionItem->left(), m_selectionItem->right(), m_selectedBlocks); } if (!m_selectedBlocks.empty()) @@ -1007,17 +1007,17 @@ void EasyGraphicsView::mouseReleaseEvent(QMouseEvent* _event) { bool clicked = false; - if (m_chronometerItemAux->isVisible() && m_chronometerItemAux->width() < 1e-6) + if (m_rulerItem->isVisible() && m_rulerItem->width() < 1e-6) { chronoHidden = true; - m_chronometerItemAux->hide(); + m_rulerItem->hide(); } - else if (m_chronometerItem->isVisible() && m_chronometerItem->hoverIndicator()) + else if (m_selectionItem->isVisible() && m_selectionItem->hoverIndicator()) { // Jump to selected zone clicked = true; m_flickerSpeedX = m_flickerSpeedY = 0; - notifyVisibleRegionPosChange(m_chronometerItem->left() + (m_chronometerItem->width() - m_visibleRegionWidth) * 0.5); + notifyVisibleRegionPosChange(m_selectionItem->left() + (m_selectionItem->width() - m_visibleRegionWidth) * 0.5); } if (!clicked && m_mouseMovePath.manhattanLength() < 5) @@ -1063,7 +1063,7 @@ void EasyGraphicsView::mouseReleaseEvent(QMouseEvent* _event) if (changedSelection) { - emit intervalChanged(m_selectedBlocks, m_beginTime, position2time(m_chronometerItem->left()), position2time(m_chronometerItem->right()), m_chronometerItem->reverse()); + emit intervalChanged(m_selectedBlocks, m_beginTime, position2time(m_selectionItem->left()), position2time(m_selectionItem->right()), m_selectionItem->reverse()); } if (changedSelectedItem) @@ -1113,7 +1113,7 @@ void EasyGraphicsView::mouseReleaseEvent(QMouseEvent* _event) ////////////////////////////////////////////////////////////////////////// -bool EasyGraphicsView::moveChrono(EasyChronometerItem* _chronometerItem, qreal _mouseX) +bool BlocksGraphicsView::moveChrono(GraphicsRulerItem* _chronometerItem, qreal _mouseX) { if (_chronometerItem->reverse()) { @@ -1161,11 +1161,11 @@ bool EasyGraphicsView::moveChrono(EasyChronometerItem* _chronometerItem, qreal _ return false; } -void EasyGraphicsView::mouseMoveEvent(QMouseEvent* _event) +void BlocksGraphicsView::mouseMoveEvent(QMouseEvent* _event) { m_idleTime = 0; - if (m_bEmpty || (m_mouseButtons == 0 && !m_chronometerItem->isVisible() && !m_chronometerItemAux->isVisible())) + if (m_bEmpty || (m_mouseButtons == 0 && !m_selectionItem->isVisible() && !m_rulerItem->isVisible())) { _event->accept(); return; @@ -1188,8 +1188,8 @@ void EasyGraphicsView::mouseMoveEvent(QMouseEvent* _event) if (m_mouseButtons & Qt::RightButton) { - bool showItem = moveChrono(m_chronometerItem, x); - m_pScrollbar->setSelectionPos(m_chronometerItem->left(), m_chronometerItem->right()); + bool showItem = moveChrono(m_selectionItem, x); + m_pScrollbar->setSelectionPos(m_selectionItem->left(), m_selectionItem->right()); if (showItem) { @@ -1203,7 +1203,7 @@ void EasyGraphicsView::mouseMoveEvent(QMouseEvent* _event) { if (m_bDoubleClick) { - moveChrono(m_chronometerItemAux, x); + moveChrono(m_rulerItem, x); } else { @@ -1233,35 +1233,35 @@ void EasyGraphicsView::mouseMoveEvent(QMouseEvent* _event) if (m_mouseButtons == 0) { - if (m_chronometerItem->isVisible()) + if (m_selectionItem->isVisible()) { - auto prevValue = m_chronometerItem->hoverIndicator(); - m_chronometerItem->setHoverIndicator(m_chronometerItem->indicatorContains(mouseScenePos)); - needUpdate = needUpdate || (prevValue != m_chronometerItem->hoverIndicator()); + auto prevValue = m_selectionItem->hoverIndicator(); + m_selectionItem->setHoverIndicator(m_selectionItem->indicatorContains(mouseScenePos)); + needUpdate = needUpdate || (prevValue != m_selectionItem->hoverIndicator()); - prevValue = m_chronometerItem->hoverLeft(); - m_chronometerItem->setHoverLeft(m_chronometerItem->hoverLeft(mouseScenePos.x())); - needUpdate = needUpdate || (prevValue != m_chronometerItem->hoverLeft()); + prevValue = m_selectionItem->hoverLeft(); + m_selectionItem->setHoverLeft(m_selectionItem->hoverLeft(mouseScenePos.x())); + needUpdate = needUpdate || (prevValue != m_selectionItem->hoverLeft()); - if (!m_chronometerItem->hoverLeft()) + if (!m_selectionItem->hoverLeft()) { - prevValue = m_chronometerItem->hoverRight(); - m_chronometerItem->setHoverRight(m_chronometerItem->hoverRight(mouseScenePos.x())); - needUpdate = needUpdate || (prevValue != m_chronometerItem->hoverRight()); + prevValue = m_selectionItem->hoverRight(); + m_selectionItem->setHoverRight(m_selectionItem->hoverRight(mouseScenePos.x())); + needUpdate = needUpdate || (prevValue != m_selectionItem->hoverRight()); } } - if (m_chronometerItemAux->isVisible()) + if (m_rulerItem->isVisible()) { - auto prevValue = m_chronometerItemAux->hoverLeft(); - m_chronometerItemAux->setHoverLeft(m_chronometerItemAux->hoverLeft(mouseScenePos.x())); - needUpdate = needUpdate || (prevValue != m_chronometerItemAux->hoverLeft()); + auto prevValue = m_rulerItem->hoverLeft(); + m_rulerItem->setHoverLeft(m_rulerItem->hoverLeft(mouseScenePos.x())); + needUpdate = needUpdate || (prevValue != m_rulerItem->hoverLeft()); - if (!m_chronometerItemAux->hoverLeft()) + if (!m_rulerItem->hoverLeft()) { - prevValue = m_chronometerItemAux->hoverRight(); - m_chronometerItemAux->setHoverRight(m_chronometerItemAux->hoverRight(mouseScenePos.x())); - needUpdate = needUpdate || (prevValue != m_chronometerItemAux->hoverRight()); + prevValue = m_rulerItem->hoverRight(); + m_rulerItem->setHoverRight(m_rulerItem->hoverRight(mouseScenePos.x())); + needUpdate = needUpdate || (prevValue != m_rulerItem->hoverRight()); } } } @@ -1276,7 +1276,7 @@ void EasyGraphicsView::mouseMoveEvent(QMouseEvent* _event) ////////////////////////////////////////////////////////////////////////// -void EasyGraphicsView::keyPressEvent(QKeyEvent* _event) +void BlocksGraphicsView::keyPressEvent(QKeyEvent* _event) { static const int KeyStep = 100; @@ -1333,7 +1333,7 @@ void EasyGraphicsView::keyPressEvent(QKeyEvent* _event) _event->accept(); } -void EasyGraphicsView::keyReleaseEvent(QKeyEvent* _event) +void BlocksGraphicsView::keyReleaseEvent(QKeyEvent* _event) { //const int key = _event->key(); m_idleTime = 0; @@ -1344,7 +1344,7 @@ void EasyGraphicsView::keyReleaseEvent(QKeyEvent* _event) ////////////////////////////////////////////////////////////////////////// -void EasyGraphicsView::resizeEvent(QResizeEvent* _event) +void BlocksGraphicsView::resizeEvent(QResizeEvent* _event) { Parent::resizeEvent(_event); @@ -1369,7 +1369,7 @@ void EasyGraphicsView::resizeEvent(QResizeEvent* _event) ////////////////////////////////////////////////////////////////////////// -void EasyGraphicsView::initMode() +void BlocksGraphicsView::initMode() { // TODO: find mode with least number of bugs :) // There are always some display bugs... @@ -1385,13 +1385,13 @@ void EasyGraphicsView::initMode() connect(&m_idleTimer, &QTimer::timeout, this, &This::onIdleTimeout); auto globalSignals = &EASY_GLOBALS.events; - connect(globalSignals, &::profiler_gui::EasyGlobalSignals::hierarchyFlagChanged, this, &This::onHierarchyFlagChange); - connect(globalSignals, &::profiler_gui::EasyGlobalSignals::selectedThreadChanged, this, &This::onSelectedThreadChange); - connect(globalSignals, &::profiler_gui::EasyGlobalSignals::selectedBlockChanged, this, &This::onSelectedBlockChange); - connect(globalSignals, &::profiler_gui::EasyGlobalSignals::itemsExpandStateChanged, this, &This::onRefreshRequired); - connect(globalSignals, &::profiler_gui::EasyGlobalSignals::refreshRequired, this, &This::onRefreshRequired); + connect(globalSignals, &::profiler_gui::GlobalSignals::hierarchyFlagChanged, this, &This::onHierarchyFlagChange); + connect(globalSignals, &::profiler_gui::GlobalSignals::selectedThreadChanged, this, &This::onSelectedThreadChange); + connect(globalSignals, &::profiler_gui::GlobalSignals::selectedBlockChanged, this, &This::onSelectedBlockChange); + connect(globalSignals, &::profiler_gui::GlobalSignals::itemsExpandStateChanged, this, &This::onRefreshRequired); + connect(globalSignals, &::profiler_gui::GlobalSignals::refreshRequired, this, &This::onRefreshRequired); - connect(globalSignals, &::profiler_gui::EasyGlobalSignals::selectedBlockIdChanged, [this](::profiler::block_id_t) + connect(globalSignals, &::profiler_gui::GlobalSignals::selectedBlockIdChanged, [this](::profiler::block_id_t) { if (::profiler_gui::is_max(EASY_GLOBALS.selected_block_id)) { @@ -1416,22 +1416,22 @@ void EasyGraphicsView::initMode() onRefreshRequired(); }); - connect(globalSignals, &::profiler_gui::EasyGlobalSignals::threadNameDecorationChanged, this, &This::onThreadViewChanged); - connect(globalSignals, &::profiler_gui::EasyGlobalSignals::hexThreadIdChanged, this, &This::onThreadViewChanged); + connect(globalSignals, &::profiler_gui::GlobalSignals::threadNameDecorationChanged, this, &This::onThreadViewChanged); + connect(globalSignals, &::profiler_gui::GlobalSignals::hexThreadIdChanged, this, &This::onThreadViewChanged); - connect(globalSignals, &::profiler_gui::EasyGlobalSignals::blocksTreeModeChanged, [this]() + connect(globalSignals, &::profiler_gui::GlobalSignals::blocksTreeModeChanged, [this]() { if (!m_selectedBlocks.empty()) - emit intervalChanged(m_selectedBlocks, m_beginTime, position2time(m_chronometerItem->left()), position2time(m_chronometerItem->right()), m_chronometerItem->reverse()); + emit intervalChanged(m_selectedBlocks, m_beginTime, position2time(m_selectionItem->left()), position2time(m_selectionItem->right()), m_selectionItem->reverse()); }); - connect(globalSignals, &profiler_gui::EasyGlobalSignals::chartSliderChanged, this, &This::onGraphicsScrollbarValueChange); - connect(globalSignals, &profiler_gui::EasyGlobalSignals::chartWheeled, this, &This::onGraphicsScrollbarWheel); + connect(globalSignals, &profiler_gui::GlobalSignals::chartSliderChanged, this, &This::onGraphicsScrollbarValueChange); + connect(globalSignals, &profiler_gui::GlobalSignals::chartWheeled, this, &This::onGraphicsScrollbarWheel); } ////////////////////////////////////////////////////////////////////////// -void EasyGraphicsView::onThreadViewChanged() +void BlocksGraphicsView::onThreadViewChanged() { if (m_bEmpty) return; @@ -1449,13 +1449,13 @@ void EasyGraphicsView::onThreadViewChanged() ////////////////////////////////////////////////////////////////////////// -void EasyGraphicsView::onScrollbarValueChange(int) +void BlocksGraphicsView::onScrollbarValueChange(int) { if (!m_bUpdatingRect && !m_bEmpty) updateVisibleSceneRect(); } -void EasyGraphicsView::onGraphicsScrollbarValueChange(qreal _value) +void BlocksGraphicsView::onGraphicsScrollbarValueChange(qreal _value) { if (!m_bEmpty) { @@ -1470,7 +1470,7 @@ void EasyGraphicsView::onGraphicsScrollbarValueChange(qreal _value) ////////////////////////////////////////////////////////////////////////// -void EasyGraphicsView::onFlickerTimeout() +void BlocksGraphicsView::onFlickerTimeout() { ++m_flickerCounterX; ++m_flickerCounterY; @@ -1531,7 +1531,7 @@ void EasyGraphicsView::onFlickerTimeout() ////////////////////////////////////////////////////////////////////////// -void EasyGraphicsView::onIdleTimeout() +void BlocksGraphicsView::onIdleTimeout() { m_idleTime += IDLE_TIMER_INTERVAL; @@ -1574,7 +1574,7 @@ void EasyGraphicsView::onIdleTimeout() return; int row = 0; - lay->addWidget(new EasyBoldLabel("Context switch event", widget), row, 0, 1, 3, Qt::AlignHCenter); + lay->addWidget(new BoldLabel("Context switch event", widget), row, 0, 1, 3, Qt::AlignHCenter); ++row; lay->addWidget(new QLabel("Thread:", widget), row, 0, Qt::AlignRight); @@ -1622,7 +1622,7 @@ void EasyGraphicsView::onIdleTimeout() lay->addWidget(new QLabel(::profiler_gui::timeStringRealNs(EASY_GLOBALS.time_units, itemBlock.per_thread_stats->total_duration, 3), widget), row, 1, 1, 2, Qt::AlignLeft); ++row; - lay->addWidget(new EasyBoldLabel("-------- Statistics --------", widget), row, 0, 1, 3, Qt::AlignHCenter); + lay->addWidget(new BoldLabel("-------- Statistics --------", widget), row, 0, 1, 3, Qt::AlignHCenter); lay->addWidget(new QLabel("per ", widget), row + 1, 0, Qt::AlignRight); lay->addWidget(new QLabel("This %:", widget), row + 2, 0, Qt::AlignRight); lay->addWidget(new QLabel("Sum %:", widget), row + 3, 0, Qt::AlignRight); @@ -1689,7 +1689,7 @@ void EasyGraphicsView::onIdleTimeout() const auto name = *itemBlock.node->name() != 0 ? itemBlock.node->name() : itemDesc.name(); //lay->addWidget(new QLabel("Name:", widget), row, 0, Qt::AlignRight); - lay->addWidget(new EasyBoldLabel(::profiler_gui::toUnicode(name), widget), row, 0, 1, 5, + lay->addWidget(new BoldLabel(::profiler_gui::toUnicode(name), widget), row, 0, 1, 5, Qt::AlignHCenter); ++row; @@ -1721,7 +1721,7 @@ void EasyGraphicsView::onIdleTimeout() { const auto name = *itemBlock.node->name() != 0 ? itemBlock.node->name() : itemDesc.name(); - lay->addWidget(new EasyBoldLabel("User defined event", widget), row, 0, 1, 2, Qt::AlignHCenter); + lay->addWidget(new BoldLabel("User defined event", widget), row, 0, 1, 2, Qt::AlignHCenter); ++row; lay->addWidget(new QLabel("Name:", widget), row, 0, Qt::AlignRight); @@ -1733,7 +1733,7 @@ void EasyGraphicsView::onIdleTimeout() case ::profiler::BlockType::Value: { - lay->addWidget(new EasyBoldLabel("Arbitrary Value", widget), row, 0, 1, 2, Qt::AlignHCenter); + lay->addWidget(new BoldLabel("Arbitrary Value", widget), row, 0, 1, 2, Qt::AlignHCenter); ++row; lay->addWidget(new QLabel("Name:", widget), row, 0, Qt::AlignRight); @@ -1809,7 +1809,7 @@ void EasyGraphicsView::onIdleTimeout() ++row; } - lay->addWidget(new EasyBoldLabel("-------- Statistics --------", widget), row, 0, 1, 5, Qt::AlignHCenter); + lay->addWidget(new BoldLabel("-------- Statistics --------", widget), row, 0, 1, 5, Qt::AlignHCenter); lay->addWidget(new QLabel("per ", widget), row + 1, 0, Qt::AlignRight); lay->addWidget(new QLabel("This %:", widget), row + 2, 0, Qt::AlignRight); lay->addWidget(new QLabel("Sum %:", widget), row + 3, 0, Qt::AlignRight); @@ -1906,7 +1906,7 @@ void EasyGraphicsView::onIdleTimeout() ////////////////////////////////////////////////////////////////////////// -void EasyGraphicsView::onHierarchyFlagChange(bool) +void BlocksGraphicsView::onHierarchyFlagChange(bool) { bool changedSelection = false; @@ -1916,12 +1916,12 @@ void EasyGraphicsView::onHierarchyFlagChange(bool) m_selectedBlocks.clear(); } - if (m_chronometerItem->isVisible()) + if (m_selectionItem->isVisible()) { for (auto item : m_items) { if (!EASY_GLOBALS.only_current_thread_hierarchy || item->threadId() == EASY_GLOBALS.selected_thread) - item->getBlocks(m_chronometerItem->left(), m_chronometerItem->right(), m_selectedBlocks); + item->getBlocks(m_selectionItem->left(), m_selectionItem->right(), m_selectedBlocks); } if (!m_selectedBlocks.empty()) @@ -1932,11 +1932,11 @@ void EasyGraphicsView::onHierarchyFlagChange(bool) if (changedSelection) { - emit intervalChanged(m_selectedBlocks, m_beginTime, position2time(m_chronometerItem->left()), position2time(m_chronometerItem->right()), m_chronometerItem->reverse()); + emit intervalChanged(m_selectedBlocks, m_beginTime, position2time(m_selectionItem->left()), position2time(m_selectionItem->right()), m_selectionItem->reverse()); } } -void EasyGraphicsView::onSelectedThreadChange(::profiler::thread_id_t _id) +void BlocksGraphicsView::onSelectedThreadChange(::profiler::thread_id_t _id) { if (m_pScrollbar == nullptr || m_pScrollbar->hystThread() == _id) { @@ -1964,9 +1964,9 @@ void EasyGraphicsView::onSelectedThreadChange(::profiler::thread_id_t _id) m_selectedBlocks.clear(); } - if (m_chronometerItem->isVisible()) + if (m_selectionItem->isVisible()) { - item->getBlocks(m_chronometerItem->left(), m_chronometerItem->right(), m_selectedBlocks); + item->getBlocks(m_selectionItem->left(), m_selectionItem->right(), m_selectedBlocks); if (!m_selectedBlocks.empty()) changedSelection = true; } @@ -1974,7 +1974,7 @@ void EasyGraphicsView::onSelectedThreadChange(::profiler::thread_id_t _id) if (changedSelection) { - emit intervalChanged(m_selectedBlocks, m_beginTime, position2time(m_chronometerItem->left()), position2time(m_chronometerItem->right()), m_chronometerItem->reverse()); + emit intervalChanged(m_selectedBlocks, m_beginTime, position2time(m_selectionItem->left()), position2time(m_selectionItem->right()), m_selectionItem->reverse()); } repaintScene(); @@ -1988,7 +1988,7 @@ void EasyGraphicsView::onSelectedThreadChange(::profiler::thread_id_t _id) ////////////////////////////////////////////////////////////////////////// -void EasyGraphicsView::onSelectedBlockChange(unsigned int _block_index) +void BlocksGraphicsView::onSelectedBlockChange(unsigned int _block_index) { if (!m_bUpdatingRect) { @@ -2040,7 +2040,7 @@ void EasyGraphicsView::onSelectedBlockChange(unsigned int _block_index) ////////////////////////////////////////////////////////////////////////// -void EasyGraphicsView::onRefreshRequired() +void BlocksGraphicsView::onRefreshRequired() { if (!m_bUpdatingRect) { @@ -2050,17 +2050,17 @@ void EasyGraphicsView::onRefreshRequired() ////////////////////////////////////////////////////////////////////////// -EasyGraphicsViewWidget::EasyGraphicsViewWidget(QWidget* _parent) +DiagramWidget::DiagramWidget(QWidget* _parent) : QWidget(_parent) , m_splitter(new QSplitter(Qt::Vertical, this)) - , m_scrollbar(new EasyGraphicsScrollbar(85 + (QFontMetrics(font()).height() << 1), this)) - , m_view(new EasyGraphicsView(this)) - , m_threadNamesWidget(new EasyThreadNamesWidget(m_view, m_scrollbar->height(), this)) + , m_scrollbar(new BlocksGraphicsScrollbar(85 + (QFontMetrics(font()).height() << 1), this)) + , m_view(new BlocksGraphicsView(this)) + , m_threadNamesWidget(new ThreadNamesWidget(m_view, m_scrollbar->height(), this)) { initWidget(); } -void EasyGraphicsViewWidget::initWidget() +void DiagramWidget::initWidget() { m_splitter->setHandleWidth(1); m_splitter->setContentsMargins(0, 0, 0, 0); @@ -2078,30 +2078,30 @@ void EasyGraphicsViewWidget::initWidget() m_view->setScrollbar(m_scrollbar); } -EasyGraphicsViewWidget::~EasyGraphicsViewWidget() +DiagramWidget::~DiagramWidget() { } -EasyGraphicsView* EasyGraphicsViewWidget::view() +BlocksGraphicsView* DiagramWidget::view() { return m_view; } -void EasyGraphicsViewWidget::clear() +void DiagramWidget::clear() { m_scrollbar->clear(); m_threadNamesWidget->clear(); m_view->clear(); } -void EasyGraphicsViewWidget::save(QSettings& settings) +void DiagramWidget::save(QSettings& settings) { settings.setValue("diagram/vsplitter/geometry", m_splitter->saveGeometry()); settings.setValue("diagram/vsplitter/state", m_splitter->saveState()); } -void EasyGraphicsViewWidget::restore(QSettings& settings) +void DiagramWidget::restore(QSettings& settings) { auto geometry = settings.value("diagram/vsplitter/geometry").toByteArray(); if (!geometry.isEmpty()) @@ -2115,9 +2115,9 @@ void EasyGraphicsViewWidget::restore(QSettings& settings) ////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////// -void EasyThreadNameItem::paint(QPainter* _painter, const QStyleOptionGraphicsItem*, QWidget*) +void ThreadNameItem::paint(QPainter* _painter, const QStyleOptionGraphicsItem*, QWidget*) { - auto const parentView = static_cast(scene()->parent()); + auto const parentView = static_cast(scene()->parent()); const auto view = parentView->view(); const auto& items = view->getItems(); if (items.empty()) @@ -2223,7 +2223,7 @@ void EasyThreadNameItem::paint(QPainter* _painter, const QStyleOptionGraphicsIte ////////////////////////////////////////////////////////////////////////// -EasyThreadNamesWidget::EasyThreadNamesWidget(EasyGraphicsView* _view, int _additionalHeight, QWidget* _parent) +ThreadNamesWidget::ThreadNamesWidget(BlocksGraphicsView* _view, int _additionalHeight, QWidget* _parent) : Parent(_parent) , m_idleTime(0) , m_view(_view) @@ -2241,20 +2241,20 @@ EasyThreadNamesWidget::EasyThreadNamesWidget(EasyGraphicsView* _view, int _addit setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); setFixedWidth(m_maxLength); - connect(&EASY_GLOBALS.events, &::profiler_gui::EasyGlobalSignals::selectedThreadChanged, [this](::profiler::thread_id_t){ repaintScene(); }); - connect(m_view, &EasyGraphicsView::treeChanged, this, &This::onTreeChange); - connect(m_view, &EasyGraphicsView::sceneUpdated, this, &This::repaintScene); + connect(&EASY_GLOBALS.events, &::profiler_gui::GlobalSignals::selectedThreadChanged, [this](::profiler::thread_id_t){ repaintScene(); }); + connect(m_view, &BlocksGraphicsView::treeChanged, this, &This::onTreeChange); + connect(m_view, &BlocksGraphicsView::sceneUpdated, this, &This::repaintScene); connect(m_view->verticalScrollBar(), &QScrollBar::valueChanged, verticalScrollBar(), &QScrollBar::setValue); connect(m_view->verticalScrollBar(), &QScrollBar::rangeChanged, this, &This::setVerticalScrollbarRange); connect(&m_idleTimer, &QTimer::timeout, this, &This::onIdleTimeout); } -EasyThreadNamesWidget::~EasyThreadNamesWidget() +ThreadNamesWidget::~ThreadNamesWidget() { } -void EasyThreadNamesWidget::removePopup(bool _removeFromScene) +void ThreadNamesWidget::removePopup(bool _removeFromScene) { if (m_popupWidget != nullptr) { @@ -2270,7 +2270,7 @@ void EasyThreadNamesWidget::removePopup(bool _removeFromScene) } } -void EasyThreadNamesWidget::clear() +void ThreadNamesWidget::clear() { const QSignalBlocker b(this); removePopup(); @@ -2283,12 +2283,12 @@ void EasyThreadNamesWidget::clear() m_idleTime = 0; } -void EasyThreadNamesWidget::setVerticalScrollbarRange(int _minValue, int _maxValue) +void ThreadNamesWidget::setVerticalScrollbarRange(int _minValue, int _maxValue) { verticalScrollBar()->setRange(_minValue, _maxValue + m_additionalHeight); } -void EasyThreadNamesWidget::onTreeChange() +void ThreadNamesWidget::onTreeChange() { const QSignalBlocker b(this); removePopup(); @@ -2313,7 +2313,7 @@ void EasyThreadNamesWidget::onTreeChange() auto r = m_view->sceneRect(); setSceneRect(0, r.top(), maxLength, r.height() + m_additionalHeight); - auto item = new EasyThreadNameItem(); + auto item = new ThreadNameItem(); item->setPos(0, 0); item->setBoundingRect(sceneRect()); scene()->addItem(item); @@ -2324,7 +2324,7 @@ void EasyThreadNamesWidget::onTreeChange() m_idleTimer.start(IDLE_TIMER_INTERVAL); } -void EasyThreadNamesWidget::onIdleTimeout() +void ThreadNamesWidget::onIdleTimeout() { static const uint16_t OVERLAP = ::profiler_gui::THREADS_ROW_SPACING >> 1; @@ -2356,7 +2356,7 @@ void EasyThreadNamesWidget::onIdleTimeout() return; } - auto const parentView = static_cast(scene()->parent()); + auto const parentView = static_cast(scene()->parent()); const auto view = parentView->view(); if (scenePos.y() > view->visibleSceneRect().bottom()) @@ -2376,7 +2376,7 @@ void EasyThreadNamesWidget::onIdleTimeout() return; } - EasyGraphicsItem* intersectingItem = nullptr; + BlocksGraphicsItem* intersectingItem = nullptr; for (auto item : items) { auto br = item->boundingRect(); @@ -2409,7 +2409,7 @@ void EasyThreadNamesWidget::onIdleTimeout() int row = 0; lay->setSpacing(2); - lay->addWidget(new EasyBoldLabel(intersectingItem->threadName(), widget), row, 0, 1, 2, Qt::AlignHCenter); + lay->addWidget(new BoldLabel(intersectingItem->threadName(), widget), row, 0, 1, 2, Qt::AlignHCenter); ++row; ::profiler::timestamp_t duration = 0; @@ -2490,12 +2490,12 @@ void EasyThreadNamesWidget::onIdleTimeout() } } -void EasyThreadNamesWidget::repaintScene() +void ThreadNamesWidget::repaintScene() { scene()->update(); } -void EasyThreadNamesWidget::mousePressEvent(QMouseEvent* _event) +void ThreadNamesWidget::mousePressEvent(QMouseEvent* _event) { m_idleTime = 0; @@ -2504,7 +2504,7 @@ void EasyThreadNamesWidget::mousePressEvent(QMouseEvent* _event) _event->accept(); } -void EasyThreadNamesWidget::mouseDoubleClickEvent(QMouseEvent* _event) +void ThreadNamesWidget::mouseDoubleClickEvent(QMouseEvent* _event) { static const auto OVERLAP = ::profiler_gui::THREADS_ROW_SPACING >> 1; @@ -2534,7 +2534,7 @@ void EasyThreadNamesWidget::mouseDoubleClickEvent(QMouseEvent* _event) _event->accept(); } -void EasyThreadNamesWidget::mouseReleaseEvent(QMouseEvent* _event) +void ThreadNamesWidget::mouseReleaseEvent(QMouseEvent* _event) { m_idleTime = 0; @@ -2543,7 +2543,7 @@ void EasyThreadNamesWidget::mouseReleaseEvent(QMouseEvent* _event) _event->accept(); } -void EasyThreadNamesWidget::mouseMoveEvent(QMouseEvent* _event) +void ThreadNamesWidget::mouseMoveEvent(QMouseEvent* _event) { m_idleTime = 0; @@ -2552,19 +2552,19 @@ void EasyThreadNamesWidget::mouseMoveEvent(QMouseEvent* _event) _event->accept(); } -void EasyThreadNamesWidget::keyPressEvent(QKeyEvent* _event) +void ThreadNamesWidget::keyPressEvent(QKeyEvent* _event) { m_idleTime = 0; m_view->keyPressEvent(_event); } -void EasyThreadNamesWidget::keyReleaseEvent(QKeyEvent* _event) +void ThreadNamesWidget::keyReleaseEvent(QKeyEvent* _event) { m_idleTime = 0; m_view->keyReleaseEvent(_event); } -void EasyThreadNamesWidget::wheelEvent(QWheelEvent* _event) +void ThreadNamesWidget::wheelEvent(QWheelEvent* _event) { m_idleTime = 0; diff --git a/profiler_gui/blocks_graphics_view.h b/profiler_gui/blocks_graphics_view.h index c486b39..4505421 100644 --- a/profiler_gui/blocks_graphics_view.h +++ b/profiler_gui/blocks_graphics_view.h @@ -15,7 +15,7 @@ * : * : * 2016/06/30 Victor Zarubkin: Replaced doubles with floats (in ProfBlockItem) for less memory consumption. * : -* : * 2016/09/15 Victor Zarubkin: Moved sources of EasyGraphicsItem and EasyChronometerItem to separate files. +* : * 2016/09/15 Victor Zarubkin: Moved sources of BlocksGraphicsItem and GraphicsRulerItem to separate files. * : * : * * ----------------- : @@ -81,10 +81,10 @@ ////////////////////////////////////////////////////////////////////////// class QGraphicsProxyWidget; -class EasyGraphicsView; -class EasyGraphicsItem; -class EasyGraphicsScrollbar; -class EasyChronometerItem; +class BlocksGraphicsView; +class BlocksGraphicsItem; +class BlocksGraphicsScrollbar; +class GraphicsRulerItem; ////////////////////////////////////////////////////////////////////////// @@ -100,35 +100,35 @@ public: \ void setBoundingRect(const QRectF& _rect) { m_boundingRect = _rect; } \ } -EASY_QGRAPHICSITEM(EasyBackgroundItem); -EASY_QGRAPHICSITEM(EasyTimelineIndicatorItem); -EASY_QGRAPHICSITEM(EasyThreadNameItem); +EASY_QGRAPHICSITEM(BackgroundItem); +EASY_QGRAPHICSITEM(TimelineIndicatorItem); +EASY_QGRAPHICSITEM(ThreadNameItem); #undef EASY_QGRAPHICSITEM ////////////////////////////////////////////////////////////////////////// -struct EasyBoldLabel : public QLabel { - EasyBoldLabel(const QString& _text, QWidget* _parent = nullptr); - virtual ~EasyBoldLabel(); +struct BoldLabel : public QLabel { + BoldLabel(const QString& _text, QWidget* _parent = nullptr); + ~BoldLabel() override; }; ////////////////////////////////////////////////////////////////////////// -class EasyGraphicsView : public QGraphicsView +class BlocksGraphicsView : public QGraphicsView { Q_OBJECT private: using Parent = QGraphicsView; - using This = EasyGraphicsView; - using Items = ::std::vector; + using This = BlocksGraphicsView; + using Items = ::std::vector; //using Keys = ::std::unordered_set >; - Items m_items; ///< Array of all EasyGraphicsItem items + Items m_items; ///< Array of all BlocksGraphicsItem items //Keys m_keys; ///< Pressed keyboard keys - ::profiler_gui::TreeBlocks m_selectedBlocks; ///< Array of items which were selected by selection zone (EasyChronometerItem) + ::profiler_gui::TreeBlocks m_selectedBlocks; ///< Array of items which were selected by selection zone (GraphicsRulerItem) QTimer m_flickerTimer; ///< Timer for flicking behavior QTimer m_idleTimer; ///< QRectF m_visibleSceneRect; ///< Visible scene rectangle @@ -142,9 +142,9 @@ private: QPoint m_mousePressPos; ///< Last mouse global position (used by mousePressEvent and mouseMoveEvent) QPoint m_mouseMovePath; ///< Mouse move path between press and release of any button Qt::MouseButtons m_mouseButtons; ///< Pressed mouse buttons - EasyGraphicsScrollbar* m_pScrollbar; ///< Pointer to the graphics scrollbar widget - EasyChronometerItem* m_chronometerItem; ///< Pointer to the EasyChronometerItem which is displayed when you press right mouse button and move mouse left or right. This item is used to select blocks to display in tree widget. - EasyChronometerItem* m_chronometerItemAux; ///< Pointer to the EasyChronometerItem which is displayed when you double click left mouse button and move mouse left or right. This item is used only to measure time. + BlocksGraphicsScrollbar* m_pScrollbar; ///< Pointer to the graphics scrollbar widget + GraphicsRulerItem* m_selectionItem; ///< Pointer to the GraphicsRulerItem which is displayed when you press right mouse button and move mouse left or right. This item is used to select blocks to display in tree widget. + GraphicsRulerItem* m_rulerItem; ///< Pointer to the GraphicsRulerItem which is displayed when you double click left mouse button and move mouse left or right. This item is used only to measure time. QGraphicsProxyWidget* m_popupWidget; ///< int m_flickerSpeedX; ///< Current flicking speed x int m_flickerSpeedY; ///< Current flicking speed y @@ -156,8 +156,8 @@ private: public: - explicit EasyGraphicsView(QWidget* _parent = nullptr); - ~EasyGraphicsView() override; + explicit BlocksGraphicsView(QWidget* _parent = nullptr); + ~BlocksGraphicsView() override; // Public virtual methods @@ -180,7 +180,7 @@ public: qreal chronoTime() const; qreal chronoTimeAux() const; - void setScrollbar(EasyGraphicsScrollbar* _scrollbar); + void setScrollbar(BlocksGraphicsScrollbar* _scrollbar); void clear(); void setTree(const ::profiler::thread_blocks_tree_t& _blocksTree); @@ -207,16 +207,16 @@ private: void removePopup(bool _removeFromScene = false); - EasyChronometerItem* createChronometer(bool _main = true); - bool moveChrono(EasyChronometerItem* _chronometerItem, qreal _mouseX); + GraphicsRulerItem* createChronometer(bool _main = true); + bool moveChrono(GraphicsRulerItem* _chronometerItem, qreal _mouseX); void initMode(); int updateVisibleSceneRect(); void updateTimelineStep(qreal _windowWidth); void scaleTo(qreal _scale); - void scrollTo(const EasyGraphicsItem* _item); + void scrollTo(const BlocksGraphicsItem* _item); qreal mapToDiagram(qreal x) const; void onWheel(qreal _scenePos, int _wheelDelta); - qreal setTree(EasyGraphicsItem* _item, const ::profiler::BlocksTree::children_t& _children, qreal& _height, uint32_t& _maxDepthChild, qreal _y, short _level); + qreal setTree(BlocksGraphicsItem* _item, const ::profiler::BlocksTree::children_t& _children, qreal& _height, uint32_t& _maxDepthChild, qreal _y, short _level); private slots: @@ -270,30 +270,30 @@ public: //return PROF_FROM_MILLISECONDS(_pos); } -}; // END of class EasyGraphicsView. +}; // END of class BlocksGraphicsView. ////////////////////////////////////////////////////////////////////////// -class EasyThreadNamesWidget : public QGraphicsView +class ThreadNamesWidget : public QGraphicsView { Q_OBJECT private: using Parent = QGraphicsView; - using This = EasyThreadNamesWidget; + using This = ThreadNamesWidget; QTimer m_idleTimer; ///< uint64_t m_idleTime; ///< - EasyGraphicsView* m_view; ///< + BlocksGraphicsView* m_view; ///< QGraphicsProxyWidget* m_popupWidget; ///< int m_maxLength; ///< const int m_additionalHeight; ///< public: - explicit EasyThreadNamesWidget(EasyGraphicsView* _view, int _additionalHeight, QWidget* _parent = nullptr); - ~EasyThreadNamesWidget() override; + explicit ThreadNamesWidget(BlocksGraphicsView* _view, int _additionalHeight, QWidget* _parent = nullptr); + ~ThreadNamesWidget() override; void mousePressEvent(QMouseEvent* _event) override; void mouseDoubleClickEvent(QMouseEvent* _event) override; @@ -307,7 +307,7 @@ public: void clear(); - const EasyGraphicsView* view() const + const BlocksGraphicsView* view() const { return m_view; } @@ -323,27 +323,27 @@ private slots: void onIdleTimeout(); void repaintScene(); -}; // END of class EasyThreadNamesWidget. +}; // END of class ThreadNamesWidget. ////////////////////////////////////////////////////////////////////////// -class EasyGraphicsViewWidget : public QWidget +class DiagramWidget : public QWidget { Q_OBJECT private: - class QSplitter* m_splitter; - EasyGraphicsScrollbar* m_scrollbar; - EasyGraphicsView* m_view; - EasyThreadNamesWidget* m_threadNamesWidget; + class QSplitter* m_splitter; + BlocksGraphicsScrollbar* m_scrollbar; + BlocksGraphicsView* m_view; + ThreadNamesWidget* m_threadNamesWidget; public: - explicit EasyGraphicsViewWidget(QWidget* _parent = nullptr); - ~EasyGraphicsViewWidget() override; + explicit DiagramWidget(QWidget* _parent = nullptr); + ~DiagramWidget() override; - EasyGraphicsView* view(); + BlocksGraphicsView* view(); void clear(); void save(class QSettings& settings); @@ -353,7 +353,7 @@ private: void initWidget(); -}; // END of class EasyGraphicsViewWidget. +}; // END of class DiagramWidget. ////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////// diff --git a/profiler_gui/blocks_tree_widget.cpp b/profiler_gui/blocks_tree_widget.cpp index ef29d90..29f9856 100644 --- a/profiler_gui/blocks_tree_widget.cpp +++ b/profiler_gui/blocks_tree_widget.cpp @@ -5,7 +5,7 @@ * author : Victor Zarubkin * email : v.s.zarubkin@gmail.com * ----------------- : -* description : The file contains implementation of EasyTreeWidget and it's auxiliary classes +* description : The file contains implementation of BlocksTreeWidget and it's auxiliary classes * : for displyaing easy_profiler blocks tree. * ----------------- : * change log : * 2016/06/26 Victor Zarubkin: Moved sources from tree_view.h @@ -79,6 +79,7 @@ #include #include #include +#include #include "blocks_tree_widget.h" #include "globals.h" @@ -136,13 +137,13 @@ const bool SIMPLIFIED_REGIME_COLUMNS[COL_COLUMNS_NUMBER] = { ////////////////////////////////////////////////////////////////////////// -EasyTreeWidget::EasyTreeWidget(QWidget* _parent) +BlocksTreeWidget::BlocksTreeWidget(QWidget* _parent) : Parent(_parent) , m_beginTime(::std::numeric_limits::max()) , m_lastFound(nullptr) , m_progress(nullptr) , m_hintLabel(nullptr) - , m_mode(EasyTreeMode_Plain) + , m_mode(TreeMode::Plain) , m_bLocked(false) , m_bSilentExpandCollapse(false) { @@ -159,7 +160,7 @@ EasyTreeWidget::EasyTreeWidget(QWidget* _parent) auto header_item = new QTreeWidgetItem(); auto f = header()->font(); f.setBold(true); - header()->setFont(f);// ::profiler_gui::EFont("Helvetica", 9, QFont::Bold)); + header()->setFont(f);// profiler_gui::EFont("Helvetica", 9, QFont::Bold)); header_item->setText(COL_NAME, "Name"); @@ -199,7 +200,7 @@ EasyTreeWidget::EasyTreeWidget(QWidget* _parent) header_item->setText(COL_ACTIVE_TIME, "Active time"); header_item->setText(COL_ACTIVE_PERCENT, "Active %"); - auto color = QColor::fromRgb(::profiler::colors::DeepOrange900); + auto color = QColor::fromRgb(profiler::colors::DeepOrange900); header_item->setForeground(COL_MIN_PER_THREAD, color); header_item->setForeground(COL_MAX_PER_THREAD, color); header_item->setForeground(COL_AVERAGE_PER_THREAD, color); @@ -207,7 +208,7 @@ EasyTreeWidget::EasyTreeWidget(QWidget* _parent) header_item->setForeground(COL_PERCENT_SUM_PER_THREAD, color); header_item->setForeground(COL_DURATION_SUM_PER_THREAD, color); - color = QColor::fromRgb(::profiler::colors::Blue900); + color = QColor::fromRgb(profiler::colors::Blue900); header_item->setForeground(COL_MIN_PER_FRAME, color); header_item->setForeground(COL_MAX_PER_FRAME, color); header_item->setForeground(COL_AVERAGE_PER_FRAME, color); @@ -216,7 +217,7 @@ EasyTreeWidget::EasyTreeWidget(QWidget* _parent) header_item->setForeground(COL_DURATION_SUM_PER_FRAME, color); header_item->setForeground(COL_PERCENT_PER_FRAME, color); - color = QColor::fromRgb(::profiler::colors::Teal900); + color = QColor::fromRgb(profiler::colors::Teal900); header_item->setForeground(COL_MIN_PER_PARENT, color); header_item->setForeground(COL_MAX_PER_PARENT, color); header_item->setForeground(COL_AVERAGE_PER_PARENT, color); @@ -227,8 +228,8 @@ EasyTreeWidget::EasyTreeWidget(QWidget* _parent) setHeaderItem(header_item); - connect(&EASY_GLOBALS.events, &::profiler_gui::EasyGlobalSignals::selectedThreadChanged, this, &This::onSelectedThreadChange, Qt::QueuedConnection); - connect(&EASY_GLOBALS.events, &::profiler_gui::EasyGlobalSignals::selectedBlockChanged, this, &This::onSelectedBlockChange, Qt::QueuedConnection); + connect(&EASY_GLOBALS.events, &profiler_gui::GlobalSignals::selectedThreadChanged, this, &This::onSelectedThreadChange, Qt::QueuedConnection); + connect(&EASY_GLOBALS.events, &profiler_gui::GlobalSignals::selectedBlockChanged, this, &This::onSelectedBlockChange, Qt::QueuedConnection); connect(&m_fillTimer, &QTimer::timeout, this, &This::onFillTimerTimeout); loadSettings(); @@ -236,7 +237,7 @@ EasyTreeWidget::EasyTreeWidget(QWidget* _parent) m_columnsHiddenStatus[0] = 0; setColumnHidden(0, false); - if (m_mode == EasyTreeMode_Full) + if (m_mode == TreeMode::Full) { for (int i = 1; i < COL_COLUMNS_NUMBER; ++i) m_columnsHiddenStatus[i] = isColumnHidden(i) ? 1 : 0; @@ -266,14 +267,14 @@ EasyTreeWidget::EasyTreeWidget(QWidget* _parent) setItemDelegateForColumn(0, new EasyItemDelegate(this)); } -EasyTreeWidget::~EasyTreeWidget() +BlocksTreeWidget::~BlocksTreeWidget() { saveSettings(); } ////////////////////////////////////////////////////////////////////////// -void EasyTreeWidget::onFillTimerTimeout() +void BlocksTreeWidget::onFillTimerTimeout() { if (m_hierarchyBuilder.done()) { @@ -300,7 +301,7 @@ void EasyTreeWidget::onFillTimerTimeout() setSortingEnabled(true); sortByColumn(COL_BEGIN, Qt::AscendingOrder); // sort by begin time - if (m_mode == EasyTreeMode_Plain) // and after that, sort by frame % + if (m_mode == TreeMode::Plain) // and after that, sort by frame % sortByColumn(COL_PERCENT_PER_FRAME, Qt::DescendingOrder); //resizeColumnToContents(COL_NAME); @@ -318,7 +319,7 @@ void EasyTreeWidget::onFillTimerTimeout() } } -void EasyTreeWidget::setTree(const unsigned int _blocksNumber, const ::profiler::thread_blocks_tree_t& _blocksTree) +void BlocksTreeWidget::setTree(const unsigned int _blocksNumber, const profiler::thread_blocks_tree_t& _blocksTree) { clearSilent(); @@ -346,7 +347,7 @@ void EasyTreeWidget::setTree(const unsigned int _blocksNumber, const ::profiler: //} } -void EasyTreeWidget::setTreeBlocks(const ::profiler_gui::TreeBlocks& _blocks, ::profiler::timestamp_t _session_begin_time, ::profiler::timestamp_t _left, ::profiler::timestamp_t _right, bool _strict) +void BlocksTreeWidget::setTreeBlocks(const profiler_gui::TreeBlocks& _blocks, profiler::timestamp_t _session_begin_time, profiler::timestamp_t _left, profiler::timestamp_t _right, bool _strict) { clearSilent(); @@ -389,7 +390,7 @@ void EasyTreeWidget::setTreeBlocks(const ::profiler_gui::TreeBlocks& _blocks, :: ////////////////////////////////////////////////////////////////////////// -void EasyTreeWidget::clearSilent(bool _global) +void BlocksTreeWidget::clearSilent(bool _global) { const QSignalBlocker b(this); @@ -419,7 +420,7 @@ void EasyTreeWidget::clearSilent(bool _global) #ifdef EASY_TREE_WIDGET__USE_VECTOR auto& gui_block = item->guiBlock(); gui_block.expanded = false; - ::profiler_gui::set_max(gui_block.tree_item); + profiler_gui::set_max(gui_block.tree_item); #else item.second->guiBlock().expanded = false; #endif @@ -427,7 +428,7 @@ void EasyTreeWidget::clearSilent(bool _global) #ifdef EASY_TREE_WIDGET__USE_VECTOR else for (auto item : m_items) { - ::profiler_gui::set_max(item->guiBlock().tree_item); + profiler_gui::set_max(item->guiBlock().tree_item); } #endif } @@ -461,7 +462,7 @@ void EasyTreeWidget::clearSilent(bool _global) ////////////////////////////////////////////////////////////////////////// -int EasyTreeWidget::findNext(const QString& _str, Qt::MatchFlags _flags) +int BlocksTreeWidget::findNext(const QString& _str, Qt::MatchFlags _flags) { if (m_bLocked || _str.isEmpty()) return 0; @@ -511,7 +512,7 @@ int EasyTreeWidget::findNext(const QString& _str, Qt::MatchFlags _flags) return itemsList.size(); } -int EasyTreeWidget::findPrev(const QString& _str, Qt::MatchFlags _flags) +int BlocksTreeWidget::findPrev(const QString& _str, Qt::MatchFlags _flags) { if (m_bLocked || _str.isEmpty()) return 0; @@ -559,7 +560,7 @@ int EasyTreeWidget::findPrev(const QString& _str, Qt::MatchFlags _flags) ////////////////////////////////////////////////////////////////////////// -void EasyTreeWidget::contextMenuEvent(QContextMenuEvent* _event) +void BlocksTreeWidget::contextMenuEvent(QContextMenuEvent* _event) { if (m_bLocked) { @@ -568,7 +569,7 @@ void EasyTreeWidget::contextMenuEvent(QContextMenuEvent* _event) } const auto col = currentColumn(); - auto item = static_cast(currentItem()); + auto item = static_cast(currentItem()); QMenu menu; menu.setToolTipsVisible(true); QAction* action = nullptr; @@ -604,16 +605,16 @@ void EasyTreeWidget::contextMenuEvent(QContextMenuEvent* _event) auto actionHierarchy = new QAction("Hierarchy mode", actionGroup); actionHierarchy->setCheckable(true); - actionHierarchy->setChecked(m_mode == EasyTreeMode_Full); + actionHierarchy->setChecked(m_mode == TreeMode::Full); actionHierarchy->setToolTip("Display full blocks hierarchy"); - actionHierarchy->setData((quint32)EasyTreeMode_Full); + actionHierarchy->setData((quint32)TreeMode::Full); menu.addAction(actionHierarchy); auto actionPlain = new QAction("Plain mode", actionGroup); actionPlain->setCheckable(true); - actionPlain->setChecked(m_mode == EasyTreeMode_Plain); + actionPlain->setChecked(m_mode == TreeMode::Plain); actionPlain->setToolTip("Display plain list of blocks per frame.\nSome columns are disabled with this mode."); - actionPlain->setData((quint32)EasyTreeMode_Plain); + actionPlain->setData((quint32)TreeMode::Plain); menu.addAction(actionPlain); connect(actionHierarchy, &QAction::triggered, this, &This::onModeChange); @@ -635,7 +636,7 @@ void EasyTreeWidget::contextMenuEvent(QContextMenuEvent* _event) case COL_MAX_PER_FRAME: { auto& block = item->block(); - auto i = ::profiler_gui::numeric_max(); + auto i = profiler_gui::numeric_max(); switch (col) { case COL_MIN_PER_THREAD: i = block.per_thread_stats->min_duration_block; break; @@ -646,7 +647,7 @@ void EasyTreeWidget::contextMenuEvent(QContextMenuEvent* _event) case COL_MAX_PER_FRAME: i = block.per_frame_stats->max_duration_block; break; } - if (i != ::profiler_gui::numeric_max(i)) + if (i != profiler_gui::numeric_max(i)) { menu.addSeparator(); auto itemAction = new QAction("Jump to such item", nullptr); @@ -676,12 +677,12 @@ void EasyTreeWidget::contextMenuEvent(QContextMenuEvent* _event) action->setToolTip(ToolTipValue);\ connect(action, &QAction::triggered, this, &This::onBlockStatusChangeClicked) - ADD_STATUS_ACTION("Off", ::profiler::OFF, "Do not profile this block."); - ADD_STATUS_ACTION("On", ::profiler::ON, "Profile this block\nif parent enabled children."); - ADD_STATUS_ACTION("Force-On", ::profiler::FORCE_ON, "Always profile this block even\nif it's parent disabled children."); - ADD_STATUS_ACTION("Off-recursive", ::profiler::OFF_RECURSIVE, "Do not profile neither this block\nnor it's children."); - ADD_STATUS_ACTION("On-without-children", ::profiler::ON_WITHOUT_CHILDREN, "Profile this block, but\ndo not profile it's children."); - ADD_STATUS_ACTION("Force-On-without-children", ::profiler::FORCE_ON_WITHOUT_CHILDREN, "Always profile this block, but\ndo not profile it's children."); + ADD_STATUS_ACTION("Off", profiler::OFF, "Do not profile this block."); + ADD_STATUS_ACTION("On", profiler::ON, "Profile this block\nif parent enabled children."); + ADD_STATUS_ACTION("Force-On", profiler::FORCE_ON, "Always profile this block even\nif it's parent disabled children."); + ADD_STATUS_ACTION("Off-recursive", profiler::OFF_RECURSIVE, "Do not profile neither this block\nnor it's children."); + ADD_STATUS_ACTION("On-without-children", profiler::ON_WITHOUT_CHILDREN, "Profile this block, but\ndo not profile it's children."); + ADD_STATUS_ACTION("Force-On-without-children", profiler::FORCE_ON_WITHOUT_CHILDREN, "Always profile this block, but\ndo not profile it's children."); #undef ADD_STATUS_ACTION submenu->setEnabled(EASY_GLOBALS.connected); @@ -698,7 +699,7 @@ void EasyTreeWidget::contextMenuEvent(QContextMenuEvent* _event) columnAction->setData(i); columnAction->setCheckable(true); columnAction->setChecked(m_columnsHiddenStatus[i] == 0); - if ((m_mode == EasyTreeMode_Full || SIMPLIFIED_REGIME_COLUMNS[i])) + if ((m_mode == TreeMode::Full || SIMPLIFIED_REGIME_COLUMNS[i])) connect(columnAction, &QAction::triggered, this, &This::onHideShowColumn); else columnAction->setEnabled(false); @@ -712,19 +713,19 @@ void EasyTreeWidget::contextMenuEvent(QContextMenuEvent* _event) ////////////////////////////////////////////////////////////////////////// -void EasyTreeWidget::resizeEvent(QResizeEvent* _event) +void BlocksTreeWidget::resizeEvent(QResizeEvent* _event) { Parent::resizeEvent(_event); alignProgressBar(); } -void EasyTreeWidget::moveEvent(QMoveEvent* _event) +void BlocksTreeWidget::moveEvent(QMoveEvent* _event) { Parent::moveEvent(_event); alignProgressBar(); } -void EasyTreeWidget::alignProgressBar() +void BlocksTreeWidget::alignProgressBar() { auto center = rect().center(); auto pos = mapToGlobal(center); @@ -735,7 +736,7 @@ void EasyTreeWidget::alignProgressBar() m_hintLabel->move(center.x() - (m_hintLabel->width() >> 1), std::max(center.y() - (m_hintLabel->height() >> 1), header()->height())); } -void EasyTreeWidget::destroyProgressDialog() +void BlocksTreeWidget::destroyProgressDialog() { if (m_progress != nullptr) { @@ -745,7 +746,7 @@ void EasyTreeWidget::destroyProgressDialog() } } -void EasyTreeWidget::createProgressDialog() +void BlocksTreeWidget::createProgressDialog() { destroyProgressDialog(); @@ -760,7 +761,7 @@ void EasyTreeWidget::createProgressDialog() ////////////////////////////////////////////////////////////////////////// -void EasyTreeWidget::onJumpToItemClicked(bool) +void BlocksTreeWidget::onJumpToItemClicked(bool) { auto action = qobject_cast(sender()); if (action == nullptr) @@ -771,11 +772,11 @@ void EasyTreeWidget::onJumpToItemClicked(bool) if (block_index < EASY_GLOBALS.gui_blocks.size()) EASY_GLOBALS.selected_block_id = easyBlock(block_index).tree.node->id(); else - ::profiler_gui::set_max(EASY_GLOBALS.selected_block_id); + profiler_gui::set_max(EASY_GLOBALS.selected_block_id); emit EASY_GLOBALS.events.selectedBlockChanged(block_index); } -void EasyTreeWidget::onCollapseAllClicked(bool) +void BlocksTreeWidget::onCollapseAllClicked(bool) { const QSignalBlocker b(this); @@ -796,7 +797,7 @@ void EasyTreeWidget::onCollapseAllClicked(bool) } } -void EasyTreeWidget::onExpandAllClicked(bool) +void BlocksTreeWidget::onExpandAllClicked(bool) { const QSignalBlocker blocker(this); @@ -821,9 +822,9 @@ void EasyTreeWidget::onExpandAllClicked(bool) } } -void EasyTreeWidget::onCollapseAllChildrenClicked(bool) +void BlocksTreeWidget::onCollapseAllChildrenClicked(bool) { - auto current = static_cast(currentItem()); + auto current = static_cast(currentItem()); if (current != nullptr) { const QSignalBlocker b(this); @@ -836,9 +837,9 @@ void EasyTreeWidget::onCollapseAllChildrenClicked(bool) } } -void EasyTreeWidget::onExpandAllChildrenClicked(bool) +void BlocksTreeWidget::onExpandAllChildrenClicked(bool) { - auto current = static_cast(currentItem()); + auto current = static_cast(currentItem()); if (current != nullptr) { const QSignalBlocker b(this); @@ -854,12 +855,12 @@ void EasyTreeWidget::onExpandAllChildrenClicked(bool) ////////////////////////////////////////////////////////////////////////// -void EasyTreeWidget::onBlockStatusChangeClicked(bool _checked) +void BlocksTreeWidget::onBlockStatusChangeClicked(bool _checked) { if (!_checked) return; - auto item = static_cast(currentItem()); + auto item = static_cast(currentItem()); if (item == nullptr) return; @@ -867,14 +868,14 @@ void EasyTreeWidget::onBlockStatusChangeClicked(bool _checked) if (action != nullptr) { auto& desc = easyDescriptor(item->block().node->id()); - desc.setStatus(static_cast<::profiler::EasyBlockStatus>(action->data().toUInt())); + desc.setStatus(static_cast(action->data().toUInt())); emit EASY_GLOBALS.events.blockStatusChanged(desc.id(), desc.status()); } } ////////////////////////////////////////////////////////////////////////// -void EasyTreeWidget::onItemExpand(QTreeWidgetItem* _item) +void BlocksTreeWidget::onItemExpand(QTreeWidgetItem* _item) { if (!EASY_GLOBALS.bind_scene_and_tree_expand_status || _item->parent() == nullptr) { @@ -882,7 +883,7 @@ void EasyTreeWidget::onItemExpand(QTreeWidgetItem* _item) return; } - static_cast(_item)->guiBlock().expanded = true; + static_cast(_item)->guiBlock().expanded = true; if (!m_bSilentExpandCollapse) { @@ -891,12 +892,12 @@ void EasyTreeWidget::onItemExpand(QTreeWidgetItem* _item) } } -void EasyTreeWidget::onItemCollapse(QTreeWidgetItem* _item) +void BlocksTreeWidget::onItemCollapse(QTreeWidgetItem* _item) { if (!EASY_GLOBALS.bind_scene_and_tree_expand_status || _item->parent() == nullptr) return; - static_cast(_item)->guiBlock().expanded = false; + static_cast(_item)->guiBlock().expanded = false; if (!m_bSilentExpandCollapse) emit EASY_GLOBALS.events.itemsExpandStateChanged(); @@ -904,36 +905,36 @@ void EasyTreeWidget::onItemCollapse(QTreeWidgetItem* _item) ////////////////////////////////////////////////////////////////////////// -void EasyTreeWidget::onCurrentItemChange(QTreeWidgetItem* _item, QTreeWidgetItem* _previous) +void BlocksTreeWidget::onCurrentItemChange(QTreeWidgetItem* _item, QTreeWidgetItem* _previous) { if (_previous != nullptr) - static_cast(_previous)->setBold(false); + static_cast(_previous)->setBold(false); if (_item == nullptr) { - ::profiler_gui::set_max(EASY_GLOBALS.selected_block); - ::profiler_gui::set_max(EASY_GLOBALS.selected_block_id); + profiler_gui::set_max(EASY_GLOBALS.selected_block); + profiler_gui::set_max(EASY_GLOBALS.selected_block_id); } else { - auto item = static_cast(_item); + auto item = static_cast(_item); item->setBold(true); EASY_GLOBALS.selected_block = item->block_index(); if (EASY_GLOBALS.selected_block < EASY_GLOBALS.gui_blocks.size()) EASY_GLOBALS.selected_block_id = easyBlock(EASY_GLOBALS.selected_block).tree.node->id(); else - ::profiler_gui::set_max(EASY_GLOBALS.selected_block_id); + profiler_gui::set_max(EASY_GLOBALS.selected_block_id); } - disconnect(&EASY_GLOBALS.events, &::profiler_gui::EasyGlobalSignals::selectedBlockChanged, this, &This::onSelectedBlockChange); + disconnect(&EASY_GLOBALS.events, &profiler_gui::GlobalSignals::selectedBlockChanged, this, &This::onSelectedBlockChange); emit EASY_GLOBALS.events.selectedBlockChanged(EASY_GLOBALS.selected_block); - connect(&EASY_GLOBALS.events, &::profiler_gui::EasyGlobalSignals::selectedBlockChanged, this, &This::onSelectedBlockChange); + connect(&EASY_GLOBALS.events, &profiler_gui::GlobalSignals::selectedBlockChanged, this, &This::onSelectedBlockChange); } ////////////////////////////////////////////////////////////////////////// -void EasyTreeWidget::onSelectedThreadChange(::profiler::thread_id_t _id) +void BlocksTreeWidget::onSelectedThreadChange(profiler::thread_id_t _id) { for (auto& it : m_roots) { @@ -950,11 +951,11 @@ void EasyTreeWidget::onSelectedThreadChange(::profiler::thread_id_t _id) f->setFocus(); } -void EasyTreeWidget::onSelectedBlockChange(uint32_t _block_index) +void BlocksTreeWidget::onSelectedBlockChange(uint32_t _block_index) { disconnect(this, &Parent::currentItemChanged, this, &This::onCurrentItemChange); - EasyTreeWidgetItem* item = nullptr; + TreeWidgetItem* item = nullptr; if (_block_index < EASY_GLOBALS.gui_blocks.size()) { @@ -969,7 +970,7 @@ void EasyTreeWidget::onSelectedBlockChange(uint32_t _block_index) #endif } - auto previous = static_cast(currentItem()); + auto previous = static_cast(currentItem()); if (previous != nullptr) previous->setBold(false); @@ -1012,7 +1013,7 @@ void EasyTreeWidget::onSelectedBlockChange(uint32_t _block_index) ////////////////////////////////////////////////////////////////////////// -void EasyTreeWidget::resizeColumnsToContents() +void BlocksTreeWidget::resizeColumnsToContents() { for (int i = 0; i < COL_COLUMNS_NUMBER; ++i) { @@ -1022,7 +1023,7 @@ void EasyTreeWidget::resizeColumnsToContents() ////////////////////////////////////////////////////////////////////////// -void EasyTreeWidget::onHideShowColumn(bool) +void BlocksTreeWidget::onHideShowColumn(bool) { auto action = qobject_cast(sender()); if (action == nullptr) @@ -1034,19 +1035,19 @@ void EasyTreeWidget::onHideShowColumn(bool) m_columnsHiddenStatus[col] = hideCol ? 1 : 0; } -void EasyTreeWidget::onModeChange(bool) +void BlocksTreeWidget::onModeChange(bool) { auto action = qobject_cast(sender()); if (action == nullptr) return; const auto prev = m_mode; - m_mode = static_cast(action->data().toUInt()); + m_mode = static_cast(action->data().toUInt()); if (m_mode == prev) return; - if (m_mode == EasyTreeMode_Full) + if (m_mode == TreeMode::Full) { for (int i = 1; i < COL_COLUMNS_NUMBER; ++i) setColumnHidden(i, m_columnsHiddenStatus[i] != 0); @@ -1062,14 +1063,14 @@ void EasyTreeWidget::onModeChange(bool) ////////////////////////////////////////////////////////////////////////// -void EasyTreeWidget::loadSettings() +void BlocksTreeWidget::loadSettings() { - QSettings settings(::profiler_gui::ORGANAZATION_NAME, ::profiler_gui::APPLICATION_NAME); + QSettings settings(profiler_gui::ORGANAZATION_NAME, profiler_gui::APPLICATION_NAME); settings.beginGroup("tree_widget"); auto val = settings.value("regime"); if (!val.isNull()) - m_mode = static_cast(val.toUInt()); + m_mode = static_cast(val.toUInt()); val = settings.value("columns"); if (!val.isNull()) @@ -1085,9 +1086,9 @@ void EasyTreeWidget::loadSettings() settings.endGroup(); } -void EasyTreeWidget::saveSettings() +void BlocksTreeWidget::saveSettings() { - QSettings settings(::profiler_gui::ORGANAZATION_NAME, ::profiler_gui::APPLICATION_NAME); + QSettings settings(profiler_gui::ORGANAZATION_NAME, profiler_gui::APPLICATION_NAME); settings.beginGroup("tree_widget"); settings.setValue("regime", static_cast(m_mode)); settings.setValue("columns", QByteArray(m_columnsHiddenStatus, COL_COLUMNS_NUMBER)); @@ -1098,8 +1099,8 @@ void EasyTreeWidget::saveSettings() ////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////// -EasyHierarchyWidget::EasyHierarchyWidget(QWidget* _parent) : Parent(_parent) - , m_tree(new EasyTreeWidget(this)) +HierarchyWidget::HierarchyWidget(QWidget* _parent) : Parent(_parent) + , m_tree(new BlocksTreeWidget(this)) , m_searchBox(new QLineEdit(this)) , m_foundNumber(new QLabel("Found 0 matches", this)) , m_searchButton(nullptr) @@ -1138,7 +1139,7 @@ EasyHierarchyWidget::EasyHierarchyWidget(QWidget* _parent) : Parent(_parent) menu->addAction(a); auto tb = new QToolBar(this); - tb->setIconSize(::profiler_gui::ICONS_SIZE); + tb->setIconSize(profiler_gui::ICONS_SIZE); tb->setContentsMargins(0, 0, 0, 0); tb->addAction(m_searchButton); tb->addWidget(m_searchBox); @@ -1157,15 +1158,15 @@ EasyHierarchyWidget::EasyHierarchyWidget(QWidget* _parent) : Parent(_parent) connect(m_searchBox, &QLineEdit::returnPressed, this, &This::onSeachBoxReturnPressed); } -EasyHierarchyWidget::~EasyHierarchyWidget() +HierarchyWidget::~HierarchyWidget() { saveSettings(); } -void EasyHierarchyWidget::loadSettings() +void HierarchyWidget::loadSettings() { - QSettings settings(::profiler_gui::ORGANAZATION_NAME, ::profiler_gui::APPLICATION_NAME); - settings.beginGroup("EasyHierarchyWidget"); + QSettings settings(profiler_gui::ORGANAZATION_NAME, profiler_gui::APPLICATION_NAME); + settings.beginGroup("HierarchyWidget"); auto val = settings.value("case_sensitive"); if (!val.isNull()) @@ -1174,15 +1175,15 @@ void EasyHierarchyWidget::loadSettings() settings.endGroup(); } -void EasyHierarchyWidget::saveSettings() +void HierarchyWidget::saveSettings() { - QSettings settings(::profiler_gui::ORGANAZATION_NAME, ::profiler_gui::APPLICATION_NAME); - settings.beginGroup("EasyHierarchyWidget"); + QSettings settings(profiler_gui::ORGANAZATION_NAME, profiler_gui::APPLICATION_NAME); + settings.beginGroup("HierarchyWidget"); settings.setValue("case_sensitive", m_bCaseSensitiveSearch); settings.endGroup(); } -void EasyHierarchyWidget::keyPressEvent(QKeyEvent* _event) +void HierarchyWidget::keyPressEvent(QKeyEvent* _event) { if (_event->key() == Qt::Key_F3) { @@ -1197,25 +1198,25 @@ void EasyHierarchyWidget::keyPressEvent(QKeyEvent* _event) ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -void EasyHierarchyWidget::contextMenuEvent(QContextMenuEvent* _event) +void HierarchyWidget::contextMenuEvent(QContextMenuEvent* _event) { m_tree->contextMenuEvent(_event); } ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -EasyTreeWidget* EasyHierarchyWidget::tree() +BlocksTreeWidget* HierarchyWidget::tree() { return m_tree; } -void EasyHierarchyWidget::clear(bool _global) +void HierarchyWidget::clear(bool _global) { m_tree->clearSilent(_global); m_foundNumber->setText(QString("Found 0 matches")); } -void EasyHierarchyWidget::onSeachBoxReturnPressed() +void HierarchyWidget::onSeachBoxReturnPressed() { if (m_searchButton->data().toBool() == true) findNext(true); @@ -1223,7 +1224,7 @@ void EasyHierarchyWidget::onSeachBoxReturnPressed() findPrev(true); } -void EasyHierarchyWidget::findNext(bool) +void HierarchyWidget::findNext(bool) { auto matches = m_tree->findNext(m_searchBox->text(), m_bCaseSensitiveSearch ? Qt::MatchCaseSensitive : Qt::MatchFlags()); @@ -1233,7 +1234,7 @@ void EasyHierarchyWidget::findNext(bool) m_foundNumber->setText(QString("Found %1 matches").arg(matches)); } -void EasyHierarchyWidget::findPrev(bool) +void HierarchyWidget::findPrev(bool) { auto matches = m_tree->findPrev(m_searchBox->text(), m_bCaseSensitiveSearch ? Qt::MatchCaseSensitive : Qt::MatchFlags()); @@ -1243,7 +1244,7 @@ void EasyHierarchyWidget::findPrev(bool) m_foundNumber->setText(QString("Found %1 matches").arg(matches)); } -void EasyHierarchyWidget::findNextFromMenu(bool _checked) +void HierarchyWidget::findNextFromMenu(bool _checked) { if (!_checked) return; @@ -1260,7 +1261,7 @@ void EasyHierarchyWidget::findNextFromMenu(bool _checked) findNext(true); } -void EasyHierarchyWidget::findPrevFromMenu(bool _checked) +void HierarchyWidget::findPrevFromMenu(bool _checked) { if (!_checked) return; diff --git a/profiler_gui/blocks_tree_widget.h b/profiler_gui/blocks_tree_widget.h index c3ca6a1..8388ed0 100644 --- a/profiler_gui/blocks_tree_widget.h +++ b/profiler_gui/blocks_tree_widget.h @@ -5,7 +5,7 @@ * author : Victor Zarubkin * email : v.s.zarubkin@gmail.com * ----------------- : -* description : The file contains declaration of EasyTreeWidget and it's auxiliary classes +* description : The file contains declaration of BlocksTreeWidget and it's auxiliary classes * : for displyaing EasyProfiler blocks tree. * ----------------- : * change log : * 2016/06/26 Victor Zarubkin: moved sources from tree_view.h @@ -73,16 +73,16 @@ ////////////////////////////////////////////////////////////////////////// -class EasyTreeWidget : public QTreeWidget +class BlocksTreeWidget : public QTreeWidget { Q_OBJECT using Parent = QTreeWidget; - using This = EasyTreeWidget; + using This = BlocksTreeWidget; protected: - EasyTreeWidgetLoader m_hierarchyBuilder; + TreeWidgetLoader m_hierarchyBuilder; Items m_items; RootsMap m_roots; ::profiler_gui::TreeBlocks m_inputBlocks; @@ -92,15 +92,15 @@ protected: ::profiler::timestamp_t m_beginTime; class QProgressDialog* m_progress; class QLabel* m_hintLabel; - EasyTreeMode m_mode; + TreeMode m_mode; bool m_bLocked; bool m_bSilentExpandCollapse; char m_columnsHiddenStatus[COL_COLUMNS_NUMBER]; public: - explicit EasyTreeWidget(QWidget* _parent = nullptr); - ~EasyTreeWidget() override; + explicit BlocksTreeWidget(QWidget* _parent = nullptr); + ~BlocksTreeWidget() override; void contextMenuEvent(QContextMenuEvent* _event) override; void dragEnterEvent(QDragEnterEvent*) override {} @@ -160,20 +160,20 @@ private: void destroyProgressDialog(); void createProgressDialog(); -}; // END of class EasyTreeWidget. +}; // END of class BlocksTreeWidget. ////////////////////////////////////////////////////////////////////////// -class EasyHierarchyWidget : public QWidget +class HierarchyWidget : public QWidget { Q_OBJECT using Parent = QWidget; - using This = EasyHierarchyWidget; + using This = HierarchyWidget; private: - EasyTreeWidget* m_tree; + BlocksTreeWidget* m_tree; class QLineEdit* m_searchBox; class QLabel* m_foundNumber; class QAction* m_searchButton; @@ -183,8 +183,8 @@ public: // Public virtual methods - explicit EasyHierarchyWidget(QWidget* _parent = nullptr); - ~EasyHierarchyWidget() override; + explicit HierarchyWidget(QWidget* _parent = nullptr); + ~HierarchyWidget() override; void keyPressEvent(QKeyEvent* _event) override; void contextMenuEvent(QContextMenuEvent* _event) override; @@ -194,7 +194,7 @@ public: // Public non-virtual methods - EasyTreeWidget* tree(); + BlocksTreeWidget* tree(); void clear(bool _global = false); private slots: @@ -214,7 +214,7 @@ private: void loadSettings(); void saveSettings(); -}; // END of class EasyHierarchyWidget. +}; // END of class HierarchyWidget. ////////////////////////////////////////////////////////////////////////// diff --git a/profiler_gui/descriptors_tree_widget.cpp b/profiler_gui/descriptors_tree_widget.cpp index 8397999..4a04ce8 100644 --- a/profiler_gui/descriptors_tree_widget.cpp +++ b/profiler_gui/descriptors_tree_widget.cpp @@ -5,7 +5,7 @@ * author : Victor Zarubkin * email : v.s.zarubkin@gmail.com * ----------------- : -* description : The file contains implementation of EasyDescTreeWidget and it's auxiliary classes +* description : The file contains implementation of DescriptorsTreeWidget and it's auxiliary classes * : for displyaing EasyProfiler blocks descriptors tree. * ----------------- : * change log : * 2016/09/17 Victor Zarubkin: initial commit. @@ -187,20 +187,20 @@ const char* statusText(::profiler::EasyBlockStatus _status) ////////////////////////////////////////////////////////////////////////// -EasyDescWidgetItem::EasyDescWidgetItem(::profiler::block_id_t _desc, Parent* _parent) +DescriptorsTreeItem::DescriptorsTreeItem(::profiler::block_id_t _desc, Parent* _parent) : Parent(_parent, QTreeWidgetItem::UserType) , m_desc(_desc) - , m_type(EasyDescWidgetItem::Type::File) + , m_type(DescriptorsTreeItem::Type::File) { } -EasyDescWidgetItem::~EasyDescWidgetItem() +DescriptorsTreeItem::~DescriptorsTreeItem() { } -bool EasyDescWidgetItem::operator < (const Parent& _other) const +bool DescriptorsTreeItem::operator < (const Parent& _other) const { const auto col = treeWidget()->sortColumn(); @@ -216,7 +216,7 @@ bool EasyDescWidgetItem::operator < (const Parent& _other) const return Parent::operator < (_other); } -QVariant EasyDescWidgetItem::data(int _column, int _role) const +QVariant DescriptorsTreeItem::data(int _column, int _role) const { if (_column == DESC_COL_TYPE) { @@ -247,7 +247,7 @@ QVariant EasyDescWidgetItem::data(int _column, int _role) const ////////////////////////////////////////////////////////////////////////// -EasyDescTreeWidget::EasyDescTreeWidget(QWidget* _parent) +DescriptorsTreeWidget::DescriptorsTreeWidget(QWidget* _parent) : Parent(_parent) , m_lastFound(nullptr) , m_lastSearchColumn(-1) @@ -269,18 +269,18 @@ EasyDescTreeWidget::EasyDescTreeWidget(QWidget* _parent) header_item->setText(DESC_COL_STATUS, "Status"); setHeaderItem(header_item); - connect(&EASY_GLOBALS.events, &::profiler_gui::EasyGlobalSignals::selectedBlockChanged, this, &This::onSelectedBlockChange); - connect(&EASY_GLOBALS.events, &::profiler_gui::EasyGlobalSignals::blockStatusChanged, this, &This::onBlockStatusChange); + connect(&EASY_GLOBALS.events, &::profiler_gui::GlobalSignals::selectedBlockChanged, this, &This::onSelectedBlockChange); + connect(&EASY_GLOBALS.events, &::profiler_gui::GlobalSignals::blockStatusChanged, this, &This::onBlockStatusChange); connect(this, &Parent::itemExpanded, this, &This::onItemExpand); connect(this, &Parent::itemDoubleClicked, this, &This::onDoubleClick); connect(this, &Parent::currentItemChanged, this, &This::onCurrentItemChange); loadSettings(); - setItemDelegateForColumn(0, new EasyTreeViewFirstColumnItemDelegate(this)); + setItemDelegateForColumn(0, new TreeViewFirstColumnItemDelegate(this)); } -EasyDescTreeWidget::~EasyDescTreeWidget() +DescriptorsTreeWidget::~DescriptorsTreeWidget() { if (::profiler_gui::is_max(EASY_GLOBALS.selected_block) && !::profiler_gui::is_max(EASY_GLOBALS.selected_block_id)) { @@ -293,19 +293,19 @@ EasyDescTreeWidget::~EasyDescTreeWidget() ////////////////////////////////////////////////////////////////////////// -void EasyDescTreeWidget::setSearchColumn(int column) +void DescriptorsTreeWidget::setSearchColumn(int column) { m_searchColumn = column; } -int EasyDescTreeWidget::searchColumn() const +int DescriptorsTreeWidget::searchColumn() const { return m_searchColumn; } ////////////////////////////////////////////////////////////////////////// -void EasyDescTreeWidget::contextMenuEvent(QContextMenuEvent* _event) +void DescriptorsTreeWidget::contextMenuEvent(QContextMenuEvent* _event) { _event->accept(); @@ -322,7 +322,7 @@ void EasyDescTreeWidget::contextMenuEvent(QContextMenuEvent* _event) auto item = currentItem(); if (item != nullptr && item->parent() != nullptr && currentColumn() >= DESC_COL_TYPE) { - const auto& desc = easyDescriptor(static_cast(item)->desc()); + const auto& desc = easyDescriptor(static_cast(item)->desc()); menu.addSeparator(); auto submenu = menu.addMenu("Change status"); @@ -354,7 +354,7 @@ void EasyDescTreeWidget::contextMenuEvent(QContextMenuEvent* _event) ////////////////////////////////////////////////////////////////////////// -void EasyDescTreeWidget::clearSilent(bool _global) +void DescriptorsTreeWidget::clearSilent(bool _global) { const QSignalBlocker b(this); @@ -396,12 +396,12 @@ void EasyDescTreeWidget::clearSilent(bool _global) struct FileItems { - using Items = ::std::unordered_map >; + using Items = ::std::unordered_map >; Items children; QTreeWidgetItem* item = nullptr; }; -void EasyDescTreeWidget::build() +void DescriptorsTreeWidget::build() { auto f = font(); f.setBold(true); @@ -421,16 +421,16 @@ void EasyDescTreeWidget::build() auto& p = fileItems[desc->file()]; if (p.item == nullptr) { - auto item = new EasyDescWidgetItem(0); + auto item = new DescriptorsTreeItem(0); item->setText(DESC_COL_FILE_LINE, QString(desc->file()).remove(QRegExp("^(\\.{2}\\\\+|\\/+)+"))); - item->setType(EasyDescWidgetItem::Type::File); + item->setType(DescriptorsTreeItem::Type::File); p.item = item; } auto it = p.children.find(desc->line()); if (it == p.children.end()) { - auto item = new EasyDescWidgetItem(desc->id(), p.item); + auto item = new DescriptorsTreeItem(desc->id(), p.item); item->setText(DESC_COL_FILE_LINE, QString::number(desc->line())); item->setData(DESC_COL_FILE_LINE, Qt::UserRole, desc->line()); item->setText(DESC_COL_NAME, desc->name()); @@ -438,15 +438,15 @@ void EasyDescTreeWidget::build() switch (desc->type()) { case ::profiler::BlockType::Block: - item->setType(EasyDescWidgetItem::Type::Block); + item->setType(DescriptorsTreeItem::Type::Block); break; case ::profiler::BlockType::Event: - item->setType(EasyDescWidgetItem::Type::Event); + item->setType(DescriptorsTreeItem::Type::Event); break; case ::profiler::BlockType::Value: - item->setType(EasyDescWidgetItem::Type::Value); + item->setType(DescriptorsTreeItem::Type::Value); break; } @@ -482,21 +482,21 @@ void EasyDescTreeWidget::build() ////////////////////////////////////////////////////////////////////////// -void EasyDescTreeWidget::onItemExpand(QTreeWidgetItem*) +void DescriptorsTreeWidget::onItemExpand(QTreeWidgetItem*) { resizeColumnsToContents(); } ////////////////////////////////////////////////////////////////////////// -void EasyDescTreeWidget::onDoubleClick(QTreeWidgetItem* _item, int _column) +void DescriptorsTreeWidget::onDoubleClick(QTreeWidgetItem* _item, int _column) { if (!EASY_GLOBALS.connected) return; if (_column >= DESC_COL_TYPE && _item->parent() != nullptr) { - auto item = static_cast(_item); + auto item = static_cast(_item); auto& desc = easyDescriptor(item->desc()); desc.setStatus(nextStatus(desc.status())); @@ -511,7 +511,7 @@ void EasyDescTreeWidget::onDoubleClick(QTreeWidgetItem* _item, int _column) ////////////////////////////////////////////////////////////////////////// -void EasyDescTreeWidget::onCurrentItemChange(QTreeWidgetItem* _item, QTreeWidgetItem* _prev) +void DescriptorsTreeWidget::onCurrentItemChange(QTreeWidgetItem* _item, QTreeWidgetItem* _prev) { if (_prev != nullptr) { @@ -529,7 +529,7 @@ void EasyDescTreeWidget::onCurrentItemChange(QTreeWidgetItem* _item, QTreeWidget if (::profiler_gui::is_max(EASY_GLOBALS.selected_block) && _item->parent() != nullptr) { - const auto id = static_cast(_item)->desc(); + const auto id = static_cast(_item)->desc(); if (EASY_GLOBALS.selected_block_id != id) { EASY_GLOBALS.selected_block_id = id; @@ -546,7 +546,7 @@ void EasyDescTreeWidget::onCurrentItemChange(QTreeWidgetItem* _item, QTreeWidget ////////////////////////////////////////////////////////////////////////// -void EasyDescTreeWidget::onBlockStatusChangeClicked(bool _checked) +void DescriptorsTreeWidget::onBlockStatusChangeClicked(bool _checked) { if (!_checked || !EASY_GLOBALS.connected) return; @@ -558,7 +558,7 @@ void EasyDescTreeWidget::onBlockStatusChangeClicked(bool _checked) auto action = qobject_cast(sender()); if (action != nullptr) { - auto& desc = easyDescriptor(static_cast(item)->desc()); + auto& desc = easyDescriptor(static_cast(item)->desc()); desc.setStatus(static_cast<::profiler::EasyBlockStatus>(action->data().toUInt())); item->setText(DESC_COL_STATUS, statusText(desc.status())); item->setForeground(DESC_COL_STATUS, QColor::fromRgba(statusColor(desc.status()))); @@ -569,7 +569,7 @@ void EasyDescTreeWidget::onBlockStatusChangeClicked(bool _checked) } } -void EasyDescTreeWidget::onBlockStatusChange(::profiler::block_id_t _id, ::profiler::EasyBlockStatus _status) +void DescriptorsTreeWidget::onBlockStatusChange(::profiler::block_id_t _id, ::profiler::EasyBlockStatus _status) { if (m_bLocked) return; @@ -585,7 +585,7 @@ void EasyDescTreeWidget::onBlockStatusChange(::profiler::block_id_t _id, ::profi ////////////////////////////////////////////////////////////////////////// -void EasyDescTreeWidget::resizeColumnsToContents() +void DescriptorsTreeWidget::resizeColumnsToContents() { for (int i = 0; i < DESC_COL_COLUMNS_NUMBER; ++i) resizeColumnToContents(i); @@ -593,7 +593,7 @@ void EasyDescTreeWidget::resizeColumnsToContents() ////////////////////////////////////////////////////////////////////////// -void EasyDescTreeWidget::onSelectedBlockChange(uint32_t _block_index) +void DescriptorsTreeWidget::onSelectedBlockChange(uint32_t _block_index) { if (::profiler_gui::is_max(_block_index)) { @@ -611,7 +611,7 @@ void EasyDescTreeWidget::onSelectedBlockChange(uint32_t _block_index) ////////////////////////////////////////////////////////////////////////// -void EasyDescTreeWidget::resetHighlight() +void DescriptorsTreeWidget::resetHighlight() { for (auto item : m_highlightItems) { for (int i = 0; i < DESC_COL_COLUMNS_NUMBER; ++i) @@ -620,7 +620,7 @@ void EasyDescTreeWidget::resetHighlight() m_highlightItems.clear(); } -void EasyDescTreeWidget::loadSettings() +void DescriptorsTreeWidget::loadSettings() { QSettings settings(::profiler_gui::ORGANAZATION_NAME, ::profiler_gui::APPLICATION_NAME); settings.beginGroup("desc_tree_widget"); @@ -632,7 +632,7 @@ void EasyDescTreeWidget::loadSettings() settings.endGroup(); } -void EasyDescTreeWidget::saveSettings() +void DescriptorsTreeWidget::saveSettings() { QSettings settings(::profiler_gui::ORGANAZATION_NAME, ::profiler_gui::APPLICATION_NAME); settings.beginGroup("desc_tree_widget"); @@ -644,7 +644,7 @@ void EasyDescTreeWidget::saveSettings() ////////////////////////////////////////////////////////////////////////// -int EasyDescTreeWidget::findNext(const QString& _str, Qt::MatchFlags _flags) +int DescriptorsTreeWidget::findNext(const QString& _str, Qt::MatchFlags _flags) { if (_str.isEmpty()) { @@ -705,7 +705,7 @@ int EasyDescTreeWidget::findNext(const QString& _str, Qt::MatchFlags _flags) return itemsList.size(); } -int EasyDescTreeWidget::findPrev(const QString& _str, Qt::MatchFlags _flags) +int DescriptorsTreeWidget::findPrev(const QString& _str, Qt::MatchFlags _flags) { if (_str.isEmpty()) { @@ -765,9 +765,9 @@ int EasyDescTreeWidget::findPrev(const QString& _str, Qt::MatchFlags _flags) ////////////////////////////////////////////////////////////////////////// -EasyDescWidget::EasyDescWidget(QWidget* _parent) : Parent(_parent) +BlockDescriptorsWidget::BlockDescriptorsWidget(QWidget* _parent) : Parent(_parent) , m_splitter(new QSplitter(Qt::Vertical, this)) - , m_tree(new EasyDescTreeWidget(this)) + , m_tree(new DescriptorsTreeWidget(this)) , m_values(new ArbitraryValuesWidget(this)) , m_searchBox(new QLineEdit(this)) , m_foundNumber(new QLabel("Found 0 matches", this)) @@ -789,7 +789,7 @@ EasyDescWidget::EasyDescWidget(QWidget* _parent) : Parent(_parent) auto refreshButton = tb->addAction(QIcon(imagePath("reload")), tr("Refresh blocks list")); refreshButton->setEnabled(EASY_GLOBALS.connected); refreshButton->setToolTip(tr("Refresh blocks list.\nConnection needed.")); - connect(refreshButton, &QAction::triggered, &EASY_GLOBALS.events, &::profiler_gui::EasyGlobalSignals::blocksRefreshRequired); + connect(refreshButton, &QAction::triggered, &EASY_GLOBALS.events, &::profiler_gui::GlobalSignals::blocksRefreshRequired); @@ -856,21 +856,21 @@ EasyDescWidget::EasyDescWidget(QWidget* _parent) : Parent(_parent) lay->addWidget(m_splitter); connect(m_searchBox, &QLineEdit::returnPressed, this, &This::onSeachBoxReturnPressed); - connect(&EASY_GLOBALS.events, &::profiler_gui::EasyGlobalSignals::connectionChanged, refreshButton, &QAction::setEnabled); + connect(&EASY_GLOBALS.events, &::profiler_gui::GlobalSignals::connectionChanged, refreshButton, &QAction::setEnabled); loadSettings(); caseSensitiveSwitch->setChecked(m_bCaseSensitiveSearch); } -EasyDescWidget::~EasyDescWidget() +BlockDescriptorsWidget::~BlockDescriptorsWidget() { saveSettings(); } -void EasyDescWidget::loadSettings() +void BlockDescriptorsWidget::loadSettings() { QSettings settings(::profiler_gui::ORGANAZATION_NAME, ::profiler_gui::APPLICATION_NAME); - settings.beginGroup("EasyDescWidget"); + settings.beginGroup("BlockDescriptorsWidget"); auto val = settings.value("case_sensitive"); if (!val.isNull()) @@ -887,17 +887,17 @@ void EasyDescWidget::loadSettings() settings.endGroup(); } -void EasyDescWidget::saveSettings() +void BlockDescriptorsWidget::saveSettings() { QSettings settings(::profiler_gui::ORGANAZATION_NAME, ::profiler_gui::APPLICATION_NAME); - settings.beginGroup("EasyDescWidget"); + settings.beginGroup("BlockDescriptorsWidget"); settings.setValue("case_sensitive", m_bCaseSensitiveSearch); settings.setValue("vsplitter/geometry", m_splitter->saveGeometry()); settings.setValue("vsplitter/state", m_splitter->saveState()); settings.endGroup(); } -void EasyDescWidget::keyPressEvent(QKeyEvent* _event) +void BlockDescriptorsWidget::keyPressEvent(QKeyEvent* _event) { if (_event->key() == Qt::Key_F3) { @@ -910,12 +910,12 @@ void EasyDescWidget::keyPressEvent(QKeyEvent* _event) _event->accept(); } -void EasyDescWidget::contextMenuEvent(QContextMenuEvent* _event) +void BlockDescriptorsWidget::contextMenuEvent(QContextMenuEvent* _event) { m_tree->contextMenuEvent(_event); } -void EasyDescWidget::build() +void BlockDescriptorsWidget::build() { m_tree->clearSilent(false); m_foundNumber->setText(QString("Found 0 matches")); @@ -923,14 +923,14 @@ void EasyDescWidget::build() m_values->rebuild(); } -void EasyDescWidget::clear() +void BlockDescriptorsWidget::clear() { m_tree->clearSilent(true); m_foundNumber->setText(QString("Found 0 matches")); m_values->clear(); } -void EasyDescWidget::onSeachBoxReturnPressed() +void BlockDescriptorsWidget::onSeachBoxReturnPressed() { if (m_searchButton->data().toBool() == true) findNext(true); @@ -938,14 +938,14 @@ void EasyDescWidget::onSeachBoxReturnPressed() findPrev(true); } -void EasyDescWidget::onSearchColumnChange(bool) +void BlockDescriptorsWidget::onSearchColumnChange(bool) { auto action = qobject_cast(sender()); if (action != nullptr) m_tree->setSearchColumn(action->data().toInt()); } -void EasyDescWidget::findNext(bool) +void BlockDescriptorsWidget::findNext(bool) { auto matches = m_tree->findNext(m_searchBox->text(), m_bCaseSensitiveSearch ? Qt::MatchCaseSensitive : Qt::MatchFlags()); @@ -955,7 +955,7 @@ void EasyDescWidget::findNext(bool) m_foundNumber->setText(QString("Found %1 matches").arg(matches)); } -void EasyDescWidget::findPrev(bool) +void BlockDescriptorsWidget::findPrev(bool) { auto matches = m_tree->findPrev(m_searchBox->text(), m_bCaseSensitiveSearch ? Qt::MatchCaseSensitive : Qt::MatchFlags()); @@ -965,7 +965,7 @@ void EasyDescWidget::findPrev(bool) m_foundNumber->setText(QString("Found %1 matches").arg(matches)); } -void EasyDescWidget::findNextFromMenu(bool _checked) +void BlockDescriptorsWidget::findNextFromMenu(bool _checked) { if (!_checked) return; @@ -982,7 +982,7 @@ void EasyDescWidget::findNextFromMenu(bool _checked) findNext(true); } -void EasyDescWidget::findPrevFromMenu(bool _checked) +void BlockDescriptorsWidget::findPrevFromMenu(bool _checked) { if (!_checked) return; diff --git a/profiler_gui/descriptors_tree_widget.h b/profiler_gui/descriptors_tree_widget.h index 2d5c74e..7c1ff0f 100644 --- a/profiler_gui/descriptors_tree_widget.h +++ b/profiler_gui/descriptors_tree_widget.h @@ -5,7 +5,7 @@ * author : Victor Zarubkin * email : v.s.zarubkin@gmail.com * ----------------- : -* description : The file contains declaration of EasyDescTreeWidget and it's auxiliary classes +* description : The file contains declaration of DescriptorsTreeWidget and it's auxiliary classes * : for displyaing EasyProfiler blocks descriptors tree. * ----------------- : * change log : * 2016/09/17 Victor Zarubkin: initial commit. @@ -67,10 +67,10 @@ ////////////////////////////////////////////////////////////////////////// -class EasyDescWidgetItem : public QTreeWidgetItem +class DescriptorsTreeItem : public QTreeWidgetItem { using Parent = QTreeWidgetItem; - using This = EasyDescWidgetItem; + using This = DescriptorsTreeItem; public: @@ -89,8 +89,8 @@ private: public: - explicit EasyDescWidgetItem(::profiler::block_id_t _desc, Parent* _parent = nullptr); - ~EasyDescWidgetItem() override; + explicit DescriptorsTreeItem(::profiler::block_id_t _desc, Parent* _parent = nullptr); + ~DescriptorsTreeItem() override; bool operator < (const Parent& _other) const override; QVariant data(int _column, int _role) const override; @@ -109,18 +109,18 @@ public: m_type = _type; } -}; // END of class EasyDescWidgetItem. +}; // END of class DescriptorsTreeItem. ////////////////////////////////////////////////////////////////////////// -class EasyDescTreeWidget : public QTreeWidget +class DescriptorsTreeWidget : public QTreeWidget { Q_OBJECT using Parent = QTreeWidget; - using This = EasyDescTreeWidget; + using This = DescriptorsTreeWidget; - using Items = ::std::vector; + using Items = ::std::vector; using TreeItems = ::std::vector; using ExpandedFiles = ::std::unordered_set<::std::string>; @@ -139,8 +139,8 @@ public: // Public virtual methods - explicit EasyDescTreeWidget(QWidget* _parent = nullptr); - ~EasyDescTreeWidget() override; + explicit DescriptorsTreeWidget(QWidget* _parent = nullptr); + ~DescriptorsTreeWidget() override; void contextMenuEvent(QContextMenuEvent* _event) override; public: @@ -175,21 +175,21 @@ private: void loadSettings(); void saveSettings(); -}; // END of class EasyDescTreeWidget. +}; // END of class DescriptorsTreeWidget. ////////////////////////////////////////////////////////////////////////// -class EasyDescWidget : public QWidget +class BlockDescriptorsWidget : public QWidget { Q_OBJECT using Parent = QWidget; - using This = EasyDescWidget; + using This = BlockDescriptorsWidget; private: class QSplitter* m_splitter; - EasyDescTreeWidget* m_tree; + DescriptorsTreeWidget* m_tree; class ArbitraryValuesWidget* m_values; class QLineEdit* m_searchBox; class QLabel* m_foundNumber; @@ -200,8 +200,8 @@ public: // Public virtual methods - explicit EasyDescWidget(QWidget* _parent = nullptr); - ~EasyDescWidget() override; + explicit BlockDescriptorsWidget(QWidget* _parent = nullptr); + ~BlockDescriptorsWidget() override; void keyPressEvent(QKeyEvent* _event) override; void contextMenuEvent(QContextMenuEvent* _event) override; @@ -228,7 +228,7 @@ private: void loadSettings(); void saveSettings(); -}; // END of class EasyDescWidget. +}; // END of class BlockDescriptorsWidget. ////////////////////////////////////////////////////////////////////////// diff --git a/profiler_gui/easy_chronometer_item.cpp b/profiler_gui/easy_chronometer_item.cpp index 357833e..21eb427 100644 --- a/profiler_gui/easy_chronometer_item.cpp +++ b/profiler_gui/easy_chronometer_item.cpp @@ -5,7 +5,7 @@ * author : Victor Zarubkin * email : v.s.zarubkin@gmail.com * ----------------- : -* description : The file contains implementation of EasyChronometerItem. +* description : The file contains implementation of GraphicsRulerItem. * ----------------- : * change log : * 2016/09/15 Victor Zarubkin: moved sources from blocks_graphics_view.cpp * : @@ -72,7 +72,7 @@ ////////////////////////////////////////////////////////////////////////// -EasyChronometerItem::EasyChronometerItem(bool _main) +GraphicsRulerItem::GraphicsRulerItem(bool _main) : Parent() , m_color(::profiler_gui::CHRONOMETER_COLOR) , m_left(0) @@ -86,16 +86,16 @@ EasyChronometerItem::EasyChronometerItem(bool _main) m_indicator.reserve(3); } -EasyChronometerItem::~EasyChronometerItem() +GraphicsRulerItem::~GraphicsRulerItem() { } -QRectF EasyChronometerItem::boundingRect() const +QRectF GraphicsRulerItem::boundingRect() const { return m_boundingRect; } -void EasyChronometerItem::paint(QPainter* _painter, const QStyleOptionGraphicsItem*, QWidget*) +void GraphicsRulerItem::paint(QPainter* _painter, const QStyleOptionGraphicsItem*, QWidget*) { auto const sceneView = view(); const auto currentScale = sceneView->scale(); @@ -290,7 +290,7 @@ void EasyChronometerItem::paint(QPainter* _painter, const QStyleOptionGraphicsIt // END Paint!~~~~~~~~~~~~~~~~~~~~~~ } -void EasyChronometerItem::hide() +void GraphicsRulerItem::hide() { m_bHoverIndicator = false; m_bHoverLeftBorder = false; @@ -299,7 +299,7 @@ void EasyChronometerItem::hide() Parent::hide(); } -bool EasyChronometerItem::indicatorContains(const QPointF& _pos) const +bool GraphicsRulerItem::indicatorContains(const QPointF& _pos) const { if (m_indicator.empty()) return false; @@ -308,56 +308,56 @@ bool EasyChronometerItem::indicatorContains(const QPointF& _pos) const return m_indicator.containsPoint(QPointF(itemX, _pos.y()), Qt::OddEvenFill); } -void EasyChronometerItem::setHoverLeft(bool _hover) +void GraphicsRulerItem::setHoverLeft(bool _hover) { m_bHoverLeftBorder = _hover; } -void EasyChronometerItem::setHoverRight(bool _hover) +void GraphicsRulerItem::setHoverRight(bool _hover) { m_bHoverRightBorder = _hover; } -bool EasyChronometerItem::hoverLeft(qreal _x) const +bool GraphicsRulerItem::hoverLeft(qreal _x) const { const auto dx = fabs(_x - m_left) * view()->scale(); return dx < 4; } -bool EasyChronometerItem::hoverRight(qreal _x) const +bool GraphicsRulerItem::hoverRight(qreal _x) const { const auto dx = fabs(_x - m_right) * view()->scale(); return dx < 4; } -QPointF EasyChronometerItem::toItem(const QPointF& _pos) const +QPointF GraphicsRulerItem::toItem(const QPointF& _pos) const { const auto sceneView = view(); return QPointF((_pos.x() - sceneView->offset()) * sceneView->scale() - x(), _pos.y()); } -qreal EasyChronometerItem::toItem(qreal _x) const +qreal GraphicsRulerItem::toItem(qreal _x) const { const auto sceneView = view(); return (_x - sceneView->offset()) * sceneView->scale() - x(); } -void EasyChronometerItem::setColor(const QColor& _color) +void GraphicsRulerItem::setColor(const QColor& _color) { m_color = _color; } -void EasyChronometerItem::setBoundingRect(qreal x, qreal y, qreal w, qreal h) +void GraphicsRulerItem::setBoundingRect(qreal x, qreal y, qreal w, qreal h) { m_boundingRect.setRect(x, y, w, h); } -void EasyChronometerItem::setBoundingRect(const QRectF& _rect) +void GraphicsRulerItem::setBoundingRect(const QRectF& _rect) { m_boundingRect = _rect; } -void EasyChronometerItem::setLeftRight(qreal _left, qreal _right) +void GraphicsRulerItem::setLeftRight(qreal _left, qreal _right) { if (_left < _right) { @@ -371,24 +371,24 @@ void EasyChronometerItem::setLeftRight(qreal _left, qreal _right) } } -void EasyChronometerItem::setReverse(bool _reverse) +void GraphicsRulerItem::setReverse(bool _reverse) { m_bReverse = _reverse; } -void EasyChronometerItem::setHoverIndicator(bool _hover) +void GraphicsRulerItem::setHoverIndicator(bool _hover) { m_bHoverIndicator = _hover; } -const EasyGraphicsView* EasyChronometerItem::view() const +const BlocksGraphicsView* GraphicsRulerItem::view() const { - return static_cast(scene()->parent()); + return static_cast(scene()->parent()); } -EasyGraphicsView* EasyChronometerItem::view() +BlocksGraphicsView* GraphicsRulerItem::view() { - return static_cast(scene()->parent()); + return static_cast(scene()->parent()); } ////////////////////////////////////////////////////////////////////////// diff --git a/profiler_gui/easy_chronometer_item.h b/profiler_gui/easy_chronometer_item.h index 1c20865..de604f2 100644 --- a/profiler_gui/easy_chronometer_item.h +++ b/profiler_gui/easy_chronometer_item.h @@ -5,7 +5,7 @@ * author : Victor Zarubkin * email : v.s.zarubkin@gmail.com * ----------------- : -* description : The file contains declaration of EasyChronometerItem - an item +* description : The file contains declaration of GraphicsRulerItem - an item * : used to display selected interval on graphics scene. * ----------------- : * change log : * 2016/09/15 Victor Zarubkin: moved sources from blocks_graphics_view.h @@ -67,12 +67,12 @@ class QWidget; class QPainter; class QStyleOptionGraphicsItem; -class EasyGraphicsView; +class BlocksGraphicsView; -class EasyChronometerItem : public QGraphicsItem +class GraphicsRulerItem : public QGraphicsItem { typedef QGraphicsItem Parent; - typedef EasyChronometerItem This; + typedef GraphicsRulerItem This; QPolygonF m_indicator; ///< Indicator displayed when this chrono item is out of screen (displaying only for main item) QRectF m_boundingRect; ///< boundingRect (see QGraphicsItem) @@ -86,8 +86,8 @@ class EasyChronometerItem : public QGraphicsItem public: - explicit EasyChronometerItem(bool _main = true); - virtual ~EasyChronometerItem(); + explicit GraphicsRulerItem(bool _main = true); + virtual ~GraphicsRulerItem(); // Public virtual methods @@ -159,11 +159,11 @@ public: private: - ///< Returns pointer to the EasyGraphicsView widget. - const EasyGraphicsView* view() const; - EasyGraphicsView* view(); + ///< Returns pointer to the BlocksGraphicsView widget. + const BlocksGraphicsView* view() const; + BlocksGraphicsView* view(); -}; // END of class EasyChronometerItem. +}; // END of class GraphicsRulerItem. ////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////// diff --git a/profiler_gui/easy_frame_rate_viewer.cpp b/profiler_gui/easy_frame_rate_viewer.cpp index 9cdde8b..b960d8c 100644 --- a/profiler_gui/easy_frame_rate_viewer.cpp +++ b/profiler_gui/easy_frame_rate_viewer.cpp @@ -5,7 +5,7 @@ * author : Victor Zarubkin * email : v.s.zarubkin@gmail.com * ----------------- : -* description : This file contains implementation of EasyFrameRateViewer widget. +* description : This file contains implementation of FpsViewerWidget widget. * ----------------- : * change log : * 2017/04/02 Victor Zarubkin: Initial commit. * : @@ -64,36 +64,36 @@ const int INTERVAL_WIDTH = 20; ////////////////////////////////////////////////////////////////////////// -EasyFPSGraphicsItem::EasyFPSGraphicsItem() : Parent(nullptr) +FpsGraphicsItem::FpsGraphicsItem() : Parent(nullptr) { } -EasyFPSGraphicsItem::~EasyFPSGraphicsItem() +FpsGraphicsItem::~FpsGraphicsItem() { } ////////////////////////////////////////////////////////////////////////// -QRectF EasyFPSGraphicsItem::boundingRect() const +QRectF FpsGraphicsItem::boundingRect() const { return m_boundingRect; } -void EasyFPSGraphicsItem::setBoundingRect(const QRectF& _boundingRect) +void FpsGraphicsItem::setBoundingRect(const QRectF& _boundingRect) { m_boundingRect = _boundingRect; } -void EasyFPSGraphicsItem::setBoundingRect(qreal x, qreal y, qreal w, qreal h) +void FpsGraphicsItem::setBoundingRect(qreal x, qreal y, qreal w, qreal h) { m_boundingRect.setRect(x, y, w, h); } ////////////////////////////////////////////////////////////////////////// -void EasyFPSGraphicsItem::paint(QPainter* _painter, const QStyleOptionGraphicsItem*, QWidget*) +void FpsGraphicsItem::paint(QPainter* _painter, const QStyleOptionGraphicsItem*, QWidget*) { if (m_frames.empty()) return; @@ -232,12 +232,12 @@ void EasyFPSGraphicsItem::paint(QPainter* _painter, const QStyleOptionGraphicsIt ////////////////////////////////////////////////////////////////////////// -void EasyFPSGraphicsItem::clear() +void FpsGraphicsItem::clear() { m_frames.clear(); } -void EasyFPSGraphicsItem::addPoint(uint32_t _maxFrameTime, uint32_t _avgFrameTime) +void FpsGraphicsItem::addPoint(uint32_t _maxFrameTime, uint32_t _avgFrameTime) { m_frames.emplace_back(_maxFrameTime, _avgFrameTime); if (static_cast(m_frames.size()) > EASY_GLOBALS.max_fps_history) @@ -246,7 +246,7 @@ void EasyFPSGraphicsItem::addPoint(uint32_t _maxFrameTime, uint32_t _avgFrameTim ////////////////////////////////////////////////////////////////////////// -EasyFrameRateViewer::EasyFrameRateViewer(QWidget* _parent) : Parent(_parent), m_fpsItem(nullptr) +FpsViewerWidget::FpsViewerWidget(QWidget* _parent) : Parent(_parent), m_fpsItem(nullptr) { setCacheMode(QGraphicsView::CacheNone); //setViewportUpdateMode(QGraphicsView::BoundingRectViewportUpdate); @@ -260,7 +260,7 @@ EasyFrameRateViewer::EasyFrameRateViewer(QWidget* _parent) : Parent(_parent), m_ setScene(new QGraphicsScene(this)); scene()->setSceneRect(0, 0, 50, 50); - m_fpsItem = new EasyFPSGraphicsItem(); + m_fpsItem = new FpsGraphicsItem(); m_fpsItem->setPos(0, 0); m_fpsItem->setBoundingRect(0, 0, 50, 50); scene()->addItem(m_fpsItem); @@ -277,24 +277,24 @@ EasyFrameRateViewer::EasyFrameRateViewer(QWidget* _parent) : Parent(_parent), m_ }); } -EasyFrameRateViewer::~EasyFrameRateViewer() +FpsViewerWidget::~FpsViewerWidget() { } -void EasyFrameRateViewer::clear() +void FpsViewerWidget::clear() { m_fpsItem->clear(); scene()->update(); } -void EasyFrameRateViewer::addPoint(uint32_t _maxFrameTime, uint32_t _avgFrameTime) +void FpsViewerWidget::addPoint(uint32_t _maxFrameTime, uint32_t _avgFrameTime) { m_fpsItem->addPoint(_maxFrameTime, _avgFrameTime); scene()->update(); } -void EasyFrameRateViewer::resizeEvent(QResizeEvent* _event) +void FpsViewerWidget::resizeEvent(QResizeEvent* _event) { Parent::resizeEvent(_event); @@ -305,21 +305,21 @@ void EasyFrameRateViewer::resizeEvent(QResizeEvent* _event) scene()->update(); } -void EasyFrameRateViewer::hideEvent(QHideEvent* _event) +void FpsViewerWidget::hideEvent(QHideEvent* _event) { Parent::hideEvent(_event); EASY_GLOBALS.fps_enabled = isVisible(); clear(); } -void EasyFrameRateViewer::showEvent(QShowEvent* _event) +void FpsViewerWidget::showEvent(QShowEvent* _event) { Parent::showEvent(_event); EASY_GLOBALS.fps_enabled = isVisible(); clear(); } -void EasyFrameRateViewer::contextMenuEvent(QContextMenuEvent* _event) +void FpsViewerWidget::contextMenuEvent(QContextMenuEvent* _event) { QMenu menu; QAction* action = nullptr; diff --git a/profiler_gui/easy_frame_rate_viewer.h b/profiler_gui/easy_frame_rate_viewer.h index 78be499..a66198f 100644 --- a/profiler_gui/easy_frame_rate_viewer.h +++ b/profiler_gui/easy_frame_rate_viewer.h @@ -5,7 +5,7 @@ * author : Victor Zarubkin * email : v.s.zarubkin@gmail.com * ----------------- : -* description : This file contains declaration of EasyFrameRateViewer widget. +* description : This file contains declaration of FpsViewerWidget widget. * ----------------- : * change log : * 2017/04/02 Victor Zarubkin: Initial commit. * : @@ -65,10 +65,10 @@ ////////////////////////////////////////////////////////////////////////// -class EasyFPSGraphicsItem : public QGraphicsItem +class FpsGraphicsItem : public QGraphicsItem { using Parent = QGraphicsItem; - using This = EasyFPSGraphicsItem; + using This = FpsGraphicsItem; using FrameTimes = std::deque >; std::vector m_points1, m_points2; @@ -77,8 +77,8 @@ class EasyFPSGraphicsItem : public QGraphicsItem public: - explicit EasyFPSGraphicsItem(); - ~EasyFPSGraphicsItem() override; + explicit FpsGraphicsItem(); + ~FpsGraphicsItem() override; QRectF boundingRect() const override; void paint(QPainter* _painter, const QStyleOptionGraphicsItem* _option, QWidget* _widget) override; @@ -89,25 +89,25 @@ public: void clear(); void addPoint(uint32_t _maxFrameTime, uint32_t _avgFrameTime); -}; // END of class EasyFPSGraphicsItem. +}; // END of class FpsGraphicsItem. ////////////////////////////////////////////////////////////////////////// -class EasyFrameRateViewer : public QGraphicsView +class FpsViewerWidget : public QGraphicsView { Q_OBJECT private: using Parent = QGraphicsView; - using This = EasyFrameRateViewer; + using This = FpsViewerWidget; - EasyFPSGraphicsItem* m_fpsItem; + FpsGraphicsItem* m_fpsItem; public: - explicit EasyFrameRateViewer(QWidget* _parent = nullptr); - ~EasyFrameRateViewer() override; + explicit FpsViewerWidget(QWidget* _parent = nullptr); + ~FpsViewerWidget() override; void resizeEvent(QResizeEvent* _event) override; void hideEvent(QHideEvent* _event) override; @@ -120,7 +120,7 @@ public slots: void clear(); void addPoint(uint32_t _maxFrameTime, uint32_t _avgFrameTime); -}; // END of class EasyFrameRateViewer. +}; // END of class FpsViewerWidget. ////////////////////////////////////////////////////////////////////////// diff --git a/profiler_gui/easy_graphics_item.cpp b/profiler_gui/easy_graphics_item.cpp index 1c51fff..cc48095 100644 --- a/profiler_gui/easy_graphics_item.cpp +++ b/profiler_gui/easy_graphics_item.cpp @@ -5,7 +5,7 @@ * author : Victor Zarubkin * email : v.s.zarubkin@gmail.com * ----------------- : -* description : The file contains implementation of EasyGraphicsItem. +* description : The file contains implementation of BlocksGraphicsItem. * ----------------- : * change log : * 2016/09/15 Victor Zarubkin: Moved sources from blocks_graphics_view.cpp * : @@ -93,7 +93,7 @@ const QPen HIGHLIGHTER_PEN = ([]() -> QPen { QPen p(::profiler::colors::Black); ////////////////////////////////////////////////////////////////////////// -EasyGraphicsItem::EasyGraphicsItem(uint8_t _index, const::profiler::BlocksTreeRoot& _root) +BlocksGraphicsItem::BlocksGraphicsItem(uint8_t _index, const::profiler::BlocksTreeRoot& _root) : QGraphicsItem(nullptr) , m_threadName(::profiler_gui::decoratedThreadName(EASY_GLOBALS.use_decorated_thread_name, _root, EASY_GLOBALS.hex_thread_id)) , m_pRoot(&_root) @@ -101,23 +101,23 @@ EasyGraphicsItem::EasyGraphicsItem(uint8_t _index, const::profiler::BlocksTreeRo { } -EasyGraphicsItem::~EasyGraphicsItem() +BlocksGraphicsItem::~BlocksGraphicsItem() { } -void EasyGraphicsItem::validateName() +void BlocksGraphicsItem::validateName() { m_threadName = ::profiler_gui::decoratedThreadName(EASY_GLOBALS.use_decorated_thread_name, *m_pRoot, EASY_GLOBALS.hex_thread_id); } -const EasyGraphicsView* EasyGraphicsItem::view() const +const BlocksGraphicsView* BlocksGraphicsItem::view() const { - return static_cast(scene()->parent()); + return static_cast(scene()->parent()); } ////////////////////////////////////////////////////////////////////////// -QRectF EasyGraphicsItem::boundingRect() const +QRectF BlocksGraphicsItem::boundingRect() const { return m_boundingRect; } @@ -141,7 +141,7 @@ struct EasyPainterInformation EASY_FINAL bool is_light; bool selectedItemsWasPainted; - explicit EasyPainterInformation(const EasyGraphicsView* sceneView) + explicit EasyPainterInformation(const BlocksGraphicsView* sceneView) : visibleSceneRect(sceneView->visibleSceneRect()) , visibleBottom(visibleSceneRect.bottom() - 1) , currentScale(sceneView->scale()) @@ -162,7 +162,7 @@ struct EasyPainterInformation EASY_FINAL }; #ifdef EASY_GRAPHICS_ITEM_RECURSIVE_PAINT -void EasyGraphicsItem::paintChildren(const float _minWidth, const int _narrowSizeHalf, const uint8_t _levelsNumber, QPainter* _painter, struct EasyPainterInformation& p, ::profiler_gui::EasyBlockItem& _item, const ::profiler_gui::EasyBlock& _itemBlock, RightBounds& _rightBounds, uint8_t _level, int8_t _mode) +void BlocksGraphicsItem::paintChildren(const float _minWidth, const int _narrowSizeHalf, const uint8_t _levelsNumber, QPainter* _painter, struct EasyPainterInformation& p, ::profiler_gui::EasyBlockItem& _item, const ::profiler_gui::EasyBlock& _itemBlock, RightBounds& _rightBounds, uint8_t _level, int8_t _mode) { if (_level >= _levelsNumber || _itemBlock.tree.children.empty()) return; @@ -436,7 +436,7 @@ void EasyGraphicsItem::paintChildren(const float _minWidth, const int _narrowSiz } #endif -void EasyGraphicsItem::paint(QPainter* _painter, const QStyleOptionGraphicsItem*, QWidget*) +void BlocksGraphicsItem::paint(QPainter* _painter, const QStyleOptionGraphicsItem*, QWidget*) { const bool gotItems = !m_levels.empty() && !m_levels.front().empty(); const bool gotSync = !m_pRoot->sync.empty(); @@ -1100,26 +1100,26 @@ void EasyGraphicsItem::paint(QPainter* _painter, const QStyleOptionGraphicsItem* ////////////////////////////////////////////////////////////////////////// -const ::profiler::BlocksTreeRoot* EasyGraphicsItem::root() const +const ::profiler::BlocksTreeRoot* BlocksGraphicsItem::root() const { return m_pRoot; } -const QString& EasyGraphicsItem::threadName() const +const QString& BlocksGraphicsItem::threadName() const { return m_threadName; } ////////////////////////////////////////////////////////////////////////// -QRect EasyGraphicsItem::getRect() const +QRect BlocksGraphicsItem::getRect() const { return view()->mapFromScene(m_boundingRect).boundingRect(); } ////////////////////////////////////////////////////////////////////////// -void EasyGraphicsItem::getBlocks(qreal _left, qreal _right, ::profiler_gui::TreeBlocks& _blocks) const +void BlocksGraphicsItem::getBlocks(qreal _left, qreal _right, ::profiler_gui::TreeBlocks& _blocks) const { // Search for first visible top-level item auto& level0 = m_levels.front(); @@ -1164,7 +1164,7 @@ void EasyGraphicsItem::getBlocks(qreal _left, qreal _right, ::profiler_gui::Tree ////////////////////////////////////////////////////////////////////////// -const ::profiler_gui::EasyBlock* EasyGraphicsItem::intersect(const QPointF& _pos, ::profiler::block_index_t& _blockIndex) const +const ::profiler_gui::EasyBlock* BlocksGraphicsItem::intersect(const QPointF& _pos, ::profiler::block_index_t& _blockIndex) const { if (m_levels.empty() || m_levels.front().empty()) { @@ -1337,7 +1337,7 @@ const ::profiler_gui::EasyBlock* EasyGraphicsItem::intersect(const QPointF& _pos return nullptr; } -const ::profiler_gui::EasyBlock* EasyGraphicsItem::intersectEvent(const QPointF& _pos) const +const ::profiler_gui::EasyBlock* BlocksGraphicsItem::intersectEvent(const QPointF& _pos) const { if (m_pRoot->sync.empty()) { @@ -1388,36 +1388,36 @@ const ::profiler_gui::EasyBlock* EasyGraphicsItem::intersectEvent(const QPointF& ////////////////////////////////////////////////////////////////////////// -void EasyGraphicsItem::setBoundingRect(qreal x, qreal y, qreal w, qreal h) +void BlocksGraphicsItem::setBoundingRect(qreal x, qreal y, qreal w, qreal h) { m_boundingRect.setRect(x, y, w, h); } -void EasyGraphicsItem::setBoundingRect(const QRectF& _rect) +void BlocksGraphicsItem::setBoundingRect(const QRectF& _rect) { m_boundingRect = _rect; } ////////////////////////////////////////////////////////////////////////// -::profiler::thread_id_t EasyGraphicsItem::threadId() const +::profiler::thread_id_t BlocksGraphicsItem::threadId() const { return m_pRoot->thread_id; } ////////////////////////////////////////////////////////////////////////// -uint8_t EasyGraphicsItem::levels() const +uint8_t BlocksGraphicsItem::levels() const { return static_cast(m_levels.size()); } -float EasyGraphicsItem::levelY(uint8_t _level) const +float BlocksGraphicsItem::levelY(uint8_t _level) const { return y() + static_cast(_level) * static_cast(::profiler_gui::GRAPHICS_ROW_SIZE_FULL); } -void EasyGraphicsItem::setLevels(uint8_t _levels) +void BlocksGraphicsItem::setLevels(uint8_t _levels) { typedef decltype(m_levelsIndexes) IndexesT; static const auto MAX_CHILD_INDEX = ::profiler_gui::numeric_max(); @@ -1427,29 +1427,29 @@ void EasyGraphicsItem::setLevels(uint8_t _levels) m_rightBounds.resize(_levels, -1e100); } -void EasyGraphicsItem::reserve(uint8_t _level, unsigned int _items) +void BlocksGraphicsItem::reserve(uint8_t _level, unsigned int _items) { m_levels[_level].reserve(_items); } ////////////////////////////////////////////////////////////////////////// -const EasyGraphicsItem::Children& EasyGraphicsItem::items(uint8_t _level) const +const BlocksGraphicsItem::Children& BlocksGraphicsItem::items(uint8_t _level) const { return m_levels[_level]; } -const ::profiler_gui::EasyBlockItem& EasyGraphicsItem::getItem(uint8_t _level, unsigned int _index) const +const ::profiler_gui::EasyBlockItem& BlocksGraphicsItem::getItem(uint8_t _level, unsigned int _index) const { return m_levels[_level][_index]; } -::profiler_gui::EasyBlockItem& EasyGraphicsItem::getItem(uint8_t _level, unsigned int _index) +::profiler_gui::EasyBlockItem& BlocksGraphicsItem::getItem(uint8_t _level, unsigned int _index) { return m_levels[_level][_index]; } -unsigned int EasyGraphicsItem::addItem(uint8_t _level) +unsigned int BlocksGraphicsItem::addItem(uint8_t _level) { m_levels[_level].emplace_back(); return static_cast(m_levels[_level].size() - 1); diff --git a/profiler_gui/easy_graphics_item.h b/profiler_gui/easy_graphics_item.h index a980e58..950b1fc 100644 --- a/profiler_gui/easy_graphics_item.h +++ b/profiler_gui/easy_graphics_item.h @@ -5,7 +5,7 @@ * author : Victor Zarubkin * email : v.s.zarubkin@gmail.com * ----------------- : -* description : The file contains declaration of EasyGraphicsItem - an item +* description : The file contains declaration of BlocksGraphicsItem - an item * : used to draw profiler blocks on graphics scene. * ----------------- : * change log : * 2016/09/15 Victor Zarubkin: moved sources from blocks_graphics_view.h/.cpp @@ -69,9 +69,9 @@ ////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////// -class EasyGraphicsView; +class BlocksGraphicsView; -class EasyGraphicsItem : public QGraphicsItem +class BlocksGraphicsItem : public QGraphicsItem { typedef ::profiler_gui::EasyItems Children; typedef ::std::vector DrawIndexes; @@ -85,12 +85,12 @@ class EasyGraphicsItem : public QGraphicsItem QRectF m_boundingRect; ///< boundingRect (see QGraphicsItem) QString m_threadName; ///< const ::profiler::BlocksTreeRoot* m_pRoot; ///< Pointer to the root profiler block (thread block). Used by ProfTreeWidget to restore hierarchy. - uint8_t m_index; ///< This item's index in the list of items of EasyGraphicsView + uint8_t m_index; ///< This item's index in the list of items of BlocksGraphicsView public: - explicit EasyGraphicsItem(uint8_t _index, const::profiler::BlocksTreeRoot& _root); - virtual ~EasyGraphicsItem(); + explicit BlocksGraphicsItem(uint8_t _index, const::profiler::BlocksTreeRoot& _root); + virtual ~BlocksGraphicsItem(); // Public virtual methods @@ -170,8 +170,8 @@ public: private: - ///< Returns pointer to the EasyGraphicsView widget. - const EasyGraphicsView* view() const; + ///< Returns pointer to the BlocksGraphicsView widget. + const BlocksGraphicsView* view() const; #ifdef EASY_GRAPHICS_ITEM_RECURSIVE_PAINT void paintChildren(const float _minWidth, const int _narrowSizeHalf, const uint8_t _levelsNumber, QPainter* _painter, struct EasyPainterInformation& p, ::profiler_gui::EasyBlockItem& _item, const ::profiler_gui::EasyBlock& _itemBlock, RightBounds& _rightBounds, uint8_t _level, int8_t _mode); @@ -181,13 +181,12 @@ public: // Public inline methods - ///< Returns this item's index in the list of graphics items of EasyGraphicsView - inline uint8_t index() const - { + ///< Returns this item's index in the list of graphics items of BlocksGraphicsView + uint8_t index() const { return m_index; } -}; // END of class EasyGraphicsItem. +}; // END of class BlocksGraphicsItem. ////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////// diff --git a/profiler_gui/easy_graphics_scrollbar.cpp b/profiler_gui/easy_graphics_scrollbar.cpp index 5889d7f..cfb44b8 100644 --- a/profiler_gui/easy_graphics_scrollbar.cpp +++ b/profiler_gui/easy_graphics_scrollbar.cpp @@ -148,7 +148,7 @@ void GraphicsHistogramItem::paintMouseIndicator(QPainter* _painter, qreal _top, void GraphicsHistogramItem::paintByPtr(QPainter* _painter) { - const auto widget = static_cast(scene()->parent()); + const auto widget = static_cast(scene()->parent()); const bool bindMode = widget->bindMode(); const auto currentScale = widget->getWindowScale(); const auto bottom = m_boundingRect.bottom(); @@ -239,7 +239,7 @@ void GraphicsHistogramItem::paintByPtr(QPainter* _painter) void GraphicsHistogramItem::paintById(QPainter* _painter) { - const auto widget = static_cast(scene()->parent()); + const auto widget = static_cast(scene()->parent()); const bool bindMode = widget->bindMode(); const auto currentScale = widget->getWindowScale(); const auto bottom = m_boundingRect.bottom(); @@ -410,13 +410,15 @@ void GraphicsHistogramItem::setSource(profiler::thread_id_t _thread_id, const pr m_timeUnits = EASY_GLOBALS.time_units; setReady(false); - m_workerThread = std::thread([this](const profiler_gui::EasyItems* _source) + + auto source = m_pSource; + m_worker.enqueue([this, source] { m_maxValue = 0; m_minValue = 1e30; bool empty = true; - for (const auto& item : *_source) + for (const auto& item : *source) { if (isReady()) return; @@ -464,7 +466,7 @@ void GraphicsHistogramItem::setSource(profiler::thread_id_t _thread_id, const pr setReady(true); - }, m_pSource); + }, m_bReady); startTimer(); show(); @@ -536,10 +538,16 @@ void GraphicsHistogramItem::setSource(profiler::thread_id_t _thread_id, profiler m_threadWaitTime = root.wait_time; setReady(false); - m_workerThread = std::thread([this](decltype(root) profiler_thread, profiler::block_index_t selected_block, bool _showOnlyTopLevelBlocks) + + const auto selected_thread = std::ref(root); + const auto selected_block = EASY_GLOBALS.selected_block; + const bool showOnlyTopLevelBlocks = EASY_GLOBALS.display_only_frames_on_histogram; + m_worker.enqueue([this, selected_thread, selected_block, showOnlyTopLevelBlocks] { using Stack = std::vector >; + const auto& profiler_thread = selected_thread.get(); + m_maxValue = 0; m_minValue = 1e30; //const auto& profiler_thread = EASY_GLOBALS.profiler_blocks[m_threadId]; @@ -565,7 +573,7 @@ void GraphicsHistogramItem::setSource(profiler::thread_id_t _thread_id, profiler m_blockTotalDuraion += w; } - if (_showOnlyTopLevelBlocks) + if (showOnlyTopLevelBlocks) continue; stack.emplace_back(frame, 0U); @@ -652,7 +660,7 @@ void GraphicsHistogramItem::setSource(profiler::thread_id_t _thread_id, profiler setReady(true); - }, std::ref(root), EASY_GLOBALS.selected_block, EASY_GLOBALS.display_only_frames_on_histogram); + }, m_bReady); startTimer(); } @@ -777,7 +785,7 @@ void GraphicsHistogramItem::onModeChanged() if (!isImageUpdatePermitted()) return; - const auto widget = static_cast(scene()->parent()); + const auto widget = static_cast(scene()->parent()); if (!widget->bindMode() && EASY_GLOBALS.auto_adjust_histogram_height) { m_topValue = m_maxValue; @@ -800,10 +808,25 @@ bool GraphicsHistogramItem::updateImage() m_imageScaleUpdate = widget->range() / widget->sliderWidth(); m_imageOriginUpdate = widget->bindMode() ? (widget->value() - widget->sliderWidth() * 3) : widget->minimum(); - m_workerThread = std::thread(&This::updateImageAsync, this, m_boundingRect, m_regime, widget->getWindowScale(), - widget->minimum(), widget->maximum(), widget->range(), widget->value(), widget->sliderWidth(), - m_topValue, m_bottomValue, widget->bindMode(), EASY_GLOBALS.frame_time, EASY_GLOBALS.begin_time, - EASY_GLOBALS.auto_adjust_histogram_height); + // Ugly, but doesn't use exceeded count of threads + const auto rect = m_boundingRect; + const auto regime = m_regime; + const auto scale = widget->getWindowScale(); + const auto left = widget->minimum(); + const auto right = widget->maximum(); + const auto value = widget->value(); + const auto window = widget->sliderWidth(); + const auto top = m_topValue; + const auto bottom = m_bottomValue; + const auto bindMode = widget->bindMode(); + const auto frameTime = EASY_GLOBALS.frame_time; + const auto beginTime = EASY_GLOBALS.begin_time; + const auto autoHeight = EASY_GLOBALS.auto_adjust_histogram_height; + m_worker.enqueue([this, rect, regime, scale, left, right, value, window, top, bottom, bindMode, frameTime, beginTime, autoHeight] + { + updateImageAsync(rect, regime, scale, left, right, right - left, value, window, top, bottom, bindMode, + frameTime, beginTime, autoHeight); + }, m_bReady); return true; } @@ -1119,7 +1142,7 @@ void GraphicsHistogramItem::updateImageAsync(QRectF _boundingRect, HistRegime _r ////////////////////////////////////////////////////////////////////////// -EasyGraphicsScrollbar::EasyGraphicsScrollbar(int _initialHeight, QWidget* _parent) +BlocksGraphicsScrollbar::BlocksGraphicsScrollbar(int _initialHeight, QWidget* _parent) : Parent(_parent) , m_histogramItem(nullptr) { @@ -1134,27 +1157,27 @@ EasyGraphicsScrollbar::EasyGraphicsScrollbar(int _initialHeight, QWidget* _paren m_histogramItem->setBoundingRect(0, scene()->sceneRect().top() + margin(), scene()->width(), sceneHeight - margins() - 1); m_histogramItem->hide(); - connect(&EASY_GLOBALS.events, &profiler_gui::EasyGlobalSignals::expectedFrameTimeChanged, + connect(&EASY_GLOBALS.events, &profiler_gui::GlobalSignals::expectedFrameTimeChanged, this, &This::onExpectedFrameTimeChanged); - connect(&EASY_GLOBALS.events, &profiler_gui::EasyGlobalSignals::autoAdjustHistogramChanged, + connect(&EASY_GLOBALS.events, &profiler_gui::GlobalSignals::autoAdjustHistogramChanged, this, &This::onAutoAdjustHistogramChanged); - connect(&EASY_GLOBALS.events, &profiler_gui::EasyGlobalSignals::displayOnlyFramesOnHistogramChanged, + connect(&EASY_GLOBALS.events, &profiler_gui::GlobalSignals::displayOnlyFramesOnHistogramChanged, this, &This::onDisplayOnlyFramesOnHistogramChanged); - connect(&EASY_GLOBALS.events, &profiler_gui::EasyGlobalSignals::threadNameDecorationChanged, this, &This::onThreadViewChanged); - connect(&EASY_GLOBALS.events, &profiler_gui::EasyGlobalSignals::hexThreadIdChanged, this, &This::onThreadViewChanged); + connect(&EASY_GLOBALS.events, &profiler_gui::GlobalSignals::threadNameDecorationChanged, this, &This::onThreadViewChanged); + connect(&EASY_GLOBALS.events, &profiler_gui::GlobalSignals::hexThreadIdChanged, this, &This::onThreadViewChanged); } -EasyGraphicsScrollbar::~EasyGraphicsScrollbar() +BlocksGraphicsScrollbar::~BlocksGraphicsScrollbar() { } ////////////////////////////////////////////////////////////////////////// -void EasyGraphicsScrollbar::onThreadViewChanged() +void BlocksGraphicsScrollbar::onThreadViewChanged() { if (m_histogramItem->isVisible()) { @@ -1163,7 +1186,7 @@ void EasyGraphicsScrollbar::onThreadViewChanged() } } -void EasyGraphicsScrollbar::onExpectedFrameTimeChanged() +void BlocksGraphicsScrollbar::onExpectedFrameTimeChanged() { if (m_histogramItem->isVisible()) { @@ -1172,13 +1195,13 @@ void EasyGraphicsScrollbar::onExpectedFrameTimeChanged() } } -void EasyGraphicsScrollbar::onAutoAdjustHistogramChanged() +void BlocksGraphicsScrollbar::onAutoAdjustHistogramChanged() { if (m_histogramItem->isVisible()) m_histogramItem->onModeChanged(); } -void EasyGraphicsScrollbar::onDisplayOnlyFramesOnHistogramChanged() +void BlocksGraphicsScrollbar::onDisplayOnlyFramesOnHistogramChanged() { if (m_histogramItem->isVisible()) m_histogramItem->rebuildSource(GraphicsHistogramItem::Hist_Id); @@ -1186,18 +1209,18 @@ void EasyGraphicsScrollbar::onDisplayOnlyFramesOnHistogramChanged() ////////////////////////////////////////////////////////////////////////// -void EasyGraphicsScrollbar::clear() +void BlocksGraphicsScrollbar::clear() { setHistogramSource(0, nullptr); Parent::clear(); } -profiler::thread_id_t EasyGraphicsScrollbar::hystThread() const +profiler::thread_id_t BlocksGraphicsScrollbar::hystThread() const { return m_histogramItem->threadId(); } -void EasyGraphicsScrollbar::setHistogramSource(profiler::thread_id_t _thread_id, const profiler_gui::EasyItems* _items) +void BlocksGraphicsScrollbar::setHistogramSource(profiler::thread_id_t _thread_id, const profiler_gui::EasyItems* _items) { if (m_bLocked) return; @@ -1206,7 +1229,7 @@ void EasyGraphicsScrollbar::setHistogramSource(profiler::thread_id_t _thread_id, scene()->update(); } -void EasyGraphicsScrollbar::setHistogramSource(profiler::thread_id_t _thread_id, profiler::block_id_t _block_id) +void BlocksGraphicsScrollbar::setHistogramSource(profiler::thread_id_t _thread_id, profiler::block_id_t _block_id) { if (m_bLocked) return; @@ -1215,7 +1238,7 @@ void EasyGraphicsScrollbar::setHistogramSource(profiler::thread_id_t _thread_id, scene()->update(); } -void EasyGraphicsScrollbar::mousePressEvent(QMouseEvent* _event) +void BlocksGraphicsScrollbar::mousePressEvent(QMouseEvent* _event) { Parent::mousePressEvent(_event); if ((m_mouseButtons & Qt::RightButton) && _event->modifiers()) diff --git a/profiler_gui/easy_graphics_scrollbar.h b/profiler_gui/easy_graphics_scrollbar.h index c5eaa8e..62c0bc5 100644 --- a/profiler_gui/easy_graphics_scrollbar.h +++ b/profiler_gui/easy_graphics_scrollbar.h @@ -142,21 +142,21 @@ private: ////////////////////////////////////////////////////////////////////////// -class EasyGraphicsScrollbar : public GraphicsSliderArea +class BlocksGraphicsScrollbar : public GraphicsSliderArea { Q_OBJECT private: using Parent = GraphicsSliderArea; - using This = EasyGraphicsScrollbar; + using This = BlocksGraphicsScrollbar; GraphicsHistogramItem* m_histogramItem = nullptr; public: - explicit EasyGraphicsScrollbar(int _initialHeight, QWidget* _parent = nullptr); - ~EasyGraphicsScrollbar() override; + explicit BlocksGraphicsScrollbar(int _initialHeight, QWidget* _parent = nullptr); + ~BlocksGraphicsScrollbar() override; void clear() override; void mousePressEvent(QMouseEvent* _event) override; @@ -180,7 +180,7 @@ private slots: void onAutoAdjustHistogramChanged(); void onDisplayOnlyFramesOnHistogramChanged(); -}; // END of class EasyGraphicsScrollbar. +}; // END of class BlocksGraphicsScrollbar. ////////////////////////////////////////////////////////////////////////// diff --git a/profiler_gui/easy_qtimer.cpp b/profiler_gui/easy_qtimer.cpp index 3bed71a..cd90b24 100644 --- a/profiler_gui/easy_qtimer.cpp +++ b/profiler_gui/easy_qtimer.cpp @@ -5,7 +5,7 @@ * author : Victor Zarubkin * email : v.s.zarubkin@gmail.com * ----------------- : -* description : This file contains implementation of EasyQTimer class used to +* description : This file contains implementation of Timer class used to * : connect QTimer to non-QObject classes. * ----------------- : * change log : * 2016/12/05 Victor Zarubkin: Initial commit. @@ -57,69 +57,69 @@ ////////////////////////////////////////////////////////////////////////// -EasyQTimer::EasyQTimer() +Timer::Timer() : QObject() { - connect(&m_timer, &QTimer::timeout, this, &EasyQTimer::onTimeout); + connect(&m_timer, &QTimer::timeout, this, &Timer::onTimeout); } -EasyQTimer::EasyQTimer(::std::function&& handler, bool signleShot) +Timer::Timer(std::function&& handler, bool signleShot) : QObject() - , m_handler(::std::forward<::std::function&&>(handler)) + , m_handler(std::forward&&>(handler)) { m_timer.setSingleShot(signleShot); - connect(&m_timer, &QTimer::timeout, this, &EasyQTimer::onTimeout); + connect(&m_timer, &QTimer::timeout, this, &Timer::onTimeout); } -EasyQTimer::~EasyQTimer() +Timer::~Timer() { } -void EasyQTimer::onTimeout() +void Timer::onTimeout() { m_handler(); } -void EasyQTimer::setHandler(::std::function&& handler) +void Timer::setHandler(std::function&& handler) { m_handler = handler; } -void EasyQTimer::setSignleShot(bool singleShot) +void Timer::setSignleShot(bool singleShot) { m_timer.setSingleShot(singleShot); } -bool EasyQTimer::isSingleShot() const +bool Timer::isSingleShot() const { return m_timer.isSingleShot(); } -void EasyQTimer::setInterval(int msec) +void Timer::setInterval(int msec) { m_timer.setInterval(msec); } -void EasyQTimer::start(int msec) +void Timer::start(int msec) { stop(); m_timer.start(msec); } -void EasyQTimer::start() +void Timer::start() { stop(); m_timer.start(); } -void EasyQTimer::stop() +void Timer::stop() { if (m_timer.isActive()) m_timer.stop(); } -bool EasyQTimer::isActive() const +bool Timer::isActive() const { return m_timer.isActive(); } diff --git a/profiler_gui/easy_qtimer.h b/profiler_gui/easy_qtimer.h index 3892ba6..3cd74b1 100644 --- a/profiler_gui/easy_qtimer.h +++ b/profiler_gui/easy_qtimer.h @@ -5,7 +5,7 @@ * author : Victor Zarubkin * email : v.s.zarubkin@gmail.com * ----------------- : -* description : This file contains declaration of EasyQTimer class used to +* description : This file contains declaration of Timer class used to * : connect QTimer to non-QObject classes. * ----------------- : * change log : * 2016/12/05 Victor Zarubkin: Initial commit. @@ -61,7 +61,7 @@ ////////////////////////////////////////////////////////////////////////// -class EasyQTimer : public QObject +class Timer : public QObject { Q_OBJECT @@ -72,11 +72,11 @@ private: public: - explicit EasyQTimer(); - explicit EasyQTimer(::std::function&& handler, bool signleShot = false); - ~EasyQTimer() override; + explicit Timer(); + explicit Timer(std::function&& handler, bool signleShot = false); + ~Timer() override; - void setHandler(::std::function&& _handler); + void setHandler(std::function&& handler); void setSignleShot(bool singleShot); bool isSingleShot() const; @@ -91,7 +91,7 @@ private slots: void onTimeout(); -}; // END of class EasyQTimer. +}; // END of class Timer. ////////////////////////////////////////////////////////////////////////// diff --git a/profiler_gui/globals.cpp b/profiler_gui/globals.cpp index b8fa942..c326e1c 100644 --- a/profiler_gui/globals.cpp +++ b/profiler_gui/globals.cpp @@ -61,15 +61,15 @@ namespace profiler_gui { - EasyGlobals& EasyGlobals::instance() + Globals& Globals::instance() { // It's okay even without C++11 "magic statics" feature because first call happens // on application initialization - there is only one thread and no data races occur. - static EasyGlobals globals; + static Globals globals; return globals; } - EasyGlobals::EasyGlobals() + Globals::Globals() : theme("default") , bg_font(::profiler_gui::EFont("DejaVu Sans", 10, QFont::Bold)) , chronometer_font(::profiler_gui::EFont("DejaVu Sans", 16, QFont::Bold)) diff --git a/profiler_gui/globals.h b/profiler_gui/globals.h index 09481c5..960306b 100644 --- a/profiler_gui/globals.h +++ b/profiler_gui/globals.h @@ -171,11 +171,11 @@ namespace profiler_gui { bool empty = true; }; - struct EasyGlobals Q_DECL_FINAL + struct Globals Q_DECL_FINAL { - static EasyGlobals& instance(); + static Globals& instance(); - EasyGlobalSignals events; ///< Global signals + GlobalSignals events; ///< Global signals ::profiler::thread_blocks_tree_t profiler_blocks; ///< Profiler blocks tree loaded from file ::profiler::descriptors_list_t descriptors; ///< Profiler block descriptors list EasyBlocks gui_blocks; ///< Profiler graphics blocks builded by GUI @@ -226,16 +226,16 @@ namespace profiler_gui { private: - EasyGlobals(); + Globals(); - }; // END of struct EasyGlobals. + }; // END of struct Globals. ////////////////////////////////////////////////////////////////////////// } // END of namespace profiler_gui. #ifndef IGNORE_GLOBALS_DECLARATION -#define EASY_GLOBALS ::profiler_gui::EasyGlobals::instance() +#define EASY_GLOBALS ::profiler_gui::Globals::instance() inline ::profiler_gui::EasyBlock& easyBlock(::profiler::block_index_t i) { return EASY_GLOBALS.gui_blocks[i]; diff --git a/profiler_gui/globals_qobjects.cpp b/profiler_gui/globals_qobjects.cpp index 62319b1..a7e1838 100644 --- a/profiler_gui/globals_qobjects.cpp +++ b/profiler_gui/globals_qobjects.cpp @@ -5,7 +5,7 @@ * authors : Victor Zarubkin, Sergey Yagovtsev * email : v.s.zarubkin@gmail.com, yse.sey@gmail.com * ----------------- : -* description : The file contains implementation of EasyGlobalSignals QObject class. +* description : The file contains implementation of GlobalSignals QObject class. * ----------------- : * change log : * 2016/08/08 Sergey Yagovtsev: moved sources from globals.cpp * : @@ -59,11 +59,11 @@ namespace profiler_gui { - EasyGlobalSignals::EasyGlobalSignals() : QObject() + GlobalSignals::GlobalSignals() : QObject() { } - EasyGlobalSignals::~EasyGlobalSignals() + GlobalSignals::~GlobalSignals() { } diff --git a/profiler_gui/globals_qobjects.h b/profiler_gui/globals_qobjects.h index 5170604..f88b703 100644 --- a/profiler_gui/globals_qobjects.h +++ b/profiler_gui/globals_qobjects.h @@ -5,7 +5,7 @@ * authors : Victor Zarubkin, Sergey Yagovtsev * email : v.s.zarubkin@gmail.com, yse.sey@gmail.com * ----------------- : -* description : The file contains declaration of EasyGlobalSignals QObject class. +* description : The file contains declaration of GlobalSignals QObject class. * ----------------- : * change log : * 2016/08/08 Sergey Yagovtsev: moved sources from globals.h * : @@ -60,14 +60,14 @@ namespace profiler_gui { - class EasyGlobalSignals Q_DECL_FINAL : public QObject + class GlobalSignals Q_DECL_FINAL : public QObject { Q_OBJECT public: - EasyGlobalSignals(); - ~EasyGlobalSignals() Q_DECL_OVERRIDE; + GlobalSignals(); + ~GlobalSignals() Q_DECL_OVERRIDE; signals: @@ -100,7 +100,7 @@ namespace profiler_gui { void chartWheeled(qreal pos, int delta); void chartSliderChanged(qreal pos); - }; // END of class EasyGlobalSignals. + }; // END of class GlobalSignals. } // END of namespace profiler_gui. diff --git a/profiler_gui/graphics_image_item.cpp b/profiler_gui/graphics_image_item.cpp index 9b0bca7..300bfab 100644 --- a/profiler_gui/graphics_image_item.cpp +++ b/profiler_gui/graphics_image_item.cpp @@ -258,9 +258,6 @@ void GraphicsImageItem::onTimeout() { // Image updated - if (m_workerThread.joinable()) - m_workerThread.join(); - m_workerImage->swap(m_image); delete m_workerImage; m_workerImage = nullptr; @@ -286,18 +283,15 @@ bool GraphicsImageItem::isImageUpdatePermitted() const void GraphicsImageItem::cancelAnyJob() { - setReady(true); - if (m_workerThread.joinable()) - m_workerThread.join(); - //setReady(false); + stopTimer(); + + m_worker.dequeue(); delete m_workerImage; m_workerImage = nullptr; m_imageOriginUpdate = m_imageOrigin; m_imageScaleUpdate = m_imageScale; - - stopTimer(); } void GraphicsImageItem::resetTopBottomValues() diff --git a/profiler_gui/graphics_image_item.h b/profiler_gui/graphics_image_item.h index 99fa692..99a11ea 100644 --- a/profiler_gui/graphics_image_item.h +++ b/profiler_gui/graphics_image_item.h @@ -4,9 +4,9 @@ #define EASY_PROFILER_GRAPHICS_IMAGE_ITEM_H #include -#include #include #include "easy_qtimer.h" +#include "thread_pool_task.h" class GraphicsImageItem : public QGraphicsItem { @@ -17,8 +17,8 @@ protected: QRectF m_boundingRect; QImage m_image; - EasyQTimer m_boundaryTimer; - std::thread m_workerThread; + Timer m_boundaryTimer; + ThreadPoolTask m_worker; QPointF m_mousePos; QImage* m_workerImage; qreal m_imageOrigin; @@ -31,11 +31,11 @@ protected: qreal m_bottomValue; qreal m_maxValue; qreal m_minValue; + std::atomic_bool m_bReady; private: - EasyQTimer m_timer; - std::atomic_bool m_bReady; + Timer m_timer; bool m_bPermitImageUpdate; ///< Is false when m_workerThread is parsing input dataset (when setSource(_block_id) is called) public: diff --git a/profiler_gui/graphics_slider_area.cpp b/profiler_gui/graphics_slider_area.cpp index 648dfc2..bc2a1e0 100644 --- a/profiler_gui/graphics_slider_area.cpp +++ b/profiler_gui/graphics_slider_area.cpp @@ -218,13 +218,13 @@ GraphicsSliderArea::GraphicsSliderArea(QWidget* _parent) centerOn(0, 0); auto globalEvents = &EASY_GLOBALS.events; - connect(globalEvents, &profiler_gui::EasyGlobalSignals::sceneCleared, this, &This::clear); - connect(globalEvents, &profiler_gui::EasyGlobalSignals::sceneVisibleRegionSizeChanged, this, &This::setSliderWidth); - connect(globalEvents, &profiler_gui::EasyGlobalSignals::sceneVisibleRegionPosChanged, this, &This::setValue); - connect(globalEvents, &profiler_gui::EasyGlobalSignals::chartSliderChanged, this, &This::onExternalChartSliderChanged); - connect(globalEvents, &profiler_gui::EasyGlobalSignals::sceneSizeChanged, this, &This::onSceneSizeChanged); - connect(globalEvents, &profiler_gui::EasyGlobalSignals::lockCharts, this, &This::lock); - connect(globalEvents, &profiler_gui::EasyGlobalSignals::unlockCharts, this, &This::unlock); + connect(globalEvents, &profiler_gui::GlobalSignals::sceneCleared, this, &This::clear); + connect(globalEvents, &profiler_gui::GlobalSignals::sceneVisibleRegionSizeChanged, this, &This::setSliderWidth); + connect(globalEvents, &profiler_gui::GlobalSignals::sceneVisibleRegionPosChanged, this, &This::setValue); + connect(globalEvents, &profiler_gui::GlobalSignals::chartSliderChanged, this, &This::onExternalChartSliderChanged); + connect(globalEvents, &profiler_gui::GlobalSignals::sceneSizeChanged, this, &This::onSceneSizeChanged); + connect(globalEvents, &profiler_gui::GlobalSignals::lockCharts, this, &This::lock); + connect(globalEvents, &profiler_gui::GlobalSignals::unlockCharts, this, &This::unlock); } GraphicsSliderArea::~GraphicsSliderArea() diff --git a/profiler_gui/main.cpp b/profiler_gui/main.cpp index fb5a0bb..ab09750 100644 --- a/profiler_gui/main.cpp +++ b/profiler_gui/main.cpp @@ -52,6 +52,7 @@ #include #include "main_window.h" #include "globals.h" +#include "thread_pool.h" #if defined(_WIN32) && defined (_BUILD_RELEASE_) #pragma comment(linker, "/SUBSYSTEM:windows /ENTRY:mainCRTStartup") @@ -62,12 +63,15 @@ int main(int argc, char **argv) auto now = ::std::chrono::duration_cast(::std::chrono::system_clock::now().time_since_epoch()).count() >> 1; srand((unsigned int)now); + // Instanciate thread pool to avoid data races for compilers without C++11 thread-safe statics + ThreadPool::instance(); + QApplication app(argc, argv); - //Instanciate easy globals after QApplication to allow creation of global fonts, and on the main thread to avoid data races - profiler_gui::EasyGlobals::instance(); + // Instanciate easy globals after QApplication to allow creation of global fonts, and on the main thread to avoid data races + profiler_gui::Globals::instance(); - EasyMainWindow window; + MainWindow window; window.show(); return app.exec(); diff --git a/profiler_gui/main_window.cpp b/profiler_gui/main_window.cpp index 171c619..7ce3527 100644 --- a/profiler_gui/main_window.cpp +++ b/profiler_gui/main_window.cpp @@ -9,7 +9,7 @@ * ----------------- : * change log : * 2016/06/26 Victor Zarubkin: Initial commit. * : -* : * 2016/06/27 Victor Zarubkin: Passing blocks number to EasyTreeWidget::setTree(). +* : * 2016/06/27 Victor Zarubkin: Passing blocks number to BlocksTreeWidget::setTree(). * : * : * 2016/06/29 Victor Zarubkin: Added menu with tests. * : @@ -195,7 +195,7 @@ EasyDockWidget::~EasyDockWidget() { } -EasyMainWindow::EasyMainWindow() : Parent(), m_theme("default"), m_lastAddress("localhost"), m_lastPort(::profiler::DEFAULT_PORT) +MainWindow::MainWindow() : Parent(), m_theme("default"), m_lastAddress("localhost"), m_lastPort(::profiler::DEFAULT_PORT) { { QIcon icon(":/images/logo"); if (!icon.isNull()) QApplication::setWindowIcon(icon); } @@ -214,7 +214,7 @@ EasyMainWindow::EasyMainWindow() : Parent(), m_theme("default"), m_lastAddress(" m_graphicsView->setMinimumHeight(50); m_graphicsView->setAllowedAreas(Qt::AllDockWidgetAreas); - auto graphicsView = new EasyGraphicsViewWidget(this); + auto graphicsView = new DiagramWidget(this); graphicsView->setObjectName("ProfilerGUI_Diagram_GraphicsView"); m_graphicsView->setWidget(graphicsView); @@ -223,12 +223,12 @@ EasyMainWindow::EasyMainWindow() : Parent(), m_theme("default"), m_lastAddress(" m_treeWidget->setMinimumHeight(50); m_treeWidget->setAllowedAreas(Qt::AllDockWidgetAreas); - auto treeWidget = new EasyHierarchyWidget(this); + auto treeWidget = new HierarchyWidget(this); m_treeWidget->setWidget(treeWidget); m_fpsViewer = new EasyDockWidget("FPS Monitor", this); m_fpsViewer->setObjectName("ProfilerGUI_FPS"); - m_fpsViewer->setWidget(new EasyFrameRateViewer(this)); + m_fpsViewer->setWidget(new FpsViewerWidget(this)); m_fpsViewer->setAllowedAreas(Qt::TopDockWidgetArea | Qt::BottomDockWidgetArea); addDockWidget(Qt::TopDockWidgetArea, m_graphicsView); @@ -236,7 +236,7 @@ EasyMainWindow::EasyMainWindow() : Parent(), m_theme("default"), m_lastAddress(" addDockWidget(Qt::TopDockWidgetArea, m_fpsViewer); #if EASY_GUI_USE_DESCRIPTORS_DOCK_WINDOW != 0 - auto descTree = new EasyDescWidget(); + auto descTree = new BlockDescriptorsWidget(); m_descTreeWidget = new EasyDockWidget("Blocks"); m_descTreeWidget->setObjectName("ProfilerGUI_Blocks"); m_descTreeWidget->setMinimumHeight(50); @@ -699,7 +699,7 @@ EasyMainWindow::EasyMainWindow() : Parent(), m_theme("default"), m_lastAddress(" action = new QAction(theme, actionGroup); action->setCheckable(true); action->setChecked(action->text() == EASY_GLOBALS.theme); - connect(action, &QAction::triggered, this, &EasyMainWindow::onThemeChange); + connect(action, &QAction::triggered, this, &MainWindow::onThemeChange); submenu->addAction(action); } @@ -723,7 +723,7 @@ EasyMainWindow::EasyMainWindow() : Parent(), m_theme("default"), m_lastAddress(" m_frameTimeEdit->setValidator(val); m_frameTimeEdit->setText(QString::number(EASY_GLOBALS.frame_time * 1e-3)); connect(m_frameTimeEdit, &QLineEdit::editingFinished, this, &This::onFrameTimeEditFinish); - connect(&EASY_GLOBALS.events, &::profiler_gui::EasyGlobalSignals::expectedFrameTimeChanged, this, &This::onFrameTimeChanged); + connect(&EASY_GLOBALS.events, &::profiler_gui::GlobalSignals::expectedFrameTimeChanged, this, &This::onFrameTimeChanged); toolbar->addWidget(m_frameTimeEdit); lbl = new QLabel("ms", toolbar); @@ -731,7 +731,7 @@ EasyMainWindow::EasyMainWindow() : Parent(), m_theme("default"), m_lastAddress(" toolbar->addWidget(lbl); - connect(graphicsView->view(), &EasyGraphicsView::intervalChanged, treeWidget->tree(), &EasyTreeWidget::setTreeBlocks); + connect(graphicsView->view(), &BlocksGraphicsView::intervalChanged, treeWidget->tree(), &BlocksTreeWidget::setTreeBlocks); connect(&m_readerTimer, &QTimer::timeout, this, &This::onFileReaderTimeout); connect(&m_listenerTimer, &QTimer::timeout, this, &This::onListenerTimerTimeout); connect(&m_fpsRequestTimer, &QTimer::timeout, this, &This::onFrameTimeRequestTimeout); @@ -745,34 +745,34 @@ EasyMainWindow::EasyMainWindow() : Parent(), m_theme("default"), m_lastAddress(" loadFile(opened_filename); } - connect(&EASY_GLOBALS.events, &::profiler_gui::EasyGlobalSignals::blockStatusChanged, this, &This::onBlockStatusChange); - connect(&EASY_GLOBALS.events, &::profiler_gui::EasyGlobalSignals::blocksRefreshRequired, this, &This::onGetBlockDescriptionsClicked); + connect(&EASY_GLOBALS.events, &::profiler_gui::GlobalSignals::blockStatusChanged, this, &This::onBlockStatusChange); + connect(&EASY_GLOBALS.events, &::profiler_gui::GlobalSignals::blocksRefreshRequired, this, &This::onGetBlockDescriptionsClicked); } -EasyMainWindow::~EasyMainWindow() +MainWindow::~MainWindow() { } ////////////////////////////////////////////////////////////////////////// -void EasyMainWindow::dragEnterEvent(QDragEnterEvent* drag_event) +void MainWindow::dragEnterEvent(QDragEnterEvent* drag_event) { if (drag_event->mimeData()->hasUrls()) drag_event->acceptProposedAction(); } -void EasyMainWindow::dragMoveEvent(QDragMoveEvent* drag_event) +void MainWindow::dragMoveEvent(QDragMoveEvent* drag_event) { if (drag_event->mimeData()->hasUrls()) drag_event->acceptProposedAction(); } -void EasyMainWindow::dragLeaveEvent(QDragLeaveEvent* drag_event) +void MainWindow::dragLeaveEvent(QDragLeaveEvent* drag_event) { drag_event->accept(); } -void EasyMainWindow::dropEvent(QDropEvent* drop_event) +void MainWindow::dropEvent(QDropEvent* drop_event) { const auto& urls = drop_event->mimeData()->urls(); if (!urls.empty()) @@ -798,7 +798,7 @@ void EasyMainWindow::dropEvent(QDropEvent* drop_event) ////////////////////////////////////////////////////////////////////////// -void EasyMainWindow::onThemeChange(bool) +void MainWindow::onThemeChange(bool) { auto action = qobject_cast(sender()); if (action == nullptr) @@ -814,7 +814,7 @@ void EasyMainWindow::onThemeChange(bool) ////////////////////////////////////////////////////////////////////////// -void EasyMainWindow::onOpenFileClicked(bool) +void MainWindow::onOpenFileClicked(bool) { auto action = qobject_cast(sender()); if (action == nullptr) @@ -850,7 +850,7 @@ void EasyMainWindow::onOpenFileClicked(bool) ////////////////////////////////////////////////////////////////////////// -void EasyMainWindow::addFileToList(const QString& filename) +void MainWindow::addFileToList(const QString& filename) { m_lastFiles.push_front(filename); @@ -878,18 +878,18 @@ void EasyMainWindow::addFileToList(const QString& filename) setWindowTitle(QString(EASY_DEFAULT_WINDOW_TITLE " - [%1]").arg(m_lastFiles.front())); } -void EasyMainWindow::loadFile(const QString& filename) +void MainWindow::loadFile(const QString& filename) { const auto i = filename.lastIndexOf(QChar('/')); const auto j = filename.lastIndexOf(QChar('\\')); - createProgressDialog(QString("Loading %1...").arg(filename.mid(::std::max(i, j) + 1))); + createProgressDialog(QString("Loading %1...").arg(filename.mid(std::max(i, j) + 1))); m_readerTimer.start(LOADER_TIMER_INTERVAL); m_reader.load(filename); } -void EasyMainWindow::readStream(::std::stringstream& _data) +void MainWindow::readStream(std::stringstream& _data) { createProgressDialog(tr("Reading from stream...")); m_readerTimer.start(LOADER_TIMER_INTERVAL); @@ -898,7 +898,7 @@ void EasyMainWindow::readStream(::std::stringstream& _data) ////////////////////////////////////////////////////////////////////////// -void EasyMainWindow::onSaveFileClicked(bool) +void MainWindow::onSaveFileClicked(bool) { if (m_serializedBlocks.empty()) return; @@ -907,7 +907,7 @@ void EasyMainWindow::onSaveFileClicked(bool) const auto i = lastFile.lastIndexOf(QChar('/')); const auto j = lastFile.lastIndexOf(QChar('\\')); - auto k = ::std::max(i, j); + auto k = std::max(i, j); QString dir; if (k > 0) @@ -968,10 +968,10 @@ void EasyMainWindow::onSaveFileClicked(bool) int8_t retry1 = -1; while (++retry1 < 4) { - ::std::ifstream inFile(m_bNetworkFileRegime ? NETWORK_CACHE_FILE : lastFile.toStdString().c_str(), ::std::fstream::binary); + std::ifstream inFile(m_bNetworkFileRegime ? NETWORK_CACHE_FILE : lastFile.toStdString().c_str(), std::fstream::binary); if (!inFile.is_open()) { - ::std::this_thread::sleep_for(::std::chrono::milliseconds(500)); + std::this_thread::sleep_for(std::chrono::milliseconds(500)); continue; } @@ -980,10 +980,10 @@ void EasyMainWindow::onSaveFileClicked(bool) int8_t retry2 = -1; while (++retry2 < 4) { - ::std::ofstream outFile(filename.toStdString(), ::std::fstream::binary); + std::ofstream outFile(filename.toStdString(), std::fstream::binary); if (!outFile.is_open()) { - ::std::this_thread::sleep_for(::std::chrono::milliseconds(500)); + std::this_thread::sleep_for(std::chrono::milliseconds(500)); continue; } @@ -1034,13 +1034,13 @@ void EasyMainWindow::onSaveFileClicked(bool) ////////////////////////////////////////////////////////////////////////// -void EasyMainWindow::clear() +void MainWindow::clear() { - static_cast(m_treeWidget->widget())->clear(true); - static_cast(m_graphicsView->widget())->clear(); + static_cast(m_treeWidget->widget())->clear(true); + static_cast(m_graphicsView->widget())->clear(); #if EASY_GUI_USE_DESCRIPTORS_DOCK_WINDOW != 0 - static_cast(m_descTreeWidget->widget())->clear(); + static_cast(m_descTreeWidget->widget())->clear(); #endif if (m_dialogDescTree != nullptr) m_dialogDescTree->clear(); @@ -1069,14 +1069,14 @@ void EasyMainWindow::clear() ////////////////////////////////////////////////////////////////////////// -void EasyMainWindow::refreshDiagram() +void MainWindow::refreshDiagram() { - static_cast(m_graphicsView->widget())->view()->scene()->update(); + static_cast(m_graphicsView->widget())->view()->scene()->update(); } ////////////////////////////////////////////////////////////////////////// -void EasyMainWindow::onDeleteClicked(bool) +void MainWindow::onDeleteClicked(bool) { int button = QMessageBox::Yes; if (m_bNetworkFileRegime) @@ -1088,14 +1088,14 @@ void EasyMainWindow::onDeleteClicked(bool) ////////////////////////////////////////////////////////////////////////// -void EasyMainWindow::onExitClicked(bool) +void MainWindow::onExitClicked(bool) { close(); } ////////////////////////////////////////////////////////////////////////// -void EasyMainWindow::onEncodingChanged(bool) +void MainWindow::onEncodingChanged(bool) { auto action = qobject_cast(sender()); if (action == nullptr) @@ -1107,20 +1107,20 @@ void EasyMainWindow::onEncodingChanged(bool) QTextCodec::setCodecForLocale(codec); } -void EasyMainWindow::onChronoTextPosChanged(bool) +void MainWindow::onChronoTextPosChanged(bool) { auto _sender = qobject_cast(sender()); EASY_GLOBALS.chrono_text_position = static_cast<::profiler_gui::ChronometerTextPosition>(_sender->data().toInt()); refreshDiagram(); } -void EasyMainWindow::onUnitsChanged(bool) +void MainWindow::onUnitsChanged(bool) { auto _sender = qobject_cast(sender()); EASY_GLOBALS.time_units = static_cast<::profiler_gui::TimeUnits>(_sender->data().toInt()); } -void EasyMainWindow::onEnableDisableStatistics(bool _checked) +void MainWindow::onEnableDisableStatistics(bool _checked) { EASY_GLOBALS.enable_statistics = _checked; @@ -1144,22 +1144,22 @@ void EasyMainWindow::onEnableDisableStatistics(bool _checked) } } -void EasyMainWindow::onCollapseItemsAfterCloseChanged(bool _checked) +void MainWindow::onCollapseItemsAfterCloseChanged(bool _checked) { EASY_GLOBALS.collapse_items_on_tree_close = _checked; } -void EasyMainWindow::onAllItemsExpandedByDefaultChange(bool _checked) +void MainWindow::onAllItemsExpandedByDefaultChange(bool _checked) { EASY_GLOBALS.all_items_expanded_by_default = _checked; } -void EasyMainWindow::onBindExpandStatusChange(bool _checked) +void MainWindow::onBindExpandStatusChange(bool _checked) { EASY_GLOBALS.bind_scene_and_tree_expand_status = _checked; } -void EasyMainWindow::onHierarchyFlagChange(bool _checked) +void MainWindow::onHierarchyFlagChange(bool _checked) { EASY_GLOBALS.only_current_thread_hierarchy = _checked; emit EASY_GLOBALS.events.hierarchyFlagChanged(_checked); @@ -1167,45 +1167,45 @@ void EasyMainWindow::onHierarchyFlagChange(bool _checked) ////////////////////////////////////////////////////////////////////////// -void EasyMainWindow::onExpandAllClicked(bool) +void MainWindow::onExpandAllClicked(bool) { for (auto& block : EASY_GLOBALS.gui_blocks) block.expanded = true; emit EASY_GLOBALS.events.itemsExpandStateChanged(); - auto tree = static_cast(m_treeWidget->widget())->tree(); + auto tree = static_cast(m_treeWidget->widget())->tree(); const QSignalBlocker b(tree); tree->expandAll(); } -void EasyMainWindow::onCollapseAllClicked(bool) +void MainWindow::onCollapseAllClicked(bool) { for (auto& block : EASY_GLOBALS.gui_blocks) block.expanded = false; emit EASY_GLOBALS.events.itemsExpandStateChanged(); - auto tree = static_cast(m_treeWidget->widget())->tree(); + auto tree = static_cast(m_treeWidget->widget())->tree(); const QSignalBlocker b(tree); tree->collapseAll(); } ////////////////////////////////////////////////////////////////////////// -void EasyMainWindow::onSpacingChange(int _value) +void MainWindow::onSpacingChange(int _value) { EASY_GLOBALS.blocks_spacing = _value; refreshDiagram(); } -void EasyMainWindow::onMinSizeChange(int _value) +void MainWindow::onMinSizeChange(int _value) { EASY_GLOBALS.blocks_size_min = _value; refreshDiagram(); } -void EasyMainWindow::onNarrowSizeChange(int _value) +void MainWindow::onNarrowSizeChange(int _value) { EASY_GLOBALS.blocks_narrow_size = _value; refreshDiagram(); @@ -1213,7 +1213,7 @@ void EasyMainWindow::onNarrowSizeChange(int _value) ////////////////////////////////////////////////////////////////////////// -void EasyMainWindow::onFpsIntervalChange(int _value) +void MainWindow::onFpsIntervalChange(int _value) { EASY_GLOBALS.fps_timer_interval = _value; @@ -1224,19 +1224,19 @@ void EasyMainWindow::onFpsIntervalChange(int _value) m_fpsRequestTimer.start(_value); } -void EasyMainWindow::onFpsHistoryChange(int _value) +void MainWindow::onFpsHistoryChange(int _value) { EASY_GLOBALS.max_fps_history = _value; } -void EasyMainWindow::onFpsMonitorLineWidthChange(int _value) +void MainWindow::onFpsMonitorLineWidthChange(int _value) { EASY_GLOBALS.fps_widget_line_width = _value; } ////////////////////////////////////////////////////////////////////////// -void EasyMainWindow::onEditBlocksClicked(bool) +void MainWindow::onEditBlocksClicked(bool) { if (m_descTreeDialog.ptr != nullptr) { @@ -1247,7 +1247,7 @@ void EasyMainWindow::onEditBlocksClicked(bool) m_descTreeDialog.create(); connect(m_descTreeDialog.ptr, &QDialog::finished, this, &This::onDescTreeDialogClose); - m_dialogDescTree = new EasyDescWidget(m_descTreeDialog.ptr); + m_dialogDescTree = new BlockDescriptorsWidget(m_descTreeDialog.ptr); auto lay = new QVBoxLayout(m_descTreeDialog.ptr); lay->addWidget(m_dialogDescTree); @@ -1258,7 +1258,7 @@ void EasyMainWindow::onEditBlocksClicked(bool) m_descTreeDialog.ptr->show(); } -void EasyMainWindow::onDescTreeDialogClose(int) +void MainWindow::onDescTreeDialogClose(int) { disconnect(m_descTreeDialog.ptr, &QDialog::finished, this, &This::onDescTreeDialogClose); m_descTreeDialog.saveGeometry(); @@ -1268,7 +1268,7 @@ void EasyMainWindow::onDescTreeDialogClose(int) ////////////////////////////////////////////////////////////////////////// -void EasyMainWindow::closeEvent(QCloseEvent* close_event) +void MainWindow::closeEvent(QCloseEvent* close_event) { if (m_bNetworkFileRegime) { @@ -1293,7 +1293,7 @@ void EasyMainWindow::closeEvent(QCloseEvent* close_event) ////////////////////////////////////////////////////////////////////////// -void EasyMainWindow::loadSettings() +void MainWindow::loadSettings() { QSettings settings(::profiler_gui::ORGANAZATION_NAME, ::profiler_gui::APPLICATION_NAME); settings.beginGroup("main"); @@ -1440,7 +1440,7 @@ void EasyMainWindow::loadSettings() settings.endGroup(); } -void EasyMainWindow::loadGeometry() +void MainWindow::loadGeometry() { QSettings settings(::profiler_gui::ORGANAZATION_NAME, ::profiler_gui::APPLICATION_NAME); settings.beginGroup("main"); @@ -1461,7 +1461,7 @@ void EasyMainWindow::loadGeometry() if (!geometry.isEmpty()) m_graphicsView->restoreGeometry(geometry); - static_cast(m_graphicsView->widget())->restore(settings); + static_cast(m_graphicsView->widget())->restore(settings); auto state = settings.value("windowState").toByteArray(); if (!state.isEmpty()) @@ -1470,7 +1470,7 @@ void EasyMainWindow::loadGeometry() settings.endGroup(); } -void EasyMainWindow::saveSettingsAndGeometry() +void MainWindow::saveSettingsAndGeometry() { QSettings settings(::profiler_gui::ORGANAZATION_NAME, ::profiler_gui::APPLICATION_NAME); settings.beginGroup("main"); @@ -1479,7 +1479,7 @@ void EasyMainWindow::saveSettingsAndGeometry() settings.setValue("fpsGeometry", m_fpsViewer->saveGeometry()); settings.setValue("descTreeDialogGeometry", m_descTreeDialog.geometry); settings.setValue("diagramGeometry", m_graphicsView->saveGeometry()); - static_cast(m_graphicsView->widget())->save(settings); + static_cast(m_graphicsView->widget())->save(settings); settings.setValue("windowState", this->saveState()); @@ -1519,7 +1519,7 @@ void EasyMainWindow::saveSettingsAndGeometry() settings.endGroup(); } -void EasyMainWindow::destroyProgressDialog() +void MainWindow::destroyProgressDialog() { if (m_progress != nullptr) { @@ -1529,7 +1529,7 @@ void EasyMainWindow::destroyProgressDialog() } } -void EasyMainWindow::createProgressDialog(const QString& text) +void MainWindow::createProgressDialog(const QString& text) { destroyProgressDialog(); @@ -1543,7 +1543,7 @@ void EasyMainWindow::createProgressDialog(const QString& text) m_progress->show(); } -void EasyMainWindow::setDisconnected(bool _showMessage) +void MainWindow::setDisconnected(bool _showMessage) { if (m_fpsRequestTimer.isActive()) m_fpsRequestTimer.stop(); @@ -1568,9 +1568,10 @@ void EasyMainWindow::setDisconnected(bool _showMessage) ////////////////////////////////////////////////////////////////////////// -void EasyMainWindow::onFrameTimeRequestTimeout() +void MainWindow::onFrameTimeRequestTimeout() { - if (EASY_GLOBALS.fps_enabled && EASY_GLOBALS.connected && (m_listener.regime() == LISTENER_IDLE || m_listener.regime() == LISTENER_CAPTURE)) + if (EASY_GLOBALS.fps_enabled && EASY_GLOBALS.connected && + (m_listener.regime() == ListenerRegime::Idle || m_listener.regime() == ListenerRegime::Capture)) { if (m_listener.requestFrameTime()) { @@ -1584,14 +1585,15 @@ void EasyMainWindow::onFrameTimeRequestTimeout() } } -void EasyMainWindow::checkFrameTimeReady() +void MainWindow::checkFrameTimeReady() { - if (EASY_GLOBALS.fps_enabled && EASY_GLOBALS.connected && (m_listener.regime() == LISTENER_IDLE || m_listener.regime() == LISTENER_CAPTURE)) + if (EASY_GLOBALS.fps_enabled && EASY_GLOBALS.connected && + (m_listener.regime() == ListenerRegime::Idle || m_listener.regime() == ListenerRegime::Capture)) { uint32_t maxTime = 0, avgTime = 0; if (m_listener.frameTime(maxTime, avgTime)) { - static_cast(m_fpsViewer->widget())->addPoint(maxTime, avgTime); + static_cast(m_fpsViewer->widget())->addPoint(maxTime, avgTime); } else if (m_fpsRequestTimer.isActive()) { @@ -1602,16 +1604,16 @@ void EasyMainWindow::checkFrameTimeReady() ////////////////////////////////////////////////////////////////////////// -void EasyMainWindow::onListenerTimerTimeout() +void MainWindow::onListenerTimerTimeout() { if (!m_listener.connected()) { - if (m_listener.regime() == LISTENER_CAPTURE_RECEIVE) + if (m_listener.regime() == ListenerRegime::Capture_Receive) m_listener.finalizeCapture(); if (m_listenerDialog) m_listenerDialog->reject(); } - else if (m_listener.regime() == LISTENER_CAPTURE_RECEIVE) + else if (m_listener.regime() == ListenerRegime::Capture_Receive) { if (m_listener.captured()) { @@ -1632,9 +1634,9 @@ void EasyMainWindow::onListenerTimerTimeout() } } -void EasyMainWindow::onListenerDialogClose(int _result) +void MainWindow::onListenerDialogClose(int _result) { - if (m_listener.regime() != LISTENER_CAPTURE_RECEIVE || !m_listener.connected()) + if (m_listener.regime() != ListenerRegime::Capture_Receive || !m_listener.connected()) { if (m_listenerTimer.isActive()) m_listenerTimer.stop(); @@ -1645,15 +1647,16 @@ void EasyMainWindow::onListenerDialogClose(int _result) switch (m_listener.regime()) { - case LISTENER_CAPTURE: + case ListenerRegime::Capture: { - m_listenerDialog = new QMessageBox(QMessageBox::Information, "Receiving data...", "This process may take some time.", QMessageBox::Cancel, this); + m_listenerDialog = new QMessageBox(QMessageBox::Information, "Receiving data...", + "This process may take some time.", QMessageBox::Cancel, this); m_listenerDialog->setAttribute(Qt::WA_DeleteOnClose, true); m_listenerDialog->show(); m_listener.stopCapture(); - if (m_listener.regime() != LISTENER_CAPTURE_RECEIVE) + if (m_listener.regime() != ListenerRegime::Capture_Receive) { m_listenerDialog->reject(); m_listenerDialog = nullptr; @@ -1667,13 +1670,14 @@ void EasyMainWindow::onListenerDialogClose(int _result) break; } - case LISTENER_CAPTURE_RECEIVE: + case ListenerRegime::Capture_Receive: { if (!m_listener.captured()) { if (_result == QDialog::Accepted) { - m_listenerDialog = new QMessageBox(QMessageBox::Information, "Receiving data...", "This process may take some time.", QMessageBox::Cancel, this); + m_listenerDialog = new QMessageBox(QMessageBox::Information, "Receiving data...", + "This process may take some time.", QMessageBox::Cancel, this); connect(m_listenerDialog, &QDialog::finished, this, &This::onListenerDialogClose); m_listenerDialog->setAttribute(Qt::WA_DeleteOnClose, true); m_listenerDialog->show(); @@ -1728,7 +1732,7 @@ void EasyMainWindow::onListenerDialogClose(int _result) break; } - case LISTENER_DESCRIBE: + case ListenerRegime::Descriptors: { break; } @@ -1747,14 +1751,14 @@ void EasyMainWindow::onListenerDialogClose(int _result) ////////////////////////////////////////////////////////////////////////// -void EasyMainWindow::onFileReaderTimeout() +void MainWindow::onFileReaderTimeout() { if (m_reader.done()) { const auto nblocks = m_reader.size(); if (nblocks != 0) { - static_cast(m_treeWidget->widget())->clear(true); + static_cast(m_treeWidget->widget())->clear(true); ::profiler::SerializedData serialized_blocks; ::profiler::SerializedData serialized_descriptors; @@ -1810,8 +1814,8 @@ void EasyMainWindow::onFileReaderTimeout() setWindowTitle(EASY_DEFAULT_WINDOW_TITLE " - UNSAVED network cache"); } - m_serializedBlocks = ::std::move(serialized_blocks); - m_serializedDescriptors = ::std::move(serialized_descriptors); + m_serializedBlocks = std::move(serialized_blocks); + m_serializedDescriptors = std::move(serialized_descriptors); m_descriptorsNumberInFile = descriptorsNumberInFile; EASY_GLOBALS.selected_thread = 0; EASY_GLOBALS.version = version; @@ -1825,16 +1829,16 @@ void EasyMainWindow::onFileReaderTimeout() memset(EASY_GLOBALS.gui_blocks.data(), 0, sizeof(::profiler_gui::EasyBlock) * nblocks); for (std::remove_const::type i = 0; i < nblocks; ++i) { auto& guiblock = EASY_GLOBALS.gui_blocks[i]; - guiblock.tree = ::std::move(blocks[i]); + guiblock.tree = std::move(blocks[i]); #ifdef EASY_TREE_WIDGET__USE_VECTOR ::profiler_gui::set_max(guiblock.tree_item); #endif } - static_cast(m_graphicsView->widget())->view()->setTree(EASY_GLOBALS.profiler_blocks); + static_cast(m_graphicsView->widget())->view()->setTree(EASY_GLOBALS.profiler_blocks); #if EASY_GUI_USE_DESCRIPTORS_DOCK_WINDOW != 0 - static_cast(m_descTreeWidget->widget())->build(); + static_cast(m_descTreeWidget->widget())->build(); #endif if (m_dialogDescTree != nullptr) m_dialogDescTree->build(); @@ -1878,7 +1882,7 @@ void EasyMainWindow::onFileReaderTimeout() } } -void EasyMainWindow::onFileReaderCancel() +void MainWindow::onFileReaderCancel() { m_readerTimer.stop(); m_reader.interrupt(); @@ -1887,56 +1891,56 @@ void EasyMainWindow::onFileReaderCancel() ////////////////////////////////////////////////////////////////////////// -EasyFileReader::EasyFileReader() +FileReader::FileReader() { } -EasyFileReader::~EasyFileReader() +FileReader::~FileReader() { interrupt(); } -const bool EasyFileReader::isFile() const +const bool FileReader::isFile() const { return m_isFile; } -bool EasyFileReader::done() const +bool FileReader::done() const { - return m_bDone.load(::std::memory_order_acquire); + return m_bDone.load(std::memory_order_acquire); } -int EasyFileReader::progress() const +int FileReader::progress() const { - return m_progress.load(::std::memory_order_acquire); + return m_progress.load(std::memory_order_acquire); } -unsigned int EasyFileReader::size() const +unsigned int FileReader::size() const { - return m_size.load(::std::memory_order_acquire); + return m_size.load(std::memory_order_acquire); } -const QString& EasyFileReader::filename() const +const QString& FileReader::filename() const { return m_filename; } -void EasyFileReader::load(const QString& _filename) +void FileReader::load(const QString& _filename) { interrupt(); m_isFile = true; m_filename = _filename; - m_thread = ::std::thread([this](bool _enableStatistics) { + m_thread = std::thread([this](bool _enableStatistics) { m_size.store(fillTreesFromFile(m_progress, m_filename.toStdString().c_str(), m_serializedBlocks, m_serializedDescriptors, - m_descriptors, m_blocks, m_blocksTree, m_descriptorsNumberInFile, m_version, _enableStatistics, m_errorMessage), ::std::memory_order_release); - m_progress.store(100, ::std::memory_order_release); - m_bDone.store(true, ::std::memory_order_release); + m_descriptors, m_blocks, m_blocksTree, m_descriptorsNumberInFile, m_version, _enableStatistics, m_errorMessage), std::memory_order_release); + m_progress.store(100, std::memory_order_release); + m_bDone.store(true, std::memory_order_release); }, EASY_GLOBALS.enable_statistics); } -void EasyFileReader::load(::std::stringstream& _stream) +void FileReader::load(std::stringstream& _stream) { interrupt(); @@ -1953,25 +1957,25 @@ void EasyFileReader::load(::std::stringstream& _stream) m_stream.swap(_stream); #endif - m_thread = ::std::thread([this](bool _enableStatistics) { - ::std::ofstream cache_file(NETWORK_CACHE_FILE, ::std::fstream::binary); + m_thread = std::thread([this](bool _enableStatistics) { + std::ofstream cache_file(NETWORK_CACHE_FILE, std::fstream::binary); if (cache_file.is_open()) { cache_file << m_stream.str(); cache_file.close(); } m_size.store(fillTreesFromStream(m_progress, m_stream, m_serializedBlocks, m_serializedDescriptors, m_descriptors, - m_blocks, m_blocksTree, m_descriptorsNumberInFile, m_version, _enableStatistics, m_errorMessage), ::std::memory_order_release); - m_progress.store(100, ::std::memory_order_release); - m_bDone.store(true, ::std::memory_order_release); + m_blocks, m_blocksTree, m_descriptorsNumberInFile, m_version, _enableStatistics, m_errorMessage), std::memory_order_release); + m_progress.store(100, std::memory_order_release); + m_bDone.store(true, std::memory_order_release); }, EASY_GLOBALS.enable_statistics); } -void EasyFileReader::interrupt() +void FileReader::interrupt() { join(); - m_bDone.store(false, ::std::memory_order_release); - m_size.store(0, ::std::memory_order_release); + m_bDone.store(false, std::memory_order_release); + m_size.store(0, std::memory_order_release); m_serializedBlocks.clear(); m_serializedDescriptors.clear(); m_descriptors.clear(); @@ -1984,7 +1988,7 @@ void EasyFileReader::interrupt() clear_stream(m_errorMessage); } -void EasyFileReader::get(::profiler::SerializedData& _serializedBlocks, ::profiler::SerializedData& _serializedDescriptors, +void FileReader::get(::profiler::SerializedData& _serializedBlocks, ::profiler::SerializedData& _serializedDescriptors, ::profiler::descriptors_list_t& _descriptors, ::profiler::blocks_t& _blocks, ::profiler::thread_blocks_tree_t& _tree, uint32_t& _descriptorsNumberInFile, uint32_t& _version, QString& _filename) { @@ -1992,7 +1996,7 @@ void EasyFileReader::get(::profiler::SerializedData& _serializedBlocks, ::profil { m_serializedBlocks.swap(_serializedBlocks); m_serializedDescriptors.swap(_serializedDescriptors); - ::profiler::descriptors_list_t(::std::move(m_descriptors)).swap(_descriptors); + ::profiler::descriptors_list_t(std::move(m_descriptors)).swap(_descriptors); m_blocks.swap(_blocks); m_blocksTree.swap(_tree); m_filename.swap(_filename); @@ -2001,28 +2005,28 @@ void EasyFileReader::get(::profiler::SerializedData& _serializedBlocks, ::profil } } -void EasyFileReader::join() +void FileReader::join() { - m_progress.store(-100, ::std::memory_order_release); + m_progress.store(-100, std::memory_order_release); if (m_thread.joinable()) m_thread.join(); - m_progress.store(0, ::std::memory_order_release); + m_progress.store(0, std::memory_order_release); } -QString EasyFileReader::getError() +QString FileReader::getError() { return QString(m_errorMessage.str().c_str()); } ////////////////////////////////////////////////////////////////////////// -void EasyMainWindow::onEventTracingPriorityChange(bool _checked) +void MainWindow::onEventTracingPriorityChange(bool _checked) { if (EASY_GLOBALS.connected) m_listener.send(profiler::net::BoolMessage(profiler::net::MessageType::Change_Event_Tracing_Priority, _checked)); } -void EasyMainWindow::onEventTracingEnableChange(bool _checked) +void MainWindow::onEventTracingEnableChange(bool _checked) { if (EASY_GLOBALS.connected) m_listener.send(profiler::net::BoolMessage(profiler::net::MessageType::Change_Event_Tracing_Status, _checked)); @@ -2030,7 +2034,7 @@ void EasyMainWindow::onEventTracingEnableChange(bool _checked) ////////////////////////////////////////////////////////////////////////// -void EasyMainWindow::onFrameTimeEditFinish() +void MainWindow::onFrameTimeEditFinish() { auto text = m_frameTimeEdit->text(); if (text.contains(QChar(','))) @@ -2041,23 +2045,23 @@ void EasyMainWindow::onFrameTimeEditFinish() EASY_GLOBALS.frame_time = text.toFloat() * 1e3f; - disconnect(&EASY_GLOBALS.events, &::profiler_gui::EasyGlobalSignals::expectedFrameTimeChanged, + disconnect(&EASY_GLOBALS.events, &::profiler_gui::GlobalSignals::expectedFrameTimeChanged, this, &This::onFrameTimeChanged); emit EASY_GLOBALS.events.expectedFrameTimeChanged(); - connect(&EASY_GLOBALS.events, &::profiler_gui::EasyGlobalSignals::expectedFrameTimeChanged, + connect(&EASY_GLOBALS.events, &::profiler_gui::GlobalSignals::expectedFrameTimeChanged, this, &This::onFrameTimeChanged); } -void EasyMainWindow::onFrameTimeChanged() +void MainWindow::onFrameTimeChanged() { m_frameTimeEdit->setText(QString::number(EASY_GLOBALS.frame_time * 1e-3)); } ////////////////////////////////////////////////////////////////////////// -void EasyMainWindow::onConnectClicked(bool) +void MainWindow::onConnectClicked(bool) { if (EASY_GLOBALS.connected) { @@ -2085,14 +2089,14 @@ void EasyMainWindow::onConnectClicked(bool) if (!isSameAddress) { - m_lastAddress = ::std::move(address); + m_lastAddress = std::move(address); m_lastPort = port; } return; } - m_lastAddress = ::std::move(address); + m_lastAddress = std::move(address); m_lastPort = port; qInfo() << "Connected successfully"; @@ -2102,7 +2106,7 @@ void EasyMainWindow::onConnectClicked(bool) m_connectAction->setText(tr("Disconnect")); if (m_fpsViewer->isVisible()) - static_cast(m_fpsViewer->widget())->clear(); + static_cast(m_fpsViewer->widget())->clear(); if (!m_fpsRequestTimer.isActive()) m_fpsRequestTimer.start(EASY_GLOBALS.fps_timer_interval); @@ -2132,7 +2136,7 @@ void EasyMainWindow::onConnectClicked(bool) } } -void EasyMainWindow::onCaptureClicked(bool) +void MainWindow::onCaptureClicked(bool) { if (!EASY_GLOBALS.connected) { @@ -2140,12 +2144,19 @@ void EasyMainWindow::onCaptureClicked(bool) return; } - if (m_listener.regime() != LISTENER_IDLE) + if (m_listener.regime() != ListenerRegime::Idle) { - if (m_listener.regime() == LISTENER_CAPTURE || m_listener.regime() == LISTENER_CAPTURE_RECEIVE) - QMessageBox::warning(this, "Warning", "Already capturing frames.\nFinish old capturing session first.", QMessageBox::Close); + if (m_listener.regime() == ListenerRegime::Capture || m_listener.regime() == ListenerRegime::Capture_Receive) + { + QMessageBox::warning(this, "Warning", + "Already capturing frames.\nFinish old capturing session first.", QMessageBox::Close); + } else - QMessageBox::warning(this, "Warning", "Capturing blocks description.\nFinish old capturing session first.", QMessageBox::Close); + { + QMessageBox::warning(this, "Warning", + "Capturing blocks description.\nFinish old capturing session first.", QMessageBox::Close); + } + return; } @@ -2186,7 +2197,7 @@ void EasyMainWindow::onCaptureClicked(bool) m_listenerDialog->show(); } -void EasyMainWindow::onGetBlockDescriptionsClicked(bool) +void MainWindow::onGetBlockDescriptionsClicked(bool) { if (!EASY_GLOBALS.connected) { @@ -2194,16 +2205,24 @@ void EasyMainWindow::onGetBlockDescriptionsClicked(bool) return; } - if (m_listener.regime() != LISTENER_IDLE) + if (m_listener.regime() != ListenerRegime::Idle) { - if (m_listener.regime() == LISTENER_DESCRIBE) - QMessageBox::warning(this, "Warning", "Already capturing blocks description.\nFinish old capturing session first.", QMessageBox::Close); + if (m_listener.regime() == ListenerRegime::Descriptors) + { + QMessageBox::warning(this, "Warning", + "Already capturing blocks description.\nFinish old capturing session first.", QMessageBox::Close); + } else - QMessageBox::warning(this, "Warning", "Already capturing frames.\nFinish old capturing session first.", QMessageBox::Close); + { + QMessageBox::warning(this, "Warning", + "Already capturing frames.\nFinish old capturing session first.", QMessageBox::Close); + } + return; } - m_listenerDialog = new QMessageBox(QMessageBox::Information, "Waiting for blocks...", "This may take some time.", QMessageBox::NoButton, this); + m_listenerDialog = new QMessageBox(QMessageBox::Information, "Waiting for blocks...", + "This may take some time.", QMessageBox::NoButton, this); m_listenerDialog->setAttribute(Qt::WA_DeleteOnClose, true); m_listenerDialog->show(); @@ -2218,7 +2237,7 @@ void EasyMainWindow::onGetBlockDescriptionsClicked(bool) decltype(EASY_GLOBALS.descriptors) descriptors; decltype(m_serializedDescriptors) serializedDescriptors; - ::std::stringstream errorMessage; + std::stringstream errorMessage; if (readDescriptionsFromStream(m_listener.data(), serializedDescriptors, descriptors, errorMessage)) { // Merge old and new descriptions @@ -2299,7 +2318,7 @@ void EasyMainWindow::onGetBlockDescriptionsClicked(bool) if (m_descTreeDialog.ptr != nullptr) { #if EASY_GUI_USE_DESCRIPTORS_DOCK_WINDOW != 0 - static_cast(m_descTreeWidget->widget())->build(); + static_cast(m_descTreeWidget->widget())->build(); #endif m_dialogDescTree->build(); m_descTreeDialog.ptr->raise(); @@ -2328,7 +2347,7 @@ void EasyMainWindow::onGetBlockDescriptionsClicked(bool) ////////////////////////////////////////////////////////////////////////// -void EasyMainWindow::onBlockStatusChange(::profiler::block_id_t _id, ::profiler::EasyBlockStatus _status) +void MainWindow::onBlockStatusChange(::profiler::block_id_t _id, ::profiler::EasyBlockStatus _status) { if (EASY_GLOBALS.connected) m_listener.send(profiler::net::BlockStatusMessage(_id, static_cast(_status))); @@ -2354,7 +2373,7 @@ void DialogWithGeometry::restoreGeometry() ////////////////////////////////////////////////////////////////////////// -EasySocketListener::EasySocketListener() : m_receivedSize(0), m_port(0), m_regime(LISTENER_IDLE) +EasySocketListener::EasySocketListener() : m_receivedSize(0), m_port(0), m_regime(ListenerRegime::Idle) { m_bInterrupt = ATOMIC_VAR_INIT(false); m_bConnected = ATOMIC_VAR_INIT(false); @@ -2367,22 +2386,22 @@ EasySocketListener::EasySocketListener() : m_receivedSize(0), m_port(0), m_regim EasySocketListener::~EasySocketListener() { - m_bInterrupt.store(true, ::std::memory_order_release); + m_bInterrupt.store(true, std::memory_order_release); if (m_thread.joinable()) m_thread.join(); } bool EasySocketListener::connected() const { - return m_bConnected.load(::std::memory_order_acquire); + return m_bConnected.load(std::memory_order_acquire); } bool EasySocketListener::captured() const { - return m_bCaptureReady.load(::std::memory_order_acquire); + return m_bCaptureReady.load(std::memory_order_acquire); } -EasyListenerRegime EasySocketListener::regime() const +ListenerRegime EasySocketListener::regime() const { return m_regime; } @@ -2392,12 +2411,12 @@ uint64_t EasySocketListener::size() const return m_receivedSize; } -::std::stringstream& EasySocketListener::data() +std::stringstream& EasySocketListener::data() { return m_receivedData; } -const ::std::string& EasySocketListener::address() const +const std::string& EasySocketListener::address() const { return m_address; } @@ -2417,14 +2436,14 @@ void EasySocketListener::disconnect() { if (connected()) { - m_bInterrupt.store(true, ::std::memory_order_release); + m_bInterrupt.store(true, std::memory_order_release); if (m_thread.joinable()) m_thread.join(); - m_bConnected.store(false, ::std::memory_order_release); - m_bInterrupt.store(false, ::std::memory_order_release); - m_bCaptureReady.store(false, ::std::memory_order_release); - m_bStopReceive.store(false, ::std::memory_order_release); + m_bConnected.store(false, std::memory_order_release); + m_bInterrupt.store(false, std::memory_order_release); + m_bCaptureReady.store(false, std::memory_order_release); + m_bStopReceive.store(false, std::memory_order_release); } m_address.clear(); @@ -2443,14 +2462,14 @@ bool EasySocketListener::connect(const char* _ipaddress, uint16_t _port, profile { if (connected()) { - m_bInterrupt.store(true, ::std::memory_order_release); + m_bInterrupt.store(true, std::memory_order_release); if (m_thread.joinable()) m_thread.join(); - m_bConnected.store(false, ::std::memory_order_release); - m_bInterrupt.store(false, ::std::memory_order_release); - m_bCaptureReady.store(false, ::std::memory_order_release); - m_bStopReceive.store(false, ::std::memory_order_release); + m_bConnected.store(false, std::memory_order_release); + m_bInterrupt.store(false, std::memory_order_release); + m_bCaptureReady.store(false, std::memory_order_release); + m_bStopReceive.store(false, std::memory_order_release); } m_address.clear(); @@ -2488,7 +2507,7 @@ bool EasySocketListener::connect(const char* _ipaddress, uint16_t _port, profile { m_address = _ipaddress; m_port = _port; - m_bConnected.store(isConnected, ::std::memory_order_release); + m_bConnected.store(isConnected, std::memory_order_release); return isConnected; } @@ -2515,7 +2534,7 @@ bool EasySocketListener::connect(const char* _ipaddress, uint16_t _port, profile m_port = _port; } - m_bConnected.store(isConnected, ::std::memory_order_release); + m_bConnected.store(isConnected, std::memory_order_release); return isConnected; } @@ -2528,9 +2547,9 @@ bool EasySocketListener::startCapture() { //if (m_thread.joinable()) //{ - // m_bInterrupt.store(true, ::std::memory_order_release); + // m_bInterrupt.store(true, std::memory_order_release); // m_thread.join(); - // m_bInterrupt.store(false, ::std::memory_order_release); + // m_bInterrupt.store(false, std::memory_order_release); //} clearData(); @@ -2539,74 +2558,74 @@ bool EasySocketListener::startCapture() m_easySocket.send(&request, sizeof(request)); if (m_easySocket.isDisconnected()) { - m_bConnected.store(false, ::std::memory_order_release); + m_bConnected.store(false, std::memory_order_release); return false; } - m_regime = LISTENER_CAPTURE; - m_bCaptureReady.store(false, ::std::memory_order_release); - //m_thread = ::std::thread(&EasySocketListener::listenCapture, this); + m_regime = ListenerRegime::Capture; + m_bCaptureReady.store(false, std::memory_order_release); + //m_thread = std::thread(&EasySocketListener::listenCapture, this); return true; } void EasySocketListener::stopCapture() { - //if (!m_thread.joinable() || m_regime != LISTENER_CAPTURE) + //if (!m_thread.joinable() || m_regime != ListenerRegime::Capture) // return; - if (m_regime != LISTENER_CAPTURE) + if (m_regime != ListenerRegime::Capture) return; - //m_bStopReceive.store(true, ::std::memory_order_release); + //m_bStopReceive.store(true, std::memory_order_release); profiler::net::Message request(profiler::net::MessageType::Request_Stop_Capture); m_easySocket.send(&request, sizeof(request)); //m_thread.join(); if (m_easySocket.isDisconnected()) { - m_bConnected.store(false, ::std::memory_order_release); - m_bStopReceive.store(false, ::std::memory_order_release); - m_regime = LISTENER_IDLE; - m_bCaptureReady.store(true, ::std::memory_order_release); + m_bConnected.store(false, std::memory_order_release); + m_bStopReceive.store(false, std::memory_order_release); + m_regime = ListenerRegime::Idle; + m_bCaptureReady.store(true, std::memory_order_release); return; } - m_regime = LISTENER_CAPTURE_RECEIVE; + m_regime = ListenerRegime::Capture_Receive; if (m_thread.joinable()) { - m_bInterrupt.store(true, ::std::memory_order_release); + m_bInterrupt.store(true, std::memory_order_release); m_thread.join(); - m_bInterrupt.store(false, ::std::memory_order_release); + m_bInterrupt.store(false, std::memory_order_release); } - m_thread = ::std::thread(&EasySocketListener::listenCapture, this); + m_thread = std::thread(&EasySocketListener::listenCapture, this); - //m_regime = LISTENER_IDLE; - //m_bStopReceive.store(false, ::std::memory_order_release); + //m_regime = ListenerRegime::Idle; + //m_bStopReceive.store(false, std::memory_order_release); } void EasySocketListener::finalizeCapture() { if (m_thread.joinable()) { - m_bInterrupt.store(true, ::std::memory_order_release); + m_bInterrupt.store(true, std::memory_order_release); m_thread.join(); - m_bInterrupt.store(false, ::std::memory_order_release); + m_bInterrupt.store(false, std::memory_order_release); } - m_regime = LISTENER_IDLE; - m_bCaptureReady.store(false, ::std::memory_order_release); - m_bStopReceive.store(false, ::std::memory_order_release); + m_regime = ListenerRegime::Idle; + m_bCaptureReady.store(false, std::memory_order_release); + m_bStopReceive.store(false, std::memory_order_release); } void EasySocketListener::requestBlocksDescription() { if (m_thread.joinable()) { - m_bInterrupt.store(true, ::std::memory_order_release); + m_bInterrupt.store(true, std::memory_order_release); m_thread.join(); - m_bInterrupt.store(false, ::std::memory_order_release); + m_bInterrupt.store(false, std::memory_order_release); } clearData(); @@ -2615,20 +2634,20 @@ void EasySocketListener::requestBlocksDescription() m_easySocket.send(&request, sizeof(request)); if(m_easySocket.isDisconnected() ){ - m_bConnected.store(false, ::std::memory_order_release); + m_bConnected.store(false, std::memory_order_release); } - m_regime = LISTENER_DESCRIBE; + m_regime = ListenerRegime::Descriptors; listenDescription(); - m_regime = LISTENER_IDLE; + m_regime = ListenerRegime::Idle; } bool EasySocketListener::frameTime(uint32_t& _maxTime, uint32_t& _avgTime) { - if (m_bFrameTimeReady.exchange(false, ::std::memory_order_acquire)) + if (m_bFrameTimeReady.exchange(false, std::memory_order_acquire)) { - _maxTime = m_frameMax.load(::std::memory_order_acquire); - _avgTime = m_frameAvg.load(::std::memory_order_acquire); + _maxTime = m_frameMax.load(std::memory_order_acquire); + _avgTime = m_frameAvg.load(std::memory_order_acquire); return true; } @@ -2637,14 +2656,14 @@ bool EasySocketListener::frameTime(uint32_t& _maxTime, uint32_t& _avgTime) bool EasySocketListener::requestFrameTime() { - if (m_regime != LISTENER_IDLE && m_regime != LISTENER_CAPTURE) + if (m_regime != ListenerRegime::Idle && m_regime != ListenerRegime::Capture) return false; if (m_thread.joinable()) { - m_bInterrupt.store(true, ::std::memory_order_release); + m_bInterrupt.store(true, std::memory_order_release); m_thread.join(); - m_bInterrupt.store(false, ::std::memory_order_release); + m_bInterrupt.store(false, std::memory_order_release); } profiler::net::Message request(profiler::net::MessageType::Request_MainThread_FPS); @@ -2652,12 +2671,12 @@ bool EasySocketListener::requestFrameTime() if (m_easySocket.isDisconnected()) { - m_bConnected.store(false, ::std::memory_order_release); + m_bConnected.store(false, std::memory_order_release); return false; } - m_bFrameTimeReady.store(false, ::std::memory_order_release); - m_thread = ::std::thread(&EasySocketListener::listenFrameTime, this); + m_bFrameTimeReady.store(false, std::memory_order_release); + m_thread = std::thread(&EasySocketListener::listenFrameTime, this); return true; } @@ -2670,16 +2689,16 @@ void EasySocketListener::listenCapture() char* buffer = new char[buffer_size]; int seek = 0, bytes = 0; - auto timeBegin = ::std::chrono::system_clock::now(); + auto timeBegin = std::chrono::system_clock::now(); bool isListen = true, disconnected = false; - while (isListen && !m_bInterrupt.load(::std::memory_order_acquire)) + while (isListen && !m_bInterrupt.load(std::memory_order_acquire)) { - if (m_bStopReceive.load(::std::memory_order_acquire)) + if (m_bStopReceive.load(std::memory_order_acquire)) { profiler::net::Message request(profiler::net::MessageType::Request_Stop_Capture); m_easySocket.send(&request, sizeof(request)); - m_bStopReceive.store(false, ::std::memory_order_release); + m_bStopReceive.store(false, std::memory_order_release); } if ((bytes - seek) == 0) @@ -2690,7 +2709,7 @@ void EasySocketListener::listenCapture() { if (m_easySocket.isDisconnected()) { - m_bConnected.store(false, ::std::memory_order_release); + m_bConnected.store(false, std::memory_order_release); isListen = false; disconnected = true; } @@ -2740,7 +2759,7 @@ void EasySocketListener::listenCapture() qInfo() << "Receive MessageType::Reply_Blocks_End"; seek += sizeof(profiler::net::Message); - const auto dt = ::std::chrono::duration_cast(::std::chrono::system_clock::now() - timeBegin); + const auto dt = std::chrono::duration_cast(std::chrono::system_clock::now() - timeBegin); const auto bytesNumber = m_receivedData.str().size(); qInfo() << "recieved " << bytesNumber << " bytes, " << dt.count() << " ms, average speed = " << double(bytesNumber) * 1e3 / double(dt.count()) / 1024. << " kBytes/sec"; @@ -2764,7 +2783,7 @@ void EasySocketListener::listenCapture() buf = buffer + seek; - auto bytesNumber = ::std::min((int)dm->size, bytes - seek); + auto bytesNumber = std::min((int)dm->size, bytes - seek); m_receivedSize += bytesNumber; m_receivedData.write(buf, bytesNumber); neededSize -= bytesNumber; @@ -2787,7 +2806,7 @@ void EasySocketListener::listenCapture() { if (m_easySocket.isDisconnected()) { - m_bConnected.store(false, ::std::memory_order_release); + m_bConnected.store(false, std::memory_order_release); isListen = false; disconnected = true; neededSize = 0; @@ -2797,7 +2816,7 @@ void EasySocketListener::listenCapture() } buf = buffer; - int toWrite = ::std::min(bytes, neededSize); + int toWrite = std::min(bytes, neededSize); m_receivedSize += toWrite; m_receivedData.write(buf, toWrite); neededSize -= toWrite; @@ -2805,11 +2824,11 @@ void EasySocketListener::listenCapture() seek = toWrite; } - if (m_bStopReceive.load(::std::memory_order_acquire)) + if (m_bStopReceive.load(std::memory_order_acquire)) { profiler::net::Message request(profiler::net::MessageType::Request_Stop_Capture); m_easySocket.send(&request, sizeof(request)); - m_bStopReceive.store(false, ::std::memory_order_release); + m_bStopReceive.store(false, std::memory_order_release); } break; @@ -2827,7 +2846,7 @@ void EasySocketListener::listenCapture() delete [] buffer; - m_bCaptureReady.store(true, ::std::memory_order_release); + m_bCaptureReady.store(true, std::memory_order_release); } void EasySocketListener::listenDescription() @@ -2838,7 +2857,7 @@ void EasySocketListener::listenDescription() int seek = 0, bytes = 0; bool isListen = true, disconnected = false; - while (isListen && !m_bInterrupt.load(::std::memory_order_acquire)) + while (isListen && !m_bInterrupt.load(std::memory_order_acquire)) { if ((bytes - seek) == 0) { @@ -2848,7 +2867,7 @@ void EasySocketListener::listenDescription() { if (m_easySocket.isDisconnected()) { - m_bConnected.store(false, ::std::memory_order_release); + m_bConnected.store(false, std::memory_order_release); isListen = false; disconnected = true; } @@ -2907,7 +2926,7 @@ void EasySocketListener::listenDescription() int neededSize = dm->size; buf = buffer + seek; - auto bytesNumber = ::std::min((int)dm->size, bytes - seek); + auto bytesNumber = std::min((int)dm->size, bytes - seek); m_receivedSize += bytesNumber; m_receivedData.write(buf, bytesNumber); neededSize -= bytesNumber; @@ -2928,7 +2947,7 @@ void EasySocketListener::listenDescription() { if (m_easySocket.isDisconnected()) { - m_bConnected.store(false, ::std::memory_order_release); + m_bConnected.store(false, std::memory_order_release); isListen = false; disconnected = true; neededSize = 0; @@ -2938,7 +2957,7 @@ void EasySocketListener::listenDescription() } buf = buffer; - int toWrite = ::std::min(bytes, neededSize); + int toWrite = std::min(bytes, neededSize); m_receivedSize += toWrite; m_receivedData.write(buf, toWrite); neededSize -= toWrite; @@ -2969,7 +2988,7 @@ void EasySocketListener::listenFrameTime() int seek = 0, bytes = 0; bool isListen = true; - while (isListen && !m_bInterrupt.load(::std::memory_order_acquire)) + while (isListen && !m_bInterrupt.load(std::memory_order_acquire)) { if ((bytes - seek) == 0) { @@ -2979,7 +2998,7 @@ void EasySocketListener::listenFrameTime() { if (m_easySocket.isDisconnected()) { - m_bConnected.store(false, ::std::memory_order_release); + m_bConnected.store(false, std::memory_order_release); isListen = false; } @@ -3023,9 +3042,9 @@ void EasySocketListener::listenFrameTime() if (seek <= buffer_size) { auto timestampMessage = (profiler::net::TimestampMessage*)message; - m_frameMax.store(timestampMessage->maxValue, ::std::memory_order_release); - m_frameAvg.store(timestampMessage->avgValue, ::std::memory_order_release); - m_bFrameTimeReady.store(true, ::std::memory_order_release); + m_frameMax.store(timestampMessage->maxValue, std::memory_order_release); + m_frameAvg.store(timestampMessage->avgValue, std::memory_order_release); + m_bFrameTimeReady.store(true, std::memory_order_release); } isListen = false; diff --git a/profiler_gui/main_window.h b/profiler_gui/main_window.h index 5396969..18d9835 100644 --- a/profiler_gui/main_window.h +++ b/profiler_gui/main_window.h @@ -83,28 +83,28 @@ namespace profiler { namespace net { struct EasyProfilerStatus; } } ////////////////////////////////////////////////////////////////////////// -class EasyFileReader Q_DECL_FINAL +class FileReader Q_DECL_FINAL { - ::profiler::SerializedData m_serializedBlocks; ///< - ::profiler::SerializedData m_serializedDescriptors; ///< - ::profiler::descriptors_list_t m_descriptors; ///< - ::profiler::blocks_t m_blocks; ///< - ::profiler::thread_blocks_tree_t m_blocksTree; ///< - ::std::stringstream m_stream; ///< - ::std::stringstream m_errorMessage; ///< - QString m_filename; ///< - uint32_t m_descriptorsNumberInFile = 0; ///< - uint32_t m_version = 0; ///< - ::std::thread m_thread; ///< - ::std::atomic_bool m_bDone; ///< - ::std::atomic m_progress; ///< - ::std::atomic m_size; ///< - bool m_isFile = false; ///< + profiler::SerializedData m_serializedBlocks; ///< + profiler::SerializedData m_serializedDescriptors; ///< + profiler::descriptors_list_t m_descriptors; ///< + profiler::blocks_t m_blocks; ///< + profiler::thread_blocks_tree_t m_blocksTree; ///< + std::stringstream m_stream; ///< + std::stringstream m_errorMessage; ///< + QString m_filename; ///< + uint32_t m_descriptorsNumberInFile = 0; ///< + uint32_t m_version = 0; ///< + std::thread m_thread; ///< + std::atomic_bool m_bDone; ///< + std::atomic m_progress; ///< + std::atomic m_size; ///< + bool m_isFile = false; ///< public: - EasyFileReader(); - ~EasyFileReader(); + FileReader(); + ~FileReader(); const bool isFile() const; bool done() const; @@ -113,44 +113,44 @@ public: const QString& filename() const; void load(const QString& _filename); - void load(::std::stringstream& _stream); + void load(std::stringstream& _stream); void interrupt(); - void get(::profiler::SerializedData& _serializedBlocks, ::profiler::SerializedData& _serializedDescriptors, - ::profiler::descriptors_list_t& _descriptors, ::profiler::blocks_t& _blocks, ::profiler::thread_blocks_tree_t& _tree, + void get(profiler::SerializedData& _serializedBlocks, profiler::SerializedData& _serializedDescriptors, + profiler::descriptors_list_t& _descriptors, profiler::blocks_t& _blocks, profiler::thread_blocks_tree_t& _tree, uint32_t& _descriptorsNumberInFile, uint32_t& _version, QString& _filename); void join(); QString getError(); -}; // END of class EasyFileReader. +}; // END of class FileReader. ////////////////////////////////////////////////////////////////////////// -enum EasyListenerRegime : uint8_t +enum class ListenerRegime : uint8_t { - LISTENER_IDLE = 0, - LISTENER_CAPTURE, - LISTENER_CAPTURE_RECEIVE, - LISTENER_DESCRIBE + Idle = 0, + Capture, + Capture_Receive, + Descriptors }; class EasySocketListener Q_DECL_FINAL { - EasySocket m_easySocket; ///< - ::std::string m_address; ///< - ::std::stringstream m_receivedData; ///< - ::std::thread m_thread; ///< - uint64_t m_receivedSize; ///< - uint16_t m_port; ///< - ::std::atomic m_frameMax; ///< - ::std::atomic m_frameAvg; ///< - ::std::atomic_bool m_bInterrupt; ///< - ::std::atomic_bool m_bConnected; ///< - ::std::atomic_bool m_bStopReceive; ///< - ::std::atomic_bool m_bCaptureReady; ///< - ::std::atomic_bool m_bFrameTimeReady; ///< - EasyListenerRegime m_regime; ///< + EasySocket m_easySocket; ///< + std::string m_address; ///< + std::stringstream m_receivedData; ///< + std::thread m_thread; ///< + uint64_t m_receivedSize; ///< + uint16_t m_port; ///< + std::atomic m_frameMax; ///< + std::atomic m_frameAvg; ///< + std::atomic_bool m_bInterrupt; ///< + std::atomic_bool m_bConnected; ///< + std::atomic_bool m_bStopReceive; ///< + std::atomic_bool m_bCaptureReady; ///< + std::atomic_bool m_bFrameTimeReady; ///< + ListenerRegime m_regime; ///< public: @@ -159,18 +159,18 @@ public: bool connected() const; bool captured() const; - EasyListenerRegime regime() const; + ListenerRegime regime() const; uint64_t size() const; - const ::std::string& address() const; + const std::string& address() const; uint16_t port() const; - ::std::stringstream& data(); + std::stringstream& data(); void clearData(); void disconnect(); void closeSocket(); - bool connect(const char* _ipaddress, uint16_t _port, ::profiler::net::EasyProfilerStatus& _reply, bool _disconnectFirst = false); - bool reconnect(const char* _ipaddress, uint16_t _port, ::profiler::net::EasyProfilerStatus& _reply); + bool connect(const char* _ipaddress, uint16_t _port, profiler::net::EasyProfilerStatus& _reply, bool _disconnectFirst = false); + bool reconnect(const char* _ipaddress, uint16_t _port, profiler::net::EasyProfilerStatus& _reply); bool startCapture(); void stopCapture(); @@ -181,8 +181,7 @@ public: bool requestFrameTime(); template - inline void send(const T& _message) - { + void send(const T& _message) { m_easySocket.send(&_message, sizeof(T)); } @@ -214,13 +213,13 @@ struct DialogWithGeometry EASY_FINAL void restoreGeometry(); }; -class EasyMainWindow : public QMainWindow +class MainWindow : public QMainWindow { Q_OBJECT protected: - using This = EasyMainWindow; + using This = MainWindow; using Parent = QMainWindow; DialogWithGeometry m_descTreeDialog; @@ -237,14 +236,14 @@ protected: #endif class QProgressDialog* m_progress = nullptr; - class EasyDescWidget* m_dialogDescTree = nullptr; + class BlockDescriptorsWidget* m_dialogDescTree = nullptr; class QMessageBox* m_listenerDialog = nullptr; QTimer m_readerTimer; QTimer m_listenerTimer; QTimer m_fpsRequestTimer; - ::profiler::SerializedData m_serializedBlocks; - ::profiler::SerializedData m_serializedDescriptors; - EasyFileReader m_reader; + profiler::SerializedData m_serializedBlocks; + profiler::SerializedData m_serializedDescriptors; + FileReader m_reader; EasySocketListener m_listener; class QLineEdit* m_addressEdit = nullptr; @@ -267,8 +266,8 @@ protected: public: - explicit EasyMainWindow(); - ~EasyMainWindow() override; + explicit MainWindow(); + ~MainWindow() override; // Public virtual methods @@ -316,7 +315,7 @@ protected slots: void onFrameTimeEditFinish(); void onFrameTimeChanged(); - void onBlockStatusChange(::profiler::block_id_t _id, ::profiler::EasyBlockStatus _status); + void onBlockStatusChange(profiler::block_id_t _id, profiler::EasyBlockStatus _status); void checkFrameTimeReady(); @@ -330,7 +329,7 @@ private: void addFileToList(const QString& filename); void loadFile(const QString& filename); - void readStream(::std::stringstream& data); + void readStream(std::stringstream& data); void loadSettings(); void loadGeometry(); @@ -341,7 +340,7 @@ private: void destroyProgressDialog(); void createProgressDialog(const QString& text); -}; // END of class EasyMainWindow. +}; // END of class MainWindow. ////////////////////////////////////////////////////////////////////////// diff --git a/profiler_gui/themes/default.css b/profiler_gui/themes/default.css index 5fe9c34..f7243ae 100644 --- a/profiler_gui/themes/default.css +++ b/profiler_gui/themes/default.css @@ -20,7 +20,7 @@ *:disabled { color: #a08888; } -EasyMainWindow, QToolBar, QDialog { +MainWindow, QToolBar, QDialog { background-color: #f8f2f2; } QToolTip { diff --git a/profiler_gui/themes/default.scss b/profiler_gui/themes/default.scss index a5d7814..7df5de7 100644 --- a/profiler_gui/themes/default.scss +++ b/profiler_gui/themes/default.scss @@ -42,7 +42,7 @@ $SpinBoxArrowSize: 8px; color: $DisabledTextColor; } -EasyMainWindow, QToolBar, QDialog { +MainWindow, QToolBar, QDialog { background-color: #f8f2f2; } diff --git a/profiler_gui/thread_pool.cpp b/profiler_gui/thread_pool.cpp new file mode 100644 index 0000000..e6f01c7 --- /dev/null +++ b/profiler_gui/thread_pool.cpp @@ -0,0 +1,77 @@ +/* + * */ + +#include "thread_pool.h" +#include + +ThreadPool& ThreadPool::instance() +{ + static ThreadPool pool; + return pool; +} + +ThreadPool::ThreadPool() +{ + const auto threadsCount = std::max(std::thread::hardware_concurrency(), 2U); + + m_threads.reserve(threadsCount); + std::generate_n(std::back_inserter(m_threads), threadsCount, [this] { + return std::thread(&ThreadPool::work, this); + }); +} + +ThreadPool::~ThreadPool() +{ + m_interrupt.store(true, std::memory_order_release); + m_cv.notify_all(); + for (auto& thread : m_threads) + thread.join(); +} + +void ThreadPool::enqueue(ThreadPoolTask& task) +{ + m_mutex.lock(); + m_tasks.emplace_back(task); + m_mutex.unlock(); + m_cv.notify_one(); +} + +void ThreadPool::dequeue(ThreadPoolTask& task) +{ + const std::lock_guard lock(m_mutex); + + if (task.status() != TaskStatus::Enqueued) + return; + + for (auto it = m_tasks.begin(); it != m_tasks.end(); ++it) + { + if (&it->get() == &task) + { + m_tasks.erase(it); + break; + } + } +} + +void ThreadPool::work() +{ + while (true) + { + std::unique_lock lock(m_mutex); + m_cv.wait(lock, [this] { return !m_tasks.empty() || m_interrupt.load(std::memory_order_acquire); }); + + if (m_interrupt.load(std::memory_order_acquire)) + break; + + if (m_tasks.empty()) + continue; + + auto& task = m_tasks.front().get(); + task.setStatus(TaskStatus::Processing); + m_tasks.pop_front(); + + lock.unlock(); + + task.execute(); + } +} diff --git a/profiler_gui/thread_pool.h b/profiler_gui/thread_pool.h new file mode 100644 index 0000000..40dae0b --- /dev/null +++ b/profiler_gui/thread_pool.h @@ -0,0 +1,39 @@ +/** + * */ + +#ifndef EASY_PROFILER_THREAD_POOL_H +#define EASY_PROFILER_THREAD_POOL_H + +#include "thread_pool_task.h" +#include +#include +#include +#include + +class ThreadPool EASY_FINAL +{ + friend ThreadPoolTask; + + std::vector m_threads; + std::deque > m_tasks; + std::mutex m_mutex; + std::condition_variable m_cv; + std::atomic_bool m_interrupt; + + ThreadPool(); + +public: + + ~ThreadPool(); + + static ThreadPool& instance(); + +private: + + void enqueue(ThreadPoolTask& task); + void dequeue(ThreadPoolTask& task); + void work(); + +}; // end of class ThreadPool. + +#endif //EASY_PROFILER_THREAD_POOL_H diff --git a/profiler_gui/thread_pool_task.cpp b/profiler_gui/thread_pool_task.cpp new file mode 100644 index 0000000..5d8e33e --- /dev/null +++ b/profiler_gui/thread_pool_task.cpp @@ -0,0 +1,65 @@ +/** + * */ + +#include "thread_pool_task.h" +#include "thread_pool.h" + +ThreadPoolTask::ThreadPoolTask() : m_func([]{}), m_interrupt(nullptr) +{ + m_status = ATOMIC_VAR_INIT(static_cast(TaskStatus::Finished)); +} + +ThreadPoolTask::~ThreadPoolTask() +{ + dequeue(); +} + +void ThreadPoolTask::enqueue(std::function&& func, std::atomic_bool& interruptFlag) +{ + dequeue(); + + m_interrupt = & interruptFlag; + m_interrupt->store(false, std::memory_order_release); + m_func = std::move(func); + + setStatus(TaskStatus::Enqueued); + ThreadPool::instance().enqueue(*this); +} + +void ThreadPoolTask::dequeue() +{ + if (m_interrupt == nullptr) + return; + + m_interrupt->store(true, std::memory_order_release); + + ThreadPool::instance().dequeue(*this); + + // wait for finish + m_mutex.lock(); + setStatus(TaskStatus::Finished); + m_mutex.unlock(); + + m_interrupt->store(false, std::memory_order_release); +} + +TaskStatus ThreadPoolTask::status() const +{ + return static_cast(m_status.load(std::memory_order_acquire)); +} + +void ThreadPoolTask::execute() +{ + const std::lock_guard guard(m_mutex); + + if (status() == TaskStatus::Finished || m_interrupt->load(std::memory_order_acquire)) + return; + + m_func(); + setStatus(TaskStatus::Finished); +} + +void ThreadPoolTask::setStatus(TaskStatus status) +{ + m_status.store(static_cast(status), std::memory_order_release); +} diff --git a/profiler_gui/thread_pool_task.h b/profiler_gui/thread_pool_task.h new file mode 100644 index 0000000..e75d5d5 --- /dev/null +++ b/profiler_gui/thread_pool_task.h @@ -0,0 +1,47 @@ +/* + * */ + +#ifndef EASY_PROFILER_THREAD_POOL_TASK_H +#define EASY_PROFILER_THREAD_POOL_TASK_H + +#include +#include +#include +#include + +enum class TaskStatus : int8_t +{ + Enqueued, + Processing, + Finished, +}; + +class ThreadPoolTask EASY_FINAL +{ + friend class ThreadPool; + + std::function m_func; + std::mutex m_mutex; + std::atomic m_status; + std::atomic_bool* m_interrupt; + +public: + + ThreadPoolTask(const ThreadPoolTask&) = delete; + ThreadPoolTask(ThreadPoolTask&&) = delete; + + ThreadPoolTask(); + ~ThreadPoolTask(); + + void enqueue(std::function&& func, std::atomic_bool& interruptFlag); + void dequeue(); + +private: + + void execute(); + + TaskStatus status() const; + void setStatus(TaskStatus status); +}; + +#endif //EASY_PROFILER_THREAD_POOL_TASK_H diff --git a/profiler_gui/tree_widget_item.cpp b/profiler_gui/tree_widget_item.cpp index b6e737f..585f584 100644 --- a/profiler_gui/tree_widget_item.cpp +++ b/profiler_gui/tree_widget_item.cpp @@ -5,7 +5,7 @@ * author : Victor Zarubkin * email : v.s.zarubkin@gmail.com * ----------------- : -* description : The file contains implementation of EasyTreeWidgetItem. +* description : The file contains implementation of TreeWidgetItem. * ----------------- : * change log : * 2016/08/18 Victor Zarubkin: Moved sources from blocks_tree_widget.cpp * : and renamed classes from Prof* to Easy*. @@ -109,7 +109,7 @@ EASY_CONSTEXPR int ColumnBit[COL_COLUMNS_NUMBER] = { ////////////////////////////////////////////////////////////////////////// -EasyTreeWidgetItem::EasyTreeWidgetItem(const ::profiler::block_index_t _treeBlock, Parent* _parent) +TreeWidgetItem::TreeWidgetItem(const profiler::block_index_t _treeBlock, Parent* _parent) : Parent(_parent, QTreeWidgetItem::UserType) , m_block(_treeBlock) , m_customBGColor(0) @@ -118,11 +118,11 @@ EasyTreeWidgetItem::EasyTreeWidgetItem(const ::profiler::block_index_t _treeBloc } -EasyTreeWidgetItem::~EasyTreeWidgetItem() +TreeWidgetItem::~TreeWidgetItem() { } -bool EasyTreeWidgetItem::operator < (const Parent& _other) const +bool TreeWidgetItem::operator < (const Parent& _other) const { const auto col = treeWidget()->sortColumn(); @@ -166,20 +166,20 @@ bool EasyTreeWidgetItem::operator < (const Parent& _other) const } } -bool EasyTreeWidgetItem::hasToolTip(int _column) const +bool TreeWidgetItem::hasToolTip(int _column) const { const int bit = ColumnBit[_column]; return bit < 0 ? false : m_bHasToolTip.test(static_cast(bit)); } -void EasyTreeWidgetItem::setHasToolTip(int _column) +void TreeWidgetItem::setHasToolTip(int _column) { const int bit = ColumnBit[_column]; if (bit >= 0) m_bHasToolTip.set(static_cast(bit), true); } -QVariant EasyTreeWidgetItem::data(int _column, int _role) const +QVariant TreeWidgetItem::data(int _column, int _role) const { if (_column == COL_NAME) { @@ -207,7 +207,7 @@ QVariant EasyTreeWidgetItem::data(int _column, int _role) const return m_font; case Qt::ForegroundRole: - return m_bMain ? QVariant::fromValue(QColor::fromRgb(::profiler_gui::SELECTED_THREAD_FOREGROUND)) : QVariant(); + return m_bMain ? QVariant::fromValue(QColor::fromRgb(profiler_gui::SELECTED_THREAD_FOREGROUND)) : QVariant(); case Qt::ToolTipRole: return hasToolTip(_column) ? @@ -219,40 +219,40 @@ QVariant EasyTreeWidgetItem::data(int _column, int _role) const } } -::profiler::block_index_t EasyTreeWidgetItem::block_index() const +profiler::block_index_t TreeWidgetItem::block_index() const { return m_block; } -::profiler_gui::EasyBlock& EasyTreeWidgetItem::guiBlock() +profiler_gui::EasyBlock& TreeWidgetItem::guiBlock() { return easyBlock(m_block); } -const ::profiler::BlocksTree& EasyTreeWidgetItem::block() const +const profiler::BlocksTree& TreeWidgetItem::block() const { return easyBlocksTree(m_block); } -::profiler::timestamp_t EasyTreeWidgetItem::duration() const +profiler::timestamp_t TreeWidgetItem::duration() const { if (parent() != nullptr) return block().node->duration(); return data(COL_DURATION, Qt::UserRole).toULongLong(); } -::profiler::timestamp_t EasyTreeWidgetItem::selfDuration() const +profiler::timestamp_t TreeWidgetItem::selfDuration() const { return data(COL_SELF_DURATION, Qt::UserRole).toULongLong(); } -void EasyTreeWidgetItem::setTimeSmart(int _column, ::profiler_gui::TimeUnits _units, const ::profiler::timestamp_t& _time, const QString& _prefix) +void TreeWidgetItem::setTimeSmart(int _column, profiler_gui::TimeUnits _units, const profiler::timestamp_t& _time, const QString& _prefix) { - const ::profiler::timestamp_t nanosecondsTime = PROF_NANOSECONDS(_time); + const profiler::timestamp_t nanosecondsTime = PROF_NANOSECONDS(_time); setData(_column, Qt::UserRole, (quint64)nanosecondsTime); setHasToolTip(_column); - setText(_column, QString("%1%2").arg(_prefix).arg(::profiler_gui::timeStringRealNs(_units, nanosecondsTime, 3))); + setText(_column, QString("%1%2").arg(_prefix).arg(profiler_gui::timeStringRealNs(_units, nanosecondsTime, 3))); // if (_time < 1e3) // { @@ -272,46 +272,46 @@ void EasyTreeWidgetItem::setTimeSmart(int _column, ::profiler_gui::TimeUnits _un // } } -void EasyTreeWidgetItem::setTimeSmart(int _column, ::profiler_gui::TimeUnits _units, const ::profiler::timestamp_t& _time) +void TreeWidgetItem::setTimeSmart(int _column, profiler_gui::TimeUnits _units, const profiler::timestamp_t& _time) { - const ::profiler::timestamp_t nanosecondsTime = PROF_NANOSECONDS(_time); + const profiler::timestamp_t nanosecondsTime = PROF_NANOSECONDS(_time); setData(_column, Qt::UserRole, (quint64)nanosecondsTime); setHasToolTip(_column); - setText(_column, ::profiler_gui::timeStringRealNs(_units, nanosecondsTime, 3)); + setText(_column, profiler_gui::timeStringRealNs(_units, nanosecondsTime, 3)); } -void EasyTreeWidgetItem::setTimeMs(int _column, const ::profiler::timestamp_t& _time) +void TreeWidgetItem::setTimeMs(int _column, const profiler::timestamp_t& _time) { - const ::profiler::timestamp_t nanosecondsTime = PROF_NANOSECONDS(_time); + const profiler::timestamp_t nanosecondsTime = PROF_NANOSECONDS(_time); setData(_column, Qt::UserRole, (quint64)nanosecondsTime); setHasToolTip(_column); setText(_column, QString::number(double(nanosecondsTime) * 1e-6, 'g', 9)); } -void EasyTreeWidgetItem::setTimeMs(int _column, const ::profiler::timestamp_t& _time, const QString& _prefix) +void TreeWidgetItem::setTimeMs(int _column, const profiler::timestamp_t& _time, const QString& _prefix) { - const ::profiler::timestamp_t nanosecondsTime = PROF_NANOSECONDS(_time); + const profiler::timestamp_t nanosecondsTime = PROF_NANOSECONDS(_time); setData(_column, Qt::UserRole, (quint64)nanosecondsTime); setHasToolTip(_column); setText(_column, QString("%1%2").arg(_prefix).arg(double(nanosecondsTime) * 1e-6, 0, 'g', 9)); } -void EasyTreeWidgetItem::setBackgroundColor(QRgb _color) +void TreeWidgetItem::setBackgroundColor(QRgb _color) { m_customBGColor = _color; } -void EasyTreeWidgetItem::setMain(bool _main) +void TreeWidgetItem::setMain(bool _main) { m_bMain = _main; } -void EasyTreeWidgetItem::collapseAll() +void TreeWidgetItem::collapseAll() { for (int i = 0, childrenNumber = childCount(); i < childrenNumber; ++i) { - static_cast(child(i))->collapseAll(); + static_cast(child(i))->collapseAll(); } setExpanded(false); @@ -319,11 +319,11 @@ void EasyTreeWidgetItem::collapseAll() guiBlock().expanded = false; } -void EasyTreeWidgetItem::expandAll() +void TreeWidgetItem::expandAll() { for (int i = 0, childrenNumber = childCount(); i < childrenNumber; ++i) { - static_cast(child(i))->expandAll(); + static_cast(child(i))->expandAll(); } setExpanded(true); @@ -331,7 +331,7 @@ void EasyTreeWidgetItem::expandAll() guiBlock().expanded = true; } -void EasyTreeWidgetItem::setBold(bool _bold) +void TreeWidgetItem::setBold(bool _bold) { m_font.setBold(_bold); } @@ -375,7 +375,7 @@ void EasyItemDelegate::paint(QPainter* painter, const QStyleOptionViewItem& opti { painter->save(); painter->setBrush(Qt::NoBrush); - painter->setPen(::profiler_gui::SYSTEM_BORDER_COLOR); + painter->setPen(profiler_gui::SYSTEM_BORDER_COLOR); painter->drawLine(QPoint(0, bottomLeft.y()), bottomLeft); painter->restore(); } @@ -414,7 +414,7 @@ void EasyItemDelegate::paint(QPainter* painter, const QStyleOptionViewItem& opti // Draw color marker with block color const auto brush = m_treeWidget->model()->data(index, Qt::UserRole + 1).value(); painter->setBrush(brush); - painter->setPen(::profiler_gui::SYSTEM_BORDER_COLOR); + painter->setPen(profiler_gui::SYSTEM_BORDER_COLOR); painter->drawRect(QRect(option.rect.left(), option.rect.top() + 5, 16, option.rect.height() - 10)); // Draw line under tree indicator diff --git a/profiler_gui/tree_widget_item.h b/profiler_gui/tree_widget_item.h index b164907..c56b4ab 100644 --- a/profiler_gui/tree_widget_item.h +++ b/profiler_gui/tree_widget_item.h @@ -5,7 +5,7 @@ * author : Victor Zarubkin * email : v.s.zarubkin@gmail.com * ----------------- : -* description : The file contains declaration of EasyTreeWidgetItem +* description : The file contains declaration of TreeWidgetItem * : for displyaing EasyProfiler blocks tree. * ----------------- : * change log : * 2016/08/18 Victor Zarubkin: moved sources from blocks_tree_widget.h @@ -113,10 +113,10 @@ enum EasyColumnsIndexes ////////////////////////////////////////////////////////////////////////// -class EasyTreeWidgetItem : public QTreeWidgetItem +class TreeWidgetItem : public QTreeWidgetItem { using Parent = QTreeWidgetItem; - using This = EasyTreeWidgetItem; + using This = TreeWidgetItem; QFont m_font; const ::profiler::block_index_t m_block; @@ -126,8 +126,8 @@ class EasyTreeWidgetItem : public QTreeWidgetItem public: - explicit EasyTreeWidgetItem(const ::profiler::block_index_t _treeBlock = ::profiler_gui::numeric_max(), Parent* _parent = nullptr); - virtual ~EasyTreeWidgetItem(); + explicit TreeWidgetItem(const ::profiler::block_index_t _treeBlock = ::profiler_gui::numeric_max(), Parent* _parent = nullptr); + virtual ~TreeWidgetItem(); bool operator < (const Parent& _other) const override; QVariant data(int _column, int _role) const override; @@ -162,7 +162,7 @@ private: bool hasToolTip(int _column) const; void setHasToolTip(int _column); -}; // END of class EasyTreeWidgetItem. +}; // END of class TreeWidgetItem. ////////////////////////////////////////////////////////////////////////// diff --git a/profiler_gui/tree_widget_loader.cpp b/profiler_gui/tree_widget_loader.cpp index c6ae0b8..6e6d5ea 100644 --- a/profiler_gui/tree_widget_loader.cpp +++ b/profiler_gui/tree_widget_loader.cpp @@ -5,7 +5,7 @@ * author : Victor Zarubkin * email : v.s.zarubkin@gmail.com * ----------------- : -* description : The file contains implementation of EasyTreeWidgetLoader which aim is +* description : The file contains implementation of TreeWidgetLoader which aim is * : to load EasyProfiler blocks hierarchy in separate thread. * ----------------- : * change log : * 2016/08/18 Victor Zarubkin: moved sources from blocks_tree_widget.h/.cpp @@ -57,6 +57,7 @@ #include "tree_widget_loader.h" #include "tree_widget_item.h" #include "globals.h" +#include #ifdef _WIN32 #include @@ -77,46 +78,46 @@ ////////////////////////////////////////////////////////////////////////// -EasyTreeWidgetLoader::EasyTreeWidgetLoader() +TreeWidgetLoader::TreeWidgetLoader() : m_bDone(ATOMIC_VAR_INIT(false)) , m_bInterrupt(ATOMIC_VAR_INIT(false)) , m_progress(ATOMIC_VAR_INIT(0)) - , m_mode(EasyTreeMode_Full) + , m_mode(TreeMode::Full) { } -EasyTreeWidgetLoader::~EasyTreeWidgetLoader() +TreeWidgetLoader::~TreeWidgetLoader() { interrupt(true); } -bool EasyTreeWidgetLoader::done() const +bool TreeWidgetLoader::done() const { - return m_bDone.load(); + return m_bDone.load(std::memory_order_acquire); } -void EasyTreeWidgetLoader::setDone() +void TreeWidgetLoader::setDone() { - m_bDone.store(true); + m_bDone.store(true, std::memory_order_release); //m_progress.store(100); } -void EasyTreeWidgetLoader::setProgress(int _progress) +void TreeWidgetLoader::setProgress(int _progress) { - m_progress.store(_progress); + m_progress.store(_progress, std::memory_order_release); } -bool EasyTreeWidgetLoader::interrupted() const +bool TreeWidgetLoader::interrupted() const { - return m_bInterrupt.load(); + return m_bInterrupt.load(std::memory_order_acquire); } -int EasyTreeWidgetLoader::progress() const +int TreeWidgetLoader::progress() const { - return m_progress.load(); + return m_progress.load(std::memory_order_acquire); } -void EasyTreeWidgetLoader::takeTopLevelItems(ThreadedItems& _output) +void TreeWidgetLoader::takeTopLevelItems(ThreadedItems& _output) { if (done()) { @@ -125,7 +126,7 @@ void EasyTreeWidgetLoader::takeTopLevelItems(ThreadedItems& _output) } } -void EasyTreeWidgetLoader::takeItems(Items& _output) +void TreeWidgetLoader::takeItems(Items& _output) { if (done()) { @@ -134,15 +135,11 @@ void EasyTreeWidgetLoader::takeItems(Items& _output) } } -void EasyTreeWidgetLoader::interrupt(bool _wait) +void TreeWidgetLoader::interrupt(bool _wait) { - m_bInterrupt.store(true); - if (m_thread.joinable()) - m_thread.join(); - - m_bInterrupt.store(false); - m_bDone.store(false); - m_progress.store(0); + m_worker.dequeue(); + m_bDone.store(false, std::memory_order_release); + m_progress.store(0, std::memory_order_release); if (!_wait) { @@ -170,27 +167,39 @@ void EasyTreeWidgetLoader::interrupt(bool _wait) m_iditems.clear(); } -void EasyTreeWidgetLoader::fillTree(::profiler::timestamp_t& _beginTime, const unsigned int _blocksNumber, const ::profiler::thread_blocks_tree_t& _blocksTree, EasyTreeMode _mode) +void TreeWidgetLoader::fillTree(::profiler::timestamp_t& _beginTime, const unsigned int _blocksNumber, const ::profiler::thread_blocks_tree_t& _blocksTree, TreeMode _mode) { interrupt(); m_mode = _mode; - m_thread = ::std::thread(&EasyTreeWidgetLoader::setTreeInternal1, this, - ::std::ref(_beginTime), _blocksNumber, ::std::ref(_blocksTree), EASY_GLOBALS.add_zero_blocks_to_hierarchy, - EASY_GLOBALS.use_decorated_thread_name, EASY_GLOBALS.hex_thread_id, EASY_GLOBALS.time_units); + + const auto zeroBlocks = EASY_GLOBALS.add_zero_blocks_to_hierarchy; + const auto decoratedNames = EASY_GLOBALS.use_decorated_thread_name; + const auto hexThreadIds = EASY_GLOBALS.hex_thread_id; + const auto timeUnits = EASY_GLOBALS.time_units; + m_worker.enqueue([this, &_beginTime, _blocksNumber, &_blocksTree, zeroBlocks, decoratedNames, hexThreadIds, timeUnits] + { + setTreeInternal1(_beginTime, _blocksNumber, _blocksTree, zeroBlocks, decoratedNames, hexThreadIds, timeUnits); + }, m_bInterrupt); } -void EasyTreeWidgetLoader::fillTreeBlocks(const::profiler_gui::TreeBlocks& _blocks, ::profiler::timestamp_t _beginTime, ::profiler::timestamp_t _left, ::profiler::timestamp_t _right, bool _strict, EasyTreeMode _mode) +void TreeWidgetLoader::fillTreeBlocks(const::profiler_gui::TreeBlocks& _blocks, ::profiler::timestamp_t _beginTime, ::profiler::timestamp_t _left, ::profiler::timestamp_t _right, bool _strict, TreeMode _mode) { interrupt(); m_mode = _mode; - m_thread = ::std::thread(&EasyTreeWidgetLoader::setTreeInternal2, this, - _beginTime, ::std::ref(_blocks), _left, _right, _strict, EASY_GLOBALS.add_zero_blocks_to_hierarchy, - EASY_GLOBALS.use_decorated_thread_name, EASY_GLOBALS.hex_thread_id, EASY_GLOBALS.time_units); + + const auto zeroBlocks = EASY_GLOBALS.add_zero_blocks_to_hierarchy; + const auto decoratedNames = EASY_GLOBALS.use_decorated_thread_name; + const auto hexThreadIds = EASY_GLOBALS.hex_thread_id; + const auto timeUnits = EASY_GLOBALS.time_units; + m_worker.enqueue([this, _beginTime, &_blocks, _left, _right, _strict, zeroBlocks, decoratedNames, hexThreadIds, timeUnits] + { + setTreeInternal2(_beginTime, _blocks, _left, _right, _strict, zeroBlocks, decoratedNames, hexThreadIds, timeUnits); + }, m_bInterrupt); } ////////////////////////////////////////////////////////////////////////// -void EasyTreeWidgetLoader::setTreeInternal1(::profiler::timestamp_t& _beginTime, const unsigned int _blocksNumber, const ::profiler::thread_blocks_tree_t& _blocksTree, bool _addZeroBlocks, bool _decoratedThreadNames, bool _hexThreadId, ::profiler_gui::TimeUnits _units) +void TreeWidgetLoader::setTreeInternal1(::profiler::timestamp_t& _beginTime, const unsigned int _blocksNumber, const ::profiler::thread_blocks_tree_t& _blocksTree, bool _addZeroBlocks, bool _decoratedThreadNames, bool _hexThreadId, ::profiler_gui::TimeUnits _units) { m_items.reserve(_blocksNumber + _blocksTree.size()); // _blocksNumber does not include Thread root blocks @@ -218,7 +227,7 @@ void EasyTreeWidgetLoader::setTreeInternal1(::profiler::timestamp_t& _beginTime, break; const auto& root = threadTree.second; - auto item = new EasyTreeWidgetItem(); + auto item = new TreeWidgetItem(); item->setText(COL_NAME, ::profiler_gui::decoratedThreadName(_decoratedThreadNames, root, u_thread, _hexThreadId)); ::profiler::timestamp_t duration = 0; @@ -270,7 +279,7 @@ void EasyTreeWidgetLoader::setTreeInternal1(::profiler::timestamp_t& _beginTime, using BeginEndIndicesMap = ::std::unordered_map<::profiler::thread_id_t, ::profiler::block_index_t, ::estd::hash<::profiler::thread_id_t> >; -void EasyTreeWidgetLoader::setTreeInternal2(const ::profiler::timestamp_t& _beginTime, +void TreeWidgetLoader::setTreeInternal2(const ::profiler::timestamp_t& _beginTime, const ::profiler_gui::TreeBlocks& _blocks, ::profiler::timestamp_t _left, ::profiler::timestamp_t _right, @@ -289,7 +298,7 @@ void EasyTreeWidgetLoader::setTreeInternal2(const ::profiler::timestamp_t& _begi BeginEndIndicesMap beginEndMap; RootsMap threadsMap; - auto const setTree = (m_mode == EasyTreeMode_Full) ? &EasyTreeWidgetLoader::setTreeInternal : &EasyTreeWidgetLoader::setTreeInternalPlain; + auto const setTree = (m_mode == TreeMode::Full) ? &TreeWidgetLoader::setTreeInternal : &TreeWidgetLoader::setTreeInternalPlain; const auto u_thread = ::profiler_gui::toUnicode("thread"); int i = 0, total = static_cast(_blocks.size()); @@ -309,7 +318,7 @@ void EasyTreeWidgetLoader::setTreeInternal2(const ::profiler::timestamp_t& _begi } ::profiler::timestamp_t duration = 0; - EasyTreeWidgetItem* thread_item = nullptr; + TreeWidgetItem* thread_item = nullptr; ::profiler::block_index_t& firstCswitch = beginEndMap[block.root->thread_id]; auto thread_item_it = threadsMap.find(block.root->thread_id); if (thread_item_it != threadsMap.end()) @@ -318,7 +327,7 @@ void EasyTreeWidgetLoader::setTreeInternal2(const ::profiler::timestamp_t& _begi } else { - thread_item = new EasyTreeWidgetItem(); + thread_item = new TreeWidgetItem(); thread_item->setText(COL_NAME, ::profiler_gui::decoratedThreadName(_decoratedThreadNames, *block.root, u_thread, _hexThreadId)); if (!block.root->children.empty()) @@ -376,7 +385,7 @@ void EasyTreeWidgetLoader::setTreeInternal2(const ::profiler::timestamp_t& _begi } } - auto item = new EasyTreeWidgetItem(block.tree, thread_item); + auto item = new TreeWidgetItem(block.tree, thread_item); duration = endTime - startTime; auto name = *gui_block.tree.node->name() != 0 ? gui_block.tree.node->name() : easyDescriptor(gui_block.tree.node->id()).name(); @@ -538,12 +547,12 @@ void EasyTreeWidgetLoader::setTreeInternal2(const ::profiler::timestamp_t& _begi ////////////////////////////////////////////////////////////////////////// -size_t EasyTreeWidgetLoader::setTreeInternal(const ::profiler::BlocksTreeRoot& _threadRoot, +size_t TreeWidgetLoader::setTreeInternal(const ::profiler::BlocksTreeRoot& _threadRoot, ::profiler::block_index_t _firstCswitch, const ::profiler::timestamp_t& _beginTime, const ::profiler::BlocksTree::children_t& _children, - EasyTreeWidgetItem* _parent, - EasyTreeWidgetItem* _frame, + TreeWidgetItem* _parent, + TreeWidgetItem* _frame, ::profiler::timestamp_t _left, ::profiler::timestamp_t _right, bool _strict, @@ -551,7 +560,7 @@ size_t EasyTreeWidgetLoader::setTreeInternal(const ::profiler::BlocksTreeRoot& _ bool _addZeroBlocks, ::profiler_gui::TimeUnits _units) { - auto const setTree = m_mode == EasyTreeMode_Full ? &EasyTreeWidgetLoader::setTreeInternal : &EasyTreeWidgetLoader::setTreeInternalPlain; + auto const setTree = m_mode == TreeMode::Full ? &TreeWidgetLoader::setTreeInternal : &TreeWidgetLoader::setTreeInternalPlain; size_t total_items = 0; for (auto child_index : _children) @@ -599,7 +608,7 @@ size_t EasyTreeWidgetLoader::setTreeInternal(const ::profiler::BlocksTreeRoot& _ } } - auto item = new EasyTreeWidgetItem(child_index, _parent); + auto item = new TreeWidgetItem(child_index, _parent); auto name = *child.node->name() != 0 ? child.node->name() : easyDescriptor(child.node->id()).name(); item->setText(COL_NAME, ::profiler_gui::toUnicode(name)); @@ -771,7 +780,7 @@ size_t EasyTreeWidgetLoader::setTreeInternal(const ::profiler::BlocksTreeRoot& _ ////////////////////////////////////////////////////////////////////////// -::profiler::timestamp_t EasyTreeWidgetLoader::calculateChildrenDurationRecursive(const ::profiler::BlocksTree::children_t& _children, ::profiler::block_id_t _id) +::profiler::timestamp_t TreeWidgetLoader::calculateChildrenDurationRecursive(const ::profiler::BlocksTree::children_t& _children, ::profiler::block_id_t _id) { ::profiler::timestamp_t total_duration = 0; @@ -789,12 +798,12 @@ size_t EasyTreeWidgetLoader::setTreeInternal(const ::profiler::BlocksTreeRoot& _ return total_duration; } -size_t EasyTreeWidgetLoader::setTreeInternalPlain(const ::profiler::BlocksTreeRoot& _threadRoot, +size_t TreeWidgetLoader::setTreeInternalPlain(const ::profiler::BlocksTreeRoot& _threadRoot, ::profiler::block_index_t _firstCswitch, const ::profiler::timestamp_t& _beginTime, const ::profiler::BlocksTree::children_t& _children, - EasyTreeWidgetItem*, - EasyTreeWidgetItem* _frame, + TreeWidgetItem*, + TreeWidgetItem* _frame, ::profiler::timestamp_t _left, ::profiler::timestamp_t _right, bool _strict, @@ -915,7 +924,7 @@ size_t EasyTreeWidgetLoader::setTreeInternalPlain(const ::profiler::BlocksTreeRo } } - auto item = new EasyTreeWidgetItem(child_index, _frame); + auto item = new TreeWidgetItem(child_index, _frame); auto name = *child.node->name() != 0 ? child.node->name() : easyDescriptor(child.node->id()).name(); item->setText(COL_NAME, ::profiler_gui::toUnicode(name)); diff --git a/profiler_gui/tree_widget_loader.h b/profiler_gui/tree_widget_loader.h index 5e0dc09..d11d4b8 100644 --- a/profiler_gui/tree_widget_loader.h +++ b/profiler_gui/tree_widget_loader.h @@ -5,7 +5,7 @@ * author : Victor Zarubkin * email : v.s.zarubkin@gmail.com * ----------------- : -* description : The file contains declaration of EasyTreeWidgetLoader which aim is +* description : The file contains declaration of TreeWidgetLoader which aim is * : to load EasyProfiler blocks hierarchy in separate thread. * ----------------- : * change log : * 2016/08/18 Victor Zarubkin: moved sources from blocks_tree_widget.h/.cpp @@ -59,50 +59,50 @@ #include #include -#include #include #include #include "common_types.h" +#include "thread_pool_task.h" ////////////////////////////////////////////////////////////////////////// -class EasyTreeWidgetItem; +class TreeWidgetItem; #ifndef EASY_TREE_WIDGET__USE_VECTOR -using Items = ::std::unordered_map<::profiler::block_index_t, EasyTreeWidgetItem*, ::estd::hash<::profiler::block_index_t> >; +using Items = ::std::unordered_map >; #else -using Items = ::std::vector; +using Items = ::std::vector; #endif -using ThreadedItems = ::std::vector<::std::pair<::profiler::thread_id_t, EasyTreeWidgetItem*> >; -using RootsMap = ::std::unordered_map<::profiler::thread_id_t, EasyTreeWidgetItem*, ::estd::hash<::profiler::thread_id_t> >; -using IdItems = ::std::unordered_map<::profiler::block_id_t, EasyTreeWidgetItem*, ::estd::hash<::profiler::block_index_t> >; +using ThreadedItems = ::std::vector<::std::pair >; +using RootsMap = ::std::unordered_map >; +using IdItems = ::std::unordered_map >; ////////////////////////////////////////////////////////////////////////// -enum EasyTreeMode : uint8_t +enum class TreeMode : uint8_t { - EasyTreeMode_Full, - EasyTreeMode_Plain + Full, + Plain }; ////////////////////////////////////////////////////////////////////////// -class EasyTreeWidgetLoader Q_DECL_FINAL +class TreeWidgetLoader Q_DECL_FINAL { ThreadedItems m_topLevelItems; ///< Items m_items; ///< IdItems m_iditems; ///< - ::std::thread m_thread; ///< - ::std::atomic_bool m_bDone; ///< - ::std::atomic_bool m_bInterrupt; ///< - ::std::atomic m_progress; ///< - EasyTreeMode m_mode; ///< + ThreadPoolTask m_worker; ///< + std::atomic_bool m_bDone; ///< + std::atomic_bool m_bInterrupt; ///< + std::atomic m_progress; ///< + TreeMode m_mode; ///< public: - EasyTreeWidgetLoader(); - ~EasyTreeWidgetLoader(); + TreeWidgetLoader(); + ~TreeWidgetLoader(); int progress() const; bool done() const; @@ -111,8 +111,8 @@ public: void takeItems(Items& _output); void interrupt(bool _wait = false); - void fillTree(::profiler::timestamp_t& _beginTime, const unsigned int _blocksNumber, const ::profiler::thread_blocks_tree_t& _blocksTree, EasyTreeMode _mode); - void fillTreeBlocks(const::profiler_gui::TreeBlocks& _blocks, ::profiler::timestamp_t _beginTime, ::profiler::timestamp_t _left, ::profiler::timestamp_t _right, bool _strict, EasyTreeMode _mode); + void fillTree(profiler::timestamp_t& _beginTime, const unsigned int _blocksNumber, const profiler::thread_blocks_tree_t& _blocksTree, TreeMode _mode); + void fillTreeBlocks(const::profiler_gui::TreeBlocks& _blocks, profiler::timestamp_t _beginTime, profiler::timestamp_t _left, profiler::timestamp_t _right, bool _strict, TreeMode _mode); private: @@ -120,14 +120,14 @@ private: void setDone(); void setProgress(int _progress); - void setTreeInternal1(::profiler::timestamp_t& _beginTime, const unsigned int _blocksNumber, const ::profiler::thread_blocks_tree_t& _blocksTree, bool _addZeroBlocks, bool _decoratedThreadNames, bool _hexThreadId, ::profiler_gui::TimeUnits _units); - void setTreeInternal2(const ::profiler::timestamp_t& _beginTime, const ::profiler_gui::TreeBlocks& _blocks, ::profiler::timestamp_t _left, ::profiler::timestamp_t _right, bool _strict, bool _addZeroBlocks, bool _decoratedThreadNames, bool _hexThreadId, ::profiler_gui::TimeUnits _units); - size_t setTreeInternal(const ::profiler::BlocksTreeRoot& _threadRoot, ::profiler::block_index_t _firstCswitch, const ::profiler::timestamp_t& _beginTime, const ::profiler::BlocksTree::children_t& _children, EasyTreeWidgetItem* _parent, EasyTreeWidgetItem* _frame, ::profiler::timestamp_t _left, ::profiler::timestamp_t _right, bool _strict, ::profiler::timestamp_t& _duration, bool _addZeroBlocks, ::profiler_gui::TimeUnits _units); - size_t setTreeInternalPlain(const ::profiler::BlocksTreeRoot& _threadRoot, ::profiler::block_index_t _firstCswitch, const ::profiler::timestamp_t& _beginTime, const ::profiler::BlocksTree::children_t& _children, EasyTreeWidgetItem* _parent, EasyTreeWidgetItem* _frame, ::profiler::timestamp_t _left, ::profiler::timestamp_t _right, bool _strict, ::profiler::timestamp_t& _duration, bool _addZeroBlocks, ::profiler_gui::TimeUnits _units); + void setTreeInternal1(profiler::timestamp_t& _beginTime, const unsigned int _blocksNumber, const profiler::thread_blocks_tree_t& _blocksTree, bool _addZeroBlocks, bool _decoratedThreadNames, bool _hexThreadId, ::profiler_gui::TimeUnits _units); + void setTreeInternal2(const profiler::timestamp_t& _beginTime, const ::profiler_gui::TreeBlocks& _blocks, profiler::timestamp_t _left, profiler::timestamp_t _right, bool _strict, bool _addZeroBlocks, bool _decoratedThreadNames, bool _hexThreadId, ::profiler_gui::TimeUnits _units); + size_t setTreeInternal(const profiler::BlocksTreeRoot& _threadRoot, profiler::block_index_t _firstCswitch, const profiler::timestamp_t& _beginTime, const profiler::BlocksTree::children_t& _children, TreeWidgetItem* _parent, TreeWidgetItem* _frame, profiler::timestamp_t _left, profiler::timestamp_t _right, bool _strict, profiler::timestamp_t& _duration, bool _addZeroBlocks, ::profiler_gui::TimeUnits _units); + size_t setTreeInternalPlain(const profiler::BlocksTreeRoot& _threadRoot, profiler::block_index_t _firstCswitch, const profiler::timestamp_t& _beginTime, const profiler::BlocksTree::children_t& _children, TreeWidgetItem* _parent, TreeWidgetItem* _frame, profiler::timestamp_t _left, profiler::timestamp_t _right, bool _strict, profiler::timestamp_t& _duration, bool _addZeroBlocks, ::profiler_gui::TimeUnits _units); - ::profiler::timestamp_t calculateChildrenDurationRecursive(const ::profiler::BlocksTree::children_t& _children, ::profiler::block_id_t _id); + profiler::timestamp_t calculateChildrenDurationRecursive(const profiler::BlocksTree::children_t& _children, profiler::block_id_t _id); -}; // END of class EasyTreeWidgetLoader. +}; // END of class TreeWidgetLoader. ////////////////////////////////////////////////////////////////////////// diff --git a/profiler_gui/treeview_first_column_delegate.cpp b/profiler_gui/treeview_first_column_delegate.cpp index bc61555..9676835 100644 --- a/profiler_gui/treeview_first_column_delegate.cpp +++ b/profiler_gui/treeview_first_column_delegate.cpp @@ -5,17 +5,17 @@ #include "treeview_first_column_delegate.h" #include "globals.h" -EasyTreeViewFirstColumnItemDelegate::EasyTreeViewFirstColumnItemDelegate(QObject* parent) : QStyledItemDelegate(parent) +TreeViewFirstColumnItemDelegate::TreeViewFirstColumnItemDelegate(QObject* parent) : QStyledItemDelegate(parent) { } -EasyTreeViewFirstColumnItemDelegate::~EasyTreeViewFirstColumnItemDelegate() +TreeViewFirstColumnItemDelegate::~TreeViewFirstColumnItemDelegate() { } -void EasyTreeViewFirstColumnItemDelegate::paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const +void TreeViewFirstColumnItemDelegate::paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const { // Draw item as usual QStyledItemDelegate::paint(painter, option, index); diff --git a/profiler_gui/treeview_first_column_delegate.h b/profiler_gui/treeview_first_column_delegate.h index d55c056..30fa5c9 100644 --- a/profiler_gui/treeview_first_column_delegate.h +++ b/profiler_gui/treeview_first_column_delegate.h @@ -8,16 +8,16 @@ #include -class EasyTreeViewFirstColumnItemDelegate : public QStyledItemDelegate +class TreeViewFirstColumnItemDelegate : public QStyledItemDelegate { Q_OBJECT public: - explicit EasyTreeViewFirstColumnItemDelegate(QObject* parent = nullptr); - ~EasyTreeViewFirstColumnItemDelegate() override; + explicit TreeViewFirstColumnItemDelegate(QObject* parent = nullptr); + ~TreeViewFirstColumnItemDelegate() override; void paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const override; -}; // END of class EasyTreeViewFirstColumnItemDelegate. +}; // END of class TreeViewFirstColumnItemDelegate. #endif // EASY_PROFILER_GUI_TREEVIEW_FIRST_COLUMN_DELEGATE_H diff --git a/sample/main.cpp b/sample/main.cpp index b2e694f..985e930 100644 --- a/sample/main.cpp +++ b/sample/main.cpp @@ -175,7 +175,7 @@ void modellingThread(){ localSleep(1200000); ++step; - EASY_VALUE("step", step, profiler::colors::Gold); + EASY_VALUE("step", sin((double)step), profiler::colors::Gold, EASY_VIN(step)); if (step > 10000000) step = 0;