![]() |
SimCenterCommon
Common functionality used within different SimCenter projects
|
#include <simfigure.h>


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) |
Definition at line 28 of file simfigure.h.
|
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.
|
strong |
The FileType enum.
used to define file type in saveToFile() and exportToFile()
| Enumerator | |
|---|---|
| PNG |
portable network graphic file |
| BMP |
MicroSOft bitmap file. |
|
portable document format | |
| PS |
PostScript file. |
| SVG |
scaleable vector graphic file |
Definition at line 102 of file simfigure.h.
|
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.
|
strong |
The Location enum.
used to define the position of the legend (if visible) on the plot() canvas.
Definition at line 79 of file simfigure.h.
|
strong |
The Marker enum.
used to define the marker used for a particular plot().
Definition at line 62 of file simfigure.h.
|
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
| parent | is 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.
| 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.
|
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.
| filename | specified via QFileDialog |
| type | default is SimFigure::FileType::PNG |
| size | QSizeF(width in MM, height in MM). Defaults to 300mm/200mm (~12in/8in) |
| res | resolution: use 75-95 for screen, ~100-150 for presentations, 300 for quality print. Defaults to 85 |
Definition at line 1181 of file simfigure.cpp.
|
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.
|
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.
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 | ) |
| ID | ... unique handle for the curve of interest |
Definition at line 964 of file simfigure.cpp.
| ID | ... unique handle for the curve of interest |
Definition at line 1003 of file simfigure.cpp.
|
inline |
returns the currently displayed maximum value of x
Definition at line 160 of file simfigure.h.
|
inline |
returns the currently displayed maximum value of y
Definition at line 168 of file simfigure.h.
|
inline |
returns the currently displayed minimum value of x
Definition at line 156 of file simfigure.h.
|
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.
|
slot |
DEPRICATED
Definition at line 625 of file simfigure.cpp.
|
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.
|
slot |
DEPRICATED
Definition at line 697 of file simfigure.cpp.
|
slot |
DEPRICATED
Definition at line 685 of file simfigure.cpp.
|
slot |
DEPRICATED
Definition at line 691 of file simfigure.cpp.
|
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()
| lt | a member of the SimFigure::LineType enum |
| color | a QColor object defining the line color. You may also use pre-defined colors like Qt::red, ... |
| mk | a member of the SimFigure::Marker enum. |
Definition at line 228 of file simfigure.cpp.
|
protected |
Regenerate th egrid with new settings (Type, limits) - (private)
Definition at line 427 of file simfigure.cpp.
|
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.
| filename | includes fully specified path |
| type | default is SimFigure::FileType::PNG |
| size | QSizeF(width in MM, height in MM). Defaults to 300mm/200mm (~12in/8in) |
| res | resolution: 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()
| color | a QColor object defining the line color. You may also use pre-defined colors like Qt::red, ... |
| mk | a 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.
|
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.
|
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.
|
protected |
used to change the current line style of a curve. (private)
Definition at line 932 of file simfigure.cpp.
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.
used to change the current marker of a curve.
Definition at line 1019 of file simfigure.cpp.
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.
|
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.
|
inline |
alias for setYLim(ymin,ymax)
Definition at line 148 of file simfigure.h.
|
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 | ) |
| int SimFigure::titleFontSize | ( | ) |
returns the current font size used for title()
Definition at line 309 of file simfigure.cpp.
| QString SimFigure::xLabel | ( | void | ) |
Definition at line 283 of file simfigure.cpp.
| QString SimFigure::yLabel | ( | void | ) |
Definition at line 292 of file simfigure.cpp.