LibrePCB Developers Documentation
Loading...
Searching...
No Matches
categorytreemodellegacy.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_CATEGORYTREEMODELLEGACY_H
21#define LIBREPCB_EDITOR_CATEGORYTREEMODELLEGACY_H
22
23/*******************************************************************************
24 * Includes
25 ******************************************************************************/
27
28#include <QtCore>
29
30#include <memory>
31
32/*******************************************************************************
33 * Namespace / Forward Declarations
34 ******************************************************************************/
35namespace librepcb {
36
37class WorkspaceLibraryDb;
38
39namespace editor {
40
41/*******************************************************************************
42 * Class CategoryTreeModelLegacy
43 ******************************************************************************/
44
48class CategoryTreeModelLegacy final : public QAbstractItemModel {
49 struct Item {
50 std::weak_ptr<Item> parent;
51 std::optional<Uuid> uuid;
52 QString text;
53 QString tooltip;
54 QVector<std::shared_ptr<Item>> childs;
55 };
56
57public:
58 // Types
59 enum class Filter {
61 CmpCat = 1 << 0,
63 CmpCatWithSymbols = 1 << 1,
65 CmpCatWithComponents = 1 << 2,
67 CmpCatWithDevices = 1 << 3,
69 PkgCat = 1 << 4,
71 PkgCatWithPackages = 1 << 5,
72 };
73 Q_DECLARE_FLAGS(Filters, Filter)
74
75 // Constructors / Destructor
78 explicit CategoryTreeModelLegacy(const WorkspaceLibraryDb& library,
79 const QStringList& localeOrder,
80 Filters filters) noexcept;
81 ~CategoryTreeModelLegacy() noexcept;
82
83 // Setters
84 void setLocaleOrder(const QStringList& order) noexcept;
85
86 // Inherited Methods
87 int columnCount(
88 const QModelIndex& parent = QModelIndex()) const noexcept override;
89 int rowCount(
90 const QModelIndex& parent = QModelIndex()) const noexcept override;
91 QModelIndex index(
92 int row, int column,
93 const QModelIndex& parent = QModelIndex()) const noexcept override;
94 QModelIndex parent(const QModelIndex& index) const noexcept override;
95 QVariant headerData(int section, Qt::Orientation orientation,
96 int role = Qt::DisplayRole) const noexcept override;
97 QVariant data(const QModelIndex& index,
98 int role = Qt::DisplayRole) const noexcept override;
99
100 // Operator Overloadings
102 delete;
103
104private: // Methods
105 void update() noexcept;
106 QVector<std::shared_ptr<Item>> getChilds(
107 std::shared_ptr<Item> parent) const noexcept;
108 bool containsItems(const std::optional<Uuid>& uuid) const;
109 bool listAll() const noexcept;
110 bool listPackageCategories() const noexcept;
111 void updateModelItem(
112 std::shared_ptr<Item> parentItem,
113 const QVector<std::shared_ptr<Item>>& newChilds) noexcept;
114 Item* itemFromIndex(const QModelIndex& index) const noexcept;
115 QModelIndex indexFromItem(const Item* item) const noexcept;
116
117private: // Data
119 QStringList mLocaleOrder;
120 const Filters mFilters;
121 std::shared_ptr<Item> mRootItem;
122};
123
124} // namespace editor
125} // namespace librepcb
126
127Q_DECLARE_OPERATORS_FOR_FLAGS(
128 librepcb::editor::CategoryTreeModelLegacy::Filters)
129
130/*******************************************************************************
131 * End of File
132 ******************************************************************************/
133
134#endif
The Uuid class is a replacement for QUuid to get UUID strings without {} braces.
Definition uuid.h:56
The WorkspaceLibraryDb class.
Definition workspacelibrarydb.h:58
The CategoryTreeModelLegacy class.
Definition categorytreemodellegacy.h:48
QVariant headerData(int section, Qt::Orientation orientation, int role=Qt::DisplayRole) const noexcept override
Definition categorytreemodellegacy.cpp:105
void updateModelItem(std::shared_ptr< Item > parentItem, const QVector< std::shared_ptr< Item > > &newChilds) noexcept
Definition categorytreemodellegacy.cpp:246
QVector< std::shared_ptr< Item > > getChilds(std::shared_ptr< Item > parent) const noexcept
Definition categorytreemodellegacy.cpp:169
bool listPackageCategories() const noexcept
Definition categorytreemodellegacy.cpp:241
std::shared_ptr< Item > mRootItem
Definition categorytreemodellegacy.h:121
QModelIndex parent(const QModelIndex &index) const noexcept override
Definition categorytreemodellegacy.cpp:96
Item * itemFromIndex(const QModelIndex &index) const noexcept
Definition categorytreemodellegacy.cpp:290
QModelIndex indexFromItem(const Item *item) const noexcept
Definition categorytreemodellegacy.cpp:305
bool listAll() const noexcept
Definition categorytreemodellegacy.cpp:237
QModelIndex index(int row, int column, const QModelIndex &parent=QModelIndex()) const noexcept override
Definition categorytreemodellegacy.cpp:86
bool containsItems(const std::optional< Uuid > &uuid) const
Definition categorytreemodellegacy.cpp:213
int columnCount(const QModelIndex &parent=QModelIndex()) const noexcept override
Definition categorytreemodellegacy.cpp:74
int rowCount(const QModelIndex &parent=QModelIndex()) const noexcept override
Definition categorytreemodellegacy.cpp:80
const Filters mFilters
Definition categorytreemodellegacy.h:120
void update() noexcept
Definition categorytreemodellegacy.cpp:140
Filter
Definition categorytreemodellegacy.h:59
@ CmpCat
Show all component categories, even empty ones.
@ CmpCatWithDevices
Show component categories containing devices.
@ PkgCatWithPackages
Show package categories containing packages.
@ CmpCatWithSymbols
Show component categories containing symbols.
@ PkgCat
Show all package categories, even empty ones.
@ CmpCatWithComponents
Show component categories containing components.
QStringList mLocaleOrder
Definition categorytreemodellegacy.h:119
void setLocaleOrder(const QStringList &order) noexcept
Definition categorytreemodellegacy.cpp:62
const WorkspaceLibraryDb & mLibrary
Definition categorytreemodellegacy.h:118
QVariant data(const QModelIndex &index, int role=Qt::DisplayRole) const noexcept override
Definition categorytreemodellegacy.cpp:119
Definition occmodel.cpp:77
Definition uuid.h:186
Definition categorytreemodellegacy.h:49
QString text
Definition categorytreemodellegacy.h:52
std::optional< Uuid > uuid
std::nullopt for items without category
Definition categorytreemodellegacy.h:51
QString tooltip
Definition categorytreemodellegacy.h:53
QVector< std::shared_ptr< Item > > childs
Definition categorytreemodellegacy.h:54
std::weak_ptr< Item > parent
nullptr for root categories
Definition categorytreemodellegacy.h:50