itemviews.cpp 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. // Copyright (C) 2016 The Qt Company Ltd.
  2. // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
  3. #include "itemviews.h"
  4. namespace Utils {
  5. /*!
  6. \class Utils::TreeView
  7. \inmodule QtCreator
  8. \brief The TreeView adds setActivationMode to QTreeView
  9. to allow for single click/double click behavior on
  10. platforms where the default is different. Use with care.
  11. Also adds sane keyboard navigation for mac.
  12. Note: This uses setUniformRowHeights(true) by default.
  13. */
  14. /*!
  15. \class Utils::TreeWidget
  16. \inmodule QtCreator
  17. \brief The TreeWidget adds setActivationMode to QTreeWidget
  18. to allow for single click/double click behavior on
  19. platforms where the default is different. Use with care.
  20. Also adds sane keyboard navigation for mac.
  21. Note: This uses setUniformRowHeights(true) by default.
  22. */
  23. /*!
  24. \class Utils::ListView
  25. \inmodule QtCreator
  26. \brief The ListView adds setActivationMode to QListView
  27. to allow for single click/double click behavior on
  28. platforms where the default is different. Use with care.
  29. Also adds sane keyboard navigation for mac.
  30. */
  31. /*!
  32. \class Utils::ListWidget
  33. \inmodule QtCreator
  34. \brief The ListWidget adds setActivationMode to QListWidget
  35. to allow for single click/double click behavior on
  36. platforms where the default is different. Use with care.
  37. Also adds sane keyboard navigation for mac.
  38. */
  39. static Internal::ViewSearchCallback &viewSearchCallback()
  40. {
  41. static Internal::ViewSearchCallback theViewSearchCallback;
  42. return theViewSearchCallback;
  43. }
  44. static void makeViewSearchable(QAbstractItemView *view, int role)
  45. {
  46. if (viewSearchCallback())
  47. viewSearchCallback()(view, role);
  48. }
  49. /*!
  50. \internal
  51. \note Only use once from Core initialization.
  52. */
  53. void Internal::setViewSearchCallback(const ViewSearchCallback &cb)
  54. {
  55. viewSearchCallback() = cb;
  56. }
  57. TreeView::TreeView(QWidget *parent)
  58. : View<QTreeView>(parent)
  59. {
  60. setUniformRowHeights(true);
  61. }
  62. void TreeView::setSearchRole(int role)
  63. {
  64. makeViewSearchable(this, role);
  65. }
  66. ListView::ListView(QWidget *parent)
  67. : View<QListView>(parent)
  68. {}
  69. ListWidget::ListWidget(QWidget *parent)
  70. : View<QListWidget>(parent)
  71. {}
  72. } // Utils