LibrePCB Developers Documentation
rulechecklistwidget.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_RULECHECKLISTWIDGET_H
21#define LIBREPCB_EDITOR_RULECHECKLISTWIDGET_H
22
23/*******************************************************************************
24 * Includes
25 ******************************************************************************/
27#include <optional/tl/optional.hpp>
28
29#include <QtCore>
30#include <QtWidgets>
31
32#include <memory>
33
34/*******************************************************************************
35 * Namespace / Forward Declarations
36 ******************************************************************************/
37namespace librepcb {
38namespace editor {
39
40/*******************************************************************************
41 * Interface IF_RuleCheckHandler
42 ******************************************************************************/
43
45public:
47 std::shared_ptr<const RuleCheckMessage> msg) noexcept = 0;
49 std::shared_ptr<const RuleCheckMessage> msg) noexcept = 0;
51 std::shared_ptr<const RuleCheckMessage> msg) noexcept = 0;
53 std::shared_ptr<const RuleCheckMessage> msg, bool approve) noexcept = 0;
55 std::shared_ptr<const RuleCheckMessage> msg) noexcept = 0;
57 std::shared_ptr<const RuleCheckMessage> msg) noexcept = 0;
58
59protected:
60 IF_RuleCheckHandler() noexcept {}
62 virtual ~IF_RuleCheckHandler() noexcept {}
63};
64
65/*******************************************************************************
66 * Class RuleCheckListItemWidget
67 ******************************************************************************/
68
72class RuleCheckListItemWidget final : public QWidget {
73 Q_OBJECT
74
75public:
76 // Constructors / Destructor
77 explicit RuleCheckListItemWidget(std::shared_ptr<const RuleCheckMessage> msg,
78 IF_RuleCheckHandler& handler, bool approved,
79 QWidget* parent = nullptr) noexcept
80 : QWidget(parent),
81 mMessage(msg),
82 mHandler(handler),
83 mIconLabel(new QLabel(this)) {
84 if (!msg) return;
85 QHBoxLayout* layout = new QHBoxLayout(this);
86 layout->setContentsMargins(0, 0, 0, 0);
87 layout->setSpacing(0);
88
89 // severity icon
90 mIconLabel->setScaledContents(true);
91 mIconLabel->setPixmap(msg->getSeverityIcon().pixmap(
92 48, approved ? QIcon::Disabled : QIcon::Normal));
93 layout->addWidget(mIconLabel.data());
94 layout->addSpacing(3);
95
96 // message
97 QLabel* lblMsg = new QLabel(msg->getMessage(), this);
98 lblMsg->setToolTip(msg->getMessage());
99 if (approved) {
100 QFont font = lblMsg->font();
101 font.setItalic(true);
102 font.setStrikeOut(true);
103 lblMsg->setFont(font);
104 }
105 layout->addWidget(lblMsg);
106 layout->addSpacing(3);
107 layout->setStretch(1, 100);
108
109 // "fix" button
111 QToolButton* btnFix = new QToolButton(this);
112 btnFix->setText(tr("Fix"));
113 btnFix->setToolTip(tr("Fix Problem"));
114 btnFix->setStatusTip(
115 tr("Automatically apply a modification to fix this message"));
116 connect(btnFix, &QToolButton::clicked, this,
118 layout->addWidget(btnFix);
119 }
120
121 // "approve" button
122 QToolButton* btnApprove = new QToolButton(this);
123 btnApprove->setText("✔");
124 btnApprove->setToolTip(tr("Approve/Disapprove"));
125 btnApprove->setStatusTip(tr("Mark/unmark this message as approved"));
126 btnApprove->setCheckable(true);
127 btnApprove->setChecked(approved);
128 connect(btnApprove, &QToolButton::clicked, this, [this, msg](bool checked) {
130 });
131 layout->addWidget(btnApprove);
132
133 // "details" button
134 QToolButton* btnDetails = new QToolButton(this);
135 btnDetails->setText("?");
136 btnDetails->setToolTip(tr("Details"));
137 btnDetails->setStatusTip(tr("Show more information about this message"));
138 connect(btnDetails, &QToolButton::clicked, this,
140 layout->addWidget(btnDetails);
141 }
144
145 // Operator Overloadings
147 delete;
148
149private: // Methods
150 void resizeEvent(QResizeEvent* event) override {
151 QWidget::resizeEvent(event);
152 mIconLabel->setFixedWidth(mIconLabel->height());
153 }
154
155private: // Data
156 std::shared_ptr<const RuleCheckMessage> mMessage;
158 QScopedPointer<QLabel> mIconLabel;
159};
160
161/*******************************************************************************
162 * Class RuleCheckListWidget
163 ******************************************************************************/
164
168class RuleCheckListWidget final : public QWidget, private IF_RuleCheckHandler {
169 Q_OBJECT
170
171public:
172 // Constructors / Destructor
173 explicit RuleCheckListWidget(QWidget* parent = nullptr) noexcept;
175 ~RuleCheckListWidget() noexcept;
176
177 // Getters
178 const tl::optional<int>& getUnapprovedMessageCount() const noexcept {
180 }
181
182 // Setters
183 void setReadOnly(bool readOnly) noexcept;
184 void setHandler(IF_RuleCheckHandler* handler) noexcept;
185 void setMessages(const tl::optional<RuleCheckMessageList>& messages) noexcept;
186 void setApprovals(const QSet<SExpression>& approvals) noexcept;
187
188 // Operator Overloadings
190
191private: // Methods
192 void updateList() noexcept;
193 void currentItemChanged(QListWidgetItem* current,
194 QListWidgetItem* previous) noexcept;
195 void itemDoubleClicked(QListWidgetItem* item) noexcept;
197 std::shared_ptr<const RuleCheckMessage> msg) noexcept override;
199 std::shared_ptr<const RuleCheckMessage> msg) noexcept override;
201 std::shared_ptr<const RuleCheckMessage> msg) noexcept override;
202 void ruleCheckApproveRequested(std::shared_ptr<const RuleCheckMessage> msg,
203 bool approve) noexcept override;
205 std::shared_ptr<const RuleCheckMessage> msg) noexcept override;
207 std::shared_ptr<const RuleCheckMessage> msg) noexcept override;
208
209private: // Data
210 QScopedPointer<QListWidget> mListWidget;
217};
218
219/*******************************************************************************
220 * End of File
221 ******************************************************************************/
222
223} // namespace editor
224} // namespace librepcb
225
226#endif
The RuleCheckMessage class.
Definition: rulecheckmessage.h:45
The SExpression class.
Definition: sexpression.h:69
Definition: rulechecklistwidget.h:44
virtual void ruleCheckApproveRequested(std::shared_ptr< const RuleCheckMessage > msg, bool approve) noexcept=0
virtual void ruleCheckFixRequested(std::shared_ptr< const RuleCheckMessage > msg) noexcept=0
virtual void ruleCheckMessageDoubleClicked(std::shared_ptr< const RuleCheckMessage > msg) noexcept=0
virtual ~IF_RuleCheckHandler() noexcept
Definition: rulechecklistwidget.h:62
virtual void ruleCheckMessageSelected(std::shared_ptr< const RuleCheckMessage > msg) noexcept=0
virtual bool ruleCheckFixAvailable(std::shared_ptr< const RuleCheckMessage > msg) noexcept=0
virtual void ruleCheckDescriptionRequested(std::shared_ptr< const RuleCheckMessage > msg) noexcept=0
IF_RuleCheckHandler() noexcept
Definition: rulechecklistwidget.h:60
IF_RuleCheckHandler(const IF_RuleCheckHandler &) noexcept
Definition: rulechecklistwidget.h:61
The RuleCheckListItemWidget class.
Definition: rulechecklistwidget.h:72
RuleCheckListItemWidget(const RuleCheckListItemWidget &other)=delete
IF_RuleCheckHandler & mHandler
Definition: rulechecklistwidget.h:157
RuleCheckListItemWidget & operator=(const RuleCheckListItemWidget &rhs)=delete
void resizeEvent(QResizeEvent *event) override
Definition: rulechecklistwidget.h:150
std::shared_ptr< const RuleCheckMessage > mMessage
Definition: rulechecklistwidget.h:156
QScopedPointer< QLabel > mIconLabel
Definition: rulechecklistwidget.h:158
RuleCheckListItemWidget(std::shared_ptr< const RuleCheckMessage > msg, IF_RuleCheckHandler &handler, bool approved, QWidget *parent=nullptr) noexcept
Definition: rulechecklistwidget.h:77
~RuleCheckListItemWidget() noexcept
Definition: rulechecklistwidget.h:143
The RuleCheckListWidget class.
Definition: rulechecklistwidget.h:168
~RuleCheckListWidget() noexcept
Definition: rulechecklistwidget.cpp:56
bool mReadOnly
Definition: rulechecklistwidget.h:211
IF_RuleCheckHandler * mHandler
Definition: rulechecklistwidget.h:212
void setApprovals(const QSet< SExpression > &approvals) noexcept
Definition: rulechecklistwidget.cpp:82
tl::optional< RuleCheckMessageList > mMessages
Definition: rulechecklistwidget.h:213
void setReadOnly(bool readOnly) noexcept
Definition: rulechecklistwidget.cpp:63
tl::optional< int > mUnapprovedMessageCount
Definition: rulechecklistwidget.h:216
bool ruleCheckFixAvailable(std::shared_ptr< const RuleCheckMessage > msg) noexcept override
Definition: rulechecklistwidget.cpp:167
QScopedPointer< QListWidget > mListWidget
Definition: rulechecklistwidget.h:210
void itemDoubleClicked(QListWidgetItem *item) noexcept
Definition: rulechecklistwidget.cpp:159
void ruleCheckApproveRequested(std::shared_ptr< const RuleCheckMessage > msg, bool approve) noexcept override
Definition: rulechecklistwidget.cpp:190
QSet< SExpression > mApprovals
Definition: rulechecklistwidget.h:215
const tl::optional< int > & getUnapprovedMessageCount() const noexcept
Definition: rulechecklistwidget.h:178
void ruleCheckDescriptionRequested(std::shared_ptr< const RuleCheckMessage > msg) noexcept override
Definition: rulechecklistwidget.cpp:183
RuleCheckListWidget(const RuleCheckListWidget &other)=delete
void setMessages(const tl::optional< RuleCheckMessageList > &messages) noexcept
Definition: rulechecklistwidget.cpp:74
RuleCheckListWidget(QWidget *parent=nullptr) noexcept
Definition: rulechecklistwidget.cpp:39
void ruleCheckFixRequested(std::shared_ptr< const RuleCheckMessage > msg) noexcept override
Definition: rulechecklistwidget.cpp:176
RuleCheckMessageList mDisplayedMessages
Definition: rulechecklistwidget.h:214
void ruleCheckMessageDoubleClicked(std::shared_ptr< const RuleCheckMessage > msg) noexcept override
Definition: rulechecklistwidget.cpp:204
void updateList() noexcept
Definition: rulechecklistwidget.cpp:94
RuleCheckListWidget & operator=(const RuleCheckListWidget &rhs)=delete
void ruleCheckMessageSelected(std::shared_ptr< const RuleCheckMessage > msg) noexcept override
Definition: rulechecklistwidget.cpp:197
void currentItemChanged(QListWidgetItem *current, QListWidgetItem *previous) noexcept
Definition: rulechecklistwidget.cpp:149
void setHandler(IF_RuleCheckHandler *handler) noexcept
Definition: rulechecklistwidget.cpp:70
Definition: occmodel.cpp:77
QVector< std::shared_ptr< const RuleCheckMessage > > RuleCheckMessageList
Definition: rulecheckmessage.h:104
Definition: uuid.h:183