GitFilesModel.cpp 810 B

123456789101112131415161718192021222324252627282930313233343536
  1. /*
  2. * Copyright (c) 2020, Itamar S. <itamar8910@gmail.com>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #include "GitFilesModel.h"
  7. namespace HackStudio {
  8. NonnullRefPtr<GitFilesModel> GitFilesModel::create(Vector<String>&& files)
  9. {
  10. return adopt_ref(*new GitFilesModel(move(files)));
  11. }
  12. GitFilesModel::GitFilesModel(Vector<String>&& files)
  13. : m_files(move(files))
  14. {
  15. }
  16. GUI::Variant GitFilesModel::data(const GUI::ModelIndex& index, GUI::ModelRole role) const
  17. {
  18. if (role == GUI::ModelRole::Display) {
  19. return m_files.at(index.row());
  20. }
  21. return {};
  22. }
  23. GUI::ModelIndex GitFilesModel::index(int row, int column, const GUI::ModelIndex&) const
  24. {
  25. if (row < 0 || row >= static_cast<int>(m_files.size()))
  26. return {};
  27. return create_index(row, column, &m_files.at(row));
  28. }
  29. };