LibrePCB Developers Documentation
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_EDITOR_EDITABLETABLEWIDGET_H
21#define LIBREPCB_EDITOR_EDITABLETABLEWIDGET_H
22
23/*******************************************************************************
24 * Includes
25 ******************************************************************************/
26#include <QtCore>
27#include <QtWidgets>
28
29/*******************************************************************************
30 * Namespace / Forward Declarations
31 ******************************************************************************/
32namespace librepcb {
33namespace editor {
34
35/*******************************************************************************
36 * Class EditableTableWidget
37 ******************************************************************************/
38
42class EditableTableWidget : public QTableView {
43 Q_OBJECT
44
45 typedef void (EditableTableWidget::*Signal)(const QPersistentModelIndex&);
46
47public:
48 // Constructors / Destructor
49 explicit EditableTableWidget(QWidget* parent = nullptr) noexcept;
51 virtual ~EditableTableWidget() noexcept;
52
53 // Setters
54 virtual void setModel(QAbstractItemModel* model) noexcept override;
55 void setReadOnly(bool readOnly) noexcept;
56 void setAddButtonOnLastRow(bool btn) noexcept { mAddButtonOnLastRow = btn; }
57 void setShowCopyButton(bool show) noexcept { mShowCopyButton = show; }
58 void setShowEditButton(bool show) noexcept { mShowEditButton = show; }
59 void setShowMoveButtons(bool show) noexcept { mShowMoveButtons = show; }
60 void setBrowseButtonColumn(int col) noexcept { mBrowseButtonColumn = col; }
61 void setMinimumRowCount(int count) noexcept;
62
63 // Inherited
64 using QAbstractItemView::edit; // Required to override edit() overload below.
65 virtual void reset() override;
66
67 // Operator Overloadings
69
70protected:
71 virtual bool edit(const QModelIndex& index, EditTrigger trigger,
72 QEvent* event) override;
73 virtual void currentChanged(const QModelIndex& current,
74 const QModelIndex& previous) override;
75 virtual void rowsInserted(const QModelIndex& parent, int start,
76 int end) override;
77
78signals:
79 void readOnlyChanged(bool readOnly);
80 void canRemoveChanged(bool canRemove);
81 void currentRowChanged(int row);
82 void btnAddClicked(const QPersistentModelIndex& itemIndex);
83 void btnRemoveClicked(const QPersistentModelIndex& itemIndex);
84 void btnCopyClicked(const QPersistentModelIndex& itemIndex);
85 void btnEditClicked(const QPersistentModelIndex& itemIndex);
86 void btnMoveUpClicked(const QPersistentModelIndex& itemIndex);
87 void btnMoveDownClicked(const QPersistentModelIndex& itemIndex);
88 void btnBrowseClicked(const QPersistentModelIndex& itemIndex);
89
90private:
91 void updateCanRemove() noexcept;
92 void installButtons(int row) noexcept;
93 QToolButton* createButton(const QString& objectName, const QIcon& icon,
94 const QString& text, const QString& toolTip,
95 int width, int height, Signal clickedSignal,
96 const QPersistentModelIndex& itemIndex,
97 bool doesModify, bool doesRemove) noexcept;
98 void buttonClickedHandler(Signal clickedSignal,
99 const QPersistentModelIndex& itemIndex) noexcept;
100
109
110 QScopedPointer<QAction> mActionAddRow;
111 QScopedPointer<QAction> mActionRemoveRow;
112 QMetaObject::Connection mRowsRemovedConnection;
113};
114
115/*******************************************************************************
116 * End of File
117 ******************************************************************************/
118
119} // namespace editor
120} // namespace librepcb
121
122#endif
The Signal class is used to emit signals on non-QObject derived classes.
Definition: signalslot.h:65
A QTableView subclass which adds buttons to edit the underlying model.
Definition: editabletablewidget.h:42
bool mReadOnly
Definition: editabletablewidget.h:108
void btnAddClicked(const QPersistentModelIndex &itemIndex)
bool mCanRemove
Definition: editabletablewidget.h:107
bool mShowCopyButton
Definition: editabletablewidget.h:102
void installButtons(int row) noexcept
Definition: editabletablewidget.cpp:182
void btnEditClicked(const QPersistentModelIndex &itemIndex)
bool mAddButtonOnLastRow
Definition: editabletablewidget.h:101
void canRemoveChanged(bool canRemove)
virtual void currentChanged(const QModelIndex &current, const QModelIndex &previous) override
Definition: editabletablewidget.cpp:144
void setReadOnly(bool readOnly) noexcept
Definition: editabletablewidget.cpp:106
void setMinimumRowCount(int count) noexcept
Definition: editabletablewidget.cpp:114
void btnMoveDownClicked(const QPersistentModelIndex &itemIndex)
QScopedPointer< QAction > mActionRemoveRow
Definition: editabletablewidget.h:111
QToolButton * createButton(const QString &objectName, const QIcon &icon, const QString &text, const QString &toolTip, int width, int height, Signal clickedSignal, const QPersistentModelIndex &itemIndex, bool doesModify, bool doesRemove) noexcept
Definition: editabletablewidget.cpp:255
void setAddButtonOnLastRow(bool btn) noexcept
Definition: editabletablewidget.h:56
void btnMoveUpClicked(const QPersistentModelIndex &itemIndex)
EditableTableWidget(QWidget *parent=nullptr) noexcept
Definition: editabletablewidget.cpp:40
void setShowCopyButton(bool show) noexcept
Definition: editabletablewidget.h:57
void btnRemoveClicked(const QPersistentModelIndex &itemIndex)
void setShowEditButton(bool show) noexcept
Definition: editabletablewidget.h:58
QMetaObject::Connection mRowsRemovedConnection
Definition: editabletablewidget.h:112
EditableTableWidget & operator=(const EditableTableWidget &rhs)=delete
virtual void setModel(QAbstractItemModel *model) noexcept override
Definition: editabletablewidget.cpp:92
void btnCopyClicked(const QPersistentModelIndex &itemIndex)
bool mShowMoveButtons
Definition: editabletablewidget.h:104
int mBrowseButtonColumn
Definition: editabletablewidget.h:105
bool mShowEditButton
Definition: editabletablewidget.h:103
void updateCanRemove() noexcept
Definition: editabletablewidget.cpp:172
void setShowMoveButtons(bool show) noexcept
Definition: editabletablewidget.h:59
virtual bool edit(const QModelIndex &index, EditTrigger trigger, QEvent *event) override
Definition: editabletablewidget.cpp:135
void buttonClickedHandler(Signal clickedSignal, const QPersistentModelIndex &itemIndex) noexcept
Definition: editabletablewidget.cpp:284
QScopedPointer< QAction > mActionAddRow
Definition: editabletablewidget.h:110
int mMinimumRowCount
Definition: editabletablewidget.h:106
void btnBrowseClicked(const QPersistentModelIndex &itemIndex)
virtual void reset() override
Definition: editabletablewidget.cpp:125
virtual void rowsInserted(const QModelIndex &parent, int start, int end) override
Definition: editabletablewidget.cpp:159
void setBrowseButtonColumn(int col) noexcept
Definition: editabletablewidget.h:60
Definition: occmodel.cpp:77