QElectroTech 0.100.0-dev
Loading...
Searching...
No Matches
genericpanel.h
Go to the documentation of this file.
1/*
2 Copyright 2006-2024 The QElectroTech Team
3 This file is part of QElectroTech.
4
5 QElectroTech is free software: you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation, either version 2 of the License, or
8 (at your option) any later version.
9
10 QElectroTech is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with QElectroTech. If not, see <http://www.gnu.org/licenses/>.
17*/
18#ifndef GENERIC_PANEL_H
19#define GENERIC_PANEL_H
20#include "qet.h"
21#include <QTreeWidget>
22
23class QTreeWidgetItem;
24class QETProject;
25class Diagram;
28
36class GenericPanel : public QTreeWidget {
37 Q_OBJECT
38
39 public:
48 Q_DECLARE_FLAGS(PanelOptions, PanelOption)
49
50 enum MetaData {
51 Item = Qt::UserRole + 1,
55 };
56
57 // Constructors, destructor
58 public:
59 GenericPanel(QWidget * = nullptr);
60 ~GenericPanel() override;
61
62 public:
63 // convenience methods to obtain what an item represents
64 virtual int currentItemType();
65 virtual QETProject *projectForItem(QTreeWidgetItem *) const;
66 virtual Diagram *diagramForItem(QTreeWidgetItem *) const;
68 QTreeWidgetItem *) const;
69
70 // convenience methods to obtain what the selected item represents
71 virtual QETProject *selectedProject() const;
72 virtual Diagram *selectedDiagram() const;
74
75 // project-related methods
76 public:
77 virtual QTreeWidgetItem *addProject(QETProject *,
78 QTreeWidgetItem * = nullptr,
79 PanelOptions = AddAllChild);
80 virtual QTreeWidgetItem *itemForProject(QETProject *);
81 protected:
82 virtual QTreeWidgetItem *getItemForProject(QETProject *,
83 bool * = nullptr);
84 virtual QTreeWidgetItem *updateProjectItem(QTreeWidgetItem *,
85 QETProject *,
86 PanelOptions = AddAllChild,
87 bool = false);
88 virtual QTreeWidgetItem *fillProjectItem (QTreeWidgetItem *,
89 QETProject *,
90 PanelOptions = AddAllChild,
91 bool = false);
92
93 // diagram-related methods
94 public:
95 virtual QTreeWidgetItem *addDiagram(Diagram *,
96 QTreeWidgetItem * = nullptr,
97 PanelOptions = AddAllChild);
98 protected:
99 virtual QTreeWidgetItem *getItemForDiagram(Diagram *, bool * = nullptr);
100 virtual QTreeWidgetItem *updateDiagramItem(QTreeWidgetItem *,
101 Diagram *,
102 PanelOptions = AddAllChild,
103 bool = false);
104 virtual QTreeWidgetItem *fillDiagramItem(
105 QTreeWidgetItem *,
106 PanelOptions = AddAllChild,
107 bool = false);
108
109 // title block templates collections methods
110 public:
111 virtual QTreeWidgetItem *addTemplatesCollection(
113 QTreeWidgetItem * = nullptr,
114 PanelOptions = AddAllChild);
115 virtual QTreeWidgetItem *itemForTemplatesCollection(
117 protected:
118 virtual QTreeWidgetItem *getItemForTemplatesCollection(
120 bool * = nullptr);
121 virtual QTreeWidgetItem *updateTemplatesCollectionItem(
122 QTreeWidgetItem *,
124 PanelOptions = AddAllChild,
125 bool = false);
126 virtual QTreeWidgetItem *fillTemplatesCollectionItem(
127 QTreeWidgetItem *,
129 PanelOptions = AddAllChild,
130 bool = false);
131
132 // title block templates methods
133 public:
134 virtual QTreeWidgetItem *addTemplate(const TitleBlockTemplateLocation &,
135 QTreeWidgetItem * = nullptr,
136 PanelOptions = AddAllChild);
137 protected:
138 virtual QTreeWidgetItem *getItemForTemplate(
140 bool * = nullptr);
141 virtual QTreeWidgetItem *updateTemplateItem(
142 QTreeWidgetItem *,
144 PanelOptions = AddAllChild,
145 bool = false);
146 virtual QTreeWidgetItem *fillTemplateItem (
147 QTreeWidgetItem *,
149 PanelOptions = AddAllChild,
150 bool = false);
151
152 // generic methods
153 protected:
154 virtual QTreeWidgetItem *updateItem(QTreeWidgetItem *,
155 PanelOptions = AddAllChild,
156 bool = false);
157 virtual QTreeWidgetItem *fillItem(QTreeWidgetItem *,
158 PanelOptions = AddAllChild,
159 bool = false);
160
161 // slots used to receive change notifications from added objects
162 protected slots:
164 virtual void diagramAdded(QETProject *, Diagram *);
165 virtual void diagramRemoved(QETProject *, Diagram *);
166 virtual void projectDiagramsOrderChanged(QETProject *, int, int);
167 virtual void diagramTitleChanged(Diagram *);
169 const QString &);
171 const QString &);
172
173 // various other methods
174 protected:
175 virtual QString defaultText(QET::ItemType);
176 virtual QIcon defaultIcon(QET::ItemType);
177 virtual QTreeWidgetItem *makeItem(QET::ItemType,
178 QTreeWidgetItem * = nullptr,
179 const QString & = QString(),
180 const QIcon & = QIcon());
181 virtual void deleteItem(QTreeWidgetItem *, bool = false);
182 virtual void markItemAsUnused(QTreeWidgetItem *);
183 virtual void reparent(QTreeWidgetItem *, QTreeWidgetItem *);
184 QList<QTreeWidgetItem *> childItems(QTreeWidgetItem *,
185 QET::ItemType, bool = false) const;
186 template<typename T> void removeObsoleteItems(const QList<T> &,
187 QTreeWidgetItem *,
189 bool);
190 template<typename T> T valueForItem(QTreeWidgetItem *) const;
191 void unregisterItem(QTreeWidgetItem *);
192
193 bool event(QEvent *) override;
194
195 signals:
198
199 private slots:
200 void emitFirstActivated();
201
202 private:
213 QHash<QETProject *, QTreeWidgetItem *> projects_;
218 QHash<Diagram *, QTreeWidgetItem *> diagrams_;
224 QHash<TitleBlockTemplateLocation, QTreeWidgetItem *> tb_templates_;
225};
226#endif
The Diagram class This class represents an electric diagram. It manages its various child elements,...
Definition diagram.h:56
The GenericPanel class The generic panel is a QTreeWidget subclass providing extra methods allowing d...
Definition genericpanel.h:36
T valueForItem(QTreeWidgetItem *) const
Definition genericpanel.cpp:988
QHash< QETProject *, QTreeWidgetItem * > projects_
projects_ Allow quick retrieval of the item representing a given project
Definition genericpanel.h:213
virtual QTreeWidgetItem * fillItem(QTreeWidgetItem *, PanelOptions=AddAllChild, bool=false)
GenericPanel::fillItem This generic method is called at the end of each fill*Item method....
Definition genericpanel.cpp:711
bool event(QEvent *) override
GenericPanel::event Handle various events; reimplemented here to emit the signal firstActivated().
Definition genericpanel.cpp:1025
virtual QTreeWidgetItem * addDiagram(Diagram *, QTreeWidgetItem *=nullptr, PanelOptions=AddAllChild)
GenericPanel::addDiagram.
Definition genericpanel.cpp:292
virtual QTreeWidgetItem * itemForTemplatesCollection(TitleBlockTemplatesCollection *)
GenericPanel::itemForTemplatesCollection.
Definition genericpanel.cpp:455
virtual QTreeWidgetItem * getItemForProject(QETProject *, bool *=nullptr)
Definition genericpanel.cpp:166
virtual QString defaultText(QET::ItemType)
GenericPanel::defaultText.
Definition genericpanel.cpp:832
virtual QTreeWidgetItem * fillDiagramItem(QTreeWidgetItem *, PanelOptions=AddAllChild, bool=false)
GenericPanel::fillDiagramItem.
Definition genericpanel.cpp:411
QHash< TitleBlockTemplateLocation, QTreeWidgetItem * > tb_templates_
tb_templates_ Allow quick retrieval of the item representing a title block template
Definition genericpanel.h:224
virtual QTreeWidgetItem * addProject(QETProject *, QTreeWidgetItem *=nullptr, PanelOptions=AddAllChild)
GenericPanel::addProject.
Definition genericpanel.cpp:133
void unregisterItem(QTreeWidgetItem *)
GenericPanel::unregisterItem.
Definition genericpanel.cpp:1005
virtual QTreeWidgetItem * fillTemplatesCollectionItem(QTreeWidgetItem *, TitleBlockTemplatesCollection *, PanelOptions=AddAllChild, bool=false)
GenericPanel::fillTemplatesCollectionItem.
Definition genericpanel.cpp:524
virtual QETProject * projectForItem(QTreeWidgetItem *) const
GenericPanel::projectForItem.
Definition genericpanel.cpp:63
void emitFirstActivated()
GenericPanel::emitFirstActivated Emit the signal firstActivated().
Definition genericpanel.cpp:1040
virtual void projectDiagramsOrderChanged(QETProject *, int, int)
GenericPanel::projectDiagramsOrderChanged.
Definition genericpanel.cpp:756
virtual QTreeWidgetItem * getItemForTemplatesCollection(TitleBlockTemplatesCollection *, bool *=nullptr)
GenericPanel::getItemForTemplatesCollection.
Definition genericpanel.cpp:467
virtual QTreeWidgetItem * fillTemplateItem(QTreeWidgetItem *, const TitleBlockTemplateLocation &, PanelOptions=AddAllChild, bool=false)
GenericPanel::fillTemplateItem.
Definition genericpanel.cpp:673
~GenericPanel() override
Definition genericpanel.cpp:44
virtual Diagram * selectedDiagram() const
GenericPanel::selectedDiagram.
Definition genericpanel.cpp:112
virtual QTreeWidgetItem * addTemplatesCollection(TitleBlockTemplatesCollection *, QTreeWidgetItem *=nullptr, PanelOptions=AddAllChild)
GenericPanel::addTemplatesCollection.
Definition genericpanel.cpp:426
virtual QTreeWidgetItem * addTemplate(const TitleBlockTemplateLocation &, QTreeWidgetItem *=nullptr, PanelOptions=AddAllChild)
GenericPanel::addTemplate.
Definition genericpanel.cpp:577
virtual QTreeWidgetItem * getItemForDiagram(Diagram *, bool *=nullptr)
GenericPanel::getItemForDiagram.
Definition genericpanel.cpp:315
void removeObsoleteItems(const QList< T > &, QTreeWidgetItem *, QET::ItemType, bool)
Definition genericpanel.cpp:969
virtual QTreeWidgetItem * updateProjectItem(QTreeWidgetItem *, QETProject *, PanelOptions=AddAllChild, bool=false)
GenericPanel::updateProjectItem.
Definition genericpanel.cpp:189
virtual void markItemAsUnused(QTreeWidgetItem *)
GenericPanel::markItemAsUnused Mark the provided QTreeWidgetItem as unused in its parent project.
Definition genericpanel.cpp:911
virtual void reparent(QTreeWidgetItem *, QTreeWidgetItem *)
GenericPanel::reparent.
Definition genericpanel.cpp:926
virtual QETProject * selectedProject() const
GenericPanel::selectedProject.
Definition genericpanel.cpp:103
virtual void diagramUsedTemplate(TitleBlockTemplatesCollection *, const QString &)
GenericPanel::diagramUsedTemplate.
Definition genericpanel.cpp:819
virtual void diagramRemoved(QETProject *, Diagram *)
GenericPanel::diagramRemoved.
Definition genericpanel.cpp:744
MetaData
Definition genericpanel.h:50
@ AliasItem
Definition genericpanel.h:52
@ Parent
Definition genericpanel.h:53
@ Item
Definition genericpanel.h:51
@ PanelFlags
Definition genericpanel.h:54
virtual QTreeWidgetItem * updateDiagramItem(QTreeWidgetItem *, Diagram *, PanelOptions=AddAllChild, bool=false)
GenericPanel::updateDiagramItem.
Definition genericpanel.cpp:338
virtual QTreeWidgetItem * fillProjectItem(QTreeWidgetItem *, QETProject *, PanelOptions=AddAllChild, bool=false)
GenericPanel::fillProjectItem.
Definition genericpanel.cpp:237
virtual TitleBlockTemplateLocation templateLocationForItem(QTreeWidgetItem *) const
GenericPanel::templateLocationForItem.
Definition genericpanel.cpp:90
virtual QIcon defaultIcon(QET::ItemType)
GenericPanel::defaultIcon.
Definition genericpanel.cpp:855
virtual void deleteItem(QTreeWidgetItem *, bool=false)
GenericPanel::deleteItem Delete and item and its children.
Definition genericpanel.cpp:894
virtual Diagram * diagramForItem(QTreeWidgetItem *) const
GenericPanel::diagramForItem.
Definition genericpanel.cpp:77
virtual QTreeWidgetItem * updateItem(QTreeWidgetItem *, PanelOptions=AddAllChild, bool=false)
GenericPanel::updateItem This generic method is called at the end of each update*Item method....
Definition genericpanel.cpp:692
bool firstActivated()
virtual QTreeWidgetItem * updateTemplateItem(QTreeWidgetItem *, const TitleBlockTemplateLocation &, PanelOptions=AddAllChild, bool=false)
GenericPanel::updateTemplateItem.
Definition genericpanel.cpp:630
QList< QTreeWidgetItem * > childItems(QTreeWidgetItem *, QET::ItemType, bool=false) const
GenericPanel::childItems.
Definition genericpanel.cpp:939
virtual void templatesCollectionChanged(TitleBlockTemplatesCollection *, const QString &)
GenericPanel::templatesCollectionChanged.
Definition genericpanel.cpp:806
virtual void diagramAdded(QETProject *, Diagram *)
GenericPanel::diagramAdded.
Definition genericpanel.cpp:733
bool first_activation_
first_activation_ boolean used to track the first time this widget is activated/shown
Definition genericpanel.h:208
virtual QTreeWidgetItem * makeItem(QET::ItemType, QTreeWidgetItem *=nullptr, const QString &=QString(), const QIcon &=QIcon())
GenericPanel::makeItem Create a QTreeWidgetItem.
Definition genericpanel.cpp:877
virtual QTreeWidgetItem * itemForProject(QETProject *)
Definition genericpanel.cpp:153
PanelOption
Definition genericpanel.h:40
@ AddAllChildTemplates
Definition genericpanel.h:44
@ All
Definition genericpanel.h:46
@ AddChildDiagrams
Definition genericpanel.h:41
@ AddChildTemplatesCollection
Definition genericpanel.h:42
@ AddChildTemplates
Definition genericpanel.h:43
@ AddAllChild
Definition genericpanel.h:45
virtual QTreeWidgetItem * getItemForTemplate(const TitleBlockTemplateLocation &, bool *=nullptr)
GenericPanel::getItemForTemplate.
Definition genericpanel.cpp:605
virtual void diagramTitleChanged(Diagram *)
GenericPanel::diagramTitleChanged Inform this panel the diagram diagram has changed its title to titl...
Definition genericpanel.cpp:795
virtual void projectInformationsChanged(QETProject *)
GenericPanel::projectInformationsChanged.
Definition genericpanel.cpp:723
QHash< Diagram *, QTreeWidgetItem * > diagrams_
diagrams_ Allow quick retrieval of the item representing a given diagram
Definition genericpanel.h:218
void panelContentChanged()
virtual QTreeWidgetItem * updateTemplatesCollectionItem(QTreeWidgetItem *, TitleBlockTemplatesCollection *, PanelOptions=AddAllChild, bool=false)
GenericPanel::updateTemplatesCollectionItem.
Definition genericpanel.cpp:492
virtual TitleBlockTemplateLocation selectedTemplateLocation() const
GenericPanel::selectedTemplateLocation.
Definition genericpanel.cpp:121
virtual int currentItemType()
Definition genericpanel.cpp:51
Definition qetproject.h:62
Definition templatelocation.h:29
Definition templatescollection.h:35
ItemType
Definition qet.h:95