18#include "TraceOverviewTimelineView.hpp"
19#include "src/ui/views/CommunicationIndicator.hpp"
20#include "src/ui/Constants.hpp"
21#include "src/models/UITrace.hpp"
23#include <QGraphicsRectItem>
24#include <QApplication>
29 auto scene =
new QGraphicsScene(
this);
30 this->setAutoFillBackground(
false);
31 this->setStyleSheet(
"background: transparent");
32 this->setScene(scene);
33 this->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
35 selectionFrom = types::TraceTime(0);
40void TraceOverviewTimelineView::populateScene(QGraphicsScene *scene) {
41 auto width = scene->width();
44 auto end = begin + runtime;
47 auto ROW_HEIGHT = scene->height() /
static_cast<qreal
>(uiTrace->
getSlots().size());
48 for (
const auto &item: uiTrace->
getSlots()) {
50 for (
const auto &slot: item.second) {
51 auto startTime = slot->startTime.count();
52 auto endTime = slot->endTime.count();
56 auto effectiveStartTime = qMax(begin, startTime);
58 auto effectiveEndTime = qMin(end, endTime);
60 auto slotBeginPos = qMax(0.0,
61 (
static_cast<qreal
>(effectiveStartTime - begin) /
static_cast<qreal
>(runtime)) *
63 auto slotRuntime =
static_cast<qreal
>(effectiveEndTime - effectiveStartTime);
64 auto rectWidth = (slotRuntime /
static_cast<qreal
>(runtime)) * width;
66 QRectF rect(slotBeginPos, top, qMax(rectWidth, 5.0), ROW_HEIGHT);
67 auto rectItem = scene->addRect(rect);
71 switch (slot->getKind()) {
73 rectColor = colors::COLOR_SLOT_MPI;
74 rectItem->setZValue(layers::Z_LAYER_SLOTS_MIN_PRIORITY + 2);
77 rectColor = colors::COLOR_SLOT_OPEN_MP;
78 rectItem->setZValue(layers::Z_LAYER_SLOTS_MIN_PRIORITY + 1);
82 rectColor = colors::COLOR_SLOT_PLAIN;
83 rectItem->setZValue(layers::Z_LAYER_SLOTS_MIN_PRIORITY + 0);
87 rectItem->setBrush(rectColor);
93 QPen selectionPen(Qt::black);
94 QBrush selectionBrush(QColor(0xFF, 0xFF, 0xFF, 0x7F));
95 selectionRectRight = scene->addRect(width - 1,0, 0, top, selectionPen, selectionBrush);
96 selectionRectRight->setZValue(layers::Z_LAYER_SELECTION);
97 selectionRectLeft = scene->addRect(0,0, 0, top, selectionPen, selectionBrush);
98 selectionRectLeft->setZValue(layers::Z_LAYER_SELECTION);
108 QGraphicsView::resizeEvent(event);
112 this->scene()->clear();
114 auto sceneRect = this->rect();
115 sceneRect.setHeight(size().height() - 2);
117 this->scene()->setSceneRect(sceneRect);
118 this->populateScene(this->scene());
122 selectionFrom = from;
124 auto durationR =
static_cast<qreal
>(uiTrace->
getRuntime().count());
125 auto fromR =
static_cast<qreal
>(from.count());
126 auto toR =
static_cast<qreal
>(to.count());
127 auto width = this->width();
129 auto l = selectionRectLeft->rect();
130 l.setWidth(fromR / durationR * width);
131 selectionRectLeft->setRect(l);
133 auto r = selectionRectRight->rect();
134 r.setX(toR / durationR * width);
135 selectionRectRight->setRect(r);
142 rubberBandOrigin =
event->pos();
143 rubberBandOrigin.setY(0);
145 rubberBand =
new QRubberBand(QRubberBand::Rectangle,
this);
146 rubberBand->setGeometry(QRect(rubberBandOrigin, QSize(0, this->height())));
152 auto nextPoint =
event->pos();
153 nextPoint.setY(this->height());
154 rubberBand->setGeometry(QRect(rubberBandOrigin, nextPoint).normalized());
161 auto from = (rubberBand->geometry().x() * fullTrace->
getRuntime()) / this->width();
162 auto to = from + (rubberBand->geometry().width() * fullTrace->
getRuntime()) / this->width();
void windowSelectionChanged(types::TraceTime from, types::TraceTime to)
Signals a change in the selection.
void mousePressEvent(QMouseEvent *event) override
void updateView()
Updates the view to reflect the current selection of the TraceDataProxy.
void setSelectionWindow(types::TraceTime from, types::TraceTime to)
Set a new selection window. The UI is updated to reflect the changes.
void mouseMoveEvent(QMouseEvent *event) override
TraceOverviewTimelineView(Trace *fullTrace, QWidget *parent=nullptr)
Creates a new instance of the TraceOverviewTimelineView class.
void resizeEvent(QResizeEvent *event) override
void mouseReleaseEvent(QMouseEvent *event) override
Abstract base class for a trace.
virtual otf2::chrono::duration getRuntime() const =0
Returns the runtime of the current trace.
virtual std::map< otf2::definition::location_group *, Range< Slot * >, LocationGroupCmp > getSlots() const =0
Returns a map of slots of the current trace.
static UITrace * forResolution(Trace *trace, otf2::chrono::duration timePerPixel)