DynExp
Highly flexible laboratory automation for dynamically changing experiments.
Util::MarkerGraphicsView Class Reference

Implements a QGraphicsView the user can interact with to insert graphical markers. Furthermore, the graphics view enables zooming into its content. More...

+ Inheritance diagram for Util::MarkerGraphicsView:

Classes

struct  MarkerType
 Data associated with one marker. More...
 

Signals

void mouseClickEvent (QPoint Position)
 

Public Member Functions

 MarkerGraphicsView (QWidget *parent)
 Constructs a MarkerGraphicsView. More...
 
void EnableActions (bool Enable)
 
Getters
auto contextMenu () const noexcept
 
bool HaveMarkersChanged () noexcept
 Returns whether a marker operation has changed the stored markers. Resets the flag. More...
 
const std::vector< MarkerType > & GetMarkers () const noexcept
 
const auto & GetCurrentImagePos () const noexcept
 
Setters
void SetCurrentImagePos (const QPointF &Pos)
 
Marker operations
void AddMarker (const QPoint &MarkerPos, const QColor &Color, bool IsUserDeletable=true, MarkerType::IDType ID=-1, std::string Name={})
 Adds a marker to the graphics view at position MarkerPos assigning the properties passed as arguments. Affects MarkersChanged. More...
 
void RemoveMarker (size_t Index, bool OnlyUserDeletableMarkers=false)
 Removes the n-th marker specified by Index. Affects MarkersChanged. More...
 
void RemoveMarker (const QPoint &MarkerPos, bool OnlyUserDeletableMarkers=false)
 Removes markers at the position MarkerPos. Affects MarkersChanged. More...
 
void RemoveMarker (std::string_view Name, bool OnlyUserDeletableMarkers=false)
 Removes markers with name Name. Affects MarkersChanged. More...
 
void RemoveMarkers (bool OnlyUserDeletableMarkers)
 Removes all markers from the graphics view. Affects MarkersChanged. More...
 
void setMarkersHidden (bool MarkersHidden)
 Hides or shows all markers. More...
 
void RenameMarker (const QPoint &MarkerPos, std::string_view NewName)
 Assigns a name to the marker at position MarkerPos. Affects MarkersChanged. More...
 
void SelectMarker (const QPoint &MarkerPos)
 Selects the marker at position MarkerPos. More...
 
void DeselectMarkers ()
 Deselects all selected markers. More...
 
Zoom operations
void ZoomIn ()
 Zooms in one step. More...
 
void ZoomOut ()
 Zooms out one step. More...
 
void ZoomReset ()
 Resets the zoom. More...
 

Protected Member Functions

virtual void mousePressEvent (QMouseEvent *Event) override
 Adds a marker to the mouse pointer position assigning the highest ID amongst all markers in the graphics view incremented by 1 as the ID. More...
 
virtual void mouseDoubleClickEvent (QMouseEvent *Event) override
 Removes the marker at the mouse pointer position if it is user-deletable. Affects MarkersChanged. More...
 
virtual void wheelEvent (QWheelEvent *Event) override
 Zooms in or out when Control is pressed on the keyboard at the same time. More...
 

Private Slots

void OnContextMenuRequested (QPoint Position)
 Shows the context menu at position Position. More...
 
void OnShowMarkers (bool Checked)
 If Checked is true, all markers are made visible, otherwise they become hidden. More...
 
void OnRemoveMarkers (bool)
 Removes all user-deletable markers. Affects MarkersChanged. More...
 
void OnSaveMarkers (bool)
 Asks the user for a file name and saves all markers to a CSV file. More...
 

Private Attributes

std::vector< MarkerTypeMarkers
 List of the markers. More...
 
bool MarkersHidden
 Determines whether the markers are currently displayed or not. More...
 
bool MarkersChanged
 Holds whether the markers have changed by any of the marker operations. More...
 
QPointF CurrentImagePos
 Sample position where the image has been recorded (in nm). Refer to MarkerType::ImagePos. More...
 
Context menu and associated actions
QMenu * ContextMenu
 
QAction * EditMarkersAction
 
QAction * ShowMarkersAction
 
QAction * RemoveMarkersAction
 
QAction * SaveMarkersAction
 

Static Private Attributes

static constexpr double ZoomFactor = 1.6
 Determines the magnification of one zoom step. More...
 
static constexpr double DeselectedMarkerOpacity = .5
 Determines the opacity of a marker which is not selected. More...
 
static constexpr double SelectedMarkerOpacity = 1
 Determines the opacity of a selected marker. More...
 

Detailed Description

Implements a QGraphicsView the user can interact with to insert graphical markers. Furthermore, the graphics view enables zooming into its content.

Definition at line 378 of file QtUtil.h.

Constructor & Destructor Documentation

◆ MarkerGraphicsView()

Util::MarkerGraphicsView::MarkerGraphicsView ( QWidget *  parent)

Constructs a MarkerGraphicsView.

Parameters
parentParent Qt object owning this item delegate

Definition at line 299 of file QtUtil.cpp.

Member Function Documentation

◆ AddMarker()

void Util::MarkerGraphicsView::AddMarker ( const QPoint &  MarkerPos,
const QColor &  Color,
bool  IsUserDeletable = true,
MarkerType::IDType  ID = -1,
std::string  Name = {} 
)

Adds a marker to the graphics view at position MarkerPos assigning the properties passed as arguments. Affects MarkersChanged.

Parameters
MarkerPosRefer to MarkerType::MarkerPos.
ColorColor of the marker when displayed in the graphics view
IsUserDeletableRefer to MarkerType::UserDeletable.
IDRefer to MarkerType::ID. It is the caller's responsibility to pass a unique ID. The function does not perform a check.
NameRefer to MarkerType::Name.

Definition at line 398 of file QtUtil.cpp.

◆ contextMenu()

auto Util::MarkerGraphicsView::contextMenu ( ) const
inlinenoexcept

Definition at line 446 of file QtUtil.h.

◆ DeselectMarkers()

void Util::MarkerGraphicsView::DeselectMarkers ( )

Deselects all selected markers.

Definition at line 506 of file QtUtil.cpp.

◆ EnableActions()

void Util::MarkerGraphicsView::EnableActions ( bool  Enable)

Definition at line 527 of file QtUtil.cpp.

◆ GetCurrentImagePos()

const auto& Util::MarkerGraphicsView::GetCurrentImagePos ( ) const
inlinenoexcept

Definition at line 449 of file QtUtil.h.

◆ GetMarkers()

const std::vector<MarkerType>& Util::MarkerGraphicsView::GetMarkers ( ) const
inlinenoexcept

Definition at line 448 of file QtUtil.h.

◆ HaveMarkersChanged()

bool Util::MarkerGraphicsView::HaveMarkersChanged ( )
noexcept

Returns whether a marker operation has changed the stored markers. Resets the flag.

Definition at line 390 of file QtUtil.cpp.

◆ mouseClickEvent

void Util::MarkerGraphicsView::mouseClickEvent ( QPoint  Position)
signal

◆ mouseDoubleClickEvent()

void Util::MarkerGraphicsView::mouseDoubleClickEvent ( QMouseEvent *  Event)
overrideprotectedvirtual

Removes the marker at the mouse pointer position if it is user-deletable. Affects MarkersChanged.

Definition at line 340 of file QtUtil.cpp.

◆ mousePressEvent()

void Util::MarkerGraphicsView::mousePressEvent ( QMouseEvent *  Event)
overrideprotectedvirtual

Adds a marker to the mouse pointer position assigning the highest ID amongst all markers in the graphics view incremented by 1 as the ID.

Definition at line 317 of file QtUtil.cpp.

◆ OnContextMenuRequested

void Util::MarkerGraphicsView::OnContextMenuRequested ( QPoint  Position)
privateslot

Shows the context menu at position Position.

Definition at line 535 of file QtUtil.cpp.

◆ OnRemoveMarkers

void Util::MarkerGraphicsView::OnRemoveMarkers ( bool  )
privateslot

Removes all user-deletable markers. Affects MarkersChanged.

Definition at line 545 of file QtUtil.cpp.

◆ OnSaveMarkers

void Util::MarkerGraphicsView::OnSaveMarkers ( bool  )
privateslot

Asks the user for a file name and saves all markers to a CSV file.

Definition at line 550 of file QtUtil.cpp.

◆ OnShowMarkers

void Util::MarkerGraphicsView::OnShowMarkers ( bool  Checked)
privateslot

If Checked is true, all markers are made visible, otherwise they become hidden.

Definition at line 540 of file QtUtil.cpp.

◆ RemoveMarker() [1/3]

void Util::MarkerGraphicsView::RemoveMarker ( const QPoint &  MarkerPos,
bool  OnlyUserDeletableMarkers = false 
)

Removes markers at the position MarkerPos. Affects MarkersChanged.

Parameters
MarkerPosRefer to MarkerType::MarkerPos.
OnlyUserDeletableMarkersIf true, markers are also removed if they are not user-deletable. If false, non-user-deletable markers are not removed.

Definition at line 430 of file QtUtil.cpp.

◆ RemoveMarker() [2/3]

void Util::MarkerGraphicsView::RemoveMarker ( size_t  Index,
bool  OnlyUserDeletableMarkers = false 
)

Removes the n-th marker specified by Index. Affects MarkersChanged.

Parameters
IndexIndex of the marker to remove
OnlyUserDeletableMarkersIf true, the marker is also removed if it is not user-deletable. If false, non-user-deletable markers are not removed.
Exceptions
OutOfRangeExceptionis thrown if Index exceeds the amount of markers stored in the graphics view.

Definition at line 413 of file QtUtil.cpp.

◆ RemoveMarker() [3/3]

void Util::MarkerGraphicsView::RemoveMarker ( std::string_view  Name,
bool  OnlyUserDeletableMarkers = false 
)

