<commit_before>// 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 "DownloadRegionDialog.h"

#include <cmath>

#include <QtGui/QDialogButtonBox>
#include <QtGui/QGroupBox>
#include <QtGui/QHBoxLayout>
#include <QtGui/QLabel>
#include <QtGui/QPushButton>
#include <QtGui/QRadioButton>
#include <QtGui/QVBoxLayout>

#include "AbstractScanlineTextureMapper.h"
#include "GeoDataLatLonBox.h"
#include "GeoSceneTexture.h"
#include "MarbleDebug.h"
#include "MarbleMath.h"
#include "LatLonBoxWidget.h"
#include "TileId.h"
#include "TileLevelRangeWidget.h"
#include "TileLoaderHelper.h"
#include "ViewportParams.h"

namespace Marble
{

int const maxTilesCount = 100000;

class DownloadRegionDialog::Private
{
public:
    Private( ViewportParams const * const viewport,
             AbstractScanlineTextureMapper const * const textureMapper,
             QDialog * const dialog );
    QGroupBox * createSelectionMethodBox();
    QLayout * createTilesCounter();
    QWidget * createOkCancelButtonBox();

    int rad2PixelX( qreal const lon ) const;
    int rad2PixelY( qreal const lat ) const;

    QDialog * m_dialog;
    LatLonBoxWidget * m_latLonBoxWidget;
    TileLevelRangeWidget * m_tileLevelRangeWidget;
    QLabel * m_tilesCountLabel;
    QLabel * m_tilesCountLimitInfo;
    QPushButton * m_okButton;
    int m_originatingTileLevel;
    int m_minimumAllowedTileLevel;
    int m_maximumAllowedTileLevel;
    ViewportParams const * const m_viewport;
    AbstractScanlineTextureMapper const * const m_textureMapper;
    GeoSceneTexture const * const m_textureLayer;
    GeoDataLatLonBox m_visibleRegion;
};

DownloadRegionDialog::Private::Private( ViewportParams const * const viewport,
                                        AbstractScanlineTextureMapper const * const textureMapper,
                                        QDialog * const dialog )
    : m_dialog( dialog ),
      m_latLonBoxWidget( new LatLonBoxWidget ),
      m_tileLevelRangeWidget( new TileLevelRangeWidget ),
      m_tilesCountLabel( 0 ),
      m_tilesCountLimitInfo( 0 ),
      m_okButton( 0 ),
      m_originatingTileLevel( textureMapper->tileZoomLevel() ),
      m_minimumAllowedTileLevel( -1 ),
      m_maximumAllowedTileLevel( -1 ),
      m_viewport( viewport ),
      m_textureMapper( textureMapper ),
      m_textureLayer( textureMapper->textureLayer() ),
      m_visibleRegion( viewport->viewLatLonAltBox() )
{
    m_latLonBoxWidget->setEnabled( false );
    m_latLonBoxWidget->setLatLonBox( m_visibleRegion );
    m_tileLevelRangeWidget->setDefaultLevel( m_originatingTileLevel );
}

QGroupBox * DownloadRegionDialog::Private::createSelectionMethodBox()
{
    QRadioButton * const visibleRegionMethodButton = new QRadioButton( tr( "Visible region" ));
    visibleRegionMethodButton->setChecked( true );
    QRadioButton * const latLonBoxMethodButton = new QRadioButton( tr( "Specify region" ));
    connect( latLonBoxMethodButton, SIGNAL( toggled( bool )),
             m_dialog, SLOT( toggleSelectionMethod() ));

    QVBoxLayout * const layout = new QVBoxLayout;
    layout->addWidget( visibleRegionMethodButton );<commit_msg>DownloadRegionDialog::Private: change return type of createSelectionMethodBox from QGroupBox* to QWidget*.<commit_after>// 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 "DownloadRegionDialog.h"

#include <cmath>

#include <QtGui/QDialogButtonBox>
#include <QtGui/QGroupBox>
#include <QtGui/QHBoxLayout>
#include <QtGui/QLabel>
#include <QtGui/QPushButton>
#include <QtGui/QRadioButton>
#include <QtGui/QVBoxLayout>

#include "AbstractScanlineTextureMapper.h"
#include "GeoDataLatLonBox.h"
#include "GeoSceneTexture.h"
#include "MarbleDebug.h"
#include "MarbleMath.h"
#include "LatLonBoxWidget.h"
#include "TileId.h"
#include "TileLevelRangeWidget.h"
#include "TileLoaderHelper.h"
#include "ViewportParams.h"

namespace Marble
{

int const maxTilesCount = 100000;

class DownloadRegionDialog::Private
{
public:
    Private( ViewportParams const * const viewport,
             AbstractScanlineTextureMapper const * const textureMapper,
             QDialog * const dialog );
    QWidget * createSelectionMethodBox();
    QLayout * createTilesCounter();
    QWidget * createOkCancelButtonBox();

    int rad2PixelX( qreal const lon ) const;
    int rad2PixelY( qreal const lat ) const;

    QDialog * m_dialog;
    LatLonBoxWidget * m_latLonBoxWidget;
    TileLevelRangeWidget * m_tileLevelRangeWidget;
    QLabel * m_tilesCountLabel;
    QLabel * m_tilesCountLimitInfo;
    QPushButton * m_okButton;
    int m_originatingTileLevel;
    int m_minimumAllowedTileLevel;
    int m_maximumAllowedTileLevel;
    ViewportParams const * const m_viewport;
    AbstractScanlineTextureMapper const * const m_textureMapper;
    GeoSceneTexture const * const m_textureLayer;
    GeoDataLatLonBox m_visibleRegion;
};

DownloadRegionDialog::Private::Private( ViewportParams const * const viewport,
                                        AbstractScanlineTextureMapper const * const textureMapper,
                                        QDialog * const dialog )
    : m_dialog( dialog ),
      m_latLonBoxWidget( new LatLonBoxWidget ),
      m_tileLevelRangeWidget( new TileLevelRangeWidget ),
      m_tilesCountLabel( 0 ),
      m_tilesCountLimitInfo( 0 ),
      m_okButton( 0 ),
      m_originatingTileLevel( textureMapper->tileZoomLevel() ),
      m_minimumAllowedTileLevel( -1 ),
      m_maximumAllowedTileLevel( -1 ),
      m_viewport( viewport ),
      m_textureMapper( textureMapper ),
      m_textureLayer( textureMapper->textureLayer() ),
      m_visibleRegion( viewport->viewLatLonAltBox() )
{
    m_latLonBoxWidget->setEnabled( false );
    m_latLonBoxWidget->setLatLonBox( m_visibleRegion );
    m_tileLevelRangeWidget->setDefaultLevel( m_originatingTileLevel );
}

QWidget * DownloadRegionDialog::Private::createSelectionMethodBox()
{
    QRadioButton * const visibleRegionMethodButton = new QRadioButton( tr( "Visible region" ));
    visibleRegionMethodButton->setChecked( true );
    QRadioButton * const latLonBoxMethodButton = new QRadioButton( tr( "Specify region" ));
    connect( latLonBoxMethodButton, SIGNAL( toggled( bool )),
             m_dialog, SLOT( toggleSelectionMethod() ));

    QVBoxLayout * const layout = new QVBoxLayout;
    layout->addWidget( visibleRegionMethodButton );
{'fraction_non_alphanumeric': 0.084779440985561, 'fraction_numerical': 0.003974036296198172, 'mean_word_length': 4.023286759813706, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 37, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 13, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '950731', 'n_tokens_mistral': 2201, 'n_tokens_neox': 2170, 'n_words': 595}