2 * ComboBoxModel.h - declaration of class ComboBoxModel
4 * Copyright (c) 2008-2011 Tobias Doerffel <tobydox/at/users.sourceforge.net>
6 * This file is part of Linux MultiMedia Studio - http://lmms.sourceforge.net
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.
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.
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.
25 #ifndef _COMBOBOX_MODEL_H
26 #define _COMBOBOX_MODEL_H
28 #include <QtCore/QVector>
29 #include <QtCore/QPair>
31 #include "AutomatableModel.h"
32 #include "templates.h"
37 class EXPORT ComboBoxModel
: public IntModel
41 ComboBoxModel( Model
* _parent
= NULL
,
42 const QString
& _display_name
= QString(),
43 bool _default_constructed
= false ) :
44 IntModel( 0, 0, 0, _parent
, _display_name
,
45 _default_constructed
)
49 virtual ~ComboBoxModel()
54 void addItem( const QString
& _item
, PixmapLoader
* _loader
= NULL
);
58 int findText( const QString
& _txt
) const;
60 inline QString
currentText() const
62 return ( size() > 0 && value() < size() ) ? m_items
[value()].first
: QString();
65 inline const PixmapLoader
* currentData() const
67 return m_items
[value()].second
;
70 inline const QString
& itemText( int _i
) const
72 return m_items
[tLimit
<int>( _i
, minValue(), maxValue() )].first
;
75 inline const PixmapLoader
* itemPixmap( int _i
) const
77 return m_items
[tLimit
<int>( _i
, minValue(), maxValue() )].second
;
80 inline int size() const
82 return m_items
.size();
86 typedef QPair
<QString
, PixmapLoader
*> Item
;
88 QVector
<Item
> m_items
;