فهرست منبع

Inspector: Implement RemoteObjectGraphModel::parent_index()

This makes GTreeView paint the tree lines correctly. It's a bit weird
that this is needed, but straightforward to implement so meh.
Andreas Kling 6 سال پیش
والد
کامیت
68e94f0a2e
2فایلهای تغییر یافته به همراه17 افزوده شده و 0 حذف شده
  1. 16 0
      DevTools/Inspector/RemoteObjectGraphModel.cpp
  2. 1 0
      DevTools/Inspector/RemoteObjectGraphModel.h

+ 16 - 0
DevTools/Inspector/RemoteObjectGraphModel.cpp

@@ -26,6 +26,22 @@ GModelIndex RemoteObjectGraphModel::index(int row, int column, const GModelIndex
     return create_index(row, column, remote_parent.children.at(row));
 }
 
+GModelIndex RemoteObjectGraphModel::parent_index(const GModelIndex& index) const
+{
+    if (!index.is_valid())
+        return {};
+    auto& remote_object = *static_cast<RemoteObject*>(index.internal_data());
+    if (!remote_object.parent)
+        return {};
+    for (int row = 0; row < remote_object.parent->children.size(); ++row) {
+        if (remote_object.parent->children[row] == &remote_object)
+            return create_index(row, 0, remote_object.parent);
+    }
+
+    ASSERT_NOT_REACHED();
+    return {};
+}
+
 int RemoteObjectGraphModel::row_count(const GModelIndex& index) const
 {
     if (!index.is_valid())

+ 1 - 0
DevTools/Inspector/RemoteObjectGraphModel.h

@@ -18,6 +18,7 @@ public:
     virtual int column_count(const GModelIndex& = GModelIndex()) const override;
     virtual GVariant data(const GModelIndex&, Role = Role::Display) const override;
     virtual GModelIndex index(int row, int column, const GModelIndex& parent = GModelIndex()) const override;
+    virtual GModelIndex parent_index(const GModelIndex&) const;
     virtual void update() override;
 
 private: