Commit fc2d617e authored by Marlin Frickenschmidt's avatar Marlin Frickenschmidt

Fixed a bug related to default values in QtBaseViewerStereo, so stereo...

Fixed a bug related to default values in QtBaseViewerStereo, so stereo anaglyph mode works again now.

Added OpenFlipperQSettings which wraps the value() function to write an error message to console if that function is used without a default value. This is meant as a reminder to developers to properly initialize their settings and specify default values such that hopefully less bugs like the one above occur from now on.

Added default values for many calls to OpenFlipperSettings().value() - if you find any that I have overlooked, please add default values there, too!

git-svn-id: http://www.openflipper.org/svnrepo/OpenFlipper/branches/Free@10424 383ad7c9-94d9-4d36-a494-682f7c89f535
parent 9ef8fe59
......@@ -966,8 +966,8 @@ void Core::multiViewMode( int _mode ) {
void
Core::slotRecentOpen(QAction* _action)
{
QStringList recentFiles = OpenFlipperSettings().value("Core/File/RecentFiles").toStringList();
QStringList recentTypes = OpenFlipperSettings().value("Core/File/RecentTypes").toStringList();
QStringList recentFiles = OpenFlipperSettings().value("Core/File/RecentFiles", QStringList()).toStringList();
QStringList recentTypes = OpenFlipperSettings().value("Core/File/RecentTypes", QStringList()).toStringList();
for (int i = 0 ; i < recentFiles.size() ; ++i )
if ( recentFiles[i] == _action->text() ){
......
......@@ -336,8 +336,8 @@ void Core::writeApplicationOptions(INIFile& _ini) {
_ini.add_entry("Options","MaxRecent", OpenFlipperSettings().value("Core/File/MaxRecent",15).toInt() );
// Write list of recent files to ini
QStringList recentFiles = OpenFlipperSettings().value("Core/File/RecentFiles").toStringList();
QStringList recentTypes = OpenFlipperSettings().value("Core/File/RecentTypes").toStringList();
QStringList recentFiles = OpenFlipperSettings().value("Core/File/RecentFiles", QStringList()).toStringList();
QStringList recentTypes = OpenFlipperSettings().value("Core/File/RecentTypes", QStringList()).toStringList();
for ( int j = 0 ; j < recentFiles.size(); ++j) {
// Save filename
......
......@@ -185,14 +185,14 @@ void Core::loadPlugins()
}
// get all Plugin Names which will not be loaded
QStringList dontLoadPlugins = OpenFlipperSettings().value("PluginControl/DontLoadNames").toStringList();
QStringList dontLoadPlugins = OpenFlipperSettings().value("PluginControl/DontLoadNames", QStringList()).toStringList();
// Output info about additional plugins
for ( int i = 0 ; i < dontLoadPlugins.size(); ++i)
emit log(LOGOUT,tr("dontLoadPlugins Plugin from ini file: %1").arg( dontLoadPlugins[i] ) );
// get all Plugins which should be loaded in addition to the standard plugins
QStringList additionalPlugins = OpenFlipperSettings().value("PluginControl/AdditionalPlugins").toStringList();
QStringList additionalPlugins = OpenFlipperSettings().value("PluginControl/AdditionalPlugins", QStringList()).toStringList();
// Output info about additional plugins
for ( int i = 0 ; i < additionalPlugins.size(); ++i) {
......@@ -385,7 +385,7 @@ void Core::slotLoadPlugin(){
return;
// Ask if the plugin is on the block list
QStringList dontLoadPlugins = OpenFlipperSettings().value("PluginControl/DontLoadNames").toStringList();
QStringList dontLoadPlugins = OpenFlipperSettings().value("PluginControl/DontLoadNames", QStringList()).toStringList();
if (dontLoadPlugins.contains(name)){
int ret = QMessageBox::question(0, tr("Plugin Loading Prevention"),
tr("OpenFlipper is currently configured to prevent loading this plugin.\n"
......@@ -400,7 +400,7 @@ void Core::slotLoadPlugin(){
}
// check if the plugin is not on the additional plugin list
QStringList additionalPlugins = OpenFlipperSettings().value("PluginControl/AdditionalPlugins").toStringList();
QStringList additionalPlugins = OpenFlipperSettings().value("PluginControl/AdditionalPlugins", QStringList()).toStringList();
if (!additionalPlugins.contains(name)){
int ret = QMessageBox::question(0, tr("Plugin Loading ..."),
tr("Should OpenFlipper load this plugin on next startup?"),
......@@ -426,7 +426,7 @@ void Core::slotLoadPlugin(){
std::cerr << "Plugin License check failed" << std::endl;
std::cerr << licenseText.toStdString() << std::endl;
}
}
}
}
/** @brief slot for showing loaded Plugins
......@@ -573,7 +573,7 @@ void Core::loadPlugin(QString filename, bool silent, QString& _licenseErrors, QO
}
}
QStringList dontLoadPlugins = OpenFlipperSettings().value("PluginControl/DontLoadNames").toStringList();
QStringList dontLoadPlugins = OpenFlipperSettings().value("PluginControl/DontLoadNames",QStringList()).toStringList();
if ( dontLoadPlugins.contains(basePlugin->name(), Qt::CaseInsensitive) ) {
emit log(LOGWARN,tr("OpenFlipper.ini prevented Plugin %1 from being loaded! ").arg( basePlugin->name() ));
......
......@@ -142,7 +142,7 @@ void Core::applyOptions(){
// toolbox orientation
coreWidget_->setToolBoxOrientationOnTheRight(OpenFlipperSettings().value("Core/Gui/ToolBoxes/ToolBoxOnTheRight").toBool());
coreWidget_->setToolBoxOrientationOnTheRight(OpenFlipperSettings().value("Core/Gui/ToolBoxes/ToolBoxOnTheRight",true).toBool());
//set defaultBackgroundColor
......@@ -150,8 +150,8 @@ void Core::applyOptions(){
for ( unsigned int i = 0 ; i < OpenFlipper::Options::examinerWidgets() ; ++i ) {
//wheel zoom factor
PluginFunctions::viewerProperties(i).wheelZoomFactor( OpenFlipperSettings().value("Core/Mouse/Wheel/ZoomFactor").toDouble() );
PluginFunctions::viewerProperties(i).wheelZoomFactorShift( OpenFlipperSettings().value("Core/Mouse/Wheel/ZoomFactorShift").toDouble() );
PluginFunctions::viewerProperties(i).wheelZoomFactor( OpenFlipperSettings().value("Core/Mouse/Wheel/ZoomFactor",1).toDouble() );
PluginFunctions::viewerProperties(i).wheelZoomFactorShift( OpenFlipperSettings().value("Core/Mouse/Wheel/ZoomFactorShift",0.2).toDouble() );
// Picking Debugger
PluginFunctions::viewerProperties(i).renderPicking( OpenFlipperSettings().value("Core/Debug/Picking/RenderPicking",false).toBool() , target );
......
......@@ -69,7 +69,7 @@ namespace Options {
static QString compilerInfo_ = "";
/// Pointer to the internal settings object storing OpenFlippers program options ( and the pplugins Options)
static QSettings* settings_ = 0;
static OpenFlipperQSettings* settings_ = 0;
/// Stores the base Path of the application
static QDir applicationDir_;
......@@ -140,7 +140,7 @@ static bool glStereo_ = true;
/// Stereo mode
static StereoMode stereoMode_ = OpenGL;
/// vectroy containing left/right color matrices for custom anaglyph mode
/// vector containing left/right color matrices for custom anaglyph mode
static std::vector<float> anaglyphLeftEyeColors_ = std::vector<float> (9, 0.0);
static std::vector<float> anaglyphRightEyeColors_ = std::vector<float> (9, 0.0);
......@@ -762,7 +762,7 @@ bool initializeSettings() {
QSettings::setPath( QSettings::IniFormat, QSettings::UserScope , configDir_.absolutePath() );
// Finally attach the settings object.
settings_ = new QSettings(QSettings::IniFormat, QSettings::UserScope, "ACG","OpenFlipper");
settings_ = new OpenFlipperQSettings(QSettings::IniFormat, QSettings::UserScope, "ACG", "OpenFlipper");
//==================================================================================================
// Now create special directories in th OpenFlipper config dir
......@@ -930,9 +930,9 @@ QString compilerInfo() {
}
}
QSettings& OpenFlipperSettings() {
OpenFlipperQSettings& OpenFlipperSettings() {
// Empty standard settings object if the right settings are not available!
static QSettings emptySettings;
static OpenFlipperQSettings emptySettings;
if ( OpenFlipper::Options::settings_ )
return *OpenFlipper::Options::settings_;
......
......@@ -64,7 +64,7 @@
#include <QStringList>
#include <QColor>
#include <QIcon>
#include <QSettings>
#include "OpenFlipperQSettings.hh"
//===========================================================================
/** @name Persistent settings
......@@ -133,7 +133,7 @@
* Anaglyph stereo mode settings:\n
*/
DLLEXPORT
QSettings& OpenFlipperSettings();
OpenFlipperQSettings& OpenFlipperSettings();
/** @} */
......
/*===========================================================================*\
* *
* OpenFlipper *
* Copyright (C) 2001-2010 by Computer Graphics Group, RWTH Aachen *
* www.openflipper.org *
* *
*--------------------------------------------------------------------------- *
* This file is part of OpenFlipper. *
* *
* OpenFlipper is free software: you can redistribute it and/or modify *
* it under the terms of the GNU Lesser General Public License as *
* published by the Free Software Foundation, either version 3 of *
* the License, or (at your option) any later version with the *
* following exceptions: *
* *
* If other files instantiate templates or use macros *
* or inline functions from this file, or you compile this file and *
* link it with other files to produce an executable, this file does *
* not by itself cause the resulting executable to be covered by the *
* GNU Lesser General Public License. This exception does not however *
* invalidate any other reasons why the executable file might be *
* covered by the GNU Lesser General Public License. *
* *
* OpenFlipper is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU Lesser General Public License for more details. *
* *
* You should have received a copy of the GNU LesserGeneral Public *
* License along with OpenFlipper. If not, *
* see <http://www.gnu.org/licenses/>. *
* *
\*===========================================================================*/
/*===========================================================================*\
* *
* $Revision: 10413 $ *
* $LastChangedBy: moebius $ *
* $Date: 2010-12-09 15:40:04 +0100 (Thu, 09 Dec 2010) $ *
* *
\*===========================================================================*/
#include <iostream>
#include "OpenFlipperQSettings.hh"
QVariant OpenFlipperQSettings::value(const QString& key, const QVariant& defaultValue) const
{
QVariant var = QSettings::value(key, defaultValue);
if (!var.isValid())
std::cerr << "Tried loading OpenFlipper settings value for " << key.toStdString() << ", but it was not found and no default value given!" << std::endl;
return var;
}
\ No newline at end of file
/*===========================================================================*\
* *
* OpenFlipper *
* Copyright (C) 2001-2010 by Computer Graphics Group, RWTH Aachen *
* www.openflipper.org *
* *
*--------------------------------------------------------------------------- *
* This file is part of OpenFlipper. *
* *
* OpenFlipper is free software: you can redistribute it and/or modify *
* it under the terms of the GNU Lesser General Public License as *
* published by the Free Software Foundation, either version 3 of *
* the License, or (at your option) any later version with the *
* following exceptions: *
* *
* If other files instantiate templates or use macros *
* or inline functions from this file, or you compile this file and *
* link it with other files to produce an executable, this file does *
* not by itself cause the resulting executable to be covered by the *
* GNU Lesser General Public License. This exception does not however *
* invalidate any other reasons why the executable file might be *
* covered by the GNU Lesser General Public License. *
* *
* OpenFlipper is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU Lesser General Public License for more details. *
* *
* You should have received a copy of the GNU LesserGeneral Public *
* License along with OpenFlipper. If not, *
* see <http://www.gnu.org/licenses/>. *
* *
\*===========================================================================*/
/*===========================================================================*\
* *
* $Revision: 10413 $ *
* $LastChangedBy: moebius $ *
* $Date: 2010-12-09 15:40:04 +0100 (Thu, 09 Dec 2010) $ *
* *
\*===========================================================================*/
#ifndef OPENLFLIPPERQSETTINGS_HH
#define OPENLFLIPPERQSETTINGS_HH
#include <QSettings>
class OpenFlipperQSettings : public QSettings
{
public:
explicit OpenFlipperQSettings(const QString &organization,
const QString &application = QString(), QObject *parent = 0) : QSettings(organization, application, parent) {};
OpenFlipperQSettings(QSettings::Scope scope, const QString &organization,
const QString &application = QString(), QObject *parent = 0) : QSettings(scope, organization, application, parent) {};
OpenFlipperQSettings(QSettings::Format format, QSettings::Scope scope, const QString &organization,
const QString &application = QString(), QObject *parent = 0) : QSettings (format, scope, organization, application, parent) {};
OpenFlipperQSettings(const QString &fileName, QSettings::Format format, QObject *parent = 0) : QSettings(fileName, format, parent) {};
explicit OpenFlipperQSettings(QObject *parent = 0) : QSettings(parent) {};
/// Wrapper function for QSettings::value() that outputs an error message to console if the key was not found and no default value given.
/// This is supposed to prevent Plugin authors from forgetting to specify the defaultValue. ;)
QVariant value(const QString &key, const QVariant &defaultValue = QVariant()) const;
};
#endif // OPENFLIPPERQSETTINGS_HH
......@@ -63,8 +63,8 @@ namespace Options {
void addRecentFile(QString _file, DataType _type) {
QStringList recentFiles = OpenFlipperSettings().value("Core/File/RecentFiles").toStringList();
QStringList recentTypes = OpenFlipperSettings().value("Core/File/RecentTypes").toStringList();
QStringList recentFiles = OpenFlipperSettings().value("Core/File/RecentFiles", QStringList()).toStringList();
QStringList recentTypes = OpenFlipperSettings().value("Core/File/RecentTypes", QStringList()).toStringList();
QString type = typeName(_type);
......
......@@ -145,7 +145,7 @@ void PluginDialog::slotUnload()
// Store the new setting and remove plugin from all lists
if (buttonState == QMessageBox::Yes || buttonState == QMessageBox::YesToAll) {
QStringList dontLoadPlugins = OpenFlipperSettings().value("PluginControl/DontLoadNames").toStringList();
QStringList dontLoadPlugins = OpenFlipperSettings().value("PluginControl/DontLoadNames",QStringList()).toStringList();
if ( !dontLoadPlugins.contains(name) ){
dontLoadPlugins << name;
OpenFlipperSettings().setValue("PluginControl/DontLoadNames",dontLoadPlugins);
......
......@@ -927,8 +927,8 @@ CoreWidget::updateRecent()
recentFilesMenu_->clear();
QStringList recentFiles = OpenFlipperSettings().value("Core/File/RecentFiles").toStringList();
QStringList recentTypes = OpenFlipperSettings().value("Core/File/RecentTypes").toStringList();
QStringList recentFiles = OpenFlipperSettings().value("Core/File/RecentFiles", QStringList()).toStringList();
QStringList recentTypes = OpenFlipperSettings().value("Core/File/RecentTypes", QStringList()).toStringList();
for (int i = 0 ; i < recentFiles.size() ; ++i ) {
......
......@@ -406,7 +406,7 @@ void glViewer::updateProjectionMatrix()
glstate_->reset_projection();
// In scereo mode we have to use a perspective matrix
// In stereo mode we have to use a perspective matrix
if (stereo_ || projectionMode_ == PERSPECTIVE_PROJECTION)
{
double aspect;
......
......@@ -117,10 +117,10 @@ glViewer::drawScene_glStereo()
h = glHeight();
a = w / h;
double fovy = OpenFlipperSettings().value("Core/Projection/FOVY").toDouble();
double fovy = OpenFlipperSettings().value("Core/Projection/FOVY",45.0).toDouble();
radians = fovy * 0.5 / 180.0 * M_PI;
wd2 = near_ * tan(radians);
zerop = near_ + ((far_ - near_) * OpenFlipperSettings().value("Core/Stereo/FocalDistance").toDouble() );
zerop = near_ + ((far_ - near_) * OpenFlipperSettings().value("Core/Stereo/FocalDistance",0.5).toDouble() );
ndfl = near_ / zerop ;
xrange = a * wd2 * 2 * zerop / near_;
......@@ -129,7 +129,7 @@ glViewer::drawScene_glStereo()
t = wd2;
b = -wd2;
double offset = 0.5 * OpenFlipperSettings().value("Core/Stereo/EyeDistance").toDouble() * xrange;
double offset = 0.5 * OpenFlipperSettings().value("Core/Stereo/EyeDistance",0.07).toDouble() * xrange;
double offset2 = offset * ndfl;
// left eye
......@@ -513,10 +513,10 @@ glViewer::drawScene_anaglyphStereo()
h = glHeight();
a = w / h;
double fovy = OpenFlipperSettings().value("Core/Projection/FOVY").toDouble();
double fovy = OpenFlipperSettings().value("Core/Projection/FOVY", 45.0).toDouble();
radians = fovy * 0.5 / 180.0 * M_PI;
wd2 = near_ * tan(radians);
zerop = near_ + ((far_ - near_) * OpenFlipperSettings().value("Core/Stereo/FocalDistance").toDouble() );
zerop = near_ + ((far_ - near_) * OpenFlipperSettings().value("Core/Stereo/FocalDistance", 0.5).toDouble() );
ndfl = near_ / zerop ;
xrange = a * wd2 * 2 * zerop / near_;
......@@ -525,7 +525,7 @@ glViewer::drawScene_anaglyphStereo()
t = wd2;
b = -wd2;
double offset = 0.5 * OpenFlipperSettings().value("Core/Stereo/EyeDistance").toDouble() * xrange;
double offset = 0.5 * OpenFlipperSettings().value("Core/Stereo/EyeDistance", 0.07).toDouble() * xrange;
double offset2 = offset * ndfl;
// left eye
......@@ -645,10 +645,10 @@ glViewer::drawScene_customAnaglyphStereo()
h = glHeight();
a = w / h;
double fovy = OpenFlipperSettings().value("Core/Projection/FOVY").toDouble();
double fovy = OpenFlipperSettings().value("Core/Projection/FOVY",45.0).toDouble();
radians = fovy * 0.5 / 180.0 * M_PI;
wd2 = near_ * tan(radians);
zerop = near_ + ((far_ - near_) * OpenFlipperSettings().value("Core/Stereo/FocalDistance").toDouble() );
zerop = near_ + ((far_ - near_) * OpenFlipperSettings().value("Core/Stereo/FocalDistance",0.5).toDouble() );
ndfl = near_ / zerop ;
xrange = a * wd2 * 2 * zerop / near_;
......@@ -657,7 +657,7 @@ glViewer::drawScene_customAnaglyphStereo()
t = wd2;
b = -wd2;
double offset = 0.5 * OpenFlipperSettings().value("Core/Stereo/EyeDistance").toDouble() * xrange;
double offset = 0.5 * OpenFlipperSettings().value("Core/Stereo/EyeDistance",0.07).toDouble() * xrange;
double offset2 = offset * ndfl;
int vp_l, vp_b, vp_w, vp_h;
......
......@@ -267,7 +267,7 @@ void OptionsWidget::showEvent ( QShowEvent * /*event*/ ) {
logFile->setText( OpenFlipperSettings().value("Core/Log/logFile").toString() );
// UI settings
toolBoxOrientation->setCurrentIndex((OpenFlipperSettings().value("Core/Gui/ToolBoxes/ToolBoxOnTheRight").toBool() ? 0 : 1));
toolBoxOrientation->setCurrentIndex((OpenFlipperSettings().value("Core/Gui/ToolBoxes/ToolBoxOnTheRight",true).toBool() ? 0 : 1));
//stereo
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment