ctkCheckableHeaderView.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. /*=========================================================================
  2. Library: CTK
  3. Copyright (c) Kitware Inc.
  4. All rights reserved.
  5. Distributed under a BSD License. See LICENSE.txt file.
  6. This software is distributed "AS IS" WITHOUT ANY WARRANTY; without even
  7. the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  8. See the above copyright notice for more information.
  9. =========================================================================*/
  10. /*=========================================================================
  11. Program: ParaView
  12. Module: $RCSfile: pqCheckableHeaderView.h,v $
  13. Copyright (c) 2005-2008 Sandia Corporation, Kitware Inc.
  14. All rights reserved.
  15. ParaView is a free software; you can redistribute it and/or modify it
  16. under the terms of the ParaView license version 1.2.
  17. See License_v1.2.txt for the full ParaView license.
  18. A copy of this license can be obtained by contacting
  19. Kitware Inc.
  20. 28 Corporate Drive
  21. Clifton Park, NY 12065
  22. USA
  23. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  24. ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  25. LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  26. A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR
  27. CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  28. EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  29. PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  30. PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  31. LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  32. NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  33. SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  34. =========================================================================*/
  35. #ifndef _ctkCheckableHeaderView_h
  36. #define _ctkCheckableHeaderView_h
  37. // Qt includes
  38. #include <QHeaderView>
  39. // CTK includes
  40. #include <ctkPimpl.h>
  41. #include "CTKWidgetsExport.h"
  42. class ctkCheckableHeaderViewPrivate;
  43. class CTK_WIDGETS_EXPORT ctkCheckableHeaderView : public QHeaderView
  44. {
  45. Q_OBJECT;
  46. Q_PROPERTY(bool propagateToItems READ propagateToItems WRITE setPropagateToItems);
  47. public:
  48. ctkCheckableHeaderView(Qt::Orientation orient, QWidget *parent=0);
  49. virtual ~ctkCheckableHeaderView();
  50. virtual void setModel(QAbstractItemModel *model);
  51. virtual void setRootIndex(const QModelIndex &index);
  52. ///
  53. /// A section is checkable if its CheckStateRole data is non null.
  54. /// One can access the same value through the model:
  55. /// model->headerData(orientation, section, Qt::CheckStateRole).isEmpty()
  56. bool isCheckable(int section)const;
  57. ///
  58. /// Utility function that returns the checkState of the section.
  59. /// One can access the same value through the model:
  60. /// model->headerData(orientation, section, Qt::CheckStateRole)
  61. Qt::CheckState checkState(int section)const;
  62. ///
  63. /// Utility function that returns the checkState of the section.
  64. /// One can access the same value through the model:
  65. /// model->headerData(orientation, section, Qt::CheckStateRole)
  66. bool checkState(int section,Qt::CheckState& checkState )const;
  67. ///
  68. /// Used to listen for focus in/out events.
  69. /// \param object The object receiving the event.
  70. /// \param e Event specific data.
  71. /// \return
  72. /// True if the event should be filtered out.
  73. virtual bool eventFilter(QObject *object, QEvent *e);
  74. void setPropagateToItems(bool propagate);
  75. bool propagateToItems()const;
  76. public slots:
  77. ///
  78. /// if the check state is PartiallyChecked, the section becomes Checked
  79. void toggleCheckState(int section);
  80. ///
  81. /// Warning, setting the check state automatically set the
  82. /// header section checkable
  83. void setCheckState(int section, Qt::CheckState checkState);
  84. private slots:
  85. void updateHeaderData(Qt::Orientation orient, int first, int last);
  86. void insertHeaderSection(const QModelIndex &parent, int first, int last);
  87. inline void updateHeaders();
  88. void updateHeadersFromItems(const QModelIndex& topLeft, const QModelIndex& bottomRight);
  89. protected:
  90. virtual void updateHeaders(int first, int last);
  91. virtual void initStyleSectionOption(QStyleOptionHeader *option, int section, QRect rect)const;
  92. virtual void mousePressEvent(QMouseEvent *e);
  93. virtual void mouseReleaseEvent(QMouseEvent *e);
  94. bool isPointInCheckBox(int section, QPoint pos)const;
  95. private:
  96. CTK_DECLARE_PRIVATE(ctkCheckableHeaderView);
  97. };
  98. //-----------------------------------------------------------------------------
  99. void ctkCheckableHeaderView::updateHeaders()
  100. {
  101. this->updateHeaders(0, this->count()-1);
  102. }
  103. #endif