Skip to content

Commit

Permalink
Threading - WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
wonder-sk committed Oct 31, 2013
1 parent 247e6c7 commit b04f81a
Show file tree
Hide file tree
Showing 18 changed files with 1,444 additions and 266 deletions.
2 changes: 0 additions & 2 deletions python/gui/qgsmapcanvasmap.sip
Expand Up @@ -33,8 +33,6 @@ class QgsMapCanvasMap : QGraphicsRectItem

void enableAntiAliasing( bool flag );

void useImageToRender( bool flag );

//! renders map using QgsMapRenderer to mPixmap
void render();

Expand Down
5 changes: 5 additions & 0 deletions src/app/CMakeLists.txt
Expand Up @@ -462,6 +462,11 @@ ELSE (ANDROID)
ADD_EXECUTABLE(${QGIS_APP_NAME} MACOSX_BUNDLE WIN32 main.cpp ${QGIS_APP_SRCS} ${QGIS_APP_MOC_SRCS} ${IMAGE_RCC_SRCS} ${TEST_RCC_SRCS})
ENDIF (ANDROID)


QT4_WRAP_CPP(tst_moc_srcs maprenderertest.h)
ADD_EXECUTABLE(maprenderertest maprenderertest.cpp ${tst_moc_srcs})
TARGET_LINK_LIBRARIES(maprenderertest qgis_core qgis_gui)

IF (WIN32)
IF (MSVC)
ADD_DEFINITIONS("-DAPP_EXPORT=${DLLEXPORT}")
Expand Down
61 changes: 61 additions & 0 deletions src/app/maprenderertest.cpp
@@ -0,0 +1,61 @@

#include "maprenderertest.h"

#include <QApplication>
#include <QPainter>
#include <QPaintEvent>

#include "qgsapplication.h"
#include "qgsvectorlayer.h"
#include "qgsmaplayerregistry.h"

#include "qgsmapcanvas.h"
#include "qgsmaptoolpan.h"

int main(int argc, char* argv[])
{
QApplication app(argc, argv);

QgsApplication::setPrefixPath("/home/martin/qgis/git-master/creator/output", true);
QgsApplication::initQgis();

QString uri = "dbname='/data/gis/praha.osm.db' table=\"praha_polygons\" (geometry) sql=";
QString uri2 = "dbname='/data/gis/praha.osm.db' table=\"praha_polylines\" (geometry) sql=";
//QString uri = "/data/gis/cr-shp-wgs84/plochy/kraje_pseudo.shp";
QgsVectorLayer* layer = new QgsVectorLayer(uri, "praha", "spatialite");
if (!layer->isValid())
{
qDebug("invalid layer");
return 1;
}
QgsMapLayerRegistry::instance()->addMapLayer(layer);

QgsVectorLayer* layer2 = new QgsVectorLayer(uri2, "praha", "spatialite");
if (!layer2->isValid())
{
qDebug("invalid layer");
return 1;
}
QgsMapLayerRegistry::instance()->addMapLayer(layer2);

// open a window and do the rendering!
/*TestWidget l(layer);
l.resize(360,360);
l.show();*/

QgsMapCanvas canvas;
canvas.setCanvasColor(Qt::white);
canvas.setExtent(layer->extent());

QList<QgsMapCanvasLayer> layers;
layers.append(QgsMapCanvasLayer(layer2));
layers.append(QgsMapCanvasLayer(layer));
canvas.setLayerSet(layers);

QgsMapTool* pan = new QgsMapToolPan(&canvas);
canvas.setMapTool(pan);

canvas.show();

return app.exec();
}
102 changes: 102 additions & 0 deletions src/app/maprenderertest.h
@@ -0,0 +1,102 @@
#ifndef MAPRENDERERTEST_H
#define MAPRENDERERTEST_H

#include <QLabel>
#include <QPainter>
#include <QTimer>
#include <QMouseEvent>

#include "qgsmaprendererv2.h"
#include "qgsmaplayer.h"

