File indexing completed on 2025-01-19 03:56:15
0001 /* ============================================================ 0002 * 0003 * This file is a part of digiKam project 0004 * https://www.digikam.org 0005 * 0006 * Date : 2010-06-23 0007 * Description : a tab to display item editing history 0008 * 0009 * SPDX-FileCopyrightText: 2010 by Martin Klapetek <martin dot klapetek at gmail dot com> 0010 * 0011 * SPDX-License-Identifier: GPL-2.0-or-later 0012 * 0013 * ============================================================ */ 0014 0015 #include "itempropertieshistorytab.h" 0016 0017 // Qt includes 0018 0019 #include <QGridLayout> 0020 #include <QTreeView> 0021 #include <QMenu> 0022 #include <QLabel> 0023 0024 // KDE includes 0025 0026 #include <klocalizedstring.h> 0027 0028 // Local includes 0029 0030 #include "digikam_debug.h" 0031 #include "itemfiltershistorymodel.h" 0032 #include "itemfiltershistorytreeitem.h" 0033 #include "itemfiltershistoryitemdelegate.h" 0034 0035 namespace Digikam 0036 { 0037 0038 RemoveFilterAction::RemoveFilterAction(const QString& label, 0039 const QModelIndex& index, 0040 QObject* const parent) 0041 : QAction(label, parent), 0042 m_index(index) 0043 { 0044 } 0045 0046 RemoveFilterAction::~RemoveFilterAction() 0047 { 0048 } 0049 0050 void RemoveFilterAction::::setIndex(const QModelIndex& index) 0051 { 0052 m_index = index; 0053 } 0054 0055 void RemoveFilterAction::::triggerSlot() 0056 { 0057 Q_EMIT actionTriggered(m_index); 0058 } 0059 0060 // ------------------------------------------------------------------------------------------------------- 0061 0062 class Q_DECL_HIDDEN ItemPropertiesHistoryTab::Private 0063 { 0064 public: 0065 0066 explicit Private() 0067 : view (nullptr), 0068 model (nullptr), 0069 layout (nullptr), 0070 delegate (nullptr), 0071 headerLabel(nullptr) 0072 { 0073 } 0074 0075 QTreeView* view; 0076 ItemFiltersHistoryModel* model; 0077 QGridLayout* layout; 0078 ItemFiltersHistoryItemDelegate* delegate; 0079 QLabel* headerLabel; 0080 }; 0081 0082 ItemPropertiesHistoryTab::ItemPropertiesHistoryTab(QWidget* const parent) 0083 : QWidget(parent), 0084 d (new Private) 0085 { 0086 d->layout = new QGridLayout(this); 0087 d->view = new QTreeView(this); 0088 d->delegate = new ItemFiltersHistoryItemDelegate(this); 0089 d->model = new ItemFiltersHistoryModel(0, QUrl()); 0090 d->headerLabel = new QLabel(this); 0091 0092 d->headerLabel->setText(i18n("Used filters")); 0093 0094 d->layout->addWidget(d->headerLabel); 0095 d->layout->addWidget(d->view); 0096 0097 d->view->setItemDelegate(d->delegate); 0098 d->view->setRootIsDecorated(false); 0099 d->view->setContextMenuPolicy(Qt::CustomContextMenu); 0100 0101 connect(d->view, SIGNAL(customContextMenuRequested(QPoint)), 0102 this, SLOT(showCustomContextMenu(QPoint))); 0103 } 0104 0105 ItemPropertiesHistoryTab::~ItemPropertiesHistoryTab() 0106 { 0107 delete d->model; 0108 delete d->view; 0109 delete d->delegate; 0110 delete d; 0111 } 0112 0113 void ItemPropertiesHistoryTab::setCurrentURL(const QUrl& url) 0114 { 0115 d->model->setUrl(url); 0116 d->view->setModel(d->model); 0117 d->view->update(); 0118 } 0119 0120 void ItemPropertiesHistoryTab::showCustomContextMenu(const QPoint& position) 0121 { 0122 QList<QAction*> actions; 0123 0124 if (d->view->indexAt(position).isValid()) 0125 { 0126 QModelIndex index = d->view->indexAt(position); 0127 0128 QString s(i18n("Remove filter")); 0129 RemoveFilterAction* removeFilterAction = new RemoveFilterAction(s, index, 0); 0130 removeFilterAction->setDisabled(true); 0131 0132 if (!index.model()->parent(index).isValid()) 0133 { 0134 actions.append(removeFilterAction); 0135 0136 connect(removeFilterAction, SIGNAL(triggered()), 0137 removeFilterAction, SLOT(triggerSlot())); 0138 0139 connect(removeFilterAction, SIGNAL(actionTriggered(QModelIndex)), 0140 d->model, SLOT(removeEntry(QModelIndex))); 0141 } 0142 } 0143 0144 if (actions.count() > 0) 0145 { 0146 QMenu::exec(actions, d->view->mapToGlobal(position)); 0147 } 0148 } 0149 0150 void ItemPropertiesHistoryTab::setModelData(const QList<DImageHistory::Entry>& entries) 0151 { 0152 d->model->setupModelData(entries); 0153 } 0154 0155 void ItemPropertiesHistoryTab::disableEntry(bool disable) 0156 { 0157 d->model->disableEntry(d->model->index(d->model->rowCount(), 0), disable); 0158 } 0159 0160 } // namespace Digikam 0161 0162 #include "moc_itempropertieshistorytab.cpp"