ctkFlatProxyModel.h 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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 __ctkFlatProxyModel_h
  15. #define __ctkFlatProxyModel_h
  16. // QT includes
  17. #include <QAbstractProxyModel>
  18. // CTK includes
  19. #include "ctkWidgetsExport.h"
  20. class ctkFlatProxyModelPrivate;
  21. /// \ingroup Widgets
  22. ///
  23. /// ctkFlatProxyModel intends to flatten contiguous hierarchies within a model.
  24. /// For now, it only supports the toplevel hierarchy flatten with the 1 degree
  25. /// children.
  26. /// The items in the levels being flatten don't appear in the model anymore,
  27. /// however their children will be visible.
  28. class CTK_WIDGETS_EXPORT ctkFlatProxyModel : public QAbstractProxyModel
  29. {
  30. Q_OBJECT
  31. /// level for which to start flattening the rows. -1 by default
  32. /// Not supported yet.
  33. Q_PROPERTY(int startFlattenLevel READ startFlattenLevel WRITE setStartFlattenLevel)
  34. /// level for which to stop flattening the rows. -1 by default
  35. Q_PROPERTY(int endFlattenLevel READ endFlattenLevel WRITE setEndFlattenLevel)
  36. /// level for which to stop flattening the rows. -1 by default
  37. /// Not supported yet.
  38. Q_PROPERTY(int hideLevel READ hideLevel WRITE setHideLevel)
  39. public:
  40. typedef QAbstractProxyModel Superclass;
  41. ctkFlatProxyModel(QObject *parentObject = 0);
  42. virtual ~ctkFlatProxyModel();
  43. void setStartFlattenLevel(int level);
  44. int startFlattenLevel() const;
  45. void setEndFlattenLevel(int level);
  46. int endFlattenLevel() const;
  47. void setHideLevel(int level);
  48. int hideLevel() const;
  49. virtual QModelIndex mapFromSource( const QModelIndex& sourceIndex ) const;
  50. virtual QModelIndex mapToSource( const QModelIndex& sourceIndex ) const;
  51. virtual QModelIndex index(int row, int column, const QModelIndex &parent) const;
  52. virtual QModelIndex parent(const QModelIndex &child) const;
  53. virtual int rowCount(const QModelIndex &parent) const;
  54. virtual int columnCount(const QModelIndex &parent) const;
  55. protected:
  56. QScopedPointer<ctkFlatProxyModelPrivate> d_ptr;
  57. private:
  58. Q_DECLARE_PRIVATE(ctkFlatProxyModel);
  59. Q_DISABLE_COPY(ctkFlatProxyModel);
  60. };
  61. #endif