File indexing completed on 2025-01-19 03:50:50

0001 /* ============================================================
0002  *
0003  * This file is a part of digiKam project
0004  * https://www.digikam.org
0005  *
0006  * Date        : 2013-02-18
0007  * Description : Sync QItemSelectionModel of ItemFilterModel and TableViewModel
0008  *
0009  * SPDX-FileCopyrightText: 2017-2024 by Gilles Caulier <caulier dot gilles at gmail dot com>
0010  * SPDX-FileCopyrightText: 2013      by Michael G. Hansen <mike at mghansen dot de>
0011  *
0012  * SPDX-License-Identifier: GPL-2.0-or-later
0013  *
0014  * ============================================================ */
0015 
0016 #ifndef DIGIKAM_TABLE_VIEW_SELECTION_MODEL_SYNCER_H
0017 #define DIGIKAM_TABLE_VIEW_SELECTION_MODEL_SYNCER_H
0018 
0019 // Qt includes
0020 
0021 #include <QItemSelectionModel>
0022 #include <QObject>
0023 
0024 namespace Digikam
0025 {
0026 
0027 class TableViewShared;
0028 
0029 class TableViewSelectionModelSyncer : public QObject
0030 {
0031     Q_OBJECT
0032 
0033 public:
0034 
0035     explicit TableViewSelectionModelSyncer(TableViewShared* const sharedObject, QObject* const parent = nullptr);
0036     ~TableViewSelectionModelSyncer() override;
0037 
0038     QModelIndex toSource(const QModelIndex& targetIndex)                         const;
0039     QModelIndex toTarget(const QModelIndex& sourceIndex)                         const;
0040     QItemSelection itemSelectionToSource(const QItemSelection& selection)        const;
0041     QItemSelection itemSelectionToTarget(const QItemSelection& selection)        const;
0042     int targetModelColumnCount()                                                 const;
0043     QItemSelection targetIndexToRowItemSelection(const QModelIndex& targetIndex) const;
0044 
0045 private Q_SLOTS:
0046 
0047     void slotSourceModelReset();
0048     void slotSourceCurrentChanged(const QModelIndex& current, const QModelIndex& previous);
0049 /*
0050     void slotSourceCurrentColumnChanged(const QModelIndex& current, const QModelIndex& previous);
0051     void slotSourceCurrentRowChanged(const QModelIndex& current, const QModelIndex& previous);
0052 */
0053     void slotSourceSelectionChanged(const QItemSelection& selected, const QItemSelection& deselected);
0054     void slotTargetCurrentChanged(const QModelIndex& current, const QModelIndex& previous);
0055 /*
0056     void slotTargetCurrentColumnChanged(const QModelIndex& current, const QModelIndex& previous);
0057     void slotTargetCurrentRowChanged(const QModelIndex& current, const QModelIndex& previous);
0058 */
0059     void slotTargetSelectionChanged(const QItemSelection& selected, const QItemSelection& deselected);
0060     void slotTargetColumnsInserted(const QModelIndex& parent, int start, int end);
0061     void slotTargetModelRowsInserted(const QModelIndex& parent, int start, int end);
0062     void slotTargetModelReset();
0063     void slotDoInitialSync();
0064 
0065 public Q_SLOTS:
0066 
0067     void slotSetActive(const bool isActive);
0068 
0069 private:
0070 
0071     class Private;
0072 
0073     const QScopedPointer<Private> d;
0074     TableViewShared* const        s;
0075 };
0076 
0077 } // namespace Digikam
0078 
0079 #endif // DIGIKAM_TABLE_VIEW_SELECTION_MODEL_SYNCER_H