LibrePCB Developers Documentation
comboboxdelegate.h
Go to the documentation of this file.
1 /*
2  * LibrePCB - Professional EDA for everyone!
3  * Copyright (C) 2013 LibrePCB Developers, see AUTHORS.md for contributors.
4  * https://librepcb.org/
5  *
6  * This program is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program. If not, see <http://www.gnu.org/licenses/>.
18  */
19 
20 #ifndef LIBREPCB_EDITOR_COMBOBOXDELEGATE_H
21 #define LIBREPCB_EDITOR_COMBOBOXDELEGATE_H
22 
23 /*******************************************************************************
24  * Includes
25  ******************************************************************************/
26 #include <QtCore>
27 #include <QtWidgets>
28 
29 /*******************************************************************************
30  * Namespace / Forward Declarations
31  ******************************************************************************/
32 namespace librepcb {
33 namespace editor {
34 
35 /*******************************************************************************
36  * Class ComboBoxDelegate
37  ******************************************************************************/
38 
42 class ComboBoxDelegate final : public QStyledItemDelegate {
43  Q_OBJECT
44 
45 public:
46  // Types
47  struct Item final {
48  QString text;
49  QIcon icon;
50  QVariant data;
51  };
52  struct Items final : public QVector<Item> {
53  void sort() noexcept;
54  };
55 
56  // Constructors / Destructor
57  explicit ComboBoxDelegate(bool editable = false,
58  QObject* parent = nullptr) noexcept;
59  ComboBoxDelegate(const ComboBoxDelegate& other) = delete;
60  ~ComboBoxDelegate() noexcept;
61 
62  // Inherited from QStyledItemDelegate
63  QWidget* createEditor(QWidget* parent, const QStyleOptionViewItem& option,
64  const QModelIndex& index) const override;
65  void setEditorData(QWidget* editor, const QModelIndex& index) const override;
66  void setModelData(QWidget* editor, QAbstractItemModel* model,
67  const QModelIndex& index) const override;
68  void updateEditorGeometry(QWidget* editor, const QStyleOptionViewItem& option,
69  const QModelIndex& index) const override;
70 
71  // Operator Overloadings
72  ComboBoxDelegate& operator=(const ComboBoxDelegate& rhs) = delete;
73 
74 private: // Data
75  bool mEditable;
76 };
77 
78 /*******************************************************************************
79  * End of File
80  ******************************************************************************/
81 
82 } // namespace editor
83 } // namespace librepcb
84 
86 
87 #endif
QWidget * createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const override
Definition: comboboxdelegate.cpp:63
ComboBoxDelegate & operator=(const ComboBoxDelegate &rhs)=delete
Definition: comboboxdelegate.h:47
void setEditorData(QWidget *editor, const QModelIndex &index) const override
Definition: comboboxdelegate.cpp:80
Definition: occmodel.cpp:77
~ComboBoxDelegate() noexcept
Definition: comboboxdelegate.cpp:56
QIcon icon
Definition: comboboxdelegate.h:49
Definition: comboboxdelegate.h:52
Subclass of QStyledItemDelegate which uses QComboBox as item editor.
Definition: comboboxdelegate.h:42
ComboBoxDelegate(bool editable=false, QObject *parent=nullptr) noexcept
Definition: comboboxdelegate.cpp:52
bool mEditable
Definition: comboboxdelegate.h:75
void updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex &index) const override
Definition: comboboxdelegate.cpp:102
QString text
Definition: comboboxdelegate.h:48
void setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const override
Definition: comboboxdelegate.cpp:92
QVariant data
Definition: comboboxdelegate.h:50