VBWidgetPropertyModel.cpp 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. #include "VBWidgetPropertyModel.h"
  2. #include "VBWidget.h"
  3. #include "VBProperty.h"
  4. VBWidgetPropertyModel::VBWidgetPropertyModel(VBWidget& widget)
  5. : m_widget(widget)
  6. {
  7. }
  8. VBWidgetPropertyModel::~VBWidgetPropertyModel()
  9. {
  10. ASSERT_NOT_REACHED();
  11. }
  12. int VBWidgetPropertyModel::row_count(const GModelIndex&) const
  13. {
  14. dbgprintf("row count: %d\n", m_widget.m_properties.size());
  15. return m_widget.m_properties.size();
  16. }
  17. String VBWidgetPropertyModel::column_name(int column) const
  18. {
  19. switch (column) {
  20. case Column::Name: return "Name";
  21. case Column::Value: return "Value";
  22. default: ASSERT_NOT_REACHED();
  23. }
  24. }
  25. GModel::ColumnMetadata VBWidgetPropertyModel::column_metadata(int column) const
  26. {
  27. UNUSED_PARAM(column);
  28. return { 100, TextAlignment::CenterLeft };
  29. }
  30. GVariant VBWidgetPropertyModel::data(const GModelIndex& index, Role role) const
  31. {
  32. if (role == Role::Display) {
  33. dbgprintf("Accessing prop #%d (size=%d) column %d\n", index.row(), m_widget.m_properties.size(), index.column());
  34. auto& property = *m_widget.m_properties[index.row()];
  35. auto value = property.value();
  36. dbgprintf("value type=%u\n", (unsigned)value.type());
  37. dbgprintf("value impl=%x\n", (unsigned)value.to_string().impl());
  38. dbgprintf("value len=%x\n", (unsigned)value.to_string().impl()->length());
  39. dbgprintf("for value='%s'\n", value.to_string().characters());
  40. switch (index.column()) {
  41. case Column::Name: return property.name();
  42. case Column::Value: return property.value();
  43. }
  44. }
  45. return { };
  46. }