1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107 | /* ============================================================
*
* This file is a part of digiKam project
* https://www.digikam.org
*
* Date : 2007-03-20
* Description : Container for image info objects
*
* SPDX-FileCopyrightText: 2007-2013 by Marcel Wiesweg <marcel dot wiesweg at gmx dot de>
* SPDX-FileCopyrightText: 2007-2025 by Gilles Caulier <caulier dot gilles at gmail dot com>
*
* SPDX-License-Identifier: GPL-2.0-or-later
*
* ============================================================ */
#include "iteminfolist.h"
// Local includes
namespace Digikam
{
ItemInfoList::ItemInfoList(const QList<ItemInfo>& list)
: QList<ItemInfo>(list)
{
}
ItemInfoList::ItemInfoList(const QList<qlonglong>& idList)
{
for (const qlonglong& id : std::as_const(idList))
{
append(ItemInfo(id));
}
}
QList<qlonglong> ItemInfoList::toImageIdList() const
{
QList<qlonglong> idList;
for (const ItemInfo& info : std::as_const(*this))
{
idList << info.id();
}
return idList;
}
QList<QUrl> ItemInfoList::toImageUrlList() const
{
QList<QUrl> urlList;
for (const ItemInfo& info : std::as_const(*this))
{
urlList << info.fileUrl();
}
return urlList;
}
bool ItemInfoList::namefileLessThan(const ItemInfo& d1, const ItemInfo& d2)
{
return d1.name().toLower() < d2.name().toLower(); // sort by name
}
ItemInfo ItemInfoList::singleGroupMainItem() const
{
if (length() == 1)
{
return first();
}
ItemInfo mainItem;
ItemInfoList grouped;
if (first().isGrouped())
{
mainItem = first().groupImage();
if (!this->contains(mainItem))
{
return ItemInfo();
}
}
else if (first().hasGroupedImages())
{
mainItem = first();
}
else
{
return ItemInfo();
}
grouped << mainItem << mainItem.groupedImages();
for (const ItemInfo& info : std::as_const(*this))
{
if (!grouped.contains(info))
{<--- Consider using std::any_of algorithm instead of a raw loop.
return ItemInfo();
}
}
return mainItem;
}
} // namespace Digikam
|