LibrePCB Developers Documentation
|
The Toolbox class provides some useful general purpose methods. More...
#include <toolbox.h>
Public Member Functions | |
Toolbox ()=delete | |
Toolbox (const Toolbox &other)=delete | |
~Toolbox ()=delete | |
Toolbox & | operator= (const Toolbox &rhs)=delete |
Static Public Member Functions | |
template<typename T > | |
static QSet< T > | toSet (const QList< T > &list) noexcept |
Helper method to convert a QList<T> to a QSet<T> | |
template<typename T > | |
static QVector< T > | toVector (const QSet< T > &set) noexcept |
Helper method to convert a QSet<T> to a QVector<T> | |
template<typename T > | |
static QList< T > | toList (const QSet< T > &set) noexcept |
Helper method to convert a QSet<T> to a QList<T> | |
template<typename T > | |
static QList< T > | sortedQSet (const QSet< T > &set) noexcept |
template<typename T , typename Compare > | |
static QList< T > | sortedQSet (const QSet< T > &set, const Compare &cmp) noexcept |
template<typename T > | |
static T | sorted (const T &container) noexcept |
template<typename T , typename Compare > | |
static void | sortNumeric (T &container, Compare compare, Qt::CaseSensitivity caseSensitivity=Qt::CaseInsensitive, bool ignorePunctuation=false) noexcept |
Sort a container of arbitrary objects using QCollators numeric mode. | |
template<typename T > | |
static void | sortNumeric (T &container, Qt::CaseSensitivity caseSensitivity=Qt::CaseInsensitive, bool ignorePunctuation=false) noexcept |
Sort a container of strings using QCollators numeric mode. | |
static bool | isTextUpsideDown (const Angle &rotation) noexcept |
Check if a text with a given rotation is considered as upside down. | |
static QRectF | boundingRectFromRadius (qreal radius) noexcept |
static QRectF | boundingRectFromRadius (qreal rx, qreal ry) noexcept |
static QRectF | adjustedBoundingRect (const QRectF &rect, qreal offset) noexcept |
static QPainterPath | shapeFromPath (const QPainterPath &path, const QPen &pen, const QBrush &brush, const UnsignedLength &minWidth=UnsignedLength(0)) noexcept |
static std::optional< Length > | arcRadius (const Point &p1, const Point &p2, const Angle &angle) noexcept |
static std::optional< Point > | arcCenter (const Point &p1, const Point &p2, const Angle &angle) noexcept |
static Angle | arcAngle (const Point &p1, const Point &p2, const Point ¢er=Point(0, 0)) noexcept |
Calculate the angle between two given points. | |
static Angle | arcAngleFrom3Points (const Point &start, const Point &mid, const Point &end) noexcept |
Calculate the angle of an arc given by 3 points. | |
static Angle | angleBetweenPoints (const Point &p1, const Point &p2) noexcept |
Calculate the angle between two points. | |
static Point | nearestPointOnLine (const Point &p, const Point &l1, const Point &l2) noexcept |
Calculate the point on a given line which is nearest to a given point. | |
static UnsignedLength | shortestDistanceBetweenPointAndLine (const Point &p, const Point &l1, const Point &l2, Point *nearest=nullptr) noexcept |
Calculate the shortest distance between a given point and a given line. | |
static QString | incrementNumberInString (QString string) noexcept |
Copy a string while incrementing its contained number. | |
static QStringList | expandRangesInString (const QString &string) noexcept |
Expand ranges like "1..5" in a string to all its values. | |
static QString | cleanUserInputString (const QString &input, const QRegularExpression &removeRegex, bool trim=true, bool toLower=false, bool toUpper=false, const QString &spaceReplacement=" ", int maxLength=-1) noexcept |
Clean a user input string. | |
static QString | prettyPrintLocale (const QString &code) noexcept |
Pretty print the name of a QLocale. | |
template<typename T > | |
static QString | floatToString (T value, int decimals, const QLocale &locale) noexcept |
Convert a float or double to a localized string. | |
template<typename T > | |
static QString | decimalFixedPointToString (T value, qint32 pointPos) noexcept |
Convert a fixed point decimal number from an integer to a QString. | |
template<typename T > | |
static T | decimalFixedPointFromString (const QString &str, qint32 pointPos) |
Convert a fixed point decimal number from a QString to an integer. | |
Static Private Member Functions | |
static QStringList | expandRangesInString (const QString &input, const QVector< std::tuple< int, int, QStringList > > &replacements) noexcept |
Internal helper function for expandRangesInString(const QString&) | |
The Toolbox class provides some useful general purpose methods.
|
delete |
|
delete |
|
inlinestaticnoexcept |
Helper method to convert a QList<T> to a QSet<T>
Until Qt 5.13, QList::toSet() was the way to do this conversion. But since Qt 5.14 this is deprecated, and a range constructor was added to QSet instead. This wrapper chooses the proper method depending on the Qt version to avoid raising any deprecation warnings.
list | The QList to be converted. |
|
inlinestaticnoexcept |
Helper method to convert a QSet<T> to a QVector<T>
Until Qt 5.13, QSet::toList() was the way to do this conversion. But since Qt 5.14 this is deprecated, and a range constructor was added to QVector instead. This wrapper chooses the proper method depending on the Qt version to avoid raising any deprecation warnings.
set | The QSet to be converted. |
|
inlinestaticnoexcept |
Helper method to convert a QSet<T> to a QList<T>
Until Qt 5.13, QSet::toList() was the way to do this conversion. But since Qt 5.14 this is deprecated, and a range constructor was added to QVector instead. This wrapper chooses the proper method depending on the Qt version to avoid raising any deprecation warnings.
set | The QSet to be converted. |
|
inlinestaticnoexcept |
|
inlinestaticnoexcept |
|
inlinestaticnoexcept |
|
inlinestaticnoexcept |
Sort a container of arbitrary objects using QCollators numeric mode.
container | A string container as supported by QCollator. |
compare | Custom comparison function with the signature bool(const QCollator&, const V&, const V&) where V represents the container item type. |
caseSensitivity | Case sensitivity of comparison. |
ignorePunctuation | Whether punctuation is ignored or not. |
|
inlinestaticnoexcept |
Sort a container of strings using QCollators numeric mode.
container | A string container as supported by QCollator. |
caseSensitivity | Case sensitivity of comparison. |
ignorePunctuation | Whether punctuation is ignored or not. |
|
staticnoexcept |
Check if a text with a given rotation is considered as upside down.
A text is considered as upside down if it is rotated counterclockwise by [-90..90°[, i.e. -90° is considered as upside down, but 90° is not considered as upside down.
Used to determine whether a text needs to be auto-rotated or not.
rotation | The global (scene coordinates) rotation of the text. |
|
inlinestaticnoexcept |
|
inlinestaticnoexcept |
|
inlinestaticnoexcept |
|
staticnoexcept |
|
staticnoexcept |
|
staticnoexcept |
|
staticnoexcept |
Calculate the angle between two given points.
p1 | First point. |
p2 | Second point. |
center | Center of the arc. Defaults to (0, 0). |
|
staticnoexcept |
Calculate the angle of an arc given by 3 points.
start | Arc start point. |
mid | Arc middle point (50% of length). |
end | Arc end point. |
Calculate the angle between two points.
p1 | First point. |
p2 | Second point. |
Calculate the point on a given line which is nearest to a given point.
p | An arbitrary point |
l1 | Start point of the line |
l2 | End point of the line |
|
staticnoexcept |
Calculate the shortest distance between a given point and a given line.
p | An arbitrary point |
l1 | Start point of the line |
l2 | End point of the line |
nearest | If not nullptr , the nearest point is returned here |
|
staticnoexcept |
Copy a string while incrementing its contained number.
This way, the returned number is guaranteed to be different from the input string. That's useful for example to generate unique, incrementing pin numbers like "X1", "X2", "X3" etc.
string | The input string |
|
staticnoexcept |
Expand ranges like "1..5" in a string to all its values.
A range is either defined by two integers with ".." in between, or two ASCII letters with ".." in between. If multiple ranges are contained, all combinations of them will be created.
For example the string "X1..10_A..C" expands to the list ["X1_A", "X1_B", "X1_C", ..., "X10_C"].
string | The input string (may or may not contain ranges). |
|
staticnoexcept |
Clean a user input string.
input | The string typed by the user |
removeRegex | Regex for all patterns to remove from the string |
trim | If true, leading and trailing spaces are removed |
toLower | If true, all characters are converted to lowercase |
toUpper | If true, all characters are converted to uppercase |
spaceReplacement | All spaces are replaced by this string |
maxLength | If >= 0, the string is truncated to this length |
|
staticnoexcept |
Pretty print the name of a QLocale.
To show locale names in the UI. Examples:
code | The code of the locale to print (e.g. "en_US"). |
|
inlinestaticnoexcept |
Convert a float or double to a localized string.
Same as QLocale::toString<float/double>(), but with omitted trailing zeros and without group separators.
|
inlinestaticnoexcept |
Convert a fixed point decimal number from an integer to a QString.
value | Value to convert |
pointPos | Number of fixed point decimal positions |
|
inlinestatic |
Convert a fixed point decimal number from a QString to an integer.
str | A QString that represents the number |
pointPos | Number of decimal positions. If the number has more decimal digits, this function will throw |
|
staticprivatenoexcept |
Internal helper function for expandRangesInString(const QString&)