ColumnGroupTreeView.h 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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. #ifndef COLUMNGROUPTREEVIEW_H
  9. #define COLUMNGROUPTREEVIEW_H
  10. #if !defined(Q_MOC_RUN)
  11. #include <QTreeView>
  12. #include <QPainter>
  13. #endif
  14. class ColumnGroupProxyModel;
  15. class ColumnGroupHeaderView;
  16. class ColumnGroupTreeView
  17. : public QTreeView
  18. {
  19. Q_OBJECT
  20. public:
  21. ColumnGroupTreeView(QWidget* parent = 0);
  22. void setModel(QAbstractItemModel* model) override;
  23. bool IsGroupsShown() const;
  24. QModelIndex mapToSource(const QModelIndex& proxyIndex) const;
  25. QModelIndex mapFromSource(const QModelIndex& sourceModel) const;
  26. public slots:
  27. void ShowGroups(bool showGroups);
  28. void Sort(int column, Qt::SortOrder order = Qt::AscendingOrder);
  29. void ToggleSortOrder(int column);
  30. void AddGroup(int column);
  31. void RemoveGroup(int column);
  32. void SetGroups(const QVector<int>& columns);
  33. void ClearGroups();
  34. QVector<int> Groups() const;
  35. protected:
  36. void paintEvent(QPaintEvent* event) override
  37. {
  38. if (model() && model()->rowCount() > 0)
  39. {
  40. QTreeView::paintEvent(event);
  41. }
  42. else
  43. {
  44. const QMargins margins(2, 2, 2, 2);
  45. QPainter painter(viewport());
  46. QString text(tr("There are no items to show."));
  47. QRect textRect = painter.fontMetrics().boundingRect(text).marginsAdded(margins);
  48. textRect.moveCenter(viewport()->rect().center());
  49. textRect.moveTop(viewport()->rect().top());
  50. painter.drawText(textRect, Qt::AlignCenter, text);
  51. }
  52. }
  53. private slots:
  54. void SaveOpenState();
  55. void RestoreOpenState();
  56. void SpanGroups(const QModelIndex& index = QModelIndex());
  57. private:
  58. ColumnGroupHeaderView* m_header;
  59. ColumnGroupProxyModel* m_groupModel;
  60. QSet<QString> m_openNodes;
  61. };
  62. #endif // COLUMNGROUPTREEVIEW_H