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, [ = ]()
109 whileBlocking( mAngleLineEdit )->setText( cleanedInputValue );
111 connect( mDistanceLineEdit, &QLineEdit::returnPressed, cadDockWidget, [ = ]()
115 whileBlocking( mDistanceLineEdit )->setText( cleanedInputValue );
137 whileBlocking( mAngleLineEdit )->setText( mCadDockWidget->constraintAngle()->displayValue() );
142 whileBlocking( mAngleLineEdit )->setText( cleanedInputValue );
148 whileBlocking( mDistanceLineEdit )->setText( mCadDockWidget->constraintDistance()->displayValue() );
153 whileBlocking( mDistanceLineEdit )->setText( cleanedInputValue );
155 changeCommonAngleSnapping( mCadDockWidget->commonAngleConstraint() );
161bool QgsAdvancedDigitizingFloater::eventFilter( QObject *obj, QEvent *event )
163 if ( mCadDockWidget && mCadDockWidget->cadEnabled() && mActive )
165 if ( event->type() == QEvent::MouseMove )
168 QMouseEvent *mouseEvent =
dynamic_cast<QMouseEvent *
>( event );
169 updatePos( mouseEvent->pos() );
171 else if ( event->type() == QEvent::Enter )
174 QEnterEvent *enterEvent =
dynamic_cast<QEnterEvent *
>( event );
175 updatePos( enterEvent->pos() );
178 else if ( event->type() == QEvent::Leave )
184 return QWidget::eventFilter( obj, event );
194 return mItemsVisibility.testFlag( item );
208 const QMetaEnum enumData { QMetaEnum::fromType<QgsAdvancedDigitizingFloater::FloaterItem>() };
209 QgsSettings().
setValue( QStringLiteral(
"/Cad/%1ShowInFloater" ).arg( enumData.valueToKey(
static_cast<int>( item ) ) ), visible );
210 mItemsVisibility.setFlag( item, visible );
214 enabledChangedX( visible );
217 enabledChangedY( visible );
220 enabledChangedM( visible );
223 enabledChangedZ( visible );
226 enabledChangedAngle( visible );
229 enabledChangedDistance( visible );
232 enabledCommonAngleSnapping( visible );
235 enabledChangedBearing( visible );
240void QgsAdvancedDigitizingFloater::updatePos(
const QPoint &pos )
243 move( pos + QPoint( 15, 5 ) );
246void QgsAdvancedDigitizingFloater::hideIfDisabled()
248 if ( !mCadDockWidget || ! mCadDockWidget->cadEnabled() || ! mActive )
254void QgsAdvancedDigitizingFloater::changeX(
const QString &text )
256 mXLineEdit->setText( text );
259void QgsAdvancedDigitizingFloater::changeY(
const QString &text )
261 mYLineEdit->setText( text );
264void QgsAdvancedDigitizingFloater::changeZ(
const QString &text )
266 mZLineEdit->setText( text );
269void QgsAdvancedDigitizingFloater::changeM(
const QString &text )
271 mMLineEdit->setText( text );
274void QgsAdvancedDigitizingFloater::changeCommonAngleSnapping(
double angle )
276 mCommonAngleSnappingLineEdit->setText(
qgsDoubleNear( angle, 0.0 ) ? tr(
"disabled" ) : QLocale().toString(
angle ).append( tr(
" °" ) ) );
279void QgsAdvancedDigitizingFloater::changeDistance(
const QString &text )
281 mDistanceLineEdit->setText( text );
284void QgsAdvancedDigitizingFloater::changeAngle(
const QString &text )
286 mAngleLineEdit->setText( text );
289void QgsAdvancedDigitizingFloater::changeBearing(
const QString &text )
291 mBearingLineEdit->setText( text );
294void QgsAdvancedDigitizingFloater::changeLockX(
bool locked )
298 mXLineEdit->setStyleSheet( QString() );
299 mXLabel->setStyleSheet( QString() );
303 mXLineEdit->setStyleSheet( QStringLiteral(
"font-weight: bold" ) );
304 mXLabel->setStyleSheet( QStringLiteral(
"font-weight: bold" ) );
308void QgsAdvancedDigitizingFloater::changeLockY(
bool locked )
312 mYLineEdit->setStyleSheet( QString() );
313 mYLabel->setStyleSheet( QString() );
317 mYLineEdit->setStyleSheet( QStringLiteral(
"font-weight: bold" ) );
318 mYLabel->setStyleSheet( QStringLiteral(
"font-weight: bold" ) );
322void QgsAdvancedDigitizingFloater::changeLockZ(
bool locked )
326 mZLineEdit->setStyleSheet( QString() );
327 mZLabel->setStyleSheet( QString() );
331 mZLineEdit->setStyleSheet( QStringLiteral(
"font-weight: bold" ) );
332 mZLabel->setStyleSheet( QStringLiteral(
"font-weight: bold" ) );
336void QgsAdvancedDigitizingFloater::changeLockM(
bool locked )
340 mMLineEdit->setStyleSheet( QString() );
341 mMLabel->setStyleSheet( QString() );
345 mMLineEdit->setStyleSheet( QStringLiteral(
"font-weight: bold" ) );
346 mMLabel->setStyleSheet( QStringLiteral(
"font-weight: bold" ) );
350void QgsAdvancedDigitizingFloater::changeLockDistance(
bool locked )
354 mDistanceLineEdit->setStyleSheet( QString() );
355 mDistanceLabel->setStyleSheet( QString() );
359 mDistanceLineEdit->setStyleSheet( QStringLiteral(
"font-weight: bold" ) );
360 mDistanceLabel->setStyleSheet( QStringLiteral(
"font-weight: bold" ) );
364void QgsAdvancedDigitizingFloater::changeLockAngle(
bool locked )
368 mAngleLineEdit->setStyleSheet( QString() );
369 mAngleLabel->setStyleSheet( QString() );
373 mAngleLineEdit->setStyleSheet( QStringLiteral(
"font-weight: bold" ) );
374 mAngleLabel->setStyleSheet( QStringLiteral(
"font-weight: bold" ) );
379void QgsAdvancedDigitizingFloater::changeRelativeX(
bool relative )
383 mXLabel->setText(
"x" );
387 mXLabel->setText(
"Δx" );
392void QgsAdvancedDigitizingFloater::changeRelativeY(
bool relative )
396 mYLabel->setText(
"y" );
400 mYLabel->setText(
"Δy" );
405void QgsAdvancedDigitizingFloater::changeRelativeZ(
bool relative )
409 mZLabel->setText(
"z" );
413 mZLabel->setText(
"Δz" );
418void QgsAdvancedDigitizingFloater::changeRelativeM(
bool relative )
422 mMLabel->setText(
"m" );
426 mMLabel->setText(
"Δm" );
433void QgsAdvancedDigitizingFloater::changeRelativeAngle(
bool relative )
437 mAngleLabel->setText(
"a" );
441 mAngleLabel->setText(
"Δa" );
446void QgsAdvancedDigitizingFloater::focusOnX()
450 mXLineEdit->setFocus();
451 mXLineEdit->selectAll();
455void QgsAdvancedDigitizingFloater::focusOnY()
459 mYLineEdit->setFocus();
460 mYLineEdit->selectAll();
464void QgsAdvancedDigitizingFloater::focusOnZ()
468 mZLineEdit->setFocus();
469 mZLineEdit->selectAll();
473void QgsAdvancedDigitizingFloater::focusOnM()
477 mMLineEdit->setFocus();
478 mMLineEdit->selectAll();
482void QgsAdvancedDigitizingFloater::focusOnDistance()
487 mDistanceLineEdit->setText( cleanedInputValue );
488 mDistanceLineEdit->setFocus();
489 mDistanceLineEdit->selectAll();
493void QgsAdvancedDigitizingFloater::focusOnAngle()
498 mAngleLineEdit->setText( cleanedInputValue );
499 mAngleLineEdit->setFocus();
500 mAngleLineEdit->selectAll();
505void QgsAdvancedDigitizingFloater::enabledChangedX(
bool enabled )
512void QgsAdvancedDigitizingFloater::enabledChangedY(
bool enabled )
519void QgsAdvancedDigitizingFloater::enabledChangedZ(
bool enabled )
526void QgsAdvancedDigitizingFloater::enabledChangedM(
bool enabled )
533void QgsAdvancedDigitizingFloater::enabledChangedDistance(
bool enabled )
540void QgsAdvancedDigitizingFloater::enabledCommonAngleSnapping(
bool enabled )
547void QgsAdvancedDigitizingFloater::enabledChangedAngle(
bool enabled )
554void 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.