Totally removed Application's setting memember

This commit is contained in:
Atlante45 2015-01-18 19:10:30 -08:00
parent 92e9df0c74
commit c2b7ff1b54
11 changed files with 94 additions and 142 deletions

View file

@ -356,9 +356,6 @@ Application::Application(int& argc, char** argv, QElapsedTimer &startup_time) :
connect(addressManager.data(), &AddressManager::rootPlaceNameChanged, this, &Application::updateWindowTitle);
_settings = new QSettings(this);
_numChangedSettings = 0;
#ifdef _WIN32
WSADATA WsaData;
int wsaresult = WSAStartup(MAKEWORD(2,2), &WsaData);
@ -514,10 +511,6 @@ Application::~Application() {
void Application::saveSettings() {
Menu::getInstance()->saveSettings();
_rearMirrorTools->saveSettings(_settings);
_settings->sync();
_numChangedSettings = 0;
}
void Application::initializeGL() {
@ -1439,10 +1432,6 @@ void Application::idle() {
// After finishing all of the above work, restart the idle timer, allowing 2ms to process events.
idleTimer->start(2);
if (_numChangedSettings > 0) {
saveSettings();
}
}
}
}
@ -1711,16 +1700,13 @@ void Application::init() {
_metavoxels.init();
auto glCanvas = DependencyManager::get<GLCanvas>();
_rearMirrorTools = new RearMirrorTools(glCanvas.data(), _mirrorViewRect, _settings);
_rearMirrorTools = new RearMirrorTools(glCanvas.data(), _mirrorViewRect);
connect(_rearMirrorTools, SIGNAL(closeView()), SLOT(closeMirrorView()));
connect(_rearMirrorTools, SIGNAL(restoreView()), SLOT(restoreMirrorView()));
connect(_rearMirrorTools, SIGNAL(shrinkView()), SLOT(shrinkMirrorView()));
connect(_rearMirrorTools, SIGNAL(resetView()), SLOT(resetSensors()));
// save settings when avatar changes
connect(_myAvatar, &MyAvatar::transformChanged, this, &Application::bumpSettings);
#ifdef USE_BULLET_PHYSICS
EntityTree* tree = _entities.getTree();
_physicsEngine.setEntityTree(tree);
@ -3551,7 +3537,6 @@ ScriptEngine* Application::loadScript(const QString& scriptFilename, bool isUser
if (activateMainWindow && !loadScriptFromEditor) {
_window->activateWindow();
}
bumpSettings();
return scriptEngine;
}
@ -3579,7 +3564,6 @@ void Application::scriptFinished(const QString& scriptName) {
_scriptEnginesHash.erase(it);
_runningScriptsWidget->scriptStopped(scriptName);
_runningScriptsWidget->setRunningScripts(getRunningScripts());
bumpSettings();
}
}
@ -3675,7 +3659,6 @@ void Application::openUrl(const QUrl& url) {
}
void Application::updateMyAvatarTransform() {
bumpSettings();
#ifdef USE_BULLET_PHYSICS
const float SIMULATION_OFFSET_QUANTIZATION = 16.0f; // meters
glm::vec3 avatarPosition = _myAvatar->getPosition();

View file

@ -219,10 +219,6 @@ public:
virtual const Transform& getViewTransform() const { return _viewTransform; }
void setViewTransform(const Transform& view);
/// if you need to access the application settings, use lockSettings()/unlockSettings()
QSettings* lockSettings() { _settingsMutex.lock(); return _settings; }
void unlockSettings() { _settingsMutex.unlock(); }
void saveSettings();
NodeToOctreeSceneStats* getOcteeSceneStats() { return &_octreeServerSceneStats; }
@ -361,7 +357,6 @@ public slots:
void openUrl(const QUrl& url);
void updateMyAvatarTransform();
void bumpSettings() { ++_numChangedSettings; }
void domainSettingsReceived(const QJsonObject& domainSettingsObject);
@ -455,10 +450,6 @@ private:
QThread* _nodeThread;
DatagramProcessor _datagramProcessor;
QMutex _settingsMutex;
QSettings* _settings;
int _numChangedSettings;
QUndoStack _undoStack;
UndoStackScriptingInterface _undoStackScriptingInterface;

View file

@ -17,6 +17,7 @@
#include <DependencyManager.h>
#include <GlowEffect.h>
#include <PathUtils.h>
#include <Settings.h>
#include <UserActivityLogger.h>
#include <XmppClient.h>
@ -544,10 +545,9 @@ Menu::Menu() {
}
void Menu::loadSettings(QSettings* settings) {
bool lockedSettings = false;
Settings defaultSettings;
if (!settings) {
settings = qApp->lockSettings();
lockedSettings = true;
settings = &defaultSettings;
}
auto audio = DependencyManager::get<Audio>();
@ -568,17 +568,12 @@ void Menu::loadSettings(QSettings* settings) {
myAvatar->updateCollisionGroups();
myAvatar->onToggleRagdoll();
myAvatar->updateMotionBehavior();
if (lockedSettings) {
qApp->unlockSettings();
}
}
void Menu::saveSettings(QSettings* settings) {
bool lockedSettings = false;
Settings defaultSettings;
if (!settings) {
settings = qApp->lockSettings();
lockedSettings = true;
settings = &defaultSettings;
}
auto audio = DependencyManager::get<Audio>();
@ -591,10 +586,6 @@ void Menu::saveSettings(QSettings* settings) {
qApp->getAvatar()->saveData(settings);
DependencyManager::get<AddressManager>()->storeCurrentAddress();
if (lockedSettings) {
qApp->unlockSettings();
}
}
void Menu::importSettings() {

View file

@ -9,6 +9,7 @@
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
//
#include <QBuffer>
#include <QCheckBox>
#include <QComboBox>
#include <QDebug>
@ -21,6 +22,7 @@
#include <QHBoxLayout>
#include <QHttpMultiPart>
#include <QImage>
#include <QJsonDocument>
#include <QLineEdit>
#include <QMessageBox>
#include <QProgressBar>
@ -28,12 +30,17 @@
#include <QStandardPaths>
#include <QTemporaryFile>
#include <QTextStream>
#include <QThread>
#include <QVBoxLayout>
#include <QVariant>
#include <AccountManager.h>
#include <GeometryCache.h>
#include <GLMHelpers.h>
#include <ResourceCache.h>
#include <Settings.h>
#include <TextureCache.h>
#include "Application.h"
#include "ModelUploader.h"
@ -107,8 +114,8 @@ ModelUploader::~ModelUploader() {
bool ModelUploader::zip() {
// File Dialog
QSettings* settings = Application::getInstance()->lockSettings();
QString lastLocation = settings->value(SETTING_NAME).toString();
Settings settings;
QString lastLocation = settings.value(SETTING_NAME).toString();
if (lastLocation.isEmpty()) {
lastLocation = QStandardPaths::writableLocation(QStandardPaths::DownloadLocation);
@ -123,11 +130,9 @@ bool ModelUploader::zip() {
lastLocation, "Model files (*.fst *.fbx)");
if (filename == "") {
// If the user canceled we return.
Application::getInstance()->unlockSettings();
return false;
}
settings->setValue(SETTING_NAME, filename);
Application::getInstance()->unlockSettings();
settings.setValue(SETTING_NAME, filename);
// First we check the FST file (if any)
QFile* fst;

View file

@ -28,6 +28,7 @@
#include <NodeList.h>
#include <PacketHeaders.h>
#include <PerfStat.h>
#include <Settings.h>
#include <ShapeCollider.h>
#include <SharedUtil.h>
#include <TextRenderer.h>
@ -795,62 +796,60 @@ void MyAvatar::loadData(QSettings* settings) {
}
void MyAvatar::saveAttachmentData(const AttachmentData& attachment) const {
QSettings* settings = Application::getInstance()->lockSettings();
settings->beginGroup("savedAttachmentData");
settings->beginGroup(_skeletonModel.getURL().toString());
settings->beginGroup(attachment.modelURL.toString());
settings->setValue("jointName", attachment.jointName);
Settings settings;
settings.beginGroup("savedAttachmentData");
settings.beginGroup(_skeletonModel.getURL().toString());
settings.beginGroup(attachment.modelURL.toString());
settings.setValue("jointName", attachment.jointName);
settings->beginGroup(attachment.jointName);
settings->setValue("translation_x", attachment.translation.x);
settings->setValue("translation_y", attachment.translation.y);
settings->setValue("translation_z", attachment.translation.z);
settings.beginGroup(attachment.jointName);
settings.setValue("translation_x", attachment.translation.x);
settings.setValue("translation_y", attachment.translation.y);
settings.setValue("translation_z", attachment.translation.z);
glm::vec3 eulers = safeEulerAngles(attachment.rotation);
settings->setValue("rotation_x", eulers.x);
settings->setValue("rotation_y", eulers.y);
settings->setValue("rotation_z", eulers.z);
settings->setValue("scale", attachment.scale);
settings.setValue("rotation_x", eulers.x);
settings.setValue("rotation_y", eulers.y);
settings.setValue("rotation_z", eulers.z);
settings.setValue("scale", attachment.scale);
settings->endGroup();
settings->endGroup();
settings->endGroup();
settings->endGroup();
Application::getInstance()->unlockSettings();
settings.endGroup();
settings.endGroup();
settings.endGroup();
settings.endGroup();
}
AttachmentData MyAvatar::loadAttachmentData(const QUrl& modelURL, const QString& jointName) const {
QSettings* settings = Application::getInstance()->lockSettings();
settings->beginGroup("savedAttachmentData");
settings->beginGroup(_skeletonModel.getURL().toString());
settings->beginGroup(modelURL.toString());
Settings settings;
settings.beginGroup("savedAttachmentData");
settings.beginGroup(_skeletonModel.getURL().toString());
settings.beginGroup(modelURL.toString());
AttachmentData attachment;
attachment.modelURL = modelURL;
if (jointName.isEmpty()) {
attachment.jointName = settings->value("jointName").toString();
attachment.jointName = settings.value("jointName").toString();
} else {
attachment.jointName = jointName;
}
settings->beginGroup(attachment.jointName);
if (settings->contains("translation_x")) {
attachment.translation.x = loadSetting(settings, "translation_x", 0.0f);
attachment.translation.y = loadSetting(settings, "translation_y", 0.0f);
attachment.translation.z = loadSetting(settings, "translation_z", 0.0f);
settings.beginGroup(attachment.jointName);
if (settings.contains("translation_x")) {
attachment.translation.x = loadSetting(&settings, "translation_x", 0.0f);
attachment.translation.y = loadSetting(&settings, "translation_y", 0.0f);
attachment.translation.z = loadSetting(&settings, "translation_z", 0.0f);
glm::vec3 eulers;
eulers.x = loadSetting(settings, "rotation_x", 0.0f);
eulers.y = loadSetting(settings, "rotation_y", 0.0f);
eulers.z = loadSetting(settings, "rotation_z", 0.0f);
eulers.x = loadSetting(&settings, "rotation_x", 0.0f);
eulers.y = loadSetting(&settings, "rotation_y", 0.0f);
eulers.z = loadSetting(&settings, "rotation_z", 0.0f);
attachment.rotation = glm::quat(eulers);
attachment.scale = loadSetting(settings, "scale", 1.0f);
attachment.scale = loadSetting(&settings, "scale", 1.0f);
} else {
attachment = AttachmentData();
}
settings->endGroup();
settings->endGroup();
settings->endGroup();
settings->endGroup();
Application::getInstance()->unlockSettings();
settings.endGroup();
settings.endGroup();
settings.endGroup();
settings.endGroup();
return attachment;
}

View file

@ -9,7 +9,8 @@
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
//
#include "Application.h"
#include <Settings.h>
#include "SettingsScriptingInterface.h"
@ -19,9 +20,7 @@ SettingsScriptingInterface* SettingsScriptingInterface::getInstance() {
}
QVariant SettingsScriptingInterface::getValue(const QString& setting) {
QSettings* settings = Application::getInstance()->lockSettings();
QVariant value = settings->value(setting);
Application::getInstance()->unlockSettings();
QVariant value = Settings().value(setting);
if (!value.isValid()) {
value = "";
}
@ -29,9 +28,7 @@ QVariant SettingsScriptingInterface::getValue(const QString& setting) {
}
QVariant SettingsScriptingInterface::getValue(const QString& setting, const QVariant& defaultValue) {
QSettings* settings = Application::getInstance()->lockSettings();
QVariant value = settings->value(setting, defaultValue);
Application::getInstance()->unlockSettings();
QVariant value = Settings().value(setting, defaultValue);
if (!value.isValid()) {
value = "";
}
@ -39,7 +36,5 @@ QVariant SettingsScriptingInterface::getValue(const QString& setting, const QVar
}
void SettingsScriptingInterface::setValue(const QString& setting, const QVariant& value) {
QSettings* settings = Application::getInstance()->lockSettings();
settings->setValue(setting, value);
Application::getInstance()->unlockSettings();
Settings().setValue(setting, value);
}

View file

@ -22,6 +22,7 @@
#include <AddressManager.h>
#include <AccountManager.h>
#include <PathUtils.h>
#include <Settings.h>
#include "Application.h"
#include "ChatMessageArea.h"
@ -377,12 +378,11 @@ void ChatWindow::messageReceived(const QXmppMessage& message) {
if (message.body().contains(usernameMention)) {
// Don't show messages already seen in icon tray at start-up.
QSettings* settings = Application::getInstance()->lockSettings();
bool showMessage = settings->value("usernameMentionTimestamp").toDateTime() < _lastMessageStamp;
Settings settings;
bool showMessage = settings.value("usernameMentionTimestamp").toDateTime() < _lastMessageStamp;
if (showMessage) {
settings->setValue("usernameMentionTimestamp", _lastMessageStamp);
settings.setValue("usernameMentionTimestamp", _lastMessageStamp);
}
Application::getInstance()->unlockSettings();
if (isHidden() && showMessage) {

View file

@ -10,14 +10,14 @@
//
#include <QApplication>
#include <QDesktopWidget>
#include <QFileInfo>
#include <QtWebKitWidgets/QWebFrame>
#include <QtWebKit/QWebElement>
#include <QDesktopWidget>
#include <PathUtils.h>
#include <Settings.h>
#include "Application.h"
#include "InfoView.h"
#define SETTINGS_VERSION_KEY "info-version"
@ -49,20 +49,19 @@ bool InfoView::shouldShow() {
return true;
}
QSettings* settings = Application::getInstance()->lockSettings();
Settings settings;
QString lastVersion = settings->value(SETTINGS_VERSION_KEY).toString();
QString lastVersion = settings.value(SETTINGS_VERSION_KEY).toString();
QWebElement versionTag = page()->mainFrame()->findFirstElement("#version");
QString version = versionTag.attribute("value");
if (version != QString::null && (lastVersion == QString::null || lastVersion != version)) {
settings->setValue(SETTINGS_VERSION_KEY, version);
settings.setValue(SETTINGS_VERSION_KEY, version);
shouldShow = true;
} else {
shouldShow = false;
}
Application::getInstance()->unlockSettings();
return shouldShow;
}
@ -72,7 +71,7 @@ void InfoView::loaded(bool ok) {
return;
}
QDesktopWidget* desktop = Application::getInstance()->desktop();
QDesktopWidget* desktop = qApp->desktop();
QWebFrame* mainFrame = page()->mainFrame();
int height = mainFrame->contentsSize().height() > desktop->height() ?

View file

@ -270,6 +270,4 @@ void PreferencesDialog::savePreferences() {
audio->setOutputStarveDetectionPeriod(ui.outputStarveDetectionPeriodSpinner->value());
Application::getInstance()->resizeGL(glCanvas->width(), glCanvas->height());
Application::getInstance()->bumpSettings();
}

View file

@ -14,6 +14,7 @@
#include <QMouseEvent>
#include <PathUtils.h>
#include <Settings.h>
#include <SharedUtil.h>
#include "Application.h"
@ -26,18 +27,14 @@ const char ZOOM_LEVEL_SETTINGS[] = "ZoomLevel";
const int ICON_SIZE = 24;
const int ICON_PADDING = 5;
RearMirrorTools::RearMirrorTools(QGLWidget* parent, QRect& bounds, QSettings* settings) :
RearMirrorTools::RearMirrorTools(QGLWidget* parent, QRect& bounds) :
_parent(parent),
_bounds(bounds),
_windowed(false),
_fullScreen(false)
{
_zoomLevel = HEAD;
_closeTextureId = _parent->bindTexture(QImage(PathUtils::resourcesPath() + "images/close.svg"));
// Disabled for now https://worklist.net/19548
// _resetTextureId = _parent->bindTexture(QImage(PathUtils::resourcesPath() + "images/reset.png"));
_zoomHeadTextureId = _parent->bindTexture(QImage(PathUtils::resourcesPath() + "images/plus.svg"));
_zoomBodyTextureId = _parent->bindTexture(QImage(PathUtils::resourcesPath() + "images/minus.svg"));
@ -46,11 +43,7 @@ RearMirrorTools::RearMirrorTools(QGLWidget* parent, QRect& bounds, QSettings* se
_resetIconRect = QRect(_bounds.width() - ICON_SIZE - ICON_PADDING, _bounds.top() + ICON_PADDING, ICON_SIZE, ICON_SIZE);
_bodyZoomIconRect = QRect(_bounds.width() - ICON_SIZE - ICON_PADDING, _bounds.bottom() - ICON_PADDING - ICON_SIZE, ICON_SIZE, ICON_SIZE);
_headZoomIconRect = QRect(_bounds.left() + ICON_PADDING, _bounds.bottom() - ICON_PADDING - ICON_SIZE, ICON_SIZE, ICON_SIZE);
settings->beginGroup(SETTINGS_GROUP_NAME);
_zoomLevel = loadSetting(settings, ZOOM_LEVEL_SETTINGS, 0) == HEAD ? HEAD : BODY;
settings->endGroup();
};
}
void RearMirrorTools::render(bool fullScreen) {
if (fullScreen) {
@ -63,11 +56,8 @@ void RearMirrorTools::render(bool fullScreen) {
if (_windowed) {
displayIcon(_bounds, _closeIconRect, _closeTextureId);
// Disabled for now https://worklist.net/19548
// displayIcon(_bounds, _resetIconRect, _resetTextureId);
displayIcon(_bounds, _headZoomIconRect, _zoomHeadTextureId, _zoomLevel == HEAD);
displayIcon(_bounds, _bodyZoomIconRect, _zoomBodyTextureId, _zoomLevel == BODY);
displayIcon(_bounds, _headZoomIconRect, _zoomHeadTextureId, getZoomLevel() == HEAD);
displayIcon(_bounds, _bodyZoomIconRect, _zoomBodyTextureId, getZoomLevel() == BODY);
}
}
}
@ -79,23 +69,14 @@ bool RearMirrorTools::mousePressEvent(int x, int y) {
emit closeView();
return true;
}
/* Disabled for now https://worklist.net/19548
if (_resetIconRect.contains(x, y)) {
emit resetView();
return true;
}
*/
if (_headZoomIconRect.contains(x, y)) {
_zoomLevel = HEAD;
Application::getInstance()->bumpSettings();
setZoomLevel(HEAD);
return true;
}
if (_bodyZoomIconRect.contains(x, y)) {
_zoomLevel = BODY;
Application::getInstance()->bumpSettings();
setZoomLevel(BODY);
return true;
}
@ -116,10 +97,20 @@ bool RearMirrorTools::mousePressEvent(int x, int y) {
return false;
}
void RearMirrorTools::saveSettings(QSettings* settings) {
settings->beginGroup(SETTINGS_GROUP_NAME);
settings->setValue(ZOOM_LEVEL_SETTINGS, _zoomLevel);
settings->endGroup();
ZoomLevel RearMirrorTools::getZoomLevel() {
Settings settings;
settings.beginGroup(SETTINGS_GROUP_NAME);
ZoomLevel zoomLevel = (ZoomLevel)settings.value(ZOOM_LEVEL_SETTINGS, HEAD).toInt();
settings.endGroup();
return zoomLevel;
}
void RearMirrorTools::setZoomLevel(ZoomLevel zoomLevel) {
Settings settings;
settings.beginGroup(SETTINGS_GROUP_NAME);
settings.setValue(ZOOM_LEVEL_SETTINGS, zoomLevel);
settings.endGroup();
}
void RearMirrorTools::displayIcon(QRect bounds, QRect iconBounds, GLuint textureId, bool selected) {

View file

@ -25,11 +25,12 @@ enum ZoomLevel {
class RearMirrorTools : public QObject {
Q_OBJECT
public:
RearMirrorTools(QGLWidget* parent, QRect& bounds, QSettings* settings);
RearMirrorTools(QGLWidget* parent, QRect& bounds);
void render(bool fullScreen);
bool mousePressEvent(int x, int y);
ZoomLevel getZoomLevel() { return _zoomLevel; }
void saveSettings(QSettings* settings);
ZoomLevel getZoomLevel();
void setZoomLevel(ZoomLevel zoomLevel);
signals:
void closeView();
@ -44,7 +45,6 @@ private:
GLuint _resetTextureId;
GLuint _zoomBodyTextureId;
GLuint _zoomHeadTextureId;
ZoomLevel _zoomLevel;
QRect _closeIconRect;
QRect _resetIconRect;