LibrePCB Developers Documentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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 QList< T > sortedQSet (const QSet< T > &set) noexcept
 
template<typename T >
static T sorted (const T &container) noexcept
 
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 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...
 
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.

Constructor & Destructor Documentation

Toolbox ( )
delete
Toolbox ( const Toolbox other)
delete
~Toolbox ( )
delete

Member Function Documentation

Toolbox& operator= ( const Toolbox rhs)
delete
static QList<T> sortedQSet ( const QSet< T > &  set)
inlinestaticnoexcept

+ Here is the caller graph for this function:

static T sorted ( const T &  container)
inlinestaticnoexcept

+ Here is the caller graph for this function:

static QRectF boundingRectFromRadius ( qreal  radius)
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 caller graph for this function:

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:

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:

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
pAn arbitrary point
l1Start point of the line
l2End 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:

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
pAn arbitrary point
l1Start point of the line
l2End point of the line
nearestIf 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:

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
stringThe input string
Returns
A new string with the incremented number

+ Here is the caller graph for this function:

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
stringThe 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:

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
inputThe string typed by the user
removeRegexRegex for all patterns to remove from the string
trimIf true, leading and trailing spaces are removed
toLowerIf true, all characters are converted to lowercase
toUpperIf true, all characters are converted to uppercase
spaceReplacementAll spaces are replaced by this string
maxLengthIf >= 0, the string is truncated to this length
Returns
The cleaned string (may be empty)

+ Here is the caller graph for this function:

static QString floatToString ( 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:

static QString decimalFixedPointToString ( value,
qint32  pointPos 
)
inlinestaticnoexcept

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

Parameters
valueValue to convert
pointPosNumber of fixed point decimal positions
static T decimalFixedPointFromString ( const QString &  str,
qint32  pointPos 
)
inlinestatic

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

Parameters
strA QString that represents the number
pointPosNumber of decimal positions. If the number has more decimal digits, this function will throw
QStringList expandRangesInString ( const QString &  input,
const QVector< std::tuple< int, int, QStringList >> &  replacements 
)
staticprivatenoexcept

Internal helper function for expandRangesInString(const QString&)

+ Here is the call graph for this function:


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