Miscelleaneous
This section documents a collection of general-purpose utility functions that do not fit into a single functional category. These functions support a wide range of tasks, including formatting, layout manipulation, string processing, image and CSS handling, timing utilities, and data conversion.
Functions
-
QString mv::util::getIntegerCountHumanReadable(const double &count)
Returns a human readable string of an integer count.
- Parameters:
count – Integer count
- Returns:
Human readable string of an integer count
-
std::uint64_t mv::util::parseByteSize(const QString &input)
Convert a byte size string to a number of bytes.
- Returns:
Number of bytes
-
QString mv::util::getNoBytesHumanReadable(std::uint64_t noBytes, bool useIEC = true)
Returns a human-readable string of a byte count.
- Parameters:
noBytes – Number of bytes
useIEC – Whether to use IEC (base 1024) or SI (base 1000) units
- Returns:
Human-readable string of a byte count
-
template<typename ActionType>
void mv::util::sortActions(QVector<QPointer<ActionType>> &actions) Sort action based on their text.
- Parameters:
actions – Actions to sort
-
template<class WidgetClass>
WidgetClass *mv::util::findParent(const QWidget *widget) Find parent of type
WidgetClass.- Parameters:
widget – Pointer to widget to search for
- Returns:
Pointer to parent widget of type
WidgetClass, otherwise a nullptr
-
inline QString mv::util::getTabIndentedMessage(QString message, const std::uint32_t &tabIndex)
Get tabbed (indented) message.
- Parameters:
message – Message to prefix with tab indentation
tabIndex – Number of tabs to prefix with
- Returns:
Message indented with tabs
-
QString mv::util::getColorAsCssString(const QColor &color, bool alpha = true)
Get
coloras CSS string, either with or withoutalpha.- Parameters:
color – Input color
alpha – Whether to use the alpha
- Returns:
Color as rgb(…) or rgba(…)
-
bool mv::util::urlExists(const QString &urlString)
Get whether
URLis valid.- Parameters:
urlString – Url string
- Returns:
Boolean determining whether the URL is valid
-
void mv::util::replaceLayout(QWidget *widget, QLayout *newLayout, bool removeWidgets = false)
-
void mv::util::clearLayout(QLayout *layout, bool removeWidgets = false)
-
void mv::util::setLayoutContentsMargins(QLayout *layout, std::int32_t margin)
-
QIcon mv::util::getAlignmentIcon(const Qt::Alignment &alignment)
-
QVariant mv::util::setValueByPath(QVariant root, const QString &path, const QVariant &value)
Set child
valueof \root bypath.- Parameters:
root – Root element
path – Path to the value
value – Value to set
-
QVariant mv::util::getValueByPath(const QVariant &root, const QString &path, const QVariant &valueIfNotFound = QVariant())
Get child value of \root by
path.- Parameters:
root – Root element
path – Path to the value
valueIfNotFound – Value if not found
- Returns:
Value, invalid when no value was found
-
QString mv::util::gifToBase64(const QByteArray &gifByteArray)
Convert
gifByteArrayto base64 encoded string.- Parameters:
gifByteArray – GIF image raw bytes
- Returns:
Base64-encoded GIF string
-
QString mv::util::embedGifFromBase64(const QString &gifBase64)
Embed
gifBase64-encodedGIF in an HTML.tag
- Parameters:
gifBase64 – GIF image as base64-encoded string
- Returns:
GIF image embedded in HTML tag
-
QString mv::util::embedGifFromResource(const QString &resourcePath)
Embed GIF image from
resourcePathinto an HTML.tag
- Parameters:
resourcePath – Path of the GIF image in the resources
- Returns:
GIF image embedded in HTML tag
-
void mv::util::waitForDuration(int milliSeconds)
This method keeps the application event loop responsive while halting the current execution for n
milliseconds.- Parameters:
milliSeconds – Milliseconds to wait
-
void mv::util::disconnectRecursively(const QObject *object)
Remove all connections (to and from) from
objectand its descendants.- Parameters:
object – Pointer to root object
-
std::string mv::util::replaceAll(std::string inputString, const std::string &from, const std::string &to)
Replace all occurrences of
fromwithtoininputStringand return the result.- Parameters:
inputString – Input string
from – String to replace
to – Replace from with this
- Returns:
Replaced string
Warning
doxygenfunction: Cannot find function “mv::util::stripNewLiness” in doxygen xml output for project “ManiVault” from directory: /home/docs/checkouts/readthedocs.org/user_builds/manivault/checkouts/1.4.2/docs/_doxygen/xml
-
std::string mv::util::escapeCssDq(std::string inputString)
Escape for a CSS double-quoted string (inside url(”…”))
- Parameters:
inputString – Input string
- Returns:
Curated resulting string
-
std::string mv::util::pixmapToCssSrc(const QPixmap &pixmap)
Convert the contents of
pixmapto base46 encoded string and form a CSS src string.- Parameters:
pixmap – Input pixmap
- Returns:
String (‘’)
-
QString mv::util::mimeForFormat(const QByteArray &byteArray)
Determine the MIME format based on
byteArray.- Parameters:
byteArray – Input byte array
- Returns:
MIME type
-
QByteArray mv::util::normalizeFormatFromSuffix(const QString &path)
Normalize image format from file
pathsuffix (e.g.jpg -> JPEG)
- Parameters:
path – Input file path
- Returns:
Normalized format (PNG, JPEG, etc.)
-
QByteArray mv::util::chooseFormatForImage(const QImage &img, const QByteArray &hinted)
Choose encoding format for
img, optionally usinghintedformat (if the source format is unknown, pick PNG when alpha is present, else JPEG)- Parameters:
img – Input image
hinted – Hinted format (may be empty)
- Returns:
Chosen format (PNG, JPEG, etc.)
-
QString mv::util::pixmapToDataUrl(const QPixmap &pixmap, const QByteArray &fmt = "PNG", int quality = -1)
Convert the contents of
pixmapto base64 encoded data URL.- Parameters:
pixmap – Input pixmap
fmt – Encoding format (PNG, JPEG, etc.)
quality – Encoding quality (-1 is default)
- Returns:
Data URL string
-
QString mv::util::applyPixmapToCss(QString css, const QPixmap &pixmap, const QByteArray &format = "PNG", int quality = -1, const QString &token = QStringLiteral("{{BACKGROUND_IMAGE}}"))
Replace
tokenincsswith a CSS data URL formed frompixmapencoded asfmtwithquality.- Parameters:
css – Input CSS
pixmap – Input pixmap
format – Encoding format (PNG, JPEG, etc.)
quality – Encoding quality (-1 is default)
token – Token to replace in the CSS (default {{BACKGROUND_IMAGE}})
- Returns:
CSS with token replaced by data URL
-
QString mv::util::applyResourceImageToCss(QString css, const QString &pathOrResource, const QString &token, float scaleFactor = 0, int quality = 90)
Replace
tokenincsswith a CSS data URL formed from image atpathOrResourceencoded asquality.- Parameters:
css – Input CSS
pathOrResource – Path to image file or resource path (e.g. “:/images/background.png”)
token – Token to replace in the CSS (default {{BACKGROUND_IMAGE}})
scaleFactor – Scale factor (0 is default, i.e. no scaling)
quality – Encoding quality (-1 is default)
- Returns:
CSS with token replaced by data URL
-
QByteArray mv::util::ensureUtf8(QByteArray byteArray)
Ensure that
byteArrayis UTF-8 encoded, converting from UTF-16 if necessary.- Parameters:
byteArray – Input byte array
-
QByteArray mv::util::sanitizeJsonWhitespaceOutsideStrings(const QByteArray &utf8)
Sanitize JSON by removing all whitespace outside of strings.
- Parameters:
utf8 – Input JSON as UTF-8 byte array
- Returns:
Sanitized JSON as UTF-8 byte array
-
QString mv::util::getFilenameFromContentDisposition(const QByteArray &contentDispositionRaw)
Minimal, practical parser for Content-Disposition filenames (prefers RFC 5987 filename* with UTF-8 when present, but also accepts other charsets as provided in the header without strict validation).
- Parameters:
contentDispositionRaw – Raw Content-Disposition header value
- Returns:
Filename if found, otherwise an empty string
-
QString mv::util::getFilenameFromUrlPath(const QUrl &effectiveUrl)
Extract filename from
effectiveUrl.- Parameters:
effectiveUrl – Input URL
- Returns:
Filename from URL path
-
QString mv::util::getFilenameFromWaterButlerMetadata(const QByteArray &raw)
Extract filename from OSF Waterbutler metadata JSON
rawThis is used to determine the filename of files downloaded from OSF storage providers.- Parameters:
raw – Raw Waterbutler metadata JSON
- Returns:
Filename if found, otherwise an empty string