PulseView  unreleased development snapshot
A Qt-based sigrok GUI
pv::views::trace::Ruler Class Reference

#include <ruler.hpp>

Inheritance diagram for pv::views::trace::Ruler:
Collaboration diagram for pv::views::trace::Ruler:

Public Member Functions

 Ruler (View &parent)
 
QSize sizeHint () const override
 
QSize extended_size_hint () const override
 
pv::util::Timestamp get_absolute_time_from_x_pos (uint32_t x) const
 
pv::util::Timestamp get_ruler_time_from_x_pos (uint32_t x) const
 
pv::util::Timestamp get_ruler_time_from_absolute_time (const pv::util::Timestamp &abs_time) const
 
pv::util::Timestamp get_absolute_time_from_ruler_time (const pv::util::Timestamp &ruler_time) const
 
shared_ptr< TimeItemget_reference_item () const
 
- Public Member Functions inherited from pv::views::trace::MarginWidget
 MarginWidget (View &parent)
 

Static Public Member Functions

static QString format_time_with_distance (const pv::util::Timestamp &distance, const pv::util::Timestamp &t, pv::util::SIPrefix prefix=pv::util::SIPrefix::unspecified, pv::util::TimeUnit unit=pv::util::TimeUnit::Time, unsigned precision=0, bool sign=true)
 

Protected Member Functions

virtual void contextMenuEvent (QContextMenuEvent *event) override
 
void resizeEvent (QResizeEvent *) override
 
virtual void item_hover (const shared_ptr< ViewItem > &item, QPoint pos) override
 
- Protected Member Functions inherited from pv::views::trace::MarginWidget
virtual void item_clicked (const shared_ptr< ViewItem > &item)
 
void show_popup (const shared_ptr< ViewItem > &item)
 
- Protected Member Functions inherited from pv::views::trace::ViewWidget
 ViewWidget (View &parent)
 
bool accept_drag () const
 
bool mouse_down () const
 
void drag_items (const QPoint &delta)
 
virtual void drag ()
 
virtual void drag_by (const QPoint &delta)
 
virtual void drag_release ()
 
void mouse_left_press_event (QMouseEvent *event)
 
void mouse_left_release_event (QMouseEvent *event)
 
virtual bool touch_event (QTouchEvent *event)
 
bool event (QEvent *event)
 
void mousePressEvent (QMouseEvent *event)
 
void mouseReleaseEvent (QMouseEvent *event)
 
void mouseMoveEvent (QMouseEvent *event)
 
void keyPressEvent (QKeyEvent *event)
 
void keyReleaseEvent (QKeyEvent *event)
 
void leaveEvent (QEvent *event)
 

Private Slots

void on_hover_point_changed (const QWidget *widget, const QPoint &hp)
 
void invalidate_tick_position_cache ()
 
void on_createMarker ()
 
void on_setZeroPosition ()
 
void on_resetZeroPosition ()
 
void on_toggleHoverMarker ()
 

Private Member Functions

vector< shared_ptr< ViewItem > > items () override
 
shared_ptr< ViewItemget_mouse_over_item (const QPoint &pt) override
 
void mouseDoubleClickEvent (QMouseEvent *event) override
 
void paintEvent (QPaintEvent *event) override
 
void draw_hover_mark (QPainter &p, int text_height)
 
int calculate_text_height () const
 

Static Private Member Functions

static TickPositions calculate_tick_positions (const pv::util::Timestamp &major_period, const pv::util::Timestamp &offset, const double scale, const int width, const unsigned int minor_tick_count, function< QString(const pv::util::Timestamp &)> format_function)
 

Private Attributes

boost::optional< TickPositionstick_position_cache_
 
shared_ptr< TimeItemhover_item_
 
uint32_t context_menu_x_pos_
 

Static Private Attributes

static const float RulerHeight = 2.5f
 Height of the ruler in multipes of the text height. More...
 
static const float HoverArrowSize = 0.5f
 Height of the hover arrow in multiples of the text height. More...
 

Friends

struct RulerTest::tick_position_test_0
 
struct RulerTest::tick_position_test_1
 
struct RulerTest::tick_position_test_2
 

Additional Inherited Members

- Public Slots inherited from pv::views::trace::ViewWidget
void clear_selection ()
 
