Commit 5816666b authored by Sebastian Eichelbaum's avatar Sebastian Eichelbaum
Browse files

[CHANGE #312] Settings of a WGEViewer are stored in the QSettings now for all views.

parent 1d8c70c3
......@@ -115,67 +115,67 @@ void WPropertyBase::setHidden( bool hidden )
WPropInt WPropertyBase::toPropInt()
{
return boost::static_pointer_cast< WPVInt >( shared_from_this() );
return boost::dynamic_pointer_cast< WPVInt >( shared_from_this() );
}
WPropDouble WPropertyBase::toPropDouble()
{
return boost::static_pointer_cast< WPVDouble >( shared_from_this() );
return boost::dynamic_pointer_cast< WPVDouble >( shared_from_this() );
}
WPropBool WPropertyBase::toPropBool()
{
return boost::static_pointer_cast< WPVBool >( shared_from_this() );
return boost::dynamic_pointer_cast< WPVBool >( shared_from_this() );
}
WPropString WPropertyBase::toPropString()
{
return boost::static_pointer_cast< WPVString >( shared_from_this() );
return boost::dynamic_pointer_cast< WPVString >( shared_from_this() );
}
WPropFilename WPropertyBase::toPropFilename()
{
return boost::static_pointer_cast< WPVFilename >( shared_from_this() );
return boost::dynamic_pointer_cast< WPVFilename >( shared_from_this() );
}
WPropSelection WPropertyBase::toPropSelection()
{
return boost::static_pointer_cast< WPVSelection >( shared_from_this() );
return boost::dynamic_pointer_cast< WPVSelection >( shared_from_this() );
}
WPropColor WPropertyBase::toPropColor()
{
return boost::static_pointer_cast< WPVColor >( shared_from_this() );
return boost::dynamic_pointer_cast< WPVColor >( shared_from_this() );
}
WPropPosition WPropertyBase::toPropPosition()
{
return boost::static_pointer_cast< WPVPosition >( shared_from_this() );
return boost::dynamic_pointer_cast< WPVPosition >( shared_from_this() );
}
WPropGroup WPropertyBase::toPropGroup()
{
return boost::static_pointer_cast< WPVGroup >( shared_from_this() );
return boost::dynamic_pointer_cast< WPVGroup >( shared_from_this() );
}
WPropertyGroupBase::SPtr WPropertyBase::toPropGroupBase()
{
return boost::static_pointer_cast< WPropertyGroupBase >( shared_from_this() );
return boost::dynamic_pointer_cast< WPropertyGroupBase >( shared_from_this() );
}
WPropMatrix4X4 WPropertyBase::toPropMatrix4X4()
{
return boost::static_pointer_cast< WPVMatrix4X4 >( shared_from_this() );
return boost::dynamic_pointer_cast< WPVMatrix4X4 >( shared_from_this() );
}
WPropTrigger WPropertyBase::toPropTrigger()
{
return boost::static_pointer_cast< WPVTrigger >( shared_from_this() );
return boost::dynamic_pointer_cast< WPVTrigger >( shared_from_this() );
}
WPropTransferFunction WPropertyBase::toPropTransferFunction()
{
return boost::static_pointer_cast< WPVTransferFunction >( shared_from_this() );
return boost::dynamic_pointer_cast< WPVTransferFunction >( shared_from_this() );
}
boost::shared_ptr< WCondition > WPropertyBase::getUpdateCondition() const
......@@ -185,6 +185,6 @@ boost::shared_ptr< WCondition > WPropertyBase::getUpdateCondition() const
WPropInterval WPropertyBase::toPropInterval()
{
return boost::static_pointer_cast< WPVInterval >( shared_from_this() );
return boost::dynamic_pointer_cast< WPVInterval >( shared_from_this() );
}
......@@ -29,6 +29,7 @@
#include <algorithm>
#include <boost/tokenizer.hpp>
#include <boost/algorithm/string/predicate.hpp>
#include "WStringUtils.h"
#include "WLogger.h"
......@@ -139,6 +140,43 @@ boost::shared_ptr< WPropertyBase > WPropertyGroupBase::findProperty( std::string
return result;
}
void WPropertyGroupBase::visitAsString( WPropertyGroupBase::PropertyStringVisitor visitor, std::string pathPrefix ) const
{
// read access
PropertySharedContainerType::ReadTicket r = getReadTicket();
for( PropertyConstIterator it = r->get().begin(); it != r->get().end(); ++it )
{
// path: handle some special cases:
std::string propName = pathPrefix + WPropertyGroupBase::separator + ( *it )->getName();
// 1: user added a separator
if( boost::algorithm::ends_with( pathPrefix, WPropertyGroupBase::separator ) )
{
propName = pathPrefix + ( *it )->getName();
}
// 2: avoid separator if prefix is empty
if( pathPrefix.empty() )
{
propName = ( *it )->getName();
}
// is it a group type?
WPropertyGroupBase::SPtr g = ( *it )->toPropGroupBase();
if( g )
{
// recurse down
g->visitAsString( visitor, propName );
}
else
{
// it is a leaf, call visitor
std::string value = ( *it )->getAsString();
visitor( propName, value );
}
}
}
bool WPropertyGroupBase::existsProperty( std::string name )
{
return ( findProperty( name ) != boost::shared_ptr< WPropertyBase >() );
......
......@@ -40,8 +40,6 @@
#include "WPropertyVariable.h"
#include "WSharedSequenceContainer.h"
/**
* This is the base class and interface for property groups. This class itself is abstract and derived from WPropertyBase. So if you create a
* group of properties, this ensures that your group is a property itself. This interface defines no way to add, remove or edit the property list
......@@ -167,6 +165,23 @@ public:
*/
virtual boost::shared_ptr< WPropertyBase > findProperty( std::string name ) const;
/**
* The visitor type used to visit properties as strings. The first parameter is the name, including the path of the property, relative to
* this group. The second parameter is the value as string.
*/
typedef boost::function< void ( std::string, std::string )> PropertyStringVisitor;
/**
* Visit all leafs in the property three that aren't empty groups. This is especially interesting when using it with lambda functionality.
* The visitor function gets two parameters: 1st: the name of the property, including the path beginning at this group; 2nd: the value as
* string.
*
* \param visitor the function to use for each property.
* \param pathPrefix add this prefix to the property name in the visitor. It might be interesting if manually implementing group visitors
* that always require a complete path, so you can add an upper-level path here.
*/
virtual void visitAsString( PropertyStringVisitor visitor, std::string pathPrefix = "" ) const;
protected:
/**
* Helping function to find a property inside a specific group. It does not recursively find properties nested inside other property groups.
......
......@@ -1105,6 +1105,11 @@ QSettings& WMainWindow::getSettings()
return WQt4Gui::getSettings();
}
void WMainWindow::setSetting( std::string key, std::string value )
{
WMainWindow::getSettings().setValue( QString::fromStdString( key ), QString::fromStdString( value ) );
}
void WMainWindow::handleLogLevelUpdate( unsigned int logLevel )
{
WLogger::getLogger()->setDefaultLogLevel( static_cast< LogLevel >( logLevel ) );
......
......@@ -151,6 +151,15 @@ public:
*/
static QSettings& getSettings();
/**
* Set a setting specified by a key to a given value. Abbreviation for the lazy programmer as it ensures proper typecast of std::string to
* the QSettings types (QString and QVariant).
*
* \param key the key
* \param value the value
*/
static void setSetting( std::string key, std::string value );
/**
* Get the current splash screen
*
......
......@@ -23,6 +23,10 @@
//---------------------------------------------------------------------------
#include <iostream>
#include <string>
#include <boost/function.hpp>
#include <boost/lambda/lambda.hpp>
#include <QtGui/QAction>
#include <QtGui/QWidgetAction>
......@@ -136,12 +140,42 @@ void WQtGLDockWidget::saveSettings()
{
m_screenCapture->saveSettings();
WQtDockWidget::saveSettings();
// visit the properties and save in QSettings. You cannot bind QSettings::setValue directly as the parameters need to be cast to QString and
// QVariant, which does not happen implicitly
m_glWidget->getViewer()->getProperties()->visitAsString( &WMainWindow::setSetting, m_dockTitle.toStdString() );
}
void WQtGLDockWidget::restoreSettings()
{
m_screenCapture->restoreSettings();
WQtDockWidget::restoreSettings();
// do not forget to load the config properties of the viewer
WMainWindow::getSettings().beginGroup( m_dockTitle );
QStringList keys = WMainWindow::getSettings().allKeys();
// iterate all the keys in the group of this viewer. QSettings does not implement a visitor mechanism, thus we iterate manually.
for( QStringList::const_iterator it = keys.constBegin(); it != keys.constEnd(); ++it )
{
std::string value = WMainWindow::getSettings().value( *it ).toString().toStdString();
std::string key = ( *it ).toStdString();
// NOTE: findProperty does not throw an exception, but setAsString.
WPropertyBase::SPtr prop = m_glWidget->getViewer()->getProperties()->findProperty( key );
if( prop )
{
// just in case something is going wrong (faulty setting): cannot cast string to property type. Be kind and ignore it.
try
{
prop->setAsString( value );
}
catch( ... )
{
// ignore faulty/old settings
}
}
}
WMainWindow::getSettings().endGroup();
}
boost::shared_ptr<WQtGLWidget>WQtGLDockWidget::getGLWidget() const
......
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