<commit_before>//
// This file is part of the Marble Desktop 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 2010      <NAME> <<EMAIL>>
//

// Self
#include "FileViewWidget.h"

// Qt
#include <QtGui/QSortFilterProxyModel>

// Marble
#include "GeoDataPlacemark.h"
#include "MarbleModel.h"
#include "MarbleWidget.h"
#include "FileViewModel.h"

using namespace Marble;
// Ui
#include "ui_FileViewWidget.h"

namespace Marble
{

class FileViewWidgetPrivate
{
 public:
    Ui::FileViewWidget  m_fileViewUi;
    MarbleWidget       *m_widget;

    QSortFilterProxyModel  *m_treeSortProxy;
};

FileViewWidget::FileViewWidget( QWidget *parent, Qt::WindowFlags f )
    : QWidget( parent, f ),
      d( new FileViewWidgetPrivate )
{
    d->m_fileViewUi.setupUi( this );
}

FileViewWidget::~FileViewWidget()
{
    delete d;
}

void FileViewWidget::setMarbleWidget( MarbleWidget *widget )
{
    //set up everything for the FileModel
    d->m_fileViewUi.m_fileView->setModel( widget->fileViewModel() );
    delete d->m_fileViewUi.m_fileView->selectionModel();
    d->m_fileViewUi.m_fileView->setSelectionModel( widget->fileViewModel()->selectionModel() );
    connect( d->m_fileViewUi.m_fileView->selectionModel(),
             SIGNAL( selectionChanged( QItemSelection, QItemSelection ) ),
             this,
             SLOT( enableFileViewActions() ) );
    connect( d->m_fileViewUi.m_saveButton,  SIGNAL( clicked() ) ,
             widget->fileViewModel(),       SLOT( saveFile() ) );
    connect( d->m_fileViewUi.m_closeButton, SIGNAL( clicked() ) ,
             widget->fileViewModel(),    SLOT( closeFile() ) );
    d->m_treeSortProxy = new QSortFilterProxyModel( this );
    d->m_treeSortProxy->setSourceModel( widget->model()->treeModel() );
    d->m_treeSortProxy->setDynamicSortFilter( true );
    d->m_fileViewUi.m_treeView->setModel( d->m_treeSortProxy );
    d->m_fileViewUi.m_treeView->setSortingEnabled( true );
    connect( d->m_fileViewUi.m_treeView, SIGNAL( activated( QModelIndex ) ),
             this, SLOT( mapCenterOnTreeViewModel( QModelIndex ) ) );
}

void FileViewWidget::enableFileViewActions()
{
    bool tmp = d->m_fileViewUi.m_fileView->selectionModel()->selectedIndexes().count() == 1;
    d->m_fileViewUi.m_saveButton->setEnabled( tmp );
    d->m_fileViewUi.m_closeButton->setEnabled( tmp );
}

void FileViewWidget::mapCenterOnTreeViewModel( const QModelIndex &index )<commit_msg>fileviewwidget: fix recenter crash<commit_after>//
// This file is part of the Marble Desktop 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 2010      <NAME> <<EMAIL>>
//

// Self
#include "FileViewWidget.h"

// Qt
#include <QtGui/QSortFilterProxyModel>

// Marble
#include "GeoDataPlacemark.h"
#include "MarbleModel.h"
#include "MarbleWidget.h"
#include "FileViewModel.h"

using namespace Marble;
// Ui
#include "ui_FileViewWidget.h"

namespace Marble
{

class FileViewWidgetPrivate
{
 public:
    Ui::FileViewWidget  m_fileViewUi;
    MarbleWidget       *m_widget;

    QSortFilterProxyModel  *m_treeSortProxy;
};

FileViewWidget::FileViewWidget( QWidget *parent, Qt::WindowFlags f )
    : QWidget( parent, f ),
      d( new FileViewWidgetPrivate )
{
    d->m_fileViewUi.setupUi( this );
}

FileViewWidget::~FileViewWidget()
{
    delete d;
}

void FileViewWidget::setMarbleWidget( MarbleWidget *widget )
{
    d->m_widget = widget;
    //set up everything for the FileModel
    d->m_fileViewUi.m_fileView->setModel( widget->fileViewModel() );
    delete d->m_fileViewUi.m_fileView->selectionModel();
    d->m_fileViewUi.m_fileView->setSelectionModel( widget->fileViewModel()->selectionModel() );
    connect( d->m_fileViewUi.m_fileView->selectionModel(),
             SIGNAL( selectionChanged( QItemSelection, QItemSelection ) ),
             this,
             SLOT( enableFileViewActions() ) );
    connect( d->m_fileViewUi.m_saveButton,  SIGNAL( clicked() ) ,
             widget->fileViewModel(),       SLOT( saveFile() ) );
    connect( d->m_fileViewUi.m_closeButton, SIGNAL( clicked() ) ,
             widget->fileViewModel(),    SLOT( closeFile() ) );
    d->m_treeSortProxy = new QSortFilterProxyModel( this );
    d->m_treeSortProxy->setSourceModel( widget->model()->treeModel() );
    d->m_treeSortProxy->setDynamicSortFilter( true );
    d->m_fileViewUi.m_treeView->setModel( d->m_treeSortProxy );
    d->m_fileViewUi.m_treeView->setSortingEnabled( true );
    connect( d->m_fileViewUi.m_treeView, SIGNAL( activated( QModelIndex ) ),
             this, SLOT( mapCenterOnTreeViewModel( QModelIndex ) ) );
}

void FileViewWidget::enableFileViewActions()
{
    bool tmp = d->m_fileViewUi.m_fileView->selectionModel()->selectedIndexes().count() == 1;
    d->m_fileViewUi.m_saveButton->setEnabled( tmp );
    d->m_fileViewUi.m_closeButton->setEnabled( tmp );
}

void FileViewWidget::mapCenterOnTreeViewModel( const QModelIndex &index )
{'fraction_non_alphanumeric': 0.12912678257472163, 'fraction_numerical': 0.0019535065442469234, 'mean_word_length': 3.8669201520912546, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 84, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7190694', 'n_tokens_mistral': 1688, 'n_tokens_neox': 1651, 'n_words': 335}