VBWidgetPropertyModel.cpp 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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. return m_widget.m_properties.size();
  15. }
  16. String VBWidgetPropertyModel::column_name(int column) const
  17. {
  18. switch (column) {
  19. case Column::Name: return "Name";
  20. case Column::Value: return "Value";
  21. default: ASSERT_NOT_REACHED();
  22. }
  23. }
  24. GModel::ColumnMetadata VBWidgetPropertyModel::column_metadata(int column) const
  25. {
  26. UNUSED_PARAM(column);
  27. return { 80, TextAlignment::CenterLeft };
  28. }
  29. GVariant VBWidgetPropertyModel::data(const GModelIndex& index, Role role) const
  30. {
  31. if (role == Role::Display) {
  32. auto& property = *m_widget.m_properties[index.row()];
  33. switch (index.column()) {
  34. case Column::Name: return property.name();
  35. case Column::Value: return property.value();
  36. }
  37. ASSERT_NOT_REACHED();
  38. }
  39. if (role == Role::ForegroundColor) {
  40. auto& property = *m_widget.m_properties[index.row()];
  41. switch (index.column()) {
  42. case Column::Name: return Color::Black;
  43. case Column::Value: return property.is_readonly() ? Color(Color::MidGray) : Color(Color::Black);
  44. }
  45. ASSERT_NOT_REACHED();
  46. }
  47. return { };
  48. }