16 #include <QMouseEvent>
17 #include <QEnterEvent>
27 : QWidget( canvas->viewport() ), mMapCanvas( canvas ), mCadDockWidget( cadDockWidget )
31 setAttribute( Qt::WA_TransparentForMouseEvents );
39 mMapCanvas->viewport()->installEventFilter(
this );
40 mMapCanvas->viewport()->setMouseTracking(
true );
43 mAngleLineEdit->installEventFilter( cadDockWidget );
44 mDistanceLineEdit->installEventFilter( cadDockWidget );
45 mXLineEdit->installEventFilter( cadDockWidget );
46 mYLineEdit->installEventFilter( cadDockWidget );
47 mZLineEdit->installEventFilter( cadDockWidget );
48 mMLineEdit->installEventFilter( cadDockWidget );
89 connect( mXLineEdit, &QLineEdit::returnPressed, cadDockWidget, [ = ]() { cadDockWidget->
setX( mXLineEdit->text(), QgsAdvancedDigitizingDockWidget::WidgetSetMode::ReturnPressed ); } );
90 connect( mYLineEdit, &QLineEdit::returnPressed, cadDockWidget, [ = ]() { cadDockWidget->
setY( mYLineEdit->text(), QgsAdvancedDigitizingDockWidget::WidgetSetMode::ReturnPressed ); } );
91 connect( mZLineEdit, &QLineEdit::returnPressed, cadDockWidget, [ = ]() { cadDockWidget->
setZ( mZLineEdit->text(), QgsAdvancedDigitizingDockWidget::WidgetSetMode::ReturnPressed ); } );
92 connect( mMLineEdit, &QLineEdit::returnPressed, cadDockWidget, [ = ]() { cadDockWidget->
setM( mMLineEdit->text(), QgsAdvancedDigitizingDockWidget::WidgetSetMode::ReturnPressed ); } );
93 connect( mAngleLineEdit, &QLineEdit::returnPressed, cadDockWidget, [ = ]() { cadDockWidget->
setAngle( mAngleLineEdit->text(), QgsAdvancedDigitizingDockWidget::WidgetSetMode::ReturnPressed ); } );
94 connect( mDistanceLineEdit, &QLineEdit::returnPressed, cadDockWidget, [ = ]() { cadDockWidget->
setDistance( mDistanceLineEdit->text(), QgsAdvancedDigitizingDockWidget::WidgetSetMode::ReturnPressed ); } );
96 connect( mXLineEdit, &QLineEdit::textEdited, cadDockWidget, [ = ]() { cadDockWidget->
setX( mXLineEdit->text(), QgsAdvancedDigitizingDockWidget::WidgetSetMode::TextEdited ); } );
97 connect( mYLineEdit, &QLineEdit::textEdited, cadDockWidget, [ = ]() { cadDockWidget->
setY( mYLineEdit->text(), QgsAdvancedDigitizingDockWidget::WidgetSetMode::TextEdited ); } );
98 connect( mZLineEdit, &QLineEdit::textEdited, cadDockWidget, [ = ]() { cadDockWidget->
setZ( mZLineEdit->text(), QgsAdvancedDigitizingDockWidget::WidgetSetMode::TextEdited ); } );
99 connect( mMLineEdit, &QLineEdit::textEdited, cadDockWidget, [ = ]() { cadDockWidget->
setM( mMLineEdit->text(), QgsAdvancedDigitizingDockWidget::WidgetSetMode::TextEdited ); } );
100 connect( mAngleLineEdit, &QLineEdit::textEdited, cadDockWidget, [ = ]() { cadDockWidget->
setAngle( mAngleLineEdit->text(), QgsAdvancedDigitizingDockWidget::WidgetSetMode::TextEdited ); } );
101 connect( mDistanceLineEdit, &QLineEdit::textEdited, cadDockWidget, [ = ]() { cadDockWidget->
setDistance( mDistanceLineEdit->text(), QgsAdvancedDigitizingDockWidget::WidgetSetMode::TextEdited ); } );
104 connect( xWatcher, &
QgsFocusWatcher::focusOut, cadDockWidget, [ = ]() { cadDockWidget->
setX( mXLineEdit->text(), QgsAdvancedDigitizingDockWidget::WidgetSetMode::FocusOut ); } );
106 connect( yWatcher, &
QgsFocusWatcher::focusOut, cadDockWidget, [ = ]() { cadDockWidget->
setY( mYLineEdit->text(), QgsAdvancedDigitizingDockWidget::WidgetSetMode::FocusOut ); } );
108 connect( zWatcher, &
QgsFocusWatcher::focusOut, cadDockWidget, [ = ]() { cadDockWidget->
setZ( mZLineEdit->text(), QgsAdvancedDigitizingDockWidget::WidgetSetMode::FocusOut ); } );
110 connect( mWatcher, &
QgsFocusWatcher::focusOut, cadDockWidget, [ = ]() { cadDockWidget->
setM( mMLineEdit->text(), QgsAdvancedDigitizingDockWidget::WidgetSetMode::FocusOut ); } );
112 connect( angleWatcher, &
QgsFocusWatcher::focusOut, cadDockWidget, [ = ]() { cadDockWidget->
setAngle( mAngleLineEdit->text(), QgsAdvancedDigitizingDockWidget::WidgetSetMode::FocusOut ); } );
114 connect( distanceWatcher, &
QgsFocusWatcher::focusOut, cadDockWidget, [ = ]() { cadDockWidget->
setDistance( mDistanceLineEdit->text(), QgsAdvancedDigitizingDockWidget::WidgetSetMode::FocusOut ); } );
118 bool QgsAdvancedDigitizingFloater::eventFilter( QObject *obj, QEvent *event )
120 if ( mCadDockWidget->
cadEnabled() && mActive )
122 if ( event->type() == QEvent::MouseMove )
125 QMouseEvent *mouseEvent =
dynamic_cast<QMouseEvent *
>( event );
126 updatePos( mouseEvent->pos() );
128 else if ( event->type() == QEvent::Enter )
131 QEnterEvent *enterEvent =
dynamic_cast<QEnterEvent *
>( event );
132 updatePos( enterEvent->pos() );
135 else if ( event->type() == QEvent::Leave )
141 return QWidget::eventFilter( obj, event );
158 void QgsAdvancedDigitizingFloater::updatePos(
const QPoint &pos )
161 move( pos + QPoint( 15, 5 ) );
164 void QgsAdvancedDigitizingFloater::hideIfDisabled()
166 if ( ! mCadDockWidget->
cadEnabled() || ! mActive )
172 void QgsAdvancedDigitizingFloater::changeX(
const QString &text )
174 mXLineEdit->setText( text );
177 void QgsAdvancedDigitizingFloater::changeY(
const QString &text )
179 mYLineEdit->setText( text );
182 void QgsAdvancedDigitizingFloater::changeZ(
const QString &text )
184 mZLineEdit->setText( text );
187 void QgsAdvancedDigitizingFloater::changeM(
const QString &text )
189 mMLineEdit->setText( text );
192 void QgsAdvancedDigitizingFloater::changeDistance(
const QString &text )
194 mDistanceLineEdit->setText( text );
197 void QgsAdvancedDigitizingFloater::changeAngle(
const QString &text )
199 mAngleLineEdit->setText( text );
202 void QgsAdvancedDigitizingFloater::changeLockX(
bool locked )
206 mXLineEdit->setStyleSheet( QString() );
207 mXLabel->setStyleSheet( QString() );
211 mXLineEdit->setStyleSheet( QStringLiteral(
"font-weight: bold" ) );
212 mXLabel->setStyleSheet( QStringLiteral(
"font-weight: bold" ) );
216 void QgsAdvancedDigitizingFloater::changeLockY(
bool locked )
220 mYLineEdit->setStyleSheet( QString() );
221 mYLabel->setStyleSheet( QString() );
225 mYLineEdit->setStyleSheet( QStringLiteral(
"font-weight: bold" ) );
226 mYLabel->setStyleSheet( QStringLiteral(
"font-weight: bold" ) );
230 void QgsAdvancedDigitizingFloater::changeLockZ(
bool locked )
234 mZLineEdit->setStyleSheet( QString() );
235 mZLabel->setStyleSheet( QString() );
239 mZLineEdit->setStyleSheet( QStringLiteral(
"font-weight: bold" ) );
240 mZLabel->setStyleSheet( QStringLiteral(
"font-weight: bold" ) );
244 void QgsAdvancedDigitizingFloater::changeLockM(
bool locked )
248 mMLineEdit->setStyleSheet( QString() );
249 mMLabel->setStyleSheet( QString() );
253 mMLineEdit->setStyleSheet( QStringLiteral(
"font-weight: bold" ) );
254 mMLabel->setStyleSheet( QStringLiteral(
"font-weight: bold" ) );
258 void QgsAdvancedDigitizingFloater::changeLockDistance(
bool locked )
262 mDistanceLineEdit->setStyleSheet( QString() );
263 mDistanceLabel->setStyleSheet( QString() );
267 mDistanceLineEdit->setStyleSheet( QStringLiteral(
"font-weight: bold" ) );
268 mDistanceLabel->setStyleSheet( QStringLiteral(
"font-weight: bold" ) );
272 void QgsAdvancedDigitizingFloater::changeLockAngle(
bool locked )
276 mAngleLineEdit->setStyleSheet( QString() );
277 mAngleLabel->setStyleSheet( QString() );
281 mAngleLineEdit->setStyleSheet( QStringLiteral(
"font-weight: bold" ) );
282 mAngleLabel->setStyleSheet( QStringLiteral(
"font-weight: bold" ) );
287 void QgsAdvancedDigitizingFloater::changeRelativeX(
bool relative )
291 mXLabel->setText(
"x" );
295 mXLabel->setText(
"Δx" );
300 void QgsAdvancedDigitizingFloater::changeRelativeY(
bool relative )
304 mYLabel->setText(
"y" );
308 mYLabel->setText(
"Δy" );
313 void QgsAdvancedDigitizingFloater::changeRelativeZ(
bool relative )
317 mZLabel->setText(
"z" );
321 mZLabel->setText(
"Δz" );
326 void QgsAdvancedDigitizingFloater::changeRelativeM(
bool relative )
330 mMLabel->setText(
"m" );
334 mMLabel->setText(
"Δm" );
341 void QgsAdvancedDigitizingFloater::changeRelativeAngle(
bool relative )
345 mAngleLabel->setText(
"a" );
349 mAngleLabel->setText(
"Δa" );
354 void QgsAdvancedDigitizingFloater::focusOnX()
358 mXLineEdit->setFocus();
359 mXLineEdit->selectAll();
363 void QgsAdvancedDigitizingFloater::focusOnY()
367 mYLineEdit->setFocus();
368 mYLineEdit->selectAll();
372 void QgsAdvancedDigitizingFloater::focusOnZ()
376 mZLineEdit->setFocus();
377 mZLineEdit->selectAll();
381 void QgsAdvancedDigitizingFloater::focusOnM()
385 mMLineEdit->setFocus();
386 mMLineEdit->selectAll();
390 void QgsAdvancedDigitizingFloater::focusOnDistance()
394 mDistanceLineEdit->setFocus();
395 mDistanceLineEdit->selectAll();
399 void QgsAdvancedDigitizingFloater::focusOnAngle()
403 mAngleLineEdit->setFocus();
404 mAngleLineEdit->selectAll();
409 void QgsAdvancedDigitizingFloater::enabledChangedX(
bool enabled )
411 mXLineEdit->setVisible( enabled );
412 mXLabel->setVisible( enabled );
416 void QgsAdvancedDigitizingFloater::enabledChangedY(
bool enabled )
418 mYLineEdit->setVisible( enabled );
419 mYLabel->setVisible( enabled );
423 void QgsAdvancedDigitizingFloater::enabledChangedZ(
bool enabled )
425 mZLineEdit->setVisible( enabled );
426 mZLabel->setVisible( enabled );
430 void QgsAdvancedDigitizingFloater::enabledChangedM(
bool enabled )
432 mMLineEdit->setVisible( enabled );
433 mMLabel->setVisible( enabled );
437 void QgsAdvancedDigitizingFloater::enabledChangedDistance(
bool enabled )
439 mDistanceLineEdit->setVisible( enabled );
440 mDistanceLabel->setVisible( enabled );
444 void QgsAdvancedDigitizingFloater::enabledChangedAngle(
bool enabled )
446 mAngleLineEdit->setVisible( enabled );
447 mAngleLabel->setVisible( enabled );
QgsAdvancedDigitizingFloater(QgsMapCanvas *canvas, QgsAdvancedDigitizingDockWidget *cadDockWidget)
Create an advanced digitizing floater widget.
void setActive(bool active)
Set whether the floater should be active or not.
bool active()
Whether the floater is active or not.
A event filter for watching for focus events on a parent object.
void focusOut()
Emitted when parent object loses focus.
Map canvas is a class for displaying all GIS data types on a canvas.
This class is a composition of two QSettings instances:
void setValue(const QString &key, const QVariant &value, QgsSettings::Section section=QgsSettings::NoSection)
Sets the value of setting key to value.