17
17
18
18
#include " qgscomposerpicturewidget.h"
19
19
#include " qgsapplication.h"
20
+ #include " qgscomposermap.h"
20
21
#include " qgscomposerpicture.h"
21
22
#include " qgscomposeritemwidget.h"
22
23
#include < QDoubleValidator>
@@ -34,18 +35,16 @@ QgsComposerPictureWidget::QgsComposerPictureWidget( QgsComposerPicture* picture
34
35
35
36
// add widget for general composer item properties
36
37
QgsComposerItemWidget* itemPropertiesWidget = new QgsComposerItemWidget ( this , picture );
37
- gridLayout->addWidget ( itemPropertiesWidget, 6 , 0 , 1 , 4 );
38
+ gridLayout->addWidget ( itemPropertiesWidget, 8 , 0 , 1 , 4 );
38
39
39
40
mWidthLineEdit ->setValidator ( new QDoubleValidator ( this ) );
40
41
mHeightLineEdit ->setValidator ( new QDoubleValidator ( this ) );
41
-
42
42
setGuiElementValues ();
43
43
44
44
mPreviewListWidget ->setIconSize ( QSize ( 30 , 30 ) );
45
45
46
46
// add preview icons
47
47
addStandardDirectoriesToPreview ();
48
-
49
48
connect ( mPicture , SIGNAL ( settingsChanged () ), this , SLOT ( setGuiElementValues () ) );
50
49
}
51
50
@@ -198,6 +197,118 @@ void QgsComposerPictureWidget::on_mRemoveDirectoryButton_clicked()
198
197
}
199
198
}
200
199
200
+ void QgsComposerPictureWidget::on_mRotationFromComposerMapCheckBox_stateChanged ( int state )
201
+ {
202
+ if ( !mPicture )
203
+ {
204
+ return ;
205
+ }
206
+
207
+ if ( state == Qt::Unchecked )
208
+ {
209
+ mPicture ->setRotationMap ( -1 );
210
+ mRotationSpinBox ->setEnabled ( true );
211
+ mComposerMapComboBox ->setEnabled ( false );
212
+ }
213
+ else
214
+ {
215
+ int currentItemIndex = mComposerMapComboBox ->currentIndex ();
216
+ if ( currentItemIndex == -1 )
217
+ {
218
+ return ;
219
+ }
220
+ int composerId = mComposerMapComboBox ->itemData ( currentItemIndex, Qt::UserRole ).toInt ();
221
+ mPicture ->setRotationMap ( composerId );
222
+ mRotationSpinBox ->setEnabled ( false );
223
+ mComposerMapComboBox ->setEnabled ( true );
224
+ }
225
+ }
226
+
227
+ void QgsComposerPictureWidget::showEvent ( QShowEvent * event )
228
+ {
229
+ refreshMapComboBox ();
230
+ QWidget::showEvent ( event );
231
+ }
232
+
233
+ void QgsComposerPictureWidget::on_mComposerMapComboBox_activated ( const QString & text )
234
+ {
235
+ if ( !mPicture || text.isEmpty () || !mPicture ->useRotationMap () )
236
+ {
237
+ return ;
238
+ }
239
+
240
+ // get composition
241
+ const QgsComposition* composition = mPicture ->composition ();
242
+ if ( !composition )
243
+ {
244
+ return ;
245
+ }
246
+
247
+ // extract id
248
+ int id;
249
+ bool conversionOk;
250
+ QStringList textSplit = text.split ( " " );
251
+ if ( textSplit.size () < 1 )
252
+ {
253
+ return ;
254
+ }
255
+
256
+ QString idString = textSplit.at ( textSplit.size () - 1 );
257
+ id = idString.toInt ( &conversionOk );
258
+
259
+ if ( !conversionOk )
260
+ {
261
+ return ;
262
+ }
263
+
264
+ const QgsComposerMap* composerMap = composition->getComposerMapById ( id );
265
+ if ( !composerMap )
266
+ {
267
+ return ;
268
+ }
269
+ mPicture ->setRotationMap ( id );
270
+ mPicture ->update ();
271
+ }
272
+
273
+ void QgsComposerPictureWidget::refreshMapComboBox ()
274
+ {
275
+ mComposerMapComboBox ->blockSignals ( true );
276
+ // save the current entry in case it is still present after refresh
277
+ QString saveCurrentComboText = mComposerMapComboBox ->currentText ();
278
+
279
+ mComposerMapComboBox ->clear ();
280
+
281
+ if ( mPicture )
282
+ {
283
+ // insert available maps into mMapComboBox
284
+ const QgsComposition* composition = mPicture ->composition ();
285
+ if ( composition )
286
+ {
287
+ QList<const QgsComposerMap*> availableMaps = composition->composerMapItems ();
288
+ QList<const QgsComposerMap*>::const_iterator mapItemIt = availableMaps.constBegin ();
289
+ for ( ; mapItemIt != availableMaps.constEnd (); ++mapItemIt )
290
+ {
291
+ mComposerMapComboBox ->addItem ( tr ( " Map %1" ).arg (( *mapItemIt )->id () ), ( *mapItemIt )->id () );
292
+ }
293
+ }
294
+ }
295
+
296
+ if ( !saveCurrentComboText.isEmpty () )
297
+ {
298
+ if ( mComposerMapComboBox ->findText ( saveCurrentComboText ) == -1 )
299
+ {
300
+ // the former entry is no longer present. Inform the scalebar about the changed composer map
301
+ on_mComposerMapComboBox_activated ( mComposerMapComboBox ->currentText () );
302
+ }
303
+ else
304
+ {
305
+ // the former entry is still present. Make it the current entry again
306
+ mComposerMapComboBox ->setCurrentIndex ( mComposerMapComboBox ->findText ( saveCurrentComboText ) );
307
+ }
308
+ }
309
+ mComposerMapComboBox ->blockSignals ( false );
310
+ }
311
+
201
312
void QgsComposerPictureWidget::setGuiElementValues ()
202
313
{
203
314
// set initial gui values
@@ -207,17 +318,43 @@ void QgsComposerPictureWidget::setGuiElementValues()
207
318
mHeightLineEdit ->blockSignals ( true );
208
319
mRotationSpinBox ->blockSignals ( true );
209
320
mPictureLineEdit ->blockSignals ( true );
321
+ mComposerMapComboBox ->blockSignals ( true );
322
+ mRotationFromComposerMapCheckBox ->blockSignals ( true );
210
323
211
324
mPictureLineEdit ->setText ( mPicture ->pictureFile () );
212
325
QRectF pictureRect = mPicture ->rect ();
213
326
mWidthLineEdit ->setText ( QString::number ( pictureRect.width () ) );
214
327
mHeightLineEdit ->setText ( QString::number ( pictureRect.height () ) );
215
328
mRotationSpinBox ->setValue ( mPicture ->rotation () );
216
329
330
+ refreshMapComboBox ();
331
+
332
+ if ( mPicture ->useRotationMap () )
333
+ {
334
+ mRotationFromComposerMapCheckBox ->setCheckState ( Qt::Checked );
335
+ mRotationSpinBox ->setEnabled ( false );
336
+ mComposerMapComboBox ->setEnabled ( true );
337
+ QString mapText = tr ( " Map %1" ).arg ( mPicture ->rotationMap () );
338
+ int itemId = mComposerMapComboBox ->findText ( mapText );
339
+ if ( itemId >= 0 )
340
+ {
341
+ mComposerMapComboBox ->setCurrentIndex ( itemId );
342
+ }
343
+ }
344
+ else
345
+ {
346
+ mRotationFromComposerMapCheckBox ->setCheckState ( Qt::Unchecked );
347
+ mRotationSpinBox ->setEnabled ( true );
348
+ mComposerMapComboBox ->setEnabled ( false );
349
+ }
350
+
351
+
352
+ mRotationFromComposerMapCheckBox ->blockSignals ( false );
217
353
mWidthLineEdit ->blockSignals ( false );
218
354
mHeightLineEdit ->blockSignals ( false );
219
355
mRotationSpinBox ->blockSignals ( false );
220
356
mPictureLineEdit ->blockSignals ( false );
357
+ mComposerMapComboBox ->blockSignals ( false );
221
358
}
222
359
}
223
360
@@ -302,7 +439,8 @@ void QgsComposerPictureWidget::addStandardDirectoriesToPreview()
302
439
{
303
440
// list all directories in $prefix/share/qgis/svg
304
441
QStringList svgPaths = QgsApplication::svgPaths ();
305
- for (int i=0 ; i<svgPaths.size (); i++) {
442
+ for ( int i = 0 ; i < svgPaths.size (); i++ )
443
+ {
306
444
QDir svgDirectory ( svgPaths[i] );
307
445
if ( !svgDirectory.exists () || !svgDirectory.isReadable () )
308
446
{
@@ -315,7 +453,7 @@ void QgsComposerPictureWidget::addStandardDirectoriesToPreview()
315
453
{
316
454
if ( addDirectoryToPreview ( dirIt->absoluteFilePath () ) == 0 )
317
455
{
318
- mSearchDirectoriesComboBox ->addItem ( dirIt->absoluteFilePath () );
456
+ mSearchDirectoriesComboBox ->addItem ( dirIt->absoluteFilePath () );
319
457
}
320
458
}
321
459
}
0 commit comments