class TestWidget : public QLabel
{
Q_OBJECT
public:
TestWidget(QgsMapLayer* layer)
{
//p = QPixmap(200,200);
//p.fill(Qt::red);

i = QImage(size(), QImage::Format_ARGB32_Premultiplied);
i.fill(Qt::gray);

// init renderer
rend.setLayers(QStringList(layer->id()));
rend.setExtent(layer->extent());
rend.setOutputSize(i.size());
rend.setOutputDpi(120);
rend.updateDerived();

if (rend.hasValidSettings())
qDebug("map renderer settings valid");

connect(&rend, SIGNAL(finished()), SLOT(f()));

setPixmap(QPixmap::fromImage(i));

connect(&timer, SIGNAL(timeout()), SLOT(onMapUpdateTimeout()));
timer.setInterval(100);
}

void mousePressEvent(QMouseEvent * event)
{
if (event->button() == Qt::RightButton)
{
qDebug("cancelling!");

rend.cancel();
}
else
{
qDebug("starting!");

if (rend.isRendering())
{
qDebug("need to cancel first!");
rend.cancel();

// TODO: need to ensure that finished slot has been called
}

i.fill(Qt::gray);

painter = new QPainter(&i);
rend.startWithCustomPainter(painter);
timer.start();
}
}

protected slots:
void f()
{
qDebug("finished!");

painter->end();
delete painter;

timer.stop();

//update();

setPixmap(QPixmap::fromImage(i));
}

void onMapUpdateTimeout()
{
qDebug("update timer!");

setPixmap(QPixmap::fromImage(i));
}

protected:
//QPixmap p;
QImage i;
QPainter* painter;
QgsMapRendererV2 rend;
QTimer timer;
};



#endif // MAPRENDERERTEST_H
7 changes: 7 additions & 0 deletions src/core/CMakeLists.txt
Expand Up @@ -3,6 +3,9 @@

SET(QGIS_CORE_SRCS

qgsmaprendererv2.cpp
qgsmaprendererjob.cpp

gps/qgsgpsconnection.cpp
gps/qgsgpsconnectionregistry.cpp
gps/qgsnmeaconnection.cpp
Expand Down Expand Up @@ -293,6 +296,10 @@ ADD_FLEX_FILES(QGIS_CORE_SRCS qgsexpressionlexer.ll)
ADD_BISON_FILES(QGIS_CORE_SRCS qgsexpressionparser.yy)

SET(QGIS_CORE_MOC_HDRS

qgsmaprendererv2.h
qgsmaprendererjob.h

qgsapplication.h
qgsbrowsermodel.h
qgscontexthelp.h
Expand Down
19 changes: 0 additions & 19 deletions src/core/qgsmaplayer.cpp
Expand Up @@ -73,16 +73,11 @@ QgsMapLayer::QgsMapLayer( QgsMapLayer::LayerType type,
mMinScale = 0;
mMaxScale = 100000000;
mScaleBasedVisibility = false;
mpCacheImage = 0;
}

QgsMapLayer::~QgsMapLayer()
{
delete mCRS;
if ( mpCacheImage )
{
delete mpCacheImage;
}
}

QgsMapLayer::LayerType QgsMapLayer::type() const
Expand Down Expand Up @@ -1334,20 +1329,6 @@ void QgsMapLayer::writeCustomProperties( QDomNode & layerNode, QDomDocument & do
layerNode.appendChild( propsElement );
}

void QgsMapLayer::setCacheImage( QImage * thepImage )
{
QgsDebugMsg( "cache Image set!" );
if ( mpCacheImage == thepImage )
return;

if ( mpCacheImage )
{
onCacheImageDelete();
delete mpCacheImage;
}
mpCacheImage = thepImage;
}

bool QgsMapLayer::isEditable() const
{
return false;
Expand Down
23 changes: 6 additions & 17 deletions src/core/qgsmaplayer.h
Expand Up @@ -360,17 +360,11 @@ class CORE_EXPORT QgsMapLayer : public QObject
/** Return pointer to layer's undo stack */
QUndoStack* undoStack();

/** Get the QImage used for caching render operations
* @note This method was added in QGIS 1.4 **/
QImage *cacheImage() { return mpCacheImage; }
/** Set the QImage used for caching render operations
* @note This method was added in QGIS 1.4 **/
void setCacheImage( QImage * thepImage );

/**
* @brief Is called when the cache image is being deleted. Overwrite and use to clean up.
* @note added in 2.0
*/
/** \note Deprecated from 2.1 - returns NULL */
QImage *cacheImage() { return 0; }
/** \note Deprecated from 2.1 - does nothing */
void setCacheImage( QImage * ) {}
/** @note Deprecated from 2.1 - does nothing */
virtual void onCacheImageDelete() {}

public slots:
Expand Down Expand Up @@ -421,8 +415,7 @@ class CORE_EXPORT QgsMapLayer : public QObject
*/
void repaintRequested();

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

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

QMap<QString, QVariant> mCustomProperties;

/**QImage for caching of rendering operations
* @note This property was added in QGIS 1.4 **/
QImage * mpCacheImage;

};

#endif

0 comments on commit b04f81a

Please sign in to comment.