SimCenterCommon
Common functionality used within different SimCenter projects
SimFigure Class Reference

#include <simfigure.h>

Inheritance diagram for SimFigure:
Collaboration diagram for SimFigure:

Public Types

enum  AxisType { AxisType::Default, AxisType::LogX, AxisType::LogY, AxisType::LogLog }
 The AxisType enum. More...
 
enum  LineType {
  LineType::None, LineType::Solid, LineType::Dotted, LineType::Dashed,
  LineType::DashDotted
}
 The LineType enum. More...
 
enum  Marker {
  Marker::None, Marker::Asterisk, Marker::Circle, Marker::Plus,
  Marker::Triangle, Marker::DownTriangle, Marker::RightTriangle, Marker::LeftTriangle,
  Marker::Box, Marker::Ex
}
 The Marker enum. More...
 
enum  Location {
  Location::Bottom, Location::Top, Location::Left, Location::Right,
  Location::TopLeft, Location::TopRight, Location::BottomLeft, Location::BottomRight,
  Location::North, Location::South, Location::East, Location::West,
  Location::NorthWest, Location::NorthEast, Location::SouthWest, Location::SouthEast
}
 The Location enum. More...
 
enum  FileType {
  FileType::PNG, FileType::BMP, FileType::PDF, FileType::PS,
  FileType::SVG
}
 The FileType enum. More...
 

Public Slots

void on_picker_activated (bool on)
 
void on_picker_selected (const QPolygon &polygon)
 
void on_picker_appended (const QPoint &pos)
 
void on_picker_moved (const QPoint &pos)
 
void on_picker_removed (const QPoint &pos)
 
void on_picker_changed (const QPolygon &selection)
 
void showAxisControls (bool show)
 
void fit_data ()
 

Signals

void curve_selected (int ID)
 

Public Member Functions

 SimFigure (QWidget *parent=nullptr)
 
 ~SimFigure ()
 
int plot (QVector< double > &, QVector< double > &, LineType lt=LineType::Solid, QColor col=Qt::red, Marker mk=Marker::None)
 
int scatter (QVector< double > &, QVector< double > &, QColor col=Qt::blue, Marker mk=Marker::Circle)
 
void clear (void)
 
void cla (void)
 
void grid (bool mayor=true, bool minor=true)
 
void legend (QList< QString > labels, Location loc=Location::South)
 
void moveLegend (Location loc)
 
void showLegend (bool=true)
 
bool legendVisible (void)
 
void select (int)
 
void clearSelection (void)
 
SimFigure::AxisType axisType (void)
 
void setAxisType (AxisType type)
 
QString xLabel ()
 SimFigure::xLabel() More...
 
QString yLabel ()
 SimFigure::yLabel() More...
 
int labelFontSize ()
 returns the current font size used for xLabel() and yLabel() More...
 
QString title ()
 SimFigure::title() More...
 
int titleFontSize ()
 returns the current font size used for title() More...
 
void setXLabel (QString lbl)
 
void setYLabel (QString lbl)
 
void setXLim (double xmin, double xmax)
 Sets x-axis limits to given values. xmax must be larger than xmin. More...
 
void setYLim (double ymin, double ymax)
 Sets y-axis limits to given values. ymax must be larger than ymin. More...
 
void setXlimits (double xmin, double xmax)
 alias for setXLim(xmin,xmax) More...
 
void setYlimits (double ymin, double ymax)
 alias for setYLim(ymin,ymax) More...
 
void setLabelFontSize (int)
 sets the current font size used for xLabel() and yLabel() to sz More...
 
void setTitle (QString title)
 
void setTitleFontSize (int)
 sets the current font size used for title() to sz More...
 
double minX ()
 returns the currently displayed minimum value of x More...
 
double maxX ()
 returns the currently displayed maximum value of x More...
 
double minY ()
 returns the currently displayed minimum value of y More...
 
double maxY ()
 returns the currently displayed maximum value of y More...
 
int lineWidth (int ID)
 
void setLineWidth (int ID, int wd)
 
double lineWidthF (int ID)
 
void setLineWidthF (int ID, double wd)
 
SimFigure::LineType lineStyle (int ID)
 
void setLineStyle (int ID, LineType lt=LineType::Solid, Marker mk=Marker::None)
 
QColor lineColor (int ID)
 
void setLineColor (int ID, QColor color)
 
SimFigure::Marker marker (int ID)
 SimFigure::marker. More...
 
int markerSize (int ID)
 SimFigure::markerSize. More...
 
void setMarker (int ID, Marker mk, int size=10)
 
void saveToFile (QString filename, SimFigure::FileType type=SimFigure::FileType::PNG, QSizeF size=QSizeF(300, 200), int res=85)
 save image to file More...
 
void exportToFile (QString filename, SimFigure::FileType type=SimFigure::FileType::PNG, QSizeF size=QSizeF(300, 200), int res=85)
 save image to file More...
 

Protected Member Functions

void select (QwtPlotItem *)
 
void setLineStyle (QwtPlotCurve *, LineType lt)
 
void setLineColor (QwtPlotCurve *, QColor color)
 
void setMarker (QwtPlotCurve *curve, Marker mk, int size)
 
QwtPlotItem * itemAt (const QPoint &pos) const
 
void rescale (void)
 
void refreshGrid (void)
 

Detailed Description

Definition at line 28 of file simfigure.h.

Member Enumeration Documentation

enum SimFigure::AxisType
strong

The AxisType enum.

used for selecting linear or logarithmic scales on th eX and Y axes.

Enumerator
Default 

linear scales for x and y

LogX 

log scale for x, linear scale for y

LogY 

linear scale for x, log scale for y

LogLog 

log scales for x and y

Definition at line 39 of file simfigure.h.

enum SimFigure::FileType
strong

The FileType enum.

used to define file type in saveToFile() and exportToFile()

Enumerator
PNG 

portable network graphic file

BMP 

MicroSOft bitmap file.

PDF 

portable document format

PS 

PostScript file.

SVG 

scaleable vector graphic file

Definition at line 102 of file simfigure.h.

enum SimFigure::LineType
strong

The LineType enum.

used to define the line type used by plot().

Enumerator
None 

no line is drawn (only markers)

Solid 

a solid line is drawn

Dotted 

a dotted line is drawn

Dashed 

a dashed line is drawn

DashDotted 

a dash-dotted line is drawn

Definition at line 50 of file simfigure.h.

enum SimFigure::Location
strong

The Location enum.

used to define the position of the legend (if visible) on the plot() canvas.

Enumerator
Bottom 

centered horizontally at the bottom

Top 

centered horizontally at the top

Left 

centered vertically on the left

Right 

centered vertically on the right

TopLeft 

top left corner

TopRight 

top right corner

BottomLeft 

bottom left corner

BottomRight 

bottom right corner

North 

equivalent to Top

South 

equivalent to Bottom

East 

equivalent to Right

West 

equivalent to Left

NorthWest 

equivalent to TopLeft

NorthEast 

equivalent to TopRight

SouthWest 

equivalent to BottomLeft

SouthEast 

equivalent to BottomRight

Definition at line 79 of file simfigure.h.

enum SimFigure::Marker
strong

The Marker enum.

used to define the marker used for a particular plot().

Enumerator
None 

no marker (line only)

Asterisk 

Circle 

o

Plus 

+

Triangle 

upright triangle

DownTriangle 

upside-down triangle

RightTriangle 

point to the right triangle

LeftTriangle 

point to the left triangle

Box 

a square box

Ex 

x

Definition at line 62 of file simfigure.h.

Constructor & Destructor Documentation

SimFigure::SimFigure ( QWidget *  parent = nullptr)
explicit

SimFigure is a widget that emulates a MATLAB-like interface to Qwt, allowing for a quick porting of MATLAB graphics to Qt5. Creating an instance of SimFigure is equivalent to MATLAB's

h = figure

Parameters
parentis a pointer to the parent widget simfigure.h "code/simfigure.h"

Definition at line 41 of file simfigure.cpp.

SimFigure::~SimFigure ( )

