GobChartsWidget  1.0
Public Slots | Signals | Public Member Functions | Protected Types | Protected Slots | Protected Member Functions | Friends | List of all members
GobChartsView Class Referenceabstract

#include <gobchartsview.h>

Inheritance diagram for GobChartsView:
GobChartsNoCopy GobChartsBarView GobChartsLineView GobChartsPieView

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.
 

Detailed Description

Derived classes must implement the following pure virtual functions:

  1. generateGraphicsItems() - creates the graphics items required for the specific chart type and positions them within the view.
  1. needsGrid() - if the chart type supports grids, this function must return "true" (e.g. PIE charts don't support chart grids whereas BAR charts do).
  1. typeInteger() - returns an integer value as a QString. The value thus returned must match one of the GobChartsType enum values.

Definition at line 60 of file gobchartsview.h.

Member Enumeration Documentation

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.

Constructor & Destructor Documentation

GobChartsView::~GobChartsView ( )
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.

Member Function Documentation

void GobChartsView::addToGraphItemsContainer ( const QModelIndex &  valueIndex,
QGraphicsItem *  item,
const QString &  legendText 
)
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.

Parameters
valueIndex- the QModelIndex that the graphics item represents.
item- the newly created graphics item.

Definition at line 705 of file gobchartsview.cpp.

QString GobChartsView::category ( int  row) const
protected

Returns the category name corresponding to "row" in validRowList()

See Also
nrValidItems() and value()

Definition at line 733 of file gobchartsview.cpp.

void GobChartsView::clearLegend ( )
signal

Emitted when a chart is redrawn and its graphics items are reset.

void GobChartsView::createLegendItem ( const QColor &  colour,
const QString &  text 
)
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.

void GobChartsView::dataChanged ( const QModelIndex &  topLeft,
const QModelIndex &  bottomRight 
)
protectedslot

Re-implemented from QAbstractItemView.

See the Qt API documentation for details.

Definition at line 778 of file gobchartsview.cpp.

void GobChartsView::debugLog ( QString  msg)
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.

void GobChartsView::emitLabelDetails ( GobChartsLabel  label,
const QString &  text,
const QFont &  font,
const QColor &  colour,
Qt::Alignment  align 
)
signal

Obtain label details.

This signal is emitted when requestLabelDetails() is called and contains all the information relevant to the specified label.

See Also
requestLabelDetails() and setLabelDetails()
QColor GobChartsView::fixedColour ( ) const
protected

If the chart colour is fixed, this function returns the colour used to draw the chart items.

See Also
setFixedColour(), setRandomColours and useFixedColour()

Definition at line 657 of file gobchartsview.cpp.

virtual void GobChartsView::generateGraphicsItems ( )
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.

Parameters
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).
See Also
setStateXML()

Definition at line 568 of file gobchartsview.cpp.

qreal GobChartsView::gridWidth ( ) const
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.

void GobChartsView::highLightLegendItem ( const QString &  text)
signal

Emitted when a graphics item is selected.

int GobChartsView::horizontalOffset ( ) const
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.

const QRectF & GobChartsView::innerSceneRectF ( ) const
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.

bool GobChartsView::isIndexHidden ( const QModelIndex &  index) const
protected

Re-implemented from QAbstractItemView.

See the Qt API documentation for details.

Definition at line 916 of file gobchartsview.cpp.

bool GobChartsView::isWithinAllowedRange ( qreal  value) const
protected

Determines whether or not a data value falls within the allowed data range.

See Also
setAllowedDataRange() and setShowTotalRange()

Definition at line 691 of file gobchartsview.cpp.

void GobChartsView::keyPressEvent ( QKeyEvent *  event)
protected

Re-implemented from QAbstractItemView.

See the Qt API documentation for details.

Definition at line 987 of file gobchartsview.cpp.

void GobChartsView::lastDebugLogMsg ( QString  )
signal

Debug messages.

This signal broadcasts the last debug log message and will only be emitted when debug logging is turned "on".

See Also
setDebugLoggingOn()
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.

void GobChartsView::mousePressEvent ( QMouseEvent *  p_event)
protectedslot

Re-implemented from QAbstractItemView.

See the Qt API documentation for details.

Definition at line 979 of file gobchartsview.cpp.

QModelIndex GobChartsView::moveCursor ( QAbstractItemView::CursorAction  cursorAction,
Qt::KeyboardModifiers  modifiers 
)
protected

Re-implemented from QAbstractItemView.

See the Qt API documentation for details.

Definition at line 859 of file gobchartsview.cpp.

virtual bool GobChartsView::needsGrid ( ) const
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.

int GobChartsView::nrValidItems ( ) const
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).

See Also
validRowList(), category() and value()

Definition at line 719 of file gobchartsview.cpp.

void GobChartsView::requestLabelDetails ( GobChartsLabel  label)
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.

Parameters
label- the header, x-axis label or y-axis label.
See Also
setLabelDetails() and emitLabelDetails()

Definition at line 377 of file gobchartsview.cpp.

void GobChartsView::rowsAboutToBeRemoved ( const QModelIndex &  parent,
int  start,
int  end 
)
protectedslot

Re-implemented from QAbstractItemView.

See the Qt API documentation for details.

Definition at line 801 of file gobchartsview.cpp.

void GobChartsView::rowsInserted ( const QModelIndex &  parent,
int  start,
int  end 
)
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.

void GobChartsView::setAllowedDataRange ( qreal  lowerBoundary,
qreal  upperBoundary 
)
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.

Parameters
lowerBoundary- the lowest allowed value to be displayed.
upperBoundary- the highest allowed value to be displayed.
See Also
setShowTotalRange() and isWithinAllowedRange()

Definition at line 673 of file gobchartsview.cpp.

void GobChartsView::setDebugLoggingOn ( bool  logging)
slot

Debug log.

Turn debug logging messages "on" or "off" (default "off").

See Also
lastDebugLogMsg()

Definition at line 664 of file gobchartsview.cpp.

void GobChartsView::setFixedColour ( QColor  colour)
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.

See Also
setRandomColours(), useFixedColour() and fixedColour()

Definition at line 624 of file gobchartsview.cpp.

void GobChartsView::setGridColour ( QColor  colour)
slot

Set grid colour.

Sets the grid line's colour to "colour".

Definition at line 426 of file gobchartsview.cpp.

void GobChartsView::setGridLineStyle ( Qt::PenStyle  style)
slot

Grid line style.

Set the pen style used to draw the grid lines.

Parameters
style- dashed, dotted, solid, etc. (see Qt API documentation for details on the enum).

Definition at line 402 of file gobchartsview.cpp.

void GobChartsView::setHorizontalGridLines ( bool  set,
int  number 
)
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.

void GobChartsView::setLabelDetails ( GobChartsLabel  label,
const QString &  text,
const QFont &  font,
const QColor &  colour,
Qt::Alignment  align 
)
slot

Set chart label.

Sets the text, font, colour and alignment of the label specified.

Parameters
label- the header, x-axis label or y-axis label.
See Also
requestLabelDetails() and emitLabelDetails

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.

void GobChartsView::setRandomColours ( )
slot

Use different colours.

Re-enables random colour generation (the default) for chart items after a call to setFixedColour().

See Also
setFixedColour(), useFixedColour() and fixedColour()

Definition at line 642 of file gobchartsview.cpp.

void GobChartsView::setSelection ( const QRect &  rect,
QItemSelectionModel::SelectionFlags  command 
)
protected

Re-implemented from QAbstractItemView.

See the Qt API documentation for details.

Definition at line 924 of file gobchartsview.cpp.

void GobChartsView::setShowTotalRange ( )
slot

Show total data range.

Displays all categories (i.e. the entire data value range).

See Also
setAllowedDataRange() and isWithinAllowedRange()

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.

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).
See Also
getStateXML()

Definition at line 475 of file gobchartsview.cpp.

void GobChartsView::setVerticalGridLines ( bool  set,
int  number 
)
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.

qreal GobChartsView::stripSpace ( qreal  perc) const
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.

qreal GobChartsView::totalValue ( ) const
protected

Returns the total, consolidated value of all category values.

Definition at line 754 of file gobchartsview.cpp.

virtual QString GobChartsView::typeInteger ( ) const
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.

bool GobChartsView::useFixedColour ( ) const
protected

Returns "true" if the chart colour is fixed or "false" if random colours must be generated.

See Also
setFixedColour(), setRandomColours and fixedColour()

Definition at line 650 of file gobchartsview.cpp.

QList< int > GobChartsView::validRowList ( ) const
protected

Returns a list of valid data row numbers.

See Also
nrValidItems(), category() and value()

Definition at line 726 of file gobchartsview.cpp.

qreal GobChartsView::value ( int  row) const
protected

Returns the data value corresponding to "row" in validRowList()

See Also
nrValidItems() and category()

Definition at line 740 of file gobchartsview.cpp.

int GobChartsView::verticalOffset ( ) const
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.

QRegion GobChartsView::visualRegionForSelection ( const QItemSelection &  selection) const
protected

Re-implemented from QAbstractItemView.

See the Qt API documentation for details.

Definition at line 1012 of file gobchartsview.cpp.

Friends And Related Function Documentation

friend class GobChartsViewPrivate
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.


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