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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401 | /* ============================================================
*
* This file is a part of digiKam project
* https://www.digikam.org
*
* Date : 2021-04-18
* Description : ExifTool metadata list view.
*
* SPDX-FileCopyrightText: 2021-2025 by Gilles Caulier <caulier dot gilles at gmail dot com>
*
* SPDX-License-Identifier: GPL-2.0-or-later
*
* ============================================================ */
#include "exiftoollistview.h"
// Qt includes
#include <QApplication>
#include <QHeaderView>
#include <QStyle>
// KDE includes
#include <klocalizedstring.h>
// Local includes
#include "exiftoollistviewgroup.h"
#include "exiftoollistviewitem.h"
#include "digikam_debug.h"
namespace Digikam
{
class Q_DECL_HIDDEN ExifToolListView::Private
{
public:
Private() = default;
public:
QString lastError;
QString selectedItemKey;
QStringList simplifiedTagsList;
ExifToolParser* parser = nullptr;
ExifToolParser::ExifToolData map;
};
ExifToolListView::ExifToolListView(QWidget* const parent)
: QTreeWidget(parent),
d (new Private)
{
setColumnCount(2);
setHeaderHidden(true);
setSortingEnabled(true);
setUniformRowHeights(true);
setAllColumnsShowFocus(true);
sortByColumn(0, Qt::AscendingOrder);
setSelectionMode(QAbstractItemView::SingleSelection);
header()->setSectionResizeMode(QHeaderView::Stretch);
setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
d->parser = new ExifToolParser(this, true);
connect(d->parser, SIGNAL(signalExifToolAsyncData(ExifToolParser::ExifToolData)),
this, SLOT(slotExifToolAsyncData(ExifToolParser::ExifToolData)));
connect(this, SIGNAL(itemClicked(QTreeWidgetItem*,int)),
this, SLOT(slotSelectionChanged(QTreeWidgetItem*,int)));
}
ExifToolListView::~ExifToolListView()
{
delete d;
}
void ExifToolListView::loadFromUrl(const QUrl& url)
{
clear();
d->map.clear();
if (!url.isValid())
{
Q_EMIT signalLoadingResult(true);
return;
}
if (!d->parser->load(url.toLocalFile()))
{
d->lastError = d->parser->currentErrorString();
Q_EMIT signalLoadingResult(false);
return;
}
d->lastError.clear();
}
QString ExifToolListView::errorString() const
{
return d->lastError;
}
void ExifToolListView::slotExifToolAsyncData(const ExifToolParser::ExifToolData& map)
{
d->map = map;
d->lastError = d->parser->currentErrorString();
Q_EMIT signalLoadingResult(d->lastError.isEmpty());
}
ExifToolListViewGroup* ExifToolListView::findGroup(const QString& group)
{
QTreeWidgetItemIterator it(this);
while (*it)
{
ExifToolListViewGroup* const item = dynamic_cast<ExifToolListViewGroup*>(*it);
if (item && (item->text(0) == group))
{
return item;
}
++it;
}
return nullptr;
}
void ExifToolListView::slotSearchTextChanged(const SearchTextSettings& settings)
{
bool query = false;
QString search = settings.text;
// Restore all Group items.
QTreeWidgetItemIterator it2(this);
while (*it2)
{
ExifToolListViewGroup* const item = dynamic_cast<ExifToolListViewGroup*>(*it2);
if (item)
{
item->setHidden(false);
}
++it2;
}
QTreeWidgetItemIterator it(this);
while (*it)
{
ExifToolListViewItem* const item = dynamic_cast<ExifToolListViewItem*>(*it);
if (item)
{
if (
item->text(0).contains(search, settings.caseSensitive) ||
item->text(1).contains(search, settings.caseSensitive)
)
{
query = true;
item->setHidden(false);
}
else
{
item->setHidden(true);
}
}
++it;
}
Q_EMIT signalTextFilterMatch(query);
}
QString ExifToolListView::getCurrentItemKey() const
{
if (currentItem() && (currentItem()->flags() & Qt::ItemIsSelectable))
{
ExifToolListViewItem* const item = static_cast<ExifToolListViewItem*>(currentItem());<--- Variable 'item' can be declared as pointer to const
return item->getKey();
}
return QString();
}
void ExifToolListView::setCurrentItemByKey(const QString& itemKey)
{
if (itemKey.isNull())
{
return;
}
QTreeWidgetItemIterator it(this);
while (*it)
{
ExifToolListViewItem* const item = dynamic_cast<ExifToolListViewItem*>(*it);
if (item)
{
if (item->getKey() == itemKey)
{
setCurrentItem(item);
scrollToItem(item);
d->selectedItemKey = itemKey;
return;
}
}
++it;
}
}
void ExifToolListView::slotSelectionChanged(QTreeWidgetItem* item, int)
{
ExifToolListViewItem* const viewItem = dynamic_cast<ExifToolListViewItem*>(item);<--- Variable 'viewItem' can be declared as pointer to const
if (!viewItem)
{
return;
}
d->selectedItemKey = viewItem->getKey();
QString tagValue = viewItem->getValue();
QString tagTitle = viewItem->getTitle();
QString tagDesc = viewItem->getDescription();
if (tagValue.length() > 128)
{
tagValue.truncate(128);
tagValue.append(QLatin1String("..."));
}
this->setWhatsThis(i18n("<b>Title: </b><p>%1</p>"
"<b>Value: </b><p>%2</p>"
"<b>Description: </b><p>%3</p>",
tagTitle, tagValue, tagDesc));
}
void ExifToolListView::setGroupList(const QStringList& tagsFilter, const QStringList& keysFilter)
{
clear();
d->simplifiedTagsList.clear();
QString simplifiedTag;
QStringList filters = tagsFilter;
#ifndef __clang_analyzer__
// Disable false-positive memory leak reported by scan-build with QTreeWidgetItem.
/** Key is formatted like this:
*
* EXIF.ExifIFD.Image.ExposureCompensation
* File.File.Other.FileType
* Composite.Composite.Time.SubSecModifyDate
* File.System.Time.FileInodeChangeDate
* File.System.Other.FileSize
* EXIF.GPS.Location.GPSLongitude
* ICC_Profile.ICC-header.Image.ProfileCreator
* EXIF.IFD1.Image.ThumbnailOffset
* JFIF.JFIF.Image.YResolution
* ICC_Profile.ICC_Profile.Image.GreenMatrixColumn
*/
for (ExifToolParser::ExifToolData::const_iterator it = d->map.constBegin() ;
it != d->map.constEnd() ; ++it)
{
// We checking if we have changed of GroupName
QString currentGroupName = it.key().section(QLatin1Char('.'), 0, 0)
.replace(QLatin1Char('_'), QLatin1Char(' '));
if (currentGroupName == QLatin1String("ExifTool"))
{
// Always ignore ExifTool errors or warnings.
continue;
}
if (!keysFilter.isEmpty() && !keysFilter.contains(currentGroupName))
{
// If group filters, always ignore not found entries.
continue;
}
ExifToolListViewGroup* parentGroupItem = findGroup(currentGroupName);
simplifiedTag = currentGroupName + QLatin1Char('.') + it.key().section(QLatin1Char('.'), -1);
if (!d->simplifiedTagsList.contains(simplifiedTag))
{
d->simplifiedTagsList.append(simplifiedTag);
if (!parentGroupItem)
{
parentGroupItem = new ExifToolListViewGroup(this, currentGroupName);
}
if (tagsFilter.isEmpty())
{
new ExifToolListViewItem(parentGroupItem, it.key(), it.value()[0].toString(), it.value()[2].toString());
}
else
{
// We ignore all unknown tags if necessary.
if (filters.contains(QLatin1String("FULL")))
{
// We don't filter the output (Photo Mode)
new ExifToolListViewItem(parentGroupItem, it.key(), it.value()[0].toString(), it.value()[2].toString());
}
else if (!filters.isEmpty())
{
// We using the filter to make a more user friendly output (Custom Mode)
// Filter is not a list of complete tag keys
if (!filters.at(0).contains(QLatin1Char('.')) && filters.contains(it.key().section(QLatin1Char('.'), -1)))
{
new ExifToolListViewItem(parentGroupItem, it.key(), it.value()[0].toString(), it.value()[2].toString());
filters.removeAll(it.key());
}
else if (filters.contains(it.key()))
{
new ExifToolListViewItem(parentGroupItem, it.key(), it.value()[0].toString(), it.value()[2].toString());
filters.removeAll(it.key());
}
}
}
}
}
#endif
// Add not found tags from filter as grey items.
d->simplifiedTagsList.clear();
if (
!filters.isEmpty() &&
(filters.at(0) != QLatin1String("FULL")) &&
filters.at(0).contains(QLatin1Char('.'))
)
{
for (const QString& key : std::as_const(filters))
{
QString grp = key.section(QLatin1Char('.'), 0, 0)
.replace(QLatin1Char('_'), QLatin1Char(' '));
simplifiedTag = grp + QLatin1Char('.') + key.section(QLatin1Char('.'), -1);
ExifToolListViewGroup* pitem = findGroup(grp);
if (!d->simplifiedTagsList.contains(simplifiedTag))
{
d->simplifiedTagsList.append(simplifiedTag);
if (!pitem)
{
pitem = new ExifToolListViewGroup(this, grp);
}
new ExifToolListViewItem(pitem, key);
}
}
// Remove groups with no children.
QTreeWidgetItemIterator it(this);
while (*it)
{
ExifToolListViewGroup* const item = dynamic_cast<ExifToolListViewGroup*>(*it);
if (item && !item->childCount())
{
delete item;
}
++it;
}
}
setCurrentItemByKey(d->selectedItemKey);
update();
}
} // namespace Digikam
#include "moc_exiftoollistview.cpp"
|