<commit_before>#include "listview/qrlistview.h"

#include <QtCore/qdebug.h>
#include <QtCore/qtimer.h>
#include <QtCore/qqueue.h>
#include <QtWidgets/qscrollbar.h>
#include <QtGui/qevent.h>
#include <QWheelEvent>
#include <QPoint>

NS_QRWIDGETS_BEGIN

///////////////////////////////////////////////////////

class QrListViewPrivate {
public:
    std::list<QWidget*> itemWidgets;
    QrListVidewDelegate *delegate = nullptr;

    int itemHeight = 1;
    int itemsHeight = 1;
    int oldDatasetSize = 0;
};

///////////////////////////////////////////////////////

class QrListViewDataPrivate {
};

///////////////////////////////////////////////////////

class QrListVidewDelegatePrivate {
public:
    bool watingFilter = false;
    QQueue<QRegExp> filterQueue;

    QVector<QrListViewData*> rawDataset;
    QVector<QrListViewData*> viewDataset;
    QMap<int, QrListViewData*> mapDataset;

public:
    virtual ~QrListVidewDelegatePrivate();
};

///////////////////////////////////////////////////////

QrListVidewDelegatePrivate::~QrListVidewDelegatePrivate()
{
    Q_FOREACH(QrListViewData* data, rawDataset) {
        delete data;
        data = nullptr;
    }
}

NS_QRWIDGETS_END

USING_NS_QRWIDGETS;

///////////////////////////////////////////////////////

QrListVidewDelegate::QrListVidewDelegate()
    : d_ptr(new QrListVidewDelegatePrivate)
{

}

void QrListVidewDelegate::managerData(QrListViewData *data)
{
    if(nullptr == data) {
        qDebug() << "list view can't mananger nullptr data";
        return;
    }

    Q_D(QrListVidewDelegate);
    d->rawDataset.push_back(data);
    d->mapDataset[data->key()] = data;
    d->viewDataset.push_back(data);
}

QrListViewData *QrListVidewDelegate::getData(int key)
{
    Q_D(QrListVidewDelegate);
    if(! d->mapDataset.contains(key)) {
        qDebug() << "listview's delegate havn't data of " << key;
        return nullptr;
    }

    return d->mapDataset[key];
}

void QrListVidewDelegate::filter(const QRegExp &regExp)
{
    Q_D(QrListVidewDelegate);
    int limitSize = 10;
    if(d->filterQueue.size() > limitSize) {
        for(int i=0; i<limitSize/2; i++) {
            d->filterQueue.removeAt(i);
        }
    }
    d->filterQueue.append(regExp);
    if (d->watingFilter) {
        qDebug() << "waiting filter";
        return;
    }

    d->watingFilter = true;
    QTimer::singleShot(500, this, [this](){
        qDebug() << "filter!";

        Q_D(QrListVidewDelegate);
        d->viewDataset.clear();
        Q_FOREACH(QrListViewData* data, d->rawDataset) {
            if(! data->filter(d->filterQueue.last())) {
                continue;
            }
            d->viewDataset.push_back(data);
        }
        emit dataChanged();

        d->watingFilter = false;
        qDebug() << "filter finish!";
    });
}

int QrListVidewDelegate::itemsSize() const
{
    Q_D(const QrListVidewDelegate);
    return d->viewDataset.size();
}

void QrListVidewDelegate::setItemWidgetByIndex(int index, QWidget *itemWidget)
{
    Q_D(QrListVidewDelegate);
    if(index > d->viewDataset.size()) {
        qDebug() << "list size is smaller than " << index;
        return;
    }

    QrListViewData* data = d->viewDataset[index];
    if(nullptr == data) {
        qDebug() << "cell's data is nullptr";
        return;
    }

    setItemWidgetByData(data, itemWidget);
}

///////////////////////////////////////////////////////

QrListViewData::QrListViewData()
    : d_ptr(new QrListViewDataPrivate)
{

}

int Qters::QrWidgets::QrListViewData::key() const
{
    return -1;
}

bool QrListViewData::filter(const QRegExp& regExp) const
{
    Q_UNUSED(regExp);
    return true;
}

///////////////////////////////////////////////////////

QrListView::QrListView(QWidget *parent)
    : QAbstractScrollArea(parent),
      d_ptr(new QrListViewPrivate())
{
    setAttribute(Qt::WA_AlwaysShowToolTips);
}

