1
/* ============================================================
3
* This file is a part of digiKam project
4
* http://www.digikam.org
7
* Description : a generic list view widget to
10
* Copyright (c) 2006-2008 by Gilles Caulier <caulier dot gilles at gmail dot com>
12
* This program is free software; you can redistribute it
13
* and/or modify it under the terms of the GNU General
14
* Public License as published by the Free Software Foundation;
15
* either version 2, or (at your option)
18
* This program is distributed in the hope that it will be useful,
19
* but WITHOUT ANY WARRANTY; without even the implied warranty of
20
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21
* GNU General Public License for more details.
23
* ============================================================ */
31
#include <qwhatsthis.h>
39
#include "mdkeylistviewitem.h"
40
#include "metadatalistviewitem.h"
41
#include "metadatalistview.h"
42
#include "metadatalistview.moc"
47
MetadataListView::MetadataListView(QWidget* parent)
51
addColumn("Name"); // No need i18n here.
52
addColumn("Value"); // No need i18n here.
54
setAllColumnsShowFocus(true);
55
setResizeMode(QListView::AllColumns);
56
// Vertical scroll bar is always disable to give more
57
// free space to metadata content
58
setVScrollBarMode(QScrollView::AlwaysOff);
60
m_parent = dynamic_cast<MetadataWidget *>(parent);
62
connect(this, SIGNAL(selectionChanged(QListViewItem*)),
63
this, SLOT(slotSelectionChanged(QListViewItem*)));
66
MetadataListView::~MetadataListView()
70
QString MetadataListView::getCurrentItemKey()
74
if (currentItem()->isSelectable())
76
MetadataListViewItem *item = static_cast<MetadataListViewItem *>(currentItem());
77
return item->getKey();
84
void MetadataListView::setCurrentItemByKey(QString itemKey)
89
QListViewItemIterator it(this);
90
while ( it.current() )
92
if ( it.current()->isSelectable() )
94
MetadataListViewItem *item = dynamic_cast<MetadataListViewItem *>(it.current());
96
if (item->getKey() == itemKey)
98
setSelected(item, true);
99
ensureItemVisible(item);
100
m_selectedItemKey = itemKey;
109
void MetadataListView::slotSelectionChanged(QListViewItem *item)
114
MetadataListViewItem* viewItem = static_cast<MetadataListViewItem *>(item);
115
m_selectedItemKey = viewItem->getKey();
116
QString tagValue = viewItem->getValue().simplifyWhiteSpace();
117
QString tagTitle = m_parent->getTagTitle(m_selectedItemKey);
118
QString tagDesc = m_parent->getTagDescription(m_selectedItemKey);
119
if (tagValue.length() > 128)
121
tagValue.truncate(128);
122
tagValue.append("...");
125
QWhatsThis::add(this, i18n("<b>Title: </b><p>%1<p>"
126
"<b>Value: </b><p>%2<p>"
127
"<b>Description: </b><p>%3")
133
void MetadataListView::setIfdList(const DMetadata::MetaDataMap& ifds, const QStringList& tagsfilter)
139
MdKeyListViewItem *parentifDItem = 0;
141
for (DMetadata::MetaDataMap::const_iterator it = ifds.begin(); it != ifds.end(); ++it)
143
// We checking if we have changed of ifDName
144
QString currentIfDName = it.key().section('.', 1, 1);
146
if ( currentIfDName != ifDItemName )
148
ifDItemName = currentIfDName;
150
// Check if the current IfD have any items. If no remove it before to toggle to the next IfD.
151
if ( subItems == 0 && parentifDItem)
152
delete parentifDItem;
154
parentifDItem = new MdKeyListViewItem(this, currentIfDName);
158
// We ignore all unknown tags if necessary.
159
if (!it.key().section('.', 2, 2).startsWith("0x"))
161
if (!tagsfilter.isEmpty())
163
// We using the filter to make a more user friendly output (Simple Mode)
165
if (tagsfilter.contains(it.key().section('.', 2, 2)))
167
QString tagTitle = m_parent->getTagTitle(it.key());
168
new MetadataListViewItem(parentifDItem, it.key(), tagTitle, it.data());
174
// We don't filter the output (Complete Mode)
176
QString tagTitle = m_parent->getTagTitle(it.key());
177
new MetadataListViewItem(parentifDItem, it.key(), tagTitle, it.data());
183
// To check if the last IfD have any items...
184
if ( subItems == 0 && parentifDItem)
185
delete parentifDItem;
187
setCurrentItemByKey(m_selectedItemKey);
188
QTimer::singleShot( 0, this, SLOT( triggerUpdate() ) );
191
void MetadataListView::setIfdList(const DMetadata::MetaDataMap& ifds, const QStringList& keysFilter,
192
const QStringList& tagsFilter)
197
MdKeyListViewItem *parentifDItem = 0;
199
for (QStringList::const_iterator itKeysFilter = keysFilter.begin();
200
itKeysFilter != keysFilter.end();
204
parentifDItem = new MdKeyListViewItem(this, *itKeysFilter);
206
DMetadata::MetaDataMap::const_iterator it = ifds.end();
210
if ( *itKeysFilter == it.key().section('.', 1, 1) )
212
// We ignore all unknown tags if necessary.
213
if (!it.key().section('.', 2, 2).startsWith("0x"))
215
if (!tagsFilter.isEmpty())
217
// We using the filter to make a more user friendly output (Simple Mode)
219
if (tagsFilter.contains(it.key().section('.', 2, 2)))
221
QString tagTitle = m_parent->getTagTitle(it.key());
222
new MetadataListViewItem(parentifDItem, it.key(), tagTitle, it.data());
228
// We don't filter the output (Complete Mode)
230
QString tagTitle = m_parent->getTagTitle(it.key());
231
new MetadataListViewItem(parentifDItem, it.key(), tagTitle, it.data());
237
if (it == ifds.begin()) break;
241
// We checking if the last IfD have any items. If no, we remove it.
242
if ( subItems == 0 && parentifDItem)
243
delete parentifDItem;
246
setCurrentItemByKey(m_selectedItemKey);
247
QTimer::singleShot( 0, this, SLOT( triggerUpdate() ) );
250
void MetadataListView::viewportResizeEvent(QResizeEvent* e)
252
QListView::viewportResizeEvent(e);
253
QTimer::singleShot( 0, this, SLOT( triggerUpdate() ) );
256
void MetadataListView::slotSearchTextChanged(const QString& filter)
259
QString search = filter.lower();
261
QListViewItemIterator it(this);
262
for ( ; it.current(); ++it )
264
MetadataListViewItem *item = dynamic_cast<MetadataListViewItem*>(it.current());
267
if (item->text(0).lower().contains(search) ||
268
item->text(1).lower().contains(search))
271
item->setVisible(true);
275
item->setVisible(false);
280
emit signalTextFilterMatch(query);
283
} // namespace Digikam