File indexing completed on 2024-05-19 05:08:36
0001 /* 0002 SPDX-FileCopyrightText: 2014-2016 Christian Dávid <christian-david@web.de> 0003 SPDX-License-Identifier: GPL-2.0-or-later 0004 */ 0005 0006 #ifndef STYLEDITEMDELEGATEFORWARDER_H 0007 #define STYLEDITEMDELEGATEFORWARDER_H 0008 0009 #include <QAbstractItemDelegate> 0010 0011 #include "kmm_base_widgets_export.h" 0012 0013 /** 0014 * @brief Helper to use multiple item delegates in a view 0015 * 0016 * This class allows to select the used item delegate based on the QModelIndex. 0017 * 0018 */ 0019 class KMM_BASE_WIDGETS_EXPORT StyledItemDelegateForwarder : public QAbstractItemDelegate 0020 { 0021 Q_OBJECT 0022 0023 public: 0024 explicit StyledItemDelegateForwarder(QObject* parent = 0); 0025 void paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const override; 0026 QSize sizeHint(const QStyleOptionViewItem& option, const QModelIndex& index) const override; 0027 QWidget* createEditor(QWidget* parent, const QStyleOptionViewItem& option, const QModelIndex& index) const override; 0028 void setEditorData(QWidget* editor, const QModelIndex& index) const override; 0029 void setModelData(QWidget* editor, QAbstractItemModel* model, const QModelIndex& index) const override; 0030 void updateEditorGeometry(QWidget* editor, const QStyleOptionViewItem& option, const QModelIndex& index) const override; 0031 0032 /** 0033 * @brief Return delegate for a given index 0034 * 0035 * If an method of this class is called, it uses this function to receive 0036 * the correct delegate where the call is forwarded to. 0037 * 0038 * @return You must return a valid item delegate. 0039 * @see connectSignals() 0040 */ 0041 virtual QAbstractItemDelegate* getItemDelegate(const QModelIndex& index) const = 0; 0042 0043 protected: 0044 /** 0045 * @brief Connects all signals accordingly 0046 * 0047 * Call this function if you create a new delegate in getItemDelegate(). 0048 */ 0049 void connectSignals(QAbstractItemDelegate* delegate, Qt::ConnectionType type = Qt::AutoConnection) const; 0050 0051 }; 0052 0053 #endif // STYLEDITEMDELEGATEFORWARDER_H