From: <ai...@us...> - 2009-08-26 15:49:11
|
Revision: 10346 http://plplot.svn.sourceforge.net/plplot/?rev=10346&view=rev Author: airwin Date: 2009-08-26 15:48:56 +0000 (Wed, 26 Aug 2009) Log Message: ----------- AWI for Alban Rochel. Commit patch which does the following: + Better implementation of flushing, resulting in x17c -dev qtwidget running about as fast as x17c -dev xwin, a large improvement in qtwidget animation speed. + Fallback to well-implemented core version of PLESC_CLEAR since the qt version was not implemented correctly. + Improve qt_example to show how to deep-copy the command-line arguments passed to the software so that Qt does not filter out the "bg" commands. Modified Paths: -------------- trunk/bindings/qt_gui/plqt.cpp trunk/drivers/qt.cpp trunk/examples/c++/qt_PlotWindow.cpp trunk/examples/c++/qt_example.cpp trunk/include/qt.h Modified: trunk/bindings/qt_gui/plqt.cpp =================================================================== --- trunk/bindings/qt_gui/plqt.cpp 2009-08-26 15:22:14 UTC (rev 10345) +++ trunk/bindings/qt_gui/plqt.cpp 2009-08-26 15:48:56 UTC (rev 10346) @@ -563,12 +563,17 @@ m_dAspectRatio=m_dWidth/m_dHeight; m_pixPixmap=NULL; - m_iOldSize=0; +// m_iOldSize=0; pageNumber=0; resize(i_iWidth, i_iHeight); lastColour.r=-1; setVisible(true); QApplication::processEvents(); + redrawFromLastFlush=false; + redrawAll=true; + + NoPen=QPen(Qt::NoPen); + NoPen.setWidthF(0.); } QtPLWidget::~QtPLWidget() @@ -579,8 +584,10 @@ void QtPLWidget::clearWidget() { - clear(); - m_bAwaitingRedraw=true; + clearBuffer(); + setBackgroundColor(bgColour.r, bgColour.g, bgColour.b, bgColour.alpha); + redrawAll=true; +// m_bAwaitingRedraw=true; update(); } @@ -624,6 +631,8 @@ } m_listBuffer.clear(); + start_iterator=m_listBuffer.constBegin(); + redrawAll=true; } void QtPLWidget::drawLine(short x1, short y1, short x2, short y2) @@ -633,6 +642,7 @@ el.Data.Line=new QLineF(QPointF((PLFLT)x1*downscale, (PLFLT)(m_dHeight-y1*downscale)), QPointF((PLFLT)x2*downscale, (PLFLT)(m_dHeight-y2*downscale))); m_listBuffer.append(el); + redrawFromLastFlush=true; } void QtPLWidget::drawPolyline(short * x, short * y, PLINT npts) @@ -646,6 +656,7 @@ } m_listBuffer.append(el); + redrawFromLastFlush=true; } void QtPLWidget::drawPolygon(short * x, short * y, PLINT npts) @@ -721,6 +732,7 @@ } m_listBuffer.append(el); + redrawFromLastFlush=true; } void QtPLWidget::setColor(int r, int g, int b, double alpha) @@ -742,6 +754,8 @@ lastColour.b=b; lastColour.alpha=alpha; } + // No need to ask for a redraw at this point. The color only affects subsequent items +// redrawFromLastFlush=true; } void QtPLWidget::setBackgroundColor(int r, int g, int b, double alpha) @@ -758,8 +772,12 @@ bgColour.g=g; bgColour.b=b; bgColour.alpha=alpha; - + if(alpha>=0.999) + { + clearBuffer(); + } m_listBuffer.append(el); + redrawFromLastFlush=true; } void QtPLWidget::setWidth(PLINT w) @@ -768,6 +786,7 @@ el.Element=SET_WIDTH; el.Data.intParam=w; m_listBuffer.append(el); +// redrawFromLastFlush=true; } void QtPLWidget::drawText(PLStream* pls, EscText* txt) @@ -797,6 +816,7 @@ el.Data.TextStruct->chrht=pls->chrht; m_listBuffer.append(el); + redrawFromLastFlush=true; } void QtPLWidget::renderText(QPainter* p, struct TextStruct_* s, double x_fact, double x_offset, double y_fact, double y_offset) @@ -821,6 +841,14 @@ p->setClipping(false); } +void QtPLWidget::resetPensAndBrushes(QPainter* painter) +{ + SolidPen=QPen(); + hasPen=true; + painter->setPen(SolidPen); + SolidBrush=QBrush(Qt::SolidPattern); +} + void QtPLWidget::mouseReleaseEvent ( QMouseEvent * event ) { if(event->button()==Qt::RightButton) @@ -851,43 +879,65 @@ void QtPLWidget::resizeEvent( QResizeEvent * ) { - m_bAwaitingRedraw=true; +// m_bAwaitingRedraw=true; + redrawAll=true; delete m_pixPixmap; m_pixPixmap=NULL; } void QtPLWidget::paintEvent( QPaintEvent * ) { - double x_fact, y_fact, x_offset(0.), y_offset(0.); //Parameters to scale and center the plot on the widget + double x_fact, y_fact, x_offset(0.), y_offset(0.); //Parameters to scale and center the plot on the widget - getPlotParameters(x_fact, y_fact, x_offset, y_offset); - if(m_bAwaitingRedraw || m_pixPixmap==NULL || m_listBuffer.size()!=m_iOldSize) // If must regenerate image, draw it in the pixmap - { - delete m_pixPixmap; - m_pixPixmap=new QPixmap(width(), height()); - QPainter* painter=new QPainter; - painter->begin(m_pixPixmap); - - // Draw the margins and the background - painter->fillRect(0, 0, width(), height(), QBrush(Qt::white)); - painter->fillRect(0, 0, width(), height(), QBrush(Qt::gray, Qt::Dense4Pattern)); + getPlotParameters(x_fact, y_fact, x_offset, y_offset); - // Draw the plot - doPlot(painter, x_fact, y_fact, x_offset, y_offset); - painter->end(); - - m_bAwaitingRedraw=false; - m_iOldSize=m_listBuffer.size(); - - delete painter; - } - - // draw the current pixmap - m_painterP->begin(this); + if(redrawAll || m_pixPixmap==NULL) + { + if(m_pixPixmap!=NULL) + { + delete m_pixPixmap; + } + m_pixPixmap=new QPixmap(width(), height()); + QPainter* painter=new QPainter; + painter->begin(m_pixPixmap); - m_painterP->drawPixmap(0, 0, *m_pixPixmap); + // Draw the margins and the background + painter->fillRect(0, 0, width(), height(), QBrush(Qt::white)); + painter->fillRect(0, 0, width(), height(), QBrush(Qt::gray, Qt::Dense4Pattern)); - m_painterP->end(); + // Re-initialise pens etc. + resetPensAndBrushes(painter); + + start_iterator=m_listBuffer.constBegin(); + + // Draw the plot + doPlot(painter, x_fact, y_fact, x_offset, y_offset); + painter->end(); + +// m_iOldSize=m_listBuffer.size(); + + delete painter; + } + else + { + QPainter* painter=new QPainter; + painter->begin(m_pixPixmap); + if(hasPen) + painter->setPen(SolidPen); + else + painter->setPen(NoPen); + + // Draw the plot + doPlot(painter, x_fact, y_fact, x_offset, y_offset); + painter->end(); + } + + // draw the current pixmap + m_painterP->begin(this); + + m_painterP->drawPixmap(0, 0, *m_pixPixmap); + + m_painterP->end(); } void QtPLWidget::doPlot(QPainter* p, double x_fact, double y_fact, double x_offset, double y_offset) @@ -898,16 +948,16 @@ QVector<qreal> vect; QRectF rect; - QPen SolidPen; - - QPen NoPen(Qt::NoPen); - NoPen.setWidthF(0.); // Cosmetic pen - p->setPen(SolidPen); - bool hasPen=true; +// QPen SolidPen; +// +// QPen NoPen(Qt::NoPen); +// NoPen.setWidthF(0.); // Cosmetic pen +// p->setPen(SolidPen); +// bool hasPen=true; p->setRenderHints(QPainter::Antialiasing, (bool)lines_aa); - QBrush SolidBrush(Qt::SolidPattern); +// QBrush SolidBrush(Qt::SolidPattern); p->setBrush(SolidBrush); QTransform trans; @@ -923,7 +973,7 @@ } // unrolls the buffer and draws each element accordingly - for(QLinkedList<BufferElement>::const_iterator i=m_listBuffer.constBegin(); i!=m_listBuffer.constEnd(); ++i) + for(QLinkedList<BufferElement>::const_iterator i=start_iterator; i!=m_listBuffer.constEnd(); ++i) { switch(i->Element) { @@ -944,6 +994,7 @@ hasPen=true; } p->drawLine(*(i->Data.Line)); + break; case POLYLINE: @@ -1007,6 +1058,12 @@ break; } } + + start_iterator=m_listBuffer.constEnd(); + --start_iterator; + redrawFromLastFlush=false; + redrawAll=false; + } void QtPLWidget::getPlotParameters(double & io_dXFact, double & io_dYFact, double & io_dXOffset, double & io_dYOffset) @@ -1029,12 +1086,6 @@ } } -void QtPLWidget::clear() -{ - clearBuffer(); - setBackgroundColor(bgColour.r, bgColour.g, bgColour.b, bgColour.alpha); -} - #endif #if defined(PLD_extqt) Modified: trunk/drivers/qt.cpp =================================================================== --- trunk/drivers/qt.cpp 2009-08-26 15:22:14 UTC (rev 10345) +++ trunk/drivers/qt.cpp 2009-08-26 15:48:56 UTC (rev 10346) @@ -1077,7 +1077,7 @@ pls->dev_flush=1; /* Driver does not have a clear capability so use (good) PLplot core * fallback for that instead. */ - pls->dev_clear=1; + pls->dev_clear=0; pls->dev_text = 1; // want to draw text pls->dev_unicode = 1; // want unicode @@ -1132,38 +1132,29 @@ switch(op) { - case PLESC_CLEAR: - widget->clear(); -// widget->clearBuffer(); -// widget->setBackgroundColor(pls->cmap0[0].r, pls->cmap0[0].g, pls->cmap0[0].b, pls->cmap0[0].a); - break; case PLESC_FILL: -// std::cout << "fill " <<pls->dev_npts<< std::endl; - xa=new short[pls->dev_npts]; - ya=new short[pls->dev_npts]; + xa=new short[pls->dev_npts]; + ya=new short[pls->dev_npts]; - for (i = 0; i < pls->dev_npts; i++) - { - xa[i] = pls->dev_x[i]; - ya[i] = pls->dev_y[i]; - } + for (i = 0; i < pls->dev_npts; i++) + { + xa[i] = pls->dev_x[i]; + ya[i] = pls->dev_y[i]; + } - widget->setColor(pls->curcolor.r, pls->curcolor.g, pls->curcolor.b, pls->curcolor.a); - widget->drawPolygon(xa, ya, pls->dev_npts); + widget->setColor(pls->curcolor.r, pls->curcolor.g, pls->curcolor.b, pls->curcolor.a); + widget->drawPolygon(xa, ya, pls->dev_npts); - delete[] xa; - delete[] ya; + delete[] xa; + delete[] ya; break; case PLESC_HAS_TEXT: - /*$$ call the generic ProcessString function - ProcessString( pls, (EscText *)ptr ); */ - widget->setColor(pls->curcolor.r, pls->curcolor.g, pls->curcolor.b, pls->curcolor.a); - widget->drawText(pls, (EscText *)ptr); + widget->setColor(pls->curcolor.r, pls->curcolor.g, pls->curcolor.b, pls->curcolor.a); + widget->drawText(pls, (EscText *)ptr); break; case PLESC_FLUSH: -// std::cout << "flush" << std::endl; widget->flush(); break; Modified: trunk/examples/c++/qt_PlotWindow.cpp =================================================================== --- trunk/examples/c++/qt_PlotWindow.cpp 2009-08-26 15:22:14 UTC (rev 10345) +++ trunk/examples/c++/qt_PlotWindow.cpp 2009-08-26 15:48:56 UTC (rev 10346) @@ -89,7 +89,6 @@ } pladv(0); - plot->clear(); plvpor(0.05, 0.95, 0.05, 0.45); plwind(0., 360., -1.2, 1.2); Modified: trunk/examples/c++/qt_example.cpp =================================================================== --- trunk/examples/c++/qt_example.cpp 2009-08-26 15:22:14 UTC (rev 10345) +++ trunk/examples/c++/qt_example.cpp 2009-08-26 15:48:56 UTC (rev 10346) @@ -27,10 +27,32 @@ int main(int argc, char** argv) { + int res; + + // Deep copy of the arguments before QApplication alters them + int Argc=argc; + char** Argv; + + Argv=new char*[argc]; + for(int i=0; i<Argc; ++i) + { + int len=strlen(argv[i])+1; + Argv[i]=new char[len]; + strncpy(Argv[i], argv[i], len); + } + QApplication a( argc, argv ); - PlotWindow* win=new PlotWindow(argc, argv); + PlotWindow* win=new PlotWindow(Argc, Argv); a.setActiveWindow( win ); win->setVisible(true); - return a.exec(); + res=a.exec(); + + for(int i=0; i<Argc; ++i) + { + delete[] Argv[i]; + } + delete[] Argv; + + return res; } Modified: trunk/include/qt.h =================================================================== --- trunk/include/qt.h 2009-08-26 15:22:14 UTC (rev 10345) +++ trunk/include/qt.h 2009-08-26 15:48:56 UTC (rev 10346) @@ -304,7 +304,6 @@ void setWidth(PLINT r); void drawText(PLStream* pls, EscText* txt); void flush(); - void clear(); protected: @@ -314,13 +313,26 @@ void getPlotParameters(double & io_dXFact, double & io_dYFact, double & io_dXOffset, double & io_dYOffset); // gives the parameters to scale and center the plot on the page void doPlot(QPainter* p, double x_fact, double y_fact, double x_offset, double y_offset); // Actually draws the plot. Deported in a function for readability void renderText(QPainter* p, struct TextStruct_* s, double x_fact, double x_offset, double y_fact, double y_offset); - + + void resetPensAndBrushes(QPainter*); + double m_dAspectRatio; // Is kept constant during resizes QPixmap * m_pixPixmap; // stores the drawn image as long as it does not have to be regenerated QLinkedList<BufferElement> m_listBuffer; // Buffer holding the draw instructions - bool m_bAwaitingRedraw; - int m_iOldSize; // Holds the size of the buffer. Modified => image has to be redrawn +// bool m_bAwaitingRedraw; +// int m_iOldSize; // Holds the size of the buffer. Modified => image has to be redrawn + bool redrawFromLastFlush; + bool redrawAll; + + // Pens and brushes required to maintain the status between 2 flushes + QPen SolidPen; + QPen NoPen; + bool hasPen; + QBrush SolidBrush; + // end parameters + + QLinkedList<BufferElement>::const_iterator start_iterator; struct { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |