VirtualBox

Changeset 43540 in vbox for trunk/src/VBox


Ignore:
Timestamp:
Oct 4, 2012 12:56:22 PM (12 years ago)
Author:
vboxsync
Message:

FE/Qt: VM group feature UI: Current-item handling cleanup (part 3).

Location:
trunk/src/VBox/Frontends/VirtualBox/src/selector/graphics/chooser
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VirtualBox/src/selector/graphics/chooser/UIGChooser.cpp

    r43536 r43540  
    149149    /* Prepare model: */
    150150    m_pChooserModel->prepare();
    151 
    152     /* Load last selected item: */
    153     m_pChooserModel->setCurrentItemDefinition(vboxGlobal().virtualBox().GetExtraData(GUI_LastItemSelected));
    154151}
    155152
    156153void UIGChooser::save()
    157154{
    158     /* Save last selected item: */
    159     vboxGlobal().virtualBox().SetExtraData(GUI_LastItemSelected, m_pChooserModel->currentItemDefinition());
    160 
    161155    /* Cleanup model: */
    162156    m_pChooserModel->cleanup();
  • trunk/src/VBox/Frontends/VirtualBox/src/selector/graphics/chooser/UIGChooserItem.h

    r43447 r43540  
    8181    virtual void startEditing() = 0;
    8282    virtual QString name() const = 0;
     83    virtual QString definition() const = 0;
    8384    void setRoot(bool fRoot);
    8485    bool isRoot() const;
  • trunk/src/VBox/Frontends/VirtualBox/src/selector/graphics/chooser/UIGChooserItemGroup.cpp

    r43539 r43540  
    185185{
    186186    return m_strName;
     187}
     188
     189QString UIGChooserItemGroup::definition() const
     190{
     191    return QString("g=%1").arg(name());
    187192}
    188193
  • trunk/src/VBox/Frontends/VirtualBox/src/selector/graphics/chooser/UIGChooserItemGroup.h

    r43505 r43540  
    6868    /* API: Basic stuff: */
    6969    QString name() const;
     70    QString definition() const;
    7071    void setName(const QString &strName);
    7172    bool closed() const;
  • trunk/src/VBox/Frontends/VirtualBox/src/selector/graphics/chooser/UIGChooserItemMachine.cpp

    r43539 r43540  
    134134}
    135135
     136QString UIGChooserItemMachine::definition() const
     137{
     138    return QString("m=%1").arg(name());
     139}
     140
    136141bool UIGChooserItemMachine::isLockedMachine() const
    137142{
  • trunk/src/VBox/Frontends/VirtualBox/src/selector/graphics/chooser/UIGChooserItemMachine.h

    r43447 r43540  
    5151    /* API: Basic stuff: */
    5252    QString name() const;
     53    QString definition() const;
    5354    bool isLockedMachine() const;
    5455
  • trunk/src/VBox/Frontends/VirtualBox/src/selector/graphics/chooser/UIGChooserModel.cpp

    r43539 r43540  
    192192}
    193193
    194 QString UIGChooserModel::currentItemDefinition() const
    195 {
    196     /* Determine item type: */
    197     QString strItemType;
    198     QString strItemName;
    199 
    200     /* Get first selected item: */
    201     UIGChooserItem *pSelectedItem = currentItem();
    202     /* Item exists? */
    203     if (pSelectedItem)
    204     {
    205         /* Update item type: */
    206         if (pSelectedItem->type() == UIGChooserItemType_Group)
    207             strItemType = "g";
    208         else if (pSelectedItem->type() == UIGChooserItemType_Machine)
    209             strItemType = "m";
    210 
    211         /* Update item name: */
    212         strItemName = pSelectedItem->name();
    213     }
    214 
    215     /* Return result: */
    216     return pSelectedItem ? strItemType + "=" + strItemName : QString();
    217 }
    218 
    219194QList<UIVMItem*> UIGChooserModel::currentMachineItems() const
    220195{
     
    260235}
    261236
    262 void UIGChooserModel::setCurrentItemDefinition(const QString &strDefinition)
    263 {
    264     /* Make sure something was passed: */
     237void UIGChooserModel::setCurrentItem(const QString &strDefinition)
     238{
     239    /* Ignore if empty definition passed: */
    265240    if (strDefinition.isEmpty())
    266     {
    267         if (mainRoot()->hasItems())
    268             setCurrentItem(0);
    269         else
    270             unsetCurrentItem();
    271241        return;
    272     }
    273 
    274     /* Parse definitions: */
     242
     243    /* Parse definition: */
     244    UIGChooserItem *pItem = 0;
    275245    QString strItemType = strDefinition.section('=', 0, 0);
    276     QString strItemName = strDefinition.section('=', 1, -1);
    277     UIGChooserItem *pItem = 0;
    278 
    279     /* Its group item? */
     246    QString strItemDescriptor = strDefinition.section('=', 1, -1);
     247    /* Its a group-item definition? */
    280248    if (strItemType == "g")
    281249    {
    282         /* Make sure group item with passed id exists: */
    283         pItem = findGroupItem(strItemName, mainRoot());
    284     }
    285     /* Its machine item? */
     250        /* Search for group-item with passed descriptor (name): */
     251        pItem = findGroupItem(strItemDescriptor, mainRoot());
     252    }
     253    /* Its a machine-item definition? */
    286254    else if (strItemType == "m")
    287255    {
    288         /* Make sure machine with passed name registered: */
    289         CMachine machine = vboxGlobal().virtualBox().FindMachine(strItemName);
     256        /* Check if machine-item with passed descriptor (name or id) registered: */
     257        CMachine machine = vboxGlobal().virtualBox().FindMachine(strItemDescriptor);
    290258        if (!machine.isNull())
    291259        {
    292             /* Make sure machine item with passed id exists: */
     260            /* Search for machine-item with required name: */
    293261            pItem = findMachineItem(machine.GetName(), mainRoot());
    294262        }
    295263    }
    296264
    297     /* Found nothing? */
    298     if (!pItem)
    299     {
    300         setCurrentItem(0);
    301         return;
    302     }
    303 
    304     /* Select desired item: */
    305     if (navigationList().contains(pItem))
     265    /* Some item found? */
     266    if (pItem)
     267    {
     268        /* This item should be in navigation list: */
     269        AssertMsg(navigationList().contains(pItem),
     270                  ("Passed item is NOT in navigation list!"));
     271        /* Make this item current: */
    306272        setCurrentItem(pItem);
    307     else
    308         setCurrentItem(0);
     273    }
    309274}
    310275
     
    345310    /* Notify listeners about selection change: */
    346311    emit sigSelectionChanged();
    347 }
    348 
    349 void UIGChooserModel::activate()
    350 {
    351     gActionPool->action(UIActionIndexSelector_State_Common_StartOrShow)->activate(QAction::Trigger);
    352312}
    353313
     
    553513{
    554514    updateGroupTree(mainRoot());
     515}
     516
     517void UIGChooserModel::activate()
     518{
     519    gActionPool->action(UIActionIndexSelector_State_Common_StartOrShow)->activate(QAction::Trigger);
    555520}
    556521
     
    12351200    updateNavigation();
    12361201    updateLayout();
    1237     if (mainRoot()->hasItems())
     1202
     1203    /* Load last selected item (choose first if unable to load): */
     1204    setCurrentItem(vboxGlobal().virtualBox().GetExtraData(GUI_LastItemSelected));
     1205    if (!currentItem() && !navigationList().isEmpty())
    12381206        setCurrentItem(0);
    1239     else
    1240         unsetCurrentItem();
    12411207}
    12421208
    12431209void UIGChooserModel::cleanupGroupTree()
    12441210{
     1211    /* Save last selected item: */
     1212    vboxGlobal().virtualBox().SetExtraData(GUI_LastItemSelected,
     1213                                           currentItem() ? currentItem()->definition() : QString());
     1214
    12451215    /* Currently we are not saving group descriptors
    12461216     * (which reflecting group toggle-state) on-the-fly
  • trunk/src/VBox/Frontends/VirtualBox/src/selector/graphics/chooser/UIGChooserModel.h

    r43539 r43540  
    111111    /* API: Current-item stuff: */
    112112    UIVMItem* currentMachineItem() const;
    113     QString currentItemDefinition() const;
    114113    QList<UIVMItem*> currentMachineItems() const;
    115114    UIGChooserItem* currentItem() const;
     
    117116    void setCurrentItem(int iItemIndex);
    118117    void setCurrentItem(UIGChooserItem *pItem);
    119     void setCurrentItemDefinition(const QString &strDefinition);
     118    void setCurrentItem(const QString &strDefinition);
    120119    void unsetCurrentItem();
    121120    void addToCurrentItems(UIGChooserItem *pItem);
     
    123122    void clearSelectionList();
    124123    void notifyCurrentItemChanged();
    125     void activate();
    126124    bool isSingleGroupSelected() const;
    127125    bool isAllItemsOfOneGroupSelected() const;
     
    142140    void startEditing();
    143141    void updateGroupTree();
     142
     143    /* API: Machine-item stuff: */
     144    void activate();
    144145
    145146    /* API: Drag&drop stuff: */
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