VirtualBox

Changeset 14540 in vbox


Ignore:
Timestamp:
Nov 24, 2008 6:44:17 PM (16 years ago)
Author:
vboxsync
Message:

FE/Qt4: FormatSize function reworked, warning about too low memory for seamless updated to use integer format of size instead of decimal.

Location:
trunk/src/VBox/Frontends/VirtualBox4
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VirtualBox4/include/VBoxDefs.h

    r14509 r14540  
    124124    };
    125125
     126    /** Size formatting types. */
     127    enum FormatSize
     128    {
     129        FormatSize_Round,
     130        FormatSize_RoundDown,
     131        FormatSize_RoundUp
     132    };
     133
    126134    static const char* GUI_LastWindowPosition;
    127135    static const char* GUI_LastWindowPosition_Max;
  • trunk/src/VBox/Frontends/VirtualBox4/include/VBoxGlobal.h

    r14511 r14540  
    844844
    845845    static quint64 parseSize (const QString &);
    846     static QString formatSize (quint64, int aMode = 0);
     846    static QString formatSize (quint64 aSize, uint aDecimal = 2,
     847                               VBoxDefs::FormatSize aMode = VBoxDefs::FormatSize_Round);
    847848
    848849    static quint64 requiredVideoMemory (CMachine *aMachine = 0);
  • trunk/src/VBox/Frontends/VirtualBox4/src/VBoxGlobal.cpp

    r14511 r14540  
    38253825 *  in form of <tt>####[.##] B|KB|MB|GB|TB|PB</tt>.
    38263826 *
    3827  *  The \a mode parameter is used for resulting numbers that get a fractional
    3828  *  part after converting the \a size to KB, MB etc:
     3827 *  The \a mode parameter is used for rounding the resulting number
     3828 *  after converting the \a size to KB, MB etc:
    38293829 *  <ul>
    3830  *  <li>When \a mode is 0, the result is rounded to the closest number
    3831  *      containing two decimal digits.
     3830 *  <li>When \a mode is FormatSize_Round, the result is rounded to the
     3831 *      closest number containing \a decimal number of digits.
    38323832 *  </li>
    3833  *  <li>When \a mode is -1, the result is rounded to the largest two decimal
    3834  *      digit number that is not greater than the result. This guarantees that
    3835  *      converting the resulting string back to the integer value in bytes
    3836  *      will not produce a value greater that the initial \a size parameter.
     3833 *  <li>When \a mode is FormatSize_RoundDown, the result is rounded to the
     3834 *      largest \a decimal number of digits that is not greater than the
     3835 *      result. This guarantees that converting the resulting string back
     3836 *      to the integer value in bytes will not produce a value greater that
     3837 *      the initial \a size parameter.
    38373838 *  </li>
    3838  *  <li>When \a mode is 1, the result is rounded to the smallest two decimal
    3839  *      digit number that is not less than the result. This guarantees that
    3840  *      converting the resulting string back to the integer value in bytes
    3841  *      will not produce a value less that the initial \a size parameter.
     3839 *  <li>When \a mode is FormatSize_RoundUp, the result is rounded to the
     3840 *      smallest \a decimal number of digits that is not less than the
     3841 *      result. This guarantees that converting the resulting string back
     3842 *      to the integer value in bytes will not produce a value less that
     3843 *      the initial \a size parameter.
    38423844 *  </li>
    38433845 *  </ul>
    38443846 *
    3845  *  @param  aSize   size value in bytes
    3846  *  @param  aMode   convertion mode (-1, 0 or 1)
    3847  *  @return         human-readable size string
     3847 *  @param  aSize    size value in bytes
     3848 *  @param  aMode    convertion mode (FormatSize_Round, FormatSize_RoundDown,
     3849 *                                                      FormatSize_RoundUp)
     3850 *  @param  aDecimal the number of decimal digits in result
     3851 *  @return          human-readable size string
    38483852 */
    38493853/* static */
    3850 QString VBoxGlobal::formatSize (quint64 aSize, int aMode /* = 0 */)
     3854QString VBoxGlobal::formatSize (quint64 aSize, uint aDecimal /* = 2 */,
     3855                                VBoxDefs::FormatSize aMode /* = FormatSize_Round */)
    38513856{
    38523857    static const char *Suffixes [] = { "B", "KB", "MB", "GB", "TB", "PB", NULL };
     
    38873892
    38883893    quint64 intg = aSize / denom;
    3889     quint64 hund = aSize % denom;
     3894    quint64 decm = aSize % denom;
     3895    quint64 mult = 1;
     3896    for (uint i = 0; i < aDecimal; ++ i) mult *= 10;
    38903897
    38913898    QString number;
    38923899    if (denom > 1)
    38933900    {
    3894         if (hund)
    3895         {
    3896             hund *= 100;
     3901        if (decm)
     3902        {
     3903            decm *= mult;
    38973904            /* not greater */
    3898             if (aMode < 0) hund = hund / denom;
     3905            if (aMode == VBoxDefs::FormatSize_RoundDown)
     3906                decm = decm / denom;
    38993907            /* not less */
    3900             else if (aMode > 0) hund = (hund + denom - 1) / denom;
     3908            else if (aMode == VBoxDefs::FormatSize_RoundUp)
     3909                decm = (decm + denom - 1) / denom;
    39013910            /* nearest */
    3902             else hund = (hund + denom / 2) / denom;
     3911            else decm = (decm + denom / 2) / denom;
    39033912        }
    39043913        /* check for the fractional part overflow due to rounding */
    3905         if (hund == 100)
    3906         {
    3907             hund = 0;
     3914        if (decm == mult)
     3915        {
     3916            decm = 0;
    39083917            ++ intg;
    39093918            /* check if we've got 1024 XB after rounding and scale down if so */
     
    39143923            }
    39153924        }
    3916         number = QString ("%1%2%3").arg (intg).arg (decimalSep())
    3917                                    .arg (QString::number (hund).rightJustified (2, '0'));
     3925        number = QString::number (intg);
     3926        if (aDecimal) number += QString ("%1%2").arg (decimalSep())
     3927            .arg (QString::number (decm).rightJustified (aDecimal, '0'));
    39183928    }
    39193929    else
  • trunk/src/VBox/Frontends/VirtualBox4/src/VBoxNewHDWzd.cpp

    r13580 r14540  
    128128    }
    129129    mSliderScale = qMax (mSliderScale, 8);
    130     mLeName->setValidator (new QRegExpValidator (QRegExp( ".+" ), this));
    131     mLeSize->setValidator (new QRegExpValidator (QRegExp(vboxGlobal().sizeRegexp()), this));
     130    mLeName->setValidator (new QRegExpValidator (QRegExp (".+"), this));
     131    mLeSize->setValidator (new QRegExpValidator (QRegExp (vboxGlobal().sizeRegexp()), this));
    132132    mLeSize->setAlignment (Qt::AlignRight);
    133133    mWValNameAndSize = new QIWidgetValidator (mPageNameAndSize, this);
  • trunk/src/VBox/Frontends/VirtualBox4/src/VBoxVMSettingsGeneral.cpp

    r14444 r14540  
    392392            "the minimum amount required to switch the virtual machine to "
    393393            "fullscreen or seamless mode.")
    394             .arg (vboxGlobal().formatSize (needBytes));
     394            .arg (vboxGlobal().formatSize (needBytes, 0, VBoxDefs::FormatSize_RoundUp));
    395395        return true;
    396396    }
  • trunk/src/VBox/Frontends/VirtualBox4/ui/VBoxNewHDWzd.ui

    r13580 r14540  
    603603                 </sizepolicy>
    604604                </property>
    605                 <property name="text" >
    606                  <string/>
    607                 </property>
    608605                <property name="alignment" >
    609606                 <set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop</set>
     
    634631                  <verstretch>0</verstretch>
    635632                 </sizepolicy>
    636                 </property>
    637                 <property name="text" >
    638                  <string/>
    639633                </property>
    640634                <property name="alignment" >
Note: See TracChangeset for help on using the changeset viewer.

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