21#include "moc_qgsadvanceddigitizingfloater.cpp"
28 : QWidget( canvas->viewport() )
29 , mMapCanvas( canvas )
30 , mCadDockWidget( cadDockWidget )
34 setAttribute( Qt::WA_TransparentForMouseEvents );
44 mMapCanvas->viewport()->installEventFilter(
this );
45 mMapCanvas->viewport()->setMouseTracking(
true );
48 mAngleLineEdit->installEventFilter( cadDockWidget );
49 mDistanceLineEdit->installEventFilter( cadDockWidget );
50 mXLineEdit->installEventFilter( cadDockWidget );
51 mYLineEdit->installEventFilter( cadDockWidget );
52 mZLineEdit->installEventFilter( cadDockWidget );
53 mMLineEdit->installEventFilter( cadDockWidget );
105 connect( mAngleLineEdit, &QLineEdit::returnPressed, cadDockWidget, [=]() {
108 whileBlocking( mAngleLineEdit )->setText( cleanedInputValue );
110 connect( mDistanceLineEdit, &QLineEdit::returnPressed, cadDockWidget, [=]() {
113 whileBlocking( mDistanceLineEdit )->setText( cleanedInputValue );
134 whileBlocking( mAngleLineEdit )->setText( mCadDockWidget->constraintAngle()->displayValue() );
138 whileBlocking( mAngleLineEdit )->setText( cleanedInputValue );
143 whileBlocking( mDistanceLineEdit )->setText( mCadDockWidget->constraintDistance()->displayValue() );
147 whileBlocking( mDistanceLineEdit )->setText( cleanedInputValue );
149 changeCommonAngleSnapping( mCadDockWidget->commonAngleConstraint() );
152bool QgsAdvancedDigitizingFloater::eventFilter( QObject *obj, QEvent *event )
154 if ( mCadDockWidget && mCadDockWidget->cadEnabled() && mActive )
156 if ( event->type() == QEvent::MouseMove )
159 QMouseEvent *mouseEvent =
dynamic_cast<QMouseEvent *
>( event );
160 updatePos( mouseEvent->pos() );
162 else if ( event->type() == QEvent::Enter )
165 QEnterEvent *enterEvent =
dynamic_cast<QEnterEvent *
>( event );
166 updatePos( enterEvent->pos() );
169 else if ( event->type() == QEvent::Leave )
175 return QWidget::eventFilter( obj, event );
185 return mItemsVisibility.testFlag( item );
199 const QMetaEnum enumData { QMetaEnum::fromType<QgsAdvancedDigitizingFloater::FloaterItem>() };
200 QgsSettings().
setValue( QStringLiteral(
"/Cad/%1ShowInFloater" ).arg( enumData.valueToKey(
static_cast<int>( item ) ) ), visible );
201 mItemsVisibility.setFlag( item, visible );
205 enabledChangedX( visible );
208 enabledChangedY( visible );
211 enabledChangedM( visible );
214 enabledChangedZ( visible );
217 enabledChangedAngle( visible );
220 enabledChangedDistance( visible );
223 enabledCommonAngleSnapping( visible );
226 enabledChangedBearing( visible );
231void QgsAdvancedDigitizingFloater::updatePos(
const QPoint &pos )
234 move( pos + QPoint( 15, 5 ) );
237void QgsAdvancedDigitizingFloater::hideIfDisabled()
239 if ( !mCadDockWidget || !mCadDockWidget->cadEnabled() || !mActive )
245void QgsAdvancedDigitizingFloater::changeX(
const QString &text )
247 mXLineEdit->setText( text );
250void QgsAdvancedDigitizingFloater::changeY(
const QString &text )
252 mYLineEdit->setText( text );
255void QgsAdvancedDigitizingFloater::changeZ(
const QString &text )
257 mZLineEdit->setText( text );
260void QgsAdvancedDigitizingFloater::changeM(
const QString &text )
262 mMLineEdit->setText( text );
265void QgsAdvancedDigitizingFloater::changeCommonAngleSnapping(
double angle )
267 mCommonAngleSnappingLineEdit->setText(
qgsDoubleNear( angle, 0.0 ) ? tr(
"disabled" ) : QLocale().toString(
angle ).append( tr(
" °" ) ) );
270void QgsAdvancedDigitizingFloater::changeDistance(
const QString &text )
272 mDistanceLineEdit->setText( text );
275void QgsAdvancedDigitizingFloater::changeAngle(
const QString &text )
277 mAngleLineEdit->setText( text );
280void QgsAdvancedDigitizingFloater::changeBearing(
const QString &text )
282 mBearingLineEdit->setText( text );
285void QgsAdvancedDigitizingFloater::changeLockX(
bool locked )
289 mXLineEdit->setStyleSheet( QString() );
290 mXLabel->setStyleSheet( QString() );
294 mXLineEdit->setStyleSheet( QStringLiteral(
"font-weight: bold" ) );
295 mXLabel->setStyleSheet( QStringLiteral(
"font-weight: bold" ) );
299void QgsAdvancedDigitizingFloater::changeLockY(
bool locked )
303 mYLineEdit->setStyleSheet( QString() );
304 mYLabel->setStyleSheet( QString() );
308 mYLineEdit->setStyleSheet( QStringLiteral(
"font-weight: bold" ) );
309 mYLabel->setStyleSheet( QStringLiteral(
"font-weight: bold" ) );
313void QgsAdvancedDigitizingFloater::changeLockZ(
bool locked )
317 mZLineEdit->setStyleSheet( QString() );
318 mZLabel->setStyleSheet( QString() );
322 mZLineEdit->setStyleSheet( QStringLiteral(
"font-weight: bold" ) );
323 mZLabel->setStyleSheet( QStringLiteral(
"font-weight: bold" ) );
327void QgsAdvancedDigitizingFloater::changeLockM(
bool locked )
331 mMLineEdit->setStyleSheet( QString() );
332 mMLabel->setStyleSheet( QString() );
336 mMLineEdit->setStyleSheet( QStringLiteral(
"font-weight: bold" ) );
337 mMLabel->setStyleSheet( QStringLiteral(
"font-weight: bold" ) );
341void QgsAdvancedDigitizingFloater::changeLockDistance(
bool locked )
345 mDistanceLineEdit->setStyleSheet( QString() );
346 mDistanceLabel->setStyleSheet( QString() );
350 mDistanceLineEdit->setStyleSheet( QStringLiteral(
"font-weight: bold" ) );
351 mDistanceLabel->setStyleSheet( QStringLiteral(
"font-weight: bold" ) );
355void QgsAdvancedDigitizingFloater::changeLockAngle(
bool locked )
359 mAngleLineEdit->setStyleSheet( QString() );
360 mAngleLabel->setStyleSheet( QString() );
364 mAngleLineEdit->setStyleSheet( QStringLiteral(
"font-weight: bold" ) );
365 mAngleLabel->setStyleSheet( QStringLiteral(
"font-weight: bold" ) );
370void QgsAdvancedDigitizingFloater::changeRelativeX(
bool relative )
374 mXLabel->setText(
"x" );
378 mXLabel->setText(
"Δx" );
383void QgsAdvancedDigitizingFloater::changeRelativeY(
bool relative )
387 mYLabel->setText(
"y" );
391 mYLabel->setText(
"Δy" );
396void QgsAdvancedDigitizingFloater::changeRelativeZ(
bool relative )
400 mZLabel->setText(
"z" );
404 mZLabel->setText(
"Δz" );
409void QgsAdvancedDigitizingFloater::changeRelativeM(
bool relative )
413 mMLabel->setText(
"m" );
417 mMLabel->setText(
"Δm" );
424void QgsAdvancedDigitizingFloater::changeRelativeAngle(
bool relative )
428 mAngleLabel->setText(
"a" );
432 mAngleLabel->setText(
"Δa" );
437void QgsAdvancedDigitizingFloater::focusOnX()
441 mXLineEdit->setFocus();
442 mXLineEdit->selectAll();
446void QgsAdvancedDigitizingFloater::focusOnY()
450 mYLineEdit->setFocus();
451 mYLineEdit->selectAll();
455void QgsAdvancedDigitizingFloater::focusOnZ()
459 mZLineEdit->setFocus();
460 mZLineEdit->selectAll();
464void QgsAdvancedDigitizingFloater::focusOnM()
468 mMLineEdit->setFocus();
469 mMLineEdit->selectAll();
473void QgsAdvancedDigitizingFloater::focusOnDistance()
478 mDistanceLineEdit->setText( cleanedInputValue );
479 mDistanceLineEdit->setFocus();
480 mDistanceLineEdit->selectAll();
484void QgsAdvancedDigitizingFloater::focusOnAngle()
489 mAngleLineEdit->setText( cleanedInputValue );
490 mAngleLineEdit->setFocus();
491 mAngleLineEdit->selectAll();
496void QgsAdvancedDigitizingFloater::enabledChangedX(
bool enabled )
503void QgsAdvancedDigitizingFloater::enabledChangedY(
bool enabled )
510void QgsAdvancedDigitizingFloater::enabledChangedZ(
bool enabled )
517void QgsAdvancedDigitizingFloater::enabledChangedM(
bool enabled )
524void QgsAdvancedDigitizingFloater::enabledChangedDistance(
bool enabled )
531void QgsAdvancedDigitizingFloater::enabledCommonAngleSnapping(
bool enabled )
538void QgsAdvancedDigitizingFloater::enabledChangedAngle(
bool enabled )
545void 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.