HAL
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 
43  {
44  public:
45  enum Type {None, Pin, Group};
46 
47  private:
48  Type mItemType;
49  u32 mId;
50  QString mPinName;
51  PinDirection mPinDirection;
52  PinType mPinType;
53  QString mNetName;
54  int mIndex;
55 
56  public:
57 
58  ModulePinsTreeItem(Type itype, u32 id_, QString pinName, PinDirection dir, PinType ptype, int inx, QString netName = QString());
59  ModulePinsTreeItem() : mItemType(None), mId(0) {;}
60  QVariant getData(int column) const override;
61  void setData(QList<QVariant> data) override;
62  void setDataAtColumn(int column, QVariant& data) override;
63  void appendData(QVariant data) override;
64  int getColumnCount() const override;
65  void setItemType(Type tp) { mItemType = tp; }
66  Type itemType() const { return mItemType; }
67  QString name() const { return mPinName; }
68  void setName(const QString& nam) { mPinName = nam; }
69  void setPinType(PinType ptype) { mPinType = ptype; }
70  void setPinDirection(PinDirection dir) { mPinDirection = dir; }
71  void setIndex(int inx) { mIndex = inx; }
72 
80  u32 id() const { return mId; }
81  };
82 
87  {
88  Q_OBJECT
89  public:
90 
97 
102 
103  //DRAG AND DROP THINGS!
104  Qt::ItemFlags flags(const QModelIndex& index) const override;
105  QStringList mimeTypes() const override;
106  QMimeData* mimeData(const QModelIndexList &indexes) const override;
107  bool dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent) override;
108  bool canDropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent) const override;
109 
110 
114  void clear() override;
115 
121  void setModule(Module* m);
122 
132 
140 
144  void handleModulePortsChanged(Module* m, PinEvent pev, u32 pgid);
146 
147  //column identifier
148  static const int sNameColumn = 0;
149  static const int sDirectionColumn = 1;
150  static const int sTypeColumn = 2;
151  static const int sNetColumn = 3;
152 
153  Q_SIGNALS:
160  void numberOfPortsChanged(const int newNumber);
161 
162  private:
163  Module* mModule;
164  //name is (hopefully) enough to identify
165  QMap<QString, BaseTreeItem*> mNameToTreeItem;
166  QMap<int, ModulePinsTreeItem*> mIdToPinItem;
167  QMap<int, ModulePinsTreeItem*> mIdToGroupItem;
168  QSet<ModulePinsTreeItem*> mOrphanedItem;
169 
170  void insertItem(ModulePinsTreeItem* item, BaseTreeItem* parent, int index);
171  void removeItem(ModulePinsTreeItem* item);
172  void updateGroupIndex(ModulePinsTreeItem* groupItem);
173  QModelIndex getIndexFromPinsItem(ModulePinsTreeItem *item) const;
174 
175 
176  // helper functions for dnd for more clarity
177  void dndGroupOnGroup(BaseTreeItem* droppedGroup, BaseTreeItem* onDroppedGroup, int row=-1);
178  void dndGroupBetweenGroup(ModulePinsTreeItem* droppedGroup, int row);
179  void dndPinOnGroup(ModulePinsTreeItem* droppedPin, BaseTreeItem* onDroppedGroup);
180  void dndPinBetweenPin(ModulePinsTreeItem* droppedPin, BaseTreeItem* onDroppedParent, int row);
181  void dndPinBetweenGroup(ModulePinsTreeItem* droppedPin, int row);
182  void dumpModel(const char* msg) const;
183  };
184 }
(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
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