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 
54  public:
55 
56  PortTreeItem(Type itype, u32 id_, QString pinName, PinDirection dir, PinType ptype, QString netName = QString());
57  PortTreeItem() : mItemType(None), mId(0) {;}
58  QVariant getData(int column) const override;
59  void setData(QList<QVariant> data) override;
60  void setDataAtIndex(int index, QVariant& data) override;
61  void appendData(QVariant data) override;
62  int getColumnCount() const override;
63  void setItemType(Type tp) { mItemType = tp; }
64  Type itemType() const { return mItemType; }
65  QString name() const { return mPinName; }
66  void setName(const QString& nam) { mPinName = nam; }
67  void setPinType(PinType ptype) { mPinType = ptype; }
68  void setPinDirection(PinDirection dir) { mPinDirection = dir; }
69 
77  u32 id() const { return mId; }
78  };
79 
84  {
85  Q_OBJECT
86  public:
87 
94 
99 
100  //DRAG AND DROP THINGS!
101  Qt::ItemFlags flags(const QModelIndex& index) const override;
102  QStringList mimeTypes() const override;
103  QMimeData* mimeData(const QModelIndexList &indexes) const override;
104  bool dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent) override;
105  bool canDropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent) const override;
106 
107 
111  void clear() override;
112 
118  void setModule(Module* m);
119 
129 
137 
141  void handleModulePortsChanged(Module* m, PinEvent pev, u32 pgid);
143 
144  //column identifier
145  static const int sNameColumn = 0;
146  static const int sDirectionColumn = 1;
147  static const int sTypeColumn = 2;
148  static const int sNetColumn = 3;
149 
150  Q_SIGNALS:
157  void numberOfPortsChanged(const int newNumber);
158 
159  private:
160  Module* mModule;
161  //name is (hopefully) enough to identify
162  QMap<QString, BaseTreeItem*> mNameToTreeItem;
163  QMap<int, PortTreeItem*> mIdToPinItem;
164  QMap<int, PortTreeItem*> mIdToGroupItem;
165 
166  void insertItem(PortTreeItem* item, BaseTreeItem* parent, int index);
167  void removeItem(PortTreeItem* item);
168 
169  // helper functions for dnd for more clarity
170  void dndGroupOnGroup(BaseTreeItem* droppedGroup, BaseTreeItem* onDroppedGroup);
171  void dndGroupBetweenGroup(PortTreeItem* droppedGroup, int row);
172  void dndPinOnGroup(PortTreeItem* droppedPin, BaseTreeItem* onDroppedGroup);
173  void dndPinBetweenPin(PortTreeItem* droppedPin, BaseTreeItem* onDroppedParent, int row);
174  void dndPinBetweenGroup(PortTreeItem* droppedPin, int row);
175  };
176 }
(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 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