Move CadConstraintType to Qgis, translate degree symbol

This commit is contained in:
Alessandro Pasotti 2023-05-11 09:36:30 +02:00 committed by Nyall Dawson
parent 49d1b61f30
commit f63dd2c360
7 changed files with 85 additions and 66 deletions

View File

@ -2428,6 +2428,17 @@ Qgis.LineExtensionSide.__doc__ = 'Designates whether the line extension constrai
# -- # --
Qgis.LineExtensionSide.baseClass = Qgis Qgis.LineExtensionSide.baseClass = Qgis
# monkey patching scoped based enum # monkey patching scoped based enum
Qgis.CadConstraintType.Generic.__doc__ = "Generic value"
Qgis.CadConstraintType.Angle.__doc__ = "Angle value"
Qgis.CadConstraintType.Distance.__doc__ = "Distance value"
Qgis.CadConstraintType.XCoordinate.__doc__ = "X Coordinate value"
Qgis.CadConstraintType.YCoordinate.__doc__ = "Y Coordinate value"
Qgis.CadConstraintType.ZValue.__doc__ = "Z value"
Qgis.CadConstraintType.MValue.__doc__ = "M value"
Qgis.CadConstraintType.__doc__ = 'Advanced digitizing constraint type.\n\n.. versionadded:: 3.32\n\n' + '* ``Generic``: ' + Qgis.CadConstraintType.Generic.__doc__ + '\n' + '* ``Angle``: ' + Qgis.CadConstraintType.Angle.__doc__ + '\n' + '* ``Distance``: ' + Qgis.CadConstraintType.Distance.__doc__ + '\n' + '* ``XCoordinate``: ' + Qgis.CadConstraintType.XCoordinate.__doc__ + '\n' + '* ``YCoordinate``: ' + Qgis.CadConstraintType.YCoordinate.__doc__ + '\n' + '* ``ZValue``: ' + Qgis.CadConstraintType.ZValue.__doc__ + '\n' + '* ``MValue``: ' + Qgis.CadConstraintType.MValue.__doc__
# --
Qgis.CadConstraintType.baseClass = Qgis
# monkey patching scoped based enum
Qgis.ProjectFlag.EvaluateDefaultValuesOnProviderSide.__doc__ = "If set, default values for fields will be evaluated on the provider side when features from the project are created instead of when they are committed." Qgis.ProjectFlag.EvaluateDefaultValuesOnProviderSide.__doc__ = "If set, default values for fields will be evaluated on the provider side when features from the project are created instead of when they are committed."
Qgis.ProjectFlag.TrustStoredLayerStatistics.__doc__ = "If set, then layer statistics (such as the layer extent) will be read from values stored in the project instead of requesting updated values from the data provider. Additionally, when this flag is set, primary key unicity is not checked for views and materialized views with Postgres provider." Qgis.ProjectFlag.TrustStoredLayerStatistics.__doc__ = "If set, then layer statistics (such as the layer extent) will be read from values stored in the project instead of requesting updated values from the data provider. Additionally, when this flag is set, primary key unicity is not checked for views and materialized views with Postgres provider."
Qgis.ProjectFlag.RememberLayerEditStatusBetweenSessions.__doc__ = "If set, then any layers set to be editable will be stored in the project and immediately made editable whenever that project is restored" Qgis.ProjectFlag.RememberLayerEditStatusBetweenSessions.__doc__ = "If set, then any layers set to be editable will be stored in the project and immediately made editable whenever that project is restored"

View File

@ -1460,6 +1460,19 @@ The development version
NoVertex, NoVertex,
}; };
enum class CadConstraintType
{
Generic,
Angle,
Distance,
XCoordinate,
YCoordinate,
ZValue,
MValue,
};
enum class ProjectFlag enum class ProjectFlag
{ {
EvaluateDefaultValuesOnProviderSide, EvaluateDefaultValuesOnProviderSide,

View File

@ -65,17 +65,6 @@ It contains all values (locked, value, relative) and pointers to corresponding w
HardLock HardLock
}; };
enum ConstraintType
{
Generic,
Angle,
Distance,
XCoordinate,
YCoordinate,
ZValue,
MValue,
};
CadConstraint( QLineEdit *lineEdit, QToolButton *lockerButton, QToolButton *relativeButton = 0, QToolButton *repeatingLockButton = 0 ); CadConstraint( QLineEdit *lineEdit, QToolButton *lockerButton, QToolButton *relativeButton = 0, QToolButton *repeatingLockButton = 0 );
%Docstring %Docstring
Constructor for CadConstraint. Constructor for CadConstraint.
@ -188,14 +177,14 @@ Sets the numeric precision (decimal places) to show in the associated widget.
.. versionadded:: 3.22 .. versionadded:: 3.22
%End %End
ConstraintType constraintType() const; Qgis::CadConstraintType cadConstraintType() const;
%Docstring %Docstring
Returns the constraint type Returns the constraint type
.. versionadded:: 3.32 .. versionadded:: 3.32
%End %End
void setConstraintType( ConstraintType constraintType ); void setCadConstraintType( Qgis::CadConstraintType constraintType );
%Docstring %Docstring
Sets the constraint type to ``constraintType`` Sets the constraint type to ``constraintType``

View File

@ -2486,6 +2486,24 @@ class CORE_EXPORT Qgis
}; };
Q_ENUM( LineExtensionSide ) Q_ENUM( LineExtensionSide )
/**
* Advanced digitizing constraint type.
* \since QGIS 3.32
*/
enum class CadConstraintType : int
{
Generic, //!< Generic value
Angle, //!< Angle value
Distance, //!< Distance value
XCoordinate, //!< X Coordinate value
YCoordinate, //!< Y Coordinate value
ZValue, //!< Z value
MValue, //!< M value
};
Q_ENUM( CadConstraintType )
/** /**
* Flags which control the behavior of QgsProjects. * Flags which control the behavior of QgsProjects.
* *

View File

@ -49,22 +49,22 @@ QgsAdvancedDigitizingDockWidget::QgsAdvancedDigitizingDockWidget( QgsMapCanvas *
mCadPaintItem = new QgsAdvancedDigitizingCanvasItem( canvas, this ); mCadPaintItem = new QgsAdvancedDigitizingCanvasItem( canvas, this );
mAngleConstraint.reset( new CadConstraint( mAngleLineEdit, mLockAngleButton, mRelativeAngleButton, mRepeatingLockAngleButton ) ); mAngleConstraint.reset( new CadConstraint( mAngleLineEdit, mLockAngleButton, mRelativeAngleButton, mRepeatingLockAngleButton ) );
mAngleConstraint->setConstraintType( CadConstraint::ConstraintType::Angle ); mAngleConstraint->setCadConstraintType( Qgis::CadConstraintType::Angle );
mAngleConstraint->setMapCanvas( mMapCanvas ); mAngleConstraint->setMapCanvas( mMapCanvas );
mDistanceConstraint.reset( new CadConstraint( mDistanceLineEdit, mLockDistanceButton, nullptr, mRepeatingLockDistanceButton ) ); mDistanceConstraint.reset( new CadConstraint( mDistanceLineEdit, mLockDistanceButton, nullptr, mRepeatingLockDistanceButton ) );
mDistanceConstraint->setConstraintType( CadConstraint::ConstraintType::Distance ); mDistanceConstraint->setCadConstraintType( Qgis::CadConstraintType::Distance );
mDistanceConstraint->setMapCanvas( mMapCanvas ); mDistanceConstraint->setMapCanvas( mMapCanvas );
mXConstraint.reset( new CadConstraint( mXLineEdit, mLockXButton, mRelativeXButton, mRepeatingLockXButton ) ); mXConstraint.reset( new CadConstraint( mXLineEdit, mLockXButton, mRelativeXButton, mRepeatingLockXButton ) );
mXConstraint->setConstraintType( CadConstraint::ConstraintType::XCoordinate ); mXConstraint->setCadConstraintType( Qgis::CadConstraintType::XCoordinate );
mXConstraint->setMapCanvas( mMapCanvas ); mXConstraint->setMapCanvas( mMapCanvas );
mYConstraint.reset( new CadConstraint( mYLineEdit, mLockYButton, mRelativeYButton, mRepeatingLockYButton ) ); mYConstraint.reset( new CadConstraint( mYLineEdit, mLockYButton, mRelativeYButton, mRepeatingLockYButton ) );
mYConstraint->setConstraintType( CadConstraint::ConstraintType::YCoordinate ); mYConstraint->setCadConstraintType( Qgis::CadConstraintType::YCoordinate );
mYConstraint->setMapCanvas( mMapCanvas ); mYConstraint->setMapCanvas( mMapCanvas );
mZConstraint.reset( new CadConstraint( mZLineEdit, mLockZButton, mRelativeZButton, mRepeatingLockZButton ) ); mZConstraint.reset( new CadConstraint( mZLineEdit, mLockZButton, mRelativeZButton, mRepeatingLockZButton ) );
mZConstraint->setConstraintType( CadConstraint::ConstraintType::ZValue ); mZConstraint->setCadConstraintType( Qgis::CadConstraintType::ZValue );
mZConstraint->setMapCanvas( mMapCanvas ); mZConstraint->setMapCanvas( mMapCanvas );
mMConstraint.reset( new CadConstraint( mMLineEdit, mLockMButton, mRelativeMButton, mRepeatingLockMButton ) ); mMConstraint.reset( new CadConstraint( mMLineEdit, mLockMButton, mRelativeMButton, mRepeatingLockMButton ) );
mMConstraint->setConstraintType( CadConstraint::ConstraintType::MValue ); mMConstraint->setCadConstraintType( Qgis::CadConstraintType::MValue );
mMConstraint->setMapCanvas( mMapCanvas ); mMConstraint->setMapCanvas( mMapCanvas );
mLineExtensionConstraint.reset( new CadConstraint( new QLineEdit(), new QToolButton() ) ); mLineExtensionConstraint.reset( new CadConstraint( new QLineEdit(), new QToolButton() ) );
@ -703,40 +703,43 @@ QgsAdvancedDigitizingDockWidget::CadConstraint *QgsAdvancedDigitizingDockWidget:
return constraint; return constraint;
} }
double QgsAdvancedDigitizingDockWidget::parseUserInput( const QString &inputValue, const CadConstraint::ConstraintType type, bool &ok ) const double QgsAdvancedDigitizingDockWidget::parseUserInput( const QString &inputValue, const Qgis::CadConstraintType type, bool &ok ) const
{ {
ok = false; ok = false;
QString cleanedInputValue { inputValue }; QString cleanedInputValue { inputValue };
// Remove angle suffix // Remove angle suffix
if ( type == QgsAdvancedDigitizingDockWidget::CadConstraint::ConstraintType::Angle ) if ( type == Qgis::CadConstraintType::Angle )
cleanedInputValue.remove( QStringLiteral( "°" ) ); cleanedInputValue.remove( tr( "°" ) );
// Remove distance unit suffix // Remove distance unit suffix
const Qgis::DistanceUnit distanceUnit { QgsProject::instance()->distanceUnits() }; const Qgis::DistanceUnit distanceUnit { QgsProject::instance()->distanceUnits() };
if ( type == QgsAdvancedDigitizingDockWidget::CadConstraint::ConstraintType::Distance ) if ( type == Qgis::CadConstraintType::Distance )
cleanedInputValue.remove( QgsUnitTypes::toAbbreviatedString( distanceUnit ) ); cleanedInputValue.remove( QgsUnitTypes::toAbbreviatedString( distanceUnit ) );
double value = qgsPermissiveToDouble( cleanedInputValue, ok ); double value = qgsPermissiveToDouble( cleanedInputValue, ok );
if ( ok ) if ( ok )
{ {
// Note: only distance is formatted for now, but it would be nice to
// handle other constraints in the future, this is the reason
// for the switch.
switch ( type ) switch ( type )
{ {
case QgsAdvancedDigitizingDockWidget::CadConstraint::ConstraintType::Distance: case Qgis::CadConstraintType::Distance:
{ {
// Convert distance to meters // Convert distance to meters
const double factorUnits = QgsUnitTypes::fromUnitToUnitFactor( distanceUnit, Qgis::DistanceUnit::Meters ); const double factorUnits = QgsUnitTypes::fromUnitToUnitFactor( distanceUnit, Qgis::DistanceUnit::Meters );
value *= factorUnits; value *= factorUnits;
break; break;
} }
case QgsAdvancedDigitizingDockWidget::CadConstraint::ConstraintType::Generic: case Qgis::CadConstraintType::Generic:
case QgsAdvancedDigitizingDockWidget::CadConstraint::ConstraintType::Angle: case Qgis::CadConstraintType::Angle:
case QgsAdvancedDigitizingDockWidget::CadConstraint::ConstraintType::ZValue: case Qgis::CadConstraintType::ZValue:
case QgsAdvancedDigitizingDockWidget::CadConstraint::ConstraintType::MValue: case Qgis::CadConstraintType::MValue:
case QgsAdvancedDigitizingDockWidget::CadConstraint::ConstraintType::XCoordinate: case Qgis::CadConstraintType::XCoordinate:
case QgsAdvancedDigitizingDockWidget::CadConstraint::ConstraintType::YCoordinate: case Qgis::CadConstraintType::YCoordinate:
break; break;
} }
} }
@ -792,7 +795,7 @@ void QgsAdvancedDigitizingDockWidget::updateConstraintValue( CadConstraint *cons
return; return;
bool ok; bool ok;
const double value = parseUserInput( textValue, constraint->constraintType(), ok ); const double value = parseUserInput( textValue, constraint->cadConstraintType(), ok );
if ( !ok ) if ( !ok )
return; return;
@ -815,7 +818,7 @@ void QgsAdvancedDigitizingDockWidget::lockConstraint( bool activate /* default t
if ( !textValue.isEmpty() ) if ( !textValue.isEmpty() )
{ {
bool ok; bool ok;
const double value = parseUserInput( textValue, constraint->constraintType(), ok ); const double value = parseUserInput( textValue, constraint->cadConstraintType(), ok );
if ( ok ) if ( ok )
{ {
constraint->setValue( value ); constraint->setValue( value );
@ -1889,25 +1892,25 @@ void QgsAdvancedDigitizingDockWidget::CadConstraint::setValue( double value, boo
QString QgsAdvancedDigitizingDockWidget::CadConstraint::displayValue() const QString QgsAdvancedDigitizingDockWidget::CadConstraint::displayValue() const
{ {
switch ( mConstraintType ) switch ( mCadConstraintType )
{ {
case CadConstraint::ConstraintType::Angle: case Qgis::CadConstraintType::Angle:
{ {
return QLocale().toString( mValue, 'f', mPrecision ).append( QStringLiteral( " °" ) ); return QLocale().toString( mValue, 'f', mPrecision ).append( tr( " °" ) );
} }
case CadConstraint::ConstraintType::XCoordinate: case Qgis::CadConstraintType::XCoordinate:
case CadConstraint::ConstraintType::YCoordinate: case Qgis::CadConstraintType::YCoordinate:
{ {
if ( mMapCanvas->mapSettings().destinationCrs().isGeographic() ) if ( mMapCanvas->mapSettings().destinationCrs().isGeographic() )
{ {
return QLocale().toString( mValue, 'f', mPrecision ).append( QStringLiteral( " °" ) ); return QLocale().toString( mValue, 'f', mPrecision ).append( tr( " °" ) );
} }
else else
{ {
return QLocale().toString( mValue, 'f', mPrecision ); return QLocale().toString( mValue, 'f', mPrecision );
} }
} }
case CadConstraint::ConstraintType::Distance: case Qgis::CadConstraintType::Distance:
{ {
// Value is always in meters (cartesian) #spellok // Value is always in meters (cartesian) #spellok
const Qgis::DistanceUnit units { QgsProject::instance()->distanceUnits() }; const Qgis::DistanceUnit units { QgsProject::instance()->distanceUnits() };
@ -1915,9 +1918,9 @@ QString QgsAdvancedDigitizingDockWidget::CadConstraint::displayValue() const
const double convertedValue { mValue * factorUnits }; const double convertedValue { mValue * factorUnits };
return QgsDistanceArea::formatDistance( convertedValue, mPrecision, units, true ); return QgsDistanceArea::formatDistance( convertedValue, mPrecision, units, true );
} }
case CadConstraint::ConstraintType::Generic: case Qgis::CadConstraintType::Generic:
case CadConstraint::ConstraintType::ZValue: case Qgis::CadConstraintType::ZValue:
case CadConstraint::ConstraintType::MValue: case Qgis::CadConstraintType::MValue:
default: default:
break; break;
} }
@ -1941,14 +1944,14 @@ void QgsAdvancedDigitizingDockWidget::CadConstraint::setPrecision( int precision
mLineEdit->setText( displayValue() ); mLineEdit->setText( displayValue() );
} }
QgsAdvancedDigitizingDockWidget::CadConstraint::ConstraintType QgsAdvancedDigitizingDockWidget::CadConstraint::constraintType() const Qgis::CadConstraintType QgsAdvancedDigitizingDockWidget::CadConstraint::cadConstraintType() const
{ {
return mConstraintType; return mCadConstraintType;
} }
void QgsAdvancedDigitizingDockWidget::CadConstraint::setConstraintType( QgsAdvancedDigitizingDockWidget::CadConstraint::ConstraintType constraintType ) void QgsAdvancedDigitizingDockWidget::CadConstraint::setCadConstraintType( Qgis::CadConstraintType constraintType )
{ {
mConstraintType = constraintType; mCadConstraintType = constraintType;
} }
void QgsAdvancedDigitizingDockWidget::CadConstraint::setMapCanvas( QgsMapCanvas *mapCanvas ) void QgsAdvancedDigitizingDockWidget::CadConstraint::setMapCanvas( QgsMapCanvas *mapCanvas )

View File

@ -98,21 +98,6 @@ class GUI_EXPORT QgsAdvancedDigitizingDockWidget : public QgsDockWidget, private
HardLock HardLock
}; };
/**
* Constraint type
* \since QGIS 3.32
*/
enum ConstraintType
{
Generic, //!< Generic value
Angle, //!< Angle value
Distance, //!< Distance value
XCoordinate, //!< X Coordinate value
YCoordinate, //!< Y Coordinate value
ZValue, //!< Z value
MValue, //!< M value
};
/** /**
* Constructor for CadConstraint. * Constructor for CadConstraint.
* \param lineEdit associated line edit for constraint value * \param lineEdit associated line edit for constraint value
@ -227,13 +212,13 @@ class GUI_EXPORT QgsAdvancedDigitizingDockWidget : public QgsDockWidget, private
* Returns the constraint type * Returns the constraint type
* \since QGIS 3.32 * \since QGIS 3.32
*/ */
ConstraintType constraintType() const; Qgis::CadConstraintType cadConstraintType() const;
/** /**
* Sets the constraint type to \a constraintType * Sets the constraint type to \a constraintType
* \since QGIS 3.32 * \since QGIS 3.32
*/ */
void setConstraintType( ConstraintType constraintType ); void setCadConstraintType( Qgis::CadConstraintType constraintType );
/** /**
* Sets the map canvas to \a mapCanvas * Sets the map canvas to \a mapCanvas
@ -251,7 +236,7 @@ class GUI_EXPORT QgsAdvancedDigitizingDockWidget : public QgsDockWidget, private
bool mRelative; bool mRelative;
double mValue; double mValue;
int mPrecision = 6; int mPrecision = 6;
ConstraintType mConstraintType = ConstraintType::Generic; Qgis::CadConstraintType mCadConstraintType = Qgis::CadConstraintType::Generic;
QgsMapCanvas *mMapCanvas = nullptr; QgsMapCanvas *mMapCanvas = nullptr;
}; };
@ -1009,7 +994,7 @@ class GUI_EXPORT QgsAdvancedDigitizingDockWidget : public QgsDockWidget, private
CadConstraint *objectToConstraint( const QObject *obj ) const; CadConstraint *objectToConstraint( const QObject *obj ) const;
//! Attempts to convert a user input value to double, either directly or via expression //! Attempts to convert a user input value to double, either directly or via expression
double parseUserInput( const QString &inputValue, const CadConstraint::ConstraintType type, bool &ok ) const; double parseUserInput( const QString &inputValue, const Qgis::CadConstraintType type, bool &ok ) const;
/** /**
* Updates a constraint value based on a text input. * Updates a constraint value based on a text input.

View File

@ -198,7 +198,7 @@ void QgsAdvancedDigitizingFloater::changeM( const QString &text )
void QgsAdvancedDigitizingFloater::changeCommonAngleSnapping( double angle ) void QgsAdvancedDigitizingFloater::changeCommonAngleSnapping( double angle )
{ {
mCommonAngleSnappingLineEdit->setText( qgsDoubleNear( angle, 0.0 ) ? tr( "disabled" ) : QLocale().toString( angle ).append( QStringLiteral( "°" ) ) ); mCommonAngleSnappingLineEdit->setText( qgsDoubleNear( angle, 0.0 ) ? tr( "disabled" ) : QLocale().toString( angle ).append( tr( " °" ) ) );
} }
void QgsAdvancedDigitizingFloater::changeDistance( const QString &text ) void QgsAdvancedDigitizingFloater::changeDistance( const QString &text )