LMMS
Loading...
Searching...
No Matches
ComboBoxModel.h
Go to the documentation of this file.
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
25#ifndef LMMS_COMBOBOX_MODEL_H
26#define LMMS_COMBOBOX_MODEL_H
27
28#include <memory>
29#include <utility>
30#include <vector>
31
32#include "AutomatableModel.h"
33#include "embed.h"
34
35namespace lmms
36{
37
38class LMMS_EXPORT ComboBoxModel : public IntModel
39{
40 Q_OBJECT
42public:
44 const QString& displayName = QString(),
45 bool isDefaultConstructed = false ) :
47 {
48 setJournalling(false);
49 }
50
51 void addItem( QString item, std::unique_ptr<PixmapLoader> loader = nullptr );
52
53 void replaceItem(std::size_t index, QString item, std::unique_ptr<PixmapLoader> loader = nullptr);
54
55 void clear();
56
57 int findText( const QString& txt ) const;
58
59 QString currentText() const
60 {
61 return ( size() > 0 && value() < size() ) ? m_items[value()].first : QString();
62 }
63
65 {
66 return m_items[value()].second.get();
67 }
68
69 const QString & itemText( int i ) const
70 {
71 return m_items[std::clamp(i, minValue(), maxValue())].first;
72 }
73
74 const PixmapLoader* itemPixmap( int i ) const
75 {
76 return m_items[std::clamp(i, minValue(), maxValue())].second.get();
77 }
78
79 int size() const
80 {
81 return m_items.size();
82 }
83
84
85private:
86 using Item = std::pair<QString, std::unique_ptr<PixmapLoader>>;
87
88 std::vector<Item> m_items;
89
90} ;
91
92} // namespace lmms
93
94#endif // LMMS_COMBOBOX_MODEL_H
#define MODEL_IS_VISITABLE
Definition AutomatableModel.h:68
const QString & itemText(int i) const
Definition ComboBoxModel.h:69
std::pair< QString, std::unique_ptr< PixmapLoader > > Item
Definition ComboBoxModel.h:86
int size() const
Definition ComboBoxModel.h:79
ComboBoxModel(Model *parent=nullptr, const QString &displayName=QString(), bool isDefaultConstructed=false)
Definition ComboBoxModel.h:43
std::vector< Item > m_items
Definition ComboBoxModel.h:88
const PixmapLoader * itemPixmap(int i) const
Definition ComboBoxModel.h:74
const PixmapLoader * currentData() const
Definition ComboBoxModel.h:64
QString currentText() const
Definition ComboBoxModel.h:59
IntModel(int val=0, int min=0, int max=0, Model *parent=nullptr, const QString &displayName=QString(), bool defaultConstructed=false)
Definition AutomatableModel.h:485
void setJournalling(const bool _sr)
Definition JournallingObject.h:73
Definition Model.h:37
virtual QString displayName() const
Definition Model.cpp:47
bool isDefaultConstructed() const
Definition Model.cpp:37
Definition embed.h:73
int minValue() const
Definition AutomatableModel.h:448
int maxValue() const
Definition AutomatableModel.h:453
register unsigned i
Definition inflate.c:1575
static PuglViewHint int value
Definition pugl.h:1708
static uintptr_t parent
Definition pugl.h:1644
Definition AudioAlsa.cpp:35
ulg size
Definition extract.c:2350