the SimFIgure destructor

Definition at line 95 of file simfigure.cpp.

Member Function Documentation

SimFigure::AxisType SimFigure::axisType ( void  )

returns the current AxisType

Definition at line 187 of file simfigure.cpp.

void SimFigure::cla ( void  )

clear curent axes – clears the figure but preserves the grid type

Definition at line 494 of file simfigure.cpp.

void SimFigure::clear ( void  )

clear curent axes – clears the figure but preserves the grid type

identical to cla()

Definition at line 488 of file simfigure.cpp.

void SimFigure::clearSelection ( void  )

clear selection of any curve. Upon completion, this function will emit a SIGNAL(curve_selected(int)) with value -1.

Definition at line 850 of file simfigure.cpp.

void SimFigure::curve_selected ( int  ID)
signal
void SimFigure::exportToFile ( QString  filename,
SimFigure::FileType  type = SimFigure::FileType::PNG,
QSizeF  size = QSizeF(300,200),
int  res = 85 
)

save image to file

used to save the plot to an image file. Location and filename are suggestions only. The user will face a QFileDialog to define actual filename and location.

Parameters
filenamespecified via QFileDialog
typedefault is SimFigure::FileType::PNG
sizeQSizeF(width in MM, height in MM). Defaults to 300mm/200mm (~12in/8in)
resresolution: use 75-95 for screen, ~100-150 for presentations, 300 for quality print. Defaults to 85

Definition at line 1181 of file simfigure.cpp.

void SimFigure::fit_data ( )
slot

Definition at line 709 of file simfigure.cpp.

void SimFigure::grid ( bool  major = true,
bool  minor = true 
)

generate a grid with major (true|false) and minor (true|false) grid markers and lines.

grid() turns major and monor grid on

grid( false, false ) turns the grid off

Definition at line 173 of file simfigure.cpp.

QwtPlotItem * SimFigure::itemAt ( const QPoint &  pos) const
protected

returns a pointer to the QwtPlotItem selected by the last mouse click (private)

Definition at line 721 of file simfigure.cpp.

int SimFigure::labelFontSize ( )

returns the current font size used for xLabel() and yLabel()

Definition at line 300 of file simfigure.cpp.

void SimFigure::legend ( QList< QString >  labels,
Location  loc = Location::South 
)

Add a legend to the current plot.

Location is an enum class.

Definition at line 531 of file simfigure.cpp.

bool SimFigure::legendVisible ( void  )

check if legend is currently visible.

Definition at line 619 of file simfigure.cpp.

QColor SimFigure::lineColor ( int  ID)

returns line color of the curve with handle ID.

Definition at line 1093 of file simfigure.cpp.

SimFigure::LineType SimFigure::lineStyle ( int  ID)

returns the line style of a curve.

Definition at line 916 of file simfigure.cpp.

int SimFigure::lineWidth ( int  ID)

return the line width of the curve with handle ID

Definition at line 868 of file simfigure.cpp.

double SimFigure::lineWidthF ( int  ID)

return the line width of the curve with handle ID

Definition at line 881 of file simfigure.cpp.

SimFigure::Marker SimFigure::marker ( int  ID)

SimFigure::marker.

Parameters
ID... unique handle for the curve of interest
Returns
SimFigure::Marker enum to identify the marker for curve with handle=ID

Definition at line 964 of file simfigure.cpp.

int SimFigure::markerSize ( int  ID)

SimFigure::markerSize.

Parameters
ID... unique handle for the curve of interest
Returns
size of the marker in pixels

Definition at line 1003 of file simfigure.cpp.

double SimFigure::maxX ( )
inline

returns the currently displayed maximum value of x

Definition at line 160 of file simfigure.h.

double SimFigure::maxY ( )
inline

returns the currently displayed maximum value of y

Definition at line 168 of file simfigure.h.

double SimFigure::minX ( )
inline

returns the currently displayed minimum value of x

Definition at line 156 of file simfigure.h.

double SimFigure::minY ( )
inline

returns the currently displayed minimum value of y

Definition at line 164 of file simfigure.h.

