abstract_widget_list.hpp 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. /**
  2. * \file
  3. *
  4. * \author Mattia Basaglia
  5. *
  6. * \copyright Copyright (C) 2013-2020 Mattia Basaglia
  7. *
  8. * This program is free software: you can redistribute it and/or modify
  9. * it under the terms of the GNU Lesser General Public License as published by
  10. * the Free Software Foundation, either version 3 of the License, or
  11. * (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
  16. * GNU Lesser General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU Lesser General Public License
  19. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  20. *
  21. */
  22. #ifndef ABSTRACT_WIDGET_LIST_HPP
  23. #define ABSTRACT_WIDGET_LIST_HPP
  24. #include "colorwidgets_global.hpp"
  25. #include <QSignalMapper>
  26. #include <QTableWidget>
  27. class QCP_EXPORT AbstractWidgetList : public QWidget
  28. {
  29. Q_OBJECT
  30. public:
  31. explicit AbstractWidgetList(QWidget *parent = 0);
  32. ~AbstractWidgetList();
  33. /**
  34. * \brief Get the number of items
  35. */
  36. int count() const;
  37. /**
  38. * \brief Swap row a and row b
  39. */
  40. virtual void swap(int a, int b) = 0;
  41. /// Whether the given row index is valid
  42. bool isValidRow(int i) const { return i >= 0 && i < count(); }
  43. void setRowHeight(int row, int height);
  44. public Q_SLOTS:
  45. /**
  46. * \brief Remove row i
  47. */
  48. void remove(int i);
  49. /**
  50. * \brief append a default row
  51. */
  52. virtual void append() = 0;
  53. Q_SIGNALS:
  54. void removed(int i);
  55. protected:
  56. /**
  57. * \brief Create a new row with the given widget
  58. *
  59. * Must be caled by implementations of append()
  60. */
  61. void appendWidget(QWidget* w);
  62. /**
  63. * \brief get the widget found at the given row
  64. */
  65. QWidget* widget(int i);
  66. /**
  67. * \brief get the widget found at the given row
  68. */
  69. template<class T>
  70. T* widget_cast(int i) { return qobject_cast<T*>(widget(i)); }
  71. /**
  72. * \brief clear all rows without emitting signals
  73. *
  74. * May be useful when implementation want to set all values at once
  75. */
  76. void clear();
  77. private Q_SLOTS:
  78. void remove_clicked(QWidget* w);
  79. void up_clicked(QWidget* w);
  80. void down_clicked(QWidget* w);
  81. private:
  82. class Private;
  83. Private * const p;
  84. QWidget* create_button(QWidget* data, QSignalMapper*mapper,
  85. QString icon_name, QString text,
  86. QString tooltip = QString()) const;
  87. };
  88. #endif // ABSTRACT_WIDGET_LIST_HPP