VirtualBox

Changeset 65701 in vbox for trunk/src/VBox/Frontends


Ignore:
Timestamp:
Feb 9, 2017 2:54:41 PM (8 years ago)
Author:
vboxsync
Message:

FE/Qt: Global preferences: Input page: Separate shortcut search functor for ease of access; this allowed to make default shortcut comparison full (e.g. to include sequence).

File:
1 edited

Legend:

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

    r65685 r65701  
    147147    bool operator==(const UIDataShortcutRow &other) const
    148148    {
    149         /* Compare by the key only: */
    150         return m_strKey == other.key();
     149        /* Compare by the key and the current sequence: */
     150        return true
     151               && (m_strKey == other.key())
     152               && (m_strCurrentSequence == other.currentSequence())
     153               ;
    151154    }
    152155
     
    297300
    298301
     302/** Global settings: Input page: Shortcut search functor. */
     303class UIFunctorFindShortcut
     304{
     305public:
     306
     307    /** Search match level enumerator. */
     308    enum UIMatchLevel { Base, Full };
     309
     310    /** Constructs shortcut search functor.
     311      * @param  matchLevel  Brings the search match level. */
     312    UIFunctorFindShortcut(UIMatchLevel enmMatchLevel)
     313        : m_enmMatchLevel(enmMatchLevel)
     314    {}
     315
     316    /** Returns the position of the 1st occurrence of the
     317      * @a shortcut in the @a shortcuts list, or -1 otherwise. */
     318    int operator()(const UIShortcutCache &shortcuts, const UIDataShortcutRow &shortcut)
     319    {
     320        for (int i = 0; i < shortcuts.size(); ++i)
     321        {
     322            const UIDataShortcutRow &iteratedShortcut = shortcuts.at(i);
     323            switch (m_enmMatchLevel)
     324            {
     325                case Base:
     326                {
     327                    if (iteratedShortcut.key() == shortcut.key())
     328                        return i;
     329                    break;
     330                }
     331                case Full:
     332                {
     333                    if (   iteratedShortcut.key() == shortcut.key()
     334                        && iteratedShortcut.currentSequence() == shortcut.currentSequence())
     335                        return i;
     336                    break;
     337                }
     338            }
     339        }
     340        return -1;
     341    }
     342
     343private:
     344
     345    /** Holds the search match level. */
     346    const UIMatchLevel m_enmMatchLevel;
     347};
     348
     349
    299350/* A model representing hot-key combination table: */
    300351class UIHotKeyTableModel : public QAbstractTableModel
     
    436487    {
    437488        /* Search for corresponding cache item index: */
    438         int iIndexOfCacheItem = shortcuts.indexOf(item);
     489        int iIndexOfCacheItem = UIFunctorFindShortcut(UIFunctorFindShortcut::Base)(shortcuts, item);
    439490        /* Make sure index is valid: */
    440491        if (iIndexOfCacheItem == -1)
     
    639690                    /* Set sequence to shortcut: */
    640691                    UIDataShortcutRow &filteredShortcut = m_filteredShortcuts[iIndex];
    641                     int iShortcutIndex = m_shortcuts.indexOf(filteredShortcut);
     692                    int iShortcutIndex = UIFunctorFindShortcut(UIFunctorFindShortcut::Base)(m_shortcuts, filteredShortcut);
    642693                    if (iShortcutIndex != -1)
    643694                    {
     
    667718    /* Make sure host-combo item is always the first one: */
    668719    UIDataShortcutRow fakeHostComboItem(0, UIHostCombo::hostComboCacheKey(), QString(), QString(), QString());
    669     int iIndexOfHostComboItem = m_shortcuts.indexOf(fakeHostComboItem);
     720    int iIndexOfHostComboItem = UIFunctorFindShortcut(UIFunctorFindShortcut::Base)(m_shortcuts, fakeHostComboItem);
    670721    if (iIndexOfHostComboItem != -1)
    671722    {
     
    9521003    UISettingsPageGlobal::fetchData(data);
    9531004
    954     // WORKAROUND:
    955     // For now we are using out-of-the-box Qt functions to search for a corresponding shortcuts.
    956     // Those functions assumes that container elements implement operator==() which we can use
    957     // either for "index-match" (to just find shortcut item independent on parameters) or for
    958     // "full-match" (to find exact shortcut item including all parameters) but not for both,
    959     // so since "index-match" is most commonly used, we need separate "full-match" functor
    960     // to check whether the shortcut item was changed, for now we can't do that.
    961 
    962     /* Save host-combo shortcut from cache: */
    963     UIDataShortcutRow fakeHostComboItem(0, UIHostCombo::hostComboCacheKey(), QString(), QString(), QString());
    964     //const int iIndexOfHostComboItemBase = m_pCache->base().shortcuts().indexOf(fakeHostComboItem);
    965     const int iIndexOfHostComboItemData = m_pCache->data().shortcuts().indexOf(fakeHostComboItem);
    966     if (   iIndexOfHostComboItemData != -1
    967         //&& iIndexOfHostComboItemData != iIndexOfHostComboItemBase
    968         )
    969         m_settings.setHostCombo(m_pCache->data().shortcuts().at(iIndexOfHostComboItemData).currentSequence());
    970 
    971     /* Save other shortcut sequences from cache: */
    972     QMap<QString, QString> sequencesBase;
    973     QMap<QString, QString> sequencesData;
    974     foreach (const UIDataShortcutRow &item, m_pCache->base().shortcuts())
    975         sequencesBase.insert(item.key(), item.currentSequence());
    976     foreach (const UIDataShortcutRow &item, m_pCache->data().shortcuts())
    977         sequencesData.insert(item.key(), item.currentSequence());
    978     if (sequencesData != sequencesBase)
    979         gShortcutPool->setOverrides(sequencesData);
    980 
    9811005    /* Save new data from cache: */
    9821006    if (m_pCache->wasChanged())
    9831007    {
     1008        /* Save host-combo shortcut from cache: */
     1009        UIDataShortcutRow fakeHostComboItem(0, UIHostCombo::hostComboCacheKey(), QString(), QString(), QString());
     1010        const int iHostComboItemBase = UIFunctorFindShortcut(UIFunctorFindShortcut::Base)(m_pCache->base().shortcuts(), fakeHostComboItem);
     1011        const int iHostComboItemData = UIFunctorFindShortcut(UIFunctorFindShortcut::Base)(m_pCache->data().shortcuts(), fakeHostComboItem);
     1012        const QString strHostComboBase = iHostComboItemBase != -1 ? m_pCache->base().shortcuts().at(iHostComboItemBase).currentSequence() : QString();
     1013        const QString strHostComboData = iHostComboItemData != -1 ? m_pCache->data().shortcuts().at(iHostComboItemData).currentSequence() : QString();
     1014        if (strHostComboData != strHostComboBase)
     1015            m_settings.setHostCombo(strHostComboData);
     1016
     1017        /* Save other shortcut sequences from cache: */
     1018        QMap<QString, QString> sequencesBase;
     1019        QMap<QString, QString> sequencesData;
     1020        foreach (const UIDataShortcutRow &item, m_pCache->base().shortcuts())
     1021            sequencesBase.insert(item.key(), item.currentSequence());
     1022        foreach (const UIDataShortcutRow &item, m_pCache->data().shortcuts())
     1023            sequencesData.insert(item.key(), item.currentSequence());
     1024        if (sequencesData != sequencesBase)
     1025            gShortcutPool->setOverrides(sequencesData);
     1026
    9841027        /* Save other things from cache: */
    9851028        if (m_pCache->data().autoCapture() != m_pCache->base().autoCapture())
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