Reference documentation
Public Member Functions | Protected Member Functions | List of all members
LinearChart Class Reference

Thistle::LinearChart class provides a default implementation for linear charts such as barcharts and line charts. More...

Inheritance diagram for LinearChart:
AxisChart AbstractChart AbstractItemView RadarChart

Public Member Functions

 LinearChart (QWidget *parent=0)
 Constructs a linear chart with the given parent.
 
- Public Member Functions inherited from AxisChart
 AxisChart (QWidget *parent=0)
 Constructs an abstract Axis chart with the given parent.
 
 ~AxisChart ()
 Destructs the current object.
 
AbstractAxisaxis () const
 Returns the current Axis instance used by this view.
 
SerieFormat serieFormat (int column) const
 Return the SerieFormat used for the column.
 
void setAxis (AbstractAxis *axis)
 Sets the Axis use by the view to determine the item's positions.
 
void setSerieFormat (int column, SerieFormat style)
 Sets the given style to the given column. More...
 
- Public Member Functions inherited from AbstractChart
 AbstractChart (QWidget *parent=0)
 Initializes a chart view with the given parent. More...
 
 ~AbstractChart ()
 Destructs the object and clean the internal components.
 
virtual QModelIndex indexAt (const QPoint &point) const
 Returns the model index of the item at the viewport coordinates point.
 
ChartLegendlegend () const
 Returns the current ChartLegend used to paint the chart legend.
 
void setLegend (ChartLegend *legend)
 Sets the legend used to paint the chart legend. More...
 
void setTitle (const QString &title)
 Sets the title displayed at the bottom.
 
void setTitleFont (const QFont &font)
 Sets the QFont used to write the title. More...
 
const QFont & titleFont () const
 Returns the QFont used to write the title. More...
 
- Public Member Functions inherited from AbstractItemView
 AbstractItemView (QWidget *parent=0)
 Constructs an abstract item view with the given parent.
 

Protected Member Functions

QList< int > calculateColumnsOrder () const
 Calculates the order in which the series (columns) should be drawn. More...
 
virtual QRectF itemRect (const QModelIndex &index) const
 Defines the outer bounds of the item as a rectangle. More...
 
virtual QRectF itemRect (int row, int column, const QModelIndex &parent=QModelIndex()) const
 This function overloads itemRect(). More...
 
virtual void paintChart (QPainter &painter)
 Paints the different parts of the chart (legend, title, axis, values, etc.).
 
virtual void paintSerieLegend (QPainter &painter, int column, QPoint pos, int maxHeight) const
 Paint the legend for the given column. More...
 
virtual void updateRects ()
 Updates the regions used to paint each part of the chart (legend, axis, values, title, etc.). More...
 
- Protected Member Functions inherited from AxisChart
 AxisChart (AxisChartPrivate *d, QWidget *parent=0)
 Initializes the abstract object with the given parent.
 
virtual void defineRects ()
 This pure virtual function defines the QRect used to to draw the different elements composing the view (series, legend, title, etc.).
 
void scan ()
 Scans values in the model to find the minimum and the maximum. More...
 
- Protected Member Functions inherited from AbstractChart
void calculateLegendRect (const QRect &source)
 Calculates the rectangle in which the legend should be drawn.
 
virtual QPainterPath itemPath (const QModelIndex &index) const
 Returns the QPainterPath defining the item's shape.
 
virtual void process ()
 Analyzes the model to define the bounds and axis values. More...
 

Additional Inherited Members

- Public Slots inherited from AbstractChart
void updateValues ()
 Updates the displayed data in the viewport. More...
 
- Public Slots inherited from AbstractItemView
virtual void updateValues ()=0
 Updates the items in the item view. More...
 

Detailed Description

Thistle::LinearChart class provides a default implementation for linear charts such as barcharts and line charts.

The Thistle::LinearChart class considers that each column from the model is a serie of values. It represents a serie with dots, lines or bars. The horizontal header contains the name of series. The vertical headers defines the x-axis data.

QStandardItemModel* model = new QStandardItemModel( 10, 2 ); model->setHorizontalHeaderLabels( QStringList() << "My values" ); model->setVerticalHeaderLabels( QStringList() << "Jan" << "Feb" << "Mar" << "Apr" << "May" << "Jun" << "Jul" << "Aug" << "Sept" << "Oct" ); for ( int i = 0; i < model2->rowCount(); ++i ) { int v = qrand() % ((high + 1) - low) + low; model->setData( model->index( i, 0 ), v ); v = qrand() % ((high + 1) - low) + low; model->setData( model->index( i, 1 ), v ); } Thistle::LinearChart linear; linear.setModel( model ); Thistle::SerieFormat style = linear.serieFormat( 1 ); style.setType( Thistle::Thistle::Bar ); linear.setSerieFormat( 1, style ); linear.setTitle( "A line chart example" ); linear.show();

Member Function Documentation

QList< int > calculateColumnsOrder ( ) const
protectedvirtual

Calculates the order in which the series (columns) should be drawn.

For example, in LinearChart, the columns with the type Thistle::Bar will be drawn at first to avoid to mask the others.

Reimplemented from AxisChart.

QRectF itemRect ( const QModelIndex &  index) const
protectedvirtual

Defines the outer bounds of the item as a rectangle.

All painting must be restricted to inside an item's bounding rect. Although the item's shape can be arbitrary, the bounding rect is always rectangular.

Reimplemented from AbstractItemView.

Reimplemented in RadarChart.

QRectF itemRect ( int  row,
int  column,
const QModelIndex &  parent = QModelIndex() 
) const
protectedvirtual

This function overloads itemRect().

Defines the outer bounds of the item as a rectangle. All painting must be restricted to inside an item's bounding rect. Although the item's shape can be arbitrary, the bounding rect is always rectangular.

Reimplemented from AbstractItemView.

void paintSerieLegend ( QPainter &  painter,
int  serie,
QPoint  pos,
int  metricsH 
) const
protectedvirtual

Paint the legend for the given column.

The kind of legend should be defined by each view (linear and radial represent legend differently). The column legend is represented by a square colored with the pen and brush style and the column name.

Reimplemented from AxisChart.

void updateRects ( )
protectedvirtual

Updates the regions used to paint each part of the chart (legend, axis, values, title, etc.).

This function is called whenever the view has been resized.

Implements AbstractChart.

Reimplemented in RadarChart.