<commit_before>//
// This file is part of the Marble Virtual Globe.
//
// This program is free software licensed under the GNU LGPL. You can
// find a copy of this license in LICENSE.txt in the top directory of
// the source code.
//
// Copyright 2006-2009 <NAME> <<EMAIL>>
// Copyright 2007      <NAME>  <<EMAIL>>
// Copyright 2008      <NAME> <<EMAIL>>
// Copyright 2009      <NAME> <<EMAIL>>
//


// Own
#include "MarbleMap.h"
#include "MarbleMap_p.h"

// Posix
#include <cmath>

// Qt
#include <QtCore/QAbstractItemModel>
#include <QtCore/QTime>
#include <QtCore/QTimer>
#include <QtGui/QItemSelectionModel>
#include <QtGui/QSizePolicy>
#include <QtGui/QRegion>

#ifdef MARBLE_DBUS
#include <QtDBus/QDBusConnection>
#endif

// Marble
#include "AbstractFloatItem.h"
#include "AbstractProjection.h"
#include "AbstractScanlineTextureMapper.h"
#include "GeoDataDocument.h"
#include "GeoDataFeature.h"
#include "GeoDataLatLonAltBox.h"
#include "GeoDataTreeModel.h"
#include "GeoPainter.h"
#include "GeoSceneDocument.h"
#include "GeoSceneHead.h"
#include "GeoSceneMap.h"
#include "GeoSceneVector.h"
#include "GeoSceneZoom.h"
#include "MarbleDebug.h"
#include "MarbleDirs.h"
#include "MarbleLocale.h"
#include "MarbleModel.h"
#include "MeasureTool.h"
#include "MergedLayerDecorator.h"
#include "PlacemarkLayout.h"
#include "Planet.h"
#include "RenderPlugin.h"
#include "SunLocator.h"
#include "TextureLayer.h"
#include "TileCoordsPyramid.h"
#include "TileCreator.h"
#include "TileCreatorDialog.h"
#include "TileLoader.h"
#include "ViewParams.h"
#include "ViewportParams.h"

using namespace Marble;
/* TRANSLATOR Marble::MarbleMap */

#ifdef Q_CC_MSVC
# ifndef KDEWIN_MATH_H
   static long double sqrt( int a ) { return sqrt( (long double)a ); }
# endif
#endif


MarbleMapPrivate::MarbleMapPrivate( MarbleMap *parent, MarbleModel *model )
        : m_parent( parent ),
          m_model( model ),
          m_backgroundVisible( true ),
          m_layerManager( model, parent ),
          m_textureLayer( model->mapThemeManager(), model->downloadManager(), model->sunLocator() ),
          m_placemarkLayout( model->placemarkModel(), model->placemarkSelectionModel(), parent ),
          m_measureTool( model ),
          m_viewAngle( 110.0 )
{
    GeoDataObject *object = static_cast<GeoDataObject*>( model->treeModel()->index(0, 0, QModelIndex()).internalPointer());
    GeoDataDocument *document = dynamic_cast<GeoDataDocument*>( object->parent() );
    m_geometryLayer = new GeometryLayer( document );
    m_layerManager.addLayer( m_geometryLayer );
}