Removes markers with name Name. Affects MarkersChanged.

Parameters
NameRefer to MarkerType::Name.
OnlyUserDeletableMarkersIf true, markers are also removed if they are not user-deletable. If false, non-user-deletable markers are not removed.

Definition at line 447 of file QtUtil.cpp.

◆ RemoveMarkers()

void Util::MarkerGraphicsView::RemoveMarkers ( bool  OnlyUserDeletableMarkers)

Removes all markers from the graphics view. Affects MarkersChanged.

Parameters
OnlyUserDeletableMarkersIf true, markers are also removed if they are not user-deletable. If false, non-user-deletable markers are not removed.

Definition at line 464 of file QtUtil.cpp.

◆ RenameMarker()

void Util::MarkerGraphicsView::RenameMarker ( const QPoint &  MarkerPos,
std::string_view  NewName 
)

Assigns a name to the marker at position MarkerPos. Affects MarkersChanged.

Parameters
MarkerPosRefer to MarkerType::MarkerPos.
NewNameName to assign

Definition at line 489 of file QtUtil.cpp.

◆ SelectMarker()

void Util::MarkerGraphicsView::SelectMarker ( const QPoint &  MarkerPos)

Selects the marker at position MarkerPos.

Parameters
MarkerPosRefer to MarkerType::MarkerPos.

Definition at line 500 of file QtUtil.cpp.

◆ SetCurrentImagePos()

void Util::MarkerGraphicsView::SetCurrentImagePos ( const QPointF &  Pos)
inline

Definition at line 455 of file QtUtil.h.

◆ setMarkersHidden()

void Util::MarkerGraphicsView::setMarkersHidden ( bool  MarkersHidden)

Hides or shows all markers.

Parameters
MarkersHiddenIf true, all markers are hidden. If false, all markers become visible.

Definition at line 481 of file QtUtil.cpp.

◆ wheelEvent()

void Util::MarkerGraphicsView::wheelEvent ( QWheelEvent *  Event)
overrideprotectedvirtual

Zooms in or out when Control is pressed on the keyboard at the same time.

Definition at line 377 of file QtUtil.cpp.

◆ ZoomIn()

void Util::MarkerGraphicsView::ZoomIn ( )

Zooms in one step.

Definition at line 512 of file QtUtil.cpp.

◆ ZoomOut()

void Util::MarkerGraphicsView::ZoomOut ( )

Zooms out one step.

Definition at line 517 of file QtUtil.cpp.

◆ ZoomReset()

void Util::MarkerGraphicsView::ZoomReset ( )

Resets the zoom.

Definition at line 522 of file QtUtil.cpp.

Member Data Documentation

◆ ContextMenu

QMenu* Util::MarkerGraphicsView::ContextMenu
private

Definition at line 553 of file QtUtil.h.

◆ CurrentImagePos

QPointF Util::MarkerGraphicsView::CurrentImagePos
private

Sample position where the image has been recorded (in nm). Refer to MarkerType::ImagePos.

Definition at line 548 of file QtUtil.h.

◆ DeselectedMarkerOpacity

constexpr double Util::MarkerGraphicsView::DeselectedMarkerOpacity = .5
staticconstexprprivate

Determines the opacity of a marker which is not selected.

Definition at line 383 of file QtUtil.h.

◆ EditMarkersAction

QAction* Util::MarkerGraphicsView::EditMarkersAction
private

Definition at line 554 of file QtUtil.h.

◆ Markers

std::vector<MarkerType> Util::MarkerGraphicsView::Markers
private

List of the markers.

Definition at line 545 of file QtUtil.h.

◆ MarkersChanged

bool Util::MarkerGraphicsView::MarkersChanged
private

Holds whether the markers have changed by any of the marker operations.

Definition at line 547 of file QtUtil.h.

◆ MarkersHidden

bool Util::MarkerGraphicsView::MarkersHidden
private

Determines whether the markers are currently displayed or not.

Definition at line 546 of file QtUtil.h.

◆ RemoveMarkersAction

QAction* Util::MarkerGraphicsView::RemoveMarkersAction
private

Definition at line 556 of file QtUtil.h.

◆ SaveMarkersAction

QAction* Util::MarkerGraphicsView::SaveMarkersAction
private

Definition at line 557 of file QtUtil.h.

◆ SelectedMarkerOpacity

constexpr double Util::MarkerGraphicsView::SelectedMarkerOpacity = 1
staticconstexprprivate

Determines the opacity of a selected marker.

Definition at line 384 of file QtUtil.h.

◆ ShowMarkersAction

QAction* Util::MarkerGraphicsView::ShowMarkersAction
private

Definition at line 555 of file QtUtil.h.

◆ ZoomFactor

constexpr double Util::MarkerGraphicsView::ZoomFactor = 1.6
staticconstexprprivate

Determines the magnification of one zoom step.

Definition at line 382 of file QtUtil.h.


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