13
13
* *
14
14
***************************************************************************/
15
15
16
+ #include < QPushButton>
17
+
16
18
#include " qgsmaptoolsimplify.h"
17
19
18
20
#include " qgsfeatureiterator.h"
29
31
#include < cmath>
30
32
#include < cfloat>
31
33
32
- QgsSimplifyDialog::QgsSimplifyDialog ( QgsMapToolSimplify *tool, QWidget *parent )
33
- : QDialog( parent )
34
- , mTool( tool )
34
+ QgsSimplifyUserInputWidget::QgsSimplifyUserInputWidget ( QWidget *parent )
35
+ : QWidget( parent )
35
36
{
36
37
setupUi ( this );
37
38
@@ -40,55 +41,62 @@ QgsSimplifyDialog::QgsSimplifyDialog( QgsMapToolSimplify *tool, QWidget *parent
40
41
mMethodComboBox ->addItem ( tr ( " Simplify by area (Visvalingam)" ), QgsMapToolSimplify::SimplifyVisvalingam );
41
42
mMethodComboBox ->addItem ( tr ( " Smooth" ), QgsMapToolSimplify::Smooth );
42
43
43
- spinTolerance->setValue ( mTool ->tolerance () );
44
- spinTolerance->setShowClearButton ( false );
45
- cboToleranceUnits->setCurrentIndex ( ( int ) mTool ->toleranceUnits () );
44
+ mToleranceUnitsComboBox ->addItem ( tr ( " Layer units" ), QgsTolerance::LayerUnits );
45
+ mToleranceUnitsComboBox ->addItem ( tr ( " Pixels" ), QgsTolerance::Pixels );
46
+ mToleranceUnitsComboBox ->addItem ( tr ( " Map units" ), QgsTolerance::ProjectUnits );
47
+
48
+ mSpinToleranceSpinBox ->setShowClearButton ( false );
46
49
47
50
mOffsetSpin ->setClearValue ( 25 );
48
- mOffsetSpin ->setValue ( mTool ->smoothOffset () * 100 );
49
51
mIterationsSpin ->setClearValue ( 1 );
50
- mIterationsSpin ->setValue ( mTool ->smoothIterations () );
51
-
52
- mMethodComboBox ->setCurrentIndex ( mMethodComboBox ->findData ( mTool ->method () ) );
53
52
if ( mMethodComboBox ->currentData ().toInt () != QgsMapToolSimplify::Smooth )
54
53
mOptionsStackedWidget ->setCurrentIndex ( 0 );
55
54
else
56
55
mOptionsStackedWidget ->setCurrentIndex ( 1 );
57
56
58
57
// communication with map tool
59
- connect ( spinTolerance, static_cast < void ( QDoubleSpinBox::* )( double ) > ( &QDoubleSpinBox::valueChanged ), mTool , &QgsMapToolSimplify::setTolerance );
60
- connect ( cboToleranceUnits, static_cast <void ( QComboBox::* )( int )>( &QComboBox::currentIndexChanged ), mTool , &QgsMapToolSimplify::setToleranceUnits );
61
- connect ( mMethodComboBox , static_cast <void ( QComboBox::* )( int )>( &QComboBox::currentIndexChanged ), mTool , [ = ]
58
+ connect ( mSpinToleranceSpinBox , static_cast < void ( QDoubleSpinBox::* )( double ) > ( &QDoubleSpinBox::valueChanged ), this , &QgsSimplifyUserInputWidget::toleranceChanged );
59
+ connect ( mToleranceUnitsComboBox , static_cast <void ( QComboBox::* )( int )>( &QComboBox::currentIndexChanged ), this , [ = ]( const int index ) {emit toleranceUnitsChanged ( ( QgsTolerance::UnitType )index );} );
60
+ connect ( mMethodComboBox , static_cast <void ( QComboBox::* )( int )>( &QComboBox::currentIndexChanged ), this , [ = ]( const int method ) {emit methodChanged ( ( QgsMapToolSimplify::Method )method );} );
61
+ connect ( mMethodComboBox , static_cast <void ( QComboBox::* )( int )>( &QComboBox::currentIndexChanged ), this , [ = ]
62
62
{
63
- mTool ->setMethod ( static_cast < QgsMapToolSimplify::Method >( mMethodComboBox ->currentData ().toInt () ) );
64
63
if ( mMethodComboBox ->currentData ().toInt () != QgsMapToolSimplify::Smooth )
65
64
mOptionsStackedWidget ->setCurrentIndex ( 0 );
66
65
else
67
66
mOptionsStackedWidget ->setCurrentIndex ( 1 );
68
67
} );
69
68
70
- connect ( mOffsetSpin , static_cast < void ( QSpinBox::* )( int ) > ( &QSpinBox::valueChanged ), mTool , [ = ]( int value ) { mTool ->setSmoothOffset ( value / 100.0 ); } );
71
- connect ( mIterationsSpin , static_cast < void ( QSpinBox::* )( int ) > ( &QSpinBox::valueChanged ), mTool , [ = ]( int value ) { mTool ->setSmoothIterations ( value ); } );
72
- connect ( okButton, &QAbstractButton::clicked, mTool , &QgsMapToolSimplify::storeSimplified );
69
+ connect ( mOffsetSpin , static_cast < void ( QSpinBox::* )( int ) > ( &QSpinBox::valueChanged ), this , [ = ]( const int offset ) {emit smoothOffsetChanged ( offset / 100.0 );} );
70
+ connect ( mIterationsSpin , static_cast < void ( QSpinBox::* )( int ) > ( &QSpinBox::valueChanged ), this , &QgsSimplifyUserInputWidget::smoothIterationsChanged );
71
+
72
+ connect ( mButtonBox , &QDialogButtonBox::accepted, this , &QgsSimplifyUserInputWidget::accepted );
73
+ connect ( mButtonBox , &QDialogButtonBox::rejected, this , &QgsSimplifyUserInputWidget::rejected );
73
74
}
74
75
75
- void QgsSimplifyDialog::updateStatusText ()
76
+ void QgsSimplifyUserInputWidget::setConfig ( const QgsMapToolSimplify::Method &method,
77
+ const double &tolerance,
78
+ const QgsTolerance::UnitType &units,
79
+ const double &smoothOffset,
80
+ const int &smoothIterations )
76
81
{
77
- labelStatus->setText ( mTool ->statusText () );
82
+ mMethodComboBox ->setCurrentIndex ( mMethodComboBox ->findData ( method ) );
83
+
84
+ mSpinToleranceSpinBox ->setValue ( tolerance );
85
+ mToleranceUnitsComboBox ->setCurrentIndex ( mToleranceUnitsComboBox ->findData ( units ) );
86
+ mOffsetSpin ->setValue ( 100 * smoothOffset );
87
+ mIterationsSpin ->setValue ( smoothIterations );
78
88
}
79
89
80
- void QgsSimplifyDialog::enableOkButton ( bool enabled )
90
+ void QgsSimplifyUserInputWidget::updateStatusText ( const QString &text )
81
91
{
82
- okButton-> setEnabled ( enabled );
92
+ labelStatus-> setText ( text );
83
93
}
84
94
85
- void QgsSimplifyDialog::closeEvent ( QCloseEvent *e )
95
+ void QgsSimplifyUserInputWidget::enableOkButton ( bool enabled )
86
96
{
87
- QDialog::closeEvent ( e );
88
- mTool ->clearSelection ();
97
+ mButtonBox ->button ( QDialogButtonBox::Ok )->setEnabled ( enabled );
89
98
}
90
99
91
-
92
100
// //////////////////////////////////////////////////////////////////////////
93
101
94
102
@@ -101,14 +109,11 @@ QgsMapToolSimplify::QgsMapToolSimplify( QgsMapCanvas *canvas )
101
109
mMethod = static_cast < QgsMapToolSimplify::Method >( settings.value ( QStringLiteral ( " digitizing/simplify_method" ), 0 ).toInt () );
102
110
mSmoothIterations = settings.value ( QStringLiteral ( " digitizing/smooth_iterations" ), 1 ).toInt ();
103
111
mSmoothOffset = settings.value ( QStringLiteral ( " digitizing/smooth_offset" ), 0.25 ).toDouble ();
104
-
105
- mSimplifyDialog = new QgsSimplifyDialog ( this , canvas->topLevelWidget () );
106
112
}
107
113
108
114
QgsMapToolSimplify::~QgsMapToolSimplify ()
109
115
{
110
116
clearSelection ();
111
- delete mSimplifyDialog ;
112
117
}
113
118
114
119
@@ -123,10 +128,8 @@ void QgsMapToolSimplify::setTolerance( double tolerance )
123
128
updateSimplificationPreview ();
124
129
}
125
130
126
- void QgsMapToolSimplify::setToleranceUnits ( int units )
131
+ void QgsMapToolSimplify::setToleranceUnits ( const QgsTolerance::UnitType & units )
127
132
{
128
- mToleranceUnits = ( QgsTolerance::UnitType ) units;
129
-
130
133
QgsSettings settings;
131
134
settings.setValue ( QStringLiteral ( " digitizing/simplify_tolerance_units" ), units );
132
135
@@ -156,8 +159,28 @@ void QgsMapToolSimplify::updateSimplificationPreview()
156
159
++i;
157
160
}
158
161
159
- mSimplifyDialog ->updateStatusText ();
160
- mSimplifyDialog ->enableOkButton ( !mReducedHasErrors );
162
+ if ( mSimplifyUserWidget )
163
+ {
164
+ mSimplifyUserWidget ->updateStatusText ( statusText () );
165
+ mSimplifyUserWidget ->enableOkButton ( !mReducedHasErrors );
166
+ }
167
+ }
168
+
169
+ void QgsMapToolSimplify::createUserInputWidget ()
170
+ {
171
+ mSimplifyUserWidget = new QgsSimplifyUserInputWidget ( );
172
+ mSimplifyUserWidget ->setConfig ( method (), tolerance (), toleranceUnits (), smoothOffset (), smoothIterations () );
173
+
174
+ connect ( mSimplifyUserWidget , &QgsSimplifyUserInputWidget::methodChanged, this , &QgsMapToolSimplify::setMethod );
175
+ connect ( mSimplifyUserWidget , &QgsSimplifyUserInputWidget::toleranceChanged, this , &QgsMapToolSimplify::setTolerance );
176
+ connect ( mSimplifyUserWidget , &QgsSimplifyUserInputWidget::toleranceUnitsChanged, this , &QgsMapToolSimplify::setToleranceUnits );
177
+ connect ( mSimplifyUserWidget , &QgsSimplifyUserInputWidget::smoothOffsetChanged, this , &QgsMapToolSimplify::setSmoothOffset );
178
+ connect ( mSimplifyUserWidget , &QgsSimplifyUserInputWidget::smoothIterationsChanged, this , &QgsMapToolSimplify::setSmoothIterations );
179
+ connect ( mSimplifyUserWidget , &QgsSimplifyUserInputWidget::accepted, this , &QgsMapToolSimplify::storeSimplified );
180
+ connect ( mSimplifyUserWidget , &QgsSimplifyUserInputWidget::rejected, this , &QgsMapToolSimplify::clearSelection );
181
+
182
+ QgisApp::instance ()->addUserInputWidget ( mSimplifyUserWidget );
183
+ mSimplifyUserWidget ->setFocus ( Qt::TabFocusReason );
161
184
}
162
185
163
186
QgsGeometry QgsMapToolSimplify::processGeometry ( const QgsGeometry &geometry, double tolerance ) const
@@ -295,10 +318,13 @@ void QgsMapToolSimplify::canvasMoveEvent( QgsMapMouseEvent *e )
295
318
296
319
void QgsMapToolSimplify::canvasReleaseEvent ( QgsMapMouseEvent *e )
297
320
{
298
- if ( e->button () != Qt::LeftButton )
321
+ if ( e->button () == Qt::RightButton )
322
+ {
323
+ clearSelection ();
299
324
return ;
325
+ }
300
326
301
- if ( !currentVectorLayer () )
327
+ if ( e-> button () != Qt::LeftButton || !currentVectorLayer () )
302
328
return ;
303
329
304
330
delete mSelectionRubberBand ;
@@ -340,10 +366,8 @@ void QgsMapToolSimplify::canvasReleaseEvent( QgsMapMouseEvent *e )
340
366
rb->show ();
341
367
mRubberBands << rb;
342
368
}
369
+ createUserInputWidget ();
343
370
updateSimplificationPreview ();
344
-
345
- // show dialog as a non-modal window
346
- mSimplifyDialog ->show ();
347
371
}
348
372
349
373
@@ -399,7 +423,8 @@ void QgsMapToolSimplify::selectFeaturesInRect()
399
423
void QgsMapToolSimplify::clearSelection ()
400
424
{
401
425
mSelectedFeatures .clear ();
402
-
426
+ delete mSimplifyUserWidget ;
427
+ mSimplifyUserWidget = nullptr ;
403
428
qDeleteAll ( mRubberBands );
404
429
mRubberBands .clear ();
405
430
}
@@ -408,9 +433,6 @@ void QgsMapToolSimplify::deactivate()
408
433
{
409
434
delete mSelectionRubberBand ;
410
435
mSelectionRubberBand = nullptr ;
411
-
412
- if ( mSimplifyDialog ->isVisible () )
413
- mSimplifyDialog ->close ();
414
436
clearSelection ();
415
437
QgsMapTool::deactivate ();
416
438
}
0 commit comments