LibrePCB Developers Documentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
editabletablewidget.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_EDITABLETABLEWIDGET_H
21 #define LIBREPCB_EDITABLETABLEWIDGET_H
22 
23 /*******************************************************************************
24  * Includes
25  ******************************************************************************/
26 #include <QtCore>
27 #include <QtWidgets>
28 
29 /*******************************************************************************
30  * Namespace / Forward Declarations
31  ******************************************************************************/
32 namespace librepcb {
33 
34 /*******************************************************************************
35  * Class EditableTableWidget
36  ******************************************************************************/
37 
41 class EditableTableWidget : public QTableView {
42  Q_OBJECT
43 
44  typedef void (EditableTableWidget::*Signal)(const QVariant& data);
45 
46 public:
47  // Constructors / Destructor
48  explicit EditableTableWidget(QWidget* parent = nullptr) noexcept;
49  EditableTableWidget(const EditableTableWidget& other) = delete;
50  virtual ~EditableTableWidget() noexcept;
51 
52  // Setters
53  void setShowCopyButton(bool show) noexcept { mShowCopyButton = show; }
54  void setShowEditButton(bool show) noexcept { mShowEditButton = show; }
55  void setShowMoveButtons(bool show) noexcept { mShowMoveButtons = show; }
56  void setBrowseButtonColumn(int col) noexcept { mBrowseButtonColumn = col; }
57 
58  // Inherited
59  virtual void reset() override;
60 
61  // Operator Overloadings
63 
64 protected:
65  virtual void currentChanged(const QModelIndex& current,
66  const QModelIndex& previous) override;
67  virtual void rowsInserted(const QModelIndex& parent, int start,
68  int end) override;
69 
70 signals:
71  void currentRowChanged(int row);
72  void btnAddClicked(const QVariant& data);
73  void btnRemoveClicked(const QVariant& data);
74  void btnCopyClicked(const QVariant& data);
75  void btnEditClicked(const QVariant& data);
76  void btnMoveUpClicked(const QVariant& data);
77  void btnMoveDownClicked(const QVariant& data);
78  void btnBrowseClicked(const QVariant& data);
79 
80 private:
81  void installButtons(int row) noexcept;
82  QToolButton* createButton(const QString& objectName, const QIcon& icon,
83  const QString& text, const QString& toolTip,
84  int width, int height, Signal clickedSignal,
85  const QPersistentModelIndex& index) noexcept;
86  void buttonClickedHandler(Signal clickedSignal,
87  const QPersistentModelIndex& index) noexcept;
88 
93 };
94 
95 /*******************************************************************************
96  * End of File
97  ******************************************************************************/
98 
99 } // namespace librepcb
100 
101 #endif // LIBREPCB_EDITABLETABLEWIDGET_H
void btnMoveDownClicked(const QVariant &data)
void setShowEditButton(bool show) noexcept
Definition: editabletablewidget.h:54
void btnAddClicked(const QVariant &data)
bool mShowMoveButtons
Definition: editabletablewidget.h:91
void installButtons(int row) noexcept
Definition: editabletablewidget.cpp:92
void buttonClickedHandler(Signal clickedSignal, const QPersistentModelIndex &index) noexcept
Definition: editabletablewidget.cpp:177
void btnMoveUpClicked(const QVariant &data)
bool mShowCopyButton
Definition: editabletablewidget.h:89
EditableTableWidget(QWidget *parent=nullptr) noexcept
Definition: editabletablewidget.cpp:37
void btnCopyClicked(const QVariant &data)
virtual void reset() override
Definition: editabletablewidget.cpp:62
void btnBrowseClicked(const QVariant &data)
EditableTableWidget & operator=(const EditableTableWidget &rhs)=delete
A QTableView subclass which adds buttons to edit the underlying model.
Definition: editabletablewidget.h:41
void setBrowseButtonColumn(int col) noexcept
Definition: editabletablewidget.h:56
int mBrowseButtonColumn
Definition: editabletablewidget.h:92
The Signal class is used to emit signals on non-QObject derived classes.
Definition: signalslot.h:65
void setShowMoveButtons(bool show) noexcept
Definition: editabletablewidget.h:55
QToolButton * createButton(const QString &objectName, const QIcon &icon, const QString &text, const QString &toolTip, int width, int height, Signal clickedSignal, const QPersistentModelIndex &index) noexcept
Definition: editabletablewidget.cpp:159
void btnRemoveClicked(const QVariant &data)
virtual void currentChanged(const QModelIndex &current, const QModelIndex &previous) override
Definition: editabletablewidget.cpp:71
virtual void rowsInserted(const QModelIndex &parent, int start, int end) override
Definition: editabletablewidget.cpp:80
void btnEditClicked(const QVariant &data)
void setShowCopyButton(bool show) noexcept
Definition: editabletablewidget.h:53
bool mShowEditButton
Definition: editabletablewidget.h:90