27 : QWidget( canvas->viewport() )
28 , mMapCanvas( canvas )
29 , mCadDockWidget( cadDockWidget )
33 setAttribute( Qt::WA_TransparentForMouseEvents );
43 mMapCanvas->viewport()->installEventFilter(
this );
44 mMapCanvas->viewport()->setMouseTracking(
true );
47 mAngleLineEdit->installEventFilter( cadDockWidget );
48 mDistanceLineEdit->installEventFilter( cadDockWidget );
49 mXLineEdit->installEventFilter( cadDockWidget );
50 mYLineEdit->installEventFilter( cadDockWidget );
51 mZLineEdit->installEventFilter( cadDockWidget );
52 mMLineEdit->installEventFilter( cadDockWidget );
104 connect( mAngleLineEdit, &QLineEdit::returnPressed, cadDockWidget, [ = ]()
108 whileBlocking( mAngleLineEdit )->setText( cleanedInputValue );
110 connect( mDistanceLineEdit, &QLineEdit::returnPressed, cadDockWidget, [ = ]()
114 whileBlocking( mDistanceLineEdit )->setText( cleanedInputValue );
136 whileBlocking( mAngleLineEdit )->setText( mCadDockWidget->constraintAngle()->displayValue() );
141 whileBlocking( mAngleLineEdit )->setText( cleanedInputValue );
147 whileBlocking( mDistanceLineEdit )->setText( mCadDockWidget->constraintDistance()->displayValue() );
152 whileBlocking( mDistanceLineEdit )->setText( cleanedInputValue );
154 changeCommonAngleSnapping( mCadDockWidget->commonAngleConstraint() );
160bool QgsAdvancedDigitizingFloater::eventFilter( QObject *obj, QEvent *event )
162 if ( mCadDockWidget && mCadDockWidget->cadEnabled() && mActive )
164 if ( event->type() == QEvent::MouseMove )
167 QMouseEvent *mouseEvent =
dynamic_cast<QMouseEvent *
>( event );
168 updatePos( mouseEvent->pos() );
170 else if ( event->type() == QEvent::Enter )
173 QEnterEvent *enterEvent =
dynamic_cast<QEnterEvent *
>( event );
174 updatePos( enterEvent->pos() );
177 else if ( event->type() == QEvent::Leave )
183 return QWidget::eventFilter( obj, event );
193 return mItemsVisibility.testFlag( item );
207 const QMetaEnum enumData { QMetaEnum::fromType<QgsAdvancedDigitizingFloater::FloaterItem>() };
208 QgsSettings().
setValue( QStringLiteral(
"/Cad/%1ShowInFloater" ).arg( enumData.valueToKey(
static_cast<int>( item ) ) ), visible );
209 mItemsVisibility.setFlag( item, visible );
213 enabledChangedX( visible );
216 enabledChangedY( visible );
219 enabledChangedM( visible );
222 enabledChangedZ( visible );
225 enabledChangedAngle( visible );
228 enabledChangedDistance( visible );
231 enabledCommonAngleSnapping( visible );
234 enabledChangedBearing( visible );
239void QgsAdvancedDigitizingFloater::updatePos(
const QPoint &pos )
242 move( pos + QPoint( 15, 5 ) );
245void QgsAdvancedDigitizingFloater::hideIfDisabled()
247 if ( !mCadDockWidget || ! mCadDockWidget->cadEnabled() || ! mActive )
253void QgsAdvancedDigitizingFloater::changeX(
const QString &text )
255 mXLineEdit->setText( text );
258void QgsAdvancedDigitizingFloater::changeY(
const QString &text )
260 mYLineEdit->setText( text );
263void QgsAdvancedDigitizingFloater::changeZ(
const QString &text )
265 mZLineEdit->setText( text );
268void QgsAdvancedDigitizingFloater::changeM(
const QString &text )
270 mMLineEdit->setText( text );
273void QgsAdvancedDigitizingFloater::changeCommonAngleSnapping(
double angle )
275 mCommonAngleSnappingLineEdit->setText(
qgsDoubleNear( angle, 0.0 ) ? tr(
"disabled" ) : QLocale().toString(
angle ).append( tr(
" °" ) ) );
278void QgsAdvancedDigitizingFloater::changeDistance(
const QString &text )
280 mDistanceLineEdit->setText( text );
283void QgsAdvancedDigitizingFloater::changeAngle(
const QString &text )
285 mAngleLineEdit->setText( text );
288void QgsAdvancedDigitizingFloater::changeBearing(
const QString &text )
290 mBearingLineEdit->setText( text );
293void QgsAdvancedDigitizingFloater::changeLockX(
bool locked )
297 mXLineEdit->setStyleSheet( QString() );
298 mXLabel->setStyleSheet( QString() );
302 mXLineEdit->setStyleSheet( QStringLiteral(
"font-weight: bold" ) );
303 mXLabel->setStyleSheet( QStringLiteral(
"font-weight: bold" ) );
307void QgsAdvancedDigitizingFloater::changeLockY(
bool locked )
311 mYLineEdit->setStyleSheet( QString() );
312 mYLabel->setStyleSheet( QString() );
316 mYLineEdit->setStyleSheet( QStringLiteral(
"font-weight: bold" ) );
317 mYLabel->setStyleSheet( QStringLiteral(
"font-weight: bold" ) );
321void QgsAdvancedDigitizingFloater::changeLockZ(
bool locked )
325 mZLineEdit->setStyleSheet( QString() );
326 mZLabel->setStyleSheet( QString() );
330 mZLineEdit->setStyleSheet( QStringLiteral(
"font-weight: bold" ) );
331 mZLabel->setStyleSheet( QStringLiteral(
"font-weight: bold" ) );
335void QgsAdvancedDigitizingFloater::changeLockM(
bool locked )
339 mMLineEdit->setStyleSheet( QString() );
340 mMLabel->setStyleSheet( QString() );
344 mMLineEdit->setStyleSheet( QStringLiteral(
"font-weight: bold" ) );
345 mMLabel->setStyleSheet( QStringLiteral(
"font-weight: bold" ) );
349void QgsAdvancedDigitizingFloater::changeLockDistance(
bool locked )
353 mDistanceLineEdit->setStyleSheet( QString() );
354 mDistanceLabel->setStyleSheet( QString() );
358 mDistanceLineEdit->setStyleSheet( QStringLiteral(
"font-weight: bold" ) );
359 mDistanceLabel->setStyleSheet( QStringLiteral(
"font-weight: bold" ) );
363void QgsAdvancedDigitizingFloater::changeLockAngle(
bool locked )
367 mAngleLineEdit->setStyleSheet( QString() );
368 mAngleLabel->setStyleSheet( QString() );
372 mAngleLineEdit->setStyleSheet( QStringLiteral(
"font-weight: bold" ) );
373 mAngleLabel->setStyleSheet( QStringLiteral(
"font-weight: bold" ) );
378void QgsAdvancedDigitizingFloater::changeRelativeX(
bool relative )
382 mXLabel->setText(
"x" );
386 mXLabel->setText(
"Δx" );
391void QgsAdvancedDigitizingFloater::changeRelativeY(
bool relative )
395 mYLabel->setText(
"y" );
399 mYLabel->setText(
"Δy" );
404void QgsAdvancedDigitizingFloater::changeRelativeZ(
bool relative )
408 mZLabel->setText(
"z" );
412 mZLabel->setText(
"Δz" );
417void QgsAdvancedDigitizingFloater::changeRelativeM(
bool relative )
421 mMLabel->setText(
"m" );
425 mMLabel->setText(
"Δm" );
432void QgsAdvancedDigitizingFloater::changeRelativeAngle(
bool relative )
436 mAngleLabel->setText(
"a" );
440 mAngleLabel->setText(
"Δa" );
445void QgsAdvancedDigitizingFloater::focusOnX()
449 mXLineEdit->setFocus();
450 mXLineEdit->selectAll();
454void QgsAdvancedDigitizingFloater::focusOnY()
458 mYLineEdit->setFocus();
459 mYLineEdit->selectAll();
463void QgsAdvancedDigitizingFloater::focusOnZ()
467 mZLineEdit->setFocus();
468 mZLineEdit->selectAll();
472void QgsAdvancedDigitizingFloater::focusOnM()
476 mMLineEdit->setFocus();
477 mMLineEdit->selectAll();
481void QgsAdvancedDigitizingFloater::focusOnDistance()
486 mDistanceLineEdit->setText( cleanedInputValue );
487 mDistanceLineEdit->setFocus();
488 mDistanceLineEdit->selectAll();
492void QgsAdvancedDigitizingFloater::focusOnAngle()
497 mAngleLineEdit->setText( cleanedInputValue );
498 mAngleLineEdit->setFocus();
499 mAngleLineEdit->selectAll();
504void QgsAdvancedDigitizingFloater::enabledChangedX(
bool enabled )
511void QgsAdvancedDigitizingFloater::enabledChangedY(
bool enabled )
518void QgsAdvancedDigitizingFloater::enabledChangedZ(
bool enabled )
525void QgsAdvancedDigitizingFloater::enabledChangedM(
bool enabled )
532void QgsAdvancedDigitizingFloater::enabledChangedDistance(
bool enabled )
539void QgsAdvancedDigitizingFloater::enabledCommonAngleSnapping(
bool enabled )
546void QgsAdvancedDigitizingFloater::enabledChangedAngle(
bool enabled )
553void QgsAdvancedDigitizingFloater::enabledChangedBearing(
bool enabled )
@ Distance
Distance value.
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 focusIn()
Emitted when parent object gains focus.
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)
QgsSignalBlocker< Object > whileBlocking(Object *object)
Temporarily blocks signals from a QObject while calling a single method from the object.