<commit_before>#include "archivelistwidget.h"
#include "archivelistwidgetitem.h"
#include "debug.h"
#include "restoredialog.h"

#include <QKeyEvent>
#include <QMessageBox>

#define DELETE_CONFIRMATION_THRESHOLD 10

ArchiveListWidget::ArchiveListWidget(QWidget *parent)
    : QListWidget(parent), _highlightedItem(nullptr)
{
    _filter.setCaseSensitivity(Qt::CaseInsensitive);
    _filter.setPatternSyntax(QRegExp::Wildcard);
    connect(this, &QListWidget::itemActivated, [&](QListWidgetItem *item) {
        if(item)
        {
            ArchiveListWidgetItem *archiveItem =
                static_cast<ArchiveListWidgetItem *>(item);
            if(archiveItem && !archiveItem->archive()->deleteScheduled())
                goingToInspectItem(archiveItem);
        }
    });
}

ArchiveListWidget::~ArchiveListWidget()
{
    clear();
}

void ArchiveListWidget::setArchives(QList<ArchivePtr> archives)
{
    std::sort(archives.begin(), archives.end(),
              [](const ArchivePtr &a, const ArchivePtr &b) {
                  return (a->timestamp() > b->timestamp());
              });
    setUpdatesEnabled(false);
    clear();
    for(const ArchivePtr &archive : archives)
        insertArchive(archive, count());
    setUpdatesEnabled(true);
}

void ArchiveListWidget::addArchive(ArchivePtr archive)
{
    if(!archive)
    {
        DEBUG << "Null ArchivePtr passed.";
        return;
    }

    int pos = 0;
    for(; pos < count(); ++pos)
    {
        ArchiveListWidgetItem *archiveItem =
            static_cast<ArchiveListWidgetItem *>(item(pos));
        if(archiveItem
           && (archive->timestamp() > archiveItem->archive()->timestamp()))
        {
            break;
        }
    }
    insertArchive(archive, pos);
}

void ArchiveListWidget::deleteItem()<commit_msg>ArchiveListWidget: clarify sorting by timestamp<commit_after>#include "archivelistwidget.h"
#include "archivelistwidgetitem.h"
#include "debug.h"
#include "restoredialog.h"

#include <QKeyEvent>
#include <QMessageBox>

#define DELETE_CONFIRMATION_THRESHOLD 10

ArchiveListWidget::ArchiveListWidget(QWidget *parent)
    : QListWidget(parent), _highlightedItem(nullptr)
{
    _filter.setCaseSensitivity(Qt::CaseInsensitive);
    _filter.setPatternSyntax(QRegExp::Wildcard);
    connect(this, &QListWidget::itemActivated, [&](QListWidgetItem *item) {
        if(item)
        {
            ArchiveListWidgetItem *archiveItem =
                static_cast<ArchiveListWidgetItem *>(item);
            if(archiveItem && !archiveItem->archive()->deleteScheduled())
                goingToInspectItem(archiveItem);
        }
    });
}

ArchiveListWidget::~ArchiveListWidget()
{
    clear();
}

static bool cmp_timestamp(const ArchivePtr &a, const ArchivePtr &b)
{
    return (a->timestamp() > b->timestamp());
}

void ArchiveListWidget::setArchives(QList<ArchivePtr> archives)
{
    std::sort(archives.begin(), archives.end(), cmp_timestamp);
    setUpdatesEnabled(false);
    clear();
    for(const ArchivePtr &archive : archives)
        insertArchive(archive, count());
    setUpdatesEnabled(true);
}

void ArchiveListWidget::addArchive(ArchivePtr archive)
{
    if(!archive)
    {
        DEBUG << "Null ArchivePtr passed.";
        return;
    }

    // Find insertion position based on sorted timestamps.
    int pos = 0;
    for(; pos < count(); ++pos)
    {
        ArchiveListWidgetItem *archiveItem =
            static_cast<ArchiveListWidgetItem *>(item(pos));
        if(archiveItem
           && (archive->timestamp() > archiveItem->archive()->timestamp()))
        {
            break;
        }
    }
    insertArchive(archive, pos);
}

void ArchiveListWidget::deleteItem()
{'fraction_non_alphanumeric': 0.1296649414328521, 'fraction_numerical': 0.0016344320348678834, 'mean_word_length': 3.330188679245283, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 31, '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': '3810701', 'n_tokens_mistral': 1140, 'n_tokens_neox': 1074, 'n_words': 185}