File indexing completed on 2024-05-19 04:56:07
0001 /** 0002 * \file proxyitemselectionmodel.h 0003 * Item selection model to share selection with proxy model. 0004 * 0005 * This is a stripped down version of KLinkItemSelectionModel from kitemmodels. 0006 * Copyright (C) 2010 Klarälvdalens Datakonsult AB, 0007 * a KDAB Group company, info@kdab.net, 0008 * author Stephen Kelly <stephen@kdab.com> 0009 * Copyright (c) 2016 Ableton AG <info@ableton.com> 0010 * Author Stephen Kelly <stephen.kelly@ableton.com> 0011 * Copyright (C) 2018-2024 Urs Fleisch 0012 * 0013 * This library is free software; you can redistribute it and/or modify it 0014 * under the terms of the GNU Library General Public License as published by 0015 * the Free Software Foundation; either version 2 of the License, or (at your 0016 * option) any later version. 0017 0018 * This library is distributed in the hope that it will be useful, but WITHOUT 0019 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 0020 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public 0021 * License for more details. 0022 0023 * You should have received a copy of the GNU Library General Public License 0024 * along with this library; see the file COPYING.LIB. If not, write to the 0025 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 0026 * 02110-1301, USA. 0027 */ 0028 0029 #pragma once 0030 0031 #include <QItemSelectionModel> 0032 #include "kid3api.h" 0033 0034 /** 0035 * Item selection model to share selection with proxy model. 0036 */ 0037 class KID3_CORE_EXPORT ProxyItemSelectionModel : public QItemSelectionModel { 0038 Q_OBJECT 0039 public: 0040 /** 0041 * Constructor. 0042 * @param proxyModel proxy model 0043 * @param sourceSelectionModel item selection model for source model 0044 * @param parent parent object 0045 */ 0046 ProxyItemSelectionModel(QAbstractItemModel* proxyModel, 0047 QItemSelectionModel* sourceSelectionModel, 0048 QObject* parent = nullptr); 0049 0050 ~ProxyItemSelectionModel() override = default; 0051 0052 /** 0053 * Select item at @a index using @a command. 0054 * @param index index of item to select 0055 * @param command selection command 0056 */ 0057 void select(const QModelIndex& index, 0058 QItemSelectionModel::SelectionFlags command) override; 0059 0060 /** 0061 * Select @a selection using @a command. 0062 * @param selection item selection 0063 * @param command selection command 0064 */ 0065 void select(const QItemSelection& selection, 0066 QItemSelectionModel::SelectionFlags command) override; 0067 0068 private slots: 0069 void onSelectionChanged(const QItemSelection& selected, 0070 const QItemSelection& deselected); 0071 void onProxyCurrentChanged(const QModelIndex& current); 0072 void onCurrentChanged(const QModelIndex& current); 0073 void onModelChanged(); 0074 0075 private: 0076 QItemSelection mapSelectionFromProxy(const QItemSelection& selection) const; 0077 QItemSelection mapSelectionFromModel(const QItemSelection& selection) const; 0078 0079 QItemSelectionModel* m_proxySelectionModel; 0080 bool m_ignoreCurrentChanged; 0081 };