26 : QWidget( canvas->viewport() )
27 , mMapCanvas( canvas )
28 , mCadDockWidget( cadDockWidget )
32 setAttribute( Qt::WA_TransparentForMouseEvents );
42 mMapCanvas->viewport()->installEventFilter(
this );
43 mMapCanvas->viewport()->setMouseTracking(
true );
46 mAngleLineEdit->installEventFilter( cadDockWidget );
47 mDistanceLineEdit->installEventFilter( cadDockWidget );
48 mXLineEdit->installEventFilter( cadDockWidget );
49 mYLineEdit->installEventFilter( cadDockWidget );
50 mZLineEdit->installEventFilter( cadDockWidget );
51 mMLineEdit->installEventFilter( cadDockWidget );
99 connect( mXLineEdit, &QLineEdit::returnPressed, cadDockWidget, [ = ]() { cadDockWidget->
setX( mXLineEdit->text(), QgsAdvancedDigitizingDockWidget::WidgetSetMode::ReturnPressed ); } );
100 connect( mYLineEdit, &QLineEdit::returnPressed, cadDockWidget, [ = ]() { cadDockWidget->
setY( mYLineEdit->text(), QgsAdvancedDigitizingDockWidget::WidgetSetMode::ReturnPressed ); } );
101 connect( mZLineEdit, &QLineEdit::returnPressed, cadDockWidget, [ = ]() { cadDockWidget->
setZ( mZLineEdit->text(), QgsAdvancedDigitizingDockWidget::WidgetSetMode::ReturnPressed ); } );
102 connect( mMLineEdit, &QLineEdit::returnPressed, cadDockWidget, [ = ]() { cadDockWidget->
setM( mMLineEdit->text(), QgsAdvancedDigitizingDockWidget::WidgetSetMode::ReturnPressed ); } );
103 connect( mAngleLineEdit, &QLineEdit::returnPressed, cadDockWidget, [ = ]() { cadDockWidget->
setAngle( mAngleLineEdit->text(), QgsAdvancedDigitizingDockWidget::WidgetSetMode::ReturnPressed ); } );
104 connect( mDistanceLineEdit, &QLineEdit::returnPressed, cadDockWidget, [ = ]() { cadDockWidget->
setDistance( mDistanceLineEdit->text(), QgsAdvancedDigitizingDockWidget::WidgetSetMode::ReturnPressed ); } );
106 connect( mXLineEdit, &QLineEdit::textEdited, cadDockWidget, [ = ]() { cadDockWidget->
setX( mXLineEdit->text(), QgsAdvancedDigitizingDockWidget::WidgetSetMode::TextEdited ); } );
107 connect( mYLineEdit, &QLineEdit::textEdited, cadDockWidget, [ = ]() { cadDockWidget->
setY( mYLineEdit->text(), QgsAdvancedDigitizingDockWidget::WidgetSetMode::TextEdited ); } );
108 connect( mZLineEdit, &QLineEdit::textEdited, cadDockWidget, [ = ]() { cadDockWidget->
setZ( mZLineEdit->text(), QgsAdvancedDigitizingDockWidget::WidgetSetMode::TextEdited ); } );
109 connect( mMLineEdit, &QLineEdit::textEdited, cadDockWidget, [ = ]() { cadDockWidget->
setM( mMLineEdit->text(), QgsAdvancedDigitizingDockWidget::WidgetSetMode::TextEdited ); } );
110 connect( mAngleLineEdit, &QLineEdit::textEdited, cadDockWidget, [ = ]() { cadDockWidget->
setAngle( mAngleLineEdit->text(), QgsAdvancedDigitizingDockWidget::WidgetSetMode::TextEdited ); } );
111 connect( mDistanceLineEdit, &QLineEdit::textEdited, cadDockWidget, [ = ]() { cadDockWidget->
setDistance( mDistanceLineEdit->text(), QgsAdvancedDigitizingDockWidget::WidgetSetMode::TextEdited ); } );
114 connect( xWatcher, &
QgsFocusWatcher::focusOut, cadDockWidget, [ = ]() { cadDockWidget->
setX( mXLineEdit->text(), QgsAdvancedDigitizingDockWidget::WidgetSetMode::FocusOut ); } );
116 connect( yWatcher, &
QgsFocusWatcher::focusOut, cadDockWidget, [ = ]() { cadDockWidget->
setY( mYLineEdit->text(), QgsAdvancedDigitizingDockWidget::WidgetSetMode::FocusOut ); } );
118 connect( zWatcher, &
QgsFocusWatcher::focusOut, cadDockWidget, [ = ]() { cadDockWidget->
setZ( mZLineEdit->text(), QgsAdvancedDigitizingDockWidget::WidgetSetMode::FocusOut ); } );
120 connect( mWatcher, &
QgsFocusWatcher::focusOut, cadDockWidget, [ = ]() { cadDockWidget->
setM( mMLineEdit->text(), QgsAdvancedDigitizingDockWidget::WidgetSetMode::FocusOut ); } );
122 connect( angleWatcher, &
QgsFocusWatcher::focusOut, cadDockWidget, [ = ]() { cadDockWidget->
setAngle( mAngleLineEdit->text(), QgsAdvancedDigitizingDockWidget::WidgetSetMode::FocusOut ); } );
124 connect( distanceWatcher, &
QgsFocusWatcher::focusOut, cadDockWidget, [ = ]() { cadDockWidget->
setDistance( mDistanceLineEdit->text(), QgsAdvancedDigitizingDockWidget::WidgetSetMode::FocusOut ); } );
125 changeCommonAngleSnapping( mCadDockWidget->commonAngleConstraint() );
131bool QgsAdvancedDigitizingFloater::eventFilter( QObject *obj, QEvent *event )
133 if ( mCadDockWidget && mCadDockWidget->cadEnabled() && mActive )
135 if ( event->type() == QEvent::MouseMove )
138 QMouseEvent *mouseEvent =
dynamic_cast<QMouseEvent *
>( event );
139 updatePos( mouseEvent->pos() );
141 else if ( event->type() == QEvent::Enter )
144 QEnterEvent *enterEvent =
dynamic_cast<QEnterEvent *
>( event );
145 updatePos( enterEvent->pos() );
148 else if ( event->type() == QEvent::Leave )
154 return QWidget::eventFilter( obj, event );
164 return mItemsVisibility.testFlag( item );
178 const QMetaEnum enumData { QMetaEnum::fromType<QgsAdvancedDigitizingFloater::FloaterItem>() };
179 QgsSettings().
setValue( QStringLiteral(
"/Cad/%1ShowInFloater" ).arg( enumData.valueToKey(
static_cast<int>( item ) ) ), visible );
180 mItemsVisibility.setFlag( item, visible );
184 enabledChangedX( visible );
187 enabledChangedY( visible );
190 enabledChangedM( visible );
193 enabledChangedZ( visible );
196 enabledChangedAngle( visible );
199 enabledChangedDistance( visible );
202 enabledCommonAngleSnapping( visible );
205 enabledChangedBearing( visible );
210void QgsAdvancedDigitizingFloater::updatePos(
const QPoint &pos )
213 move( pos + QPoint( 15, 5 ) );
216void QgsAdvancedDigitizingFloater::hideIfDisabled()
218 if ( !mCadDockWidget || ! mCadDockWidget->cadEnabled() || ! mActive )
224void QgsAdvancedDigitizingFloater::changeX(
const QString &text )
226 mXLineEdit->setText( text );
229void QgsAdvancedDigitizingFloater::changeY(
const QString &text )
231 mYLineEdit->setText( text );
234void QgsAdvancedDigitizingFloater::changeZ(
const QString &text )
236 mZLineEdit->setText( text );
239void QgsAdvancedDigitizingFloater::changeM(
const QString &text )
241 mMLineEdit->setText( text );
244void QgsAdvancedDigitizingFloater::changeCommonAngleSnapping(
double angle )
246 mCommonAngleSnappingLineEdit->setText(
qgsDoubleNear(
angle, 0.0 ) ? tr(
"disabled" ) : QLocale().toString(
angle ).append( tr(
" °" ) ) );
249void QgsAdvancedDigitizingFloater::changeDistance(
const QString &text )
251 mDistanceLineEdit->setText( text );
254void QgsAdvancedDigitizingFloater::changeAngle(
const QString &text )
256 mAngleLineEdit->setText( text );
259void QgsAdvancedDigitizingFloater::changeBearing(
const QString &text )
261 mBearingLineEdit->setText( text );
264void QgsAdvancedDigitizingFloater::changeLockX(
bool locked )
268 mXLineEdit->setStyleSheet( QString() );
269 mXLabel->setStyleSheet( QString() );
273 mXLineEdit->setStyleSheet( QStringLiteral(
"font-weight: bold" ) );
274 mXLabel->setStyleSheet( QStringLiteral(
"font-weight: bold" ) );
278void QgsAdvancedDigitizingFloater::changeLockY(
bool locked )
282 mYLineEdit->setStyleSheet( QString() );
283 mYLabel->setStyleSheet( QString() );
287 mYLineEdit->setStyleSheet( QStringLiteral(
"font-weight: bold" ) );
288 mYLabel->setStyleSheet( QStringLiteral(
"font-weight: bold" ) );
292void QgsAdvancedDigitizingFloater::changeLockZ(
bool locked )
296 mZLineEdit->setStyleSheet( QString() );
297 mZLabel->setStyleSheet( QString() );
301 mZLineEdit->setStyleSheet( QStringLiteral(
"font-weight: bold" ) );
302 mZLabel->setStyleSheet( QStringLiteral(
"font-weight: bold" ) );
306void QgsAdvancedDigitizingFloater::changeLockM(
bool locked )
310 mMLineEdit->setStyleSheet( QString() );
311 mMLabel->setStyleSheet( QString() );
315 mMLineEdit->setStyleSheet( QStringLiteral(
"font-weight: bold" ) );
316 mMLabel->setStyleSheet( QStringLiteral(
"font-weight: bold" ) );
320void QgsAdvancedDigitizingFloater::changeLockDistance(
bool locked )
324 mDistanceLineEdit->setStyleSheet( QString() );
325 mDistanceLabel->setStyleSheet( QString() );
329 mDistanceLineEdit->setStyleSheet( QStringLiteral(
"font-weight: bold" ) );
330 mDistanceLabel->setStyleSheet( QStringLiteral(
"font-weight: bold" ) );
334void QgsAdvancedDigitizingFloater::changeLockAngle(
bool locked )
338 mAngleLineEdit->setStyleSheet( QString() );
339 mAngleLabel->setStyleSheet( QString() );
343 mAngleLineEdit->setStyleSheet( QStringLiteral(
"font-weight: bold" ) );
344 mAngleLabel->setStyleSheet( QStringLiteral(
"font-weight: bold" ) );
349void QgsAdvancedDigitizingFloater::changeRelativeX(
bool relative )
353 mXLabel->setText(
"x" );
357 mXLabel->setText(
"Δx" );
362void QgsAdvancedDigitizingFloater::changeRelativeY(
bool relative )
366 mYLabel->setText(
"y" );
370 mYLabel->setText(
"Δy" );
375void QgsAdvancedDigitizingFloater::changeRelativeZ(
bool relative )
379 mZLabel->setText(
"z" );
383 mZLabel->setText(
"Δz" );
388void QgsAdvancedDigitizingFloater::changeRelativeM(
bool relative )
392 mMLabel->setText(
"m" );
396 mMLabel->setText(
"Δm" );
403void QgsAdvancedDigitizingFloater::changeRelativeAngle(
bool relative )
407 mAngleLabel->setText(
"a" );
411 mAngleLabel->setText(
"Δa" );
416void QgsAdvancedDigitizingFloater::focusOnX()
420 mXLineEdit->setFocus();
421 mXLineEdit->selectAll();
425void QgsAdvancedDigitizingFloater::focusOnY()
429 mYLineEdit->setFocus();
430 mYLineEdit->selectAll();
434void QgsAdvancedDigitizingFloater::focusOnZ()
438 mZLineEdit->setFocus();
439 mZLineEdit->selectAll();
443void QgsAdvancedDigitizingFloater::focusOnM()
447 mMLineEdit->setFocus();
448 mMLineEdit->selectAll();
452void QgsAdvancedDigitizingFloater::focusOnDistance()
456 mDistanceLineEdit->setFocus();
457 mDistanceLineEdit->selectAll();
461void QgsAdvancedDigitizingFloater::focusOnAngle()
465 mAngleLineEdit->setFocus();
466 mAngleLineEdit->selectAll();
471void QgsAdvancedDigitizingFloater::enabledChangedX(
bool enabled )
478void QgsAdvancedDigitizingFloater::enabledChangedY(
bool enabled )
485void QgsAdvancedDigitizingFloater::enabledChangedZ(
bool enabled )
492void QgsAdvancedDigitizingFloater::enabledChangedM(
bool enabled )
499void QgsAdvancedDigitizingFloater::enabledChangedDistance(
bool enabled )
506void QgsAdvancedDigitizingFloater::enabledCommonAngleSnapping(
bool enabled )
513void QgsAdvancedDigitizingFloater::enabledChangedAngle(
bool enabled )
520void QgsAdvancedDigitizingFloater::enabledChangedBearing(
bool enabled )
QgsAdvancedDigitizingFloater(QgsMapCanvas *canvas, QgsAdvancedDigitizingDockWidget *cadDockWidget)
Create an advanced digitizing floater widget.
void setItemVisibility(const QgsAdvancedDigitizingFloater::FloaterItem &item, bool visible)
Set whether the floater item should be visible or not.
FloaterItem
Available floater items.
bool itemVisibility(const QgsAdvancedDigitizingFloater::FloaterItem &item) const
Returns true if the floater item visibility setting is enabled.
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.
double ANALYSIS_EXPORT angle(QgsPoint *p1, QgsPoint *p2, QgsPoint *p3, QgsPoint *p4)
Calculates the angle between two segments (in 2 dimension, z-values are ignored)
bool qgsDoubleNear(double a, double b, double epsilon=4 *std::numeric_limits< double >::epsilon())
Compare two doubles (but allow some difference)