A base class for plot print filters. More...
#include <qwt_plot_printfilter.h>

Classes | |
| class | PrivateData |
Public Types | |
| enum | Options { PrintMargin = 1, PrintTitle = 2, PrintLegend = 4, PrintGrid = 8, PrintBackground = 16, PrintFrameWithScales = 32, PrintAll = ~PrintFrameWithScales } |
Print options. More... | |
| enum | Item { Title, Legend, Curve, CurveSymbol, Marker, MarkerSymbol, MajorGrid, MinorGrid, CanvasBackground, AxisScale, AxisTitle, WidgetBackground } |
Print items. More... | |
Public Member Functions | |
| QwtPlotPrintFilter () | |
| virtual | ~QwtPlotPrintFilter () |
| Destructor. | |
| virtual QColor | color (const QColor &, Item item) const |
| Modifies a color for printing. | |
| virtual QFont | font (const QFont &, Item item) const |
| Modifies a font for printing. | |
| void | setOptions (int options) |
| Set plot print options. | |
| int | options () const |
| Get plot print options. | |
| virtual void | apply (QwtPlot *) const |
| virtual void | reset (QwtPlot *) const |
| virtual void | apply (QwtPlotItem *) const |
| virtual void | reset (QwtPlotItem *) const |
A base class for plot print filters.
A print filter can be used to customize QwtPlot::print().
Definition at line 30 of file qwt_plot_printfilter.h.
Print items.
| Title | |
| Legend | |
| Curve | |
| CurveSymbol | |
| Marker | |
| MarkerSymbol | |
| MajorGrid | |
| MinorGrid | |
| CanvasBackground | |
| AxisScale | |
| AxisTitle | |
| WidgetBackground |
Definition at line 47 of file qwt_plot_printfilter.h.
Print options.
| PrintMargin | |
| PrintTitle | |
| PrintLegend | |
| PrintGrid | |
| PrintBackground | |
| PrintFrameWithScales | |
| PrintAll |
Definition at line 34 of file qwt_plot_printfilter.h.
{
PrintMargin = 1,
PrintTitle = 2,
PrintLegend = 4,
PrintGrid = 8,
PrintBackground = 16,
PrintFrameWithScales = 32,
PrintAll = ~PrintFrameWithScales
};
| QwtPlotPrintFilter::QwtPlotPrintFilter | ( | ) | [explicit] |
Sets filter options to PrintAll
Definition at line 82 of file qwt_plot_printfilter.cpp.
{
d_data = new PrivateData;
}
| QwtPlotPrintFilter::~QwtPlotPrintFilter | ( | ) | [virtual] |
| void QwtPlotPrintFilter::apply | ( | QwtPlot * | plot ) | const [virtual] |
Change color and fonts of a plot
Definition at line 157 of file qwt_plot_printfilter.cpp.
References QwtPlot::autoReplot(), QwtPlot::axisCnt, AxisScale, AxisTitle, QwtPlot::axisWidget(), QwtSymbol::brush(), QwtPlotPrintFilter::PrivateData::cache, CanvasBackground, QwtPlot::canvasBackground(), QwtPlotPrintFilter::PrivateData::Cache::canvasBackground, QwtText::color(), color(), Curve, QwtLegendItem::curvePen(), CurveSymbol, QwtText::font(), font(), QwtScaleWidget::getBorderDistHint(), QwtPlotDict::itemList(), Legend, QwtPlot::legend(), QwtPlotPrintFilter::PrivateData::Cache::legendFonts, QwtLegend::legendItems(), QwtText::PaintUsingTextColor, QwtText::PaintUsingTextFont, QwtSymbol::pen(), QwtPlotPrintFilter::PrivateData::Cache::scaleColor, QwtPlotPrintFilter::PrivateData::Cache::scaleFont, QwtPlotPrintFilter::PrivateData::Cache::scaleTitle, QwtPlotPrintFilter::PrivateData::Cache::scaleTitleColor, QwtPlotPrintFilter::PrivateData::Cache::scaleTitleFont, QwtPlot::setAutoReplot(), QwtScaleWidget::setBorderDist(), QwtSymbol::setBrush(), QwtPlot::setCanvasBackground(), QwtText::setColor(), QwtLegendItem::setCurvePen(), QwtText::setFont(), QwtSymbol::setPen(), QwtLegendItem::setSymbol(), QwtScaleWidget::setTitle(), QwtLegendItem::symbol(), QwtText::testPaintAttribute(), QwtScaleWidget::title(), Title, QwtPlotPrintFilter::PrivateData::Cache::titleColor, QwtPlotPrintFilter::PrivateData::Cache::titleFont, QwtPlot::titleLabel(), WidgetBackground, and QwtPlotPrintFilter::PrivateData::Cache::widgetBackground.
Referenced by QwtPlot::print().
{
const bool doAutoReplot = plot->autoReplot();
plot->setAutoReplot(false);
delete d_data->cache;
d_data->cache = new PrivateData::Cache;
PrivateData::Cache &cache = *d_data->cache;
if ( plot->titleLabel() )
{
QPalette palette = plot->titleLabel()->palette();
cache.titleColor = palette.color(
QPalette::Active, Palette::Text);
palette.setColor(QPalette::Active, Palette::Text,
color(cache.titleColor, Title));
plot->titleLabel()->setPalette(palette);
cache.titleFont = plot->titleLabel()->font();
plot->titleLabel()->setFont(font(cache.titleFont, Title));
}
if ( plot->legend() )
{
#if QT_VERSION < 0x040000
QValueList<QWidget *> list = plot->legend()->legendItems();
for ( QValueListIterator<QWidget *> it = list.begin();
it != list.end(); ++it )
#else
QList<QWidget *> list = plot->legend()->legendItems();
for ( QList<QWidget*>::iterator it = list.begin();
it != list.end(); ++it )
#endif
{
QWidget *w = *it;
cache.legendFonts.insert(w, w->font());
w->setFont(font(w->font(), Legend));
if ( w->inherits("QwtLegendItem") )
{
QwtLegendItem *label = (QwtLegendItem *)w;
QwtSymbol symbol = label->symbol();
QPen pen = symbol.pen();
QBrush brush = symbol.brush();
pen.setColor(color(pen.color(), CurveSymbol));
brush.setColor(color(brush.color(), CurveSymbol));
symbol.setPen(pen);
symbol.setBrush(brush);
label->setSymbol(symbol);
pen = label->curvePen();
pen.setColor(color(pen.color(), Curve));
label->setCurvePen(pen);
}
}
}
for ( int axis = 0; axis < QwtPlot::axisCnt; axis++ )
{
QwtScaleWidget *scaleWidget = plot->axisWidget(axis);
if ( scaleWidget )
{
cache.scaleColor[axis] = scaleWidget->palette().color(
QPalette::Active, Palette::Foreground);
QPalette palette = scaleWidget->palette();
palette.setColor(QPalette::Active, Palette::Foreground,
color(cache.scaleColor[axis], AxisScale));
scaleWidget->setPalette(palette);
cache.scaleFont[axis] = scaleWidget->font();
scaleWidget->setFont(font(cache.scaleFont[axis], AxisScale));
cache.scaleTitle[axis] = scaleWidget->title();
QwtText scaleTitle = scaleWidget->title();
if ( scaleTitle.testPaintAttribute(QwtText::PaintUsingTextColor) )
{
cache.scaleTitleColor[axis] = scaleTitle.color();
scaleTitle.setColor(
color(cache.scaleTitleColor[axis], AxisTitle));
}
if ( scaleTitle.testPaintAttribute(QwtText::PaintUsingTextFont) )
{
cache.scaleTitleFont[axis] = scaleTitle.font();
scaleTitle.setFont(
font(cache.scaleTitleFont[axis], AxisTitle));
}
scaleWidget->setTitle(scaleTitle);
int startDist, endDist;
scaleWidget->getBorderDistHint(startDist, endDist);
scaleWidget->setBorderDist(startDist, endDist);
}
}
QPalette p = plot->palette();
cache.widgetBackground = plot->palette().color(
QPalette::Active, Palette::Background);
p.setColor(QPalette::Active, Palette::Background,
color(cache.widgetBackground, WidgetBackground));
plot->setPalette(p);
cache.canvasBackground = plot->canvasBackground();
plot->setCanvasBackground(color(cache.canvasBackground, CanvasBackground));
const QwtPlotItemList& itmList = plot->itemList();
for ( QwtPlotItemIterator it = itmList.begin();
it != itmList.end(); ++it )
{
apply(*it);
}
plot->setAutoReplot(doAutoReplot);
}
| void QwtPlotPrintFilter::apply | ( | QwtPlotItem * | item ) | const [virtual] |
Definition at line 278 of file qwt_plot_printfilter.cpp.
References QwtSymbol::brush(), QwtPlotPrintFilter::PrivateData::cache, QwtText::color(), color(), Curve, QwtPlotPrintFilter::PrivateData::Cache::curveColors, CurveSymbol, QwtPlotPrintFilter::PrivateData::Cache::curveSymbolBrushColors, QwtPlotPrintFilter::PrivateData::Cache::curveSymbolPenColors, font(), QwtText::font(), QwtPlotPrintFilter::PrivateData::Cache::gridColors, QwtPlotMarker::label(), QwtPlotMarker::linePen(), MajorGrid, QwtPlotGrid::majPen(), Marker, QwtPlotPrintFilter::PrivateData::Cache::markerFonts, QwtPlotPrintFilter::PrivateData::Cache::markerLabelColors, QwtPlotPrintFilter::PrivateData::Cache::markerLineColors, MarkerSymbol, QwtPlotPrintFilter::PrivateData::Cache::markerSymbolBrushColors, QwtPlotPrintFilter::PrivateData::Cache::markerSymbolPenColors, MinorGrid, QwtPlotGrid::minPen(), QwtPlotCurve::pen(), QwtSymbol::pen(), QwtPlotItem::rtti(), QwtPlotItem::Rtti_PlotCurve, QwtPlotItem::Rtti_PlotGrid, QwtPlotItem::Rtti_PlotMarker, QwtSymbol::setBrush(), QwtText::setColor(), QwtText::setFont(), QwtPlotMarker::setLabel(), QwtPlotMarker::setLinePen(), QwtPlotGrid::setMajPen(), QwtPlotGrid::setMinPen(), QwtPlotCurve::setPen(), QwtSymbol::setPen(), QwtPlotMarker::setSymbol(), QwtPlotCurve::setSymbol(), QwtPlotMarker::symbol(), and QwtPlotCurve::symbol().
{
PrivateData::Cache &cache = *d_data->cache;
switch(item->rtti())
{
case QwtPlotItem::Rtti_PlotGrid:
{
QwtPlotGrid *grid = (QwtPlotGrid *)item;
QPen pen = grid->majPen();
cache.gridColors[0] = pen.color();
pen.setColor(color(pen.color(), MajorGrid));
grid->setMajPen(pen);
pen = grid->minPen();
cache.gridColors[1] = pen.color();
pen.setColor(color(pen.color(), MinorGrid));
grid->setMinPen(pen);
break;
}
case QwtPlotItem::Rtti_PlotCurve:
{
QwtPlotCurve *c = (QwtPlotCurve *)item;
QwtSymbol symbol = c->symbol();
QPen pen = symbol.pen();
cache.curveSymbolPenColors.insert(c, pen.color());
pen.setColor(color(pen.color(), CurveSymbol));
symbol.setPen(pen);
QBrush brush = symbol.brush();
cache.curveSymbolBrushColors.insert(c, brush.color());
brush.setColor(color(brush.color(), CurveSymbol));
symbol.setBrush(brush);
c->setSymbol(symbol);
pen = c->pen();
cache.curveColors.insert(c, pen.color());
pen.setColor(color(pen.color(), Curve));
c->setPen(pen);
break;
}
case QwtPlotItem::Rtti_PlotMarker:
{
QwtPlotMarker *m = (QwtPlotMarker *)item;
QwtText label = m->label();
cache.markerFonts.insert(m, label.font());
label.setFont(font(label.font(), Marker));
cache.markerLabelColors.insert(m, label.color());
label.setColor(color(label.color(), Marker));
m->setLabel(label);
QPen pen = m->linePen();
cache.markerLineColors.insert(m, pen.color());
pen.setColor(color(pen.color(), Marker));
m->setLinePen(pen);
QwtSymbol symbol = m->symbol();
pen = symbol.pen();
cache.markerSymbolPenColors.insert(m, pen.color());
pen.setColor(color(pen.color(), MarkerSymbol));
symbol.setPen(pen);
QBrush brush = symbol.brush();
cache.markerSymbolBrushColors.insert(m, brush.color());
brush.setColor(color(brush.color(), MarkerSymbol));
symbol.setBrush(brush);
m->setSymbol(symbol);
break;
}
default:
break;
}
}
| QColor QwtPlotPrintFilter::color | ( | const QColor & | c, |
| Item | item | ||
| ) | const [virtual] |
Modifies a color for printing.
| c | Color to be modified |
| item | Type of item where the color belongs |
In case of !(QwtPlotPrintFilter::options() & PrintBackground) MajorGrid is modified to Qt::darkGray, MinorGrid to Qt::gray. All other colors are returned unmodified.
Definition at line 124 of file qwt_plot_printfilter.cpp.
References MajorGrid, MinorGrid, options(), and PrintBackground.
Referenced by apply().
{
if ( !(options() & PrintBackground))
{
switch(item)
{
case MajorGrid:
return Qt::darkGray;
case MinorGrid:
return Qt::gray;
default:;
}
}
return c;
}
| QFont QwtPlotPrintFilter::font | ( | const QFont & | f, |
| Item | item | ||
| ) | const [virtual] |
Modifies a font for printing.
| f | Font to be modified |
| item | Type of item where the font belongs |
All fonts are returned unmodified
Definition at line 148 of file qwt_plot_printfilter.cpp.
Referenced by apply().
{
return f;
}
| int QwtPlotPrintFilter::options | ( | ) | const |
Get plot print options.
Definition at line 108 of file qwt_plot_printfilter.cpp.
References QwtPlotPrintFilter::PrivateData::options.
Referenced by color(), QwtPlot::drawItems(), QwtPlot::print(), QwtPlot::printCanvas(), and setOptions().
{
return d_data->options;
}
| void QwtPlotPrintFilter::reset | ( | QwtPlot * | plot ) | const [virtual] |
Reset color and fonts of a plot
Definition at line 366 of file qwt_plot_printfilter.cpp.
References QwtPlot::autoReplot(), QwtPlot::axisCnt, QwtPlot::axisWidget(), QwtSymbol::brush(), QwtPlotPrintFilter::PrivateData::cache, QwtPlotPrintFilter::PrivateData::Cache::canvasBackground, QwtPlotPrintFilter::PrivateData::Cache::curveColors, QwtLegendItem::curvePen(), QwtPlotPrintFilter::PrivateData::Cache::curveSymbolBrushColors, QwtPlotPrintFilter::PrivateData::Cache::curveSymbolPenColors, QwtLegend::find(), QwtScaleWidget::getBorderDistHint(), QwtPlotDict::itemList(), QwtPlot::legend(), QwtPlotPrintFilter::PrivateData::Cache::legendFonts, QwtLegend::legendItems(), QwtText::PaintUsingTextFont, QwtSymbol::pen(), QwtPlotPrintFilter::PrivateData::Cache::scaleColor, QwtPlotPrintFilter::PrivateData::Cache::scaleFont, QwtPlotPrintFilter::PrivateData::Cache::scaleTitle, QwtPlot::setAutoReplot(), QwtScaleWidget::setBorderDist(), QwtSymbol::setBrush(), QwtPlot::setCanvasBackground(), QwtText::setColor(), QwtLegendItem::setCurvePen(), QwtText::setFont(), QwtSymbol::setPen(), QwtLegendItem::setSymbol(), QwtTextLabel::setText(), QwtScaleWidget::setTitle(), QwtLegendItem::symbol(), QwtText::testPaintAttribute(), QwtTextLabel::text(), QwtPlotPrintFilter::PrivateData::Cache::titleColor, QwtPlotPrintFilter::PrivateData::Cache::titleFont, QwtPlot::titleLabel(), and QwtPlotPrintFilter::PrivateData::Cache::widgetBackground.
Referenced by QwtPlot::print().
{
if ( d_data->cache == 0 )
return;
const bool doAutoReplot = plot->autoReplot();
plot->setAutoReplot(false);
const PrivateData::Cache &cache = *d_data->cache;
if ( plot->titleLabel() )
{
QwtTextLabel* title = plot->titleLabel();
if ( title->text().testPaintAttribute(QwtText::PaintUsingTextFont) )
{
QwtText text = title->text();
text.setColor(cache.titleColor);
title->setText(text);
}
else
{
QPalette palette = title->palette();
palette.setColor(
QPalette::Active, Palette::Text, cache.titleColor);
title->setPalette(palette);
}
if ( title->text().testPaintAttribute(QwtText::PaintUsingTextFont) )
{
QwtText text = title->text();
text.setFont(cache.titleFont);
title->setText(text);
}
else
{
title->setFont(cache.titleFont);
}
}
if ( plot->legend() )
{
#if QT_VERSION < 0x040000
QValueList<QWidget *> list = plot->legend()->legendItems();
for ( QValueListIterator<QWidget *> it = list.begin();
it != list.end(); ++it )
#else
QList<QWidget *> list = plot->legend()->legendItems();
for ( QList<QWidget*>::iterator it = list.begin();
it != list.end(); ++it )
#endif
{
QWidget *w = *it;
if ( cache.legendFonts.contains(w) )
w->setFont(cache.legendFonts[w]);
if ( w->inherits("QwtLegendItem") )
{
QwtLegendItem *label = (QwtLegendItem *)w;
const QwtPlotItem *plotItem =
(const QwtPlotItem*)plot->legend()->find(label);
QwtSymbol symbol = label->symbol();
if ( cache.curveSymbolPenColors.contains(plotItem) )
{
QPen pen = symbol.pen();
pen.setColor(cache.curveSymbolPenColors[plotItem]);
symbol.setPen(pen);
}
if ( cache.curveSymbolBrushColors.contains(plotItem) )
{
QBrush brush = symbol.brush();
brush.setColor(cache.curveSymbolBrushColors[plotItem]);
symbol.setBrush(brush);
}
label->setSymbol(symbol);
if ( cache.curveColors.contains(plotItem) )
{
QPen pen = label->curvePen();
pen.setColor(cache.curveColors[plotItem]);
label->setCurvePen(pen);
}
}
}
}
for ( int axis = 0; axis < QwtPlot::axisCnt; axis++ )
{
QwtScaleWidget *scaleWidget = plot->axisWidget(axis);
if ( scaleWidget )
{
QPalette palette = scaleWidget->palette();
palette.setColor(QPalette::Active, Palette::Foreground,
cache.scaleColor[axis]);
scaleWidget->setPalette(palette);
scaleWidget->setFont(cache.scaleFont[axis]);
scaleWidget->setTitle(cache.scaleTitle[axis]);
int startDist, endDist;
scaleWidget->getBorderDistHint(startDist, endDist);
scaleWidget->setBorderDist(startDist, endDist);
}
}
QPalette p = plot->palette();
p.setColor(QPalette::Active, Palette::Background, cache.widgetBackground);
plot->setPalette(p);
plot->setCanvasBackground(cache.canvasBackground);
const QwtPlotItemList& itmList = plot->itemList();
for ( QwtPlotItemIterator it = itmList.begin();
it != itmList.end(); ++it )
{
reset(*it);
}
delete d_data->cache;
d_data->cache = 0;
plot->setAutoReplot(doAutoReplot);
}
| void QwtPlotPrintFilter::reset | ( | QwtPlotItem * | item ) | const [virtual] |
Definition at line 491 of file qwt_plot_printfilter.cpp.
References QwtSymbol::brush(), QwtPlotPrintFilter::PrivateData::cache, QwtPlotPrintFilter::PrivateData::Cache::curveColors, QwtPlotPrintFilter::PrivateData::Cache::curveSymbolBrushColors, QwtPlotPrintFilter::PrivateData::Cache::curveSymbolPenColors, QwtPlotPrintFilter::PrivateData::Cache::gridColors, QwtPlotMarker::label(), QwtPlotMarker::linePen(), QwtPlotGrid::majPen(), QwtPlotPrintFilter::PrivateData::Cache::markerFonts, QwtPlotPrintFilter::PrivateData::Cache::markerLabelColors, QwtPlotPrintFilter::PrivateData::Cache::markerLineColors, QwtPlotPrintFilter::PrivateData::Cache::markerSymbolBrushColors, QwtPlotPrintFilter::PrivateData::Cache::markerSymbolPenColors, QwtPlotGrid::minPen(), QwtSymbol::pen(), QwtPlotCurve::pen(), QwtPlotItem::rtti(), QwtPlotItem::Rtti_PlotCurve, QwtPlotItem::Rtti_PlotGrid, QwtPlotItem::Rtti_PlotMarker, QwtSymbol::setBrush(), QwtText::setColor(), QwtText::setFont(), QwtPlotMarker::setLabel(), QwtPlotMarker::setLinePen(), QwtPlotGrid::setMajPen(), QwtPlotGrid::setMinPen(), QwtPlotCurve::setPen(), QwtSymbol::setPen(), QwtPlotMarker::setSymbol(), QwtPlotCurve::setSymbol(), QwtPlotMarker::symbol(), and QwtPlotCurve::symbol().
{
if ( d_data->cache == 0 )
return;
const PrivateData::Cache &cache = *d_data->cache;
switch(item->rtti())
{
case QwtPlotItem::Rtti_PlotGrid:
{
QwtPlotGrid *grid = (QwtPlotGrid *)item;
QPen pen = grid->majPen();
pen.setColor(cache.gridColors[0]);
grid->setMajPen(pen);
pen = grid->minPen();
pen.setColor(cache.gridColors[1]);
grid->setMinPen(pen);
break;
}
case QwtPlotItem::Rtti_PlotCurve:
{
QwtPlotCurve *c = (QwtPlotCurve *)item;
QwtSymbol symbol = c->symbol();
if ( cache.curveSymbolPenColors.contains(c) )
{
symbol.setPen(cache.curveSymbolPenColors[c]);
}
if ( cache.curveSymbolBrushColors.contains(c) )
{
QBrush brush = symbol.brush();
brush.setColor(cache.curveSymbolBrushColors[c]);
symbol.setBrush(brush);
}
c->setSymbol(symbol);
if ( cache.curveColors.contains(c) )
{
QPen pen = c->pen();
pen.setColor(cache.curveColors[c]);
c->setPen(pen);
}
break;
}
case QwtPlotItem::Rtti_PlotMarker:
{
QwtPlotMarker *m = (QwtPlotMarker *)item;
if ( cache.markerFonts.contains(m) )
{
QwtText label = m->label();
label.setFont(cache.markerFonts[m]);
m->setLabel(label);
}
if ( cache.markerLabelColors.contains(m) )
{
QwtText label = m->label();
label.setColor(cache.markerLabelColors[m]);
m->setLabel(label);
}
if ( cache.markerLineColors.contains(m) )
{
QPen pen = m->linePen();
pen.setColor(cache.markerLineColors[m]);
m->setLinePen(pen);
}
QwtSymbol symbol = m->symbol();
if ( cache.markerSymbolPenColors.contains(m) )
{
QPen pen = symbol.pen();
pen.setColor(cache.markerSymbolPenColors[m]);
symbol.setPen(pen);
}
if ( cache.markerSymbolBrushColors.contains(m) )
{
QBrush brush = symbol.brush();
brush.setColor(cache.markerSymbolBrushColors[m]);
symbol.setBrush(brush);
}
m->setSymbol(symbol);
break;
}
default:
break;
}
}
| void QwtPlotPrintFilter::setOptions | ( | int | options ) |
Set plot print options.
| options | Or'd QwtPlotPrintFilter::Options values |
Definition at line 99 of file qwt_plot_printfilter.cpp.
References options(), and QwtPlotPrintFilter::PrivateData::options.
1.7.2