Galaxis Codebase  1.0.0
Team Galaxis software stack for the Carolo Cup 2023 - ROS2 based software
jsontreemodel.h
Go to the documentation of this file.
1 #ifndef JSONTREEMODEL_H
2 #define JSONTREEMODEL_H
3 
4 #include <QAbstractItemModel>
5 #include <QModelIndex>
6 #include <QVariant>
7 #include "jsontreeitem.h"
8 #include <nlohmann/json.hpp>
9 
10 using namespace nlohmann::detail;
11 
12 
13 class JsonTreeModel : public QAbstractItemModel
14 {
15  Q_OBJECT
16 
17 public:
18  JsonTreeModel(const QStringList &headers, const nlohmann::json &data,
19  QObject *parent = 0);
20  ~JsonTreeModel();
21 
22  QVariant data(const QModelIndex &index, int role) const;
23  QVariant headerData(int section, Qt::Orientation orientation,
24  int role = Qt::DisplayRole) const;
25 
26  QModelIndex index(int row, int column,
27  const QModelIndex &parent = QModelIndex()) const;
28  QModelIndex parent(const QModelIndex &index) const;
29 
30  int rowCount(const QModelIndex &parent = QModelIndex()) const;
31  int columnCount(const QModelIndex &parent = QModelIndex()) const;
32 
33  Qt::ItemFlags flags(const QModelIndex &index) const;
34  bool setData(const QModelIndex &index, const QVariant &value,
35  int role = Qt::EditRole);
36  bool setHeaderData(int section, Qt::Orientation orientation,
37  const QVariant &value, int role = Qt::EditRole);
38 
39  bool insertColumns(int position, int columns,
40  const QModelIndex &parent = QModelIndex());
41  bool removeColumns(int position, int columns,
42  const QModelIndex &parent = QModelIndex());
43  bool insertRows(int position, int rows,
44  const QModelIndex &parent = QModelIndex());
45  bool removeRows(int position, int rows,
46  const QModelIndex &parent = QModelIndex());
47 
48  JsonTreeItem *getRootItem();
49 
50 private:
51  void setupModelData(const nlohmann::json &lines, JsonTreeItem *parent);
52  QString getTypeString(value_t vType);
53 
54  JsonTreeItem *getItem(const QModelIndex &index) const;
56 };
57 
58 #endif
jsontreeitem.h
json
nlohmann::json json
Definition: AutoPilotNode.hpp:21
JsonTreeModel
Definition: jsontreemodel.h:13
JsonTreeModel::rootItem
JsonTreeItem * rootItem
Definition: jsontreemodel.h:55
JsonTreeItem
Definition: jsontreeitem.h:8