File indexing completed on 2024-04-21 03:56:13

0001 /*
0002     SPDX-FileCopyrightText: 2010 Klarälvdalens Datakonsult AB, a KDAB Group company <info@kdab.net>
0003     SPDX-FileContributor: Stephen Kelly <stephen@kdab.com>
0004 
0005     SPDX-License-Identifier: LGPL-2.0-or-later
0006 */
0007 
0008 #ifndef BREADCRUMBNAVIGATION_WIDGET_H
0009 #define BREADCRUMBNAVIGATION_WIDGET_H
0010 
0011 #include "klinkitemselectionmodel.h"
0012 #include <kselectionproxymodel.h>
0013 
0014 #include <QItemSelection>
0015 #include <QLabel>
0016 #include <QWidget>
0017 
0018 class CurrentItemLabel : public QLabel
0019 {
0020     Q_OBJECT
0021 public:
0022     CurrentItemLabel(QAbstractItemModel *model, QWidget *parent = nullptr, Qt::WindowFlags f = Qt::WindowFlags());
0023 
0024 private Q_SLOTS:
0025     void rowsInserted(const QModelIndex &parent, int start, int end);
0026     void rowsRemoved(const QModelIndex &parent, int start, int end);
0027     void dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight);
0028     void modelReset();
0029 
0030 private:
0031     QAbstractItemModel *m_model;
0032 };
0033 
0034 class KBreadcrumbNavigationProxyModel : public KSelectionProxyModel
0035 {
0036     Q_OBJECT
0037 public:
0038     KBreadcrumbNavigationProxyModel(QItemSelectionModel *selectionModel, QObject *parent = nullptr);
0039 
0040     void setShowHiddenAscendantData(bool showHiddenAscendantData);
0041     bool showHiddenAscendantData() const;
0042 
0043     QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
0044 
0045 private:
0046     bool m_showHiddenAscendantData;
0047 };
0048 
0049 class KNavigatingProxyModel : public KSelectionProxyModel
0050 {
0051     Q_OBJECT
0052 public:
0053     KNavigatingProxyModel(QItemSelectionModel *selectionModel, QObject *parent = nullptr);
0054 
0055     void setSourceModel(QAbstractItemModel *sourceModel) override;
0056 
0057     QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
0058 
0059 private Q_SLOTS:
0060     void modelReset();
0061     void updateNavigation();
0062     void navigationSelectionChanged(const QItemSelection &, const QItemSelection &);
0063 
0064 private:
0065 private:
0066     using KSelectionProxyModel::setFilterBehavior;
0067 
0068     QItemSelectionModel *m_selectionModel;
0069 };
0070 
0071 class KForwardingItemSelectionModel : public QItemSelectionModel
0072 {
0073     Q_OBJECT
0074 public:
0075     enum Direction {
0076         Forward,
0077         Reverse,
0078     };
0079     KForwardingItemSelectionModel(QAbstractItemModel *model, QItemSelectionModel *selectionModel, QObject *parent = nullptr);
0080     KForwardingItemSelectionModel(QAbstractItemModel *model, QItemSelectionModel *selectionModel, Direction direction, QObject *parent = nullptr);
0081 
0082     void select(const QModelIndex &index, SelectionFlags command) override;
0083     void select(const QItemSelection &selection, SelectionFlags command) override;
0084 
0085 private Q_SLOTS:
0086     void navigationSelectionChanged(const QItemSelection &selected, const QItemSelection &deselected);
0087 
0088 private:
0089     QItemSelectionModel *m_selectionModel;
0090     Direction m_direction;
0091 };
0092 
0093 class BreadcrumbNavigationWidget : public QWidget
0094 {
0095     Q_OBJECT
0096 public:
0097     BreadcrumbNavigationWidget(QWidget *parent = nullptr, Qt::WindowFlags f = Qt::WindowFlags());
0098 };
0099 
0100 #endif