ctkCheckableComboBox.h 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. /*=========================================================================
  2. Library: CTK
  3. Copyright (c) Kitware Inc.
  4. Licensed under the Apache License, Version 2.0 (the "License");
  5. you may not use this file except in compliance with the License.
  6. You may obtain a copy of the License at
  7. http://www.apache.org/licenses/LICENSE-2.0.txt
  8. Unless required by applicable law or agreed to in writing, software
  9. distributed under the License is distributed on an "AS IS" BASIS,
  10. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  11. See the License for the specific language governing permissions and
  12. limitations under the License.
  13. =========================================================================*/
  14. #ifndef __ctkCheckableComboBox_h
  15. #define __ctkCheckableComboBox_h
  16. // Qt includes
  17. #include <QComboBox>
  18. // CTK includes
  19. #include "ctkWidgetsExport.h"
  20. class ctkCheckableModelHelper;
  21. class ctkCheckableComboBoxPrivate;
  22. /// \ingroup Widgets
  23. /// Description
  24. /// ctkCheckableComboBox is a QComboBox that allow its items to be checkable
  25. class CTK_WIDGETS_EXPORT ctkCheckableComboBox : public QComboBox
  26. {
  27. Q_OBJECT
  28. public:
  29. ctkCheckableComboBox(QWidget *parent = 0);
  30. virtual ~ctkCheckableComboBox();
  31. /// Use setCheckableModel instead of setModel()
  32. QAbstractItemModel* checkableModel()const;
  33. void setCheckableModel(QAbstractItemModel *model);
  34. /// Returns an up-to-date list of all the checked indexes.
  35. QModelIndexList checkedIndexes()const;
  36. /// Returns true if all the indexes are checked, false otherwise
  37. bool allChecked()const;
  38. /// Returns true if none of the indexes is checked, false otherwise
  39. bool noneChecked()const;
  40. /// Utility function to conveniently check the state of an index
  41. void setCheckState(const QModelIndex& index, Qt::CheckState check);
  42. /// Utility function to return the check state of a model index
  43. Qt::CheckState checkState(const QModelIndex& index)const;
  44. /// Returns a pointer to the checkable model helper to give a direct access
  45. /// to the check manager.
  46. ctkCheckableModelHelper* checkableModelHelper()const;
  47. /// Reimplemented for internal reasons
  48. bool eventFilter(QObject *o, QEvent *e);
  49. Q_SIGNALS:
  50. void checkedIndexesChanged();
  51. protected Q_SLOTS:
  52. void onDataChanged(const QModelIndex& topLeft, const QModelIndex& bottomRight);
  53. protected:
  54. /// Reimplemented for internal reasons
  55. virtual void paintEvent(QPaintEvent*);
  56. protected:
  57. QScopedPointer<ctkCheckableComboBoxPrivate> d_ptr;
  58. private:
  59. Q_DECLARE_PRIVATE(ctkCheckableComboBox);
  60. Q_DISABLE_COPY(ctkCheckableComboBox);
  61. };
  62. #endif