-
-
Notifications
You must be signed in to change notification settings - Fork 3k
/
qgscomposerscalebarwidget.cpp
679 lines (595 loc) · 22.1 KB
/
qgscomposerscalebarwidget.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
/***************************************************************************
qgscomposerscalebarwidget.cpp
-----------------------------
begin : 11 June 2008
copyright : (C) 2008 by Marco Hugentobler
email : marco dot hugentobler at karto dot baug dot ethz dot ch
***************************************************************************/
/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
#include "qgscomposerscalebarwidget.h"
#include "qgscomposeritemwidget.h"
#include "qgscomposermap.h"
#include "qgscomposerscalebar.h"
#include "qgscomposition.h"
#include "qgsguiutils.h"
#include <QColorDialog>
#include <QFontDialog>
#include <QWidget>
QgsComposerScaleBarWidget::QgsComposerScaleBarWidget( QgsComposerScaleBar *scaleBar ): QgsComposerItemBaseWidget( nullptr, scaleBar ), mComposerScaleBar( scaleBar )
{
setupUi( this );
setPanelTitle( tr( "Scalebar properties" ) );
mFontButton->setMode( QgsFontButton::ModeQFont );
connectUpdateSignal();
//add widget for general composer item properties
QgsComposerItemWidget *itemPropertiesWidget = new QgsComposerItemWidget( this, scaleBar );
mainLayout->addWidget( itemPropertiesWidget );
mSegmentSizeRadioGroup.addButton( mFixedSizeRadio );
mSegmentSizeRadioGroup.addButton( mFitWidthRadio );
connect( &mSegmentSizeRadioGroup, static_cast < void ( QButtonGroup::* )( QAbstractButton * ) > ( &QButtonGroup::buttonClicked ), this, &QgsComposerScaleBarWidget::segmentSizeRadioChanged );
blockMemberSignals( true );
//style combo box
mStyleComboBox->insertItem( 0, tr( "Single Box" ) );
mStyleComboBox->insertItem( 1, tr( "Double Box" ) );
mStyleComboBox->insertItem( 2, tr( "Line Ticks Middle" ) );
mStyleComboBox->insertItem( 3, tr( "Line Ticks Down" ) );
mStyleComboBox->insertItem( 4, tr( "Line Ticks Up" ) );
mStyleComboBox->insertItem( 5, tr( "Numeric" ) );
//alignment combo box
mAlignmentComboBox->insertItem( 0, tr( "Left" ) );
mAlignmentComboBox->insertItem( 1, tr( "Middle" ) );
mAlignmentComboBox->insertItem( 2, tr( "Right" ) );
//units combo box
mUnitsComboBox->insertItem( 0, tr( "Map units" ), QgsUnitTypes::DistanceUnknownUnit );
mUnitsComboBox->insertItem( 1, tr( "Meters" ), QgsUnitTypes::DistanceMeters );
mUnitsComboBox->insertItem( 2, tr( "Feet" ), QgsUnitTypes::DistanceFeet );
mUnitsComboBox->insertItem( 3, tr( "Nautical Miles" ), QgsUnitTypes::DistanceNauticalMiles );
mFillColorButton->setColorDialogTitle( tr( "Select Fill Color" ) );
mFillColorButton->setAllowOpacity( true );
mFillColorButton->setContext( QStringLiteral( "composer" ) );
mFillColorButton->setNoColorString( tr( "Transparent Fill" ) );
mFillColorButton->setShowNoColor( true );
mFillColor2Button->setColorDialogTitle( tr( "Select Alternate Fill Color" ) );
mFillColor2Button->setAllowOpacity( true );
mFillColor2Button->setContext( QStringLiteral( "composer" ) );
mFillColor2Button->setNoColorString( tr( "Transparent fill" ) );
mFillColor2Button->setShowNoColor( true );
mFontColorButton->setColorDialogTitle( tr( "Select Font Color" ) );
mFontColorButton->setAllowOpacity( true );
mFontColorButton->setContext( QStringLiteral( "composer" ) );
mStrokeColorButton->setColorDialogTitle( tr( "Select Line Color" ) );
mStrokeColorButton->setAllowOpacity( true );
mStrokeColorButton->setContext( QStringLiteral( "composer" ) );
mStrokeColorButton->setNoColorString( tr( "Transparent line" ) );
mStrokeColorButton->setShowNoColor( true );
QgsComposition *scaleBarComposition = mComposerScaleBar->composition();
if ( scaleBarComposition )
{
mMapItemComboBox->setComposition( scaleBarComposition );
mMapItemComboBox->setItemType( QgsComposerItem::ComposerMap );
}
connect( mMapItemComboBox, &QgsComposerItemComboBox::itemChanged, this, &QgsComposerScaleBarWidget::composerMapChanged );
registerDataDefinedButton( mFillColorDDBtn, QgsComposerObject::ScalebarFillColor );
registerDataDefinedButton( mFillColor2DDBtn, QgsComposerObject::ScalebarFillColor2 );
registerDataDefinedButton( mLineColorDDBtn, QgsComposerObject::ScalebarLineColor );
registerDataDefinedButton( mLineWidthDDBtn, QgsComposerObject::ScalebarLineWidth );
blockMemberSignals( false );
setGuiElements(); //set the GUI elements to the state of scaleBar
connect( mFontButton, &QgsFontButton::changed, this, &QgsComposerScaleBarWidget::fontChanged );
}
void QgsComposerScaleBarWidget::setGuiElements()
{
if ( !mComposerScaleBar )
{
return;
}
blockMemberSignals( true );
mNumberOfSegmentsSpinBox->setValue( mComposerScaleBar->numSegments() );
mSegmentsLeftSpinBox->setValue( mComposerScaleBar->numSegmentsLeft() );
mSegmentSizeSpinBox->setValue( mComposerScaleBar->numUnitsPerSegment() );
mLineWidthSpinBox->setValue( mComposerScaleBar->lineWidth() );
mHeightSpinBox->setValue( mComposerScaleBar->height() );
mMapUnitsPerBarUnitSpinBox->setValue( mComposerScaleBar->numMapUnitsPerScaleBarUnit() );
mLabelBarSpaceSpinBox->setValue( mComposerScaleBar->labelBarSpace() );
mBoxSizeSpinBox->setValue( mComposerScaleBar->boxContentSpace() );
mUnitLabelLineEdit->setText( mComposerScaleBar->unitLabeling() );
mLineJoinStyleCombo->setPenJoinStyle( mComposerScaleBar->lineJoinStyle() );
mLineCapStyleCombo->setPenCapStyle( mComposerScaleBar->lineCapStyle() );
mFontColorButton->setColor( mComposerScaleBar->fontColor() );
mFillColorButton->setColor( mComposerScaleBar->fillColor() );
mFillColor2Button->setColor( mComposerScaleBar->fillColor2() );
mStrokeColorButton->setColor( mComposerScaleBar->lineColor() );
mFontButton->setCurrentFont( mComposerScaleBar->font() );
//map combo box
mMapItemComboBox->setItem( mComposerScaleBar->composerMap() );
//style...
QString style = mComposerScaleBar->style();
mStyleComboBox->setCurrentIndex( mStyleComboBox->findText( tr( style.toLocal8Bit().data() ) ) );
toggleStyleSpecificControls( style );
//alignment
mAlignmentComboBox->setCurrentIndex( ( int )( mComposerScaleBar->alignment() ) );
//units
mUnitsComboBox->setCurrentIndex( mUnitsComboBox->findData( ( int )mComposerScaleBar->units() ) );
if ( mComposerScaleBar->segmentSizeMode() == QgsScaleBarSettings::SegmentSizeFixed )
{
mFixedSizeRadio->setChecked( true );
mSegmentSizeSpinBox->setEnabled( true );
mMinWidthSpinBox->setEnabled( false );
mMaxWidthSpinBox->setEnabled( false );
}
else /*if(mComposerScaleBar->segmentSizeMode() == QgsComposerScaleBar::SegmentSizeFitWidth)*/
{
mFitWidthRadio->setChecked( true );
mSegmentSizeSpinBox->setEnabled( false );
mMinWidthSpinBox->setEnabled( true );
mMaxWidthSpinBox->setEnabled( true );
}
mMinWidthSpinBox->setValue( mComposerScaleBar->minBarWidth() );
mMaxWidthSpinBox->setValue( mComposerScaleBar->maxBarWidth() );
updateDataDefinedButton( mFillColorDDBtn );
updateDataDefinedButton( mFillColor2DDBtn );
updateDataDefinedButton( mLineColorDDBtn );
updateDataDefinedButton( mLineWidthDDBtn );
blockMemberSignals( false );
}
//slots
void QgsComposerScaleBarWidget::on_mLineWidthSpinBox_valueChanged( double d )
{
if ( !mComposerScaleBar )
{
return;
}
mComposerScaleBar->beginCommand( tr( "Scalebar line width" ), QgsComposerMergeCommand::ScaleBarLineWidth );
disconnectUpdateSignal();
mComposerScaleBar->setLineWidth( d );
mComposerScaleBar->update();
connectUpdateSignal();
mComposerScaleBar->endCommand();
}
void QgsComposerScaleBarWidget::on_mSegmentSizeSpinBox_valueChanged( double d )
{
if ( !mComposerScaleBar )
{
return;
}
mComposerScaleBar->beginCommand( tr( "Scalebar segment size" ), QgsComposerMergeCommand::ScaleBarSegmentSize );
disconnectUpdateSignal();
mComposerScaleBar->setNumUnitsPerSegment( d );
mComposerScaleBar->update();
connectUpdateSignal();
mComposerScaleBar->endCommand();
}
void QgsComposerScaleBarWidget::on_mSegmentsLeftSpinBox_valueChanged( int i )
{
if ( !mComposerScaleBar )
{
return;
}
mComposerScaleBar->beginCommand( tr( "Scalebar segments left" ), QgsComposerMergeCommand::ScaleBarSegmentsLeft );
disconnectUpdateSignal();
mComposerScaleBar->setNumSegmentsLeft( i );
mComposerScaleBar->update();
connectUpdateSignal();
mComposerScaleBar->endCommand();
}
void QgsComposerScaleBarWidget::on_mNumberOfSegmentsSpinBox_valueChanged( int i )
{
if ( !mComposerScaleBar )
{
return;
}
mComposerScaleBar->beginCommand( tr( "Number of scalebar segments changed" ), QgsComposerMergeCommand::ScaleBarNSegments );
disconnectUpdateSignal();
mComposerScaleBar->setNumSegments( i );
mComposerScaleBar->update();
connectUpdateSignal();
mComposerScaleBar->endCommand();
}
void QgsComposerScaleBarWidget::on_mHeightSpinBox_valueChanged( double d )
{
if ( !mComposerScaleBar )
{
return;
}
mComposerScaleBar->beginCommand( tr( "Scalebar height changed" ), QgsComposerMergeCommand::ScaleBarHeight );
disconnectUpdateSignal();
mComposerScaleBar->setHeight( d );
mComposerScaleBar->update();
connectUpdateSignal();
mComposerScaleBar->endCommand();
}
void QgsComposerScaleBarWidget::fontChanged()
{
if ( !mComposerScaleBar )
{
return;
}
mComposerScaleBar->beginCommand( tr( "Scalebar font changed" ) );
disconnectUpdateSignal();
mComposerScaleBar->setFont( mFontButton->currentFont() );
connectUpdateSignal();
mComposerScaleBar->endCommand();
mComposerScaleBar->update();
}
void QgsComposerScaleBarWidget::on_mFontColorButton_colorChanged( const QColor &newColor )
{
if ( !mComposerScaleBar )
{
return;
}
mComposerScaleBar->beginCommand( tr( "Scalebar font color changed" ), QgsComposerMergeCommand::ScaleBarFontColor );
disconnectUpdateSignal();
mComposerScaleBar->setFontColor( newColor );
mComposerScaleBar->update();
connectUpdateSignal();
mComposerScaleBar->endCommand();
}
void QgsComposerScaleBarWidget::on_mFillColorButton_colorChanged( const QColor &newColor )
{
if ( !mComposerScaleBar )
{
return;
}
mComposerScaleBar->beginCommand( tr( "Scalebar color changed" ), QgsComposerMergeCommand::ScaleBarFillColor );
disconnectUpdateSignal();
mComposerScaleBar->setFillColor( newColor );
mComposerScaleBar->update();
connectUpdateSignal();
mComposerScaleBar->endCommand();
}
void QgsComposerScaleBarWidget::on_mFillColor2Button_colorChanged( const QColor &newColor )
{
if ( !mComposerScaleBar )
{
return;
}
mComposerScaleBar->beginCommand( tr( "Scalebar secondary color changed" ), QgsComposerMergeCommand::ScaleBarFill2Color );
disconnectUpdateSignal();
mComposerScaleBar->setFillColor2( newColor );
mComposerScaleBar->update();
connectUpdateSignal();
mComposerScaleBar->endCommand();
}
void QgsComposerScaleBarWidget::on_mStrokeColorButton_colorChanged( const QColor &newColor )
{
if ( !mComposerScaleBar )
{
return;
}
mComposerScaleBar->beginCommand( tr( "Scalebar line color changed" ), QgsComposerMergeCommand::ScaleBarStrokeColor );
disconnectUpdateSignal();
mComposerScaleBar->setLineColor( newColor );
mComposerScaleBar->update();
connectUpdateSignal();
mComposerScaleBar->endCommand();
}
void QgsComposerScaleBarWidget::on_mUnitLabelLineEdit_textChanged( const QString &text )
{
if ( !mComposerScaleBar )
{
return;
}
mComposerScaleBar->beginCommand( tr( "Scalebar unit text" ), QgsComposerMergeCommand::ScaleBarUnitText );
disconnectUpdateSignal();
mComposerScaleBar->setUnitLabeling( text );
mComposerScaleBar->update();
connectUpdateSignal();
mComposerScaleBar->endCommand();
}
void QgsComposerScaleBarWidget::on_mMapUnitsPerBarUnitSpinBox_valueChanged( double d )
{
if ( !mComposerScaleBar )
{
return;
}
mComposerScaleBar->beginCommand( tr( "Scalebar map units per segment" ), QgsComposerMergeCommand::ScaleBarMapUnitsSegment );
disconnectUpdateSignal();
mComposerScaleBar->setNumMapUnitsPerScaleBarUnit( d );
mComposerScaleBar->update();
connectUpdateSignal();
mComposerScaleBar->endCommand();
}
void QgsComposerScaleBarWidget::on_mStyleComboBox_currentIndexChanged( const QString &text )
{
if ( !mComposerScaleBar )
{
return;
}
mComposerScaleBar->beginCommand( tr( "Scalebar style changed" ) );
disconnectUpdateSignal();
QString untranslatedStyleName;
if ( text == tr( "Single Box" ) )
{
untranslatedStyleName = QStringLiteral( "Single Box" );
}
else if ( text == tr( "Double Box" ) )
{
untranslatedStyleName = QStringLiteral( "Double Box" );
}
else if ( text == tr( "Line Ticks Middle" ) )
{
untranslatedStyleName = QStringLiteral( "Line Ticks Middle" );
}
else if ( text == tr( "Line Ticks Middle" ) )
{
untranslatedStyleName = QStringLiteral( "Line Ticks Middle" );
}
else if ( text == tr( "Line Ticks Down" ) )
{
untranslatedStyleName = QStringLiteral( "Line Ticks Down" );
}
else if ( text == tr( "Line Ticks Up" ) )
{
untranslatedStyleName = QStringLiteral( "Line Ticks Up" );
}
else if ( text == tr( "Numeric" ) )
{
untranslatedStyleName = QStringLiteral( "Numeric" );
}
//disable or enable controls which apply to specific scale bar styles
toggleStyleSpecificControls( untranslatedStyleName );
mComposerScaleBar->setStyle( untranslatedStyleName );
mComposerScaleBar->update();
connectUpdateSignal();
mComposerScaleBar->endCommand();
}
void QgsComposerScaleBarWidget::toggleStyleSpecificControls( const QString &style )
{
if ( style == QLatin1String( "Numeric" ) )
{
//Disable controls which don't apply to numeric scale bars
mGroupBoxUnits->setEnabled( false );
mGroupBoxUnits->setCollapsed( true );
mGroupBoxSegments->setEnabled( false );
mGroupBoxSegments->setCollapsed( true );
mLabelBarSpaceSpinBox->setEnabled( false );
mLineWidthSpinBox->setEnabled( false );
mFillColorButton->setEnabled( false );
mFillColor2Button->setEnabled( false );
mStrokeColorButton->setEnabled( false );
mLineJoinStyleCombo->setEnabled( false );
mLineCapStyleCombo->setEnabled( false );
}
else
{
//Enable controls
mGroupBoxUnits->setEnabled( true );
mGroupBoxSegments->setEnabled( true );
mLabelBarSpaceSpinBox->setEnabled( true );
mLineWidthSpinBox->setEnabled( true );
mFillColorButton->setEnabled( true );
mFillColor2Button->setEnabled( true );
mStrokeColorButton->setEnabled( true );
if ( style == QLatin1String( "Single Box" ) || style == QLatin1String( "Double Box" ) )
{
mLineJoinStyleCombo->setEnabled( true );
mLineCapStyleCombo->setEnabled( false );
}
else
{
mLineJoinStyleCombo->setEnabled( false );
mLineCapStyleCombo->setEnabled( true );
}
}
}
void QgsComposerScaleBarWidget::on_mLabelBarSpaceSpinBox_valueChanged( double d )
{
if ( !mComposerScaleBar )
{
return;
}
mComposerScaleBar->beginCommand( tr( "Scalebar label bar space" ), QgsComposerMergeCommand::ScaleBarLabelBarSize );
disconnectUpdateSignal();
mComposerScaleBar->setLabelBarSpace( d );
mComposerScaleBar->update();
connectUpdateSignal();
mComposerScaleBar->endCommand();
}
void QgsComposerScaleBarWidget::on_mBoxSizeSpinBox_valueChanged( double d )
{
if ( !mComposerScaleBar )
{
return;
}
mComposerScaleBar->beginCommand( tr( "Scalebar box content space" ), QgsComposerMergeCommand::ScaleBarBoxContentSpace );
disconnectUpdateSignal();
mComposerScaleBar->setBoxContentSpace( d );
mComposerScaleBar->update();
connectUpdateSignal();
mComposerScaleBar->endCommand();
}
void QgsComposerScaleBarWidget::on_mAlignmentComboBox_currentIndexChanged( int index )
{
if ( !mComposerScaleBar )
{
return;
}
mComposerScaleBar->beginCommand( tr( "Scalebar alignment" ) );
disconnectUpdateSignal();
mComposerScaleBar->setAlignment( ( QgsScaleBarSettings::Alignment ) index );
connectUpdateSignal();
mComposerScaleBar->endCommand();
}
void QgsComposerScaleBarWidget::on_mUnitsComboBox_currentIndexChanged( int index )
{
if ( !mComposerScaleBar )
{
return;
}
QVariant unitData = mUnitsComboBox->itemData( index );
if ( unitData.type() == QVariant::Invalid )
{
return;
}
disconnectUpdateSignal();
mComposerScaleBar->setUnits( ( QgsUnitTypes::DistanceUnit )unitData.toInt() );
switch ( mUnitsComboBox->currentIndex() )
{
case 0:
{
mComposerScaleBar->beginCommand( tr( "Scalebar changed to map units" ) );
mComposerScaleBar->applyDefaultSize( QgsUnitTypes::DistanceUnknownUnit );
break;
}
case 2:
{
mComposerScaleBar->beginCommand( tr( "Scalebar changed to feet" ) );
mComposerScaleBar->applyDefaultSize( QgsUnitTypes::DistanceFeet );
break;
}
case 3:
{
mComposerScaleBar->beginCommand( tr( "Scalebar changed to nautical miles" ) );
mComposerScaleBar->applyDefaultSize( QgsUnitTypes::DistanceNauticalMiles );
break;
}
case 1:
default:
{
mComposerScaleBar->beginCommand( tr( "Scalebar changed to meters" ) );
mComposerScaleBar->applyDefaultSize( QgsUnitTypes::DistanceMeters );
break;
}
}
mComposerScaleBar->update();
mUnitLabelLineEdit->setText( mComposerScaleBar->unitLabeling() );
mSegmentSizeSpinBox->setValue( mComposerScaleBar->numUnitsPerSegment() );
mMapUnitsPerBarUnitSpinBox->setValue( mComposerScaleBar->numMapUnitsPerScaleBarUnit() );
connectUpdateSignal();
mComposerScaleBar->endCommand();
}
void QgsComposerScaleBarWidget::blockMemberSignals( bool block )
{
mSegmentSizeSpinBox->blockSignals( block );
mNumberOfSegmentsSpinBox->blockSignals( block );
mSegmentsLeftSpinBox->blockSignals( block );
mStyleComboBox->blockSignals( block );
mUnitLabelLineEdit->blockSignals( block );
mMapUnitsPerBarUnitSpinBox->blockSignals( block );
mHeightSpinBox->blockSignals( block );
mLineWidthSpinBox->blockSignals( block );
mLabelBarSpaceSpinBox->blockSignals( block );
mBoxSizeSpinBox->blockSignals( block );
mAlignmentComboBox->blockSignals( block );
mUnitsComboBox->blockSignals( block );
mLineJoinStyleCombo->blockSignals( block );
mLineCapStyleCombo->blockSignals( block );
mFontColorButton->blockSignals( block );
mFillColorButton->blockSignals( block );
mFillColor2Button->blockSignals( block );
mStrokeColorButton->blockSignals( block );
mSegmentSizeRadioGroup.blockSignals( block );
mMapItemComboBox->blockSignals( block );
mFontButton->blockSignals( block );
mMinWidthSpinBox->blockSignals( block );
mMaxWidthSpinBox->blockSignals( block );
}
void QgsComposerScaleBarWidget::connectUpdateSignal()
{
if ( mComposerScaleBar )
{
connect( mComposerScaleBar, &QgsComposerObject::itemChanged, this, &QgsComposerScaleBarWidget::setGuiElements );
}
}
void QgsComposerScaleBarWidget::disconnectUpdateSignal()
{
if ( mComposerScaleBar )
{
disconnect( mComposerScaleBar, &QgsComposerObject::itemChanged, this, &QgsComposerScaleBarWidget::setGuiElements );
}
}
void QgsComposerScaleBarWidget::on_mLineJoinStyleCombo_currentIndexChanged( int index )
{
Q_UNUSED( index );
if ( !mComposerScaleBar )
{
return;
}
mComposerScaleBar->beginCommand( tr( "Scalebar line join style" ) );
mComposerScaleBar->setLineJoinStyle( mLineJoinStyleCombo->penJoinStyle() );
mComposerScaleBar->endCommand();
}
void QgsComposerScaleBarWidget::on_mLineCapStyleCombo_currentIndexChanged( int index )
{
Q_UNUSED( index );
if ( !mComposerScaleBar )
{
return;
}
mComposerScaleBar->beginCommand( tr( "Scalebar line cap style" ) );
mComposerScaleBar->setLineCapStyle( mLineCapStyleCombo->penCapStyle() );
mComposerScaleBar->endCommand();
}
void QgsComposerScaleBarWidget::segmentSizeRadioChanged( QAbstractButton *radio )
{
bool fixedSizeMode = radio == mFixedSizeRadio;
mMinWidthSpinBox->setEnabled( !fixedSizeMode );
mMaxWidthSpinBox->setEnabled( !fixedSizeMode );
mSegmentSizeSpinBox->setEnabled( fixedSizeMode );
if ( !mComposerScaleBar )
{
return;
}
mComposerScaleBar->beginCommand( tr( "Scalebar segment size mode" ), QgsComposerMergeCommand::ScaleBarSegmentSize );
disconnectUpdateSignal();
if ( mFixedSizeRadio->isChecked() )
{
mComposerScaleBar->setSegmentSizeMode( QgsScaleBarSettings::SegmentSizeFixed );
mComposerScaleBar->setNumUnitsPerSegment( mSegmentSizeSpinBox->value() );
}
else /*if(mFitWidthRadio->isChecked())*/
{
mComposerScaleBar->setSegmentSizeMode( QgsScaleBarSettings::SegmentSizeFitWidth );
}
mComposerScaleBar->update();
connectUpdateSignal();
mComposerScaleBar->endCommand();
}
void QgsComposerScaleBarWidget::composerMapChanged( QgsComposerItem *item )
{
QgsComposerMap *composerMap = dynamic_cast< QgsComposerMap * >( item );
if ( !composerMap )
{
return;
}
//set it to scale bar
mComposerScaleBar->beginCommand( tr( "Scalebar map changed" ) );
disconnectUpdateSignal();
mComposerScaleBar->setComposerMap( composerMap );
mComposerScaleBar->update();
connectUpdateSignal();
mComposerScaleBar->endCommand();
}
void QgsComposerScaleBarWidget::on_mMinWidthSpinBox_valueChanged( double )
{
if ( !mComposerScaleBar )
{
return;
}
mComposerScaleBar->beginCommand( tr( "Scalebar segment size mode" ), QgsComposerMergeCommand::ScaleBarSegmentSize );
disconnectUpdateSignal();
mComposerScaleBar->setMinBarWidth( mMinWidthSpinBox->value() );
mComposerScaleBar->update();
connectUpdateSignal();
mComposerScaleBar->endCommand();
}
void QgsComposerScaleBarWidget::on_mMaxWidthSpinBox_valueChanged( double )
{
if ( !mComposerScaleBar )
{
return;
}
mComposerScaleBar->beginCommand( tr( "Scalebar segment size mode" ), QgsComposerMergeCommand::ScaleBarSegmentSize );
disconnectUpdateSignal();
mComposerScaleBar->setMaxBarWidth( mMaxWidthSpinBox->value() );
mComposerScaleBar->update();
connectUpdateSignal();
mComposerScaleBar->endCommand();
}