18#include "TimelineView.hpp"
19#include "src/ui/views/CommunicationIndicator.hpp"
20#include "src/ui/views/SlotIndicator.hpp"
21#include "src/ui/Constants.hpp"
22#include "CollectiveCommunicationIndicator.hpp"
24#include <QGraphicsRectItem>
25#include <QApplication>
29 auto scene =
new QGraphicsScene();
30 this->setAlignment(Qt::AlignTop | Qt::AlignLeft);
31 this->setAutoFillBackground(
false);
32 this->setStyleSheet(
"background: transparent");
33 this->setScene(scene);
34 this->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
37 connect(this->data, SIGNAL(selectionChanged(types::TraceTime,types::TraceTime)),
this, SLOT(
updateView()));
38 connect(this->data, SIGNAL(filterChanged(
Filter)),
this, SLOT(
updateView()));
43void TimelineView::populateScene(QGraphicsScene *scene) {
44 auto width = scene->width();
46 auto runtime = selection->
getRuntime().count();
47 auto runtimeR =
static_cast<qreal
>(runtime);
48 auto begin = this->data->
getBegin().count();
49 auto beginR =
static_cast<qreal
>(begin);
50 auto end = begin + runtime;
51 auto endR =
static_cast<qreal
>(end);
53 QPen arrowPen(Qt::black, 1);
54 QPen collectiveCommunicationPen(colors::COLOR_COLLECTIVE_COMMUNICATION, 2);
58 auto onTimedElementDoubleClicked = [
this](
TimedElement *element) {
59 this->data->
setSelection(element->getStartTime(), element->getEndTime());
65 for (
const auto &item: selection->getSlots()) {
67 for (
const auto &slot: item.second) {
70 auto region = slot->region;
71 auto regionName = region->name();
72 auto regionNameStr = regionName.str();
73 auto startTime = slot->startTime.count();
74 auto endTime = slot->endTime.count();
78 auto effectiveStartTime = qMax(begin, startTime);
80 auto effectiveEndTime = qMin(end, endTime);
82 auto slotBeginPos = (
static_cast<qreal
>(effectiveStartTime - begin) /
static_cast<qreal
>(runtime)) * width;
83 auto slotRuntime =
static_cast<qreal
>(effectiveEndTime - effectiveStartTime);
84 auto rectWidth = (slotRuntime /
static_cast<qreal
>(runtime)) * width;
86 QRectF rect(slotBeginPos, top, qMax(rectWidth, 5.0), ROW_HEIGHT);
88 rectItem->setOnDoubleClick(onTimedElementDoubleClicked);
89 rectItem->setOnSelected(onTimedElementSelected);
90 rectItem->setToolTip(regionNameStr.c_str());
94 switch (slot->getKind()) {
96 rectColor = colors::COLOR_SLOT_MPI;
97 rectItem->setZValue(layers::Z_LAYER_SLOTS_MIN_PRIORITY + 2);
100 rectColor = colors::COLOR_SLOT_OPEN_MP;
101 rectItem->setZValue(layers::Z_LAYER_SLOTS_MIN_PRIORITY + 1);
106 rectColor = colors::COLOR_SLOT_PLAIN;
107 rectItem->setZValue(layers::Z_LAYER_SLOTS_MIN_PRIORITY + 0);
110 rectItem->setBrush(rectColor);
111 scene->addItem(rectItem);
117 for (
const auto &communication: selection->getCommunications()) {
119 auto startEventEnd =
static_cast<qreal
>(startEvent->
getEndTime().count());
120 auto startEventStart =
static_cast<qreal
>(startEvent->
getStartTime().count());
124 auto endEventEnd =
static_cast<qreal
>(startEvent->
getEndTime().count());
125 auto endEventStart =
static_cast<qreal
>(startEvent->
getStartTime().count());
128 auto fromTime = startEventStart + (startEventEnd - startEventStart) / 2;
129 auto effectiveFromTime = qMax(beginR, fromTime) - beginR;
131 auto toTime = endEventStart + (endEventEnd - endEventStart) / 2;
132 auto effectiveToTime = qMin(endR, toTime) - beginR;
134 auto fromRank = startEvent->
getLocation()->ref().get();
135 auto toRank = endEvent->
getLocation()->ref().get();
137 auto fromX = effectiveFromTime / runtimeR * width;
138 auto fromY =
static_cast<qreal
>(fromRank * ROW_HEIGHT) + .5 * ROW_HEIGHT + 20;
140 auto toX = effectiveToTime / runtimeR * width;
141 auto toY =
static_cast<qreal
> (toRank * ROW_HEIGHT) + .5 * ROW_HEIGHT + 20;
144 arrow->setOnSelected(onTimedElementSelected);
145 arrow->setOnDoubleClick(onTimedElementDoubleClicked);
146 arrow->setPen(arrowPen);
147 arrow->setZValue(layers::Z_LAYER_P2P_COMMUNICATIONS);
148 scene->addItem(arrow);
151 for (
const auto &communication: selection->getCollectiveCommunications()) {
152 auto fromTime =
static_cast<qreal
>(communication->getStartTime().count());
153 auto effectiveFromTime = qMax(beginR, fromTime) - beginR;
155 auto toTime =
static_cast<qreal
>(communication->getEndTime().count());
156 auto effectiveToTime = qMin(endR, toTime) - beginR;
158 auto fromX = (effectiveFromTime / runtimeR) * width;
161 auto toX = (effectiveToTime / runtimeR) * width;
165 rectItem->setOnSelected(onTimedElementSelected);
166 rectItem->setRect(QRectF(QPointF(fromX, fromY), QPointF(toX, toY)));
167 rectItem->setPen(collectiveCommunicationPen);
168 rectItem->setZValue(layers::Z_LAYER_COLLECTIVE_COMMUNICATIONS);
169 scene->addItem(rectItem);
177 QGraphicsView::resizeEvent(event);
182 this->scene()->clear();
184 auto ROW_HEIGHT = 30;
186 auto sceneRect = this->rect();
187 sceneRect.setHeight(sceneHeight);
189 this->scene()->setSceneRect(sceneRect);
190 this->populateScene(this->scene());
196 QPoint numDegrees =
event->angleDelta() / 8;
198 if (!numDegrees.isNull() && QApplication::keyboardModifiers() & (Qt::CTRL | Qt::SHIFT)) {
200 QPoint numSteps = numDegrees / 15;
202 auto deltaDuration = stepSize * numSteps.y();
203 auto delta =
static_cast<double>(deltaDuration.count());
205 types::TraceTime newBegin;
206 types::TraceTime newEnd;
207 if (QApplication::keyboardModifiers() == Qt::CTRL) {
209 auto originFactor =
event->scenePosition().x() / this->scene()->width();
211 auto leftDelta = types::TraceTime(
static_cast<long>(originFactor * 2 * delta));
212 auto rightDelta = types::TraceTime(
static_cast<long>((1 - originFactor) * 2 * delta));
222 auto newBeginBounded = qMax(newBeginAbs, types::TraceTime(0));
234 QGraphicsView::wheelEvent(event);
Indicator for collective communications.
Abstract class for generic Communication events.
virtual otf2::definition::location * getLocation() const =0
otf2::chrono::duration getEndTime() const override=0
otf2::chrono::duration getStartTime() const override=0
Class containing options to filter the view.
SlotKind getSlotKinds() const
Returns the kinds of slots that should be rendered.
Indicator for collective communications.
A base class for all elements with a start and end time.
virtual types::TraceTime getStartTime() const =0
Returns the start time of the current object.
void updateView()
Updates the view to reflect the current selection of the TraceDataProxy.
void resizeEvent(QResizeEvent *event) override
TimelineView(TraceDataProxy *data, QWidget *parent=nullptr)
Creates a new instance of the TimelineView class.
void wheelEvent(QWheelEvent *event) override
Model class providing access to data and pub/sub architecture of change events.
ViewSettings * getSettings() const
Returns the current view settings.
types::TraceTime getTotalRuntime() const
types::TraceTime getBegin() const
Returns the selected start time.
Trace * getSelection() const
Returns the current selection.
void setTimeElementSelection(TimedElement *newSlot)
void setSelection(types::TraceTime newBegin, types::TraceTime newEnd)
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.
int getZoomQuotient() const
Returns the reciprocal of the current zoom factor.
Filter getFilter() const
Returns the current filter.