VirtualBox

Changeset 100969 in vbox


Ignore:
Timestamp:
Aug 25, 2023 12:15:39 PM (14 months ago)
Author:
vboxsync
Message:

FE/Qt: UISettingsDialog: Moving code specific for page validator from dialog to corresponding class.

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

Legend:

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

    r100967 r100969  
    198198    /* Retranslate all validators: */
    199199    foreach (UISettingsPageValidator *pValidator, findChildren<UISettingsPageValidator*>())
    200         if (!pValidator->lastMessage().isEmpty())
    201             revalidate(pValidator);
     200        pValidator->setTitlePrefix(m_pSelector->itemTextByPage(pValidator->page()));
    202201    revalidate();
    203202}
     
    448447}
    449448
    450 void UISettingsDialog::revalidate(UISettingsPageValidator *pValidator)
    451 {
    452     /* Perform page revalidation: */
    453     UISettingsPage *pSettingsPage = pValidator->page();
    454     QList<UIValidationMessage> messages;
    455     bool fIsValid = pSettingsPage->validate(messages);
    456 
    457     /* Remember revalidation result: */
    458     pValidator->setValid(fIsValid);
    459 
    460     /* Remember warning/error message: */
    461     if (messages.isEmpty())
    462         pValidator->setLastMessage(QString());
    463     else
    464     {
    465         /* Prepare title prefix: */
    466         // Its the only thing preventing us from moving this method to validator.
    467         const QString strTitlePrefix(m_pSelector->itemTextByPage(pSettingsPage));
    468         /* Prepare text: */
    469         QStringList text;
    470         foreach (const UIValidationMessage &message, messages)
    471         {
    472             /* Prepare title: */
    473             const QString strTitle(message.first.isNull() ? tr("<b>%1</b> page:").arg(strTitlePrefix) :
    474                                                             tr("<b>%1: %2</b> page:").arg(strTitlePrefix, message.first));
    475             /* Prepare paragraph: */
    476             QStringList paragraph(message.second);
    477             paragraph.prepend(strTitle);
    478             /* Format text for iterated message: */
    479             text << paragraph.join("<br>");
    480         }
    481         /* Remember text: */
    482         pValidator->setLastMessage(text.join("<br><br>"));
    483         LogRelFlow(("Settings Dialog:  Page validation FAILED: {%s}\n",
    484                     pValidator->lastMessage().toUtf8().constData()));
    485     }
    486 }
    487 
    488449void UISettingsDialog::revalidate()
    489450{
     
    554515
    555516        /* Perform page revalidation: */
    556         revalidate(pValidator);
     517        pValidator->revalidate();
    557518        /* Perform inter-page recorrelation: */
    558519        recorrelate(pSettingsPage);
  • trunk/src/VBox/Frontends/VirtualBox/src/settings/UISettingsDialog.h

    r100961 r100969  
    159159    void addPageHelpKeyword(int iPageType, const QString &strHelpKeyword);
    160160
    161     /** Validates data correctness using certain @a pValidator. */
    162     void revalidate(UISettingsPageValidator *pValidator);
    163161    /** Validates data correctness. */
    164162    void revalidate();
  • trunk/src/VBox/Frontends/VirtualBox/src/settings/UISettingsPageValidator.cpp

    r100968 r100969  
    4848}
    4949
     50void UISettingsPageValidator::setTitlePrefix(const QString &strPrefix)
     51{
     52    /* Assign new prefix: */
     53    m_strPrefix = strPrefix;
     54
     55    /* Revalidate if we had errors previously: */
     56    if (!lastMessage().isEmpty())
     57        revalidate();
     58}
     59
    5060void UISettingsPageValidator::setLastMessage(const QString &strLastMessage)
    5161{
     
    6575    emit sigValidityChanged(this);
    6676}
     77
     78void UISettingsPageValidator::revalidate()
     79{
     80    /* Perform page revalidation: */
     81    QList<UIValidationMessage> messages;
     82    setValid(m_pPage->validate(messages));
     83
     84    /* Remember warning/error message: */
     85    if (messages.isEmpty())
     86        setLastMessage(QString());
     87    else
     88    {
     89        /* Prepare text: */
     90        QStringList text;
     91        foreach (const UIValidationMessage &message, messages)
     92        {
     93            /* Prepare title: */
     94            const QString strTitle(message.first.isNull() ? tr("<b>%1</b> page:").arg(m_strPrefix) :
     95                                                            tr("<b>%1: %2</b> page:").arg(m_strPrefix, message.first));
     96
     97            /* Prepare paragraph: */
     98            QStringList paragraph(message.second);
     99            paragraph.prepend(strTitle);
     100
     101            /* Format text for iterated message: */
     102            text << paragraph.join("<br>");
     103        }
     104
     105        /* Remember text: */
     106        setLastMessage(text.join("<br><br>"));
     107        LogRelFlow(("Settings Dialog:  Page validation FAILED: {%s}\n",
     108                    lastMessage().toUtf8().constData()));
     109    }
     110}
  • trunk/src/VBox/Frontends/VirtualBox/src/settings/UISettingsPageValidator.h

    r100968 r100969  
    7373    QString internalName() const;
    7474
     75    /** Defines title @a strPrefix. */
     76    void setTitlePrefix(const QString &strPrefix);
     77
    7578    /** Returns whether validator is valid. */
    7679    bool isValid() const { return m_fIsValid; }
     
    8689    void invalidate();
    8790
     91    /** Revalidate validator. */
     92    void revalidate();
     93
    8894private:
    8995
    9096    /** Holds the validated page. */
    9197    UISettingsPage *m_pPage;
     98
     99    /** Holds the title prefix. */
     100    QString  m_strPrefix;
    92101
    93102    /** Holds whether the page is valid. */
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