 LibrePCB Developers Documentation
Toolbox Class Referencefinal

The Toolbox class provides some useful general purpose methods. More...

`#include <toolbox.h>` Collaboration diagram for Toolbox:

## Public Member Functions

Toolbox ()=delete

Toolbox (const Toolbox &other)=delete

~Toolbox ()=delete

Toolboxoperator= (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> More...

template<typename T >
static QList< T > sortedQSet (const QSet< T > &set) noexcept

template<typename T >
static T sorted (const T &container) 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 Length arcRadius (const Point &p1, const Point &p2, const Angle &a) noexcept

static Point arcCenter (const Point &p1, const Point &p2, const Angle &a) noexcept

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. More...

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. More...

static QString incrementNumberInString (QString string) noexcept
Copy a string while incrementing its contained number. More...

static QStringList expandRangesInString (const QString &string) noexcept
Expand ranges like "1..5" in a string to all its values. More...

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. More...

static QString prettyPrintLocale (const QString &code) noexcept
Pretty print the name of a QLocale. More...

template<typename T >
static QString floatToString (T value, int decimals, const QLocale &locale) noexcept
Convert a float or double to a localized string. More...

template<typename T >
static QString decimalFixedPointToString (T value, qint32 pointPos) noexcept
Convert a fixed point decimal number from an integer to a QString. More...

template<typename T >
static T decimalFixedPointFromString (const QString &str, qint32 pointPos)
Convert a fixed point decimal number from a QString to an integer. More...

## 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&) More...

## Detailed Description

The Toolbox class provides some useful general purpose methods.

## ◆ Toolbox() [1/2]

 Toolbox ( )
delete

## ◆ Toolbox() [2/2]

 Toolbox ( const Toolbox & other )
delete

## ◆ ~Toolbox()

 ~Toolbox ( )
delete

## ◆ operator=()

 Toolbox& operator= ( const Toolbox & rhs )
delete

## ◆ toSet()

 static QSet toSet ( const QList< T > & list )
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.

Parameters
 list The QList to be converted.
Returns
The created QSet. Here is the caller graph for this function:

## ◆ sortedQSet()

 static QList sortedQSet ( const QSet< T > & set )
inlinestaticnoexcept Here is the caller graph for this function:

## ◆ sorted()

 static T sorted ( const T & container )
inlinestaticnoexcept Here is the caller graph for this function:

inlinestaticnoexcept Here is the caller graph for this function:

 static QRectF boundingRectFromRadius ( qreal rx, qreal ry )
inlinestaticnoexcept

 static QRectF adjustedBoundingRect ( const QRectF & rect, qreal offset )
inlinestaticnoexcept Here is the call graph for this function: Here is the caller graph for this function:

## ◆ shapeFromPath()

 QPainterPath shapeFromPath ( const QPainterPath & path, const QPen & pen, const QBrush & brush, const UnsignedLength & minWidth = `UnsignedLength(0)` )
staticnoexcept Here is the caller graph for this function:

 Length arcRadius ( const Point & p1, const Point & p2, const Angle & a )
staticnoexcept Here is the call graph for this function: Here is the caller graph for this function:

## ◆ arcCenter()

 Point arcCenter ( const Point & p1, const Point & p2, const Angle & a )
staticnoexcept Here is the call graph for this function: Here is the caller graph for this function:

## ◆ nearestPointOnLine()

 Point nearestPointOnLine ( const Point & p, const Point & l1, const Point & l2 )
staticnoexcept

Calculate the point on a given line which is nearest to a given point.

Parameters
 p An arbitrary point l1 Start point of the line l2 End point of the line
Returns
Nearest point on the given line (either l1, l2, or a point between them)
Warning
This method works with floating point numbers and thus the result may not be perfectly precise. Here is the call graph for this function: Here is the caller graph for this function:

## ◆ shortestDistanceBetweenPointAndLine()

 UnsignedLength shortestDistanceBetweenPointAndLine ( const Point & p, const Point & l1, const Point & l2, Point * nearest = `nullptr` )
staticnoexcept

Calculate the shortest distance between a given point and a given line.

Parameters
 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
Returns
Shortest distance between the given point and the given line (>=0) Here is the call graph for this function: Here is the caller graph for this function:

## ◆ incrementNumberInString()

 QString incrementNumberInString ( QString string )
staticnoexcept

Copy a string while incrementing its contained number.

• If the string contains one or more numbers, the last one gets incremented
• If it does not contain a number, a "1" is appended instead

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.

Parameters
 string The input string
Returns
A new string with the incremented number Here is the caller graph for this function:

## ◆ expandRangesInString() [1/2]

 QStringList expandRangesInString ( const QString & 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"].

Note
Minus ('-') and plus ('+') characters are not interpreted as the sign of a number because in EDA tools they often are considered as strings, not as number signs (e.g. the inputs of an OpAmp).
Parameters
 string The input string (may or may not contain ranges).
Returns
A list with expanded ranges in all combinations. If the input string does not contain ranges, a list with one element (equal to the input) is returned. Here is the caller graph for this function:

## ◆ cleanUserInputString()

 QString cleanUserInputString ( const QString & input, const QRegularExpression & removeRegex, bool trim = `true`, bool toLower = `false`, bool toUpper = `false`, const QString & spaceReplacement = `" "`, int maxLength = `-1` )
staticnoexcept

Clean a user input string.

Parameters
 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
Returns
The cleaned string (may be empty) Here is the caller graph for this function:

## ◆ prettyPrintLocale()

 QString prettyPrintLocale ( const QString & code )
staticnoexcept

Pretty print the name of a QLocale.

To show locale names in the UI. Examples:

• "en_US" -> "American English (United States)"
• "de" -> "Deutsch"
• "eo" -> "Esperanto"
Parameters
 code The code of the locale to print (e.g. "en_US").
Returns
String with the pretty printed locale name. Here is the caller graph for this function:

## ◆ floatToString()

 static QString floatToString ( T value, int decimals, const QLocale & locale )
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. Here is the caller graph for this function:

## ◆ decimalFixedPointToString()

 static QString decimalFixedPointToString ( T value, qint32 pointPos )
inlinestaticnoexcept

Convert a fixed point decimal number from an integer to a QString.

Parameters
 value Value to convert pointPos Number of fixed point decimal positions

## ◆ decimalFixedPointFromString()

 static T decimalFixedPointFromString ( const QString & str, qint32 pointPos )
inlinestatic

Convert a fixed point decimal number from a QString to an integer.

Parameters
 str A QString that represents the number pointPos Number of decimal positions. If the number has more decimal digits, this function will throw Here is the call graph for this function:

## ◆ expandRangesInString() [2/2]

 QStringList expandRangesInString ( const QString & input, const QVector< std::tuple< int, int, QStringList >> & replacements )
staticprivatenoexcept

Internal helper function for expandRangesInString(const QString&)

The documentation for this class was generated from the following files: