VirtualBox

Changeset 84376 in vbox for trunk/src


Ignore:
Timestamp:
May 19, 2020 5:57:56 PM (5 years ago)
Author:
vboxsync
Message:

FE/Qt: bugref:9653: VirtualBox Manager: Chooser pane: Unify extra-data chooser node definitions in one place for reusing.

Location:
trunk/src/VBox/Frontends/VirtualBox/src/manager/chooser
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VirtualBox/src/manager/chooser/UIChooserAbstractModel.cpp

    r84373 r84376  
    314314{
    315315    return uId.toString().remove(QRegExp("[{}]"));
     316}
     317
     318/* static */
     319QString UIChooserAbstractModel::definitionOption(NodeDef enmOption)
     320{
     321    switch (enmOption)
     322    {
     323        /* Global nodes: */
     324        case NodeDef_GlobalPrefix:         return "n";
     325        case NodeDef_GlobalOptionFavorite: return "f";
     326        case NodeDef_GlobalValueDefault:   return "GLOBAL";
     327        /* Machine nodes: */
     328        case NodeDef_MachinePrefix:        return "m";
     329        /* Group nodes: */
     330        case NodeDef_GroupPrefix:          return "g";
     331        case NodeDef_GroupOptionOpened:    return "o";
     332    }
     333    return QString();
    316334}
    317335
     
    699717
    700718    /* Prepare required group definition reg-exp: */
    701     const QString strDefinitionTemplate = QString("g(\\S)*=%1").arg(strName);
     719    const QString strNodePrefix = definitionOption(NodeDef_GroupPrefix);
     720    const QString strNodeOptionOpened = definitionOption(NodeDef_GroupOptionOpened);
     721    const QString strDefinitionTemplate = QString("%1(\\S)*=%2").arg(strNodePrefix, strName);
    702722    const QRegExp definitionRegExp(strDefinitionTemplate);
    703723    /* For each the group definition: */
     
    709729            /* Get group descriptor: */
    710730            const QString strDescriptor(definitionRegExp.cap(1));
    711             if (strDescriptor.contains('o'))
     731            if (strDescriptor.contains(strNodeOptionOpened))
    712732                return true;
    713733        }
     
    744764
    745765    /* Prepare required group definition reg-exp: */
    746     const QString strDefinitionTemplate = QString("n(\\S)*=GLOBAL");
    747     const QRegExp definitionRegExp = QRegExp(strDefinitionTemplate);
     766    const QString strNodePrefix = definitionOption(NodeDef_GlobalPrefix);
     767    const QString strNodeOptionFavorite = definitionOption(NodeDef_GlobalOptionFavorite);
     768    const QString strNodeValueDefault = definitionOption(NodeDef_GlobalValueDefault);
     769    const QString strDefinitionTemplate = QString("%1(\\S)*=%2").arg(strNodePrefix, strNodeValueDefault);
     770    const QRegExp definitionRegExp(strDefinitionTemplate);
    748771    /* For each the group definition: */
    749772    foreach (const QString &strDefinition, definitions)
     
    754777            /* Get group descriptor: */
    755778            const QString strDescriptor(definitionRegExp.cap(1));
    756             if (strDescriptor.contains('f'))
     779            if (strDescriptor.contains(strNodeOptionFavorite))
    757780                return true;
    758781        }
  • trunk/src/VBox/Frontends/VirtualBox/src/manager/chooser/UIChooserAbstractModel.h

    r84186 r84376  
    6565public:
    6666
     67    /** Extra-data node definition option types. */
     68    enum NodeDef
     69    {
     70        NodeDef_GlobalPrefix,
     71        NodeDef_GlobalOptionFavorite,
     72        NodeDef_GlobalValueDefault,
     73        NodeDef_MachinePrefix,
     74        NodeDef_GroupPrefix,
     75        NodeDef_GroupOptionOpened,
     76    };
     77
    6778    /** Constructs abstract Chooser-model passing @a pParent to the base-class. */
    6879    UIChooserAbstractModel(UIChooser *pParent);
     
    109120          * @note  Required for backward compatibility after QString=>QUuid change. */
    110121        static QString toOldStyleUuid(const QUuid &uId);
     122
     123        /** Returns extra-data node definition option of certain @a enmType. */
     124        static QString definitionOption(NodeDef enmType);
    111125    /** @} */
    112126
  • trunk/src/VBox/Frontends/VirtualBox/src/manager/chooser/UIChooserModel.cpp

    r84371 r84376  
    222222    const QString strItemDescriptor = strDefinition.section('=', 1, -1);
    223223    /* Its a group-item definition? */
    224     if (strItemType == "g")
     224    if (strItemType == definitionOption(NodeDef_GroupPrefix))
    225225    {
    226226        /* Search for group-item with passed descriptor (name): */
     
    232232    }
    233233    /* Its a global-item definition? */
    234     else if (strItemType == "n")
     234    else if (strItemType == definitionOption(NodeDef_GlobalPrefix))
    235235    {
    236236        /* Search for global-item with required name: */
     
    240240    }
    241241    /* Its a machine-item definition? */
    242     else if (strItemType == "m")
     242    else if (strItemType == definitionOption(NodeDef_MachinePrefix))
    243243    {
    244244        /* Search for machine-item with required ID: */
  • trunk/src/VBox/Frontends/VirtualBox/src/manager/chooser/UIChooserNodeGlobal.cpp

    r84373 r84376  
    1717
    1818/* GUI includes: */
     19#include "UIChooserAbstractModel.h"
    1920#include "UIChooserNodeGlobal.h"
    2021
     
    7778QString UIChooserNodeGlobal::definition(bool fFull /* = false */) const
    7879{
     80    const QString strNodePrefix = UIChooserAbstractModel::definitionOption(UIChooserAbstractModel::NodeDef_GlobalPrefix);
     81    const QString strNodeOptionFavorite = UIChooserAbstractModel::definitionOption(UIChooserAbstractModel::NodeDef_GlobalOptionFavorite);
     82    const QString strNodeValueDefault = UIChooserAbstractModel::definitionOption(UIChooserAbstractModel::NodeDef_GlobalValueDefault);
    7983    return   fFull
    80            ? QString("n%1=%2").arg(isFavorite() ? "f" : "").arg("GLOBAL")
    81            : QString("n=%1").arg("GLOBAL");
     84           ? QString("%1%2=%3").arg(strNodePrefix).arg(isFavorite() ? strNodeOptionFavorite : "").arg(strNodeValueDefault)
     85           : QString("%1=%2").arg(strNodePrefix).arg(strNodeValueDefault);
    8286}
    8387
  • trunk/src/VBox/Frontends/VirtualBox/src/manager/chooser/UIChooserNodeGroup.cpp

    r84373 r84376  
    1717
    1818/* GUI includes: */
     19#include "UIChooserAbstractModel.h"
    1920#include "UIChooserNodeGroup.h"
    2021#include "UIChooserNodeGlobal.h"
     
    107108QString UIChooserNodeGroup::definition(bool fFull /* = false */) const
    108109{
     110    const QString strNodePrefix = UIChooserAbstractModel::definitionOption(UIChooserAbstractModel::NodeDef_GroupPrefix);
     111    const QString strNodeOptionOpened = UIChooserAbstractModel::definitionOption(UIChooserAbstractModel::NodeDef_GroupOptionOpened);
    109112    return   fFull
    110            ? QString("g%1=%2").arg(isOpened() ? "o" : "").arg(name())
    111            : QString("g=%1").arg(fullName());
     113           ? QString("%1%2=%3").arg(strNodePrefix).arg(isOpened() ? strNodeOptionOpened : "").arg(name())
     114           : QString("%1=%2").arg(strNodePrefix).arg(fullName());
    112115}
    113116
  • trunk/src/VBox/Frontends/VirtualBox/src/manager/chooser/UIChooserNodeMachine.cpp

    r84373 r84376  
    138138QString UIChooserNodeMachine::definition(bool) const
    139139{
    140     return QString("m=%1").arg(UIChooserAbstractModel::toOldStyleUuid(id()));
     140    const QString strNodePrefix = UIChooserAbstractModel::definitionOption(UIChooserAbstractModel::NodeDef_MachinePrefix);
     141    return QString("%1=%2").arg(strNodePrefix).arg(UIChooserAbstractModel::toOldStyleUuid(id()));
    141142}
    142143
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