LibrePCB Developers Documentation
partinformationdelegate.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_PARTINFORMATIONDELEGATE_H
21#define LIBREPCB_EDITOR_PARTINFORMATIONDELEGATE_H
22
23/*******************************************************************************
24 * Includes
25 ******************************************************************************/
26#include "../project/partinformationprovider.h"
27
28#include <QtCore>
29#include <QtWidgets>
30
31/*******************************************************************************
32 * Namespace / Forward Declarations
33 ******************************************************************************/
34namespace librepcb {
35namespace editor {
36
37/*******************************************************************************
38 * Class PartInformationDelegate
39 ******************************************************************************/
40
44class PartInformationDelegate final : public QStyledItemDelegate {
45 Q_OBJECT
46
47public:
48 struct Data {
49 bool initialized = false;
50 bool infoRequested = false;
51 int progress = 0;
53 std::shared_ptr<const PartInformationProvider::PartInformation> info;
55
56 QSize calcSizeHint(const QStyleOptionViewItem& option) const noexcept;
57 QString getDisplayText(bool maxLen = false) const noexcept;
58 bool getColors(QBrush& background, QPen& outline,
59 QPen& text) const noexcept;
60 };
61
62 // Constructors / Destructor
63 explicit PartInformationDelegate(bool fillCell,
64 QObject* parent = nullptr) noexcept;
66 ~PartInformationDelegate() noexcept;
67
68 // Inherited from QStyledItemDelegate
69 virtual QSize sizeHint(const QStyleOptionViewItem& option,
70 const QModelIndex& index) const noexcept override;
71 virtual void paint(QPainter* painter, const QStyleOptionViewItem& option,
72 const QModelIndex& index) const override;
73
74 // Operator Overloadings
76 delete;
77
78private: // Methods
79 bool getData(const QModelIndex& index, Data& data) const noexcept;
80
81private: // Data
82 const bool mFillCell;
83};
84
85/*******************************************************************************
86 * End of File
87 ******************************************************************************/
88
89} // namespace editor
90} // namespace librepcb
91
92Q_DECLARE_METATYPE(librepcb::editor::PartInformationDelegate::Data)
93
94#endif
Subclass of QStyledItemDelegate to display part status/price.
Definition: partinformationdelegate.h:44
const bool mFillCell
Definition: partinformationdelegate.h:82
virtual void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const override
Definition: partinformationdelegate.cpp:153
virtual QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const noexcept override
Definition: partinformationdelegate.cpp:139
bool getData(const QModelIndex &index, Data &data) const noexcept
Definition: partinformationdelegate.cpp:195
Definition: occmodel.cpp:77
Definition: partinformationdelegate.h:48
std::shared_ptr< const PartInformationProvider::PartInformation > info
Definition: partinformationdelegate.h:53
PartInformationProvider::Part part
Definition: partinformationdelegate.h:52
int progress
Definition: partinformationdelegate.h:51
QString getDisplayText(bool maxLen=false) const noexcept
Definition: partinformationdelegate.cpp:50
bool getColors(QBrush &background, QPen &outline, QPen &text) const noexcept
Definition: partinformationdelegate.cpp:65
bool infoRequested
Definition: partinformationdelegate.h:50
int priceQuantity
Definition: partinformationdelegate.h:54
QSize calcSizeHint(const QStyleOptionViewItem &option) const noexcept
Definition: partinformationdelegate.cpp:37
bool initialized
Definition: partinformationdelegate.h:49
Definition: partinformationprovider.h:57