HAL
port_tree_model.h
Go to the documentation of this file.
1 // MIT License
2 //
3 // Copyright (c) 2019 Ruhr University Bochum, Chair for Embedded Security. All Rights reserved.
4 // Copyright (c) 2019 Marc Fyrbiak, Sebastian Wallat, Max Hoffmann ("ORIGINAL AUTHORS"). All rights reserved.
5 // Copyright (c) 2021 Max Planck Institute for Security and Privacy. All Rights reserved.
6 // Copyright (c) 2021 Jörn Langheinrich, Julian Speith, Nils Albartus, René Walendy, Simon Klix ("ORIGINAL AUTHORS"). All Rights reserved.
7 //
8 // Permission is hereby granted, free of charge, to any person obtaining a copy
9 // of this software and associated documentation files (the "Software"), to deal
10 // in the Software without restriction, including without limitation the rights
11 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12 // copies of the Software, and to permit persons to whom the Software is
13 // furnished to do so, subject to the following conditions:
14 //
15 // The above copyright notice and this permission notice shall be included in all
16 // copies or substantial portions of the Software.
17 //
18 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
24 // SOFTWARE.
25 
26 #pragma once
27 
28 //#include "gui/new_selection_details_widget/models/base_tree_model.h"
33 #include <QMap>
34 
35 namespace hal
36 {
37  class Module;
38  class Net;
39 
40 
41  class PortTreeItem : public BaseTreeItem
42  {
43  public:
44  enum Type {None, Pin, Group};
45 
46  private:
47  Type mItemType;
48  u32 mId;
49  QString mPinName;
50  PinDirection mPinDirection;
51  PinType mPinType;
52  QString mNetName;
53  int mIndex;
54 
55  public:
56 
57  PortTreeItem(Type itype, u32 id_, QString pinName, PinDirection dir, PinType ptype, int inx, QString netName = QString());
58  PortTreeItem() : mItemType(None), mId(0) {;}
59  QVariant getData(int column) const override;
60  void setData(QList<QVariant> data) override;
61  void setDataAtIndex(int index, QVariant& data) override;
62  void appendData(QVariant data) override;
63  int getColumnCount() const override;
64  void setItemType(Type tp) { mItemType = tp; }
65  Type itemType() const { return mItemType; }
66  QString name() const { return mPinName; }
67  void setName(const QString& nam) { mPinName = nam; }
68  void setPinType(PinType ptype) { mPinType = ptype; }
69  void setPinDirection(PinDirection dir) { mPinDirection = dir; }
70  void setIndex(int inx) { mIndex = inx; }
71 
79  u32 id() const { return mId; }
80  };
81 
86  {
87  Q_OBJECT
88  public:
89 
96 
101 
102  //DRAG AND DROP THINGS!
103  Qt::ItemFlags flags(const QModelIndex& index) const override;
104  QStringList mimeTypes() const override;
105  QMimeData* mimeData(const QModelIndexList &indexes) const override;
106  bool dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent) override;
107  bool canDropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent) const override;
108 
109 
113  void clear() override;
114 
120  void setModule(Module* m);
121 
131 
139 
143  void handleModulePortsChanged(Module* m, PinEvent pev, u32 pgid);
145 
146  //column identifier
147  static const int sNameColumn = 0;
148  static const int sDirectionColumn = 1;
149  static const int sTypeColumn = 2;
150  static const int sNetColumn = 3;
151 
152  Q_SIGNALS:
159  void numberOfPortsChanged(const int newNumber);
160 
161  private:
162  Module* mModule;
163  //name is (hopefully) enough to identify
164  QMap<QString, BaseTreeItem*> mNameToTreeItem;
165  QMap<int, PortTreeItem*> mIdToPinItem;
166  QMap<int, PortTreeItem*> mIdToGroupItem;
167 
168  void insertItem(PortTreeItem* item, BaseTreeItem* parent, int index);
169  void removeItem(PortTreeItem* item);
170  void updateGroupIndex(PortTreeItem* groupItem);
171 
172  // helper functions for dnd for more clarity
173  void dndGroupOnGroup(BaseTreeItem* droppedGroup, BaseTreeItem* onDroppedGroup, int row=-1);
174  void dndGroupBetweenGroup(PortTreeItem* droppedGroup, int row);
175  void dndPinOnGroup(PortTreeItem* droppedPin, BaseTreeItem* onDroppedGroup);
176  void dndPinBetweenPin(PortTreeItem* droppedPin, BaseTreeItem* onDroppedParent, int row);
177  void dndPinBetweenGroup(PortTreeItem* droppedPin, int row);
178  };
179 }
(Future) Base class for all tree models related to the details widget.
The BaseTreeModel implements generic standard functions of a tree model.
virtual QModelIndex index(int row, int column, const QModelIndex &parent=QModelIndex()) const override
virtual QVariant data(const QModelIndex &index, int role=Qt::DisplayRole) const override
A model to represent the ports of a module.
bool canDropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent) const override
ModulePinsTreeModel(QObject *parent=nullptr)
QStringList mimeTypes() const override
Net * getNetFromItem(PortTreeItem *item)
static const int sNetColumn
QMimeData * mimeData(const QModelIndexList &indexes) const override
void handleModulePortsChanged(Module *m, PinEvent pev, u32 pgid)
static const int sDirectionColumn
static const int sNameColumn
Qt::ItemFlags flags(const QModelIndex &index) const override
static const int sTypeColumn
void numberOfPortsChanged(const int newNumber)
bool dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent) override
Definition: net.h:58
void setPinDirection(PinDirection dir)
void setIndex(int inx)
void setPinType(PinType ptype)
void appendData(QVariant data) override
QString name() const
void setDataAtIndex(int index, QVariant &data) override
void setData(QList< QVariant > data) override
int getColumnCount() const override
void setName(const QString &nam)
Type itemType() const
void setItemType(Type tp)
QVariant getData(int column) const override
action
Definition: control.py:16
PinDirection
Definition: pin_direction.h:36
PinEvent
Definition: pin_event.h:42
PinType
Definition: pin_type.h:36
quint32 u32
Q_OBJECTQ_OBJECT
Q_SIGNALSQ_SIGNALS
QObject * parent() const const
DropAction
typedef ItemFlags