LibrePCB Developers Documentation
Loading...
Searching...
No Matches
menubuilder.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_MENUBUILDER_H
21#define LIBREPCB_EDITOR_MENUBUILDER_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 MenuBuilder
37 ******************************************************************************/
38
42class MenuBuilder final {
43 Q_DECLARE_TR_FUNCTIONS(MenuBuilder)
44
45public:
46 // Types
47 typedef QMenu* (*MenuFactory)(QWidget*);
48
49 enum class Flag {
50 DefaultAction = (1 << 0),
51 };
52 Q_DECLARE_FLAGS(Flags, Flag)
53
54 // Constructors / Destructor
55 MenuBuilder() = delete;
56 MenuBuilder(const MenuBuilder& other) = delete;
57 explicit MenuBuilder(QMenuBar* menuBar) noexcept;
58 explicit MenuBuilder(QMenu* menu) noexcept;
59 ~MenuBuilder() noexcept;
60
61 // General Methods
62 QMenu* newMenu(MenuFactory factory) noexcept;
63 QMenu* addSubMenu(MenuFactory factory) noexcept;
64 QMenu* addSubMenu(const QString& objectName, const QString& title,
65 const QIcon& icon = QIcon()) noexcept;
66 void addAction(QAction* action, Flags flags = Flags()) noexcept;
67 void addAction(const QScopedPointer<QAction>& action,
68 Flags flags = Flags()) noexcept;
69 void addSection(const QString& text, const QIcon& icon = QIcon()) noexcept;
70 void addSeparator() noexcept;
71
72 // Operator Overloadings
73 MenuBuilder& operator=(const MenuBuilder& rhs) = delete;
74
75 // Static Methods
76 static QMenu* createChangeDeviceMenu(QWidget* parent) noexcept;
77 static QMenu* createChangeFootprintMenu(QWidget* parent) noexcept;
78 static QMenu* createChangeModelMenu(QWidget* parent) noexcept;
79 static QMenu* createMoreResourcesMenu(QWidget* parent) noexcept;
80
81private: // Methods
82 static QMenu* createMenu(const QString& objectName, const QString& text,
83 const QIcon& icon, QWidget* parent) noexcept;
84
85private: // Data
86 QMenuBar* mMenuBar;
87 QPointer<QMenu> mMenu;
88};
89
90} // namespace editor
91} // namespace librepcb
92
93Q_DECLARE_OPERATORS_FOR_FLAGS(librepcb::editor::MenuBuilder::Flags)
94
95/*******************************************************************************
96 * End of File
97 ******************************************************************************/
98
99#endif
Helper to easily create a QMenu.
Definition menubuilder.h:42
static QMenu * createMenu(const QString &objectName, const QString &text, const QIcon &icon, QWidget *parent) noexcept
Definition menubuilder.cpp:135
QMenu * addSubMenu(MenuFactory factory) noexcept
Definition menubuilder.cpp:63
QMenuBar * mMenuBar
Definition menubuilder.h:86
static QMenu * createMoreResourcesMenu(QWidget *parent) noexcept
Definition menubuilder.cpp:127
Flag
Definition menubuilder.h:49
@ DefaultAction
Set action as default.
QMenu * newMenu(MenuFactory factory) noexcept
Definition menubuilder.cpp:55
void addAction(QAction *action, Flags flags=Flags()) noexcept
Definition menubuilder.cpp:82
static QMenu * createChangeDeviceMenu(QWidget *parent) noexcept
Definition menubuilder.cpp:112
QMenu *(* MenuFactory)(QWidget *)
Definition menubuilder.h:47
static QMenu * createChangeModelMenu(QWidget *parent) noexcept
Definition menubuilder.cpp:122
void addSection(const QString &text, const QIcon &icon=QIcon()) noexcept
Definition menubuilder.cpp:96
static QMenu * createChangeFootprintMenu(QWidget *parent) noexcept
Definition menubuilder.cpp:117
QPointer< QMenu > mMenu
Definition menubuilder.h:87
void addSeparator() noexcept
Definition menubuilder.cpp:102
Definition occmodel.cpp:77