void SimFigure::moveLegend ( Location  loc)

Move the legend to a new location identified by Location (enum class Location)

Definition at line 543 of file simfigure.cpp.

void SimFigure::on_picker_activated ( bool  on)
slot

DEPRICATED

Definition at line 625 of file simfigure.cpp.

void SimFigure::on_picker_appended ( const QPoint &  pos)
slot

upon mouse click inside the plot canvas, identify the QwtPlotItem most likely selected by that mouse event. There is a 5 pixel tolerance to either side of a curve for which a hit will be detected.

Definition at line 637 of file simfigure.cpp.

void SimFigure::on_picker_changed ( const QPolygon &  selection)
slot

DEPRICATED

Definition at line 697 of file simfigure.cpp.

void SimFigure::on_picker_moved ( const QPoint &  pos)
slot

DEPRICATED

Definition at line 685 of file simfigure.cpp.

void SimFigure::on_picker_removed ( const QPoint &  pos)
slot

DEPRICATED

Definition at line 691 of file simfigure.cpp.

void SimFigure::on_picker_selected ( const QPolygon &  polygon)
slot

DEPRICATED

Definition at line 631 of file simfigure.cpp.

int SimFigure::plot ( QVector< double > &  x,
QVector< double > &  y,
LineType  lt = LineType::Solid,
QColor  color = Qt::red,
Marker  mk = Marker::None 
)

The plot() method provides a plot functionality similar to MATLAP's plot function x and y are regerences to QVector<double>. The must be of equal length.

plot returns an integer serving as a unique handle for the curve. The following functions use that handle to read or change settings for that curve:

lineWidth(), lineWidthF(), setLineWidth(), setLineWidthF(), lineStyle(), setLineStyle(), lineColor(), setLineColor(), setMarker()

Parameters
lta member of the SimFigure::LineType enum
colora QColor object defining the line color. You may also use pre-defined colors like Qt::red, ...
mka member of the SimFigure::Marker enum.

Definition at line 228 of file simfigure.cpp.

void SimFigure::refreshGrid ( void  )
protected

Regenerate th egrid with new settings (Type, limits) - (private)

Definition at line 427 of file simfigure.cpp.

void SimFigure::rescale ( void  )
protected

reinitialize the scale engine for both axes (private)

Definition at line 383 of file simfigure.cpp.

void SimFigure::saveToFile ( QString  filename,
SimFigure::FileType  type = SimFigure::FileType::PNG,
QSizeF  size = QSizeF(300,200),
int  res = 85 
)

save image to file

used to save the plot to an image file. Location and filename are defined from within the code. No user interaction required.

Parameters
filenameincludes fully specified path
typedefault is SimFigure::FileType::PNG
sizeQSizeF(width in MM, height in MM). Defaults to 300mm/200mm (~12in/8in)
resresolution: use 75-95 for screen, ~100-150 for presentations, 300 for quality print. Defaults to 85

Definition at line 1136 of file simfigure.cpp.

int SimFigure::scatter ( QVector< double > &  x,
QVector< double > &  y,
QColor  color = Qt::blue,
Marker  mk = Marker::Circle 
)

The scatter() method provides a plot functionality similar to MATLAP's scatter function x and y are regerences to QVector<double>. The must be of equal length.

scatter returns an integer serving as a unique handle for all points. The following functions use that handle to read or change settings for that curve:

lineWidth(), lineWidthF(), setLineWidth(), setLineWidthF(), lineStyle(), setLineStyle(), lineColor(), setLineColor(), setMarker()

Parameters
colora QColor object defining the line color. You may also use pre-defined colors like Qt::red, ...
mka member of the SimFigure::Marker enum.

Definition at line 275 of file simfigure.cpp.

void SimFigure::select ( int  ID)

select the curve identified by its integer handle ID. Upon completion, this function will emit a SIGNAL(curve_selected(int)) with value = integer handle of that curve.

Definition at line 812 of file simfigure.cpp.

void SimFigure::select ( QwtPlotItem *  item)
protected

select the curve identified by the provided pointer (private). Upon completion, this function will emit a SIGNAL(curve_selected(int)) with value = integer handle of that curve.

Definition at line 824 of file simfigure.cpp.

void SimFigure::setAxisType ( AxisType  type)

set the AxisType for the current grid

Definition at line 194 of file simfigure.cpp.

void SimFigure::setLabelFontSize ( int  sz)

sets the current font size used for xLabel() and yLabel() to sz

Definition at line 318 of file simfigure.cpp.

void SimFigure::setLineColor ( int  ID,
QColor  color 
)

used to change the current color of a curve.

Definition at line 1107 of file simfigure.cpp.

void SimFigure::setLineColor ( QwtPlotCurve *  curve,
QColor  color 
)
protected

used to change the current color of a curve. (private)

Definition at line 1116 of file simfigure.cpp.

void SimFigure::setLineStyle ( int  ID,
LineType  lt = LineType::Solid,
Marker  mk = Marker::None 
)

used to change the current line style of a curve.

Definition at line 922 of file simfigure.cpp.

void SimFigure::setLineStyle ( QwtPlotCurve *  curve,
LineType  lt 
)
protected

used to change the current line style of a curve. (private)

Definition at line 932 of file simfigure.cpp.

void SimFigure::setLineWidth ( int  ID,
int  wd 
)

change the line width of the curve with handle ID

Definition at line 894 of file simfigure.cpp.

void SimFigure::setLineWidthF ( int  ID,
double  wd 
)

change the line width of the curve with handle ID

Definition at line 905 of file simfigure.cpp.

void SimFigure::setMarker ( int  ID,
Marker  mk,
int  size = 10 
)

used to change the current marker of a curve.

Definition at line 1019 of file simfigure.cpp.

void SimFigure::setMarker ( QwtPlotCurve *  curve,
Marker  mk,
int  size 
)
protected

used to change the current marker of a curve. (private)

Definition at line 1028 of file simfigure.cpp.

void SimFigure::setTitle ( QString  title)

set the figure title

Definition at line 377 of file simfigure.cpp.

void SimFigure::setTitleFontSize ( int  sz)

sets the current font size used for title() to sz

Definition at line 337 of file simfigure.cpp.

void SimFigure::setXLabel ( QString  label)

set the title for the x-axis

Definition at line 361 of file simfigure.cpp.

void SimFigure::setXLim ( double  xmin,
double  xmax 
)

Sets x-axis limits to given values. xmax must be larger than xmin.

See maxX() and minX() on how to obtain the current limits.

Definition at line 404 of file simfigure.cpp.

void SimFigure::setXlimits ( double  xmin,
double  xmax 
)
inline

alias for setXLim(xmin,xmax)

Definition at line 145 of file simfigure.h.

void SimFigure::setYLabel ( QString  label)

set the title for the y-axis

Definition at line 369 of file simfigure.cpp.

void SimFigure::setYLim ( double  ymin,
double  ymax 
)

Sets y-axis limits to given values. ymax must be larger than ymin.

See maxY() and minY() on how to obtain the current limits.

Definition at line 417 of file simfigure.cpp.

void SimFigure::setYlimits ( double  ymin,
double  ymax 
)
inline

alias for setYLim(ymin,ymax)

Definition at line 148 of file simfigure.h.

void SimFigure::showAxisControls ( bool  show)
slot

Definition at line 703 of file simfigure.cpp.

void SimFigure::showLegend ( bool  on = true)

show (on=true) or hide (on=false) a legend for the current plots.

Definition at line 597 of file simfigure.cpp.

QString SimFigure::title ( void  )

SimFigure::title()

Returns
title of the current figure

Definition at line 353 of file simfigure.cpp.

int SimFigure::titleFontSize ( )

returns the current font size used for title()

Definition at line 309 of file simfigure.cpp.

QString SimFigure::xLabel ( void  )

SimFigure::xLabel()

Returns
title of the current x-axis label

Definition at line 283 of file simfigure.cpp.

QString SimFigure::yLabel ( void  )

SimFigure::yLabel()

Returns
text of the current y-axis label

Definition at line 292 of file simfigure.cpp.


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