ModelIndex.cpp 680 B

12345678910111213141516171819202122232425262728293031323334353637
  1. /*
  2. * Copyright (c) 2018-2021, Andreas Kling <kling@serenityos.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #include <AK/String.h>
  7. #include <LibGUI/Model.h>
  8. #include <LibGUI/Variant.h>
  9. namespace GUI {
  10. Variant ModelIndex::data(ModelRole role) const
  11. {
  12. if (!is_valid())
  13. return {};
  14. VERIFY(model());
  15. return model()->data(*this, role);
  16. }
  17. ModelIndex ModelIndex::sibling(int row, int column) const
  18. {
  19. if (!is_valid())
  20. return {};
  21. VERIFY(model());
  22. return model()->index(row, column, parent());
  23. }
  24. ModelIndex ModelIndex::sibling_at_column(int column) const
  25. {
  26. if (!is_valid())
  27. return {};
  28. return sibling(row(), column);
  29. }
  30. }