[Marble-devel] [PATCH 13/13] Make switching clouds layer on/off work again.

Torsten Rahn tackat at t-online.de
Wed Mar 31 09:47:01 CEST 2010


As we had discussed already some of the stuff should really go into 

Viewparams->mapTheme() (for per-maptheme settings)

or

into a global GeoSceneSettings object inside ViewParams.
 
So those two would get passed instead of the whole ViewParams (and 
MapThemeSettings would get removed).

But as a temporary solution it looks fine to me.


On Dienstag 30 März 2010 20:37:57 Jens-Michael Hoffmann wrote:
> Make switching clouds layer on/off work again.
>  This fixes a regression introduced by the tileloader refactoring.
> 
> The approach taken is to store the clouds settings in a new class
> MapThemeSettings, which is basically a thin wrapper around a
> map<layername, on/off>. These settings reside in MarbleModel and
> are handed to the TileLoader, which can then decide which layer
> to use.
> 
> Open questions/remaining issues:
> - New method StackedTileLoader::reset() really needed?
>   Or better adjust one of the existing ones?
> - Use ViewParams to store settings, however I tend to not be entirely
>   happy with passing ViewParams to the StackedTileLoader.
> ---
>  marble/src/lib/CMakeLists.txt        |    1 +
>  marble/src/lib/MapThemeSettings.cpp  |   35
> ++++++++++++++++++++++++++++++++ marble/src/lib/MapThemeSettings.h    |  
> 37 ++++++++++++++++++++++++++++++++++ marble/src/lib/MarbleMap.cpp        
> |   10 +++-----
>  marble/src/lib/MarbleModel.cpp       |   21 +++++++++++++++++-
>  marble/src/lib/MarbleModel.h         |    6 +++-
>  marble/src/lib/StackedTileLoader.cpp |   26 ++++++++++++++++++++---
>  marble/src/lib/StackedTileLoader.h   |    5 ++-
>  8 files changed, 125 insertions(+), 16 deletions(-)
>  create mode 100644 marble/src/lib/MapThemeSettings.cpp
>  create mode 100644 marble/src/lib/MapThemeSettings.h
> 
> diff --git a/marble/src/lib/CMakeLists.txt b/marble/src/lib/CMakeLists.txt
> index 88a84c4..89615f3 100644
> --- a/marble/src/lib/CMakeLists.txt
> +++ b/marble/src/lib/CMakeLists.txt
> @@ -63,6 +63,7 @@ set(marblewidget_SRCS
>      blendings/BlendingAlgorithms.cpp
>      blendings/BlendingFactory.cpp
>      blendings/SunLightBlending.cpp
> +    MapThemeSettings.cpp
>      MarbleWidget.cpp
>      MarbleModel.cpp
>      MarbleMap.cpp
> diff --git a/marble/src/lib/MapThemeSettings.cpp
> b/marble/src/lib/MapThemeSettings.cpp new file mode 100644
> index 0000000..4753bdd
> --- /dev/null
> +++ b/marble/src/lib/MapThemeSettings.cpp
> @@ -0,0 +1,35 @@
> +// Copyright 2010 Jens-Michael Hoffmann <jmho at c-xx.com>
> +//
> +// This library 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 2.1 of the License, or (at your option) any later version.
> +//
> +// This library 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 Lesser General Public
> +// License along with this library. If not, see
> <http://www.gnu.org/licenses/>. +
> +#include "MapThemeSettings.h"
> +
> +namespace Marble
> +{
> +
> +bool MapThemeSettings::isEnabled( QString const & layer ) const
> +{
> +    QMap<QString, bool>::const_iterator const pos = m_settings.constFind(
> layer ); +    if ( pos != m_settings.constEnd() )
> +        return pos.value();
> +    else
> +        return false;
> +}
> +
> +void MapThemeSettings::setEnabled( QString const & layer, bool const
> enable ) +{
> +    m_settings[ layer ] = enable;
> +}
> +
> +}
> diff --git a/marble/src/lib/MapThemeSettings.h
> b/marble/src/lib/MapThemeSettings.h new file mode 100644
> index 0000000..06aad82
> --- /dev/null
> +++ b/marble/src/lib/MapThemeSettings.h
> @@ -0,0 +1,37 @@
> +// Copyright 2010 Jens-Michael Hoffmann <jmho at c-xx.com>
> +//
> +// This library 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 2.1 of the License, or (at your option) any later version.
> +//
> +// This library 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 Lesser General Public
> +// License along with this library. If not, see
> <http://www.gnu.org/licenses/>. +
> +#ifndef MARBLE_MAP_THEME_SETTINGS_H
> +#define MARBLE_MAP_THEME_SETTINGS_H
> +
> +#include <QtCore/QMap>
> +#include <QtCore/QString>
> +
> +namespace Marble
> +{
> +
> +class MapThemeSettings
> +{
> + public:
> +    bool isEnabled( QString const & layer ) const;
> +    void setEnabled( QString const & layer, bool const enable = true );
> +
> + private:
> +    QMap<QString, bool> m_settings;
> +};
> +
> +}
> +
> +#endif
> diff --git a/marble/src/lib/MarbleMap.cpp b/marble/src/lib/MarbleMap.cpp
> index 8bb64d6..7260778 100644
> --- a/marble/src/lib/MarbleMap.cpp
> +++ b/marble/src/lib/MarbleMap.cpp
> @@ -635,8 +635,7 @@ bool MarbleMap::showGrid() const
> 
>  bool MarbleMap::showClouds() const
>  {
> -    // TODO
> -    return true;
> +    return d->m_model->showClouds();
>  }
> 
>  bool MarbleMap::showAtmosphere() const
> @@ -1034,16 +1033,15 @@ void MarbleMap::setShowCrosshairs( bool visible )
> 
>  void MarbleMap::setShowClouds( bool visible )
>  {
> -    // TODO
> +    d->m_model->setShowClouds( visible );
> +    setNeedsUpdate();
>  }
> 
>  void MarbleMap::setShowTileId( bool visible )
>  {
> -
>      d->m_model->layerDecorator()->setShowTileId( visible );
> -
> -
>  }
> +
>  void MarbleMap::setShowGrid( bool visible )
>  {
>      setPropertyValue( "coordinate-grid", visible );
> diff --git a/marble/src/lib/MarbleModel.cpp
> b/marble/src/lib/MarbleModel.cpp index 7420c8d..45313e4 100644
> --- a/marble/src/lib/MarbleModel.cpp
> +++ b/marble/src/lib/MarbleModel.cpp
> @@ -24,6 +24,7 @@
>  #include <QtGui/QSortFilterProxyModel>
> 
>  #include "MapThemeManager.h"
> +#include "MapThemeSettings.h"
>  #include "global.h"
>  #include "MarbleDebug.h"
>  #include "gps/GpsLayer.h"
> @@ -87,6 +88,7 @@ class MarbleModelPrivate
>            m_dataFacade( 0 ),
>            m_pluginManager( new PluginManager( parent ) ),
>            m_mapThemeManager( new MapThemeManager( parent )),
> +          m_mapThemeSettings( new MapThemeSettings ),
>            m_mapTheme( 0 ),
>            m_layerManager( 0 ),
>            m_downloadManager( new HttpDownloadManager( new
> FileStoragePolicy( @@ -100,6 +102,7 @@ class MarbleModelPrivate
>      ~MarbleModelPrivate()
>      {
>          delete m_downloadManager;
> +        delete m_mapThemeSettings;
>      }
> 
>      void resize( int width, int height );
> @@ -111,6 +114,7 @@ class MarbleModelPrivate
> 
>      PluginManager           *m_pluginManager;
>      MapThemeManager         *m_mapThemeManager;
> +    MapThemeSettings        *m_mapThemeSettings;
> 
>      // View and paint stuff
>      GeoSceneDocument        *m_mapTheme;
> @@ -161,8 +165,8 @@ MarbleModel::MarbleModel( QObject *parent )
>      MarbleModelPrivate::refCounter.ref();
>      d->m_dataFacade = new MarbleDataFacade( this );
> 
> -    d->m_tileLoader = new StackedTileLoader( d->m_mapThemeManager,
> d->m_downloadManager, this ); -
> +    d->m_tileLoader = new StackedTileLoader( d->m_mapThemeManager,
> d->m_mapThemeSettings, +                                            
> d->m_downloadManager, this ); d->m_texmapper = 0;
> 
>      d->m_fileManager = new FileManager();
> @@ -266,6 +270,19 @@ bool MarbleModel::showGps() const
>      return d->m_gpsLayer->visible();
>  }
> 
> +bool MarbleModel::showClouds() const
> +{
> +    return d->m_mapThemeSettings->isEnabled( "clouds_data" );
> +}
> +
> +void MarbleModel::setShowClouds( bool const visible )
> +{
> +    if ( visible == d->m_mapThemeSettings->isEnabled(  "clouds_data" ))
> +        return;
> +    d->m_mapThemeSettings->setEnabled( "clouds_data", visible );
> +    d->m_tileLoader->reset();
> +}
> +
>  void MarbleModel::setShowGps( bool visible )
>  {
>      d->m_gpsLayer->setVisible( visible );
> diff --git a/marble/src/lib/MarbleModel.h b/marble/src/lib/MarbleModel.h
> index cd21fe9..e522cb6 100644
> --- a/marble/src/lib/MarbleModel.h
> +++ b/marble/src/lib/MarbleModel.h
> @@ -225,13 +225,15 @@ class MARBLE_EXPORT MarbleModel : public QObject
>       * @return The Gps Data visibility.
>       */
>      bool showGps() const;
> +    bool showClouds() const;
> 
> -    /**
> +    void setShowClouds( bool const visible );
> +   /**
>       * @brief Set whether the Gps Data is visible.
>       * @param visible visibility of the Gps Data.
>       */
>      void setShowGps( bool visible );
> -
> +
>      /**
>       * @brief Start the model's timer polling
>       * @param time the amount of milliseconds between each poll
> diff --git a/marble/src/lib/StackedTileLoader.cpp
> b/marble/src/lib/StackedTileLoader.cpp index 0452f59..145998d 100644
> --- a/marble/src/lib/StackedTileLoader.cpp
> +++ b/marble/src/lib/StackedTileLoader.cpp
> @@ -31,6 +31,7 @@
>  #include "GeoSceneTexture.h"
>  #include "HttpDownloadManager.h"
>  #include "MapThemeManager.h"
> +#include "MapThemeSettings.h"
>  #include "MarbleDebug.h"
>  #include "MarbleDirs.h"
>  #include "MarbleModel.h"
> @@ -61,7 +62,8 @@ public:
>      StackedTileLoaderPrivate()
> 
>          : m_datasetProvider( 0 ),
> 
>            m_mapThemeManager( 0 ),
> -          m_tileLoader( 0 )
> +          m_tileLoader( 0 ),
> +          m_settings( 0 )
>      {
>          m_tileCache.setMaxCost( 20000 * 1024 ); // Cache size measured in
> bytes }
> @@ -74,16 +76,19 @@ public:
>      TileLoader *m_tileLoader;
>      QHash <TileId, StackedTile*>  m_tilesOnDisplay;
>      QCache <TileId, StackedTile>  m_tileCache;
> +    MapThemeSettings const * m_settings;
>  };
> 
> 
>  StackedTileLoader::StackedTileLoader( MapThemeManager const * const
> mapThemeManager, +                                      MapThemeSettings
> const * const settings, HttpDownloadManager * const downloadManager,
> MarbleModel * const model )
> 
>      : d( new StackedTileLoaderPrivate ),
> 
>        m_parent( model )
>  {
>      d->m_mapThemeManager = mapThemeManager;
> +    d->m_settings = settings;
>      initTextureLayers();
>      d->m_tileLoader = new TileLoader( mapThemeManager, downloadManager );
>      d->m_tileLoader->setTextureLayers( d->m_textureLayers );
> @@ -251,6 +256,12 @@ StackedTile* StackedTileLoader::reloadTile( TileId
> const & stackedTileId ) return stackedTile;
>  }
> 
> +void StackedTileLoader::reset()
> +{
> +    d->m_tilesOnDisplay.clear();
> +    d->m_tileCache.clear();
> +}
> +
>  quint64 StackedTileLoader::volatileCacheLimit() const
>  {
>      return d->m_tileCache.maxCost() / 1024;
> @@ -391,9 +402,16 @@ StackedTileLoader::findRelevantTextureLayers( TileId
> const & stackedTileId ) con
> QVector<GeoSceneAbstractDataset*>::const_iterator const end =
> textureLayers.constEnd(); for (; pos != end; ++pos ) {
>          GeoSceneTexture const * const candidate =
> dynamic_cast<GeoSceneTexture const *>( *pos ); -        if ( candidate &&
> ( !candidate->hasMaximumTileLevel()
> -                            || stackedTileId.zoomLevel() <=
> candidate->maximumTileLevel() )) { -            result.append( candidate
> );
> +        if ( candidate ) {
> +            // FIXME (hack): first layer is always enabled
> +            bool const enabled = ( pos == textureLayers.constBegin() )
> +                || d->m_settings->isEnabled( candidate->name() );
> +            mDebug() << "StackedTileLoader::findRelevantTextureLayers:
> checking" << candidate->name() +                     << ( enabled ?
> "enabled" : "disabled" );
> +            if ( enabled && ( !candidate->hasMaximumTileLevel()
> +                              || stackedTileId.zoomLevel() <=
> candidate->maximumTileLevel() )) { +                result.append(
> candidate );
> +            }
>          }
>      }
>      return result;
> diff --git a/marble/src/lib/StackedTileLoader.h
> b/marble/src/lib/StackedTileLoader.h index 335816c..dc414d0 100644
> --- a/marble/src/lib/StackedTileLoader.h
> +++ b/marble/src/lib/StackedTileLoader.h
> @@ -32,10 +32,10 @@ class QString;
> 
>  namespace Marble
>  {
> -
>  class StackedTile;
>  class HttpDownloadManager;
>  class MapThemeManager;
> +class MapThemeSettings;
>  class MarbleModel;
>  class GeoSceneLayer;
>  class GeoSceneTexture;
> @@ -67,6 +67,7 @@ class StackedTileLoader : public QObject
>           *                        the tiles from a remote resource.
>           */
>          StackedTileLoader( MapThemeManager const * const mapThemeManager,
> +                           MapThemeSettings const * const settings,
>                             HttpDownloadManager * const downloadManager,
> MarbleModel * const model ); virtual ~StackedTileLoader();
> 
> @@ -83,8 +84,8 @@ class StackedTileLoader : public QObject
>           *                      and the zoom level.
>           */
>          StackedTile* loadTile( TileId const &stackedTileId );
> -
>          StackedTile* reloadTile( TileId const & stackedTileId );
> +        void reset();
> 
>          /**
>           * Resets the internal tile hash.



More information about the Marble-devel mailing list