QElectroTech  0.70
genericpanel.h
Go to the documentation of this file.
1 /*
2  Copyright 2006-2019 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 
35 class GenericPanel : public QTreeWidget {
36  Q_OBJECT
37 
38  public:
39  enum PanelOption {
45  All = 127
46  };
47  Q_DECLARE_FLAGS(PanelOptions, PanelOption)
48 
49  enum MetaData {
50  Item = Qt::UserRole + 1,
54  };
55 
56  // Constructors, destructor
57  public:
58  GenericPanel(QWidget * = nullptr);
59  ~GenericPanel() override;
60 
61  public:
62  // convenience methods to obtain what an item represents
63  virtual int currentItemType();
64  virtual QETProject *projectForItem(QTreeWidgetItem *) const;
65  virtual Diagram *diagramForItem(QTreeWidgetItem *) const;
66  virtual TitleBlockTemplateLocation templateLocationForItem(QTreeWidgetItem *) const;
67 
68  // convenience methods to obtain what the selected item represents
69  virtual QETProject *selectedProject() const;
70  virtual Diagram *selectedDiagram() const;
72 
73  // project-related methods
74  public:
75  virtual QTreeWidgetItem *addProject(QETProject *, QTreeWidgetItem * = nullptr, PanelOptions = AddAllChild);
76  virtual QTreeWidgetItem *itemForProject(QETProject *);
77  protected:
78  virtual QTreeWidgetItem *getItemForProject(QETProject *, bool * = nullptr);
79  virtual QTreeWidgetItem *updateProjectItem(QTreeWidgetItem *, QETProject *, PanelOptions = AddAllChild, bool = false);
80  virtual QTreeWidgetItem *fillProjectItem (QTreeWidgetItem *, QETProject *, PanelOptions = AddAllChild, bool = false);
81 
82  // diagram-related methods
83  public:
84  virtual QTreeWidgetItem *addDiagram(Diagram *, QTreeWidgetItem * = nullptr, PanelOptions = AddAllChild);
85  protected:
86  virtual QTreeWidgetItem *getItemForDiagram(Diagram *, bool * = nullptr);
87  virtual QTreeWidgetItem *updateDiagramItem(QTreeWidgetItem *, Diagram *, PanelOptions = AddAllChild, bool = false);
88  virtual QTreeWidgetItem *fillDiagramItem (QTreeWidgetItem *, Diagram *, PanelOptions = AddAllChild, bool = false);
89 
90  // title block templates collections methods
91  public:
92  virtual QTreeWidgetItem *addTemplatesCollection(TitleBlockTemplatesCollection *, QTreeWidgetItem * = nullptr, PanelOptions = AddAllChild);
94  protected:
95  virtual QTreeWidgetItem *getItemForTemplatesCollection(TitleBlockTemplatesCollection *, bool * = nullptr);
96  virtual QTreeWidgetItem *updateTemplatesCollectionItem(QTreeWidgetItem *, TitleBlockTemplatesCollection *, PanelOptions = AddAllChild, bool = false);
97  virtual QTreeWidgetItem *fillTemplatesCollectionItem (QTreeWidgetItem *, TitleBlockTemplatesCollection *, PanelOptions = AddAllChild, bool = false);
98 
99  // title block templates methods
100  public:
101  virtual QTreeWidgetItem *addTemplate(const TitleBlockTemplateLocation &, QTreeWidgetItem * = nullptr, PanelOptions = AddAllChild);
102  protected:
103  virtual QTreeWidgetItem *getItemForTemplate(const TitleBlockTemplateLocation &, bool * = nullptr);
104  virtual QTreeWidgetItem *updateTemplateItem(QTreeWidgetItem *, const TitleBlockTemplateLocation &, PanelOptions = AddAllChild, bool = false);
105  virtual QTreeWidgetItem *fillTemplateItem (QTreeWidgetItem *, const TitleBlockTemplateLocation &, PanelOptions = AddAllChild, bool = false);
106 
107  // generic methods
108  protected:
109  virtual QTreeWidgetItem *updateItem(QTreeWidgetItem *, PanelOptions = AddAllChild, bool = false);
110  virtual QTreeWidgetItem *fillItem (QTreeWidgetItem *, PanelOptions = AddAllChild, bool = false);
111 
112  // slots used to receive change notifications from added objects
113  protected slots:
114  virtual void projectInformationsChanged(QETProject *);
115  virtual void diagramAdded(QETProject *, Diagram *);
116  virtual void diagramRemoved(QETProject *, Diagram *);
117  virtual void projectDiagramsOrderChanged(QETProject *, int, int);
118  virtual void diagramTitleChanged(Diagram *, const QString &);
119  virtual void templatesCollectionChanged(TitleBlockTemplatesCollection*, const QString &);
120  virtual void diagramUsedTemplate(TitleBlockTemplatesCollection *, const QString &);
121 
122  // various other methods
123  protected:
124  virtual QString defaultText(QET::ItemType);
125  virtual QIcon defaultIcon(QET::ItemType);
126  virtual QTreeWidgetItem *makeItem(QET::ItemType, QTreeWidgetItem * = nullptr, const QString & = QString(), const QIcon & = QIcon());
127  virtual void deleteItem(QTreeWidgetItem *, bool = false);
128  virtual void markItemAsUnused(QTreeWidgetItem *);
129  virtual void reparent(QTreeWidgetItem *, QTreeWidgetItem *);
130  QList<QTreeWidgetItem *> childItems(QTreeWidgetItem *, QET::ItemType, bool = false) const;
131  template<typename T> void removeObsoleteItems(const QList<T> &, QTreeWidgetItem *, QET::ItemType, bool);
132  template<typename T> T valueForItem(QTreeWidgetItem *) const;
133  void unregisterItem(QTreeWidgetItem *);
134 
135  bool event(QEvent *) override;
136 
137  signals:
138  bool firstActivated();
139  void panelContentChanged();
140 
141  private slots:
142  void emitFirstActivated();
143 
144  private:
146  QHash<QETProject *, QTreeWidgetItem *> projects_;
147  QHash<Diagram *, QTreeWidgetItem *> diagrams_;
148  QHash<TitleBlockTemplateLocation, QTreeWidgetItem *> tb_templates_;
149 };
150 #endif
virtual QTreeWidgetItem * fillTemplateItem(QTreeWidgetItem *, const TitleBlockTemplateLocation &, PanelOptions=AddAllChild, bool=false)
virtual void templatesCollectionChanged(TitleBlockTemplatesCollection *, const QString &)
void panelContentChanged()
virtual QTreeWidgetItem * updateProjectItem(QTreeWidgetItem *, QETProject *, PanelOptions=AddAllChild, bool=false)
virtual QTreeWidgetItem * addProject(QETProject *, QTreeWidgetItem *=nullptr, PanelOptions=AddAllChild)
virtual QTreeWidgetItem * itemForProject(QETProject *)
virtual void diagramUsedTemplate(TitleBlockTemplatesCollection *, const QString &)
virtual void projectInformationsChanged(QETProject *)
GenericPanel(QWidget *=nullptr)
void emitFirstActivated()
virtual int currentItemType()
virtual TitleBlockTemplateLocation templateLocationForItem(QTreeWidgetItem *) const
virtual QTreeWidgetItem * fillProjectItem(QTreeWidgetItem *, QETProject *, PanelOptions=AddAllChild, bool=false)
virtual QTreeWidgetItem * updateTemplatesCollectionItem(QTreeWidgetItem *, TitleBlockTemplatesCollection *, PanelOptions=AddAllChild, bool=false)
virtual void deleteItem(QTreeWidgetItem *, bool=false)
virtual QTreeWidgetItem * addTemplate(const TitleBlockTemplateLocation &, QTreeWidgetItem *=nullptr, PanelOptions=AddAllChild)
virtual void diagramAdded(QETProject *, Diagram *)
virtual QTreeWidgetItem * fillDiagramItem(QTreeWidgetItem *, Diagram *, PanelOptions=AddAllChild, bool=false)
QHash< QETProject *, QTreeWidgetItem * > projects_
Allow quick retrieval of the item representing a given project.
Definition: genericpanel.h:146
~GenericPanel() override
virtual QTreeWidgetItem * getItemForTemplatesCollection(TitleBlockTemplatesCollection *, bool *=nullptr)
virtual QIcon defaultIcon(QET::ItemType)
virtual TitleBlockTemplateLocation selectedTemplateLocation() const
virtual QTreeWidgetItem * getItemForProject(QETProject *, bool *=nullptr)
virtual void diagramTitleChanged(Diagram *, const QString &)
bool first_activation_
boolean used to track the first time this widget is activated/shown
Definition: genericpanel.h:145
virtual QTreeWidgetItem * addTemplatesCollection(TitleBlockTemplatesCollection *, QTreeWidgetItem *=nullptr, PanelOptions=AddAllChild)
virtual QString defaultText(QET::ItemType)
bool event(QEvent *) override
virtual QTreeWidgetItem * makeItem(QET::ItemType, QTreeWidgetItem *=nullptr, const QString &=QString(), const QIcon &=QIcon())
virtual QETProject * projectForItem(QTreeWidgetItem *) const
QList< QTreeWidgetItem * > childItems(QTreeWidgetItem *, QET::ItemType, bool=false) const
virtual QTreeWidgetItem * getItemForDiagram(Diagram *, bool *=nullptr)
virtual Diagram * diagramForItem(QTreeWidgetItem *) const
virtual QTreeWidgetItem * updateTemplateItem(QTreeWidgetItem *, const TitleBlockTemplateLocation &, PanelOptions=AddAllChild, bool=false)
virtual void reparent(QTreeWidgetItem *, QTreeWidgetItem *)
virtual QTreeWidgetItem * updateDiagramItem(QTreeWidgetItem *, Diagram *, PanelOptions=AddAllChild, bool=false)
virtual QTreeWidgetItem * addDiagram(Diagram *, QTreeWidgetItem *=nullptr, PanelOptions=AddAllChild)
virtual void diagramRemoved(QETProject *, Diagram *)
QHash< TitleBlockTemplateLocation, QTreeWidgetItem * > tb_templates_
Allow quick retrieval of the item representing a title block template.
Definition: genericpanel.h:148
virtual QTreeWidgetItem * updateItem(QTreeWidgetItem *, PanelOptions=AddAllChild, bool=false)
virtual Diagram * selectedDiagram() const
bool firstActivated()
virtual void projectDiagramsOrderChanged(QETProject *, int, int)
GenericPanel::projectDiagramsOrderChanged.
QHash< Diagram *, QTreeWidgetItem * > diagrams_
Allow quick retrieval of the item representing a given diagram.
Definition: genericpanel.h:147
ItemType
Definition: qet.h:97
virtual QTreeWidgetItem * fillItem(QTreeWidgetItem *, PanelOptions=AddAllChild, bool=false)
virtual QTreeWidgetItem * getItemForTemplate(const TitleBlockTemplateLocation &, bool *=nullptr)
virtual QTreeWidgetItem * fillTemplatesCollectionItem(QTreeWidgetItem *, TitleBlockTemplatesCollection *, PanelOptions=AddAllChild, bool=false)
virtual void markItemAsUnused(QTreeWidgetItem *)
T valueForItem(QTreeWidgetItem *) const
void removeObsoleteItems(const QList< T > &, QTreeWidgetItem *, QET::ItemType, bool)
virtual QTreeWidgetItem * itemForTemplatesCollection(TitleBlockTemplatesCollection *)
void unregisterItem(QTreeWidgetItem *)
virtual QETProject * selectedProject() const