LibrePCB Developers Documentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
lengthdelegate.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_LENGTHDELEGATE_H
21 #define LIBREPCB_LENGTHDELEGATE_H
22 
23 /*******************************************************************************
24  * Includes
25  ******************************************************************************/
26 #include "../units/lengthunit.h"
27 
28 #include <QtCore>
29 #include <QtWidgets>
30 
31 /*******************************************************************************
32  * Namespace / Forward Declarations
33  ******************************************************************************/
34 namespace librepcb {
35 
36 /*******************************************************************************
37  * Class LengthDelegate
38  ******************************************************************************/
39 
44 class LengthDelegate final : public QStyledItemDelegate {
45  Q_OBJECT
46 
47 public:
48  // Constructors / Destructor
49  explicit LengthDelegate(QObject* parent = nullptr) noexcept;
50  LengthDelegate(const LengthDelegate& other) = delete;
51  ~LengthDelegate() noexcept;
52 
53  // Setters
54  void setUnit(const LengthUnit& unit) noexcept;
55 
56  // Inherited from QStyledItemDelegate
57  QString displayText(const QVariant& value,
58  const QLocale& locale) const override;
59  QWidget* createEditor(QWidget* parent, const QStyleOptionViewItem& option,
60  const QModelIndex& index) const override;
61  void setEditorData(QWidget* editor, const QModelIndex& index) const override;
62  void setModelData(QWidget* editor, QAbstractItemModel* model,
63  const QModelIndex& index) const override;
64  void updateEditorGeometry(QWidget* editor, const QStyleOptionViewItem& option,
65  const QModelIndex& index) const override;
66 
67  // Operator Overloadings
68  LengthDelegate& operator=(const LengthDelegate& rhs) = delete;
69 
70 private: // Methods
71  void editingFinished() noexcept;
72 
73 private: // Data
75 };
76 
77 /*******************************************************************************
78  * End of File
79  ******************************************************************************/
80 
81 } // namespace librepcb
82 
83 #endif // LIBREPCB_LENGTHDELEGATE_H
LengthDelegate(QObject *parent=nullptr) noexcept
Definition: lengthdelegate.cpp:40
Subclass of QStyledItemDelegate to display/edit librepcb::Length values.
Definition: lengthdelegate.h:44
void setUnit(const LengthUnit &unit) noexcept
Definition: lengthdelegate.cpp:51
LengthUnit mUnit
Definition: lengthdelegate.h:74
QString displayText(const QVariant &value, const QLocale &locale) const override
Definition: lengthdelegate.cpp:59
LengthDelegate & operator=(const LengthDelegate &rhs)=delete
void setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const override
Definition: lengthdelegate.cpp:91
void updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex &index) const override
Definition: lengthdelegate.cpp:97
void setEditorData(QWidget *editor, const QModelIndex &index) const override
Definition: lengthdelegate.cpp:85
void editingFinished() noexcept
Definition: lengthdelegate.cpp:108
The LengthUnit class represents a length unit (millimeters, inches,...) and provides some useful meth...
Definition: lengthunit.h:61
~LengthDelegate() noexcept
Definition: lengthdelegate.cpp:44
QWidget * createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const override
Definition: lengthdelegate.cpp:65