ctkTreeComboBox.h 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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 __ctkTreeComboBox_h
  15. #define __ctkTreeComboBox_h
  16. // Qt includes
  17. #include <QComboBox>
  18. // CTK includes
  19. #include <ctkPimpl.h>
  20. #include "ctkWidgetsExport.h"
  21. class ctkTreeComboBoxPrivate;
  22. class QTreeView;
  23. /// \ingroup Widgets
  24. /// Description:
  25. /// ComboBox that displays the items as a tree view.
  26. /// See below for a use case:
  27. /// ctkTreeComboBox combo;
  28. /// QStandardItemModel model;
  29. /// model.appendRow(new QStandardItem("Test1"));
  30. /// model.item(0)->appendRow(new QStandardItem("Test1.1"));
  31. /// model.item(0)->appendRow(new QStandardItem("Test1.2"));
  32. /// model.item(0)->appendRow(new QStandardItem("Test1.3"));
  33. /// model.appendRow(new QStandardItem("Test2"));
  34. /// model.appendRow(new QStandardItem("Test3"));
  35. /// combo.setModel(&model);
  36. /// combo.show();
  37. /// TODO fix size of the view
  38. class CTK_WIDGETS_EXPORT ctkTreeComboBox : public QComboBox
  39. {
  40. Q_OBJECT
  41. /// Column index visible in the view. If \sa visibleModelColumn is -1
  42. /// (default) then all columns are visible.
  43. Q_PROPERTY(int visibleModelColumn READ visibleModelColumn WRITE setVisibleModelColumn)
  44. public:
  45. typedef QComboBox Superclass;
  46. explicit ctkTreeComboBox(QWidget* parent = 0);
  47. virtual ~ctkTreeComboBox();
  48. int visibleModelColumn()const;
  49. void setVisibleModelColumn(int index);
  50. virtual bool eventFilter(QObject* object, QEvent* event);
  51. virtual void showPopup();
  52. virtual void hidePopup();
  53. /// ctkTreeComboBox uses a QTreeView for its model view. treeView() is a
  54. /// utility function that cast QComboBox::view() into a QTreeView.
  55. /// \sa view()
  56. QTreeView* treeView()const;
  57. protected:
  58. virtual void paintEvent(QPaintEvent*);
  59. protected Q_SLOTS:
  60. void resizePopup();
  61. signals:
  62. void popupShow();
  63. void popupHide();
  64. protected:
  65. QScopedPointer<ctkTreeComboBoxPrivate> d_ptr;
  66. private:
  67. Q_DECLARE_PRIVATE(ctkTreeComboBox);
  68. Q_DISABLE_COPY(ctkTreeComboBox);
  69. };
  70. #endif