mirror of
https://github.com/qgis/QGIS.git
synced 2025-12-01 00:03:42 -05:00
Move CadConstraintType to Qgis, translate degree symbol
This commit is contained in:
parent
49d1b61f30
commit
f63dd2c360
@ -2428,6 +2428,17 @@ Qgis.LineExtensionSide.__doc__ = 'Designates whether the line extension constrai
|
||||
# --
|
||||
Qgis.LineExtensionSide.baseClass = Qgis
|
||||
# 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.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"
|
||||
|
||||
@ -1460,6 +1460,19 @@ The development version
|
||||
NoVertex,
|
||||
};
|
||||
|
||||
|
||||
enum class CadConstraintType
|
||||
{
|
||||
Generic,
|
||||
Angle,
|
||||
Distance,
|
||||
XCoordinate,
|
||||
YCoordinate,
|
||||
ZValue,
|
||||
MValue,
|
||||
};
|
||||
|
||||
|
||||
enum class ProjectFlag
|
||||
{
|
||||
EvaluateDefaultValuesOnProviderSide,
|
||||
|
||||
@ -65,17 +65,6 @@ It contains all values (locked, value, relative) and pointers to corresponding w
|
||||
HardLock
|
||||
};
|
||||
|
||||
enum ConstraintType
|
||||
{
|
||||
Generic,
|
||||
Angle,
|
||||
Distance,
|
||||
XCoordinate,
|
||||
YCoordinate,
|
||||
ZValue,
|
||||
MValue,
|
||||
};
|
||||
|
||||
CadConstraint( QLineEdit *lineEdit, QToolButton *lockerButton, QToolButton *relativeButton = 0, QToolButton *repeatingLockButton = 0 );
|
||||
%Docstring
|
||||
Constructor for CadConstraint.
|
||||
@ -188,14 +177,14 @@ Sets the numeric precision (decimal places) to show in the associated widget.
|
||||
.. versionadded:: 3.22
|
||||
%End
|
||||
|
||||
ConstraintType constraintType() const;
|
||||
Qgis::CadConstraintType cadConstraintType() const;
|
||||
%Docstring
|
||||
Returns the constraint type
|
||||
|
||||
.. versionadded:: 3.32
|
||||
%End
|
||||
|
||||
void setConstraintType( ConstraintType constraintType );
|
||||
void setCadConstraintType( Qgis::CadConstraintType constraintType );
|
||||
%Docstring
|
||||
Sets the constraint type to ``constraintType``
|
||||
|
||||
|
||||
@ -2486,6 +2486,24 @@ class CORE_EXPORT Qgis
|
||||
};
|
||||
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.
|
||||
*
|
||||
|
||||
@ -49,22 +49,22 @@ QgsAdvancedDigitizingDockWidget::QgsAdvancedDigitizingDockWidget( QgsMapCanvas *
|
||||
mCadPaintItem = new QgsAdvancedDigitizingCanvasItem( canvas, this );
|
||||
|
||||
mAngleConstraint.reset( new CadConstraint( mAngleLineEdit, mLockAngleButton, mRelativeAngleButton, mRepeatingLockAngleButton ) );
|
||||
mAngleConstraint->setConstraintType( CadConstraint::ConstraintType::Angle );
|
||||
mAngleConstraint->setCadConstraintType( Qgis::CadConstraintType::Angle );
|
||||
mAngleConstraint->setMapCanvas( mMapCanvas );
|
||||
mDistanceConstraint.reset( new CadConstraint( mDistanceLineEdit, mLockDistanceButton, nullptr, mRepeatingLockDistanceButton ) );
|
||||
mDistanceConstraint->setConstraintType( CadConstraint::ConstraintType::Distance );
|
||||
mDistanceConstraint->setCadConstraintType( Qgis::CadConstraintType::Distance );
|
||||
mDistanceConstraint->setMapCanvas( mMapCanvas );
|
||||
mXConstraint.reset( new CadConstraint( mXLineEdit, mLockXButton, mRelativeXButton, mRepeatingLockXButton ) );
|
||||
mXConstraint->setConstraintType( CadConstraint::ConstraintType::XCoordinate );
|
||||
mXConstraint->setCadConstraintType( Qgis::CadConstraintType::XCoordinate );
|
||||
mXConstraint->setMapCanvas( mMapCanvas );
|
||||
mYConstraint.reset( new CadConstraint( mYLineEdit, mLockYButton, mRelativeYButton, mRepeatingLockYButton ) );
|
||||
mYConstraint->setConstraintType( CadConstraint::ConstraintType::YCoordinate );
|
||||
mYConstraint->setCadConstraintType( Qgis::CadConstraintType::YCoordinate );
|
||||
mYConstraint->setMapCanvas( mMapCanvas );
|
||||
mZConstraint.reset( new CadConstraint( mZLineEdit, mLockZButton, mRelativeZButton, mRepeatingLockZButton ) );
|
||||
mZConstraint->setConstraintType( CadConstraint::ConstraintType::ZValue );
|
||||
mZConstraint->setCadConstraintType( Qgis::CadConstraintType::ZValue );
|
||||
mZConstraint->setMapCanvas( mMapCanvas );
|
||||
mMConstraint.reset( new CadConstraint( mMLineEdit, mLockMButton, mRelativeMButton, mRepeatingLockMButton ) );
|
||||
mMConstraint->setConstraintType( CadConstraint::ConstraintType::MValue );
|
||||
mMConstraint->setCadConstraintType( Qgis::CadConstraintType::MValue );
|
||||
mMConstraint->setMapCanvas( mMapCanvas );
|
||||
|
||||
mLineExtensionConstraint.reset( new CadConstraint( new QLineEdit(), new QToolButton() ) );
|
||||
@ -703,40 +703,43 @@ QgsAdvancedDigitizingDockWidget::CadConstraint *QgsAdvancedDigitizingDockWidget:
|
||||
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;
|
||||
|
||||
QString cleanedInputValue { inputValue };
|
||||
|
||||
// Remove angle suffix
|
||||
if ( type == QgsAdvancedDigitizingDockWidget::CadConstraint::ConstraintType::Angle )
|
||||
cleanedInputValue.remove( QStringLiteral( "°" ) );
|
||||
if ( type == Qgis::CadConstraintType::Angle )
|
||||
cleanedInputValue.remove( tr( "°" ) );
|
||||
|
||||
// Remove distance unit suffix
|
||||
const Qgis::DistanceUnit distanceUnit { QgsProject::instance()->distanceUnits() };
|
||||
if ( type == QgsAdvancedDigitizingDockWidget::CadConstraint::ConstraintType::Distance )
|
||||
if ( type == Qgis::CadConstraintType::Distance )
|
||||
cleanedInputValue.remove( QgsUnitTypes::toAbbreviatedString( distanceUnit ) );
|
||||
|
||||
double value = qgsPermissiveToDouble( cleanedInputValue, 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 )
|
||||
{
|
||||
case QgsAdvancedDigitizingDockWidget::CadConstraint::ConstraintType::Distance:
|
||||
case Qgis::CadConstraintType::Distance:
|
||||
{
|
||||
// Convert distance to meters
|
||||
const double factorUnits = QgsUnitTypes::fromUnitToUnitFactor( distanceUnit, Qgis::DistanceUnit::Meters );
|
||||
value *= factorUnits;
|
||||
break;
|
||||
}
|
||||
case QgsAdvancedDigitizingDockWidget::CadConstraint::ConstraintType::Generic:
|
||||
case QgsAdvancedDigitizingDockWidget::CadConstraint::ConstraintType::Angle:
|
||||
case QgsAdvancedDigitizingDockWidget::CadConstraint::ConstraintType::ZValue:
|
||||
case QgsAdvancedDigitizingDockWidget::CadConstraint::ConstraintType::MValue:
|
||||
case QgsAdvancedDigitizingDockWidget::CadConstraint::ConstraintType::XCoordinate:
|
||||
case QgsAdvancedDigitizingDockWidget::CadConstraint::ConstraintType::YCoordinate:
|
||||
case Qgis::CadConstraintType::Generic:
|
||||
case Qgis::CadConstraintType::Angle:
|
||||
case Qgis::CadConstraintType::ZValue:
|
||||
case Qgis::CadConstraintType::MValue:
|
||||
case Qgis::CadConstraintType::XCoordinate:
|
||||
case Qgis::CadConstraintType::YCoordinate:
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -792,7 +795,7 @@ void QgsAdvancedDigitizingDockWidget::updateConstraintValue( CadConstraint *cons
|
||||
return;
|
||||
|
||||
bool ok;
|
||||
const double value = parseUserInput( textValue, constraint->constraintType(), ok );
|
||||
const double value = parseUserInput( textValue, constraint->cadConstraintType(), ok );
|
||||
if ( !ok )
|
||||
return;
|
||||
|
||||
@ -815,7 +818,7 @@ void QgsAdvancedDigitizingDockWidget::lockConstraint( bool activate /* default t
|
||||
if ( !textValue.isEmpty() )
|
||||
{
|
||||
bool ok;
|
||||
const double value = parseUserInput( textValue, constraint->constraintType(), ok );
|
||||
const double value = parseUserInput( textValue, constraint->cadConstraintType(), ok );
|
||||
if ( ok )
|
||||
{
|
||||
constraint->setValue( value );
|
||||
@ -1889,25 +1892,25 @@ void QgsAdvancedDigitizingDockWidget::CadConstraint::setValue( double value, boo
|
||||
|
||||
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 CadConstraint::ConstraintType::YCoordinate:
|
||||
case Qgis::CadConstraintType::XCoordinate:
|
||||
case Qgis::CadConstraintType::YCoordinate:
|
||||
{
|
||||
if ( mMapCanvas->mapSettings().destinationCrs().isGeographic() )
|
||||
{
|
||||
return QLocale().toString( mValue, 'f', mPrecision ).append( QStringLiteral( " °" ) );
|
||||
return QLocale().toString( mValue, 'f', mPrecision ).append( tr( " °" ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
return QLocale().toString( mValue, 'f', mPrecision );
|
||||
}
|
||||
}
|
||||
case CadConstraint::ConstraintType::Distance:
|
||||
case Qgis::CadConstraintType::Distance:
|
||||
{
|
||||
// Value is always in meters (cartesian) #spellok
|
||||
const Qgis::DistanceUnit units { QgsProject::instance()->distanceUnits() };
|
||||
@ -1915,9 +1918,9 @@ QString QgsAdvancedDigitizingDockWidget::CadConstraint::displayValue() const
|
||||
const double convertedValue { mValue * factorUnits };
|
||||
return QgsDistanceArea::formatDistance( convertedValue, mPrecision, units, true );
|
||||
}
|
||||
case CadConstraint::ConstraintType::Generic:
|
||||
case CadConstraint::ConstraintType::ZValue:
|
||||
case CadConstraint::ConstraintType::MValue:
|
||||
case Qgis::CadConstraintType::Generic:
|
||||
case Qgis::CadConstraintType::ZValue:
|
||||
case Qgis::CadConstraintType::MValue:
|
||||
default:
|
||||
break;
|
||||
}
|
||||
@ -1941,14 +1944,14 @@ void QgsAdvancedDigitizingDockWidget::CadConstraint::setPrecision( int precision
|
||||
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 )
|
||||
|
||||
@ -98,21 +98,6 @@ class GUI_EXPORT QgsAdvancedDigitizingDockWidget : public QgsDockWidget, private
|
||||
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.
|
||||
* \param lineEdit associated line edit for constraint value
|
||||
@ -227,13 +212,13 @@ class GUI_EXPORT QgsAdvancedDigitizingDockWidget : public QgsDockWidget, private
|
||||
* Returns the constraint type
|
||||
* \since QGIS 3.32
|
||||
*/
|
||||
ConstraintType constraintType() const;
|
||||
Qgis::CadConstraintType cadConstraintType() const;
|
||||
|
||||
/**
|
||||
* Sets the constraint type to \a constraintType
|
||||
* \since QGIS 3.32
|
||||
*/
|
||||
void setConstraintType( ConstraintType constraintType );
|
||||
void setCadConstraintType( Qgis::CadConstraintType constraintType );
|
||||
|
||||
/**
|
||||
* Sets the map canvas to \a mapCanvas
|
||||
@ -251,7 +236,7 @@ class GUI_EXPORT QgsAdvancedDigitizingDockWidget : public QgsDockWidget, private
|
||||
bool mRelative;
|
||||
double mValue;
|
||||
int mPrecision = 6;
|
||||
ConstraintType mConstraintType = ConstraintType::Generic;
|
||||
Qgis::CadConstraintType mCadConstraintType = Qgis::CadConstraintType::Generic;
|
||||
QgsMapCanvas *mMapCanvas = nullptr;
|
||||
};
|
||||
|
||||
@ -1009,7 +994,7 @@ class GUI_EXPORT QgsAdvancedDigitizingDockWidget : public QgsDockWidget, private
|
||||
CadConstraint *objectToConstraint( const QObject *obj ) const;
|
||||
|
||||
//! 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.
|
||||
|
||||
@ -198,7 +198,7 @@ void QgsAdvancedDigitizingFloater::changeM( const QString &text )
|
||||
|
||||
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 )
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user