VirtualBox

Changeset 78250 in vbox for trunk/src/VBox


Ignore:
Timestamp:
Apr 22, 2019 3:03:45 PM (6 years ago)
Author:
vboxsync
Message:

FE/Qt: bugref:9434: Import Appliance wizard: Form Editor widget: A bit of cleanup/rework for ChoiceData class.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VirtualBox/src/wizards/importappliance/UIFormEditorWidget.cpp

    r78249 r78250  
    5757    /** Constructs null choice data. */
    5858    ChoiceData() {}
    59     /** Constructs choice data on the basis of passed @a choices and @a iSelectedChoice. */
    60     ChoiceData(const QVector<QString> &choices, int iSelectedChoice)
    61         : m_choices(choices), m_iSelectedChoice(iSelectedChoice) {}
     59    /** Constructs choice data on the basis of passed @a values and @a iSelectedIndex. */
     60    ChoiceData(const QVector<QString> &values, int iSelectedIndex)
     61        : m_values(values), m_iSelectedIndex(iSelectedIndex) {}
    6262    /** Constructs choice data on the basis of another @a choice data. */
    6363    ChoiceData(const ChoiceData &choice)
    64         : m_choices(choice.choices()), m_iSelectedChoice(choice.selectedChoice()) {}
    65 
    66     /** Returns choice list. */
    67     QVector<QString> choices() const { return m_choices; }
    68     /** Returns current selected choice. */
    69     int selectedChoice() const { return m_iSelectedChoice; }
     64        : m_values(choice.values()), m_iSelectedIndex(choice.selectedIndex()) {}
     65
     66    /** Assigns values of @a other choice to this one. */
     67    ChoiceData &operator=(const ChoiceData &other)
     68    {
     69        m_values = other.values();
     70        m_iSelectedIndex = other.selectedIndex();
     71        return *this;
     72    }
     73
     74    /** Returns values vector. */
     75    QVector<QString> values() const { return m_values; }
     76    /** Returns selected index. */
     77    int selectedIndex() const { return m_iSelectedIndex; }
     78    /** Returns selected value. */
     79    QString selectedValue() const
     80    {
     81        return   m_iSelectedIndex >= 0 && m_iSelectedIndex < m_values.size()
     82               ? m_values.at(m_iSelectedIndex) : QString();
     83    }
    7084
    7185private:
    7286
    73     /** Holds choice list. */
    74     QVector<QString>  m_choices;
    75     /** Holds current selected choice. */
    76     int               m_iSelectedChoice;
     87    /** Holds values vector. */
     88    QVector<QString>  m_values;
     89    /** Holds selected index. */
     90    int               m_iSelectedIndex;
    7791};
    7892Q_DECLARE_METATYPE(ChoiceData);
     
    96110    void setChoice(const ChoiceData &choice)
    97111    {
    98         addItems(choice.choices().toList());
    99         setCurrentIndex(choice.selectedChoice());
     112        addItems(choice.values().toList());
     113        setCurrentIndex(choice.selectedIndex());
    100114    }
    101115
     
    415429{
    416430    /* Do nothing for empty choices: */
    417     if (choice.selectedChoice() == -1)
     431    if (choice.selectedIndex() == -1)
    418432        return;
    419433
    420434    AssertReturnVoid(valueType() == KFormValueType_Choice);
    421435    CChoiceFormValue comValue(m_comValue);
    422     CProgress comProgress = comValue.SetSelectedIndex(choice.selectedChoice());
     436    CProgress comProgress = comValue.SetSelectedIndex(choice.selectedIndex());
    423437
    424438    /* Show error message if necessary: */
     
    468482            const int iSelectedIndex = comValue.GetSelectedIndex();
    469483            m_choice = ChoiceData(values, iSelectedIndex);
    470             m_cells[UIFormEditorDataType_Value]->setText(  !m_choice.choices().isEmpty()
    471                                                          ? m_choice.choices().at(m_choice.selectedChoice())
    472                                                          : QString());
     484            m_cells[UIFormEditorDataType_Value]->setText(m_choice.selectedValue());
    473485            /// @todo check for errors
    474486            break;
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