31
31
#include " qgssettings.h"
32
32
#include " qgisapp.h"
33
33
34
- #include " qgisapp .h"
34
+ #include " qgslogger .h"
35
35
36
36
QgsMapToolOffsetCurve::QgsMapToolOffsetCurve ( QgsMapCanvas *canvas )
37
37
: QgsMapToolEdit( canvas )
38
38
, mSnapIndicator( qgis::make_unique< QgsSnapIndicator >( canvas ) )
39
- {
40
- }
39
+ {}
41
40
42
41
QgsMapToolOffsetCurve::~QgsMapToolOffsetCurve ()
43
42
{
@@ -241,6 +240,7 @@ void QgsMapToolOffsetCurve::cancel()
241
240
{
242
241
deleteUserInputWidget ();
243
242
deleteRubberBandAndGeometry ();
243
+ mCtrlHeldOnFirstClick = false ;
244
244
mLayer = nullptr ;
245
245
}
246
246
@@ -275,10 +275,6 @@ void QgsMapToolOffsetCurve::canvasMoveEvent( QgsMapMouseEvent *e )
275
275
mSnapIndicator ->setMatch ( e->mapPointMatch () );
276
276
277
277
double offset = calculateOffset ( mapPoint );
278
- if ( offset == 0.0 )
279
- {
280
- return ;
281
- }
282
278
283
279
if ( mUserInputWidget )
284
280
{
@@ -356,19 +352,18 @@ void QgsMapToolOffsetCurve::prepareGeometry( QgsVectorLayer *vl, const QgsPointL
356
352
357
353
void QgsMapToolOffsetCurve::createUserInputWidget ()
358
354
{
359
- if ( !mCanvas )
360
- {
361
- return ;
362
- }
363
-
364
355
deleteUserInputWidget ();
356
+
365
357
mUserInputWidget = new QgsOffsetUserWidget ();
358
+ mUserInputWidget ->setPolygonMode ( QgsWkbTypes::geometryType ( mOriginalGeometry .wkbType () ) != QgsWkbTypes::LineGeometry );
366
359
QgisApp::instance ()->addUserInputWidget ( mUserInputWidget );
367
360
mUserInputWidget ->setFocus ( Qt::TabFocusReason );
368
361
369
362
connect ( mUserInputWidget , &QgsOffsetUserWidget::offsetChanged, this , &QgsMapToolOffsetCurve::updateGeometryAndRubberBand );
370
363
connect ( mUserInputWidget , &QgsOffsetUserWidget::offsetEditingFinished, this , &QgsMapToolOffsetCurve::applyOffset );
371
364
connect ( mUserInputWidget , &QgsOffsetUserWidget::offsetEditingCanceled, this , &QgsMapToolOffsetCurve::cancel );
365
+
366
+ connect ( mUserInputWidget , &QgsOffsetUserWidget::offsetConfigChanged, this , [ = ] {updateGeometryAndRubberBand ( mUserInputWidget ->offset () );} );
372
367
}
373
368
374
369
void QgsMapToolOffsetCurve::deleteUserInputWidget ()
@@ -404,19 +399,21 @@ void QgsMapToolOffsetCurve::updateGeometryAndRubberBand( double offset )
404
399
return ;
405
400
}
406
401
402
+ QgsGeometry offsetGeom;
407
403
QgsSettings s;
408
- QgsGeometry::JoinStyle joinStyle = static_cast < QgsGeometry::JoinStyle >( s.value ( QStringLiteral ( " /qgis/digitizing/offset_join_style" ), 0 ).toInt () );
404
+ QgsGeometry::JoinStyle joinStyle = static_cast < QgsGeometry::JoinStyle >( s.value ( QStringLiteral ( " /qgis/digitizing/offset_join_style" ), QgsGeometry::JoinStyleRound ).toInt () );
409
405
int quadSegments = s.value ( QStringLiteral ( " /qgis/digitizing/offset_quad_seg" ), 8 ).toInt ();
410
406
double miterLimit = s.value ( QStringLiteral ( " /qgis/digitizing/offset_miter_limit" ), 5.0 ).toDouble ();
407
+ QgsGeometry::EndCapStyle capStyle = static_cast < QgsGeometry::EndCapStyle >( s.value ( QStringLiteral ( " /qgis/digitizing/offset_cap_style" ), QgsGeometry::CapRound ).toInt () );
408
+
411
409
412
- QgsGeometry offsetGeom;
413
410
if ( QgsWkbTypes::geometryType ( mOriginalGeometry .wkbType () ) == QgsWkbTypes::LineGeometry )
414
411
{
415
412
offsetGeom = mManipulatedGeometry .offsetCurve ( offset, quadSegments, joinStyle, miterLimit );
416
413
}
417
414
else
418
415
{
419
- offsetGeom = mManipulatedGeometry .buffer ( offset, quadSegments, QgsGeometry::CapRound , joinStyle, miterLimit );
416
+ offsetGeom = mManipulatedGeometry .buffer ( offset, quadSegments, capStyle , joinStyle, miterLimit );
420
417
}
421
418
422
419
if ( !offsetGeom )
@@ -441,26 +438,41 @@ void QgsMapToolOffsetCurve::updateGeometryAndRubberBand( double offset )
441
438
QgsOffsetUserWidget::QgsOffsetUserWidget ( QWidget *parent )
442
439
: QWidget( parent )
443
440
{
444
- mLayout = new QGridLayout ( this );
445
- mLayout ->setContentsMargins ( 0 , 0 , 0 , 0 );
446
- // mLayout->setAlignment( Qt::AlignLeft );
447
- setLayout ( mLayout );
448
-
449
- QLabel *lbl = new QLabel ( tr ( " Offset" ), this );
450
- lbl->setAlignment ( Qt::AlignRight | Qt::AlignCenter );
451
- mLayout ->addWidget ( lbl, 0 , 0 );
452
-
453
- mOffsetSpinBox = new QgsDoubleSpinBox ();
454
- mOffsetSpinBox ->setMinimum ( -99999999 );
455
- mOffsetSpinBox ->setMaximum ( 99999999 );
456
- mOffsetSpinBox ->setDecimals ( 6 );
457
- mOffsetSpinBox ->setClearValue ( 0.0 );
458
- mOffsetSpinBox ->setShowClearButton ( false );
459
- mLayout ->addWidget ( mOffsetSpinBox , 0 , 1 );
441
+ setupUi ( this );
442
+
443
+ // fill comboboxes
444
+ mJoinStyleComboBox ->addItem ( tr ( " round" ), QgsGeometry::JoinStyleRound );
445
+ mJoinStyleComboBox ->addItem ( tr ( " miter" ), QgsGeometry::JoinStyleMiter );
446
+ mJoinStyleComboBox ->addItem ( tr ( " bevel" ), QgsGeometry::JoinStyleBevel );
447
+ mCapStyleComboBox ->addItem ( tr ( " round" ), QgsGeometry::CapRound );
448
+ mCapStyleComboBox ->addItem ( tr ( " flat" ), QgsGeometry::CapFlat );
449
+ mCapStyleComboBox ->addItem ( tr ( " square" ), QgsGeometry::CapSquare );
450
+
451
+ QgsSettings s;
452
+ QgsGeometry::JoinStyle joinStyle = static_cast < QgsGeometry::JoinStyle >( s.value ( QStringLiteral ( " /qgis/digitizing/offset_join_style" ), QgsGeometry::JoinStyleRound ).toInt () );
453
+ int quadSegments = s.value ( QStringLiteral ( " /qgis/digitizing/offset_quad_seg" ), 8 ).toInt ();
454
+ double miterLimit = s.value ( QStringLiteral ( " /qgis/digitizing/offset_miter_limit" ), 5.0 ).toDouble ();
455
+ QgsGeometry::EndCapStyle capStyle = static_cast < QgsGeometry::EndCapStyle >( s.value ( QStringLiteral ( " /qgis/digitizing/offset_cap_style" ), QgsGeometry::CapRound ).toInt () );
456
+
457
+ mJoinStyleComboBox ->setCurrentIndex ( mJoinStyleComboBox ->findData ( joinStyle ) );
458
+ mQuadrantSpinBox ->setValue ( quadSegments );
459
+ mMiterLimitSpinBox ->setValue ( miterLimit );
460
+ mCapStyleComboBox ->setCurrentIndex ( mCapStyleComboBox ->findData ( capStyle ) );
460
461
461
462
// connect signals
462
463
mOffsetSpinBox ->installEventFilter ( this );
463
- connect ( mOffsetSpinBox , static_cast < void ( QgsDoubleSpinBox::* )( double ) > ( &QgsDoubleSpinBox::valueChanged ), this , &QgsOffsetUserWidget::offsetSpinBoxValueChanged );
464
+ connect ( mOffsetSpinBox , static_cast < void ( QDoubleSpinBox::* )( double ) > ( &QDoubleSpinBox::valueChanged ), this , &QgsOffsetUserWidget::offsetChanged );
465
+
466
+ connect ( mJoinStyleComboBox , static_cast < void ( QComboBox::* )( int ) > ( &QComboBox::currentIndexChanged ), this , [ = ] { QgsSettings ().setValue ( QStringLiteral ( " /qgis/digitizing/offset_join_style" ), mJoinStyleComboBox ->currentData () ); emit offsetConfigChanged (); } );
467
+ connect ( mQuadrantSpinBox , static_cast < void ( QSpinBox::* )( int ) > ( &QSpinBox::valueChanged ), this , [ = ]( const int quadSegments ) { QgsSettings ().setValue ( QStringLiteral ( " /qgis/digitizing/offset_quad_seg" ), quadSegments ); emit offsetConfigChanged (); } );
468
+ connect ( mMiterLimitSpinBox , static_cast < void ( QDoubleSpinBox::* )( double ) > ( &QDoubleSpinBox::valueChanged ), this , [ = ]( const double & miterLimit ) { QgsSettings ().setValue ( QStringLiteral ( " /qgis/digitizing/offset_miter_limit" ), miterLimit ); emit offsetConfigChanged (); } );
469
+ connect ( mCapStyleComboBox , static_cast < void ( QComboBox::* )( int ) > ( &QComboBox::currentIndexChanged ), this , [ = ] { QgsSettings ().setValue ( QStringLiteral ( " /qgis/digitizing/offset_cap_style" ), mCapStyleComboBox ->currentData () ); emit offsetConfigChanged (); } );
470
+
471
+ bool showAdvanced = s.value ( QStringLiteral ( " /qgis/digitizing/offset_show_advanced" ), false ).toBool ();
472
+ mShowAdvancedButton ->setChecked ( showAdvanced );
473
+ mAdvancedConfigWidget ->setVisible ( showAdvanced );
474
+ connect ( mShowAdvancedButton , &QToolButton::clicked, mAdvancedConfigWidget , &QWidget::setVisible );
475
+ connect ( mShowAdvancedButton , &QToolButton::clicked, this , [ = ]( const bool clicked ) {QgsSettings ().setValue ( QStringLiteral ( " /qgis/digitizing/offset_show_advanced" ), clicked );} );
464
476
465
477
// config focus
466
478
setFocusProxy ( mOffsetSpinBox );
@@ -476,6 +488,12 @@ double QgsOffsetUserWidget::offset()
476
488
return mOffsetSpinBox ->value ();
477
489
}
478
490
491
+ void QgsOffsetUserWidget::setPolygonMode ( bool polygon )
492
+ {
493
+ mCapStyleLabel ->setEnabled ( polygon );
494
+ mCapStyleComboBox ->setEnabled ( polygon );
495
+ }
496
+
479
497
bool QgsOffsetUserWidget::eventFilter ( QObject *obj, QEvent *ev )
480
498
{
481
499
if ( obj == mOffsetSpinBox && ev->type () == QEvent::KeyPress )
@@ -495,8 +513,3 @@ bool QgsOffsetUserWidget::eventFilter( QObject *obj, QEvent *ev )
495
513
496
514
return false ;
497
515
}
498
-
499
- void QgsOffsetUserWidget::offsetSpinBoxValueChanged ( double offset )
500
- {
501
- emit offsetChanged ( offset );
502
- }
0 commit comments