GobChartsWidget
1.0
|
#include <gobchartsview.h>
Public Slots | |
void | setLabelDetails (GobChartsLabel label, const QString &text, const QFont &font, const QColor &colour, Qt::Alignment align) |
Set chart label. | |
void | requestLabelDetails (GobChartsLabel label) |
Request a specific label's settings. | |
void | setGridLineStyle (Qt::PenStyle style) |
Grid line style. | |
void | setHorizontalGridLines (bool set, int number) |
Set horizontal grid lines. | |
void | setVerticalGridLines (bool set, int number) |
Set horizontal grid lines. | |
void | setGridColour (QColor colour) |
Set grid colour. | |
void | setFixedColour (QColor colour) |
Fix the chart colour. | |
void | setRandomColours () |
Use different colours. | |
void | setAllowedDataRange (qreal lowerBoundary, qreal upperBoundary) |
Limit data range. | |
void | setShowTotalRange () |
Show total data range. | |
void | setDebugLoggingOn (bool logging) |
Debug log. | |
Signals | |
void | lastDebugLogMsg (QString) |
Debug messages. | |
void | emitLabelDetails (GobChartsLabel label, const QString &text, const QFont &font, const QColor &colour, Qt::Alignment align) |
Obtain label details. | |
void | createLegendItem (const QColor &colour, const QString &text) |
Emitted when a new graphics item was created. | |
void | clearLegend () |
Emitted when a chart is redrawn and its graphics items are reset. | |
void | highLightLegendItem (const QString &text) |
Emitted when a graphics item is selected. | |
Public Member Functions | |
virtual | ~GobChartsView () |
Constructor. | |
void | drawChart () |
Displays the chosen chart type. | |
void | legendItemSelected (const QString &text) |
Informs the view that a legend of name "text" has been selected. | |
void | setStateXML (const QDomNode &viewNode, const QDomNode &dataNode, bool includeData=true) |
Set the chart values when loading from file. | |
QString | getStateXML (bool includeData=true) const |
Returns the chart content and settings as an XML QString. | |
QRect | visualRect (const QModelIndex &index) const |
Re-implemented from QAbstractItemView. | |
QModelIndex | indexAt (const QPoint &point) const |
Re-implemented from QAbstractItemView. | |
void | scrollTo (const QModelIndex &index, ScrollHint hint=EnsureVisible) |
Re-implemented from QAbstractItemView. | |
void | setModel (QAbstractItemModel *model) |
Re-implemented from QAbstractItemView. | |
Protected Types | |
enum | GobChartsColumn { CATEGORY, VALUE } |
Expected data model columns. More... | |
Protected Slots | |
void | debugLog (QString msg) |
Log debug messages. | |
void | dataChanged (const QModelIndex &topLeft, const QModelIndex &bottomRight) |
Re-implemented from QAbstractItemView. | |
void | rowsInserted (const QModelIndex &parent, int start, int end) |
Re-implemented from QAbstractItemView. | |
void | rowsAboutToBeRemoved (const QModelIndex &parent, int start, int end) |
Re-implemented from QAbstractItemView. | |
void | mousePressEvent (QMouseEvent *p_event) |
Re-implemented from QAbstractItemView. | |
Protected Member Functions | |
GobChartsView (QWidget *parent=0) | |
Destructor. | |
virtual void | generateGraphicsItems ()=0 |
Derived classes must implement this function. | |
virtual bool | needsGrid () const =0 |
Derived classes must implement this function. | |
virtual QString | typeInteger () const =0 |
Derived classes must implement this function. | |
bool | useFixedColour () const |
Returns "true" if the chart colour is fixed or "false" if random colours must be generated. | |
QColor | fixedColour () const |
If the chart colour is fixed, this function returns the colour used to draw the chart items. | |
void | addToGraphItemsContainer (const QModelIndex &valueIndex, QGraphicsItem *item, const QString &legendText) |
Stores dynamically created graphics items. | |
int | nrValidItems () const |
Returns the number of valid rows in the data model. | |
QList< int > | validRowList () const |
Returns a list of valid data row numbers. | |
QString | category (int row) const |
Returns the category name corresponding to "row" in validRowList() | |
qreal | value (int row) const |
Returns the data value corresponding to "row" in validRowList() | |
const QRectF & | innerSceneRectF () const |
Returns the rectangle corresponding to the "inner scene". | |
bool | isWithinAllowedRange (qreal value) const |
Determines whether or not a data value falls within the allowed data range. | |
qreal | gridWidth () const |
Returns the grid width. | |
qreal | stripSpace (qreal perc) const |
Calculates the amount of space at the top of the view that is "extra". | |
qreal | totalValue () const |
Returns the total, consolidated value of all category values. | |
QModelIndex | moveCursor (QAbstractItemView::CursorAction cursorAction, Qt::KeyboardModifiers modifiers) |
Re-implemented from QAbstractItemView. | |
QRegion | visualRegionForSelection (const QItemSelection &selection) const |
Re-implemented from QAbstractItemView. | |
int | horizontalOffset () const |
Re-implemented from QAbstractItemView. | |
int | verticalOffset () const |
Re-implemented from QAbstractItemView. | |
bool | isIndexHidden (const QModelIndex &index) const |
Re-implemented from QAbstractItemView. | |
void | setSelection (const QRect &rect, QItemSelectionModel::SelectionFlags command) |
Re-implemented from QAbstractItemView. | |
void | keyPressEvent (QKeyEvent *event) |
Re-implemented from QAbstractItemView. | |
Friends | |
class | GobChartsViewPrivate |
The PIMPL idiom will help with future binary compatibility. | |
Derived classes must implement the following pure virtual functions:
Definition at line 60 of file gobchartsview.h.
|
protected |
Expected data model columns.
GobChartsWidget is only capable of displaying one to one mappings between categories and data values and expects the first column of the data model to contain the chart's category names and the second the corresponding data values.
Definition at line 193 of file gobchartsview.h.
|
virtual |
Constructor.
Public virtual constructor so that we may delete "new"-ed derived objects from pointer-to-base. GobChartsFactory and the underlying strategy pattern depend on this for run-time type polymorphism.
Definition at line 356 of file gobchartsview.cpp.
|
protected |
Stores dynamically created graphics items.
This function adds newly created graphics items to a map so that they can be retrieved based on their corresponding model indices later on.
valueIndex | - the QModelIndex that the graphics item represents. |
item | - the newly created graphics item. |
Definition at line 705 of file gobchartsview.cpp.
|
protected |
Returns the category name corresponding to "row" in validRowList()
Definition at line 733 of file gobchartsview.cpp.
|
signal |
Emitted when a chart is redrawn and its graphics items are reset.
|
signal |
Emitted when a new graphics item was created.
This signal is emitted shortly after a graphics item is created and contains the details for the corresponding legend item.
|
protectedslot |
Re-implemented from QAbstractItemView.
See the Qt API documentation for details.
Definition at line 778 of file gobchartsview.cpp.
|
protectedslot |
Log debug messages.
This slot receives logging information from privately owned objects.
Definition at line 761 of file gobchartsview.cpp.
void GobChartsView::drawChart | ( | ) |
Displays the chosen chart type.
Generates and displays the chart within the confines of the QGraphicsView which contains it.
Definition at line 434 of file gobchartsview.cpp.
|
signal |
Obtain label details.
This signal is emitted when requestLabelDetails() is called and contains all the information relevant to the specified label.
|
protected |
If the chart colour is fixed, this function returns the colour used to draw the chart items.
Definition at line 657 of file gobchartsview.cpp.
|
protectedpure virtual |
Derived classes must implement this function.
This function must create the graphics items required for the specific chart type and position them within the confines of the view.
Implemented in GobChartsBarView, GobChartsLineView, and GobChartsPieView.
QString GobChartsView::getStateXML | ( | bool | includeData = true | ) | const |
Returns the chart content and settings as an XML QString.
Charts are saved to file as XML, this function takes all the view settings, converts it to XML and returns the XML string.
includeData | - specifies whether or not the chart data must also be saved (if "false", then only the view settings are provided in the XML QString). |
Definition at line 568 of file gobchartsview.cpp.
|
protected |
Returns the grid width.
Within the context of the allowed space, this is the width that the grid may occupy.
Definition at line 712 of file gobchartsview.cpp.
|
signal |
Emitted when a graphics item is selected.
|
protected |
Re-implemented from QAbstractItemView.
See the Qt API documentation for details.
Definition at line 902 of file gobchartsview.cpp.
QModelIndex GobChartsView::indexAt | ( | const QPoint & | point | ) | const |
Re-implemented from QAbstractItemView.
See the Qt API documentation for details.
Definition at line 847 of file gobchartsview.cpp.
|
protected |
Returns the rectangle corresponding to the "inner scene".
The "inner scene" is the rectangle defined as the space within which the chart items must fit. Within the context of the entire view, this means that the space taken up by labels is excluded.
Definition at line 747 of file gobchartsview.cpp.
|
protected |
Re-implemented from QAbstractItemView.
See the Qt API documentation for details.
Definition at line 916 of file gobchartsview.cpp.
|
protected |
Determines whether or not a data value falls within the allowed data range.
Definition at line 691 of file gobchartsview.cpp.
|
protected |
Re-implemented from QAbstractItemView.
See the Qt API documentation for details.
Definition at line 987 of file gobchartsview.cpp.
|
signal |
Debug messages.
This signal broadcasts the last debug log message and will only be emitted when debug logging is turned "on".
void GobChartsView::legendItemSelected | ( | const QString & | text | ) |
Informs the view that a legend of name "text" has been selected.
Definition at line 463 of file gobchartsview.cpp.
|
protectedslot |
Re-implemented from QAbstractItemView.
See the Qt API documentation for details.
Definition at line 979 of file gobchartsview.cpp.
|
protected |
Re-implemented from QAbstractItemView.
See the Qt API documentation for details.
Definition at line 859 of file gobchartsview.cpp.
|
protectedpure virtual |
Derived classes must implement this function.
This function must return "true" when the chart type supports grid lines and "false" otherwise (e.g. PIE charts don't support chart grids whereas BAR charts do).
Implemented in GobChartsBarView, GobChartsLineView, and GobChartsPieView.
|
protected |
Returns the number of valid rows in the data model.
"Valid rows" are rows defined as those containing chart categories or data values and excludes empty rows).
Definition at line 719 of file gobchartsview.cpp.
|
slot |
Request a specific label's settings.
Calling this function will result in the emitLabelDetails() signal being emitted. The signal's parameters contain all the information for the relevant label - text, font, colour and alignment.
label | - the header, x-axis label or y-axis label. |
Definition at line 377 of file gobchartsview.cpp.
|
protectedslot |
Re-implemented from QAbstractItemView.
See the Qt API documentation for details.
Definition at line 801 of file gobchartsview.cpp.
|
protectedslot |
Re-implemented from QAbstractItemView.
See the Qt API documentation for details.
Definition at line 792 of file gobchartsview.cpp.
void GobChartsView::scrollTo | ( | const QModelIndex & | index, |
ScrollHint | hint = EnsureVisible |
||
) |
Re-implemented from QAbstractItemView.
See the Qt API documentation for details.
Definition at line 823 of file gobchartsview.cpp.
|
slot |
Limit data range.
Setting the allowed data range determines which categories will be shown in the final chart (i.e. only those data categories with values within the range will be shown). By default the entire value range is drawn.
lowerBoundary | - the lowest allowed value to be displayed. |
upperBoundary | - the highest allowed value to be displayed. |
Definition at line 673 of file gobchartsview.cpp.
|
slot |
Debug log.
Turn debug logging messages "on" or "off" (default "off").
Definition at line 664 of file gobchartsview.cpp.
|
slot |
Fix the chart colour.
Fix the chart colour to "colour". This means that the different data categories will all be displayed in "colour" as opposed to having randomly generated (different) colours.
Definition at line 624 of file gobchartsview.cpp.
|
slot |
Set grid colour.
Sets the grid line's colour to "colour".
Definition at line 426 of file gobchartsview.cpp.
|
slot |
Grid line style.
Set the pen style used to draw the grid lines.
style | - dashed, dotted, solid, etc. (see Qt API documentation for details on the enum). |
Definition at line 402 of file gobchartsview.cpp.
|
slot |
Set horizontal grid lines.
Turn horizontal grid lines "on" or "off" and also sets the number of grid lines.
Definition at line 410 of file gobchartsview.cpp.
|
slot |
Set chart label.
Sets the text, font, colour and alignment of the label specified.
label | - the header, x-axis label or y-axis label. |
Definition at line 363 of file gobchartsview.cpp.
void GobChartsView::setModel | ( | QAbstractItemModel * | model | ) |
Re-implemented from QAbstractItemView.
See the Qt API documentation for details.
Definition at line 831 of file gobchartsview.cpp.
|
slot |
Use different colours.
Re-enables random colour generation (the default) for chart items after a call to setFixedColour().
Definition at line 642 of file gobchartsview.cpp.
|
protected |
Re-implemented from QAbstractItemView.
See the Qt API documentation for details.
Definition at line 924 of file gobchartsview.cpp.
|
slot |
Show total data range.
Displays all categories (i.e. the entire data value range).
Definition at line 683 of file gobchartsview.cpp.
void GobChartsView::setStateXML | ( | const QDomNode & | viewNode, |
const QDomNode & | dataNode, | ||
bool | includeData = true |
||
) |
Set the chart values when loading from file.
When loading a chart from file, the content of the file is parsed from XML and the QDomNodes containing the necessary information for building the chart is provided to this function as parameters.
viewNode | - the QDomNode containing settings specific to the chart view itself. |
dataNode | - the QDomNode containing the data read from the saved file. |
includeData | - whether or not the dataNode's content must be read (if "false", it will be ignored). |
Definition at line 475 of file gobchartsview.cpp.
|
slot |
Set horizontal grid lines.
Turn vertical grid lines "on" or "off" and also sets the number of grid lines.
Definition at line 418 of file gobchartsview.cpp.
|
protected |
Calculates the amount of space at the top of the view that is "extra".
This extra space can be stripped from all item height calculations and is needed to ensure that as much space is used for the display of the chart as possible.
Definition at line 610 of file gobchartsview.cpp.
|
protected |
Returns the total, consolidated value of all category values.
Definition at line 754 of file gobchartsview.cpp.
|
protectedpure virtual |
Derived classes must implement this function.
This function must return an integer value that matches one of the GobChartsType enum values as a QString (this information is used when saving and loading charts to and from file).
Implemented in GobChartsBarView, GobChartsLineView, and GobChartsPieView.
|
protected |
Returns "true" if the chart colour is fixed or "false" if random colours must be generated.
Definition at line 650 of file gobchartsview.cpp.
|
protected |
Returns a list of valid data row numbers.
Definition at line 726 of file gobchartsview.cpp.
|
protected |
Returns the data value corresponding to "row" in validRowList()
Definition at line 740 of file gobchartsview.cpp.
|
protected |
Re-implemented from QAbstractItemView.
See the Qt API documentation for details.
Definition at line 909 of file gobchartsview.cpp.
QRect GobChartsView::visualRect | ( | const QModelIndex & | index | ) | const |
Re-implemented from QAbstractItemView.
See the Qt API documentation for details.
Definition at line 810 of file gobchartsview.cpp.
|
protected |
Re-implemented from QAbstractItemView.
See the Qt API documentation for details.
Definition at line 1012 of file gobchartsview.cpp.
|
friend |
The PIMPL idiom will help with future binary compatibility.
Since the GobChartsViewPrivate class is completely restricted to this class, the "friend" status does not cause any adverse coupling (the class is basically a container of all the data members that would have been declared as "private" anyway, with one or two utility methods thrown in).
Definition at line 308 of file gobchartsview.h.