LinkedModelGroupViews.h 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. /*
  2. * LinkedModelGroupViews.h - view for groups of linkable models
  3. *
  4. * Copyright (c) 2019-2019 Johannes Lorenz <j.git$$$lorenz-ho.me, $$$=@>
  5. *
  6. * This file is part of LMMS - https://lmms.io
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU General Public
  10. * License as published by the Free Software Foundation; either
  11. * version 2 of the License, or (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  16. * General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public
  19. * License along with this program (see COPYING); if not, write to the
  20. * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  21. * Boston, MA 02110-1301 USA.
  22. *
  23. */
  24. #ifndef LINKEDMODELGROUPVIEWS_H
  25. #define LINKEDMODELGROUPVIEWS_H
  26. #include <cstddef>
  27. #include <memory>
  28. #include <vector>
  29. #include <QWidget>
  30. /**
  31. @file LinkedModelGroupViews.h
  32. See Lv2ViewBase.h for example usage
  33. */
  34. /**
  35. View for a representative processor
  36. Features:
  37. * Remove button for removable models
  38. * Simple handling of adding, removing and model changing
  39. @note Neither this class, nor any inheriting classes, shall inherit
  40. ModelView. The "view" in the name is just for consistency
  41. with LinkedModelGroupsView.
  42. */
  43. class LinkedModelGroupView : public QWidget
  44. {
  45. public:
  46. /**
  47. @param colNum numbers of columns for the controls
  48. (link LEDs not counted)
  49. */
  50. LinkedModelGroupView(QWidget *parent, class LinkedModelGroup* model,
  51. std::size_t colNum);
  52. ~LinkedModelGroupView();
  53. //! Reconnect models if model changed
  54. void modelChanged(class LinkedModelGroup *linkedModelGroup);
  55. protected:
  56. //! Add a control to this widget
  57. //! @warning This widget will own this control, do not free it
  58. void addControl(class Control *ctrl, const std::string &id,
  59. const std::string& display, bool removable);
  60. void removeControl(const QString &key);
  61. private:
  62. class LinkedModelGroup* m_model;
  63. //! column number in surrounding grid in LinkedModelGroupsView
  64. std::size_t m_colNum;
  65. class ControlLayout* m_layout;
  66. std::map<std::string, std::unique_ptr<class Control>> m_widgets;
  67. };
  68. /**
  69. Container class for one LinkedModelGroupView
  70. @note It's intended this class does not inherit from ModelView.
  71. Inheriting classes need to do that, see e.g. Lv2Instrument.h
  72. */
  73. class LinkedModelGroupsView
  74. {
  75. protected:
  76. ~LinkedModelGroupsView() = default;
  77. //! Reconnect models if model changed; to be called by child virtuals
  78. void modelChanged(class LinkedModelGroups* ctrlBase);
  79. private:
  80. //! The base class must return the adressed group view,
  81. //! which has the same value as "this"
  82. virtual LinkedModelGroupView* getGroupView() = 0;
  83. };
  84. #endif // LINKEDMODELGROUPVIEWS_H