SETestKCL  1.0.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Public Types | Public Member Functions | Protected Attributes | List of all members
QCPPainter Class Reference

#include <qcustomplot.h>

Inheritance diagram for QCPPainter:
Inheritance graph
[legend]
Collaboration diagram for QCPPainter:
Collaboration graph
[legend]

Public Types

enum  PainterMode { pmDefault = 0x00, pmVectorized = 0x01, pmNoCaching = 0x02, pmNonCosmetic = 0x04 }
 

Public Member Functions

 QCPPainter ()
 
 QCPPainter (QPaintDevice *device)
 
 ~QCPPainter ()
 
bool antialiasing () const
 
PainterModes modes () const
 
void setAntialiasing (bool enabled)
 
void setMode (PainterMode mode, bool enabled=true)
 
void setModes (PainterModes modes)
 
bool begin (QPaintDevice *device)
 
void setPen (const QPen &pen)
 
void setPen (const QColor &color)
 
void setPen (Qt::PenStyle penStyle)
 
void drawLine (const QLineF &line)
 
void drawLine (const QPointF &p1, const QPointF &p2)
 
void save ()
 
void restore ()
 
void makeNonCosmetic ()
 

Protected Attributes

PainterModes mModes
 
bool mIsAntialiasing
 
QStack< bool > mAntialiasingStack
 

Detailed Description

QPainter subclass used internally.

This QPainter subclass is used to provide some extended functionality e.g. for tweaking position consistency between antialiased and non-antialiased painting. Further it provides workarounds for QPainter quirks.

Warning
This class intentionally hides non-virtual functions of QPainter, e.g. setPen, save and restore. So while it is possible to pass a QCPPainter instance to a function that expects a QPainter pointer, some of the workarounds and tweaks will be unavailable to the function (because it will call the base class implementations of the functions actually hidden by QCPPainter).

Definition at line 312 of file qcustomplot.h.

Member Enumeration Documentation

Defines special modes the painter can operate in. They disable or enable certain subsets of features/fixes/workarounds, depending on whether they are wanted on the respective output device.

Enumerator
pmDefault 

0x00 Default mode for painting on screen devices

pmVectorized 

0x01 Mode for vectorized painting (e.g. PDF export). For example, this prevents some antialiasing fixes.

pmNoCaching 

0x02 Mode for all sorts of exports (e.g. PNG, PDF,...). For example, this prevents using cached pixmap labels

pmNonCosmetic 

0x04 Turns pen widths 0 to 1, i.e. disables cosmetic pens. (A cosmetic pen is always drawn with width 1 pixel in the vector image/pdf viewer, independent of zoom.)

Definition at line 320 of file qcustomplot.h.

Constructor & Destructor Documentation

Creates a new QCPPainter instance and sets default values

Definition at line 50 of file qcustomplot.cpp.

QCPPainter ( QPaintDevice *  device)

Creates a new QCPPainter instance on the specified paint device and sets default values. Just like the analogous QPainter constructor, begins painting on device immediately.

Like begin, this method sets QPainter::NonCosmeticDefaultPen in Qt versions before Qt5.

Definition at line 65 of file qcustomplot.cpp.

~QCPPainter ( )

Definition at line 76 of file qcustomplot.cpp.

Member Function Documentation

bool antialiasing ( ) const
inline

Definition at line 333 of file qcustomplot.h.

Referenced by QCPAxisPainterPrivate::draw().

bool begin ( QPaintDevice *  device)

Sets the QPainter::NonCosmeticDefaultPen in Qt versions before Qt5 after beginning painting on device. This is necessary to get cosmetic pen consistency across Qt versions, because since Qt5, all pens are non-cosmetic by default, and in Qt4 this render hint must be set to get that behaviour.

The Constructor QCPPainter(QPaintDevice *device) which directly starts painting also sets the render hint as appropriate.

Note
this function hides the non-virtual base class implementation.

Definition at line 179 of file qcustomplot.cpp.

Referenced by QCustomPlot::replot(), QCustomPlot::savePdf(), and QCustomPlot::toPixmap().

void drawLine ( const QLineF &  line)

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Works around a Qt bug introduced with Qt 4.8 which makes drawing QLineF unpredictable when antialiasing is disabled. Thus when antialiasing is disabled, it rounds the line to integer coordinates and then passes it to the original drawLine.

Note
this function hides the non-virtual base class implementation.

Definition at line 129 of file qcustomplot.cpp.

References mIsAntialiasing, mModes, and pmVectorized.

Referenced by QCPLineEnding::draw(), QCPAxisPainterPrivate::draw(), QCPCurve::draw(), QCPItemStraightLine::draw(), QCPItemLine::draw(), QCPItemTracer::draw(), QCPItemBracket::draw(), QCPFinancial::drawCandlestickPlot(), QCPGraph::drawError(), QCPGrid::drawGridLines(), QCPGraph::drawLegendIcon(), QCPCurve::drawLegendIcon(), QCPFinancial::drawLegendIcon(), QCPGraph::drawLinePlot(), QCPStatisticalBox::drawMedian(), QCPFinancial::drawOhlcPlot(), QCPScatterStyle::drawShape(), QCPGrid::drawSubGridLines(), and QCPStatisticalBox::drawWhiskers().

void drawLine ( const QPointF &  p1,
const QPointF &  p2 
)
inline

Definition at line 347 of file qcustomplot.h.

References drawLine().

Referenced by drawLine().

void makeNonCosmetic ( )

Changes the pen width to 1 if it currently is 0. This function is called in the setPen overrides when the pmNonCosmetic mode is set.

Definition at line 237 of file qcustomplot.cpp.

Referenced by setPen().

PainterModes modes ( ) const
inline
void restore ( )

Restores the painter (see QPainter::restore). Since QCPPainter adds some new internal state to QPainter, the save/restore functions are reimplemented to also save/restore those members.

Note
this function hides the non-virtual base class implementation.
See Also
save

Definition at line 224 of file qcustomplot.cpp.

References mAntialiasingStack, and mIsAntialiasing.

Referenced by QCustomPlot::draw(), QCPPlottableLegendItem::draw(), and QCPStatisticalBox::draw().

void save ( )

Saves the painter (see QPainter::save). Since QCPPainter adds some new internal state to QPainter, the save/restore functions are reimplemented to also save/restore those members.

Note
this function hides the non-virtual base class implementation.
See Also
restore

Definition at line 210 of file qcustomplot.cpp.

References mAntialiasingStack, and mIsAntialiasing.

Referenced by QCustomPlot::draw(), QCPPlottableLegendItem::draw(), and QCPStatisticalBox::draw().

void setAntialiasing ( bool  enabled)

Sets whether painting uses antialiasing or not. Use this method instead of using setRenderHint with QPainter::Antialiasing directly, as it allows QCPPainter to regain pixel exactness between antialiased and non-antialiased painting (Since Qt < 5.0 uses slightly different coordinate systems for AA/Non-AA painting).

Definition at line 143 of file qcustomplot.cpp.

References mIsAntialiasing, mModes, and pmVectorized.

Referenced by QCPLayerable::applyAntialiasingHint(), QCPAxisRect::applyDefaultAntialiasingHint(), QCPColorScale::applyDefaultAntialiasingHint(), QCPAxisPainterPrivate::draw(), and QCPFinancial::drawLegendIcon().

void setMode ( QCPPainter::PainterMode  mode,
bool  enabled = true 
)

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Sets the mode of the painter. This controls whether the painter shall adjust its fixes/workarounds optimized for certain output devices.

Definition at line 194 of file qcustomplot.cpp.

References mModes.

Referenced by QCustomPlot::savePdf(), QCustomPlot::toPainter(), and QCustomPlot::toPixmap().

void setModes ( PainterModes  modes)

Sets the mode of the painter. This controls whether the painter shall adjust its fixes/workarounds optimized for certain output devices.

Definition at line 163 of file qcustomplot.cpp.

References mModes, and modes().

void setPen ( const QPen &  pen)
void setPen ( const QColor &  color)

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Sets the pen (by color) of the painter and applies certain fixes to it, depending on the mode of this QCPPainter.

Note
this function hides the non-virtual base class implementation.

Definition at line 100 of file qcustomplot.cpp.

References makeNonCosmetic(), mModes, and pmNonCosmetic.

void setPen ( Qt::PenStyle  penStyle)

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Sets the pen (by style) of the painter and applies certain fixes to it, depending on the mode of this QCPPainter.

Note
this function hides the non-virtual base class implementation.

Definition at line 114 of file qcustomplot.cpp.

References makeNonCosmetic(), mModes, and pmNonCosmetic.

Member Data Documentation

QStack<bool> mAntialiasingStack
protected

Definition at line 360 of file qcustomplot.h.

Referenced by restore(), and save().

bool mIsAntialiasing
protected

Definition at line 357 of file qcustomplot.h.

Referenced by drawLine(), restore(), save(), and setAntialiasing().

PainterModes mModes
protected

Definition at line 356 of file qcustomplot.h.

Referenced by drawLine(), setAntialiasing(), setMode(), setModes(), and setPen().


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