@@ -20,18 +20,23 @@ QgsMapRendererSequentialJob::QgsMapRendererSequentialJob(const QgsMapSettings& s
2020 : QgsMapRendererQImageJob(SequentialJob, settings)
2121 , mInternalJob(0 )
2222{
23+ qDebug (" SEQUENTIAL construct" );
2324}
2425
2526QgsMapRendererSequentialJob::~QgsMapRendererSequentialJob ()
2627{
27- delete mInternalJob ;
28+ qDebug (" SEQUENTIAL destruct" );
29+ // delete mInternalJob;
30+ Q_ASSERT (mInternalJob == 0 );
2831}
2932
3033
3134void QgsMapRendererSequentialJob::start ()
3235{
36+ qDebug (" SEQUENTIAL START" );
37+ qDebug (" %d,%d" , mSettings .outputSize ().width (), mSettings .outputSize ().height ());
38+
3339 mImage = QImage (mSettings .outputSize (), QImage::Format_ARGB32_Premultiplied);
34- mImage .fill (Qt::blue);
3540
3641 // 1. create an image where we will output all rendering
3742 mPainter = new QPainter (&mImage );
@@ -47,7 +52,11 @@ void QgsMapRendererSequentialJob::start()
4752void QgsMapRendererSequentialJob::cancel ()
4853{
4954 if (mInternalJob )
55+ {
5056 mInternalJob ->cancel ();
57+ delete mInternalJob ;
58+ mInternalJob = 0 ;
59+ }
5160}
5261
5362
@@ -59,6 +68,8 @@ QImage QgsMapRendererSequentialJob::renderedImage()
5968
6069void QgsMapRendererSequentialJob::internalFinished ()
6170{
71+ qDebug (" SEQUENTIAL finished" );
72+
6273 mPainter ->end ();
6374 delete mPainter ;
6475 mPainter = 0 ;
@@ -78,17 +89,22 @@ QgsMapRendererCustomPainterJob::QgsMapRendererCustomPainterJob(const QgsMapSetti
7889 : QgsMapRendererJob(CustomPainterJob, settings)
7990 , mPainter(painter)
8091{
81- connect (& mFutureWatcher , SIGNAL ( finished ()), SLOT ( futureFinished ()) );
92+ qDebug ( " QPAINTER construct " );
8293}
8394
8495QgsMapRendererCustomPainterJob::~QgsMapRendererCustomPainterJob ()
8596{
86- cancel ();
97+ qDebug (" QPAINTER destruct" );
98+ Q_ASSERT (!mFutureWatcher .isRunning ());
99+ // cancel();
87100}
88101
89102void QgsMapRendererCustomPainterJob::start ()
90103{
91- qDebug (" run!" );
104+ qDebug (" QPAINTER run!" );
105+
106+ connect (&mFutureWatcher , SIGNAL (finished ()), SLOT (futureFinished ()));
107+
92108 mFuture = QtConcurrent::run (staticRender, this );
93109 mFutureWatcher .setFuture (mFuture );
94110}
@@ -99,47 +115,46 @@ void QgsMapRendererCustomPainterJob::cancel()
99115{
100116 if (mFuture .isRunning ())
101117 {
118+ qDebug (" QPAINTER cancelling" );
119+ disconnect (&mFutureWatcher , SIGNAL (finished ()), this , SLOT (futureFinished ()));
120+
102121 mRenderContext .setRenderingStopped (true );
103122
123+ QTime t;
124+ t.start ();
125+
104126 mFutureWatcher .waitForFinished ();
105- qApp->processEvents ( QEventLoop::ExcludeUserInputEvents | QEventLoop::ExcludeSocketNotifiers ); // TODO: necessary?
127+
128+ qDebug (" QPAINER cancel waited %f ms" , t.elapsed () / 1000.0 );
129+
130+ futureFinished ();
131+
132+ qDebug (" QPAINTER cancelled" );
106133 }
107134}
108135
109136
110137void QgsMapRendererCustomPainterJob::futureFinished ()
111138{
112- qDebug (" futureFinished" );
139+ qDebug (" QPAINTER futureFinished" );
113140 emit finished ();
114141}
115142
116143
117144void QgsMapRendererCustomPainterJob::staticRender (QgsMapRendererCustomPainterJob* self)
118145{
119- qDebug (" staticRender" );
120146 self->startRender ();
121147}
122148
123149
124150void QgsMapRendererCustomPainterJob::startRender ()
125151{
126- qDebug (" startRender" );
127- /*
128- for (int i = 0; i < 50; ++i)
129- {
130- if (mStopped)
131- return;
152+ qDebug (" QPAINTER startRender" );
132153
133- mPainter->drawLine(rand() % 360, rand() % 360, rand() % 360, rand() % 360);
134- //QThread::msleep(100);
135- int x = 0;
136- for (int i = 0; i < 1000; i++)
137- {
138- for (int j = 0; j < 10000; j++)
139- x *= x+5;
140- }
141- qDebug("drawn line");
142- }*/
154+ // clear the background
155+ mPainter ->fillRect ( 0 , 0 , mSettings .outputSize ().width (), mSettings .outputSize ().height (), mSettings .backgroundColor () );
156+
157+ mPainter ->setRenderHint ( QPainter::Antialiasing, mSettings .isAntiAliasingEnabled () );
143158
144159#ifdef QGISDEBUG
145160 QgsDebugMsg ( " Starting to render layer stack." );
@@ -163,7 +178,7 @@ void QgsMapRendererCustomPainterJob::startRender()
163178 int myGreen = prj->readNumEntry( "Gui", "/SelectionColorGreenPart", 255 );
164179 int myBlue = prj->readNumEntry( "Gui", "/SelectionColorBluePart", 0 );
165180 int myAlpha = prj->readNumEntry( "Gui", "/SelectionColorAlphaPart", 255 );*/
166- mRenderContext .setSelectionColor ( Qt::red ); // TODO QColor( myRed, myGreen, myBlue, myAlpha ) );
181+ mRenderContext .setSelectionColor ( mSettings . selectionColor () ); // TODO QColor( myRed, myGreen, myBlue, myAlpha ) );
167182
168183 // calculate scale factor
169184 // use the specified dpi and not those from the paint device
0 commit comments