Changeset 66611 in vbox
- Timestamp:
- Apr 19, 2017 2:01:30 PM (8 years ago)
- svn:sync-xref-src-repo-rev:
- 114654
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VirtualBox/src/settings/UISettingsDefs.h
r66610 r66611 66 66 /** Returns the NON-modifiable REFERENCE to the current cached data. */ 67 67 const CacheData &data() const { return m_value.second; } 68 /** Returns the modifiable REFERENCE to the initial cached data. */ 69 CacheData &base() { return m_value.first; } 68 70 /** Returns the modifiable REFERENCE to the current cached data. */ 69 71 CacheData &data() { return m_value.second; } … … 174 176 }; 175 177 178 179 /** Template organizing settings object cache with 2 groups of children. */ 180 template <class ParentCacheData, class ChildCacheData1, class ChildCacheData2> class UISettingsCachePoolOfTwo : public UISettingsCache<ParentCacheData> 181 { 182 public: 183 184 /** Group 1 children map. */ 185 typedef QMap<QString, ChildCacheData1> UISettingsCacheChildMap1; 186 /** Group 2 children map. */ 187 typedef QMap<QString, ChildCacheData2> UISettingsCacheChildMap2; 188 /** Group 1 children map iterator. */ 189 typedef QMapIterator<QString, ChildCacheData1> UISettingsCacheChildIterator1; 190 /** Group 2 children map iterator. */ 191 typedef QMapIterator<QString, ChildCacheData2> UISettingsCacheChildIterator2; 192 193 /** Constructs empty cache object. */ 194 UISettingsCachePoolOfTwo() : UISettingsCache<ParentCacheData>() {} 195 196 /** Returns group 1 children count. */ 197 int childCount1() const { return m_children1.size(); } 198 /** Returns the modifiable REFERENCE to the group 1 child cached data. */ 199 ChildCacheData1 &child1(const QString &strChildKey) { return m_children1[strChildKey]; } 200 /** Wraps method above to return the modifiable REFERENCE to the group 1 child cached data. */ 201 ChildCacheData1 &child1(int iIndex) { return child1(indexToKey1(iIndex)); } 202 /** Returns the NON-modifiable COPY to the group 1 child cached data. */ 203 const ChildCacheData1 child1(const QString &strChildKey) const { return m_children1[strChildKey]; } 204 /** Wraps method above to return the NON-modifiable COPY to the group 1 child cached data. */ 205 const ChildCacheData1 child1(int iIndex) const { return child1(indexToKey1(iIndex)); } 206 207 /** Returns group 2 children count. */ 208 int childCount2() const { return m_children2.size(); } 209 /** Returns the modifiable REFERENCE to the group 2 child cached data. */ 210 ChildCacheData2 &child2(const QString &strChildKey) { return m_children2[strChildKey]; } 211 /** Wraps method above to return the modifiable REFERENCE to the group 2 child cached data. */ 212 ChildCacheData2 &child2(int iIndex) { return child2(indexToKey2(iIndex)); } 213 /** Returns the NON-modifiable COPY to the group 2 child cached data. */ 214 const ChildCacheData2 child2(const QString &strChildKey) const { return m_children2[strChildKey]; } 215 /** Wraps method above to return the NON-modifiable COPY to the group 2 child cached data. */ 216 const ChildCacheData2 child2(int iIndex) const { return child2(indexToKey2(iIndex)); } 217 218 /** Returns whether the cache was updated. 219 * We assume that cache object was updated if current and 220 * initial data were both set and not equal to each other. 221 * Takes into account all the children of both groups. */ 222 bool wasUpdated() const 223 { 224 /* First of all, cache object is considered to be updated if parent data was updated: */ 225 bool fWasUpdated = UISettingsCache<ParentCacheData>::wasUpdated(); 226 /* If parent data was NOT updated but also was NOT created or removed too 227 * (e.j. was NOT changed at all), we have to check children too: */ 228 if (!fWasUpdated && !UISettingsCache<ParentCacheData>::wasRemoved() && !UISettingsCache<ParentCacheData>::wasCreated()) 229 { 230 for (int iChildIndex = 0; !fWasUpdated && iChildIndex < childCount1(); ++iChildIndex) 231 if (child1(iChildIndex).wasChanged()) 232 fWasUpdated = true; 233 for (int iChildIndex = 0; !fWasUpdated && iChildIndex < childCount2(); ++iChildIndex) 234 if (child2(iChildIndex).wasChanged()) 235 fWasUpdated = true; 236 } 237 return fWasUpdated; 238 } 239 240 /** Resets the initial and the current one data to be both empty. 241 * Removes all the children from both groups. */ 242 void clear() 243 { 244 UISettingsCache<ParentCacheData>::clear(); 245 m_children1.clear(); 246 m_children2.clear(); 247 } 248 249 private: 250 251 /** Returns QString representation of passed @a iIndex inside group 1. */ 252 QString indexToKey1(int iIndex) const 253 { 254 UISettingsCacheChildIterator1 childIterator(m_children1); 255 for (int iChildIndex = 0; childIterator.hasNext(); ++iChildIndex) 256 { 257 childIterator.next(); 258 if (iChildIndex == iIndex) 259 return childIterator.key(); 260 } 261 return QString("%1").arg(iIndex, 8 /* up to 8 digits */, 10 /* base */, QChar('0') /* filler */); 262 } 263 264 /** Returns QString representation of passed @a iIndex inside group 2. */ 265 QString indexToKey2(int iIndex) const 266 { 267 UISettingsCacheChildIterator2 childIterator(m_children2); 268 for (int iChildIndex = 0; childIterator.hasNext(); ++iChildIndex) 269 { 270 childIterator.next(); 271 if (iChildIndex == iIndex) 272 return childIterator.key(); 273 } 274 return QString("%1").arg(iIndex, 8 /* up to 8 digits */, 10 /* base */, QChar('0') /* filler */); 275 } 276 277 /** Holds the children of group 1. */ 278 UISettingsCacheChildMap1 m_children1; 279 /** Holds the children of group 2. */ 280 UISettingsCacheChildMap2 m_children2; 281 }; 282 176 283 #endif /* !___UISettingsDefs_h___ */ 177 284
Note:
See TracChangeset
for help on using the changeset viewer.