ComboBoxModel.h 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. /*
  2. * ComboBoxModel.h - declaration of class ComboBoxModel
  3. *
  4. * Copyright (c) 2008-2014 Tobias Doerffel <tobydox/at/users.sourceforge.net>
  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 COMBOBOX_MODEL_H
  25. #define COMBOBOX_MODEL_H
  26. #include <memory>
  27. #include <utility>
  28. #include <vector>
  29. #include "AutomatableModel.h"
  30. #include "embed.h"
  31. class LMMS_EXPORT ComboBoxModel : public IntModel
  32. {
  33. Q_OBJECT
  34. MODEL_IS_VISITABLE
  35. public:
  36. ComboBoxModel( Model* parent = NULL,
  37. const QString& displayName = QString(),
  38. bool isDefaultConstructed = false ) :
  39. IntModel( 0, 0, 0, parent, displayName, isDefaultConstructed )
  40. {
  41. }
  42. virtual ~ComboBoxModel()
  43. {
  44. clear();
  45. }
  46. void addItem( QString item, std::unique_ptr<PixmapLoader> loader = nullptr );
  47. void clear();
  48. int findText( const QString& txt ) const;
  49. QString currentText() const
  50. {
  51. return ( size() > 0 && value() < size() ) ? m_items[value()].first : QString();
  52. }
  53. const PixmapLoader* currentData() const
  54. {
  55. return m_items[value()].second.get();
  56. }
  57. const QString & itemText( int i ) const
  58. {
  59. return m_items[qBound<int>( minValue(), i, maxValue() )].first;
  60. }
  61. const PixmapLoader* itemPixmap( int i ) const
  62. {
  63. return m_items[qBound<int>( minValue(), i, maxValue() )].second.get();
  64. }
  65. int size() const
  66. {
  67. return m_items.size();
  68. }
  69. private:
  70. typedef std::pair<QString, std::unique_ptr<PixmapLoader> > Item;
  71. std::vector<Item> m_items;
  72. } ;
  73. #endif