VirtualBox

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


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

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

    r65678 r65686  
    181181UIGlobalSettingsLanguage::UIGlobalSettingsLanguage()
    182182    : m_fPolished(false)
    183     , m_fIsLanguageChanged(false)
    184183{
    185184    /* Apply UI decorations: */
     
    210209    UISettingsPageGlobal::fetchData(data);
    211210
    212     /* Load to cache: */
    213     m_cache.m_strLanguageId = m_settings.languageId();
     211    /* Clear cache initially: */
     212    m_cache.clear();
     213
     214    /* Prepare old data: */
     215    UIDataSettingsGlobalLanguage oldData;
     216
     217    /* Gather old data: */
     218    oldData.m_strLanguageId = m_settings.languageId();
     219
     220    /* Cache old data: */
     221    m_cache.cacheInitialData(oldData);
    214222
    215223    /* Upload properties & settings to data: */
     
    219227void UIGlobalSettingsLanguage::getFromCache()
    220228{
    221     /* Fetch from cache: */
    222     reload(m_cache.m_strLanguageId);
     229    /* Get old data from cache: */
     230    const UIDataSettingsGlobalLanguage &oldData = m_cache.base();
     231
     232    /* Load old data from cache: */
     233    reload(oldData.m_strLanguageId);
    223234}
    224235
    225236void UIGlobalSettingsLanguage::putToCache()
    226237{
    227     /* Upload to cache: */
     238    /* Prepare new data: */
     239    UIDataSettingsGlobalLanguage newData = m_cache.base();
     240
     241    /* Gather new data: */
    228242    QTreeWidgetItem *pCurrentItem = m_pLanguageTree->currentItem();
    229243    Assert(pCurrentItem);
    230244    if (pCurrentItem)
    231         m_cache.m_strLanguageId = pCurrentItem->text(1);
     245        newData.m_strLanguageId = pCurrentItem->text(1);
     246
     247    /* Cache new data: */
     248    m_cache.cacheCurrentData(newData);
    232249}
    233250
     
    239256    UISettingsPageGlobal::fetchData(data);
    240257
    241     /* Save from cache: */
    242     if (m_fIsLanguageChanged)
    243         m_settings.setLanguageId(m_cache.m_strLanguageId);
     258    /* Save new data from cache: */
     259    if (m_cache.wasChanged())
     260    {
     261        /* Save from cache: */
     262        if (m_cache.data().m_strLanguageId != m_cache.base().m_strLanguageId)
     263            m_settings.setLanguageId(m_cache.data().m_strLanguageId);
     264    }
    244265
    245266    /* Upload properties & settings to data: */
     
    339360    m_pLanguageTree->sortItems(0, Qt::AscendingOrder);
    340361    m_pLanguageTree->scrollToItem(pItem);
    341     m_fIsLanguageChanged = false;
    342362}
    343363
     
    373393                             .arg(tr("Author(s):"))
    374394                             .arg(pItem->text(3)));
    375 
    376     m_fIsLanguageChanged = true;
    377 }
    378 
     395}
     396
  • trunk/src/VBox/Frontends/VirtualBox/src/settings/global/UIGlobalSettingsLanguage.h

    r65678 r65686  
    2424
    2525
    26 /** Global settings: Language page cache structure. */
    27 struct UISettingsCacheGlobalLanguage
     26/** Global settings: Language page data structure. */
     27struct UIDataSettingsGlobalLanguage
    2828{
     29    /** Constructs data. */
     30    UIDataSettingsGlobalLanguage()
     31        : m_strLanguageId(QString())
     32    {}
     33
     34    /** Returns whether the @a other passed data is equal to this one. */
     35    bool equal(const UIDataSettingsGlobalLanguage &other) const
     36    {
     37        return true
     38               && (m_strLanguageId == other.m_strLanguageId)
     39               ;
     40    }
     41
     42    /** Returns whether the @a other passed data is equal to this one. */
     43    bool operator==(const UIDataSettingsGlobalLanguage &other) const { return equal(other); }
     44    /** Returns whether the @a other passed data is different from this one. */
     45    bool operator!=(const UIDataSettingsGlobalLanguage &other) const { return !equal(other); }
     46
    2947    /** Holds the current language id. */
    3048    QString m_strLanguageId;
    3149};
     50typedef UISettingsCache<UIDataSettingsGlobalLanguage> UISettingsCacheGlobalLanguage;
    3251
    3352
     
    83102    /* Variables: */
    84103    bool m_fPolished;
    85     bool m_fIsLanguageChanged;
    86104
    87105    /* Cache: */
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