LibrePCB Developers Documentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
libraryelementchecklistwidget.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_LIBRARY_EDITOR_LIBRARYELEMENTCHECKLISTWIDGET_H
21 #define LIBREPCB_LIBRARY_EDITOR_LIBRARYELEMENTCHECKLISTWIDGET_H
22 
23 /*******************************************************************************
24  * Includes
25  ******************************************************************************/
27 
28 #include <QtCore>
29 #include <QtWidgets>
30 
31 #include <memory>
32 
33 /*******************************************************************************
34  * Namespace / Forward Declarations
35  ******************************************************************************/
36 namespace librepcb {
37 namespace library {
38 namespace editor {
39 
40 /*******************************************************************************
41  * Interface IF_LibraryElementCheckHandler
42  ******************************************************************************/
43 
45 public:
47  std::shared_ptr<const LibraryElementCheckMessage> msg) noexcept = 0;
49  std::shared_ptr<const LibraryElementCheckMessage> msg) noexcept = 0;
51  std::shared_ptr<const LibraryElementCheckMessage> msg) noexcept = 0;
52 
53 protected:
56  }
57  virtual ~IF_LibraryElementCheckHandler() noexcept {}
58 };
59 
60 /*******************************************************************************
61  * Class LibraryElementCheckListItemWidget
62  ******************************************************************************/
63 
67 class LibraryElementCheckListItemWidget final : public QWidget {
68  Q_OBJECT
69 
70 public:
71  // Constructors / Destructor
73  std::shared_ptr<const LibraryElementCheckMessage> msg,
75  QWidget* parent = nullptr) noexcept
76  : QWidget(parent),
77  mMessage(msg),
78  mHandler(handler),
79  mIconLabel(new QLabel(this)) {
80  if (!msg) return;
81  QHBoxLayout* layout = new QHBoxLayout(this);
82  layout->setContentsMargins(0, 0, 0, 0);
83  layout->setSpacing(3);
84 
85  // severity icon
86  mIconLabel->setScaledContents(true);
87  mIconLabel->setPixmap(msg->getSeverityPixmap());
88  layout->addWidget(mIconLabel.data());
89 
90  // message
91  QLabel* lblMsg = new QLabel(msg->getMessage(), this);
92  lblMsg->setToolTip(msg->getMessage());
93  layout->addWidget(lblMsg);
94  layout->setStretch(1, 100);
95 
96  // "fix" button
98  QToolButton* btnFix = new QToolButton(this);
99  btnFix->setText(tr("Fix"));
100  connect(btnFix, &QToolButton::clicked,
102  layout->addWidget(btnFix);
103  }
104 
105  // "details" button
106  QToolButton* btnDetails = new QToolButton(this);
107  btnDetails->setText("?");
108  btnDetails->setToolTip(tr("Details"));
109  connect(btnDetails, &QToolButton::clicked, [this]() {
111  });
112  layout->addWidget(btnDetails);
113  }
115  const LibraryElementCheckListItemWidget& other) = delete;
117 
118  // Operator Overloadings
120  const LibraryElementCheckListItemWidget& rhs) = delete;
121 
122 private: // Methods
123  void resizeEvent(QResizeEvent* event) override {
124  QWidget::resizeEvent(event);
125  mIconLabel->setFixedWidth(mIconLabel->height());
126  }
127 
128 private: // Data
129  std::shared_ptr<const LibraryElementCheckMessage> mMessage;
131  QScopedPointer<QLabel> mIconLabel;
132 };
133 
134 /*******************************************************************************
135  * Class LibraryElementCheckListWidget
136  ******************************************************************************/
137 
142  : public QWidget,
144  Q_OBJECT
145 
146 public:
147  // Constructors / Destructor
148  explicit LibraryElementCheckListWidget(QWidget* parent = nullptr) noexcept;
150  delete;
152 
153  // Setters
154  void setHandler(IF_LibraryElementCheckHandler* handler) noexcept;
155  void setMessages(LibraryElementCheckMessageList messages) noexcept;
156 
157  // Operator Overloadings
159  const LibraryElementCheckListWidget& rhs) = delete;
160 
161 private: // Methods
162  void updateList() noexcept;
163  void itemDoubleClicked(QListWidgetItem* item) noexcept;
165  std::shared_ptr<const LibraryElementCheckMessage> msg) noexcept override;
167  std::shared_ptr<const LibraryElementCheckMessage> msg) noexcept override;
169  std::shared_ptr<const LibraryElementCheckMessage> msg) noexcept override;
170 
171 private: // Data
172  QScopedPointer<QListWidget> mListWidget;
175 };
176 
177 /*******************************************************************************
178  * End of File
179  ******************************************************************************/
180 
181 } // namespace editor
182 } // namespace library
183 } // namespace librepcb
184 
185 #endif // LIBREPCB_LIBRARY_EDITOR_LIBRARYELEMENTCHECKLISTWIDGET_H
virtual void libraryElementCheckDescriptionRequested(std::shared_ptr< const LibraryElementCheckMessage > msg) noexcept=0
void setHandler(IF_LibraryElementCheckHandler *handler) noexcept
Definition: libraryelementchecklistwidget.cpp:56
QVector< std::shared_ptr< const LibraryElementCheckMessage > > LibraryElementCheckMessageList
Definition: libraryelementcheckmessage.h:96
virtual bool libraryElementCheckFixAvailable(std::shared_ptr< const LibraryElementCheckMessage > msg) noexcept=0
IF_LibraryElementCheckHandler() noexcept
Definition: libraryelementchecklistwidget.h:54
IF_LibraryElementCheckHandler & mHandler
Definition: libraryelementchecklistwidget.h:130
IF_LibraryElementCheckHandler(const IF_LibraryElementCheckHandler &) noexcept
Definition: libraryelementchecklistwidget.h:55
LibraryElementCheckListItemWidget & operator=(const LibraryElementCheckListItemWidget &rhs)=delete
LibraryElementCheckListWidget & operator=(const LibraryElementCheckListWidget &rhs)=delete
LibraryElementCheckListWidget(QWidget *parent=nullptr) noexcept
Definition: libraryelementchecklistwidget.cpp:38
void setMessages(LibraryElementCheckMessageList messages) noexcept
Definition: libraryelementchecklistwidget.cpp:61
void resizeEvent(QResizeEvent *event) override
Definition: libraryelementchecklistwidget.h:123
std::shared_ptr< const LibraryElementCheckMessage > mMessage
Definition: libraryelementchecklistwidget.h:129
void itemDoubleClicked(QListWidgetItem *item) noexcept
Definition: libraryelementchecklistwidget.cpp:110
The LibraryElementCheckListItemWidget class.
Definition: libraryelementchecklistwidget.h:67
void libraryElementCheckFixRequested(std::shared_ptr< const LibraryElementCheckMessage > msg) noexceptoverride
Definition: libraryelementchecklistwidget.cpp:132
virtual ~IF_LibraryElementCheckHandler() noexcept
Definition: libraryelementchecklistwidget.h:57
Definition: libraryelementchecklistwidget.h:44
The LibraryElementCheckListWidget class.
Definition: libraryelementchecklistwidget.h:141
LibraryElementCheckListItemWidget(std::shared_ptr< const LibraryElementCheckMessage > msg, IF_LibraryElementCheckHandler &handler, QWidget *parent=nullptr) noexcept
Definition: libraryelementchecklistwidget.h:72
void libraryElementCheckDescriptionRequested(std::shared_ptr< const LibraryElementCheckMessage > msg) noexceptoverride
Definition: libraryelementchecklistwidget.cpp:139
IF_LibraryElementCheckHandler * mHandler
Definition: libraryelementchecklistwidget.h:173
LibraryElementCheckMessageList mMessages
Definition: libraryelementchecklistwidget.h:174
~LibraryElementCheckListItemWidget() noexcept
Definition: libraryelementchecklistwidget.h:116
QScopedPointer< QListWidget > mListWidget
Definition: libraryelementchecklistwidget.h:172
bool libraryElementCheckFixAvailable(std::shared_ptr< const LibraryElementCheckMessage > msg) noexceptoverride
Definition: libraryelementchecklistwidget.cpp:123
QScopedPointer< QLabel > mIconLabel
Definition: libraryelementchecklistwidget.h:131
void updateList() noexcept
Definition: libraryelementchecklistwidget.cpp:93
~LibraryElementCheckListWidget() noexcept
Definition: libraryelementchecklistwidget.cpp:49
virtual void libraryElementCheckFixRequested(std::shared_ptr< const LibraryElementCheckMessage > msg) noexcept=0