VirtualBox

Changeset 77556 in vbox


Ignore:
Timestamp:
Mar 4, 2019 1:33:06 PM (6 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
129161
Message:

FE/Qt: bugref:9335. Making sure size editor has size suffix even if the user leaves it out.

Location:
trunk/src/VBox/Frontends/VirtualBox/src
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VirtualBox/src/globals/VBoxGlobal.cpp

    r77377 r77556  
    971971    else
    972972        return 0;
     973}
     974
     975/* static */
     976SizeSuffix VBoxGlobal::parseSizeSuffix(const QString &strText)
     977{
     978    /* Text should be in form of B|KB|MB|GB|TB|PB. */
     979    QRegExp regexp(sizeRegexp());
     980    int iPos = regexp.indexIn(strText);
     981    if (iPos != -1)
     982    {
     983        QString strInteger = regexp.cap(1);
     984        QString strSuff = regexp.cap(2);
     985        if (strInteger.isEmpty())
     986        {
     987            strInteger = regexp.cap(3);
     988            strSuff = regexp.cap(5);
     989        }
     990
     991        SizeSuffix enmSizeSuffix = SizeSuffix_Byte;
     992
     993        if (strSuff.isEmpty() || strSuff == tr("B", "size suffix Bytes"))
     994            enmSizeSuffix = SizeSuffix_Byte;
     995        else if (strSuff == tr("KB", "size suffix KBytes=1024 Bytes"))
     996            enmSizeSuffix = SizeSuffix_KiloByte;
     997        else if (strSuff == tr("MB", "size suffix MBytes=1024 KBytes"))
     998            enmSizeSuffix = SizeSuffix_MegaByte;
     999        else if (strSuff == tr("GB", "size suffix GBytes=1024 MBytes"))
     1000            enmSizeSuffix = SizeSuffix_GigaByte;
     1001        else if (strSuff == tr("TB", "size suffix TBytes=1024 GBytes"))
     1002            enmSizeSuffix = SizeSuffix_TeraByte;
     1003        else if (strSuff == tr("PB", "size suffix PBytes=1024 TBytes"))
     1004            enmSizeSuffix = SizeSuffix_PetaByte;
     1005        return enmSizeSuffix;
     1006    }
     1007    else
     1008        return SizeSuffix_Byte;
     1009}
     1010
     1011/* static */
     1012bool VBoxGlobal::hasSizeSuffix(const QString &strText)
     1013{
     1014    /* Text should be in form of B|KB|MB|GB|TB|PB. */
     1015    QRegExp regexp(sizeRegexp());
     1016    int iPos = regexp.indexIn(strText);
     1017    if (iPos != -1)
     1018    {
     1019        QString strInteger = regexp.cap(1);
     1020        QString strSuff = regexp.cap(2);
     1021        if (strInteger.isEmpty())
     1022        {
     1023            strInteger = regexp.cap(3);
     1024            strSuff = regexp.cap(5);
     1025        }
     1026
     1027        if (strSuff.isEmpty())
     1028            return false;
     1029        if (strSuff == tr("B", "size suffix Bytes") ||
     1030            strSuff == tr("KB", "size suffix KBytes=1024 Bytes") ||
     1031            strSuff == tr("MB", "size suffix MBytes=1024 KBytes") ||
     1032            strSuff == tr("GB", "size suffix GBytes=1024 MBytes") ||
     1033            strSuff == tr("TB", "size suffix TBytes=1024 GBytes") ||
     1034            strSuff == tr("PB", "size suffix PBytes=1024 TBytes"))
     1035            return true;
     1036        return false;
     1037    }
     1038    else
     1039        return false;
    9731040}
    9741041
  • trunk/src/VBox/Frontends/VirtualBox/src/globals/VBoxGlobal.h

    r77291 r77556  
    320320        /** Parses the given size strText and returns the size value in bytes. */
    321321        static quint64 parseSize(const QString &strText);
     322        /** Parses the given size strText and returns the size suffix. */
     323        static SizeSuffix parseSizeSuffix(const QString &strText);
     324        /** Parses the given string @a strText and returns true if it includes a size suffix. */
     325        static bool hasSizeSuffix(const QString &strText);
    322326        /** Formats the given @a uSize value in bytes to a human readable string.
    323327          * @param  uSize     Brings the size value in bytes.
  • trunk/src/VBox/Frontends/VirtualBox/src/widgets/UIMediumSizeEditor.cpp

    r76606 r77556  
    2525#include "QILineEdit.h"
    2626#include "VBoxGlobal.h"
     27#include "UIConverter.h"
    2728#include "UIMediumSizeEditor.h"
    2829
     
    3839    , m_uSizeMax(vboxGlobal().virtualBox().GetSystemProperties().GetInfoVDSize())
    3940    , m_iSliderScale(calculateSliderScale(m_uSizeMax))
     41    , m_uSize(0)
     42    , m_enmSizeSuffix(SizeSuffix_Byte)
    4043    , m_pSlider(0)
    4144    , m_pLabelMinSize(0)
     
    5861    m_pEditor->blockSignals(true);
    5962    m_pEditor->setText(vboxGlobal().formatSize(m_uSize));
     63    m_enmSizeSuffix = vboxGlobal().parseSizeSuffix(m_pEditor->text());
    6064    m_pEditor->blockSignals(false);
    6165
     
    8589    m_pEditor->blockSignals(true);
    8690    m_pEditor->setText(vboxGlobal().formatSize(m_uSize));
     91    m_enmSizeSuffix = vboxGlobal().parseSizeSuffix(m_pEditor->text());
    8792    m_pEditor->blockSignals(false);
    8893    /* Update the tool-tips: */
     
    9297}
    9398
    94 void UIMediumSizeEditor::sltSizeEditorChanged(const QString &strValue)
    95 {
     99void UIMediumSizeEditor::sltSizeEditorEditingFinished()
     100{
     101    QString strSizeString = ensureSizeSuffix(m_pEditor->text());
     102
     103    if (strSizeString != m_pEditor->text())
     104    {
     105        m_pEditor->blockSignals(true);
     106        m_pEditor->setText(strSizeString);
     107        m_pEditor->blockSignals(false);
     108    }
     109
    96110    /* Update the current size: */
    97     m_uSize = vboxGlobal().parseSize(strValue);
     111    m_uSize = checkSectorSizeAlignment(vboxGlobal().parseSize(strSizeString));
     112
    98113    /* Update the other widget: */
    99114    m_pSlider->blockSignals(true);
     
    106121}
    107122
    108 void UIMediumSizeEditor::sltSizeEditorEditingFinished()
    109 {
    110     qulonglong uSize = checkSectorSizeAlignment(m_uSize);
    111 
    112     /* The size is already aligned to sector size: */
    113     if (uSize == m_uSize)
    114         return;
    115     setMediumSize(uSize);
     123QString UIMediumSizeEditor::ensureSizeSuffix(const QString &strSizeString)
     124{
     125    if (vboxGlobal().hasSizeSuffix(strSizeString))
     126    {
     127        /* Update the m_enmSizeSuffix: */
     128        m_enmSizeSuffix = vboxGlobal().parseSizeSuffix(strSizeString);
     129        return strSizeString;
     130    }
     131
     132    return QString("%1 %2").arg(strSizeString).arg(gpConverter->toString(m_enmSizeSuffix));
    116133}
    117134
     
    180197            m_pEditor->setAlignment(Qt::AlignRight);
    181198            m_pEditor->setValidator(new QRegExpValidator(QRegExp(vboxGlobal().sizeRegexp()), this));
    182             connect(m_pEditor, &QILineEdit::textChanged,
    183                     this, &UIMediumSizeEditor::sltSizeEditorChanged);
    184199            connect(m_pEditor, &QILineEdit::editingFinished,
    185200                    this, &UIMediumSizeEditor::sltSizeEditorEditingFinished);
  • trunk/src/VBox/Frontends/VirtualBox/src/widgets/UIMediumSizeEditor.h

    r76581 r77556  
    2727/* GUI includes: */
    2828#include "QIWithRetranslateUI.h"
     29#include "UIDefs.h"
    2930#include "UILibraryDefs.h"
    3031
     
    6566    /** Handles size slider change. */
    6667    void sltSizeSliderChanged(int iValue);
    67     /** Handles size editor change. */
    68     void sltSizeEditorChanged(const QString &strValue);
     68    /** Handles size editor text edit finished signal. */
    6969    void sltSizeEditorEditingFinished();
    7070
     
    8686    /** Checks if the uSize is divisible by m_uSectorSize */
    8787    qulonglong checkSectorSizeAlignment(qulonglong uSize);
     88    QString ensureSizeSuffix(const QString &strSizeString);
    8889
    8990    /* Holds the block size. We force m_uSize to be multiple of this number. */
     
    9798    /** Holds the current medium size. */
    9899    qulonglong        m_uSize;
     100    SizeSuffix        m_enmSizeSuffix;
    99101
    100102    /** Holds the size slider. */
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