QrListView::~QrListView()
{
    Q_D(QrListView);
    d->itemWidgets.clear();<commit_msg>listview get data<commit_after>#include "listview/qrlistview.h"

#include <QtCore/qdebug.h>
#include <QtCore/qtimer.h>
#include <QtCore/qqueue.h>
#include <QtWidgets/qscrollbar.h>
#include <QtGui/qevent.h>
#include <QWheelEvent>
#include <QPoint>

NS_QRWIDGETS_BEGIN

///////////////////////////////////////////////////////

class QrListViewPrivate {
public:
    std::list<QWidget*> itemWidgets;
    QrListVidewDelegate *delegate = nullptr;

    int itemHeight = 1;
    int itemsHeight = 1;
    int oldDatasetSize = 0;
};

///////////////////////////////////////////////////////

class QrListViewDataPrivate {
};

///////////////////////////////////////////////////////

class QrListVidewDelegatePrivate {
public:
    bool watingFilter = false;
    QQueue<QRegExp> filterQueue;

    QVector<QrListViewData*> rawDataset;
    QVector<QrListViewData*> viewDataset;
    QMap<int, QrListViewData*> mapDataset;

public:
    virtual ~QrListVidewDelegatePrivate();
};

///////////////////////////////////////////////////////

QrListVidewDelegatePrivate::~QrListVidewDelegatePrivate()
{
    Q_FOREACH(QrListViewData* data, rawDataset) {
        delete data;
        data = nullptr;
    }
}

NS_QRWIDGETS_END

USING_NS_QRWIDGETS;

///////////////////////////////////////////////////////

QrListVidewDelegate::QrListVidewDelegate()
    : d_ptr(new QrListVidewDelegatePrivate)
{

}

void QrListVidewDelegate::managerData(QrListViewData *data)
{
    if(nullptr == data) {
        qDebug() << "list view can't mananger nullptr data";
        return;
    }

    Q_D(QrListVidewDelegate);
    d->rawDataset.push_back(data);
    d->mapDataset[data->key()] = data;
    d->viewDataset.push_back(data);
}

QrListViewData *QrListVidewDelegate::getData(int key)
{
    Q_D(QrListVidewDelegate);
    if(! d->mapDataset.contains(key)) {
        qDebug() << "listview's delegate havn't data of " << key;
        return nullptr;
    }

    return d->mapDataset[key];
}

void QrListVidewDelegate::filter(const QRegExp &regExp)
{
    Q_D(QrListVidewDelegate);
    int limitSize = 10;
    if(d->filterQueue.size() > limitSize) {
        for(int i=0; i<limitSize/2; i++) {
            d->filterQueue.removeAt(i);
        }
    }
    d->filterQueue.append(regExp);
    if (d->watingFilter) {
        qDebug() << "waiting filter";
        return;
    }

    d->watingFilter = true;
    QTimer::singleShot(500, this, [this](){
        qDebug() << "filter!";

        Q_D(QrListVidewDelegate);
        d->viewDataset.clear();
        Q_FOREACH(QrListViewData* data, d->rawDataset) {
            if(! data->filter(d->filterQueue.last())) {
                continue;
            }
            d->viewDataset.push_back(data);
        }
        emit dataChanged();

        d->watingFilter = false;
        qDebug() << "filter finish!";
    });
}

int QrListVidewDelegate::itemsSize() const
{
    Q_D(const QrListVidewDelegate);
    return d->viewDataset.size();
}

void QrListVidewDelegate::setItemWidgetByIndex(int index, QWidget *itemWidget)
{
    Q_D(QrListVidewDelegate);
    if(index > d->viewDataset.size()) {
        qDebug() << "list size is smaller than " << index;
        return;
    }

    QrListViewData* data = d->viewDataset[index];
    if(nullptr == data) {
        qDebug() << "cell's data is nullptr";
        return;
    }

    setItemWidgetByData(data, itemWidget);
}

///////////////////////////////////////////////////////

QrListViewData::QrListViewData()
    : d_ptr(new QrListViewDataPrivate)
{

}

int QrListViewData::key() const
{
    return -1;
}

bool QrListViewData::filter(const QRegExp& regExp) const
{
    Q_UNUSED(regExp);
    return true;
}

///////////////////////////////////////////////////////

QrListView::QrListView(QWidget *parent)
    : QAbstractScrollArea(parent),
      d_ptr(new QrListViewPrivate())
{
    setAttribute(Qt::WA_AlwaysShowToolTips);
}

QrListView::~QrListView()
{
    Q_D(QrListView);
    d->itemWidgets.clear();
{'fraction_non_alphanumeric': 0.2174574980969297, 'fraction_numerical': 0.002791169753869576, 'mean_word_length': 2.2453684643886374, 'pattern_counts': {'":': 0, '<': 65, '<?xml version=': 0, '>': 73, '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': '4650083', 'n_tokens_mistral': 2650, 'n_tokens_neox': 2605, 'n_words': 417}