HAL  v4.5.0-83-g30c8f0afc
The Hardware Analyzer - a comprehensive reverse engineering and manipulation framework for gate-level netlists.
context_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 "hal_core/defines.h"
31 
32 #include <QMimeData>
33 
34 namespace hal
35 {
36 
41  {
42  private:
43  u32 mId;
44  QString mName;
45  u32 mParentId;
46 
47  public:
48  ContextDirectory(QString name, u32 parentId, u32 id):mName(name){
49  mId = id;
50  mParentId = parentId;
51  }
52 
58  void writeToFile(QJsonObject& json);
59 
60  QString name() const { return mName; }
61  u32 id() const { return mId; }
62  void setId(u32 id_) { mId = id_; }
63  void setName(QString name_) { mName = name_; }
64  };
65 
70  {
71  private:
72  GraphContext* mContext;
73  ContextDirectory* mDirectory;
74  public:
75 
78  QVariant getData(int column) const override;
79  void setData(QList<QVariant> data) override;
80  void setDataAtColumn(int column, QVariant& data) override;
81  void appendData(QVariant data) override;
82  int getColumnCount() const override;
83  int row() const;
84  bool isDirectory() const;
85  bool isContext() const;
86  u32 getId() const;
87  QString getName() const;
88  QDateTime getTimestamp() const;
89  GraphContext* context() const;
90  ContextDirectory* directory() const;
91  };
92 
103  {
104  Q_OBJECT
105 
106  public:
112  ContextTreeModel(QObject* parent = nullptr);
113 
117  //int rowCount(const QModelIndex& parent = QModelIndex()) const override;
118  QVariant data(const QModelIndex& inddex, int role = Qt::DisplayRole) const override;
120 
128  BaseTreeItem* getDirectory(u32 directoryId) const;
129 
137  BaseTreeItem* getContext(u32 contextId) const;
138 
147 
154  void addContext(GraphContext* context, BaseTreeItem* parent = nullptr);
155 
161  void removeContext(GraphContext* context);
162 
168  void removeDirectory(ContextDirectory* directory);
169 
176  GraphContext* getContext(const QModelIndex& index) const;
177 
185 
189  void clear() override;
190 
191  Qt::ItemFlags flags(const QModelIndex& index) const override;
192  QStringList mimeTypes() const override;
193 
199  const QVector<GraphContext*>& list();
200 
207 
213  void setCurrentDirectory(ContextTreeItem* currentItem);
214 
221 
231  bool moveItem(ContextTreeItem* itemToMove, BaseTreeItem* newParent, int row = -1);
232 
239  std::vector<u32> getChildDirectoriesOf(u32 directoryId);
240 
247  std::vector<u32> getChildContextsOf(u32 directoryId);
248 
249  Q_SIGNALS:
251 
252  private:
253  BaseTreeItem* getItemInternal(BaseTreeItem* parentItem, u32 id, bool isDirectory) const;
254  ContextTreeItem *mCurrentDirectory;
255  std::map<GraphContext *, ContextTreeItem *> mContextMap;
256  QVector<GraphContext*> mContextList;
257  QVector<ContextDirectory*> mDirectoryList;
258 
259  void dumpRecursion(ContextTreeItem* parent = nullptr, int level = 0) const;
260  };
261 } // namespace hal
(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
ContextDirectory(QString name, u32 parentId, u32 id)
void setName(QString name_)
void writeToFile(QJsonObject &json)
QVariant getData(int column) const override
QDateTime getTimestamp() const
ContextTreeItem(GraphContext *context)
int getColumnCount() const override
GraphContext * context() const
ContextDirectory * directory() const
void setData(QList< QVariant > data) override
void appendData(QVariant data) override
void setDataAtColumn(int column, QVariant &data) override
Base model for the ContextManagerWidget to manage GraphContexts.
bool moveItem(ContextTreeItem *itemToMove, BaseTreeItem *newParent, int row=-1)
std::vector< u32 > getChildDirectoriesOf(u32 directoryId)
void removeDirectory(ContextDirectory *directory)
QStringList mimeTypes() const override
void setCurrentDirectory(ContextTreeItem *currentItem)
Qt::ItemFlags flags(const QModelIndex &index) const override
void directoryCreatedSignal(ContextTreeItem *item)
const QVector< GraphContext * > & list()
QVariant data(const QModelIndex &inddex, int role=Qt::DisplayRole) const override
std::vector< u32 > getChildContextsOf(u32 directoryId)
QModelIndex getIndexFromContext(GraphContext *context) const
BaseTreeItem * getDirectory(u32 directoryId) const
ContextTreeItem * getCurrentDirectory()
void removeContext(GraphContext *context)
ContextDirectory * addDirectory(QString name, BaseTreeItem *parentItem, u32 id)
void addContext(GraphContext *context, BaseTreeItem *parent=nullptr)
ContextTreeModel(QObject *parent=nullptr)
const QVector< ContextDirectory * > & directoryList()
BaseTreeItem * getContext(u32 contextId) const
Logical container for modules, gates, and nets.
Definition: graph_context.h:55
uint32_t u32
Definition: defines.h:41
Definition: defines.h:45
std::string name
Q_OBJECTQ_OBJECT
Q_SIGNALSQ_SIGNALS
QObject * parent() const const
DisplayRole
typedef ItemFlags