VirtualBox

Changeset 99178 in vbox


Ignore:
Timestamp:
Mar 24, 2023 3:54:10 PM (21 months ago)
Author:
vboxsync
Message:

FE/Qt: bugref:10343: Extend UIUSBFilterDetailsEditor functionality with basic validation mechanism.

Location:
trunk/src/VBox/Frontends/VirtualBox/src/settings/editors
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VirtualBox/src/settings/editors/UIUSBFilterDetailsEditor.cpp

    r99177 r99178  
    3030#include <QGridLayout>
    3131#include <QLabel>
     32#include <QPushButton>
    3233#include <QRegularExpressionValidator>
    3334
     
    234235}
    235236
     237void UIUSBFilterDetailsEditor::sltRevalidate()
     238{
     239    /* Cast sender to editor: */
     240    QILineEdit *pEditor = qobject_cast<QILineEdit*>(sender());
     241    AssertPtrReturnVoid(pEditor);
     242
     243    /* Performs sender's validation: */
     244    revalidate(pEditor);
     245}
     246
    236247void UIUSBFilterDetailsEditor::prepare()
    237248{
     
    270281            m_pEditorName->setMinimumWidthByText(QString().fill('0', 32));
    271282            m_pEditorName->setValidator(new QRegularExpressionValidator(QRegularExpression(".+"), this));
     283            connect(m_pEditorName, &QLineEdit::textChanged,
     284                    this, &UIUSBFilterDetailsEditor::sltRevalidate);
    272285            pLayout->addWidget(m_pEditorName, 0, 1);
    273286        }
     
    288301            m_pEditorVendorID->setMinimumWidthByText(QString().fill('0', 8));
    289302            m_pEditorVendorID->setValidator(new QRegularExpressionValidator(QRegularExpression("[0-9a-fA-F]{0,4}"), this));
     303            connect(m_pEditorVendorID, &QLineEdit::textChanged,
     304                    this, &UIUSBFilterDetailsEditor::sltRevalidate);
    290305            pLayout->addWidget(m_pEditorVendorID, 1, 1);
    291306        }
     
    306321            m_pEditorProductID->setMinimumWidthByText(QString().fill('0', 8));
    307322            m_pEditorProductID->setValidator(new QRegularExpressionValidator(QRegularExpression("[0-9a-fA-F]{0,4}"), this));
     323            connect(m_pEditorProductID, &QLineEdit::textChanged,
     324                    this, &UIUSBFilterDetailsEditor::sltRevalidate);
    308325            pLayout->addWidget(m_pEditorProductID, 2, 1);
    309326        }
     
    324341            m_pEditorRevision->setMinimumWidthByText(QString().fill('0', 8));
    325342            m_pEditorRevision->setValidator(new QRegularExpressionValidator(QRegularExpression("[0-9a-fA-F]{0,4}"), this));
     343            connect(m_pEditorRevision, &QLineEdit::textChanged,
     344                    this, &UIUSBFilterDetailsEditor::sltRevalidate);
    326345            pLayout->addWidget(m_pEditorRevision, 3, 1);
    327346        }
     
    393412            m_pEditorPort->setMinimumWidthByText(QString().fill('0', 8));
    394413            m_pEditorPort->setValidator(new QRegularExpressionValidator(QRegularExpression("(0[xX])?[0-9a-fA-F]{0,4}"), this));
     414            connect(m_pEditorPort, &QLineEdit::textChanged,
     415                    this, &UIUSBFilterDetailsEditor::sltRevalidate);
    395416            pLayout->addWidget(m_pEditorPort, 7, 1);
    396417        }
     
    436457}
    437458
     459void UIUSBFilterDetailsEditor::revalidate(QILineEdit *pEditor)
     460{
     461    /* Acquire current validator: */
     462    const QValidator *pValidator = pEditor->validator();
     463    AssertPtrReturnVoid(pValidator);
     464
     465    /* Validate current text: */
     466    QString strText = pEditor->text();
     467    int iPos = 0;
     468    const QValidator::State enmState = pValidator->validate(strText, iPos);
     469
     470    /* Store current validation verdict: */
     471    m_valid[pEditor] = enmState == QValidator::Acceptable;
     472
     473    /* Calculate overall validation result: */
     474    bool fValid = true;
     475    foreach (bool fValidOne, m_valid.values())
     476        if (!fValidOne)
     477        {
     478            fValid = false;
     479            break;
     480        }
     481
     482    /* Enable/disable button-box Ok button accordingly: */
     483    m_pButtonBox->button(QDialogButtonBox::Ok)->setEnabled(fValid);
     484}
     485
    438486/* static */
    439487QString UIUSBFilterDetailsEditor::wiped(const QString &strString)
  • trunk/src/VBox/Frontends/VirtualBox/src/settings/editors/UIUSBFilterDetailsEditor.h

    r99177 r99178  
    102102    virtual void retranslateUi() RT_OVERRIDE;
    103103
     104private slots:
     105
     106    /** Performs validation for connected sender. */
     107    void sltRevalidate();
     108
    104109private:
    105110
     
    111116    void prepareConnections();
    112117
     118    /** Performs validation for @a pEditor. */
     119    void revalidate(QILineEdit *pEditor);
     120
    113121    /** Wipes out @a strString if it's empty. */
    114122    static QString wiped(const QString &strString);
     123
     124    /** Holds whether editors currently valid. */
     125    QMap<QILineEdit*, bool>  m_valid;
    115126
    116127    /** @name Widgets
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