[QGIS Commit] r13932 - branches/threading-branch/src/gui
svn_qgis at osgeo.org
svn_qgis at osgeo.org
Sun Jul 18 18:07:38 EDT 2010
Author: wonder
Date: 2010-07-18 22:07:38 +0000 (Sun, 18 Jul 2010)
New Revision: 13932
Modified:
branches/threading-branch/src/gui/CMakeLists.txt
branches/threading-branch/src/gui/qgsmapcanvas.cpp
branches/threading-branch/src/gui/qgsmapcanvas.h
branches/threading-branch/src/gui/qgsmapcanvasmap.cpp
branches/threading-branch/src/gui/qgsmapcanvasmap.h
branches/threading-branch/src/gui/qgsmapoverviewcanvas.cpp
Log:
QgsMapCanvas::refresh() only stops rendering and marks map as dirty, the rendering is started from the main loop.
(as a result, multiple refresh() calls boil down to only one redraw)
Trigger rendering from QgsMapCanvasMap class - it seems to be more appropriate for that.
Modified: branches/threading-branch/src/gui/CMakeLists.txt
===================================================================
--- branches/threading-branch/src/gui/CMakeLists.txt 2010-07-18 15:07:07 UTC (rev 13931)
+++ branches/threading-branch/src/gui/CMakeLists.txt 2010-07-18 22:07:38 UTC (rev 13932)
@@ -83,6 +83,7 @@
qgsformannotationitem.h
qgsgenericprojectionselector.h
qgsmapcanvas.h
+qgsmapcanvasmap.h
qgsmapoverviewcanvas.h
qgsmaptoolemitpoint.h
qgsmessageviewer.h
Modified: branches/threading-branch/src/gui/qgsmapcanvas.cpp
===================================================================
--- branches/threading-branch/src/gui/qgsmapcanvas.cpp 2010-07-18 15:07:07 UTC (rev 13931)
+++ branches/threading-branch/src/gui/qgsmapcanvas.cpp 2010-07-18 22:07:38 UTC (rev 13932)
@@ -92,7 +92,6 @@
mLastNonZoomMapTool = NULL;
mFrozen = false;
- mDirty = true;
setWheelAction( WheelZoom );
@@ -103,16 +102,16 @@
setFocusPolicy( Qt::StrongFocus );
mMapRenderer = new QgsMapRenderer;
- connect(mMapRenderer, SIGNAL(finishedThreadedRendering(QImage)), SLOT(renderingFinished(QImage)));
// create map canvas item which will show the map
mMap = new QgsMapCanvasMap( this );
mScene->addItem( mMap );
mScene->update(); // porting??
+ connect( mMap, SIGNAL(renderStarting()), this, SIGNAL(renderStarting()) );
+
moveCanvasContents( true );
- connect( &mMapUpdateTimer, SIGNAL(timeout()), this, SLOT(updateMap()));
connect( mMapRenderer, SIGNAL( drawError( QgsMapLayer* ) ), this, SLOT( showError( QgsMapLayer* ) ) );
// project handling
@@ -202,12 +201,12 @@
void QgsMapCanvas::setDirty( bool dirty )
{
- mDirty = dirty;
+ mMap->setDirty(dirty);
}
bool QgsMapCanvas::isDirty() const
{
- return mDirty;
+ return mMap->isDirty();
}
@@ -356,44 +355,20 @@
return mCurrentLayer;
}
-
void QgsMapCanvas::refresh()
{
- if ( !mRenderFlag || mFrozen )
- {
- QgsDebugMsg("REFRESH ignored: canvas frozen");
- return;
- }
+ QgsDebugMsg("refresh called.");
cancelRendering();
- clear();
+ mMap->setDirty(true);
+ mMap->update();
- // Tell the user we're going to be a while
- //QApplication::setOverrideCursor( Qt::WaitCursor );
-
- emit renderStarting();
-
- // TRIGGER RENDERING
- //mMap->render();
- qDebug("STARTING \n\n\n\n\n");
- mMapRenderer->startThreadedRendering();
-
- mMapUpdateTimer.start(250);
-
- updateMap();
-
} // refresh
void QgsMapCanvas::updateMap()
{
- QgsDebugMsg("updating map!");
- QImage i = mMapRenderer->threadedRenderingOutput();
- if (!i.isNull())
- {
- mMap->setMap(i);
- mMap->update();
- }
+ // nop
}
//the format defaults to "PNG" if not specified
@@ -475,11 +450,6 @@
void QgsMapCanvas::setExtent( QgsRectangle const & r )
{
- if ( isDrawing() )
- {
- return;
- }
-
QgsRectangle current = extent();
if ( r.isEmpty() )
@@ -544,11 +514,6 @@
void QgsMapCanvas::zoomToFullExtent()
{
- if ( isDrawing() )
- {
- return;
- }
-
QgsRectangle extent = fullExtent();
// If the full extent is an empty set, don't do the zoom
if ( !extent.isEmpty() )
@@ -565,11 +530,6 @@
void QgsMapCanvas::zoomToPreviousExtent()
{
- if ( isDrawing() )
- {
- return;
- }
-
if ( mLastExtentIndex > 0 )
{
mLastExtentIndex--;
@@ -588,10 +548,6 @@
void QgsMapCanvas::zoomToNextExtent()
{
- if ( isDrawing() )
- {
- return;
- }
if ( mLastExtentIndex < mLastExtent.size() - 1 )
{
mLastExtentIndex++;
@@ -643,11 +599,6 @@
void QgsMapCanvas::zoomToSelected( QgsVectorLayer* layer )
{
- if ( isDrawing() )
- {
- return;
- }
-
if ( layer == NULL )
{
// use current layer by default
@@ -690,12 +641,6 @@
void QgsMapCanvas::keyPressEvent( QKeyEvent * e )
{
-
- if ( isDrawing() )
- {
- e->ignore();
- }
-
emit keyPressed( e );
if ( mCanvasProperties->mouseButtonDown || mCanvasProperties->panSelectorDown )
@@ -792,11 +737,6 @@
{
QgsDebugMsg( "keyRelease event" );
- if ( isDrawing() )
- {
- return;
- }
-
switch ( e->key() )
{
case Qt::Key_Space:
@@ -828,11 +768,6 @@
void QgsMapCanvas::mouseDoubleClickEvent( QMouseEvent * e )
{
- if ( isDrawing() )
- {
- return;
- }
-
// call handler of current map tool
if ( mMapTool )
mMapTool->canvasDoubleClickEvent( e );
@@ -930,12 +865,9 @@
updateCanvasItemPositions();
updateScale();
-#if QT_VERSION >= 0x40600
- // FIXME: temporary workaround for #2714
- QTimer::singleShot( 1, this, SLOT( refresh() ) );
-#else
+
refresh();
-#endif
+
emit extentsChanged();
}
} // resizeEvent
@@ -1030,11 +962,6 @@
void QgsMapCanvas::zoomWithCenter( int x, int y, bool zoomIn )
{
- if ( isDrawing() )
- {
- return;
- }
-
double scaleFactor = ( zoomIn ? 1 / mWheelZoomFactor : mWheelZoomFactor );
// transform the mouse pos to map coordinates
@@ -1169,6 +1096,10 @@
void QgsMapCanvas::freeze( bool frz )
{
mFrozen = frz;
+
+ if (!mFrozen)
+ update();
+
} // freeze
bool QgsMapCanvas::isFrozen()
@@ -1231,11 +1162,6 @@
void QgsMapCanvas::panActionEnd( QPoint releasePoint )
{
- if ( isDrawing() )
- {
- return;
- }
-
// move map image and other items to standard position
moveCanvasContents( true ); // true means reset
@@ -1378,11 +1304,6 @@
void QgsMapCanvas::zoomByFactor( double scaleFactor )
{
- if ( isDrawing() )
- {
- return;
- }
-
QgsRectangle r = mMapRenderer->extent();
r.scale( scaleFactor );
setExtent( r );
@@ -1399,32 +1320,18 @@
void QgsMapCanvas::renderingFinished(QImage img)
{
- QgsDebugMsg("finished!!!");
- mMapUpdateTimer.stop();
-
- mDirty = false;
-
// notify any listeners that rendering is complete
QPainter p;
p.begin( &img );
emit renderComplete( &p );
p.end();
- mMap->setMap(img);
- mMap->update();
-
// notifies current map tool
if ( mMapTool )
mMapTool->renderComplete();
-
- // Tell the user we've finished going to be a while
- //QApplication::restoreOverrideCursor();
}
void QgsMapCanvas::cancelRendering()
{
- if ( isDrawing() )
- {
- mMapRenderer->cancelThreadedRendering();
- }
+ mMap->cancelRendering();
}
Modified: branches/threading-branch/src/gui/qgsmapcanvas.h
===================================================================
--- branches/threading-branch/src/gui/qgsmapcanvas.h 2010-07-18 15:07:07 UTC (rev 13931)
+++ branches/threading-branch/src/gui/qgsmapcanvas.h 2010-07-18 22:07:38 UTC (rev 13932)
@@ -30,7 +30,6 @@
#include <QDomDocument>
#include <QGraphicsView>
#include <QtCore>
-#include <QTimer>
class QWheelEvent;
class QPixmap;
@@ -286,7 +285,7 @@
/** The map units may have changed, so cope with that */
void mapUnitsChanged();
- /** updates pixmap on render progress */
+ /** @deprecated does nothing. map is updated within QgsMapCanvasMap */
void updateMap();
//! show whatever error is exposed by the QgsMapLayer.
@@ -411,17 +410,6 @@
//! Flag indicating if the map canvas is frozen.
bool mFrozen;
- /*! \brief Flag to track the state of the Map canvas.
- *
- * The canvas is
- * flagged as dirty by any operation that changes the state of
- * the layers or the view extent. If the canvas is not dirty, paint
- * events are handled by bit-blitting the stored canvas bitmap to
- * the canvas. This improves performance by not reading the data source
- * when no real change has occurred
- */
- bool mDirty;
-
//! determines whether user has requested to suppress rendering
bool mRenderFlag;
@@ -457,8 +445,6 @@
//! Mouse wheel action
WheelAction mWheelAction;
- QTimer mMapUpdateTimer;
-
}; // class QgsMapCanvas
Modified: branches/threading-branch/src/gui/qgsmapcanvasmap.cpp
===================================================================
--- branches/threading-branch/src/gui/qgsmapcanvasmap.cpp 2010-07-18 15:07:07 UTC (rev 13931)
+++ branches/threading-branch/src/gui/qgsmapcanvasmap.cpp 2010-07-18 22:07:38 UTC (rev 13932)
@@ -29,14 +29,82 @@
resize( QSize( 1, 1 ) );
mUseQImageToRender = false;
+ mDirty = true;
+
+ connect( mCanvas->mapRenderer(), SIGNAL(finishedThreadedRendering(QImage)), SLOT(renderingFinished(QImage)));
+ connect( &mMapUpdateTimer, SIGNAL(timeout()), this, SLOT(updateMap()));
}
void QgsMapCanvasMap::paint( QPainter* p, const QStyleOptionGraphicsItem*, QWidget* )
{
+
+ if ( mDirty )
+ {
+ if ( mCanvas->isDrawing() )
+ {
+ QgsDebugMsg("drawing already started");
+ }
+ else if ( ! mCanvas->renderFlag() || mCanvas->isFrozen() )
+ {
+ QgsDebugMsg("redraw ignored: canvas frozen");
+ }
+ else
+ {
+ emit renderStarting();
+
+ // TRIGGER RENDERING
+ qDebug("STARTING \n\n\n\n\n");
+ mCanvas->mapRenderer()->startThreadedRendering();
+
+ mMapUpdateTimer.start(250);
+
+ updateMap();
+ }
+ }
+ else
+ {
+ QgsDebugMsg("not dirty");
+ }
+
//refreshes the canvas map with the current offscreen image
p->drawPixmap( 0, 0, mPixmap );
}
+void QgsMapCanvasMap::updateMap()
+{
+ QgsDebugMsg("updating map!");
+ QImage i = mCanvas->mapRenderer()->threadedRenderingOutput();
+ if (!i.isNull())
+ {
+ setMap(i);
+ update();
+ }
+}
+
+void QgsMapCanvasMap::renderingFinished(QImage img)
+{
+ QgsDebugMsg("finished!!!");
+
+ mMapUpdateTimer.stop();
+
+ mDirty = false;
+
+ // inform canvas
+ mCanvas->renderingFinished(img);
+
+ setMap(img);
+ update();
+}
+
+void QgsMapCanvasMap::cancelRendering()
+{
+ if ( mCanvas->isDrawing() )
+ {
+ mCanvas->mapRenderer()->cancelThreadedRendering();
+ }
+}
+
+
QRectF QgsMapCanvasMap::boundingRect() const
{
return QRectF( 0, 0, mPixmap.width(), mPixmap.height() );
Modified: branches/threading-branch/src/gui/qgsmapcanvasmap.h
===================================================================
--- branches/threading-branch/src/gui/qgsmapcanvasmap.h 2010-07-18 15:07:07 UTC (rev 13931)
+++ branches/threading-branch/src/gui/qgsmapcanvasmap.h 2010-07-18 22:07:38 UTC (rev 13932)
@@ -19,16 +19,18 @@
#include <QGraphicsRectItem>
#include <QPixmap>
+#include <QTimer>
-
class QgsMapRenderer;
class QgsMapCanvas;
/** \ingroup gui
* A rectangular graphics item representing the map on the canvas.
*/
-class GUI_EXPORT QgsMapCanvasMap : public QGraphicsRectItem
+class GUI_EXPORT QgsMapCanvasMap : public QObject, public QGraphicsRectItem
{
+ Q_OBJECT
+
public:
//! constructor
@@ -66,6 +68,21 @@
void setMap(QImage img) { mPixmap = QPixmap::fromImage(img); }
+ bool isDirty() const { return mDirty; }
+ void setDirty(bool dirty) { mDirty = dirty; }
+
+ //! force stop of the rendering process
+ void cancelRendering();
+
+ public slots:
+ void updateMap();
+
+ //! Called when asynchronous rendering is finished
+ void renderingFinished(QImage img);
+
+ signals:
+ void renderStarting();
+
private:
//! indicates whether antialiasing will be used for rendering
@@ -83,6 +100,20 @@
QColor mBgColor;
QPoint mOffset;
+
+ QTimer mMapUpdateTimer;
+
+ /*! \brief Flag to track the state of the Map canvas.
+ *
+ * The canvas is
+ * flagged as dirty by any operation that changes the state of
+ * the layers or the view extent. If the canvas is not dirty, paint
+ * events are handled by bit-blitting the stored canvas bitmap to
+ * the canvas. This improves performance by not reading the data source
+ * when no real change has occurred
+ */
+ bool mDirty;
+
};
#endif
Modified: branches/threading-branch/src/gui/qgsmapoverviewcanvas.cpp
===================================================================
--- branches/threading-branch/src/gui/qgsmapoverviewcanvas.cpp 2010-07-18 15:07:07 UTC (rev 13931)
+++ branches/threading-branch/src/gui/qgsmapoverviewcanvas.cpp 2010-07-18 22:07:38 UTC (rev 13932)
@@ -163,6 +163,8 @@
mPanningWidget->setGeometry( r );
mPanningWidget->show(); // show if hidden
+
+ repaint();
}
More information about the QGIS-commit
mailing list