<commit_before>/*Copyright 2010 <NAME>

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.*/

#include "myflattreeview.h"

using namespace GUtil::QtUtil;

myFlatTreeView::myFlatTreeView(QObject *parent) :
    QAbstractProxyModel(parent)
{
}

void myFlatTreeView::setSourceModel(QAbstractItemModel *m)
{
    QAbstractProxyModel::setSourceModel(m);

    if(m)
    {
        // So we can reset ourself when something changes
        connect(m, SIGNAL(rowsInserted(QModelIndex, int, int)),
                this, SLOT(source_model_rows_inserted(QModelIndex,int,int)));
        connect(m, SIGNAL(rowsRemoved(QModelIndex, int, int)),
                this, SLOT(source_model_rows_removed(QModelIndex,int,int)));
        connect(m, SIGNAL(modelReset()), this, SLOT(_reset_model()));
    }
    else
    {
        disconnect(this, SLOT(source_model_rows_inserted(QModelIndex,int,int)));
        disconnect(this, SLOT(source_model_rows_removed(QModelIndex,int,int)));
        disconnect(this, SLOT(_reset_model()));
    }

    _reset_model();
}

void myFlatTreeView::source_model_rows_inserted(const QModelIndex &ind,
                                                int start, int end)
{
    _reset_model();
}

void myFlatTreeView::source_model_rows_removed(const QModelIndex &ind,
                                               int start, int end)
{
    _reset_model();
}

void myFlatTreeView::_reset_model()
{
    beginResetModel();

    // This is an expensive operation, so we only do it when we have to, storing
    //  the results we calculate for quick lookup later
    _refresh_child_record();

    reset();
    endResetModel();
}

void myFlatTreeView::_refresh_child_record()
{
    _child_record.clear();
    _total_rows = 0;

    QAbstractItemModel *m = sourceModel();
    if(m)
    {
        int c = sourceModel()->rowCount();
        for(int i = 0; i < c; i++)
        {
            _total_rows += _count_child_indexes(m->index(i, 0));
        }
    }
}<commit_msg>Minor improvement of logic; not worth writing home about though<commit_after>/*Copyright 2010 <NAME>

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.*/

#include "myflattreeview.h"

using namespace GUtil::QtUtil;

myFlatTreeView::myFlatTreeView(QObject *parent) :
    QAbstractProxyModel(parent)
{
}

void myFlatTreeView::setSourceModel(QAbstractItemModel *m)
{
    QAbstractProxyModel::setSourceModel(m);

    if(m)
    {
        // So we can reset ourself when something changes
        connect(m, SIGNAL(rowsInserted(QModelIndex, int, int)),
                this, SLOT(source_model_rows_inserted(QModelIndex,int,int)));
        connect(m, SIGNAL(rowsRemoved(QModelIndex, int, int)),
                this, SLOT(source_model_rows_removed(QModelIndex,int,int)));
        connect(m, SIGNAL(modelReset()), this, SLOT(_reset_model()));
    }
    else
    {
        disconnect(this, SLOT(source_model_rows_inserted(QModelIndex,int,int)));
        disconnect(this, SLOT(source_model_rows_removed(QModelIndex,int,int)));
        disconnect(this, SLOT(_reset_model()));
    }

    _reset_model();
}

void myFlatTreeView::source_model_rows_inserted(const QModelIndex &ind,
                                                int start, int end)
{
    _reset_model();
}

void myFlatTreeView::source_model_rows_removed(const QModelIndex &ind,
                                               int start, int end)
{
    _reset_model();
}

void myFlatTreeView::_reset_model()
{
    beginResetModel();

    // This is an expensive operation, so we only do it when we have to, storing
    //  the results we calculate for quick lookup later
    _refresh_child_record();

    reset();
    endResetModel();
}

void myFlatTreeView::_refresh_child_record()
{
    _child_record.clear();
    _total_rows = 0;

    QAbstractItemModel *m = sourceModel();
    if(m)
    {
        for(int i = sourceModel()->rowCount() - 1; i >= 0; i--)
        {
            _total_rows += _count_child_indexes(m->index(i, 0));
        }
    }
}
{'fraction_non_alphanumeric': 0.10118078175895766, 'fraction_numerical': 0.004682410423452769, 'mean_word_length': 3.1741716227697534, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 10, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6482450', 'n_tokens_mistral': 1499, 'n_tokens_neox': 1459, 'n_words': 395}