VirtualBox

Changeset 104926 in vbox


Ignore:
Timestamp:
Jun 14, 2024 3:44:31 PM (11 months ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
163528
Message:

FE/Qt: bugref:10666, bugref:10669: Cleanup for UIMediumSizeEditor code.

Location:
trunk/src/VBox/Frontends/VirtualBox/src/widgets
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VirtualBox/src/widgets/UIMediumSizeEditor.cpp

    r104697 r104926  
    55
    66/*
    7  * Copyright (C) 2006-2023 Oracle and/or its affiliates.
     7 * Copyright (C) 2006-2024 Oracle and/or its affiliates.
    88 *
    99 * This file is part of VirtualBox base platform packages, as
     
    4444
    4545
    46 const qulonglong UIMediumSizeEditor::m_uSectorSize = 512;
     46/* static */
     47const qulonglong UIMediumSizeEditor::s_uSectorSize = 512;
    4748
    4849UIMediumSizeEditor::UIMediumSizeEditor(QWidget *pParent, qulonglong uMinimumSize /* = _4M */)
     
    5758    , m_pEditor(0)
    5859{
    59     /* Prepare: */
    6060    prepare();
    61     QString strRegEx = QString("[^\\d%1]").arg(UITranslator::decimalSep());
    62     m_regExNonDigitOrSeparator = QRegularExpression(strRegEx);
    6361}
    6462
     
    110108    QString strSizeString = ensureSizeSuffix(m_pEditor->text());
    111109
    112 
    113110    m_pEditor->blockSignals(true);
    114111    int iCursorPosition = m_pEditor->cursorPosition();
     
    129126}
    130127
    131 QString UIMediumSizeEditor::ensureSizeSuffix(const QString &strSizeString)
    132 {
    133     /* Try to update the m_strSizeSuffix: */
    134     if (UITranslator::hasSizeSuffix(strSizeString))
    135         m_strSizeSuffix = gpConverter->toString(UITranslator::parseSizeSuffix(strSizeString));
    136 
    137     QString strOnlyDigits(strSizeString);
    138     /* Remove any chars from the string except digits and decimal separator and then add a space and size suffix: */
    139     return QString("%1 %2").arg(strOnlyDigits.remove(m_regExNonDigitOrSeparator)).arg(m_strSizeSuffix);
    140 }
    141 
    142128void UIMediumSizeEditor::prepare()
    143129{
     130    /* Configure reg-exp: */
     131    m_regExNonDigitOrSeparator = QRegularExpression(QString("[^\\d%1]").arg(UITranslator::decimalSep()));
     132
    144133    /* Create layout: */
    145134    QGridLayout *pLayout = new QGridLayout(this);
     
    153142
    154143        /* Create size slider: */
    155         m_pSlider = new QSlider;
     144        m_pSlider = new QSlider(this);
    156145        if (m_pSlider)
    157146        {
     
    262251int UIMediumSizeEditor::sizeMBToSlider(qulonglong uValue, int iSliderScale)
    263252{
    264     /* Make sure *any* slider value is multiple of m_uSectorSize: */
    265     uValue /= m_uSectorSize;
     253    /* Make sure *any* slider value is multiple of s_uSectorSize: */
     254    uValue /= s_uSectorSize;
    266255
    267256    /* Calculate result: */
     
    286275    qulonglong uResult = uTickMB + (uTickMBNext - uTickMB) * iStep / iSliderScale;
    287276
    288     /* Make sure *any* slider value is multiple of m_uSectorSize: */
    289     uResult *= m_uSectorSize;
     277    /* Make sure *any* slider value is multiple of s_uSectorSize: */
     278    uResult *= s_uSectorSize;
    290279
    291280    /* Return result: */
     
    302291qulonglong UIMediumSizeEditor::checkSectorSizeAlignment(qulonglong uSize)
    303292{
    304     if (m_uSectorSize == 0 || uSize % m_uSectorSize == 0)
     293    if (s_uSectorSize == 0 || uSize % s_uSectorSize == 0)
    305294        return uSize;
    306     qulonglong uNewSize = (uSize / m_uSectorSize) * m_uSectorSize;
    307     return uNewSize;
    308 }
     295    return (uSize / s_uSectorSize) * s_uSectorSize;
     296}
     297
     298QString UIMediumSizeEditor::ensureSizeSuffix(const QString &strSizeString)
     299{
     300    /* Try to update the m_strSizeSuffix: */
     301    if (UITranslator::hasSizeSuffix(strSizeString))
     302        m_strSizeSuffix = gpConverter->toString(UITranslator::parseSizeSuffix(strSizeString));
     303
     304    /* Remove any chars from the string except digits and decimal separator and then add a space and size suffix: */
     305    QString strOnlyDigits(strSizeString);
     306    return QString("%1 %2").arg(strOnlyDigits.remove(m_regExNonDigitOrSeparator)).arg(m_strSizeSuffix);
     307}
  • trunk/src/VBox/Frontends/VirtualBox/src/widgets/UIMediumSizeEditor.h

    r104358 r104926  
    55
    66/*
    7  * Copyright (C) 2006-2023 Oracle and/or its affiliates.
     7 * Copyright (C) 2006-2024 Oracle and/or its affiliates.
    88 *
    99 * This file is part of VirtualBox base platform packages, as
     
    7070    /** Handles translation event. */
    7171    void sltRetranslateUI();
     72
    7273    /** Handles size slider change. */
    7374    void sltSizeSliderChanged(int iValue);
     
    9091    /** Updates slider/editor tool-tips. */
    9192    void updateSizeToolTips(qulonglong uSize);
    92     /** Checks if the uSize is divisible by m_uSectorSize */
     93    /** Checks if the uSize is divisible by s_uSectorSize */
    9394    qulonglong checkSectorSizeAlignment(qulonglong uSize);
     95    /** Ensures there is only proper size-suffix available. */
    9496    QString ensureSizeSuffix(const QString &strSizeString);
    9597
    9698    /* Holds the block size. We force m_uSize to be multiple of this number. */
    97     static const qulonglong m_uSectorSize;
     99    static const qulonglong  s_uSectorSize;
    98100    /** Holds the minimum medium size. */
    99101    const qulonglong  m_uSizeMin;
Note: See TracChangeset for help on using the changeset viewer.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette