DatabaseGraphWidget Class
(CDP::GraphWidgets::DatabaseGraphWidget)The Database Graph widget allows users to plot values saved to a database. More...
Header: | #include <DatabaseGraphWidget> |
Properties
Public Functions
DatabaseGraphWidget(QWidget *parent = 0) | |
virtual | ~DatabaseGraphWidget() |
QColor | activeCursorColor() const |
QString | cdpLoggerRouting() |
int | currentTimeOffsetMs() const |
const QUrl & | databaseUrl() const |
bool | disconnectOnHide() const |
GraphExportFormat | exportFormat() const |
QString | exportPath() const |
const QColor & | graphBackgroundColorEnd() const |
const QColor & | graphBackgroundColorStart() const |
GraphPlottingMode | graphPlottingMode() const |
QColor | gridPenColorX() const |
QColor | gridPenColorY() const |
Qt::PenStyle | gridPenStyleX() const |
Qt::PenStyle | gridPenStyleY() const |
QColor | hoverCursorColor() const |
bool | isLegendVisible() const |
bool | isYAxisSumColumnEnabled() const |
const QFont & | legendFont() const |
const QColor & | legendTextColor() const |
QString | lineColors() const override |
int | paintIntervalMs() const |
QColor | pausedCursorColor() const |
void | setActiveCursorColor(const QColor &color) |
void | setCdpLoggerRouting(const QString &routing) |
void | setExportFormat(GraphExportFormat format) |
void | setExportPath(const QString &path) |
void | setGraphBackgroundColorEnd(const QColor &color) |
void | setGraphBackgroundColorStart(const QColor &color) |
void | setGraphPlottingMode(GraphPlottingMode mode) |
void | setGridPenColorX(const QColor &color) |
void | setGridPenColorY(const QColor &color) |
void | setGridPenStyleX(Qt::PenStyle style) |
void | setGridPenStyleY(Qt::PenStyle style) |
void | setHoverCursorColor(const QColor &color) |
void | setLegendFont(const QFont &font) |
void | setLegendTextColor(const QColor &color) |
void | setLineColors(const QString &colors) override |
void | setPaintIntervalMs(int interval) |
void | setPausedCursorColor(const QColor &color) |
void | setSignalContentType(SignalContentType type) |
void | setUpdateIntervalMs(uint interval) |
void | setXAxisFont(const QFont &font) |
void | setXAxisMajorTickCount(uint count) |
void | setXAxisMinorTickCount(uint count) |
void | setXAxisPenColor(const QColor &color) |
void | setXAxisTextColor(const QColor &color) |
void | setXAxisTextSelectedColor(const QColor &color) |
void | setYAxisFont(const QFont &font) |
void | setYAxisMajorTickCount(uint count) |
void | setYAxisMinorTickCount(uint count) |
void | setYAxisPenColor(const QColor &color) |
void | setYAxisTextColor(const QColor &color) |
void | setYAxisTextSelectedColor(const QColor &color) |
SignalContentType | signalContentType() const |
const QString & | table() const |
uint | updateIntervalMs() const |
const QString & | xAxisColumn() const |
const QFont & | xAxisFont() const |
qint64 | xAxisIntervalMSecs() const |
uint | xAxisMajorTickCount() const |
uint | xAxisMinorTickCount() const |
QColor | xAxisPenColor() const |
const QColor & | xAxisTextColor() const |
const QColor & | xAxisTextSelectedColor() const |
QStringList | yAxisColumns() const |
const QFont & | yAxisFont() const |
uint | yAxisMajorTickCount() const |
double | yAxisMaxValue() const |
double | yAxisMinValue() const |
uint | yAxisMinorTickCount() const |
QColor | yAxisPenColor() const |
const QColor & | yAxisTextColor() const |
const QColor & | yAxisTextSelectedColor() const |
int | yAxisValueMinPrecision() const |
Public Slots
void | autoScale() |
void | exportData() |
void | hideWidget() |
void | pause() |
void | reconnectToDatabase() |
void | resume() |
void | scaleXAxis() |
void | scaleYAxis() |
void | setCurrentTimeOffsetMs(int offsetMs) |
void | setDatabaseUrl(const QUrl &url) |
void | setDisconnectOnHide(bool enabled) |
void | setInCommand(bool cmd) |
void | setLegendVisible(bool visible) |
void | setPauseEnabled(bool enabled) |
void | setSmoothPixmap(bool smooth) |
void | setTable(const QString &table) |
void | setWidgetFont(const QString &font) |
void | setWidgetStyle(int style) |
void | setWidgetTheme(const QString &theme) |
void | setXAxisColumn(const QString &column) |
void | setXAxisIntervalMSecs(qint64 msecs) |
void | setYAxisColumns(const QStringList &columns) |
void | setYAxisColumns(const ColumnList &columns) |
void | setYAxisMaxValue(double value) |
void | setYAxisMinValue(double value) |
void | setYAxisSumColumnEnabled(bool enabled) |
void | setYAxisValueMinPrecision(int precision) |
void | showWidget() |
Signals
void | connectedChanged(bool status) |
void | connectionStatus(const QString &statusString) |
void | databaseUrlChanged(const QUrl &url) |
void | exportFailed() |
void | exportFinished(bool success) |
void | exportProgressChanged(int progress) |
void | exportStarted() |
void | loadingChanged(bool status) |
void | pauseEnabledChanged(bool enabled) |
void | xAxisRangeReceived() |
Detailed Description
The Database Graph widget allows users to plot values saved to a database.
The widget is able to:
- Connect directly to CDP Logger built-in server.
- Open the database file created by CDP Logger default back-end CDPCompactDatastore (custom format is automatically detected).
- Open any SQLite or MySQL database file. Just select the table and specify which column is x-axis and which is y-axis.
Modes
There are three different plotting modes: standstill, wrapping and scrolling. The first one is meant for analyzing static data. The latter two however are useful when values are dynamically added to the database, for example when connecting to a running CDP Logger.
- Standstill mode: This mode is designed for analyzing static data. When you open the database, all the values will be displayed on the screen, allowing you to zoom in and pan for a closer look.
Note: It is recommended to increase the updateIntervalMs property or set it to zero (which disables it) when using Standstill Mode. This prevents the graph from continuously checking for new data, reducing CPU overhead.
- Wrapping mode: In this mode, the x-axis remains steady while the data is updated in real-time. A moving vertical line, called the beam, sweeps from left to right across the graph, representing the current time. As the beam moves, the values for the current time are updated on the graph. If you pause the graph, the beam will stop at the paused time.
- Scrolling mode: This mode features a moving x-axis, where the current time is always positioned on the right side of the graph. The display shifts continuously, creating a "moving window" effect that shows the most recent data on the right.
Configuring
CDP Logger Database
The preferred way to view logged data is to connect to the built-in server of a running CDP Logger. In case the logger is configured to log to a local database file using CDPCompactDatastore, it is also possible to open the file directly.
First the databaseUrl property must be filled:
Target | databaseUrl example |
---|---|
CDP Logger built-in server | ip://127.0.0.1:17000 |
CDPCompactDatastore database file | file:///directory-path/database-file.db (asbolute path) or file:database-file.db (relative path) |
The hardcoded path in databaseUrl
can be avoided using the optional cdpLoggerRouting
property. Configure it with routing to the CDP Logger component. The IP and port will be retrieved in run-time:
Property | Value |
---|---|
cdpLoggerRouting | Application.CDPLogger |
After that, you must set the y-axis columns to display. The list of available values can be found by looking at the Name column of the LoggedValues table in your CDP Logger configuration.
Property | Value |
---|---|
yAxisColumns | List of values logged by CDP Logger. |
It is not necessary to fill table
and xAxisColumn
properties.
SQL Database
To open a generic database file, you must first specify the databaseUrl property. At the moment SQLite and MySQL database systems are supported.
Examples:
Database system | databaseUrl |
---|---|
SQLite | Path to the database file, e.g. "file:///directory-path/database-file.db" (asbolute path) or "file:database-file.db" (relative path) |
MySQL | The connection string, e.g. "mysql://user:password@127.0.0.1:3306/database-name" |
Next, set the following properties:
Property | Value |
---|---|
table | Name of the database table to plot |
xAxisColumn | Name of the column in the selected table to use as x-axis on the plot |
yAxisColumns | List of columns in the same table that are used for y-axis. |
graphPlottingMode | Set it to Standstill mode unless all of these conditions are met:
|
updateIntervalMs | When in Standstill mode, it is recommended to increase this or set it to zero (which disables it) to avoid unnecessary database queries. |
Selecting Columns Dynamically
An alternative to filling the yAxisColumns
described in the previous section is to use either DB Graph Signal Selector widget or DB Graph Configuration widget. The output of these widgets must be connected to setYAxisColumns() slot. Then it is possible to select during runtime which values to plot.
Property Documentation
activeCursorColor : QColor
Access functions:
QColor | activeCursorColor() const |
void | setActiveCursorColor(const QColor &color) |
cdpLoggerRouting : QString
This property holds routing to CDP Logger component to connect. Will override connection string set in databaseUrl.
Access functions:
QString | cdpLoggerRouting() |
void | setCdpLoggerRouting(const QString &routing) |
See also databaseUrl.
cssFile : const QString
This property holds the css file to style the widget.
currentTimeOffsetMs : int
This property holds the offset to current time.
Affects scrolling and wrapping mode. Useful when database connection has some latency, meaning that data appearing on the graph is "behind" current time.
Access functions:
int | currentTimeOffsetMs() const |
void | setCurrentTimeOffsetMs(int offsetMs) |
databaseUrl : QUrl
This property holds connection string to the database.
Examples:
Target | Connection string |
---|---|
CDP Logger built-in server | ip://127.0.0.1:17000 |
CDPCompactDatastore file | file:///directory-path/log.db |
SQLite database file | file:///directory-path/database-file.db |
MySQL database | mysql://user:password@127.0.0.1:3306/database-name |
Note: Consider using cdpLoggerRouting instead of hardcoded string when connecting to CDP Logger built-in server.
Access functions:
const QUrl & | databaseUrl() const |
void | setDatabaseUrl(const QUrl &url) |
See also cdpLoggerRouting.
disconnectOnHide : bool
This property specifies if we should disconnect and pause the graph while hidden to reduce the CPU usage.
Access functions:
bool | disconnectOnHide() const |
void | setDisconnectOnHide(bool enabled) |
exportFormat : CDP::GraphWidgets::GraphExport::Format
This property specifies the file format used in export data.
- CSV for comma-seperated values to be used by third party tools.
- DB for CDP Compact Datastore that can be opened with Database Graph Widget and CDP Studio Analyze mode.
Access functions:
GraphExportFormat | exportFormat() const |
void | setExportFormat(GraphExportFormat format) |
exportPath : QString
This property holds directory path where the plot data is exported. For each export a new file is created in that directory. If left empty, application directory is used.
Access functions:
QString | exportPath() const |
void | setExportPath(const QString &path) |
graphBackgroundColorEnd : QColor
Graph's plotting area background is drawn as gradient from upper-left to lower-right corner. This is the gradient's ending color.
Access functions:
const QColor & | graphBackgroundColorEnd() const |
void | setGraphBackgroundColorEnd(const QColor &color) |
See also graphBackgroundColorStart.
graphBackgroundColorStart : QColor
Graph's plotting area background is drawn as gradient from upper-left to lower-right corner. This is the gradient's starting color.
Access functions:
const QColor & | graphBackgroundColorStart() const |
void | setGraphBackgroundColorStart(const QColor &color) |
See also graphBackgroundColorEnd.
graphPlottingMode : CDP::GraphWidgets::GraphPlotting::Mode
This property holds the plotting mode.
There are three different plotting modes: standstill, wrapping and scrolling. The first one is meant for analyzing static data. The latter two however are useful when values are dynamically added to the database, for example when connecting to a running CDP Logger.
- Standstill mode: This mode is designed for analyzing static data. When you open the database, all the values will be displayed on the screen, allowing you to zoom in and pan for a closer look.
Note: It is recommended to increase the updateIntervalMs property or set it to zero (which disables it) when using Standstill Mode. This prevents the graph from continuously checking for new data, reducing CPU overhead.
- Wrapping mode: In this mode, the x-axis remains steady while the data is updated in real-time. A moving vertical line, called the beam, sweeps from left to right across the graph, representing the current time. As the beam moves, the values for the current time are updated on the graph. If you pause the graph, the beam will stop at the paused time.
- Scrolling mode: This mode features a moving x-axis, where the current time is always positioned on the right side of the graph. The display shifts continuously, creating a "moving window" effect that shows the most recent data on the right.
Access functions:
GraphPlottingMode | graphPlottingMode() const |
void | setGraphPlottingMode(GraphPlottingMode mode) |
gridPenColorX : QColor
This property holds the color of vertical grid lines.
Access functions:
QColor | gridPenColorX() const |
void | setGridPenColorX(const QColor &color) |
gridPenColorY : QColor
This property holds the color of horizontal grid lines.
Access functions:
QColor | gridPenColorY() const |
void | setGridPenColorY(const QColor &color) |
gridPenStyleX : Qt::PenStyle
This property holds the style of vertical grid lines.
Access functions:
Qt::PenStyle | gridPenStyleX() const |
void | setGridPenStyleX(Qt::PenStyle style) |
gridPenStyleY : Qt::PenStyle
This property holds the style of horizontal grid lines.
Access functions:
Qt::PenStyle | gridPenStyleY() const |
void | setGridPenStyleY(Qt::PenStyle style) |
hoverCursorColor : QColor
Access functions:
QColor | hoverCursorColor() const |
void | setHoverCursorColor(const QColor &color) |
legendFont : QFont
This property holds the font of signal names in legend.
Access functions:
const QFont & | legendFont() const |
void | setLegendFont(const QFont &font) |
legendTextColor : QColor
This property holds the color of signal names in legend.
Access functions:
const QColor & | legendTextColor() const |
void | setLegendTextColor(const QColor &color) |
legendVisible : bool
Access functions:
bool | isLegendVisible() const |
void | setLegendVisible(bool visible) |
lineColors : QString
This property holds the graph data series line colors as a semicolon-separated string.
The line color string could look something like the following, providing colors for the first nine lines: #aed1d9;#f58d69;#fadf89;#cf9bc8;#d0daa5;#f89e83;#94d1ba;#5d6089;#e7ce9a
.
Note: In CDP Studio Design mode, you can manage these colors using a special editor by right-clicking the graph and selecting "Edit Line Colors...".
Access functions:
QString | lineColors() const override |
void | setLineColors(const QString &colors) override |
paintIntervalMs : int
This property specifies how often the graph should get painted. Increase the number to reduce the load on slow hardware. When the x-axis range is large, the graph will update just as smoothly.
Access functions:
int | paintIntervalMs() const |
void | setPaintIntervalMs(int interval) |
pausedCursorColor : QColor
Access functions:
QColor | pausedCursorColor() const |
void | setPausedCursorColor(const QColor &color) |
signalContentType : CDP::GraphWidgets::SignalContent::Type
This property specifies whether to display signal name or full path (when both are available).
Access functions:
SignalContentType | signalContentType() const |
void | setSignalContentType(SignalContentType type) |
table : QString
This property holds the name of the table to plot.
Access functions:
const QString & | table() const |
void | setTable(const QString &table) |
updateIntervalMs : uint
This property specifies how often data is refreshed from the database.
The recommended value is 500 ms or more for scrolling or wrapping graphs to prevent overloading the database but still see real-time updates. For a static graph (graphPlottingMode set to StandStill
) the value can be set to 0 to disable automatic updates or a much larger value when the data is not changing so often.
Access functions:
uint | updateIntervalMs() const |
void | setUpdateIntervalMs(uint interval) |
xAxisColumn : QString
This property holds the column whose values are displayed on the horizontal axis.
Access functions:
const QString & | xAxisColumn() const |
void | setXAxisColumn(const QString &column) |
xAxisFont : QFont
This property holds the font of x-axis labels.
Access functions:
const QFont & | xAxisFont() const |
void | setXAxisFont(const QFont &font) |
xAxisIntervalMSecs : qint64
This property holds the x-axis interval in milliseconds.
Access functions:
qint64 | xAxisIntervalMSecs() const |
void | setXAxisIntervalMSecs(qint64 msecs) |
xAxisMajorTickCount : uint
This property holds the number of x-axis major ticks which determine vertical grid line and labels count.
Note: The count is taken as a hint. The actual number of ticks may be different.
Access functions:
uint | xAxisMajorTickCount() const |
void | setXAxisMajorTickCount(uint count) |
xAxisMinorTickCount : uint
This property holds the number of ticks between x-axis major ticks (both edges included).
Note: The count is taken as a hint. The actual number of ticks may be different.
Access functions:
uint | xAxisMinorTickCount() const |
void | setXAxisMinorTickCount(uint count) |
See also xAxisMajorTickCount.
xAxisPenColor : QColor
This property holds the color of x-axis line and ticks.
Access functions:
QColor | xAxisPenColor() const |
void | setXAxisPenColor(const QColor &color) |
xAxisTextColor : QColor
This property holds the color of x-axis label text.
Access functions:
const QColor & | xAxisTextColor() const |
void | setXAxisTextColor(const QColor &color) |
xAxisTextSelectedColor : QColor
This property holds the color of x-axis label text when the axis is selected.
Access functions:
const QColor & | xAxisTextSelectedColor() const |
void | setXAxisTextSelectedColor(const QColor &color) |
yAxisColumns : QStringList
This property holds the list of column names for the y-axis.
Access functions:
QStringList | yAxisColumns() const |
void | setYAxisColumns(const QStringList &columns) |
void | setYAxisColumns(const ColumnList &columns) |
yAxisFont : QFont
This property holds the font of y-axis labels.
Access functions:
const QFont & | yAxisFont() const |
void | setYAxisFont(const QFont &font) |
yAxisMajorTickCount : uint
This property holds the number of y-axis major ticks, which determine vertical grid line and labels count.
Note: The count is taken as a hint. The actual number of ticks may be different.
Access functions:
uint | yAxisMajorTickCount() const |
void | setYAxisMajorTickCount(uint count) |
yAxisMaxValue : double
This property holds the y-axis maximum value.
Access functions:
double | yAxisMaxValue() const |
void | setYAxisMaxValue(double value) |
yAxisMinValue : double
This property holds the y-axis minimum value.
Access functions:
double | yAxisMinValue() const |
void | setYAxisMinValue(double value) |
yAxisMinorTickCount : uint
This property holds the number of ticks between y-axis major ticks (both edges included).
Note: The count is taken as a hint. The actual number of ticks may be different.
Access functions:
uint | yAxisMinorTickCount() const |
void | setYAxisMinorTickCount(uint count) |
See also yAxisMajorTickCount.
yAxisPenColor : QColor
This property holds the color of y-axis line and ticks.
Access functions:
QColor | yAxisPenColor() const |
void | setYAxisPenColor(const QColor &color) |
yAxisSumColumnEnabled : bool
This property holds whether to display an additional line that is the sum of all other plotted values.
Access functions:
bool | isYAxisSumColumnEnabled() const |
void | setYAxisSumColumnEnabled(bool enabled) |
yAxisTextColor : QColor
This property holds the color of y-axis label text.
Access functions:
const QColor & | yAxisTextColor() const |
void | setYAxisTextColor(const QColor &color) |
yAxisTextSelectedColor : QColor
This property holds the color of y-axis label text when the axis is selected.
Access functions:
const QColor & | yAxisTextSelectedColor() const |
void | setYAxisTextSelectedColor(const QColor &color) |
yAxisValueMinPrecision : int
This property holds the minimum precision for y-axis value labels.
Access functions:
int | yAxisValueMinPrecision() const |
void | setYAxisValueMinPrecision(int precision) |
Member Function Documentation
DatabaseGraphWidget::DatabaseGraphWidget(QWidget *parent = 0)
Constructs an instance of DatabaseGraphWidget with parent
[virtual]
DatabaseGraphWidget::~DatabaseGraphWidget()
Destroys the instance of DatabaseGraphWidget. The destructor is virtual.
[slot]
void DatabaseGraphWidget::autoScale()
Fits signals data into the plotting area. Functionality is dependant on axis selection.
[signal]
void DatabaseGraphWidget::connectedChanged(bool status)
Emitted when connection to database status is changed. Argument status is true
if connection was established and false
if connection was lost.
[signal]
void DatabaseGraphWidget::connectionStatus(const QString &statusString)
Emitted when connection to database status is changed. Argument statusString is the name of the new status.
[signal]
void DatabaseGraphWidget::databaseUrlChanged(const QUrl &url)
Emitted when database url is changed. Argument url is the name of the new url.
[slot]
void DatabaseGraphWidget::exportData()
Exports visible data to CSV file. See exportDir for location of files.
[signal]
void DatabaseGraphWidget::exportFailed()
Emitted when export has failed.
[signal]
void DatabaseGraphWidget::exportFinished(bool success)
Emitted when export is finished. Argument success is True when export succeeds, otherwise false.
[signal]
void DatabaseGraphWidget::exportProgressChanged(int progress)
Emitted when export progress is changed. Argument progress value ranges between 0 and 100.
[signal]
void DatabaseGraphWidget::exportStarted()
Emitted when export is started.
[slot]
void DatabaseGraphWidget::hideWidget()
[signal]
void DatabaseGraphWidget::loadingChanged(bool status)
Emitted when loading status is changed. Argument status is true
if any database queries are loading.
[slot]
void DatabaseGraphWidget::pause()
Enables pause. This convenience function is equivalent to calling setPauseEnabled(true)
.
See also setPauseEnabled() and resume().
[signal]
void DatabaseGraphWidget::pauseEnabledChanged(bool enabled)
Emitted when widget is paused or resumed. Argument enabled is true
if widget has been paused.
[slot]
void DatabaseGraphWidget::reconnectToDatabase()
Tries to reconnects if connection to database has been lost.
[slot]
void DatabaseGraphWidget::resume()
Disables pause. This convenience function is equivalent to calling setPauseEnabled(false)
.
See also setPauseEnabled() and pause().
[slot]
void DatabaseGraphWidget::scaleXAxis()
Scales the x-axis to fit signal data into the plotting area.
[slot]
void DatabaseGraphWidget::scaleYAxis()
Scales the y-axis to fit signal data into the plotting area.
[slot]
void DatabaseGraphWidget::setInCommand(bool cmd)
void DatabaseGraphWidget::setLineColors(const QString &colors)
Sets the line colors as a semicolon-separated string.
Note: Setter function for property lineColors.
See also lineColors().
[slot]
void DatabaseGraphWidget::setPauseEnabled(bool enabled)
Enables pause if enabled is true. Otherwise disables pause. When pause is enabled, y-axis range and plots are not updated.
See also pause() and resume().
[slot]
void DatabaseGraphWidget::setSmoothPixmap(bool smooth)
[slot]
void DatabaseGraphWidget::setWidgetFont(const QString &font)
[slot]
void DatabaseGraphWidget::setWidgetStyle(int style)
[slot]
void DatabaseGraphWidget::setWidgetTheme(const QString &theme)
[slot]
void DatabaseGraphWidget::showWidget()
[signal]
void DatabaseGraphWidget::xAxisRangeReceived()
Emitted after database initial connection is made and the x-axis range of plotted columns is received. This signal can be connected to the autoScale() slot to make sure data fits into the plotting area.
See also autoScale(), scaleXAxis(), and scaleYAxis().
Get started with CDP Studio today
Let us help you take your great ideas and turn them into the products your customer will love.