1 /*************************************************************************** 2 qgsunittypes.h 3 -------------- 4 begin : February 2016 5 copyright : (C) 2016 by Nyall Dawson 6 email : nyall dot dawson at gmail dot com 7 ***************************************************************************/ 8 9 /*************************************************************************** 10 * * 11 * This program is free software; you can redistribute it and/or modify * 12 * it under the terms of the GNU General Public License as published by * 13 * the Free Software Foundation; either version 2 of the License, or * 14 * (at your option) any later version. * 15 * * 16 ***************************************************************************/ 17 18 #ifndef QGSUNITTYPES_H 19 #define QGSUNITTYPES_H 20 21 #include "qgis_core.h" 22 #include "qgis_sip.h" 23 #include <QObject> 24 25 /*************************************************************************** 26 * This class is considered CRITICAL and any change MUST be accompanied with 27 * full unit tests in test_qgsunittypes.py. 28 * See details in QEP #17 29 ****************************************************************************/ 30 31 /** 32 * \ingroup core 33 * \class QgsUnitTypes 34 * \brief Helper functions for various unit types. 35 * \since QGIS 2.14 36 */ 37 38 class CORE_EXPORT QgsUnitTypes 39 { 40 Q_GADGET 41 42 public: 43 //! Systems of unit measurement 44 enum SystemOfMeasurement 45 { 46 UnknownSystem = 0, //!< Unknown system of measurement 47 MetricSystem, //!< International System of Units (SI) 48 ImperialSystem, //!< British Imperial 49 USCSSystem //!< United States customary system 50 }; 51 Q_ENUM( SystemOfMeasurement ) 52 53 /** 54 * Unit types. 55 * \since QGIS 3.10 56 */ 57 enum UnitType 58 { 59 TypeDistance = 0, //!< Distance unit 60 TypeArea, //!< Area unit 61 TypeVolume, //!< Volume unit 62 TypeUnknown, //!< Unknown unit type 63 TypeTemporal, //!< Temporal unit 64 }; 65 66 //! Units of distance 67 enum DistanceUnit 68 { 69 DistanceMeters = 0, //!< Meters 70 DistanceKilometers, //!< Kilometers 71 DistanceFeet, //!< Imperial feet 72 DistanceNauticalMiles, //!< Nautical miles 73 DistanceYards, //!< Imperial yards 74 DistanceMiles, //!< Terrestrial miles 75 DistanceDegrees, //!< Degrees, for planar geographic CRS distance measurements 76 DistanceCentimeters, //!< Centimeters 77 DistanceMillimeters, //!< Millimeters 78 DistanceUnknownUnit, //!< Unknown distance unit 79 }; 80 Q_ENUM( DistanceUnit ) 81 82 /** 83 * Types of distance units 84 */ 85 enum DistanceUnitType 86 { 87 Standard = 0, //!< Unit is a standard measurement unit 88 Geographic, //!< Unit is a geographic (e.g., degree based) unit 89 UnknownType, //!< Unknown unit type 90 }; 91 92 //! Units of area 93 enum AreaUnit 94 { 95 AreaSquareMeters = 0, //!< Square meters 96 AreaSquareKilometers, //!< Square kilometers 97 AreaSquareFeet, //!< Square feet 98 AreaSquareYards, //!< Square yards 99 AreaSquareMiles, //!< Square miles 100 AreaHectares, //!< Hectares 101 AreaAcres, //!< Acres 102 AreaSquareNauticalMiles, //!< Square nautical miles 103 AreaSquareDegrees, //!< Square degrees, for planar geographic CRS area measurements 104 AreaSquareCentimeters, //!< Square centimeters 105 AreaSquareMillimeters, //!< Square millimeters 106 AreaUnknownUnit, //!< Unknown areal unit 107 }; 108 Q_ENUM( AreaUnit ) 109 110 /** 111 * Units of volume. 112 * \since QGIS 3.10 113 */ 114 enum VolumeUnit 115 { 116 VolumeCubicMeters = 0, //!< Cubic meters 117 VolumeCubicFeet, //!< Cubic feet 118 VolumeCubicYards, //!< Cubic yards 119 VolumeBarrel, //!< Barrels 120 VolumeCubicDecimeter, //!< Cubic decimeters 121 VolumeLiters, //!< Litres 122 VolumeGallonUS, //!< US Gallons 123 VolumeCubicInch, //!< Cubic inches 124 VolumeCubicCentimeter, //!< Cubic Centimeters 125 VolumeCubicDegrees, //!< Cubic degrees, for planar geographic CRS volume measurements 126 VolumeUnknownUnit, //!< Unknown volume unit 127 }; 128 Q_ENUM( VolumeUnit ) 129 130 //! Units of angles 131 enum AngleUnit 132 { 133 AngleDegrees = 0, //!< Degrees 134 AngleRadians, //!< Square kilometers 135 AngleGon, //!< Gon/gradian 136 AngleMinutesOfArc, //!< Minutes of arc 137 AngleSecondsOfArc, //!< Seconds of arc 138 AngleTurn, //!< Turn/revolutions 139 AngleMilliradiansSI, //!< Angular milliradians (SI definition, 1/1000 of radian) 140 AngleMilNATO, //!< Angular mil (NATO definition, 6400 mil = 2PI radians) 141 AngleUnknownUnit, //!< Unknown angle unit 142 }; 143 Q_ENUM( AngleUnit ) 144 145 /** 146 * Temporal units. 147 * \since QGIS 3.14 148 */ 149 enum TemporalUnit 150 { 151 TemporalMilliseconds, //!< Milliseconds 152 TemporalSeconds, //!< Seconds 153 TemporalMinutes, //!< Minutes 154 TemporalHours, //!< Hours 155 TemporalDays, //!< Days 156 TemporalWeeks, //!< Weeks 157 TemporalMonths, //!< Months 158 TemporalYears, //!< Years 159 TemporalDecades, //!< Decades 160 TemporalCenturies, //!< Centuries 161 TemporalIrregularStep, //!< Special "irregular step" time unit, used for temporal data which uses irregular, non-real-world unit steps (since QGIS 3.20) 162 TemporalUnknownUnit //!< Unknown time unit 163 }; 164 Q_ENUM( TemporalUnit ) 165 166 //! Rendering size units 167 enum RenderUnit 168 { 169 RenderMillimeters = 0, //!< Millimeters 170 RenderMapUnits, //!< Map units 171 RenderPixels, //!< Pixels 172 RenderPercentage, //!< Percentage of another measurement (e.g., canvas size, feature size) 173 RenderPoints, //!< Points (e.g., for font sizes) 174 RenderInches, //!< Inches 175 RenderUnknownUnit, //!< Mixed or unknown units 176 RenderMetersInMapUnits, //!< Meters value as Map units 177 }; 178 Q_ENUM( RenderUnit ) 179 180 //! Layout measurement units 181 enum LayoutUnit 182 { 183 LayoutMillimeters = 0, //!< Millimeters 184 LayoutCentimeters, //!< Centimeters 185 LayoutMeters, //!< Meters 186 LayoutInches, //!< Inches 187 LayoutFeet, //!< Feet 188 LayoutPoints, //!< Typographic points 189 LayoutPicas, //!< Typographic picas 190 LayoutPixels //!< Pixels 191 }; 192 Q_ENUM( LayoutUnit ) 193 194 //! Types of layout units 195 enum LayoutUnitType 196 { 197 LayoutPaperUnits = 0, //!< Unit is a paper based measurement unit 198 LayoutScreenUnits //!< Unit is a screen based measurement unit 199 }; 200 201 /** 202 * A combination of distance value and unit. 203 * 204 * \since QGIS 3.0 205 */ 206 struct DistanceValue 207 { 208 209 /** 210 * The value part of the distance. For 3.7 meters, this will be 3.7. 211 */ 212 double value; 213 214 /** 215 * The value part of the distance. For 3.7 meters, this will be QgsUnitTypes::DistanceMeters. 216 */ 217 QgsUnitTypes::DistanceUnit unit; 218 }; 219 220 /** 221 * A combination of area value and unit. 222 * 223 * \since QGIS 3.0 224 */ 225 struct AreaValue 226 { 227 228 /** 229 * The value part of the distance. For 3.7 square meters, this will be 3.7. 230 */ 231 double value; 232 233 /** 234 * The value part of the distance. For 3.7 square meters, this will be QgsUnitTypes::AreaSquareMeters. 235 */ 236 QgsUnitTypes::AreaUnit unit; 237 }; 238 239 //! List of render units 240 typedef QList<QgsUnitTypes::RenderUnit> RenderUnitList; 241 242 /** 243 * Encodes a unit \a type to a string. 244 * \returns encoded string 245 * \see decodeUnitType() 246 * \since QGIS 3.10 247 */ 248 Q_INVOKABLE static QString encodeUnitType( QgsUnitTypes::UnitType type ); 249 250 /** 251 * Decodes a unit type from a \a string. 252 * \param string string to decode 253 * \param ok optional boolean, will be set to TRUE if string was converted successfully 254 * \returns decoded unit type 255 * \see encodeUnitType() 256 * \since QGIS 3.10 257 */ 258 Q_INVOKABLE static QgsUnitTypes::UnitType decodeUnitType( const QString &string, bool *ok SIP_OUT = nullptr ); 259 260 261 // DISTANCE UNITS 262 263 /** 264 * Returns the type for a distance unit. 265 */ 266 Q_INVOKABLE static QgsUnitTypes::DistanceUnitType unitType( QgsUnitTypes::DistanceUnit unit ); 267 268 /** 269 * Encodes a distance unit to a string. 270 * \param unit unit to encode 271 * \returns encoded string 272 * \see decodeDistanceUnit() 273 */ 274 Q_INVOKABLE static QString encodeUnit( QgsUnitTypes::DistanceUnit unit ); 275 276 /** 277 * Decodes a distance unit from a string. 278 * \param string string to decode 279 * \param ok optional boolean, will be set to TRUE if string was converted successfully 280 * \returns decoded units 281 * \see encodeUnit() 282 */ 283 Q_INVOKABLE static QgsUnitTypes::DistanceUnit decodeDistanceUnit( const QString &string, bool *ok SIP_OUT = nullptr ); 284 285 /** 286 * Returns a translated string representing a distance unit. 287 * \param unit unit to convert to string 288 * \see stringToDistanceUnit() 289 */ 290 Q_INVOKABLE static QString toString( QgsUnitTypes::DistanceUnit unit ); 291 292 /** 293 * Returns a translated abbreviation representing a distance unit. 294 * \param unit unit to convert to string 295 * \see stringToDistanceUnit() 296 * 297 * \since QGIS 3.0 298 */ 299 Q_INVOKABLE static QString toAbbreviatedString( QgsUnitTypes::DistanceUnit unit ); 300 301 /** 302 * Converts a translated string to a distance unit. 303 * \param string string representing a distance unit 304 * \param ok optional boolean, will be set to TRUE if string was converted successfully 305 * \returns the distance unit 306 * \see toString() 307 */ 308 Q_INVOKABLE static QgsUnitTypes::DistanceUnit stringToDistanceUnit( const QString &string, bool *ok SIP_OUT = nullptr ); 309 310 /** 311 * Returns the conversion factor between the specified distance units. 312 * \param fromUnit distance unit to convert from 313 * \param toUnit distance unit to convert to 314 * \returns multiplication factor to convert between units 315 */ 316 Q_INVOKABLE static double fromUnitToUnitFactor( QgsUnitTypes::DistanceUnit fromUnit, QgsUnitTypes::DistanceUnit toUnit ); 317 318 // AREAL UNITS 319 320 /** 321 * Returns the type for an areal unit. 322 */ 323 static QgsUnitTypes::DistanceUnitType unitType( QgsUnitTypes::AreaUnit unit ); 324 325 /** 326 * Encodes an areal unit to a string. 327 * \param unit unit to encode 328 * \returns encoded string 329 * \see decodeAreaUnit() 330 */ 331 static QString encodeUnit( QgsUnitTypes::AreaUnit unit ); 332 333 /** 334 * Decodes an areal unit from a string. 335 * \param string string to decode 336 * \param ok optional boolean, will be set to TRUE if string was converted successfully 337 * \returns decoded units 338 * \see encodeUnit() 339 */ 340 Q_INVOKABLE static QgsUnitTypes::AreaUnit decodeAreaUnit( const QString &string, bool *ok SIP_OUT = nullptr ); 341 342 /** 343 * Returns a translated string representing an areal unit. 344 * \param unit unit to convert to string 345 * \see stringToAreaUnit() 346 */ 347 static QString toString( QgsUnitTypes::AreaUnit unit ); 348 349 /** 350 * Returns a translated abbreviation representing an areal unit. 351 * \param unit unit to convert to string 352 * \see stringToAreaUnit() 353 * 354 * \since QGIS 3.0 355 */ 356 static QString toAbbreviatedString( QgsUnitTypes::AreaUnit unit ); 357 358 /** 359 * Converts a translated string to an areal unit. 360 * \param string string representing an areal unit 361 * \param ok optional boolean, will be set to TRUE if string was converted successfully 362 * \returns the area unit 363 * \see toString() 364 */ 365 Q_INVOKABLE static QgsUnitTypes::AreaUnit stringToAreaUnit( const QString &string, bool *ok SIP_OUT = nullptr ); 366 367 /** 368 * Returns the conversion factor between the specified areal units. 369 * \param fromUnit area unit to convert from 370 * \param toUnit area unit to convert to 371 * \returns multiplication factor to convert between units 372 */ 373 static double fromUnitToUnitFactor( QgsUnitTypes::AreaUnit fromUnit, QgsUnitTypes::AreaUnit toUnit ); 374 375 /** 376 * Converts a distance unit to its corresponding area unit, e.g., meters to square meters 377 * \param distanceUnit distance unit to convert 378 * \returns matching areal unit 379 */ 380 Q_INVOKABLE static QgsUnitTypes::AreaUnit distanceToAreaUnit( QgsUnitTypes::DistanceUnit distanceUnit ); 381 382 /** 383 * Converts an area unit to its corresponding distance unit, e.g., square meters to meters 384 * \param areaUnit area unit to convert 385 * \returns matching distance unit 386 * \since QGIS 3.10 387 */ 388 Q_INVOKABLE static QgsUnitTypes::DistanceUnit areaToDistanceUnit( QgsUnitTypes::AreaUnit areaUnit ); 389 390 // TEMPORAL UNITS 391 392 /** 393 * Encodes a temporal \a unit to a string. 394 * \returns encoded string 395 * \see decodeTemporalUnit() 396 * \since QGIS 3.14 397 */ 398 static QString encodeUnit( QgsUnitTypes::TemporalUnit unit ); 399 400 /** 401 * Decodes a temporal unit from a \a string. 402 * \param string string to decode 403 * \param ok optional boolean, will be set to TRUE if string was converted successfully 404 * \returns decoded units 405 * \see encodeUnit() 406 * \since QGIS 3.14 407 */ 408 Q_INVOKABLE static QgsUnitTypes::TemporalUnit decodeTemporalUnit( const QString &string, bool *ok SIP_OUT = nullptr ); 409 410 /** 411 * Returns a translated string representing a temporal \a unit. 412 * \see stringToTemporalUnit() 413 * \since QGIS 3.14 414 */ 415 static QString toString( QgsUnitTypes::TemporalUnit unit ); 416 417 /** 418 * Returns a translated abbreviation representing a temporal \a unit. 419 * \see stringToTemporalUnit() 420 * 421 * \since QGIS 3.14 422 */ 423 static QString toAbbreviatedString( QgsUnitTypes::TemporalUnit unit ); 424 425 /** 426 * Converts a translated \a string to a temporal unit. 427 * \param string string representing a volume unit 428 * \param ok optional boolean, will be set to TRUE if string was converted successfully 429 * \returns the temporal unit 430 * \see toString() 431 * \since QGIS 3.14 432 */ 433 Q_INVOKABLE static QgsUnitTypes::TemporalUnit stringToTemporalUnit( const QString &string, bool *ok SIP_OUT = nullptr ); 434 435 /** 436 * Returns the conversion factor between the specified temporal units. 437 * 438 * \note Conversion to or from month units assumes a 30 day month length. 439 * \note Conversion to or from year based units assumes a 365.25 day year length. 440 * 441 * \param fromUnit temporal unit to convert from 442 * \param toUnit temporal unit to convert to 443 * \returns multiplication factor to convert between units 444 * \since QGIS 3.14 445 */ 446 static double fromUnitToUnitFactor( QgsUnitTypes::TemporalUnit fromUnit, QgsUnitTypes::TemporalUnit toUnit ); 447 448 // VOLUME UNITS 449 450 /** 451 * Returns the type for an volume unit. 452 * \since QGIS 3.10 453 */ 454 static QgsUnitTypes::DistanceUnitType unitType( QgsUnitTypes::VolumeUnit unit ); 455 456 /** 457 * Encodes a volume \a unit to a string. 458 * \returns encoded string 459 * \see decodeVolumeUnit() 460 * \since QGIS 3.10 461 */ 462 static QString encodeUnit( QgsUnitTypes::VolumeUnit unit ); 463 464 /** 465 * Decodes a volume unit from a \a string. 466 * \param string string to decode 467 * \param ok optional boolean, will be set to TRUE if string was converted successfully 468 * \returns decoded units 469 * \see encodeUnit() 470 * \since QGIS 3.10 471 */ 472 Q_INVOKABLE static QgsUnitTypes::VolumeUnit decodeVolumeUnit( const QString &string, bool *ok SIP_OUT = nullptr ); 473 474 /** 475 * Returns a translated string representing a volume \a unit. 476 * \see stringToVolumeUnit() 477 * \since QGIS 3.10 478 */ 479 static QString toString( QgsUnitTypes::VolumeUnit unit ); 480 481 /** 482 * Returns a translated abbreviation representing a volume \a unit. 483 * \see stringToVolumeUnit() 484 * 485 * \since QGIS 3.10 486 */ 487 static QString toAbbreviatedString( QgsUnitTypes::VolumeUnit unit ); 488 489 /** 490 * Converts a translated \a string to a volume unit. 491 * \param string string representing a volume unit 492 * \param ok optional boolean, will be set to TRUE if string was converted successfully 493 * \returns the volume unit 494 * \see toString() 495 * \since QGIS 3.10 496 */ 497 Q_INVOKABLE static QgsUnitTypes::VolumeUnit stringToVolumeUnit( const QString &string, bool *ok SIP_OUT = nullptr ); 498 499 /** 500 * Returns the conversion factor between the specified volume units. 501 * \param fromUnit volume unit to convert from 502 * \param toUnit volume unit to convert to 503 * \returns multiplication factor to convert between units 504 * \since QGIS 3.10 505 */ 506 static double fromUnitToUnitFactor( QgsUnitTypes::VolumeUnit fromUnit, QgsUnitTypes::VolumeUnit toUnit ); 507 508 /** 509 * Converts a distance unit to its corresponding volume unit, e.g., meters to cubic meters 510 * \param distanceUnit distance unit to convert 511 * \returns matching volume unit 512 * \since QGIS 3.10 513 */ 514 Q_INVOKABLE static QgsUnitTypes::VolumeUnit distanceToVolumeUnit( QgsUnitTypes::DistanceUnit distanceUnit ); 515 516 /** 517 * Converts a volume unit to its corresponding distance unit, e.g., cubic meters to meters 518 * \param volumeUnit volume unit to convert 519 * \returns matching distance unit 520 * \since QGIS 3.10 521 */ 522 Q_INVOKABLE static QgsUnitTypes::DistanceUnit volumeToDistanceUnit( QgsUnitTypes::VolumeUnit volumeUnit ); 523 524 // ANGULAR UNITS 525 526 /** 527 * Encodes an angular unit to a string. 528 * \param unit unit to encode 529 * \returns encoded string 530 * \see decodeAngleUnit() 531 */ 532 static QString encodeUnit( QgsUnitTypes::AngleUnit unit ); 533 534 /** 535 * Decodes an angular unit from a string. 536 * \param string string to decode 537 * \param ok optional boolean, will be set to TRUE if string was converted successfully 538 * \returns decoded units 539 * \see encodeUnit() 540 */ 541 Q_INVOKABLE static QgsUnitTypes::AngleUnit decodeAngleUnit( const QString &string, bool *ok SIP_OUT = nullptr ); 542 543 /** 544 * Returns a translated string representing an angular unit. 545 * \param unit unit to convert to string 546 */ 547 static QString toString( QgsUnitTypes::AngleUnit unit ); 548 549 /** 550 * Returns the conversion factor between the specified angular units. 551 * \param fromUnit angle unit to convert from 552 * \param toUnit angle unit to convert to 553 * \returns multiplication factor to convert between units 554 */ 555 static double fromUnitToUnitFactor( QgsUnitTypes::AngleUnit fromUnit, QgsUnitTypes::AngleUnit toUnit ); 556 557 /** 558 * Returns an angle formatted as a friendly string. 559 * \param angle angle to format 560 * \param decimals number of decimal places to show. A value of -1 indicates that an appropriate number of decimal places should automatically be selected. 561 * \param unit unit of angle 562 * \returns formatted angle string 563 */ 564 Q_INVOKABLE static QString formatAngle( double angle, int decimals, QgsUnitTypes::AngleUnit unit ); 565 566 /** 567 * Will convert a \a distance with a given \a unit to a distance value which is nice to display. 568 * It will convert between different units (e.g. from meters to kilometers or millimeters) 569 * if appropriate, unless forced otherwise with \a keepBaseUnit. 570 * The value will also be rounded to \a decimals (be prepared that the returned value is still a double so it will require 571 * further formatting when converting to a string). 572 * 573 * \since QGIS 3.0 574 */ 575 Q_INVOKABLE static QgsUnitTypes::DistanceValue scaledDistance( double distance, QgsUnitTypes::DistanceUnit unit, int decimals, bool keepBaseUnit = false ); 576 577 /** 578 * Will convert an \a area with a given \a unit to an area value which is nice to display. 579 * It will convert between different units (e.g. from square meters to square kilometers) 580 * if appropriate, unless forced otherwise with \a keepBaseUnit. 581 * The value will also be rounded to \a decimals (be prepared that the returned value is still a double so it will require 582 * further formatting when converting to a string). 583 * 584 * \since QGIS 3.0 585 */ 586 Q_INVOKABLE static QgsUnitTypes::AreaValue scaledArea( double area, QgsUnitTypes::AreaUnit unit, int decimals, bool keepBaseUnit = false ); 587 588 /** 589 * Returns an distance formatted as a friendly string. 590 * \param distance distance to format 591 * \param decimals number of decimal places to show 592 * \param unit unit of distance 593 * \param keepBaseUnit set to FALSE to allow conversion of large distances to more suitable units, e.g., meters to 594 * kilometers 595 * \returns formatted distance string 596 * \see formatArea() 597 * \since QGIS 3.0 598 */ 599 Q_INVOKABLE static QString formatDistance( double distance, int decimals, QgsUnitTypes::DistanceUnit unit, bool keepBaseUnit = false ); 600 601 /** 602 * Returns an area formatted as a friendly string. 603 * \param area area to format 604 * \param decimals number of decimal places to show 605 * \param unit unit of area 606 * \param keepBaseUnit set to FALSE to allow conversion of large areas to more suitable units, e.g., square meters to 607 * square kilometers 608 * \returns formatted area string 609 * \see formatDistance() 610 * \since QGIS 3.0 611 */ 612 Q_INVOKABLE static QString formatArea( double area, int decimals, QgsUnitTypes::AreaUnit unit, bool keepBaseUnit = false ); 613 614 // RENDER UNITS 615 616 /** 617 * Encodes a render unit to a string. 618 * \param unit unit to encode 619 * \returns encoded string 620 * \see decodeRenderUnit() 621 */ 622 static QString encodeUnit( QgsUnitTypes::RenderUnit unit ); 623 624 /** 625 * Decodes a render unit from a string. 626 * \param string string to decode 627 * \param ok optional boolean, will be set to TRUE if string was converted successfully 628 * \returns decoded units 629 * \see encodeUnit() 630 */ 631 Q_INVOKABLE static QgsUnitTypes::RenderUnit decodeRenderUnit( const QString &string, bool *ok SIP_OUT = nullptr ); 632 633 634 /** 635 * Returns a translated string representing a render \a unit. 636 * \since QGIS 3.0 637 */ 638 static QString toString( QgsUnitTypes::RenderUnit unit ); 639 640 /** 641 * Returns a translated abbreviation representing a render unit. 642 * \param unit unit to convert to string 643 * 644 * \since QGIS 3.8 645 */ 646 static QString toAbbreviatedString( QgsUnitTypes::RenderUnit unit ); 647 648 649 // LAYOUT UNITS 650 651 /** 652 * Encodes a layout unit to a string. 653 * \param unit unit to encode 654 * \returns encoded string 655 * \see decodeLayoutUnit() 656 * \since QGIS 3.0 657 */ 658 static QString encodeUnit( QgsUnitTypes::LayoutUnit unit ); 659 660 /** 661 * Decodes a layout unit from a string. 662 * \param string string to decode 663 * \param ok optional boolean, will be set to TRUE if string was converted successfully 664 * \returns decoded units 665 * \see encodeUnit() 666 * \since QGIS 3.0 667 */ 668 Q_INVOKABLE static QgsUnitTypes::LayoutUnit decodeLayoutUnit( const QString &string, bool *ok SIP_OUT = nullptr ); 669 670 /** 671 * Returns the type for a unit of measurement. 672 * 673 * \since QGIS 3.0 674 */ 675 Q_INVOKABLE static QgsUnitTypes::LayoutUnitType unitType( QgsUnitTypes::LayoutUnit units ); 676 677 /** 678 * Returns a translated abbreviation representing a layout \a unit (e.g. "mm"). 679 * 680 * \since QGIS 3.0 681 */ 682 static QString toAbbreviatedString( QgsUnitTypes::LayoutUnit unit ); 683 684 /** 685 * Returns a translated string representing a layout \a unit. 686 * 687 * \since QGIS 3.0 688 */ 689 static QString toString( QgsUnitTypes::LayoutUnit unit ); 690 691 }; 692 693 #endif // QGSUNITTYPES_H 694