mirror of
https://github.com/overte-org/overte.git
synced 2025-08-09 17:49:27 +02:00
more changes from code review
This commit is contained in:
parent
0c7aab1556
commit
37c613c3d4
2 changed files with 23 additions and 30 deletions
|
@ -22,19 +22,19 @@
|
||||||
|
|
||||||
static const QString RESTRICTED_FLAG_PROPERTY = "RestrictFileAccess";
|
static const QString RESTRICTED_FLAG_PROPERTY = "RestrictFileAccess";
|
||||||
|
|
||||||
QReadWriteLock ContextAwareProfile::_global_contextMapProtect;
|
QReadWriteLock ContextAwareProfile::_contextMapProtect;
|
||||||
ContextAwareProfile::ContextMap ContextAwareProfile::_global_contextMap;
|
ContextAwareProfile::ContextMap ContextAwareProfile::_contextMap;
|
||||||
|
|
||||||
ContextAwareProfile::ContextAwareProfile(QQmlContext* context) : ContextAwareProfileParent(context), _context(context) {
|
ContextAwareProfile::ContextAwareProfile(QQmlContext* context) : ContextAwareProfileParent(context), _context(context) {
|
||||||
assert(context);
|
assert(context);
|
||||||
|
|
||||||
{ // register our object for future updates
|
{ // register our object for future updates
|
||||||
QWriteLocker guard(&_global_contextMapProtect);
|
QWriteLocker guard(&_contextMapProtect);
|
||||||
ContextMap::iterator setLookup = _global_contextMap.find(_context);
|
ContextMap::iterator setLookup = _contextMap.find(_context);
|
||||||
if (setLookup == _global_contextMap.end()) {
|
if (setLookup == _contextMap.end()) {
|
||||||
setLookup = _global_contextMap.insert(_context, ContextAwareProfileSet());
|
setLookup = _contextMap.insert(_context, ContextAwareProfileSet());
|
||||||
}
|
}
|
||||||
assert(setLookup != _global_contextMap.end());
|
assert(setLookup != _contextMap.end());
|
||||||
ContextAwareProfileSet& profileSet = setLookup.value();
|
ContextAwareProfileSet& profileSet = setLookup.value();
|
||||||
assert(profileSet.find(this) == profileSet.end());
|
assert(profileSet.find(this) == profileSet.end());
|
||||||
profileSet.insert(this);
|
profileSet.insert(this);
|
||||||
|
@ -44,17 +44,16 @@ ContextAwareProfile::ContextAwareProfile(QQmlContext* context) : ContextAwarePro
|
||||||
}
|
}
|
||||||
|
|
||||||
ContextAwareProfile::~ContextAwareProfile() {
|
ContextAwareProfile::~ContextAwareProfile() {
|
||||||
{ // deregister our object
|
// deregister our object
|
||||||
QWriteLocker guard(&_global_contextMapProtect);
|
QWriteLocker guard(&_contextMapProtect);
|
||||||
ContextMap::iterator setLookup = _global_contextMap.find(_context);
|
ContextMap::iterator setLookup = _contextMap.find(_context);
|
||||||
assert(setLookup != _global_contextMap.end());
|
assert(setLookup != _contextMap.end());
|
||||||
if (setLookup != _global_contextMap.end()) {
|
if (setLookup != _contextMap.end()) {
|
||||||
ContextAwareProfileSet& profileSet = setLookup.value();
|
ContextAwareProfileSet& profileSet = setLookup.value();
|
||||||
assert(profileSet.find(this) != profileSet.end());
|
assert(profileSet.find(this) != profileSet.end());
|
||||||
profileSet.remove(this);
|
profileSet.remove(this);
|
||||||
if (profileSet.isEmpty()) {
|
if (profileSet.isEmpty()) {
|
||||||
_global_contextMap.erase(setLookup);
|
_contextMap.erase(setLookup);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -65,13 +64,13 @@ void ContextAwareProfile::restrictContext(QQmlContext* context, bool restrict) {
|
||||||
context->setContextProperty(RESTRICTED_FLAG_PROPERTY, restrict);
|
context->setContextProperty(RESTRICTED_FLAG_PROPERTY, restrict);
|
||||||
|
|
||||||
// broadcast the new value to any registered ContextAwareProfile objects
|
// broadcast the new value to any registered ContextAwareProfile objects
|
||||||
QReadLocker guard(&_global_contextMapProtect);
|
QReadLocker guard(&_contextMapProtect);
|
||||||
ContextMap::const_iterator setLookup = _global_contextMap.find(context);
|
ContextMap::const_iterator setLookup = _contextMap.find(context);
|
||||||
if (setLookup != _global_contextMap.end()) {
|
if (setLookup != _contextMap.end()) {
|
||||||
const ContextAwareProfileSet& profileSet = setLookup.value();
|
const ContextAwareProfileSet& profileSet = setLookup.value();
|
||||||
for (ContextAwareProfileSet::const_iterator profileIterator = profileSet.begin();
|
for (ContextAwareProfileSet::const_iterator profileIterator = profileSet.begin();
|
||||||
profileIterator != profileSet.end(); profileIterator++) {
|
profileIterator != profileSet.end(); profileIterator++) {
|
||||||
(*profileIterator)->onIsRestrictedChanged(restrict);
|
(*profileIterator)->_isRestricted.store(restrict);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -93,10 +92,6 @@ bool ContextAwareProfile::isRestrictedGetProperty() {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ContextAwareProfile::onIsRestrictedChanged(bool newValue) {
|
|
||||||
_isRestricted.store(newValue);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool ContextAwareProfile::isRestricted() {
|
bool ContextAwareProfile::isRestricted() {
|
||||||
return _isRestricted.load();
|
return _isRestricted.load();
|
||||||
}
|
}
|
||||||
|
|
|
@ -58,10 +58,8 @@ private:
|
||||||
QQmlContext* _context{ nullptr };
|
QQmlContext* _context{ nullptr };
|
||||||
std::atomic<bool> _isRestricted{ false };
|
std::atomic<bool> _isRestricted{ false };
|
||||||
|
|
||||||
static QReadWriteLock _global_contextMapProtect;
|
static QReadWriteLock _contextMapProtect;
|
||||||
static ContextMap _global_contextMap;
|
static ContextMap _contextMap;
|
||||||
|
|
||||||
void onIsRestrictedChanged(bool newValue);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // hifi_FileTypeProfile_h
|
#endif // hifi_FileTypeProfile_h
|
||||||
|
|
Loading…
Reference in a new issue