HAL
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 
38  {
39  private:
40  u32 mId;
41  QString mName;
42  u32 mParentId;
43 
44  public:
45  ContextDirectory(QString name, u32 parentId, u32 id):mName(name){
46  mId = id;
47  mParentId = parentId;
48  }
49 
55  void writeToFile(QJsonObject& json);
56 
57  QString name() const { return mName; }
58  u32 id() const { return mId; }
59  void setId(u32 id_) { mId = id_; }
60  void setName(QString name_) { mName = name_; }
61  };
62 
64  {
65  private:
66  GraphContext* mContext;
67  ContextDirectory* mDirectory;
68  public:
69 
72  QVariant getData(int column) const override;
73  void setData(QList<QVariant> data) override;
74  void setDataAtIndex(int index, QVariant& data) override;
75  void appendData(QVariant data) override;
76  int getColumnCount() const override;
77  int row() const;
78  bool isDirectory() const;
79  bool isContext() const;
80  u32 getId() const;
81  QString getName() const;
82  QDateTime getTimestamp() const;
83  GraphContext* context() const;
84  ContextDirectory* directory() const;
85  };
86 
97  {
98  Q_OBJECT
99 
100  public:
106  ContextTreeModel(QObject* parent = nullptr);
107 
111  //int rowCount(const QModelIndex& parent = QModelIndex()) const override;
112  QVariant data(const QModelIndex& inddex, int role = Qt::DisplayRole) const override;
114 
122  BaseTreeItem* getDirectory(u32 directoryId) const;
123 
131  BaseTreeItem* getContext(u32 contextId) const;
132 
141 
148  void addContext(GraphContext* context, BaseTreeItem* parent = nullptr);
149 
155  void removeContext(GraphContext* context);
156 
162  void removeDirectory(ContextDirectory* directory);
163 
170  GraphContext* getContext(const QModelIndex& index) const;
171 
179 
183  void clear() override;
184 
185  Qt::ItemFlags flags(const QModelIndex& index) const override;
186  QStringList mimeTypes() const override;
187 
193  const QVector<GraphContext*>& list();
194 
201 
207  void setCurrentDirectory(ContextTreeItem* currentItem);
208 
215 
225  bool moveItem(ContextTreeItem* itemToMove, BaseTreeItem* newParent, int row = -1);
226 
233  std::vector<u32> getChildDirectoriesOf(u32 directoryId);
234 
241  std::vector<u32> getChildContextsOf(u32 directoryId);
242 
243  Q_SIGNALS:
245 
246  private:
247  BaseTreeItem* getItemInternal(BaseTreeItem* parentItem, u32 id, bool isDirectory) const;
248  ContextTreeItem *mCurrentDirectory;
249  std::map<GraphContext *, ContextTreeItem *> mContextMap;
250  QVector<GraphContext*> mContextList;
251  QVector<ContextDirectory*> mDirectoryList;
252 
253  void dumpRecursion(ContextTreeItem* parent = nullptr, int level = 0) const;
254  };
255 } // 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 setDataAtIndex(int index, 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
quint32 u32
std::string name
Q_OBJECTQ_OBJECT
Q_SIGNALSQ_SIGNALS
QObject * parent() const const
DisplayRole
typedef ItemFlags