File indexing completed on 2024-05-05 05:40:56
0001 /************************************************************************* 0002 * Copyright (C) 2021 by Renaud Guezennec * 0003 * * 0004 * https://rolisteam.org/ * 0005 * * 0006 * rolisteam is free software; you can redistribute it and/or modify * 0007 * it under the terms of the GNU General Public License as published * 0008 * by the Free Software Foundation; either version 2 of the License, * 0009 * or (at your option) any later version. * 0010 * * 0011 * This program is distributed in the hope that it will be useful, * 0012 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 0013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 0014 * GNU General Public License for more details. * 0015 * * 0016 * You should have received a copy of the GNU General Public License * 0017 * along with this program; if not, write to the * 0018 * Free Software Foundation, Inc., * 0019 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * 0020 *************************************************************************/ 0021 0022 #include "rwidgets_global.h" 0023 #include <QStyledItemDelegate> 0024 #include <memory> 0025 class CenteredCheckBox; 0026 0027 namespace rwidgets 0028 { 0029 /** 0030 * @brief The CheckBoxDelegate class 0031 */ 0032 class RWIDGET_EXPORT CheckBoxDelegate : public QStyledItemDelegate 0033 { 0034 Q_OBJECT 0035 public: 0036 /** 0037 * @brief CheckBoxDelegate 0038 * @param aRedCheckBox 0039 * @param parent 0040 */ 0041 CheckBoxDelegate(bool aRedCheckBox= false, QObject* parent= nullptr); 0042 ~CheckBoxDelegate(); 0043 /** 0044 * @brief createEditor 0045 * @param parent 0046 * @param option 0047 * @param index 0048 * @return 0049 */ 0050 virtual QWidget* createEditor(QWidget* parent, const QStyleOptionViewItem& option, const QModelIndex& index) const; 0051 /** 0052 * @brief setEditorData 0053 * @param editor 0054 * @param index 0055 */ 0056 virtual void setEditorData(QWidget* editor, const QModelIndex& index) const; 0057 /** 0058 * @brief setModelData 0059 * @param editor 0060 * @param model 0061 * @param index 0062 */ 0063 virtual void setModelData(QWidget* editor, QAbstractItemModel* model, const QModelIndex& index) const; 0064 /** 0065 * @brief sizeHint 0066 * @param option 0067 * @param index 0068 * @return 0069 */ 0070 QSize sizeHint(const QStyleOptionViewItem& option, const QModelIndex& index) const; 0071 /** 0072 * @brief paint 0073 * @param painter 0074 * @param option 0075 * @param index 0076 */ 0077 void paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const; 0078 0079 public slots: 0080 void commitEditor(); 0081 0082 private: 0083 std::unique_ptr<CenteredCheckBox> m_editor; 0084 }; 0085 0086 } // namespace rwidgets