QElectroTech  0.8-dev
genericpanel.h
Go to the documentation of this file.
1 /*
2  Copyright 2006-2020 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 
23 class QTreeWidgetItem;
24 class QETProject;
25 class Diagram;
28 
36 class GenericPanel : public QTreeWidget {
37  Q_OBJECT
38 
39  public:
40  enum PanelOption {
46  All = 127
47  };
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 (QTreeWidgetItem *,
105  Diagram *,
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:
163  virtual void projectInformationsChanged(QETProject *);
164  virtual void diagramAdded(QETProject *, Diagram *);
165  virtual void diagramRemoved(QETProject *, Diagram *);
166  virtual void projectDiagramsOrderChanged(QETProject *, int, int);
167  virtual void diagramTitleChanged(Diagram *, const QString &);
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
QETProject::readOnlyChanged
void readOnlyChanged(QETProject *, bool)
QET::Project
@ Project
Definition: qet.h:109
GenericPanel::getItemForDiagram
virtual QTreeWidgetItem * getItemForDiagram(Diagram *, bool *=nullptr)
GenericPanel::getItemForDiagram.
Definition: genericpanel.cpp:305
GenericPanel::Parent
@ Parent
Definition: genericpanel.h:53
QET::TitleBlockTemplatesCollection
@ TitleBlockTemplatesCollection
Definition: qet.h:106
GenericPanel::event
bool event(QEvent *) override
GenericPanel::event Handle various events; reimplemented here to emit the signal firstActivated().
Definition: genericpanel.cpp:1016
GenericPanel::reparent
virtual void reparent(QTreeWidgetItem *, QTreeWidgetItem *)
GenericPanel::reparent.
Definition: genericpanel.cpp:919
GenericPanel::projectInformationsChanged
virtual void projectInformationsChanged(QETProject *)
GenericPanel::projectInformationsChanged.
Definition: genericpanel.cpp:714
GenericPanel::valueForItem
T valueForItem(QTreeWidgetItem *) const
Definition: genericpanel.cpp:980
GenericPanel::getItemForTemplate
virtual QTreeWidgetItem * getItemForTemplate(const TitleBlockTemplateLocation &, bool *=nullptr)
GenericPanel::getItemForTemplate.
Definition: genericpanel.cpp:596
GenericPanel
The GenericPanel class The generic panel is a QTreeWidget subclass providing extra methods allowing d...
Definition: genericpanel.h:36
GenericPanel::updateTemplateItem
virtual QTreeWidgetItem * updateTemplateItem(QTreeWidgetItem *, const TitleBlockTemplateLocation &, PanelOptions=AddAllChild, bool=false)
GenericPanel::updateTemplateItem.
Definition: genericpanel.cpp:621
GenericPanel::templateLocationForItem
virtual TitleBlockTemplateLocation templateLocationForItem(QTreeWidgetItem *) const
GenericPanel::templateLocationForItem.
Definition: genericpanel.cpp:84
QETProject::projectDiagramsOrderChanged
void projectDiagramsOrderChanged(QETProject *, int, int)
GenericPanel::fillProjectItem
virtual QTreeWidgetItem * fillProjectItem(QTreeWidgetItem *, QETProject *, PanelOptions=AddAllChild, bool=false)
GenericPanel::fillProjectItem.
Definition: genericpanel.cpp:227
GenericPanel::removeObsoleteItems
void removeObsoleteItems(const QList< T > &, QTreeWidgetItem *, QET::ItemType, bool)
Definition: genericpanel.cpp:961
GenericPanel::AliasItem
@ AliasItem
Definition: genericpanel.h:52
GenericPanel::~GenericPanel
~GenericPanel() override
Definition: genericpanel.cpp:42
QET::ElementsContainer
@ ElementsContainer
Definition: qet.h:103
GenericPanel::updateDiagramItem
virtual QTreeWidgetItem * updateDiagramItem(QTreeWidgetItem *, Diagram *, PanelOptions=AddAllChild, bool=false)
GenericPanel::updateDiagramItem.
Definition: genericpanel.cpp:328
TitleBlockTemplatesCollection::changed
void changed(TitleBlockTemplatesCollection *, const QString &=QString())
QET::ItemType
ItemType
Definition: qet.h:99
QETProject::diagramRemoved
void diagramRemoved(QETProject *, Diagram *)
GenericPanel::getItemForProject
virtual QTreeWidgetItem * getItemForProject(QETProject *, bool *=nullptr)
Definition: genericpanel.cpp:156
GenericPanel::markItemAsUnused
virtual void markItemAsUnused(QTreeWidgetItem *)
GenericPanel::markItemAsUnused Mark the provided QTreeWidgetItem as unused in its parent project.
Definition: genericpanel.cpp:904
GenericPanel::diagramAdded
virtual void diagramAdded(QETProject *, Diagram *)
GenericPanel::diagramAdded.
Definition: genericpanel.cpp:724
GenericPanel::updateTemplatesCollectionItem
virtual QTreeWidgetItem * updateTemplatesCollectionItem(QTreeWidgetItem *, TitleBlockTemplatesCollection *, PanelOptions=AddAllChild, bool=false)
GenericPanel::updateTemplatesCollectionItem.
Definition: genericpanel.cpp:483
GenericPanel::firstActivated
bool firstActivated()
GenericPanel::emitFirstActivated
void emitFirstActivated()
GenericPanel::emitFirstActivated Emit the signal firstActivated().
Definition: genericpanel.cpp:1031
GenericPanel::diagramForItem
virtual Diagram * diagramForItem(QTreeWidgetItem *) const
GenericPanel::diagramForItem.
Definition: genericpanel.cpp:72
GenericPanel::diagrams_
QHash< Diagram *, QTreeWidgetItem * > diagrams_
diagrams_ Allow quick retrieval of the item representing a given diagram
Definition: genericpanel.h:218
GenericPanel::selectedProject
virtual QETProject * selectedProject() const
GenericPanel::selectedProject.
Definition: genericpanel.cpp:96
GenericPanel::projectForItem
virtual QETProject * projectForItem(QTreeWidgetItem *) const
GenericPanel::projectForItem.
Definition: genericpanel.cpp:59
QET::Diagram
@ Diagram
Definition: qet.h:108
QET::ElementsCollection
@ ElementsCollection
Definition: qet.h:102
GenericPanel::addTemplatesCollection
virtual QTreeWidgetItem * addTemplatesCollection(TitleBlockTemplatesCollection *, QTreeWidgetItem *=nullptr, PanelOptions=AddAllChild)
GenericPanel::addTemplatesCollection.
Definition: genericpanel.cpp:417
Diagram::border_and_titleblock
BorderTitleBlock border_and_titleblock
Diagram dimensions and title block.
Definition: diagram.h:83
qetapp.h
GenericPanel::diagramTitleChanged
virtual void diagramTitleChanged(Diagram *, const QString &)
GenericPanel::diagramTitleChanged Inform this panel the diagram diagram has changed its title to titl...
Definition: genericpanel.cpp:787
QET::TitleBlockTemplate
@ TitleBlockTemplate
Definition: qet.h:105
GenericPanel::itemForProject
virtual QTreeWidgetItem * itemForProject(QETProject *)
Definition: genericpanel.cpp:143
GenericPanel::updateProjectItem
virtual QTreeWidgetItem * updateProjectItem(QTreeWidgetItem *, QETProject *, PanelOptions=AddAllChild, bool=false)
GenericPanel::updateProjectItem.
Definition: genericpanel.cpp:179
Diagram
The Diagram class This class represents an electric diagram. It manages its various child elements,...
Definition: diagram.h:56
GenericPanel::fillItem
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:702
GenericPanel::MetaData
MetaData
Definition: genericpanel.h:50
GenericPanel::Item
@ Item
Definition: genericpanel.h:51
QETProject::diagramUsedTemplate
void diagramUsedTemplate(TitleBlockTemplatesCollection *, const QString &)
QETProject::diagramAdded
void diagramAdded(QETProject *, Diagram *)
qeticons.h
qet.h
TitleBlockTemplateLocation::parentProject
QETProject * parentProject() const
Definition: templatelocation.cpp:116
GenericPanel::All
@ All
Definition: genericpanel.h:46
GenericPanel::itemForTemplatesCollection
virtual QTreeWidgetItem * itemForTemplatesCollection(TitleBlockTemplatesCollection *)
GenericPanel::itemForTemplatesCollection.
Definition: genericpanel.cpp:446
GenericPanel::updateItem
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:683
GenericPanel::fillDiagramItem
virtual QTreeWidgetItem * fillDiagramItem(QTreeWidgetItem *, Diagram *, PanelOptions=AddAllChild, bool=false)
GenericPanel::fillDiagramItem.
Definition: genericpanel.cpp:402
GenericPanel::defaultIcon
virtual QIcon defaultIcon(QET::ItemType)
GenericPanel::defaultIcon.
Definition: genericpanel.cpp:848
TitleBlockTemplateLocation::isValid
bool isValid() const
Definition: templatelocation.cpp:87
TitleBlockTemplateLocation
Definition: templatelocation.h:29
GenericPanel::diagramUsedTemplate
virtual void diagramUsedTemplate(TitleBlockTemplatesCollection *, const QString &)
GenericPanel::diagramUsedTemplate.
Definition: genericpanel.cpp:812
TitleBlockTemplateLocation::toString
QString toString() const
Definition: templatelocation.cpp:108
templatescollection.h
QET::Icons::ProjectFileGP
QIcon ProjectFileGP
Definition: qeticons.cpp:148
QET::Icons::Folder
QIcon Folder
Definition: qeticons.cpp:94
GenericPanel::fillTemplateItem
virtual QTreeWidgetItem * fillTemplateItem(QTreeWidgetItem *, const TitleBlockTemplateLocation &, PanelOptions=AddAllChild, bool=false)
GenericPanel::fillTemplateItem.
Definition: genericpanel.cpp:664
GenericPanel::addDiagram
virtual QTreeWidgetItem * addDiagram(Diagram *, QTreeWidgetItem *=nullptr, PanelOptions=AddAllChild)
GenericPanel::addDiagram.
Definition: genericpanel.cpp:282
GenericPanel::AddChildTemplates
@ AddChildTemplates
Definition: genericpanel.h:43
QET::ElementsCategory
@ ElementsCategory
Definition: qet.h:101
GenericPanel::templatesCollectionChanged
virtual void templatesCollectionChanged(TitleBlockTemplatesCollection *, const QString &)
GenericPanel::templatesCollectionChanged.
Definition: genericpanel.cpp:799
GenericPanel::selectedTemplateLocation
virtual TitleBlockTemplateLocation selectedTemplateLocation() const
GenericPanel::selectedTemplateLocation.
Definition: genericpanel.cpp:112
GenericPanel::AddAllChild
@ AddAllChild
Definition: genericpanel.h:45
qetproject.h
GenericPanel::panelContentChanged
void panelContentChanged()
GenericPanel::AddChildDiagrams
@ AddChildDiagrams
Definition: genericpanel.h:41
ElementsLocation
The ElementsLocation class This class represents the location, the location of an element or of a cat...
Definition: elementslocation.h:46
GenericPanel::addProject
virtual QTreeWidgetItem * addProject(QETProject *, QTreeWidgetItem *=nullptr, PanelOptions=AddAllChild)
GenericPanel::addProject.
Definition: genericpanel.cpp:123
QETProject
Definition: qetproject.h:51
Diagram::diagramTitleChanged
void diagramTitleChanged(Diagram *, const QString &)
BorderTitleBlock::finalfolio
QString finalfolio() const
Definition: bordertitleblock.h:115
GenericPanel::AddAllChildTemplates
@ AddAllChildTemplates
Definition: genericpanel.h:44
GenericPanel::fillTemplatesCollectionItem
virtual QTreeWidgetItem * fillTemplatesCollectionItem(QTreeWidgetItem *, TitleBlockTemplatesCollection *, PanelOptions=AddAllChild, bool=false)
GenericPanel::fillTemplatesCollectionItem.
Definition: genericpanel.cpp:515
GenericPanel::selectedDiagram
virtual Diagram * selectedDiagram() const
GenericPanel::selectedDiagram.
Definition: genericpanel.cpp:104
GenericPanel::currentItemType
virtual int currentItemType()
Definition: genericpanel.cpp:48
GenericPanel::childItems
QList< QTreeWidgetItem * > childItems(QTreeWidgetItem *, QET::ItemType, bool=false) const
GenericPanel::childItems.
Definition: genericpanel.cpp:932
GenericPanel::unregisterItem
void unregisterItem(QTreeWidgetItem *)
GenericPanel::unregisterItem.
Definition: genericpanel.cpp:996
GenericPanel::diagramRemoved
virtual void diagramRemoved(QETProject *, Diagram *)
GenericPanel::diagramRemoved.
Definition: genericpanel.cpp:735
TitleBlockTemplatesCollection
Definition: templatescollection.h:34
QETProject::projectInformationsChanged
void projectInformationsChanged(QETProject *)
QET::TitleBlockTemplatesCollectionItem
@ TitleBlockTemplatesCollectionItem
Definition: qet.h:107
QET::ElementsCollectionItem
@ ElementsCollectionItem
Definition: qet.h:104
GenericPanel::makeItem
virtual QTreeWidgetItem * makeItem(QET::ItemType, QTreeWidgetItem *=nullptr, const QString &=QString(), const QIcon &=QIcon())
GenericPanel::makeItem Create a QTreeWidgetItem.
Definition: genericpanel.cpp:870
templatelocation.h
GenericPanel::GenericPanel
GenericPanel(QWidget *=nullptr)
Definition: genericpanel.cpp:31
GenericPanel::getItemForTemplatesCollection
virtual QTreeWidgetItem * getItemForTemplatesCollection(TitleBlockTemplatesCollection *, bool *=nullptr)
GenericPanel::getItemForTemplatesCollection.
Definition: genericpanel.cpp:458
GenericPanel::tb_templates_
QHash< TitleBlockTemplateLocation, QTreeWidgetItem * > tb_templates_
tb_templates_ Allow quick retrieval of the item representing a title block template
Definition: genericpanel.h:224
GenericPanel::first_activation_
bool first_activation_
first_activation_ boolean used to track the first time this widget is activated/shown
Definition: genericpanel.h:208
GenericPanel::projectDiagramsOrderChanged
virtual void projectDiagramsOrderChanged(QETProject *, int, int)
GenericPanel::projectDiagramsOrderChanged.
Definition: genericpanel.cpp:747
GenericPanel::defaultText
virtual QString defaultText(QET::ItemType)
GenericPanel::defaultText.
Definition: genericpanel.cpp:825
genericpanel.h
QET::Element
@ Element
Definition: qet.h:100
QET::Icons::tr
QIcon tr
Definition: qeticons.cpp:206
QET::Icons::TitleBlock
QIcon TitleBlock
Definition: qeticons.cpp:165
GenericPanel::addTemplate
virtual QTreeWidgetItem * addTemplate(const TitleBlockTemplateLocation &, QTreeWidgetItem *=nullptr, PanelOptions=AddAllChild)
GenericPanel::addTemplate.
Definition: genericpanel.cpp:568
GenericPanel::projects_
QHash< QETProject *, QTreeWidgetItem * > projects_
projects_ Allow quick retrieval of the item representing a given project
Definition: genericpanel.h:213
GenericPanel::deleteItem
virtual void deleteItem(QTreeWidgetItem *, bool=false)
GenericPanel::deleteItem Delete and item and its children.
Definition: genericpanel.cpp:887
QET::Icons::Diagram
QIcon Diagram
Definition: qeticons.cpp:43
GenericPanel::PanelOption
PanelOption
Definition: genericpanel.h:40
diagram.h
TitleBlockTemplateLocation::name
QString name() const
Definition: templatelocation.cpp:73
GenericPanel::AddChildTemplatesCollection
@ AddChildTemplatesCollection
Definition: genericpanel.h:42
TitleBlockTemplatesCollection::location
virtual TitleBlockTemplateLocation location(const QString &=QString())=0
GenericPanel::PanelFlags
@ PanelFlags
Definition: genericpanel.h:54