File indexing completed on 2024-04-28 04:39:08

0001 /*
0002     SPDX-FileCopyrightText: 2013 Milian Wolff <mail@milianw.de>
0003 
0004     SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
0005 */
0006 
0007 #ifndef COMBOBOXDELEGATE_H
0008 #define COMBOBOXDELEGATE_H
0009 
0010 #include <QStyledItemDelegate>
0011 
0012 namespace KDevelop {
0013 
0014 class ComboBoxDelegate : public QStyledItemDelegate
0015 {
0016     Q_OBJECT
0017 public:
0018 
0019     struct Item {
0020         Item()
0021         {}
0022         Item(const QString& text, const QVariant& data)
0023             : text(text)
0024             , data(data)
0025         {}
0026         QString text;
0027         QVariant data;
0028     };
0029 
0030     explicit ComboBoxDelegate(const QVector<Item>& items, QObject* parent = nullptr);
0031     ~ComboBoxDelegate() override;
0032 
0033     QWidget* createEditor(QWidget* parent, const QStyleOptionViewItem& option, const QModelIndex& index) const override;
0034     void setEditorData(QWidget* editor, const QModelIndex& index) const override;
0035     void setModelData(QWidget* editor, QAbstractItemModel* model, const QModelIndex& index) const override;
0036 
0037 private:
0038     QVector<Item> m_items;
0039 };
0040 
0041 }
0042 
0043 Q_DECLARE_TYPEINFO(KDevelop::ComboBoxDelegate::Item, Q_MOVABLE_TYPE);
0044 
0045 #endif // COMBOBOXDELEGATE_H