Skip to content

Commit b04f81a

Browse files
committed
Threading - WIP
1 parent 247e6c7 commit b04f81a

18 files changed

+1444
-266
lines changed

python/gui/qgsmapcanvasmap.sip

-2
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,6 @@ class QgsMapCanvasMap : QGraphicsRectItem
3333

3434
void enableAntiAliasing( bool flag );
3535

36-
void useImageToRender( bool flag );
37-
3836
//! renders map using QgsMapRenderer to mPixmap
3937
void render();
4038

src/app/CMakeLists.txt

+5
Original file line numberDiff line numberDiff line change
@@ -462,6 +462,11 @@ ELSE (ANDROID)
462462
ADD_EXECUTABLE(${QGIS_APP_NAME} MACOSX_BUNDLE WIN32 main.cpp ${QGIS_APP_SRCS} ${QGIS_APP_MOC_SRCS} ${IMAGE_RCC_SRCS} ${TEST_RCC_SRCS})
463463
ENDIF (ANDROID)
464464

465+
466+
QT4_WRAP_CPP(tst_moc_srcs maprenderertest.h)
467+
ADD_EXECUTABLE(maprenderertest maprenderertest.cpp ${tst_moc_srcs})
468+
TARGET_LINK_LIBRARIES(maprenderertest qgis_core qgis_gui)
469+
465470
IF (WIN32)
466471
IF (MSVC)
467472
ADD_DEFINITIONS("-DAPP_EXPORT=${DLLEXPORT}")

src/app/maprenderertest.cpp

+61
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
2+
#include "maprenderertest.h"
3+
4+
#include <QApplication>
5+
#include <QPainter>
6+
#include <QPaintEvent>
7+
8+
#include "qgsapplication.h"
9+
#include "qgsvectorlayer.h"
10+
#include "qgsmaplayerregistry.h"
11+
12+
#include "qgsmapcanvas.h"
13+
#include "qgsmaptoolpan.h"
14+
15+
int main(int argc, char* argv[])
16+
{
17+
QApplication app(argc, argv);
18+
19+
QgsApplication::setPrefixPath("/home/martin/qgis/git-master/creator/output", true);
20+
QgsApplication::initQgis();
21+
22+
QString uri = "dbname='/data/gis/praha.osm.db' table=\"praha_polygons\" (geometry) sql=";
23+
QString uri2 = "dbname='/data/gis/praha.osm.db' table=\"praha_polylines\" (geometry) sql=";
24+
//QString uri = "/data/gis/cr-shp-wgs84/plochy/kraje_pseudo.shp";
25+
QgsVectorLayer* layer = new QgsVectorLayer(uri, "praha", "spatialite");
26+
if (!layer->isValid())
27+
{
28+
qDebug("invalid layer");
29+
return 1;
30+
}
31+
QgsMapLayerRegistry::instance()->addMapLayer(layer);
32+
33+
QgsVectorLayer* layer2 = new QgsVectorLayer(uri2, "praha", "spatialite");
34+
if (!layer2->isValid())
35+
{
36+
qDebug("invalid layer");
37+
return 1;
38+
}
39+
QgsMapLayerRegistry::instance()->addMapLayer(layer2);
40+
41+
// open a window and do the rendering!
42+
/*TestWidget l(layer);
43+
l.resize(360,360);
44+
l.show();*/
45+
46+
QgsMapCanvas canvas;
47+
canvas.setCanvasColor(Qt::white);
48+
canvas.setExtent(layer->extent());
49+
50+
QList<QgsMapCanvasLayer> layers;
51+
layers.append(QgsMapCanvasLayer(layer2));
52+
layers.append(QgsMapCanvasLayer(layer));
53+
canvas.setLayerSet(layers);
54+
55+
QgsMapTool* pan = new QgsMapToolPan(&canvas);
56+
canvas.setMapTool(pan);
57+
58+
canvas.show();
59+
60+
return app.exec();
61+
}

src/app/maprenderertest.h

+102
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
#ifndef MAPRENDERERTEST_H
2+
#define MAPRENDERERTEST_H
3+
4+
#include <QLabel>
5+
#include <QPainter>
6+
#include <QTimer>
7+
#include <QMouseEvent>
8+
9+
#include "qgsmaprendererv2.h"
10+
#include "qgsmaplayer.h"
11+
12+
class TestWidget : public QLabel
13+
{
14+
Q_OBJECT
15+
public:
16+
TestWidget(QgsMapLayer* layer)
17+
{
18+
//p = QPixmap(200,200);
19+
//p.fill(Qt::red);
20+
21+
i = QImage(size(), QImage::Format_ARGB32_Premultiplied);
22+
i.fill(Qt::gray);
23+
24+
// init renderer
25+
rend.setLayers(QStringList(layer->id()));
26+
rend.setExtent(layer->extent());
27+
rend.setOutputSize(i.size());
28+
rend.setOutputDpi(120);
29+
rend.updateDerived();
30+
31+
if (rend.hasValidSettings())
32+
qDebug("map renderer settings valid");
33+
34+
connect(&rend, SIGNAL(finished()), SLOT(f()));
35+
36+
setPixmap(QPixmap::fromImage(i));
37+
38+
connect(&timer, SIGNAL(timeout()), SLOT(onMapUpdateTimeout()));
39+
timer.setInterval(100);
40+
}
41+
42+
void mousePressEvent(QMouseEvent * event)
43+
{
44+
if (event->button() == Qt::RightButton)
45+
{
46+
qDebug("cancelling!");
47+
48+
rend.cancel();
49+
}
50+
else
51+
{
52+
qDebug("starting!");
53+
54+
if (rend.isRendering())
55+
{
56+
qDebug("need to cancel first!");
57+
rend.cancel();
58+
59+
// TODO: need to ensure that finished slot has been called
60+
}
61+
62+
i.fill(Qt::gray);
63+
64+
painter = new QPainter(&i);
65+
rend.startWithCustomPainter(painter);
66+
timer.start();
67+
}
68+
}
69+
70+
protected slots:
71+
void f()
72+
{
73+
qDebug("finished!");
74+
75+
painter->end();
76+
delete painter;
77+
78+
timer.stop();
79+
80+
//update();
81+
82+
setPixmap(QPixmap::fromImage(i));
83+
}
84+
85+
void onMapUpdateTimeout()
86+
{
87+
qDebug("update timer!");
88+
89+
setPixmap(QPixmap::fromImage(i));
90+
}
91+
92+
protected:
93+
//QPixmap p;
94+
QImage i;
95+
QPainter* painter;
96+
QgsMapRendererV2 rend;
97+
QTimer timer;
98+
};
99+
100+
101+
102+
#endif // MAPRENDERERTEST_H

