VirtualBox

Changeset 65681 in vbox


Ignore:
Timestamp:
Feb 8, 2017 2:42:11 PM (8 years ago)
Author:
vboxsync
Message:

FE/Qt: Global preferences: Display 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/UIGlobalSettingsDisplay.cpp

    r65678 r65681  
    5353    UISettingsPageGlobal::fetchData(data);
    5454
    55     /* Load to cache: */
    56     m_cache.m_strMaxGuestResolution = m_settings.maxGuestRes();
    57     m_cache.m_fActivateHoveredMachineWindow = gEDataManager->activateHoveredMachineWindow();
     55    /* Clear cache initially: */
     56    m_cache.clear();
     57
     58    /* Prepare old data: */
     59    UIDataSettingsGlobalDisplay oldData;
     60
     61    /* Gather old data: */
     62    oldData.m_strMaxGuestResolution = m_settings.maxGuestRes();
     63    oldData.m_fActivateHoveredMachineWindow = gEDataManager->activateHoveredMachineWindow();
     64
     65    /* Cache old data: */
     66    m_cache.cacheInitialData(oldData);
    5867
    5968    /* Upload properties & settings to data: */
     
    6372void UIGlobalSettingsDisplay::getFromCache()
    6473{
    65     /* Fetch from cache: */
    66     if ((m_cache.m_strMaxGuestResolution.isEmpty()) ||
    67         (m_cache.m_strMaxGuestResolution == "auto"))
     74    /* Get old data from cache: */
     75    const UIDataSettingsGlobalDisplay &oldData = m_cache.base();
     76
     77    /* Load old data from cache: */
     78    if ((oldData.m_strMaxGuestResolution.isEmpty()) ||
     79        (oldData.m_strMaxGuestResolution == "auto"))
    6880    {
    6981        /* Switch combo-box item: */
    7082        m_pMaxResolutionCombo->setCurrentIndex(m_pMaxResolutionCombo->findData("auto"));
    7183    }
    72     else if (m_cache.m_strMaxGuestResolution == "any")
     84    else if (oldData.m_strMaxGuestResolution == "any")
    7385    {
    7486        /* Switch combo-box item: */
     
    8092        m_pMaxResolutionCombo->setCurrentIndex(m_pMaxResolutionCombo->findData("fixed"));
    8193        /* Trying to parse text into 2 sections by ',' symbol: */
    82         int iWidth  = m_cache.m_strMaxGuestResolution.section(',', 0, 0).toInt();
    83         int iHeight = m_cache.m_strMaxGuestResolution.section(',', 1, 1).toInt();
     94        int iWidth  = oldData.m_strMaxGuestResolution.section(',', 0, 0).toInt();
     95        int iHeight = oldData.m_strMaxGuestResolution.section(',', 1, 1).toInt();
    8496        /* And set values if they are present: */
    8597        m_pResolutionWidthSpin->setValue(iWidth);
    8698        m_pResolutionHeightSpin->setValue(iHeight);
    8799    }
    88     m_pCheckBoxActivateOnMouseHover->setChecked(m_cache.m_fActivateHoveredMachineWindow);
     100    m_pCheckBoxActivateOnMouseHover->setChecked(oldData.m_fActivateHoveredMachineWindow);
    89101}
    90102
    91103void UIGlobalSettingsDisplay::putToCache()
    92104{
    93     /* Upload to cache: */
     105    /* Prepare new data: */
     106    UIDataSettingsGlobalDisplay newData = m_cache.base();
     107
     108    /* Gather new data: */
    94109    if (m_pMaxResolutionCombo->itemData(m_pMaxResolutionCombo->currentIndex()).toString() == "auto")
    95110    {
    96111        /* If resolution current combo item is "auto" => resolution set to "auto": */
    97         m_cache.m_strMaxGuestResolution = QString();
     112        newData.m_strMaxGuestResolution = QString();
    98113    }
    99114    else if (m_pMaxResolutionCombo->itemData(m_pMaxResolutionCombo->currentIndex()).toString() == "any" ||
     
    102117        /* Else if resolution current combo item is "any"
    103118         * or any of the resolution field attributes is zero => resolution set to "any": */
    104         m_cache.m_strMaxGuestResolution = "any";
     119        newData.m_strMaxGuestResolution = "any";
    105120    }
    106121    else if (m_pResolutionWidthSpin->value() != 0 && m_pResolutionHeightSpin->value() != 0)
    107122    {
    108123        /* Else if both field attributes are non-zeroes => resolution set to "fixed": */
    109         m_cache.m_strMaxGuestResolution = QString("%1,%2").arg(m_pResolutionWidthSpin->value()).arg(m_pResolutionHeightSpin->value());
    110     }
    111     m_cache.m_fActivateHoveredMachineWindow = m_pCheckBoxActivateOnMouseHover->isChecked();
     124        newData.m_strMaxGuestResolution = QString("%1,%2").arg(m_pResolutionWidthSpin->value()).arg(m_pResolutionHeightSpin->value());
     125    }
     126    newData.m_fActivateHoveredMachineWindow = m_pCheckBoxActivateOnMouseHover->isChecked();
     127
     128    /* Cache new data: */
     129    m_cache.cacheCurrentData(newData);
    112130}
    113131
     
    117135    UISettingsPageGlobal::fetchData(data);
    118136
    119     /* Save from cache: */
    120     m_settings.setMaxGuestRes(m_cache.m_strMaxGuestResolution);
    121     gEDataManager->setActivateHoveredMachineWindow(m_cache.m_fActivateHoveredMachineWindow);
     137    /* Save new data from cache: */
     138    if (m_cache.wasChanged())
     139    {
     140        if (m_cache.data().m_strMaxGuestResolution != m_cache.base().m_strMaxGuestResolution)
     141            m_settings.setMaxGuestRes(m_cache.data().m_strMaxGuestResolution);
     142        if (m_cache.data().m_fActivateHoveredMachineWindow != m_cache.base().m_fActivateHoveredMachineWindow)
     143            gEDataManager->setActivateHoveredMachineWindow(m_cache.data().m_fActivateHoveredMachineWindow);
     144    }
    122145
    123146    /* Upload properties & settings to data: */
  • trunk/src/VBox/Frontends/VirtualBox/src/settings/global/UIGlobalSettingsDisplay.h

    r65678 r65681  
    2424
    2525
    26 /** Global settings: Display page cache structure. */
    27 struct UISettingsCacheGlobalDisplay
     26/** Global settings: Display page data structure. */
     27struct UIDataSettingsGlobalDisplay
    2828{
     29    /** Constructs data. */
     30    UIDataSettingsGlobalDisplay()
     31        : m_strMaxGuestResolution(QString())
     32        , m_fActivateHoveredMachineWindow(false)
     33    {}
     34
     35    /** Returns whether the @a other passed data is equal to this one. */
     36    bool equal(const UIDataSettingsGlobalDisplay &other) const
     37    {
     38        return true
     39               && (m_strMaxGuestResolution == other.m_strMaxGuestResolution)
     40               && (m_fActivateHoveredMachineWindow == other.m_fActivateHoveredMachineWindow)
     41               ;
     42    }
     43
     44    /** Returns whether the @a other passed data is equal to this one. */
     45    bool operator==(const UIDataSettingsGlobalDisplay &other) const { return equal(other); }
     46    /** Returns whether the @a other passed data is different from this one. */
     47    bool operator!=(const UIDataSettingsGlobalDisplay &other) const { return !equal(other); }
     48
    2949    /** Holds the maximum guest resolution or preset name. */
    3050    QString m_strMaxGuestResolution;
     
    3252    bool m_fActivateHoveredMachineWindow;
    3353};
     54typedef UISettingsCache<UIDataSettingsGlobalDisplay> UISettingsCacheGlobalDisplay;
    3455
    3556
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