void MarbleMapPrivate::construct()
{
    m_parent->connect( m_model, SIGNAL( themeChanged( QString ) ),
                       m_parent, SIGNAL( themeChanged( QString ) ) );
    m_parent->connect( m_model, SIGNAL( modelChanged() ),
                       m_parent, SIGNAL( repaintNeeded() ) );

    m_parent->connect( &m_veccomposer, SIGNAL( datasetLoaded() ),
                       m_parent, SIGNAL( repaintNeeded() ));

    QObject::connect( m_model->placemarkSelectionModel(), SIGNAL( selectionChanged( QItemSelection, QItemSelection) ),
                      &m_placemarkLayout,                 SLOT( requestStyleReset() ) );
    QObject::connect( m_model->placemarkModel(),          SIGNAL( layoutChanged() ),
                      &m_placemarkLayout,                 SLOT( requestStyleReset() ) );

    // FIXME: more on the spot update names and API
    QObject::connect ( &m_layerManager, SIGNAL( floatItemsChanged() ),
                       m_parent,        SIGNAL( repaintNeeded() ) );

    QObject::connect ( &m_layerManager, SIGNAL( pluginSettingsChanged() ),
                       m_parent,        SIGNAL( pluginSettingsChanged() ) );
    QObject::connect ( &m_layerManager, SIGNAL( repaintNeeded( QRegion ) ),
                       m_parent,        SIGNAL( repaintNeeded( QRegion ) ) );
    QObject::connect ( &m_layerManager, SIGNAL( renderPluginInitialized( RenderPlugin * ) ),
                       m_parent,        SIGNAL( renderPluginInitialized( RenderPlugin * ) ) );

    m_logzoom  = 0;

    // FloatItems
    m_showFrameRate = false;


    m_parent->connect( m_model->sunLocator(), SIGNAL( updateSun() ),
                       &m_textureLayer,       SLOT( update() ) );
    m_parent->connect( m_model->sunLocator(), SIGNAL( centerSun( qreal, qreal ) ),
                       m_parent,              SLOT( centerOn( qreal, qreal ) ) );

    m_parent->connect( &m_textureLayer, SIGNAL( tileLevelChanged( int ) ),
                       m_parent, SIGNAL( tileLevelChanged( int ) ) );
    m_parent->connect( &m_textureLayer, SIGNAL( repaintNeeded( QRegion ) ),
                       m_parent, SIGNAL( repaintNeeded( QRegion ) ) );
}

void  MarbleMapPrivate::paintMarbleSplash( GeoPainter &painter, QRect &dirtyRect )
{
    Q_UNUSED( dirtyRect )

    painter.save();

    QPixmap logoPixmap( MarbleDirs::path( "svg/marble-logo-inverted-72dpi.png" ) );

    if ( logoPixmap.width() > m_parent->width() * 0.7
         || logoPixmap.height() > m_parent->height() * 0.7 )
    {
        logoPixmap = logoPixmap.scaled( QSize( m_parent->width(), m_parent->height() ) * 0.7,
                                        Qt::KeepAspectRatio, Qt::SmoothTransformation );
    }

    QPoint logoPosition( ( m_parent->width()  - logoPixmap.width() ) / 2,
                            ( m_parent->height() - logoPixmap.height() ) / 2 );
    painter.drawPixmap( logoPosition, logoPixmap );

    QString message; // "Please assign a map theme!";

    painter.setPen( Qt::white );

    int yTop = logoPosition.y() + logoPixmap.height() + 10;
    QRect textRect( 0, yTop,
                    m_parent->width(), m_parent->height() - yTop );
    painter.drawText( textRect, Qt::AlignHCenter | Qt::AlignTop, message ); 

    painter.restore();
}

void MarbleMapPrivate::paintGround( GeoPainter &painter, QRect &dirtyRect )
{
    if ( !m_viewParams.mapTheme() ) {
        mDebug() << "No theme yet!";
        paintMarbleSplash( painter, dirtyRect );
        return;
    }

    QStringList renderPositions;

    if ( m_backgroundVisible ) {
        renderPositions << "STARS" << "BEHIND_TARGET";
        m_layerManager.renderLayers( &painter, &m_viewParams, renderPositions );
    }

    if ( m_viewParams.showAtmosphere() ) {
        m_atmosphereLayer.render( &painter, m_viewParams.viewport() );
    }

    m_textureLayer.paintGlobe( &painter, &m_viewParams, dirtyRect );

    renderPositions.clear();
    renderPositions << "SURFACE";

    // Paint the vector layer.
    if ( m_model->mapTheme()->map()->hasVectorLayers() ) {

        if ( !m_model->mapTheme()->map()->hasTextureLayers() ) {
            m_veccomposer.paintBaseVectorMap( &painter, &m_viewParams );
        }

        m_layerManager.renderLayers( &painter, &m_viewParams, renderPositions );
<commit_msg>Changes: Don't paint the texture layer for the "Plain Map"<commit_after>//
// This file is part of the Marble Virtual Globe.
//
// This program is free software licensed under the GNU LGPL. You can
// find a copy of this license in LICENSE.txt in the top directory of
// the source code.
//
// Copyright 2006-2009 <NAME> <<EMAIL>>
// Copyright 2007      <NAME>  <<EMAIL>>
// Copyright 2008      <NAME> <<EMAIL>>
// Copyright 2009      <NAME> <<EMAIL>>
//


// Own
#include "MarbleMap.h"
#include "MarbleMap_p.h"

// Posix
#include <cmath>

// Qt
#include <QtCore/QAbstractItemModel>
#include <QtCore/QTime>
#include <QtCore/QTimer>
#include <QtGui/QItemSelectionModel>
#include <QtGui/QSizePolicy>
#include <QtGui/QRegion>

#ifdef MARBLE_DBUS
#include <QtDBus/QDBusConnection>
#endif

// Marble
#include "AbstractFloatItem.h"
#include "AbstractProjection.h"
#include "AbstractScanlineTextureMapper.h"
#include "GeoDataDocument.h"
#include "GeoDataFeature.h"
#include "GeoDataLatLonAltBox.h"
#include "GeoDataTreeModel.h"
#include "GeoPainter.h"
#include "GeoSceneDocument.h"
#include "GeoSceneHead.h"
#include "GeoSceneMap.h"
#include "GeoSceneVector.h"
#include "GeoSceneZoom.h"
#include "MarbleDebug.h"
#include "MarbleDirs.h"
#include "MarbleLocale.h"
#include "MarbleModel.h"
#include "MeasureTool.h"
#include "MergedLayerDecorator.h"
#include "PlacemarkLayout.h"
#include "Planet.h"
#include "RenderPlugin.h"
#include "SunLocator.h"
#include "TextureLayer.h"
#include "TileCoordsPyramid.h"
#include "TileCreator.h"
#include "TileCreatorDialog.h"
#include "TileLoader.h"
#include "ViewParams.h"
#include "ViewportParams.h"

using namespace Marble;
/* TRANSLATOR Marble::MarbleMap */

#ifdef Q_CC_MSVC
# ifndef KDEWIN_MATH_H
   static long double sqrt( int a ) { return sqrt( (long double)a ); }
# endif
#endif


MarbleMapPrivate::MarbleMapPrivate( MarbleMap *parent, MarbleModel *model )
        : m_parent( parent ),
          m_model( model ),
          m_backgroundVisible( true ),
          m_layerManager( model, parent ),
          m_textureLayer( model->mapThemeManager(), model->downloadManager(), model->sunLocator() ),
          m_placemarkLayout( model->placemarkModel(), model->placemarkSelectionModel(), parent ),
          m_measureTool( model ),
          m_viewAngle( 110.0 )
{
    GeoDataObject *object = static_cast<GeoDataObject*>( model->treeModel()->index(0, 0, QModelIndex()).internalPointer());
    GeoDataDocument *document = dynamic_cast<GeoDataDocument*>( object->parent() );
    m_geometryLayer = new GeometryLayer( document );
    m_layerManager.addLayer( m_geometryLayer );
}

void MarbleMapPrivate::construct()
{
    m_parent->connect( m_model, SIGNAL( themeChanged( QString ) ),
                       m_parent, SIGNAL( themeChanged( QString ) ) );
    m_parent->connect( m_model, SIGNAL( modelChanged() ),
                       m_parent, SIGNAL( repaintNeeded() ) );

    m_parent->connect( &m_veccomposer, SIGNAL( datasetLoaded() ),
                       m_parent, SIGNAL( repaintNeeded() ));

    QObject::connect( m_model->placemarkSelectionModel(), SIGNAL( selectionChanged( QItemSelection, QItemSelection) ),
                      &m_placemarkLayout,                 SLOT( requestStyleReset() ) );
    QObject::connect( m_model->placemarkModel(),          SIGNAL( layoutChanged() ),
                      &m_placemarkLayout,                 SLOT( requestStyleReset() ) );

    // FIXME: more on the spot update names and API
    QObject::connect ( &m_layerManager, SIGNAL( floatItemsChanged() ),
                       m_parent,        SIGNAL( repaintNeeded() ) );

    QObject::connect ( &m_layerManager, SIGNAL( pluginSettingsChanged() ),
                       m_parent,        SIGNAL( pluginSettingsChanged() ) );
    QObject::connect ( &m_layerManager, SIGNAL( repaintNeeded( QRegion ) ),
                       m_parent,        SIGNAL( repaintNeeded( QRegion ) ) );
    QObject::connect ( &m_layerManager, SIGNAL( renderPluginInitialized( RenderPlugin * ) ),
                       m_parent,        SIGNAL( renderPluginInitialized( RenderPlugin * ) ) );

    m_logzoom  = 0;

    // FloatItems
    m_showFrameRate = false;


    m_parent->connect( m_model->sunLocator(), SIGNAL( updateSun() ),
                       &m_textureLayer,       SLOT( update() ) );
    m_parent->connect( m_model->sunLocator(), SIGNAL( centerSun( qreal, qreal ) ),
                       m_parent,              SLOT( centerOn( qreal, qreal ) ) );

    m_parent->connect( &m_textureLayer, SIGNAL( tileLevelChanged( int ) ),
                       m_parent, SIGNAL( tileLevelChanged( int ) ) );
    m_parent->connect( &m_textureLayer, SIGNAL( repaintNeeded( QRegion ) ),
                       m_parent, SIGNAL( repaintNeeded( QRegion ) ) );
}

void  MarbleMapPrivate::paintMarbleSplash( GeoPainter &painter, QRect &dirtyRect )
{
    Q_UNUSED( dirtyRect )

    painter.save();

    QPixmap logoPixmap( MarbleDirs::path( "svg/marble-logo-inverted-72dpi.png" ) );

    if ( logoPixmap.width() > m_parent->width() * 0.7
         || logoPixmap.height() > m_parent->height() * 0.7 )
    {
        logoPixmap = logoPixmap.scaled( QSize( m_parent->width(), m_parent->height() ) * 0.7,
                                        Qt::KeepAspectRatio, Qt::SmoothTransformation );
    }

    QPoint logoPosition( ( m_parent->width()  - logoPixmap.width() ) / 2,
                            ( m_parent->height() - logoPixmap.height() ) / 2 );
    painter.drawPixmap( logoPosition, logoPixmap );

    QString message; // "Please assign a map theme!";

    painter.setPen( Qt::white );

    int yTop = logoPosition.y() + logoPixmap.height() + 10;
    QRect textRect( 0, yTop,
                    m_parent->width(), m_parent->height() - yTop );
    painter.drawText( textRect, Qt::AlignHCenter | Qt::AlignTop, message ); 

    painter.restore();
}

void MarbleMapPrivate::paintGround( GeoPainter &painter, QRect &dirtyRect )
{
    if ( !m_viewParams.mapTheme() ) {
        mDebug() << "No theme yet!";
        paintMarbleSplash( painter, dirtyRect );
        return;
    }

    QStringList renderPositions;

    if ( m_backgroundVisible ) {
        renderPositions << "STARS" << "BEHIND_TARGET";
        m_layerManager.renderLayers( &painter, &m_viewParams, renderPositions );
    }

    if ( m_viewParams.showAtmosphere() ) {
        m_atmosphereLayer.render( &painter, m_viewParams.viewport() );
    }

    if ( m_model->mapTheme()->map()->hasTextureLayers() ) {
        m_textureLayer.paintGlobe( &painter, &m_viewParams, dirtyRect );
    }

    renderPositions.clear();
    renderPositions << "SURFACE";

    // Paint the vector layer.
    if ( m_model->mapTheme()->map()->hasVectorLayers() ) {

        if ( !m_model->mapTheme()->map()->hasTextureLayers() ) {
            m_veccomposer.paintBaseVectorMap( &painter, &m_viewParams );
        }

        m_layerManager.renderLayers( &painter, &m_viewParams, renderPositions );

{'fraction_non_alphanumeric': 0.1319863362162948, 'fraction_numerical': 0.005814376044770695, 'mean_word_length': 3.062592264540892, 'pattern_counts': {'":': 0, '<': 63, '<?xml version=': 0, '>': 120, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5072020', 'n_tokens_mistral': 4578, 'n_tokens_neox': 4347, 'n_words': 905}