ctkCmdLineModuleExplorerTreeWidget.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. /*=============================================================================
  2. Library: CTK
  3. Copyright (c) German Cancer Research Center,
  4. Division of Medical and Biological Informatics
  5. Licensed under the Apache License, Version 2.0 (the "License");
  6. you may not use this file except in compliance with the License.
  7. You may obtain a copy of the License at
  8. http://www.apache.org/licenses/LICENSE-2.0
  9. Unless required by applicable law or agreed to in writing, software
  10. distributed under the License is distributed on an "AS IS" BASIS,
  11. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. See the License for the specific language governing permissions and
  13. limitations under the License.
  14. =============================================================================*/
  15. #ifndef CTKCMDLINEMODULEEXPLORERTREEWIDGET_H
  16. #define CTKCMDLINEMODULEEXPLORERTREEWIDGET_H
  17. #include <ctkCmdLineModuleReference.h>
  18. #include <QSortFilterProxyModel>
  19. #include <QTreeView>
  20. class ctkCmdLineModuleFrontend;
  21. struct ctkCmdLineModuleFrontendFactory;
  22. class ctkCmdLineModuleExplorerShowXmlAction;
  23. class QStandardItem;
  24. class QStandardItemModel;
  25. class ModuleSortFilterProxyModel : public QSortFilterProxyModel
  26. {
  27. Q_OBJECT
  28. public:
  29. ModuleSortFilterProxyModel(QObject *parent = 0);
  30. protected:
  31. bool filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const;
  32. bool lessThan(const QModelIndex &left, const QModelIndex &right) const;
  33. };
  34. /**
  35. * \class ctkCmdLineModuleExplorerTreeWidget
  36. * \brief Example application tree widget.
  37. */
  38. class ctkCmdLineModuleExplorerTreeWidget : public QTreeView
  39. {
  40. Q_OBJECT
  41. public:
  42. explicit ctkCmdLineModuleExplorerTreeWidget(QWidget* parent = 0);
  43. void setModuleFrontendFactories(const QList<ctkCmdLineModuleFrontendFactory*>& frontendFactories, ctkCmdLineModuleFrontendFactory *defaultFactory);
  44. Q_SLOT void addModuleItem(const ctkCmdLineModuleReference& moduleRef);
  45. Q_SLOT void removeModuleItem(const ctkCmdLineModuleReference& moduleRef);
  46. Q_SIGNAL void moduleFrontendCreated(ctkCmdLineModuleFrontend* moduleFrontend);
  47. Q_SLOT void setFilter(const QString& filter);
  48. protected:
  49. void contextMenuEvent(QContextMenuEvent* event);
  50. private:
  51. ctkCmdLineModuleFrontend* createFrontend(const ctkCmdLineModuleReference &moduleRef,
  52. ctkCmdLineModuleFrontendFactory* frontendFactory);
  53. Q_SLOT void moduleDoubleClicked(const QModelIndex& index);
  54. Q_SLOT void frontendFactoryActionTriggered();
  55. static QString CATEGORY_UNKNOWN;
  56. QMenu* ContextMenu;
  57. QMenu* ShowFrontendMenu;
  58. ctkCmdLineModuleExplorerShowXmlAction* ShowXmlAction;
  59. ctkCmdLineModuleReference ContextReference;
  60. QList<ctkCmdLineModuleFrontendFactory*> FrontendFactories;
  61. ctkCmdLineModuleFrontendFactory* DefaultFrontendFactory;
  62. QHash<QString, QStandardItem*> TreeWidgetCategories;
  63. QHash<ctkCmdLineModuleReference, QStandardItem*> TreeWidgetItems;
  64. QHash<QAction*, ctkCmdLineModuleFrontendFactory*> ActionsToFrontendFactoryMap;
  65. QStandardItemModel* TreeModel;
  66. QSortFilterProxyModel* FilterProxyModel;
  67. };
  68. #endif // CTKCMDLINEMODULEEXPLORERTREEWIDGET_H