Changeset 65701 in vbox for trunk/src/VBox/Frontends
- Timestamp:
- Feb 9, 2017 2:54:41 PM (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VirtualBox/src/settings/global/UIGlobalSettingsInput.cpp
r65685 r65701 147 147 bool operator==(const UIDataShortcutRow &other) const 148 148 { 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 ; 151 154 } 152 155 … … 297 300 298 301 302 /** Global settings: Input page: Shortcut search functor. */ 303 class UIFunctorFindShortcut 304 { 305 public: 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 343 private: 344 345 /** Holds the search match level. */ 346 const UIMatchLevel m_enmMatchLevel; 347 }; 348 349 299 350 /* A model representing hot-key combination table: */ 300 351 class UIHotKeyTableModel : public QAbstractTableModel … … 436 487 { 437 488 /* Search for corresponding cache item index: */ 438 int iIndexOfCacheItem = shortcuts.indexOf(item);489 int iIndexOfCacheItem = UIFunctorFindShortcut(UIFunctorFindShortcut::Base)(shortcuts, item); 439 490 /* Make sure index is valid: */ 440 491 if (iIndexOfCacheItem == -1) … … 639 690 /* Set sequence to shortcut: */ 640 691 UIDataShortcutRow &filteredShortcut = m_filteredShortcuts[iIndex]; 641 int iShortcutIndex = m_shortcuts.indexOf(filteredShortcut);692 int iShortcutIndex = UIFunctorFindShortcut(UIFunctorFindShortcut::Base)(m_shortcuts, filteredShortcut); 642 693 if (iShortcutIndex != -1) 643 694 { … … 667 718 /* Make sure host-combo item is always the first one: */ 668 719 UIDataShortcutRow fakeHostComboItem(0, UIHostCombo::hostComboCacheKey(), QString(), QString(), QString()); 669 int iIndexOfHostComboItem = m_shortcuts.indexOf(fakeHostComboItem);720 int iIndexOfHostComboItem = UIFunctorFindShortcut(UIFunctorFindShortcut::Base)(m_shortcuts, fakeHostComboItem); 670 721 if (iIndexOfHostComboItem != -1) 671 722 { … … 952 1003 UISettingsPageGlobal::fetchData(data); 953 1004 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 use957 // either for "index-match" (to just find shortcut item independent on parameters) or for958 // "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" functor960 // 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 != -1967 //&& iIndexOfHostComboItemData != iIndexOfHostComboItemBase968 )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 981 1005 /* Save new data from cache: */ 982 1006 if (m_pCache->wasChanged()) 983 1007 { 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 984 1027 /* Save other things from cache: */ 985 1028 if (m_pCache->data().autoCapture() != m_pCache->base().autoCapture())
Note:
See TracChangeset
for help on using the changeset viewer.