src/core/CMakeLists.txt

+7
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33

44
SET(QGIS_CORE_SRCS
55

6+
qgsmaprendererv2.cpp
7+
qgsmaprendererjob.cpp
8+
69
gps/qgsgpsconnection.cpp
710
gps/qgsgpsconnectionregistry.cpp
811
gps/qgsnmeaconnection.cpp
@@ -293,6 +296,10 @@ ADD_FLEX_FILES(QGIS_CORE_SRCS qgsexpressionlexer.ll)
293296
ADD_BISON_FILES(QGIS_CORE_SRCS qgsexpressionparser.yy)
294297

295298
SET(QGIS_CORE_MOC_HDRS
299+
300+
qgsmaprendererv2.h
301+
qgsmaprendererjob.h
302+
296303
qgsapplication.h
297304
qgsbrowsermodel.h
298305
qgscontexthelp.h

src/core/qgsmaplayer.cpp

-19
Original file line numberDiff line numberDiff line change
@@ -73,16 +73,11 @@ QgsMapLayer::QgsMapLayer( QgsMapLayer::LayerType type,
7373
mMinScale = 0;
7474
mMaxScale = 100000000;
7575
mScaleBasedVisibility = false;
76-
mpCacheImage = 0;
7776
}
7877

7978
QgsMapLayer::~QgsMapLayer()
8079
{
8180
delete mCRS;
82-
if ( mpCacheImage )
83-
{
84-
delete mpCacheImage;
85-
}
8681
}
8782

8883
QgsMapLayer::LayerType QgsMapLayer::type() const
@@ -1334,20 +1329,6 @@ void QgsMapLayer::writeCustomProperties( QDomNode & layerNode, QDomDocument & do
13341329
layerNode.appendChild( propsElement );
13351330
}
13361331

1337-
void QgsMapLayer::setCacheImage( QImage * thepImage )
1338-
{
1339-
QgsDebugMsg( "cache Image set!" );
1340-
if ( mpCacheImage == thepImage )
1341-
return;
1342-
1343-
if ( mpCacheImage )
1344-
{
1345-
onCacheImageDelete();
1346-
delete mpCacheImage;
1347-
}
1348-
mpCacheImage = thepImage;
1349-
}
1350-
13511332
bool QgsMapLayer::isEditable() const
13521333
{
13531334
return false;

src/core/qgsmaplayer.h

+6-17
Original file line numberDiff line numberDiff line change
@@ -360,17 +360,11 @@ class CORE_EXPORT QgsMapLayer : public QObject
360360
/** Return pointer to layer's undo stack */
361361
QUndoStack* undoStack();
362362

363-
/** Get the QImage used for caching render operations
364-
* @note This method was added in QGIS 1.4 **/
365-
QImage *cacheImage() { return mpCacheImage; }
366-
/** Set the QImage used for caching render operations
367-
* @note This method was added in QGIS 1.4 **/
368-
void setCacheImage( QImage * thepImage );
369-
370-
/**
371-
* @brief Is called when the cache image is being deleted. Overwrite and use to clean up.
372-
* @note added in 2.0
373-
*/
363+
/** \note Deprecated from 2.1 - returns NULL */
364+
QImage *cacheImage() { return 0; }
365+
/** \note Deprecated from 2.1 - does nothing */
366+
void setCacheImage( QImage * ) {}
367+
/** @note Deprecated from 2.1 - does nothing */
374368
virtual void onCacheImageDelete() {}
375369

376370
public slots:
@@ -421,8 +415,7 @@ class CORE_EXPORT QgsMapLayer : public QObject
421415
*/
422416
void repaintRequested();
423417

424-
/**The layer emits this signal when a screen update is requested.
425-
This signal should be connected with the slot QgsMapCanvas::updateMap()*/
418+
//! \note Deprecated in 2.1 and not emitted anymore
426419
void screenUpdateRequested();
427420

428421
/** This is used to send a request that any mapcanvas using this layer update its extents */
@@ -544,10 +537,6 @@ class CORE_EXPORT QgsMapLayer : public QObject
544537

545538
QMap<QString, QVariant> mCustomProperties;
546539

547-
/**QImage for caching of rendering operations
548-
* @note This property was added in QGIS 1.4 **/
549-
QImage * mpCacheImage;
550-
551540
};
552541

553542
#endif

0 commit comments

Comments
 (0)