Merge branch 'work/transaction_selection' into 'develop'

Improve selection-area of transactions.

See merge request ems/astdm/dram.sys!318
This commit is contained in:
Lukas Steiner
2021-09-22 14:13:05 +00:00
9 changed files with 33 additions and 34 deletions

View File

@@ -137,22 +137,18 @@ Qt::BrushStyle Phase::getBrushStyle() const
return Qt::SolidPattern;
}
bool Phase::isSelected(traceTime time, double yVal,
const TraceDrawingProperties &drawingProperties) const
bool Phase::isSelected(Timespan timespan, double yVal, const TraceDrawingProperties &drawingProperties) const
{
// Increase selectable area of phases with zero span
traceTime offset = (span.Begin() == span.End()) ? static_cast<traceTime>(0.05 * clk) : 0;
if (span.Begin() <= time && time <= (span.End() + offset))
if (span.overlaps(timespan))
{
for (auto line : getTracePlotLines(drawingProperties))
{
if (!line->isCollapsed() && fabs(yVal - line->getYVal()) <= hexagonHeight)
if (!line->isCollapsed() && fabs(yVal - line->getYVal()) <= hexagonHeight / 2)
return true;
}
}
if (spanOnDataBus && spanOnDataBus->contains(time))
if (spanOnDataBus && spanOnDataBus->overlaps(timespan))
{
for (auto dataBusLine : drawingProperties.getDataBusLines())
{
@@ -161,8 +157,9 @@ bool Phase::isSelected(traceTime time, double yVal,
}
}
for (Timespan span : spansOnCommandBus) {
if (span.contains(time))
for (const Timespan &span : spansOnCommandBus)
{
if (span.overlaps(timespan))
{
for (auto commandBusLine : drawingProperties.getCommandBusLines())
{

View File

@@ -64,8 +64,7 @@ public:
void draw(QPainter *painter, const QwtScaleMap &xMap, const QwtScaleMap &yMap,
const QRectF &canvasRect, bool highlight,
const TraceDrawingProperties &drawingProperties) const;
bool isSelected(traceTime time, double yVal,
const TraceDrawingProperties &drawingproperties) const;
bool isSelected(Timespan timespan, double yVal, const TraceDrawingProperties &drawingproperties) const;
const Timespan &Span() const
{
return span;

View File

@@ -42,6 +42,11 @@ bool Timespan::contains(traceTime time) const
return (begin <= time && time <= end);
}
bool Timespan::overlaps(const Timespan &other) const
{
return other.Begin() < this->end && this->begin < other.End();
}
void Timespan::shift(traceTime offset)
{
begin += offset;

View File

@@ -73,6 +73,7 @@ public:
end = time;
}
bool contains(traceTime time) const;
bool overlaps(const Timespan &other) const;
void shift(traceTime offset);
};

View File

@@ -60,16 +60,13 @@ void Transaction::draw(QPainter *painter, const QwtScaleMap &xMap,
phase->draw(painter, xMap, yMap, canvasRect, highlight, drawingProperties);
}
bool Transaction::isSelected(traceTime time, double yVal,
const TraceDrawingProperties &drawingproperties) const
bool Transaction::isSelected(Timespan timespan, double yVal, const TraceDrawingProperties &drawingproperties) const
{
// Increase selectable area of transactions for phases with zero span
traceTime offset = static_cast<traceTime>(0.05 * clk);
if (span.Begin() <= time && time <= (span.End() + offset))
if (span.overlaps(timespan))
{
for (shared_ptr<Phase> phase : phases) {
if (phase->isSelected(time, yVal, drawingproperties))
for (shared_ptr<Phase> phase : phases)
{
if (phase->isSelected(timespan, yVal, drawingproperties))
return true;
}
}

View File

@@ -68,8 +68,7 @@ public:
const TraceDrawingProperties &drawingProperties) const;
void addPhase(std::shared_ptr<Phase> phase);
bool isSelected(traceTime time, double yVal,
const TraceDrawingProperties &drawingproperties) const;
bool isSelected(Timespan timespan, double yVal, const TraceDrawingProperties &drawingproperties) const;
const std::vector<std::shared_ptr<Phase>> &Phases() const
{

View File

@@ -723,12 +723,15 @@ bool TracePlot::eventFilter(QObject *object, QEvent *event)
void TracePlot::SelectTransaction(int x, int y) const
{
double yVal = invTransform(yLeft, y);
traceTime time = invTransform(xBottom, x);
vector<shared_ptr<Transaction>> selectedTransactions =
tracePlotItem->getSelectedTransactions(time, yVal);
if (selectedTransactions.size() > 0) {
Timespan timespan = hoveredTimespan(x);
auto selectedTransactions = tracePlotItem->getSelectedTransactions(timespan, yVal);
if (selectedTransactions.size() > 0)
{
if (!keyPressData.ctrlPressed)
navigator->clearSelectedTransactions();
navigator->addSelectedTransactions(selectedTransactions);
}
}
@@ -750,7 +753,7 @@ void TracePlot::SelectComment(int x) const
Timespan TracePlot::hoveredTimespan(int x) const
{
traceTime time = invTransform(xBottom, x);
traceTime offset = 0.01 * zoomLevel;
traceTime offset = 0.005 * zoomLevel;
return Timespan(time - offset, time + offset);
}

View File

@@ -60,13 +60,13 @@ void TracePlotItem::draw(QPainter *painter, const QwtScaleMap &xMap,
}
}
vector<shared_ptr<Transaction>> TracePlotItem::getSelectedTransactions(
traceTime time, double yVal)
vector<shared_ptr<Transaction>> TracePlotItem::getSelectedTransactions(Timespan timespan, double yVal)
{
vector<shared_ptr<Transaction>> result;
for (const auto &transaction : transactions) {
if (transaction->isSelected(time, yVal, drawingProperties))
for (const auto &transaction : transactions)
{
if (transaction->isSelected(timespan, yVal, drawingProperties))
result.push_back(transaction);
}

View File

@@ -65,9 +65,7 @@ public:
virtual int rtti() const;
virtual void draw(QPainter *painter, const QwtScaleMap &xMap,
const QwtScaleMap &yMap, const QRectF &canvasRect) const;
std::vector<std::shared_ptr<Transaction>> getSelectedTransactions(
traceTime time, double yVal);
std::vector<std::shared_ptr<Transaction>> getSelectedTransactions(Timespan timespan, double yVal);
};
#endif // TRACEPLOTITEM_H