HAL  v4.5.0-83-g30c8f0afc
The Hardware Analyzer - a comprehensive reverse engineering and manipulation framework for gate-level netlists.
module_pins_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 #include <QSet>
35 
36 namespace hal
37 {
38  class Module;
39  class Net;
40 
41 
46  {
47  public:
48  enum Type {None, Pin, Group};
49 
50  private:
51  Type mItemType;
52  u32 mId;
53  QString mPinName;
54  PinDirection mPinDirection;
55  PinType mPinType;
56  QString mNetName;
57  int mIndex;
58 
59  public:
60 
61  ModulePinsTreeItem(Type itype, u32 id_, QString pinName, PinDirection dir, PinType ptype, int inx, QString netName = QString());
62  ModulePinsTreeItem() : mItemType(None), mId(0) {;}
63  QVariant getData(int column) const override;
64  void setData(QList<QVariant> data) override;
65  void setDataAtColumn(int column, QVariant& data) override;
66  void appendData(QVariant data) override;
67  int getColumnCount() const override;
68  void setItemType(Type tp) { mItemType = tp; }
69  Type itemType() const { return mItemType; }
70  QString name() const { return mPinName; }
71  void setName(const QString& nam) { mPinName = nam; }
72  void setPinType(PinType ptype) { mPinType = ptype; }
73  void setPinDirection(PinDirection dir) { mPinDirection = dir; }
74  void setIndex(int inx) { mIndex = inx; }
75 
82  u32 id() const { return mId; }
83  };
84 
89  {
90  Q_OBJECT
91  public:
92 
99 
104 
105  //DRAG AND DROP THINGS!
106  Qt::ItemFlags flags(const QModelIndex& index) const override;
107  QStringList mimeTypes() const override;
108  QMimeData* mimeData(const QModelIndexList &indexes) const override;
109  bool dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent) override;
110  bool canDropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent) const override;
111 
112 
116  void clear() override;
117 
123  void setModule(Module* m);
124 
131  void reload();
132 
142 
150 
154  void handleModulePortsChanged(Module* m, PinEvent pev, u32 pgid);
156 
157  //column identifier
158  static const int sNameColumn = 0;
159  static const int sDirectionColumn = 1;
160  static const int sTypeColumn = 2;
161  static const int sNetColumn = 3;
162 
163  Q_SIGNALS:
170  void numberOfPortsChanged(const int newNumber);
171 
176 
180  void pinsReloaded();
181 
182  private:
183  Module* mModule;
184  //name is (hopefully) enough to identify
185  QMap<QString, BaseTreeItem*> mNameToTreeItem;
186  QMap<int, ModulePinsTreeItem*> mIdToPinItem;
187  QMap<int, ModulePinsTreeItem*> mIdToGroupItem;
188  QSet<ModulePinsTreeItem*> mOrphanedItem;
189 
190  void insertItem(ModulePinsTreeItem* item, BaseTreeItem* parent, int index);
191  void removeItem(ModulePinsTreeItem* item);
192  void updateGroupIndex(ModulePinsTreeItem* groupItem);
193  QModelIndex getIndexFromPinsItem(ModulePinsTreeItem *item) const;
194 
195 
196  // helper functions for dnd for more clarity
197  void dndGroupOnGroup(BaseTreeItem* droppedGroup, BaseTreeItem* onDroppedGroup, int row=-1);
198  void dndGroupBetweenGroup(ModulePinsTreeItem* droppedGroup, int row);
199  void dndPinOnGroup(ModulePinsTreeItem* droppedPin, BaseTreeItem* onDroppedGroup);
200  void dndPinBetweenPin(ModulePinsTreeItem* droppedPin, BaseTreeItem* onDroppedParent, int row);
201  void dndPinBetweenGroup(ModulePinsTreeItem* droppedPin, int row);
202  void dumpModel(const char* msg) const;
203  };
204 }
(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
void setPinType(PinType ptype)
void setName(const QString &nam)
QVariant getData(int column) const override
void setPinDirection(PinDirection dir)
int getColumnCount() const override
void setData(QList< QVariant > data) override
void setDataAtColumn(int column, QVariant &data) override
void appendData(QVariant data) 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
QMimeData * mimeData(const QModelIndexList &indexes) const override
void handleModulePortsChanged(Module *m, PinEvent pev, u32 pgid)
Qt::ItemFlags flags(const QModelIndex &index) const override
Net * getNetFromItem(ModulePinsTreeItem *item)
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
uint32_t u32
Definition: defines.h:41
Definition: defines.h:45
PinDirection
Definition: pin_direction.h:36
PinEvent
Definition: pin_event.h:42
PinType
Definition: pin_type.h:36
Q_OBJECTQ_OBJECT
Q_SIGNALSQ_SIGNALS
QObject * parent() const const
DropAction
typedef ItemFlags