Commit 8bf2ad8d authored by Daniel Vrátil's avatar Daniel Vrátil 🤖

Modernize MessageList

Use range-based for loops and "auto" where it makes sense.
parent da743944
......@@ -202,14 +202,12 @@ void Aggregation::save(QDataStream &stream) const
QList< QPair< QString, int > > Aggregation::enumerateGroupingOptions()
{
QList< QPair< QString, int > > ret;
ret.append(QPair< QString, int >(i18nc("No grouping of messages", "None"), NoGrouping));
ret.append(QPair< QString, int >(i18n("By Exact Date (of Thread Leaders)"), GroupByDate));
ret.append(QPair< QString, int >(i18n("By Smart Date Ranges (of Thread Leaders)"), GroupByDateRange));
ret.append(QPair< QString, int >(i18n("By Smart Sender/Receiver"), GroupBySenderOrReceiver));
ret.append(QPair< QString, int >(i18n("By Sender"), GroupBySender));
ret.append(QPair< QString, int >(i18n("By Receiver"), GroupByReceiver));
return ret;
return { { i18nc("No grouping of messages", "None"), NoGrouping },
{ i18n("By Exact Date (of Thread Leaders)"), GroupByDate },
{ i18n("By Smart Date Ranges (of Thread Leaders)"), GroupByDateRange },
{ i18n("By Smart Sender/Receiver"), GroupBySenderOrReceiver },
{ i18n("By Sender"), GroupBySender },
{ i18n("By Receiver"), GroupByReceiver } };
}
QList< QPair< QString, int > > Aggregation::enumerateGroupExpandPolicyOptions(Grouping g)
......@@ -218,22 +216,21 @@ QList< QPair< QString, int > > Aggregation::enumerateGroupExpandPolicyOptions(Gr
if (g == NoGrouping) {
return ret;
}
ret.append(QPair< QString, int >(i18n("Never Expand Groups"), NeverExpandGroups));
ret.append({ i18n("Never Expand Groups"), NeverExpandGroups });
if ((g == GroupByDate) || (g == GroupByDateRange)) {
ret.append(QPair< QString, int >(i18n("Expand Recent Groups"), ExpandRecentGroups));
ret.append({ i18n("Expand Recent Groups"), ExpandRecentGroups });
}
ret.append(QPair< QString, int >(i18n("Always Expand Groups"), AlwaysExpandGroups));
ret.append({ i18n("Always Expand Groups"), AlwaysExpandGroups });
return ret;
}
QList< QPair< QString, int > > Aggregation::enumerateThreadingOptions()
{
QList< QPair< QString, int > > ret;
ret.append(QPair< QString, int >(i18nc("No threading of messages", "None"), NoThreading));
ret.append(QPair< QString, int >(i18n("Perfect Only"), PerfectOnly));
ret.append(QPair< QString, int >(i18n("Perfect and by References"), PerfectAndReferences));
ret.append(QPair< QString, int >(i18n("Perfect, by References and by Subject"), PerfectReferencesAndSubject));
return ret;
return { { i18nc("No threading of messages", "None"), NoThreading },
{ i18n("Perfect Only"), PerfectOnly },
{ i18n("Perfect and by References"), PerfectAndReferences },
{ i18n("Perfect, by References and by Subject"), PerfectReferencesAndSubject } };
}
QList< QPair< QString, int > > Aggregation::enumerateThreadLeaderOptions(Grouping g, Threading t)
......@@ -242,33 +239,31 @@ QList< QPair< QString, int > > Aggregation::enumerateThreadLeaderOptions(Groupin
if (t == NoThreading) {
return ret;
}
ret.append(QPair< QString, int >(i18n("Topmost Message"), TopmostMessage));
ret.append({ i18n("Topmost Message"), TopmostMessage });
if ((g != GroupByDate) && (g != GroupByDateRange)) {
return ret;
}
ret.append(QPair< QString, int >(i18n("Most Recent Message"), MostRecentMessage));
ret.append({ i18n("Most Recent Message"), MostRecentMessage });
return ret;
}
QList< QPair< QString, int > > Aggregation::enumerateThreadExpandPolicyOptions(Threading t)
{
QList< QPair< QString, int > > ret;
if (t == NoThreading) {
return ret;
return {};
}
ret.append(QPair< QString, int >(i18n("Never Expand Threads"), NeverExpandThreads));
ret.append(QPair< QString, int >(i18n("Expand Threads With Unread Messages"), ExpandThreadsWithUnreadMessages));
ret.append(QPair< QString, int >(i18n("Expand Threads With Unread or Important Messages"), ExpandThreadsWithUnreadOrImportantMessages));
ret.append(QPair< QString, int >(i18n("Always Expand Threads"), AlwaysExpandThreads));
return ret;
return { { i18n("Never Expand Threads"), NeverExpandThreads },
{ i18n("Expand Threads With Unread Messages"), ExpandThreadsWithUnreadMessages },
{ i18n("Expand Threads With Unread or Important Messages"), ExpandThreadsWithUnreadOrImportantMessages },
{ i18n("Always Expand Threads"), AlwaysExpandThreads } };
}
QList< QPair< QString, int > > Aggregation::enumerateFillViewStrategyOptions()
{
QList< QPair< QString, int > > ret;
ret.append(QPair< QString, int >(i18n("Favor Interactivity"), FavorInteractivity));
ret.append(QPair< QString, int >(i18n("Favor Speed"), FavorSpeed));
ret.append(QPair< QString, int >(i18n("Batch Job (No Interactivity)"), BatchNoInteractivity));
return ret;
return { { i18n("Favor Interactivity"), FavorInteractivity },
{ i18n("Favor Speed"), FavorSpeed },
{ i18n("Batch Job (No Interactivity)"), BatchNoInteractivity } };
}
......@@ -209,13 +209,12 @@ void Item::childItemStats(ChildItemStats &stats) const
Q_ASSERT(d_ptr->mChildItems);
stats.mTotalChildCount += d_ptr->mChildItems->count();
QList< Item * >::ConstIterator end(d_ptr->mChildItems->constEnd());
for (QList< Item * >::ConstIterator it = d_ptr->mChildItems->constBegin(); it != end; ++it) {
if (!(*it)->status().isRead()) {
for (const auto child : qAsConst(*d_ptr->mChildItems)) {
if (!child->status().isRead()) {
stats.mUnreadChildCount++;
}
if ((*it)->d_ptr->mChildItems) {
(*it)->childItemStats(stats);
if (child->d_ptr->mChildItems) {
child->childItemStats(stats);
}
}
}
......@@ -455,10 +454,9 @@ bool Item::recomputeMaxDate()
time_t newMaxDate = d_ptr->mDate;
if (d_ptr->mChildItems) {
QList< Item * >::ConstIterator end = d_ptr->mChildItems->constEnd();
for (QList< Item * >::ConstIterator it = d_ptr->mChildItems->constBegin(); it != end; ++it) {
if ((*it)->d_ptr->mMaxDate > newMaxDate) {
newMaxDate = (*it)->d_ptr->mMaxDate;
for (auto child : qAsConst(*d_ptr->mChildItems)) {
if (child->d_ptr->mMaxDate > newMaxDate) {
newMaxDate = child->d_ptr->mMaxDate;
}
}
}
......@@ -525,14 +523,12 @@ void Item::setViewable(Model *model, bool bViewable)
d_ptr->mIsViewable = true;
}
QList< Item * >::ConstIterator end(d_ptr->mChildItems->constEnd());
for (QList< Item * >::ConstIterator it = d_ptr->mChildItems->constBegin(); it != end; ++it) {
(*it)->setViewable(model, bViewable);
for (const auto child : qAsConst(*d_ptr->mChildItems)) {
child->setViewable(model, bViewable);
}
} else {
QList< Item * >::ConstIterator end(d_ptr->mChildItems->constEnd());
for (QList< Item * >::ConstIterator it = d_ptr->mChildItems->constBegin(); it != end; ++it) {
(*it)->setViewable(model, bViewable);
for (const auto child : qAsConst(*d_ptr->mChildItems)) {
child->setViewable(model, bViewable);
}
// It seems that we can avoid removing child items here since the parent has been removed: this is a hack tough
......@@ -756,9 +752,8 @@ void Item::dump(const QString &prefix)
return;
}
QList< Item * >::ConstIterator end(d_ptr->mChildItems->constEnd());
for (QList< Item * >::ConstIterator it = d_ptr->mChildItems->constBegin(); it != end; ++it) {
(*it)->dump(nPrefix);
for (const auto child : qAsConst(*d_ptr->mChildItems)) {
child->dump(nPrefix);
}
}
......
......@@ -59,8 +59,10 @@ Manager::Manager()
mCachedLocalizedUnknownText = i18nc("Unknown date", "Unknown");
loadConfiguration();
connect(MessageListSettings::self(), &MessageListSettings::configChanged, this, &Manager::reloadGlobalConfiguration);
connect(MessageCore::MessageCoreSettings::self(), &MessageCore::MessageCoreSettings::configChanged, this, &Manager::reloadGlobalConfiguration);
connect(MessageListSettings::self(), &MessageListSettings::configChanged,
this, &Manager::reloadGlobalConfiguration);
connect(MessageCore::MessageCoreSettings::self(), &MessageCore::MessageCoreSettings::configChanged,
this, &Manager::reloadGlobalConfiguration);
}
Manager::~Manager()
......
......@@ -196,14 +196,13 @@ void MessageItemPrivate::fillTagList(const Akonadi::Tag::List &taglist)
for (const Akonadi::Tag &tag : taglist) {
QString symbol = QStringLiteral("mail-tagged");
Akonadi::TagAttribute *attr = tag.attribute<Akonadi::TagAttribute>();
auto attr = tag.attribute<Akonadi::TagAttribute>();
if (attr) {
if (!attr->iconName().isEmpty()) {
symbol = attr->iconName();
}
}
MessageItem::Tag *messageListTag =
new MessageItem::Tag(SmallIcon(symbol), tag.name(), tag.url().url());
auto messageListTag = new MessageItem::Tag(SmallIcon(symbol), tag.name(), tag.url().url());
if (attr) {
messageListTag->setTextColor(attr->textColor());
......@@ -271,8 +270,8 @@ QString MessageItem::annotation() const
{
Q_D(const MessageItem);
if (d->mAkonadiItem.hasAttribute<Akonadi::EntityAnnotationsAttribute>()) {
Akonadi::EntityAnnotationsAttribute *attr = d->mAkonadiItem.attribute<Akonadi::EntityAnnotationsAttribute>();
const QMap<QByteArray, QByteArray> annotations = attr->annotations();
auto attr = d->mAkonadiItem.attribute<Akonadi::EntityAnnotationsAttribute>();
const auto annotations = attr->annotations();
QByteArray annot = annotations.value("/private/comment");
if (!annot.isEmpty()) {
return QString::fromLatin1(annot);
......@@ -570,7 +569,7 @@ QString MessageItem::accessibleText(const Theme *theme, int columnIndex)
for (Theme::Row *row : rows) {
QStringList leftStrings;
QStringList rightStrings;
const QList<Theme::ContentItem *> leftItems = row->leftItems();
const auto leftItems = row->leftItems();
leftStrings.reserve(leftItems.count());
for (Theme::ContentItem *contentItem : qAsConst(leftItems)) {
leftStrings.append(accessibleTextForField(contentItem->type()));
......@@ -589,14 +588,13 @@ QString MessageItem::accessibleText(const Theme *theme, int columnIndex)
void MessageItem::subTreeToList(QList< MessageItem * > &list)
{
list.append(this);
QList< Item * > *childList = childItems();
const auto childList = childItems();
if (!childList) {
return;
}
QList< Item * >::ConstIterator end(childList->constEnd());
for (QList< Item * >::ConstIterator it = childList->constBegin(); it != end; ++it) {
Q_ASSERT((*it)->type() == Item::Message);
static_cast< MessageItem * >(*it)->subTreeToList(list);
for (const auto child : *childList) {
Q_ASSERT(child->type() == Item::Message);
static_cast<MessageItem *>(child)->subTreeToList(list);
}
}
......@@ -709,7 +707,7 @@ void TagCache::retrieveTags(const Akonadi::Tag::List &tags, MessageItemPrivate *
}
//Because fillTagList expects to be called once we either fetch all or none
if (!toFetch.isEmpty()) {
Akonadi::TagFetchJob *tagFetchJob = new Akonadi::TagFetchJob(tags, this);
auto tagFetchJob = new Akonadi::TagFetchJob(tags, this);
tagFetchJob->fetchScope().fetchAttribute<Akonadi::TagAttribute>();
connect(tagFetchJob, &Akonadi::TagFetchJob::result, this, &TagCache::onTagsFetched);
mRequests.insert(tagFetchJob, m);
......@@ -732,12 +730,11 @@ void TagCache::onTagsFetched(KJob *job)
qCWarning(MESSAGELIST_LOG) << "Failed to fetch tags: " << job->errorString();
return;
}
Akonadi::TagFetchJob *fetchJob = static_cast<Akonadi::TagFetchJob *>(job);
auto fetchJob = static_cast<Akonadi::TagFetchJob *>(job);
Q_FOREACH (const Akonadi::Tag &tag, fetchJob->tags()) {
mCache.insert(tag.id(), new Akonadi::Tag(tag));
}
MessageItemPrivate *m = mRequests.take(fetchJob);
if (m) {
if (auto m = mRequests.take(fetchJob)) {
m->fillTagList(fetchJob->tags());
}
}
......@@ -25,7 +25,7 @@ using namespace MessageList::Core;
MessageItemSetManager::MessageItemSetManager()
{
mSets = new QHash< MessageItemSetReference, QHash< MessageItem *, MessageItem * > * >();
mSets = new QHash<MessageItemSetReference, QHash<MessageItem *, MessageItem *> *>();
}
MessageItemSetManager::~MessageItemSetManager()
......@@ -36,11 +36,9 @@ MessageItemSetManager::~MessageItemSetManager()
void MessageItemSetManager::clearAllSets()
{
QHash< MessageItemSetReference, QHash< MessageItem *, MessageItem * > * >::ConstIterator end(mSets->constEnd());
for (QHash< MessageItemSetReference, QHash< MessageItem *, MessageItem * > * >::ConstIterator it = mSets->constBegin(); it != end; ++it) {
for (auto it = mSets->cbegin(), end = mSets->cend(); it != end; ++it) {
delete(*it);
}
mSets->clear();
}
......@@ -51,46 +49,37 @@ int MessageItemSetManager::setCount() const
void MessageItemSetManager::removeSet(MessageItemSetReference ref)
{
QHash< MessageItem *, MessageItem * > *set = mSets->value(static_cast< unsigned long int >(ref), nullptr);
auto set = mSets->value(static_cast<ulong>(ref), nullptr);
if (!set) {
return;
}
mSets->remove(static_cast< unsigned long int >(ref));
mSets->remove(static_cast<ulong>(ref));
delete set;
}
QList< MessageItem * > MessageItemSetManager::messageItems(MessageItemSetReference ref)
{
QList< MessageItem * > ret;
QHash< MessageItem *, MessageItem * > *set = mSets->value(static_cast< unsigned long int >(ref), nullptr);
auto *set = mSets->value(static_cast<ulong>(ref), nullptr);
if (!set) {
return ret;
}
QHash< MessageItem *, MessageItem * >::ConstIterator end(set->constEnd());
ret.reserve(set->count());
for (QHash< MessageItem *, MessageItem * >::ConstIterator it = set->constBegin(); it != end; ++it) {
ret.append(*it);
return {};
}
return ret;
return set->values();
}
void MessageItemSetManager::removeMessageItemFromAllSets(MessageItem *mi)
{
QList< MessageItemSetReference > setsToBeKilled;
QHash< MessageItemSetReference, QHash< MessageItem *, MessageItem * > * >::ConstIterator end(mSets->end());
for (QHash< MessageItemSetReference, QHash< MessageItem *, MessageItem * > * >::ConstIterator it = mSets->constBegin(); it != end; ++it) {
for (auto it = mSets->cbegin(), end = mSets->cend(); it != end; ++it) {
(*it)->remove(mi);
if ((*it)->isEmpty()) {
setsToBeKilled.append(it.key());
}
}
QList< MessageItemSetReference >::ConstIterator endit2(setsToBeKilled.constEnd());
for (QList< MessageItemSetReference >::ConstIterator it2 = setsToBeKilled.constBegin(); it2 != endit2; ++it2) {
removeSet(*it2);
for (const auto set : setsToBeKilled) {
removeSet(set);
}
}
......@@ -99,7 +88,7 @@ MessageItemSetReference MessageItemSetManager::createSet()
static unsigned long int uNextId = 0;
uNextId++;
QHash< MessageItem *, MessageItem * > *set = mSets->value(uNextId, nullptr);
auto set = mSets->value(uNextId, nullptr);
// Here we assume that having 2^32 sets is impossible
// (that would be _at_least_ 2^32 * 8 bytes of allocated memory which is
......@@ -110,7 +99,7 @@ MessageItemSetReference MessageItemSetManager::createSet()
set = mSets->value(uNextId, nullptr);
}
set = new QHash< MessageItem *, MessageItem * >();
set = new QHash<MessageItem *, MessageItem *>();
mSets->insert(uNextId, set);
return static_cast< MessageItemSetReference >(uNextId);
......@@ -118,7 +107,7 @@ MessageItemSetReference MessageItemSetManager::createSet()
bool MessageItemSetManager::addMessageItem(MessageItemSetReference ref, MessageItem *mi)
{
QHash< MessageItem *, MessageItem * > *set = mSets->value(static_cast< unsigned long int >(ref), nullptr);
auto set = mSets->value(static_cast<ulong>(ref), nullptr);
if (!set) {
return false;
}
......
......@@ -394,7 +394,7 @@ void Model::setFilter(const Filter *filter)
void ModelPrivate::slotApplyFilter()
{
QList< Item * > *childList = mRootItem->childItems();
auto childList = mRootItem->childItems();
if (!childList) {
return;
}
......@@ -402,9 +402,8 @@ void ModelPrivate::slotApplyFilter()
QModelIndex idx; // invalid
QApplication::setOverrideCursor(Qt::WaitCursor);
QList< Item * >::ConstIterator end = childList->constEnd();
for (QList< Item * >::ConstIterator it = childList->constBegin(); it != end; ++it) {
applyFilterToSubtree(*it, idx);
for (const auto child : qAsConst(*childList)) {
applyFilterToSubtree(child, idx);
}
QApplication::restoreOverrideCursor();
......@@ -424,16 +423,15 @@ bool ModelPrivate::applyFilterToSubtree(Item *item, const QModelIndex &parentInd
// Apply to children first
QList< Item * > *childList = item->childItems();
auto childList = item->childItems();
bool childrenMatch = false;
QModelIndex thisIndex = q->index(item, 0);
if (childList) {
QList< Item * >::ConstIterator end(childList->constEnd());
for (QList< Item * >::ConstIterator it = childList->constBegin(); it != end; ++it) {
if (applyFilterToSubtree(*it, thisIndex)) {
for (const auto child : qAsConst(*childList)) {
if (applyFilterToSubtree(child, thisIndex)) {
childrenMatch = true;
}
}
......@@ -484,13 +482,13 @@ QVariant Model::data(const QModelIndex &index, int role) const
/// messagelist uses its own internal roles, here we respond
/// to the ETM ones.
Item *item = static_cast< Item * >(index.internalPointer());
auto item = static_cast<Item *>(index.internalPointer());
switch (role) {
/// taken from entitytreemodel.h
case Qt::UserRole + 1: //EntityTreeModel::ItemIdRole
if (item->type() == MessageList::Core::Item::Message) {
MessageItem *mItem = static_cast<MessageItem *>(item);
auto mItem = static_cast<MessageItem *>(item);
return QVariant::fromValue(mItem->akonadiItem().id());
} else {
return QVariant();
......@@ -498,7 +496,7 @@ QVariant Model::data(const QModelIndex &index, int role) const
break;
case Qt::UserRole + 2: //EntityTreeModel::ItemRole
if (item->type() == MessageList::Core::Item::Message) {
MessageItem *mItem = static_cast<MessageItem *>(item);
auto mItem = static_cast<MessageItem *>(item);
return QVariant::fromValue(mItem->akonadiItem());
} else {
return QVariant();
......@@ -513,13 +511,13 @@ QVariant Model::data(const QModelIndex &index, int role) const
break;
case Qt::AccessibleTextRole:
if (item->type() == MessageList::Core::Item::Message) {
MessageItem *mItem = static_cast<MessageItem *>(item);
auto mItem = static_cast<MessageItem *>(item);
return mItem->accessibleText(d->mTheme, index.column());
} else if (item->type() == MessageList::Core::Item::GroupHeader) {
if (index.column() > 0) {
return QString();
}
GroupHeaderItem *hItem = static_cast<GroupHeaderItem *>(item);
auto hItem = static_cast<GroupHeaderItem *>(item);
return hItem->label();
}
return QString();
......@@ -535,7 +533,7 @@ QVariant Model::headerData(int section, Qt::Orientation, int role) const
return QVariant();
}
Theme::Column *column = d->mTheme->column(section);
auto column = d->mTheme->column(section);
if (!column) {
return QVariant();
}
......@@ -570,7 +568,7 @@ QModelIndex Model::index(Item *item, int column) const
return QModelIndex();
}
// FIXME: This function is a bottleneck (the caching in indexOfChildItem only works 30% of the time)
Item *par = item->parent();
auto par = item->parent();
if (!par) {
if (item != d->mRootItem) {
item->dump(QString());
......@@ -599,7 +597,7 @@ QModelIndex Model::index(int row, int column, const QModelIndex &parent) const
const Item *item;
if (parent.isValid()) {
item = static_cast< const Item * >(parent.internalPointer());
item = static_cast<const Item *>(parent.internalPointer());
if (!item) {
return QModelIndex(); // should never happen
}
......@@ -625,11 +623,11 @@ QModelIndex Model::parent(const QModelIndex &modelIndex) const
if (!modelIndex.isValid()) {
return QModelIndex(); // should never happen
}
Item *item = static_cast< Item * >(modelIndex.internalPointer());
auto item = static_cast<Item *>(modelIndex.internalPointer());
if (!item) {
return QModelIndex();
}
Item *par = item->parent();
auto par = item->parent();
if (!par) {
return QModelIndex(); // should never happen
}
......@@ -645,7 +643,7 @@ int Model::rowCount(const QModelIndex &parent) const
const Item *item;
if (parent.isValid()) {
item = static_cast< const Item * >(parent.internalPointer());
item = static_cast<const Item *>(parent.internalPointer());
if (!item) {
return 0; // should never happen
}
......@@ -913,11 +911,12 @@ void Model::setStorageModel(StorageModel *storageModel, PreSelectionMode preSele
if ((!canDoJobWithDisconnectedUI) && (d->mStorageModel->rowCount() > 3000)) { // empiric value
// First a small job with the most recent messages. Large chunk, small (but non zero) idle interval
// and a larger number of messages to process at once.
ViewItemJob *job1 = new ViewItemJob(d->mStorageModel->rowCount() - 1000, d->mStorageModel->rowCount() - 1, 200, 20, 100, canDoFirstSmallChunkWithDisconnectedUI);
auto job1 = new ViewItemJob(d->mStorageModel->rowCount() - 1000, d->mStorageModel->rowCount() - 1,
200, 20, 100, canDoFirstSmallChunkWithDisconnectedUI);
d->mViewItemJobs.append(job1);
// Then a larger job with older messages. Small chunk, bigger idle interval, small number of messages to
// process at once.
ViewItemJob *job2 = new ViewItemJob(0, d->mStorageModel->rowCount() - 1001, 100, 50, 10, false);
auto job2 = new ViewItemJob(0, d->mStorageModel->rowCount() - 1001, 100, 50, 10, false);
d->mViewItemJobs.append(job2);
// We could even extremize this by splitting the folder in several
......@@ -926,7 +925,7 @@ void Model::setStorageModel(StorageModel *storageModel, PreSelectionMode preSele
} else {
// small folder or can be done with disconnected UI: single chunk work.
// Lag the CPU a bit more but not too much to destroy even the earliest interactivity.
ViewItemJob *job = new ViewItemJob(0, d->mStorageModel->rowCount() - 1, 150, 30, 30, canDoJobWithDisconnectedUI);
auto job = new ViewItemJob(0, d->mStorageModel->rowCount() - 1, 150, 30, 30, canDoJobWithDisconnectedUI);
d->mViewItemJobs.append(job);
}
break;
......@@ -934,20 +933,21 @@ void Model::setStorageModel(StorageModel *storageModel, PreSelectionMode preSele
// More batchy jobs, still interactive to a certain degree
if ((!canDoJobWithDisconnectedUI) && (d->mStorageModel->rowCount() > 3000)) { // empiric value
// large folder, but favor speed
ViewItemJob *job1 = new ViewItemJob(d->mStorageModel->rowCount() - 1000, d->mStorageModel->rowCount() - 1, 250, 0, 100, canDoFirstSmallChunkWithDisconnectedUI);
auto job1 = new ViewItemJob(d->mStorageModel->rowCount() - 1000, d->mStorageModel->rowCount() - 1,
250, 0, 100, canDoFirstSmallChunkWithDisconnectedUI);
d->mViewItemJobs.append(job1);
ViewItemJob *job2 = new ViewItemJob(0, d->mStorageModel->rowCount() - 1001, 200, 0, 10, false);
auto job2 = new ViewItemJob(0, d->mStorageModel->rowCount() - 1001, 200, 0, 10, false);
d->mViewItemJobs.append(job2);
} else {
// small folder or can be done with disconnected UI and favor speed: single chunk work.
// Lag the CPU more, get more work done
ViewItemJob *job = new ViewItemJob(0, d->mStorageModel->rowCount() - 1, 250, 0, 100, canDoJobWithDisconnectedUI);
auto job = new ViewItemJob(0, d->mStorageModel->rowCount() - 1, 250, 0, 100, canDoJobWithDisconnectedUI);
d->mViewItemJobs.append(job);
}
break;
case Aggregation::BatchNoInteractivity: {
// one large job, never interrupt, block UI
ViewItemJob *job = new ViewItemJob(0, d->mStorageModel->rowCount() - 1, 60000, 0, 100000, canDoJobWithDisconnectedUI);
auto job = new ViewItemJob(0, d->mStorageModel->rowCount() - 1, 60000, 0, 100000, canDoJobWithDisconnectedUI);
d->mViewItemJobs.append(job);
}
break;
......@@ -1032,8 +1032,6 @@ void ModelPrivate::clearUnassignedMessageLists()
// when the model is destroyed.
Q_ASSERT((mOldestItem == nullptr) && (mNewestItem == nullptr));
QList< MessageItem * >::ConstIterator it;
if (!mUnassignedMessageListForPass2.isEmpty()) {
// We're actually in Pass1* or Pass2: everything is mUnassignedMessageListForPass2
// Something may *also* be in mUnassignedMessageListForPass3 and mUnassignedMessageListForPass4
......@@ -1044,19 +1042,15 @@ void ModelPrivate::clearUnassignedMessageLists()
// would then lead to a SIGSEGV. We first sweep the list gathering parentless
// items and *then* delete them without accessing the parented ones.
QList< MessageItem * > parentless;
QList< MessageItem * >::ConstIterator end(mUnassignedMessageListForPass2.constEnd());
for (it = mUnassignedMessageListForPass2.constBegin();
it != end; ++it) {
if (!(*it)->parent()) {
parentless.append(*it);
QList<MessageItem*> parentless;
for (const auto mi : qAsConst(mUnassignedMessageListForPass2)) {
if (!mi->parent()) {
parentless.append(mi);
}
}
end = parentless.constEnd();
for (it = parentless.constBegin(); it != end; ++it) {
delete *it;
for (const auto mi : qAsConst(parentless)) {
delete mi;
}
mUnassignedMessageListForPass2.clear();
......@@ -1078,23 +1072,19 @@ void ModelPrivate::clearUnassignedMessageLists()
if (!mUnassignedMessageListForPass4.isEmpty()) {
// We're actually in Pass3: the messiest one.
QHash< MessageItem *, MessageItem * > itemsToDelete;
QList< MessageItem * >::ConstIterator end(mUnassignedMessageListForPass3.constEnd());
for (it = mUnassignedMessageListForPass3.constBegin(); it != end; ++it) {
if (!(*it)->parent()) {
itemsToDelete.insert(*it, *it);
QSet<MessageItem *> itemsToDelete;
for (const auto mi : qAsConst(mUnassignedMessageListForPass3)) {
if (!mi->parent()) {
itemsToDelete.insert(mi);
}
}
end = mUnassignedMessageListForPass4.constEnd();
for (it = mUnassignedMessageListForPass4.constBegin(); it != end; ++it) {
if (!(*it)->parent()) {
itemsToDelete.insert(*it, *it);
for (const auto mi : qAsConst(mUnassignedMessageListForPass4)) {
if (!mi->parent()) {
itemsToDelete.insert(mi);
}
}
QHash< MessageItem *, MessageItem * >::ConstIterator end3 = itemsToDelete.constEnd();
for (QHash< MessageItem *, MessageItem * >::ConstIterator it3 = itemsToDelete.constBegin(); it3 != end3; ++it3) {
delete(*it3);
for (const auto mi : qAsConst(itemsToDelete)) {
delete mi;
}
mUnassignedMessageListForPass3.clear();
......@@ -1104,16 +1094,14 @@ void ModelPrivate::clearUnassignedMessageLists()
// mUnassignedMessageListForPass4 is empty so we must be at the end of a very special kind of Pass2
// We have the same problem as in mUnassignedMessageListForPass2.
QList< MessageItem * > parentless;