GemRepoProxyModel.cpp 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. /*
  2. * Copyright (c) Contributors to the Open 3D Engine Project.
  3. * For complete copyright and license terms please see the LICENSE at the root of this distribution.
  4. *
  5. * SPDX-License-Identifier: Apache-2.0 OR MIT
  6. *
  7. */
  8. #include <GemRepo/GemRepoProxyModel.h>
  9. #include <GemRepo/GemRepoModel.h>
  10. #include <ProjectManagerDefs.h>
  11. namespace O3DE::ProjectManager
  12. {
  13. GemRepoProxyModel::GemRepoProxyModel(QObject* parent)
  14. : QSortFilterProxyModel(parent)
  15. {
  16. }
  17. bool GemRepoProxyModel::lessThan(const QModelIndex& left, const QModelIndex& right) const
  18. {
  19. GemRepoModel* model = qobject_cast<GemRepoModel*>(sourceModel());
  20. if (model)
  21. {
  22. const QString leftUri = model->GetRepoUri(left);
  23. if (leftUri.compare(CanonicalRepoUri, Qt::CaseInsensitive) == 0)
  24. {
  25. // make sure canonical is at top
  26. return true;
  27. }
  28. const QString rightUri = model->GetRepoUri(right);
  29. if (rightUri.compare(CanonicalRepoUri, Qt::CaseInsensitive) == 0)
  30. {
  31. // make sure canonical is at top
  32. return false;
  33. }
  34. return model->GetName(left).compare(model->GetName(right), Qt::CaseInsensitive) < 0;
  35. }
  36. return true;
  37. }
  38. } // namespace O3DE::ProjectManager