VirtualBox

Ignore:
Timestamp:
Sep 17, 2019 1:08:09 PM (5 years ago)
Author:
vboxsync
Message:

FE/Qt: bugref:9335: Connecting to text change rather than text edited.

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

Legend:

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

    r79365 r80859  
    4848    /* Prepare: */
    4949    prepare();
     50    QString strRegEx = QString("[^(\\d|%1)]").arg(uiCommon().decimalSep());
     51    m_regExNonDigitOrSeparator = QRegularExpression(strRegEx);
    5052}
    5153
     
    9799}
    98100
    99 void UIMediumSizeEditor::sltSizeEditorEditingFinished()
     101void UIMediumSizeEditor::sltSizeEditorTextChanged()
    100102{
    101103    QString strSizeString = ensureSizeSuffix(m_pEditor->text());
    102104
    103     if (strSizeString != m_pEditor->text())
    104     {
    105         m_pEditor->blockSignals(true);
    106         m_pEditor->setText(strSizeString);
    107         m_pEditor->blockSignals(false);
    108     }
     105
     106    m_pEditor->blockSignals(true);
     107    m_pEditor->setText(strSizeString);
     108    /* Reposition the cursor to the front of the size suffix (and 1 char for the space) */
     109    m_pEditor->setCursorPosition(strSizeString.length() - (gpConverter->toString(m_enmSizeSuffix).length() + 1));
     110    m_pEditor->blockSignals(false);
    109111
    110112    /* Update the current size: */
     
    123125QString UIMediumSizeEditor::ensureSizeSuffix(const QString &strSizeString)
    124126{
     127    /* Try to update the m_enmSizeSuffix: */
    125128    if (uiCommon().hasSizeSuffix(strSizeString))
    126     {
    127         /* Update the m_enmSizeSuffix: */
    128129        m_enmSizeSuffix = uiCommon().parseSizeSuffix(strSizeString);
    129         return strSizeString;
    130     }
    131 
    132     return QString("%1 %2").arg(strSizeString).arg(gpConverter->toString(m_enmSizeSuffix));
     130
     131    QString strOnlyDigits(strSizeString);
     132    /* Remove any chars from the string except digits and decimal separator and then add a space and size suffix: */
     133    return QString("%1 %2").arg(strOnlyDigits.remove(m_regExNonDigitOrSeparator)).arg(gpConverter->toString(m_enmSizeSuffix));
    133134}
    134135
     
    193194        {
    194195            /* Configure editor: */
     196            m_pEditor->installEventFilter(this);
    195197            m_pEditor->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Fixed);
    196198            m_pEditor->setFixedWidthByText("88888.88 MB");
    197199            m_pEditor->setAlignment(Qt::AlignRight);
    198200            m_pEditor->setValidator(new QRegExpValidator(QRegExp(uiCommon().sizeRegexp()), this));
    199             connect(m_pEditor, &QILineEdit::editingFinished,
    200                     this, &UIMediumSizeEditor::sltSizeEditorEditingFinished);
     201            connect(m_pEditor, &QILineEdit::textChanged,
     202                    this, &UIMediumSizeEditor::sltSizeEditorTextChanged);
    201203
    202204            /* Add into layout: */
  • trunk/src/VBox/Frontends/VirtualBox/src/widgets/UIMediumSizeEditor.h

    r77556 r80859  
    2323
    2424/* Qt includes: */
     25#include <QRegularExpression>
    2526#include <QWidget>
    2627
     
    5455    /** Returns the medium size. */
    5556    qulonglong mediumSize() const { return m_uSize; }
    56     /** Defines the @a uSize. */
     57    /** Sets the initial medium size as the widget is created. */
    5758    void setMediumSize(qulonglong uSize);
    5859
     
    6768    void sltSizeSliderChanged(int iValue);
    6869    /** Handles size editor text edit finished signal. */
    69     void sltSizeEditorEditingFinished();
     70    void sltSizeEditorTextChanged();
    7071
    7172private:
     
    108109    /** Holds the size editor. */
    109110    QILineEdit *m_pEditor;
     111
     112    /* A regular expression used to remove any character from a QString which is neither a digit nor decimal separator. */
     113    QRegularExpression m_regExNonDigitOrSeparator;
    110114};
    111115
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