- Signals inherited from pv::views::trace::ViewWidget
void selection_changed ()
 
- Protected Slots inherited from pv::views::trace::MarginWidget
virtual void keyPressEvent (QKeyEvent *event)
 
virtual void on_popup_closed ()
 
- Protected Attributes inherited from pv::views::trace::ViewWidget
pv::views::trace::Viewview_
 
QPoint mouse_point_
 
QPoint mouse_down_point_
 
pv::util::Timestamp mouse_down_offset_
 
shared_ptr< ViewItemmouse_down_item_
 
Qt::KeyboardModifiers mouse_modifiers_
 Keyboard modifiers that were active when mouse was last moved or clicked. More...
 
bool item_dragging_
 

Detailed Description

The Ruler class manages and displays the time scale above the trace canvas. It may also contain TimeItem instances used to identify or highlight time-related information.

Definition at line 60 of file ruler.hpp.

Constructor & Destructor Documentation

pv::views::trace::Ruler::Ruler ( View parent)

Definition at line 47 of file ruler.cpp.

Here is the call graph for this function:

Member Function Documentation

int pv::views::trace::Ruler::calculate_text_height ( ) const
private

Definition at line 344 of file ruler.cpp.

Here is the caller graph for this function:

TickPositions pv::views::trace::Ruler::calculate_tick_positions ( const pv::util::Timestamp major_period,
const pv::util::Timestamp offset,
const double  scale,
const int  width,
const unsigned int  minor_tick_count,
function< QString(const pv::util::Timestamp &)>  format_function 
)
staticprivate

Calculates the major and minor tick positions.

Parameters
major_periodThe period between the major ticks.
offsetThe virtual time at the left border of the ruler.
scaleThe scale in seconds per pixel.
widththe Width of the ruler.
format_functionA function used to format the major tick times.
Returns
An object of type 'TickPositions' that contains the major tick positions together with the labels at that ticks, and the minor tick positions.

Definition at line 349 of file ruler.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

void pv::views::trace::Ruler::contextMenuEvent ( QContextMenuEvent *  event)
overrideprotectedvirtual

Reimplemented from pv::views::trace::MarginWidget.

Definition at line 141 of file ruler.cpp.

Here is the call graph for this function:

void pv::views::trace::Ruler::draw_hover_mark ( QPainter &  p,
int  text_height 
)
private

Draw a hover arrow under the cursor position.

Parameters
pThe painter to draw into.
text_heightThe height of a single text ascent.

Definition at line 324 of file ruler.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

QSize pv::views::trace::Ruler::extended_size_hint ( ) const
overridevirtual

The extended area that the header widget would like to be sized to.

Remarks
This area is the area specified by sizeHint, extended by the area to overlap the viewport.

Implements pv::views::trace::MarginWidget.

Definition at line 74 of file ruler.cpp.

Here is the call graph for this function:

QString pv::views::trace::Ruler::format_time_with_distance ( const pv::util::Timestamp distance,
const pv::util::Timestamp t,
pv::util::SIPrefix  prefix = pv::util::SIPrefix::unspecified,
pv::util::TimeUnit  unit = pv::util::TimeUnit::Time,
unsigned  precision = 0,
bool  sign = true 
)
static

Formats a timestamp depending on its distance to another timestamp.

Heuristic function, useful when multiple timestamps should be put side by side. The function procedes in the following order:

Parameters
distanceThe distance between the timestamp to format and an adjacent one.
tThe value to format
prefixThe SI prefix to use.
unitThe representation of the timestamp value.
precisionThe number of digits after the decimal separator.
signWhether or not to add a sign also for positive numbers.
Returns
The formated value.

Definition at line 84 of file ruler.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

pv::util::Timestamp pv::views::trace::Ruler::get_absolute_time_from_ruler_time ( const pv::util::Timestamp ruler_time) const

Definition at line 136 of file ruler.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

pv::util::Timestamp pv::views::trace::Ruler::get_absolute_time_from_x_pos ( uint32_t  x) const

Definition at line 121 of file ruler.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

shared_ptr< ViewItem > pv::views::trace::Ruler::get_mouse_over_item ( const QPoint &  pt)
overrideprivatevirtual

Gets the first view item which has a label that contains pt .

Parameters
ptthe point to search with.
Returns
the view item that has been found, or and empty shared_ptr if no item was found.

Implements pv::views::trace::ViewWidget.

Definition at line 232 of file ruler.cpp.

Here is the call graph for this function:

shared_ptr< TimeItem > pv::views::trace::Ruler::get_reference_item ( ) const

Definition at line 201 of file ruler.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

pv::util::Timestamp pv::views::trace::Ruler::get_ruler_time_from_absolute_time ( const pv::util::Timestamp abs_time) const

Definition at line 131 of file ruler.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

pv::util::Timestamp pv::views::trace::Ruler::get_ruler_time_from_x_pos ( uint32_t  x) const

Definition at line 126 of file ruler.cpp.

Here is the call graph for this function:

void pv::views::trace::Ruler::invalidate_tick_position_cache ( )
privateslot

Definition at line 395 of file ruler.cpp.

Here is the caller graph for this function:

void pv::views::trace::Ruler::item_hover ( const shared_ptr< ViewItem > &  item,
QPoint  pos 
)
overrideprotectedvirtual

Indicates when a view item is being hovered over.

Parameters
itemThe item that is being hovered over, or nullptr if no view item is being hovered over.
Remarks
the default implementation does nothing.

Reimplemented from pv::views::trace::ViewWidget.

Definition at line 194 of file ruler.cpp.

vector< shared_ptr< ViewItem > > pv::views::trace::Ruler::items ( )
overrideprivatevirtual

Gets the time items.

Implements pv::views::trace::ViewWidget.

Definition at line 187 of file ruler.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

void pv::views::trace::Ruler::mouseDoubleClickEvent ( QMouseEvent *  event)
overrideprivate

Definition at line 243 of file ruler.cpp.

Here is the call graph for this function:

void pv::views::trace::Ruler::on_createMarker ( )
privateslot

Definition at line 400 of file ruler.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

void pv::views::trace::Ruler::on_hover_point_changed ( const QWidget *  widget,
const QPoint &  hp 
)
privateslot

Definition at line 387 of file ruler.cpp.

Here is the caller graph for this function:

void pv::views::trace::Ruler::on_resetZeroPosition ( )
privateslot

Definition at line 410 of file ruler.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

void pv::views::trace::Ruler::on_setZeroPosition ( )
privateslot

Definition at line 405 of file ruler.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

void pv::views::trace::Ruler::on_toggleHoverMarker ( )
privateslot

Definition at line 415 of file ruler.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

void pv::views::trace::Ruler::paintEvent ( QPaintEvent *  event)
overrideprivate

Definition at line 252 of file ruler.cpp.

Here is the call graph for this function:

void pv::views::trace::Ruler::resizeEvent ( QResizeEvent *  )
overrideprotected

Definition at line 181 of file ruler.cpp.

Here is the call graph for this function:

QSize pv::views::trace::Ruler::sizeHint ( ) const
override

Definition at line 68 of file ruler.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

Friends And Related Function Documentation

friend struct RulerTest::tick_position_test_0
friend

Definition at line 64 of file ruler.hpp.

friend struct RulerTest::tick_position_test_1
friend

Definition at line 65 of file ruler.hpp.

friend struct RulerTest::tick_position_test_2
friend

Definition at line 66 of file ruler.hpp.

Member Data Documentation

uint32_t pv::views::trace::Ruler::context_menu_x_pos_
private

Definition at line 199 of file ruler.hpp.

shared_ptr<TimeItem> pv::views::trace::Ruler::hover_item_
private

Definition at line 197 of file ruler.hpp.

const float pv::views::trace::Ruler::HoverArrowSize = 0.5f
staticprivate

Height of the hover arrow in multiples of the text height.

Definition at line 73 of file ruler.hpp.

const float pv::views::trace::Ruler::RulerHeight = 2.5f
staticprivate

Height of the ruler in multipes of the text height.

Definition at line 70 of file ruler.hpp.

boost::optional<TickPositions> pv::views::trace::Ruler::tick_position_cache_
private

Holds the tick positions so that they don't have to be recalculated on every redraw. Set by 'paintEvent()' when needed.

Definition at line 195 of file ruler.hpp.


The documentation for this class was generated from the following files: