{
QwtPlotItemList lAlwaysDrawnItems;
// null pixmap means cache not valid
bool lCacheValid = !mPixmapCache->isNull();
const QwtPlotItemList& lItemList = itemList();
for (QwtPlotItemIterator lItemIter = lItemList.begin(); lItemIter != lItemList.end(); ++lItemIter)
{
if (lItem && lItem->isVisible() )
{
{
continue;
}
// render items below z-index 1000
// when cache is invalid only
if(lItem->z() < 1000)
{
if(!lCacheValid)
{
pPainter->save();
pPainter
->setRenderHint
(QPainter::Antialiasing, lItem
->testRenderHint
(QwtPlotItem::RenderAntialiased));
lItem->draw(pPainter, pMap[lItem->xAxis()], pMap[lItem->yAxis()], pRect);
pPainter->restore();
}
}
else
{
// all items above z-index 1000 are added to a list in order to draw after cache content
lAlwaysDrawnItems.append(lItem);
}
}
}
if(lCacheValid)
{
// if cache has been valid then paint from pixmap cache
pPainter->drawPixmap(pRect, *mPixmapCache);
}
else
{
// create new pixmap when cache not valid
mPixmapCache
= new QPixmap(pRect.
size());
// else make a snapshot from the plot canvas curves
*mPixmapCache
= QPixmap::grabWidget(canvas
(), pRect
);
}
// finally draw the rest to be rendered each time (z-index > 1000)
for (QwtPlotItemIterator lItemIter = lAlwaysDrawnItems.begin(); lItemIter != lAlwaysDrawnItems.end(); ++lItemIter)
{
pPainter->save();
pPainter
->setRenderHint
(QPainter::Antialiasing, lItem
->testRenderHint
(QwtPlotItem::RenderAntialiased));
lItem->draw(pPainter, pMap[lItem->xAxis()], pMap[lItem->yAxis()], pRect);
pPainter->restore();
}
}
void Plot::drawItems(QPainter *pPainter, const QRect &pRect, const QwtScaleMap pMap[QwtPlot::axisCnt], const QwtPlotPrintFilter &pFilter)
{
QwtPlotItemList lAlwaysDrawnItems;
// null pixmap means cache not valid
bool lCacheValid = !mPixmapCache->isNull();
const QwtPlotItemList& lItemList = itemList();
for (QwtPlotItemIterator lItemIter = lItemList.begin(); lItemIter != lItemList.end(); ++lItemIter)
{
QwtPlotItem *lItem = *lItemIter;
if (lItem && lItem->isVisible() )
{
if ( !(pFilter.options() & QwtPlotPrintFilter::PrintGrid) && lItem->rtti() == QwtPlotItem::Rtti_PlotGrid)
{
continue;
}
// render items below z-index 1000
// when cache is invalid only
if(lItem->z() < 1000)
{
if(!lCacheValid)
{
pPainter->save();
pPainter->setRenderHint(QPainter::Antialiasing, lItem->testRenderHint(QwtPlotItem::RenderAntialiased));
lItem->draw(pPainter, pMap[lItem->xAxis()], pMap[lItem->yAxis()], pRect);
pPainter->restore();
}
}
else
{
// all items above z-index 1000 are added to a list in order to draw after cache content
lAlwaysDrawnItems.append(lItem);
}
}
}
if(lCacheValid)
{
// if cache has been valid then paint from pixmap cache
pPainter->drawPixmap(pRect, *mPixmapCache);
}
else
{
// create new pixmap when cache not valid
mPixmapCache = new QPixmap(pRect.size());
// else make a snapshot from the plot canvas curves
*mPixmapCache = QPixmap::grabWidget(canvas(), pRect);
}
// finally draw the rest to be rendered each time (z-index > 1000)
for (QwtPlotItemIterator lItemIter = lAlwaysDrawnItems.begin(); lItemIter != lAlwaysDrawnItems.end(); ++lItemIter)
{
QwtPlotItem *lItem = *lItemIter;
pPainter->save();
pPainter->setRenderHint(QPainter::Antialiasing, lItem->testRenderHint(QwtPlotItem::RenderAntialiased));
lItem->draw(pPainter, pMap[lItem->xAxis()], pMap[lItem->yAxis()], pRect);
pPainter->restore();
}
}
To copy to clipboard, switch view to plain text mode
Bookmarks