VirtualBox

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


Ignore:
Timestamp:
Feb 8, 2017 3:55:22 PM (8 years ago)
Author:
vboxsync
Message:

FE/Qt: Global preferences: Input page: Integrate settings caching.

Location:
trunk/src/VBox/Frontends/VirtualBox/src/settings/global
Files:
2 edited

Legend:

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

    r65679 r65685  
    5454
    5555
    56 /** Global settings: Input page: Shortcut cell cache structure. */
    57 class UIShortcutCacheCell : public QITableViewCell
     56/** Global settings: Input page: Shortcut cell data structure. */
     57class UIDataShortcutCell : public QITableViewCell
    5858{
    5959    Q_OBJECT;
     
    6464      * @param  pParent  Brings the row this cell belongs too.
    6565      * @param  strText  Brings the text describing this cell. */
    66     UIShortcutCacheCell(QITableViewRow *pParent, const QString &strText)
     66    UIDataShortcutCell(QITableViewRow *pParent, const QString &strText)
    6767        : QITableViewCell(pParent)
    6868        , m_strText(strText)
     
    7979
    8080
    81 /** Global settings: Input page: Shortcut cache structure. */
    82 class UIShortcutCacheRow : public QITableViewRow
     81/** Global settings: Input page: Shortcut data structure. */
     82class UIDataShortcutRow : public QITableViewRow
    8383{
    8484    Q_OBJECT;
     
    9292      * @param  strCurrentSequence  Brings the current held sequence.
    9393      * @param  strDefaultSequence  Brings the default held sequence. */
    94     UIShortcutCacheRow(QITableView *pParent,
     94    UIDataShortcutRow(QITableView *pParent,
    9595                       const QString &strKey,
    9696                       const QString &strDescription,
     
    108108
    109109    /** Constructs table row on the basis of @a other one. */
    110     UIShortcutCacheRow(const UIShortcutCacheRow &other)
     110    UIDataShortcutRow(const UIDataShortcutRow &other)
    111111        : QITableViewRow(other.table())
    112112        , m_strKey(other.key())
     
    120120
    121121    /** Destructs table row. */
    122     ~UIShortcutCacheRow()
     122    ~UIDataShortcutRow()
    123123    {
    124124        /* Destroy cells: */
     
    127127
    128128    /** Copies a table row from @a other one. */
    129     UIShortcutCacheRow &operator=(const UIShortcutCacheRow &other)
     129    UIDataShortcutRow &operator=(const UIDataShortcutRow &other)
    130130    {
    131131        /* Reassign variables: */
     
    145145
    146146    /** Returns whether this row equals to @a other. */
    147     bool operator==(const UIShortcutCacheRow &other) const
     147    bool operator==(const UIDataShortcutRow &other) const
    148148    {
    149149        /* Compare by the key only: */
     
    189189    {
    190190        /* Create cells on the basis of description and current sequence: */
    191         m_cells = qMakePair(new UIShortcutCacheCell(this, m_strDescription),
    192                             new UIShortcutCacheCell(this, m_strCurrentSequence));
     191        m_cells = qMakePair(new UIDataShortcutCell(this, m_strDescription),
     192                            new UIDataShortcutCell(this, m_strCurrentSequence));
    193193    }
    194194
     
    213213
    214214    /** Holds the cell instances. */
    215     QPair<UIShortcutCacheCell*, UIShortcutCacheCell*> m_cells;
     215    QPair<UIDataShortcutCell*, UIDataShortcutCell*> m_cells;
    216216};
    217 typedef QList<UIShortcutCacheRow> UIShortcutCache;
    218 
    219 
    220 /** Global settings: Input page cache structure. */
    221 class UISettingsCacheGlobalInput
     217typedef QList<UIDataShortcutRow> UIShortcutCache;
     218
     219
     220/** Global settings: Input page data structure. */
     221class UIDataSettingsGlobalInput
    222222{
    223223public:
    224224
    225225    /** Constructs cache. */
    226     UISettingsCacheGlobalInput()
     226    UIDataSettingsGlobalInput()
    227227        : m_fAutoCapture(false)
    228228    {}
     
    230230    /** Returns the shortcuts cache [full access]. */
    231231    UIShortcutCache &shortcuts() { return m_shortcuts; }
     232    /** Returns the shortcuts cache [read-only access]. */
     233    const UIShortcutCache &shortcuts() const { return m_shortcuts; }
    232234
    233235    /** Defines whether the keyboard auto-capture is @a fEnabled. */
     
    235237    /** Returns whether the keyboard auto-capture is enabled. */
    236238    bool autoCapture() const { return m_fAutoCapture; }
     239
     240    /** Returns whether the @a other passed data is equal to this one. */
     241    bool equal(const UIDataSettingsGlobalInput &other) const
     242    {
     243        return (m_shortcuts == other.m_shortcuts) &&
     244               (m_fAutoCapture == other.m_fAutoCapture);
     245    }
     246
     247    /** Returns whether the @a other passed data is equal to this one. */
     248    bool operator==(const UIDataSettingsGlobalInput &other) const { return equal(other); }
     249    /** Returns whether the @a other passed data is different from this one. */
     250    bool operator!=(const UIDataSettingsGlobalInput &other) const { return !equal(other); }
    237251
    238252private:
     
    261275    /** Returns whether the @a item1 is more/less than the @a item2.
    262276      * @note  Order depends on the one set through constructor, stored in m_order. */
    263     bool operator()(const UIShortcutCacheRow &item1, const UIShortcutCacheRow &item2)
     277    bool operator()(const UIDataShortcutRow &item1, const UIDataShortcutRow &item2)
    264278    {
    265279        switch (m_iColumn)
     
    401415{
    402416    /* Load shortcuts: */
    403     foreach (const UIShortcutCacheRow &item, shortcuts)
     417    foreach (const UIDataShortcutRow &item, shortcuts)
    404418    {
    405419        /* Filter out unnecessary shortcuts: */
     
    419433{
    420434    /* Save model items: */
    421     foreach (const UIShortcutCacheRow &item, m_shortcuts)
     435    foreach (const UIDataShortcutRow &item, m_shortcuts)
    422436    {
    423437        /* Search for corresponding cache item index: */
     
    435449    /* Enumerate all the sequences: */
    436450    QMap<QString, QString> usedSequences;
    437     foreach (const UIShortcutCacheRow &item, m_shortcuts)
     451    foreach (const UIDataShortcutRow &item, m_shortcuts)
    438452        if (!item.currentSequence().isEmpty())
    439453            usedSequences.insertMulti(item.currentSequence(), item.key());
     
    624638                    int iIndex = index.row();
    625639                    /* Set sequence to shortcut: */
    626                     UIShortcutCacheRow &filteredShortcut = m_filteredShortcuts[iIndex];
     640                    UIDataShortcutRow &filteredShortcut = m_filteredShortcuts[iIndex];
    627641                    int iShortcutIndex = m_shortcuts.indexOf(filteredShortcut);
    628642                    if (iShortcutIndex != -1)
     
    652666    qStableSort(m_shortcuts.begin(), m_shortcuts.end(), UIShortcutCacheItemFunctor(iColumn, order));
    653667    /* Make sure host-combo item is always the first one: */
    654     UIShortcutCacheRow fakeHostComboItem(0, UIHostCombo::hostComboCacheKey(), QString(), QString(), QString());
     668    UIDataShortcutRow fakeHostComboItem(0, UIHostCombo::hostComboCacheKey(), QString(), QString(), QString());
    655669    int iIndexOfHostComboItem = m_shortcuts.indexOf(fakeHostComboItem);
    656670    if (iIndexOfHostComboItem != -1)
    657671    {
    658         UIShortcutCacheRow hostComboItem = m_shortcuts.takeAt(iIndexOfHostComboItem);
     672        UIDataShortcutRow hostComboItem = m_shortcuts.takeAt(iIndexOfHostComboItem);
    659673        m_shortcuts.prepend(hostComboItem);
    660674    }
     
    684698    {
    685699        /* Check if the description matches the filter: */
    686         foreach (const UIShortcutCacheRow &item, m_shortcuts)
     700        foreach (const UIDataShortcutRow &item, m_shortcuts)
    687701        {
    688702            /* If neither description nor sequence matches the filter, skip item: */
     
    876890    UISettingsPageGlobal::fetchData(data);
    877891
    878     /* Load to cache: */
    879     m_pCache->shortcuts() << UIShortcutCacheRow(m_pMachineTable, UIHostCombo::hostComboCacheKey(), tr("Host Key Combination"),  m_settings.hostCombo(), QString());
    880     const QMap<QString, UIShortcut>& shortcuts = gShortcutPool->shortcuts();
     892    /* Clear cache initially: */
     893    m_pCache->clear();
     894
     895    /* Prepare old data: */
     896    UIDataSettingsGlobalInput oldData;
     897
     898    /* Gather old data: */
     899    oldData.shortcuts() << UIDataShortcutRow(m_pMachineTable, UIHostCombo::hostComboCacheKey(), tr("Host Key Combination"),  m_settings.hostCombo(), QString());
     900    const QMap<QString, UIShortcut> &shortcuts = gShortcutPool->shortcuts();
    881901    const QList<QString> shortcutKeys = shortcuts.keys();
    882902    foreach (const QString &strShortcutKey, shortcutKeys)
     
    886906                               strShortcutKey.startsWith(GUI_Input_SelectorShortcuts) ? m_pSelectorTable : 0;
    887907        AssertPtr(pParent);
    888         m_pCache->shortcuts() << UIShortcutCacheRow(pParent, strShortcutKey, VBoxGlobal::removeAccelMark(shortcut.description()),
    889                                                     shortcut.sequence().toString(QKeySequence::NativeText),
    890                                                     shortcut.defaultSequence().toString(QKeySequence::NativeText));
    891     }
    892     m_pCache->setAutoCapture(m_settings.autoCapture());
     908        oldData.shortcuts() << UIDataShortcutRow(pParent, strShortcutKey, VBoxGlobal::removeAccelMark(shortcut.description()),
     909                                                 shortcut.sequence().toString(QKeySequence::NativeText),
     910                                                 shortcut.defaultSequence().toString(QKeySequence::NativeText));
     911    }
     912    oldData.setAutoCapture(m_settings.autoCapture());
     913
     914    /* Cache old data: */
     915    m_pCache->cacheInitialData(oldData);
    893916
    894917    /* Upload properties & settings to data: */
     
    898921void UIGlobalSettingsInput::getFromCache()
    899922{
    900     /* Fetch from cache: */
    901     m_pSelectorModel->load(m_pCache->shortcuts());
    902     m_pMachineModel->load(m_pCache->shortcuts());
    903     m_pEnableAutoGrabCheckbox->setChecked(m_pCache->autoCapture());
     923    /* Get old data from cache: */
     924    const UIDataSettingsGlobalInput &oldData = m_pCache->base();
     925
     926    /* Load old data from cache: */
     927    m_pSelectorModel->load(oldData.shortcuts());
     928    m_pMachineModel->load(oldData.shortcuts());
     929    m_pEnableAutoGrabCheckbox->setChecked(oldData.autoCapture());
    904930
    905931    /* Revalidate: */
     
    909935void UIGlobalSettingsInput::putToCache()
    910936{
    911     /* Upload to cache: */
    912     m_pSelectorModel->save(m_pCache->shortcuts());
    913     m_pMachineModel->save(m_pCache->shortcuts());
    914     m_pCache->setAutoCapture(m_pEnableAutoGrabCheckbox->isChecked());
     937    /* Prepare new data: */
     938    UIDataSettingsGlobalInput newData = m_pCache->base();
     939
     940    /* Gather new data: */
     941    m_pSelectorModel->save(newData.shortcuts());
     942    m_pMachineModel->save(newData.shortcuts());
     943    newData.setAutoCapture(m_pEnableAutoGrabCheckbox->isChecked());
     944
     945    /* Cache new data: */
     946    m_pCache->cacheCurrentData(newData);
    915947}
    916948
     
    920952    UISettingsPageGlobal::fetchData(data);
    921953
    922     /* Save from cache: */
    923     UIShortcutCacheRow fakeHostComboItem(0, UIHostCombo::hostComboCacheKey(), QString(), QString(), QString());
    924     int iIndexOfHostComboItem = m_pCache->shortcuts().indexOf(fakeHostComboItem);
    925     if (iIndexOfHostComboItem != -1)
    926         m_settings.setHostCombo(m_pCache->shortcuts()[iIndexOfHostComboItem].currentSequence());
    927     QMap<QString, QString> sequences;
    928     foreach (const UIShortcutCacheRow &item, m_pCache->shortcuts())
    929         sequences.insert(item.key(), item.currentSequence());
    930     gShortcutPool->setOverrides(sequences);
    931     m_settings.setAutoCapture(m_pCache->autoCapture());
     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
     981    /* Save new data from cache: */
     982    if (m_pCache->wasChanged())
     983    {
     984        /* Save other things from cache: */
     985        if (m_pCache->data().autoCapture() != m_pCache->base().autoCapture())
     986            m_settings.setAutoCapture(m_pCache->data().autoCapture());
     987    }
    932988
    933989    /* Upload properties & settings to data: */
     
    9641020}
    9651021
    966 /* Navigation stuff: */
    9671022void UIGlobalSettingsInput::setOrderAfter(QWidget *pWidget)
    9681023{
     
    9711026}
    9721027
    973 /* Translation stuff: */
    9741028void UIGlobalSettingsInput::retranslateUi()
    9751029{
  • trunk/src/VBox/Frontends/VirtualBox/src/settings/global/UIGlobalSettingsInput.h

    r65679 r65685  
    2626class QTabWidget;
    2727class QLineEdit;
    28 class UISettingsCacheGlobalInput;
     28class UIDataSettingsGlobalInput;
    2929class UIHotKeyTableModel;
    3030class UIHotKeyTable;
     31typedef UISettingsCache<UIDataSettingsGlobalInput> UISettingsCacheGlobalInput;
    3132
    3233
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