QSkinny 0.8.0
C++/Qt UI toolkit
Loading...
Searching...
No Matches
QskSimpleListBox.h
1/******************************************************************************
2 * QSkinny - Copyright (C) The authors
3 * SPDX-License-Identifier: BSD-3-Clause
4 *****************************************************************************/
5
6#ifndef QSK_LIST_BOX_H
7#define QSK_LIST_BOX_H
8
9#include "QskListView.h"
10#include <qstringlist.h>
11
12class QSK_EXPORT QskSimpleListBox : public QskListView
13{
14 Q_OBJECT
15
16 Q_PROPERTY( QStringList entries READ entries
17 WRITE setEntries NOTIFY entriesChanged )
18
19 using Inherited = QskListView;
20
21 public:
22 QskSimpleListBox( QQuickItem* parent = nullptr );
23 ~QskSimpleListBox() override;
24
25 void setColumnWidthHint( int column, qreal width );
26 qreal columnWidthHint( int column ) const;
27
28 // not sure if we will keep this, but
29 // at least it is worth trying to avoid models
30
31 void insert( const QStringList&, int index );
32 void insert( const QString&, int index );
33
34 void append( const QStringList& );
35 void append( const QString& );
36
37 void removeAt( int index );
38 void removeBulk( int from, int to = -1 );
39
40 int rowCount() const override final;
41 int columnCount() const override final;
42
43 qreal columnWidth( int col ) const override;
44 qreal rowHeight() const override;
45
46 QString entryAt( int row ) const;
47 QString selectedEntry() const;
48 QStringList entries() const;
49
50 QVariant valueAt( int row, int col ) const override final;
51
52 public Q_SLOTS:
53 void setEntries( const QStringList& );
54 void clear();
55
56 Q_SIGNALS:
57 void entriesChanged();
58 void selectedEntryChanged( const QString& );
59
60 private:
61 void propagateEntries();
62
63 class PrivateData;
64 std::unique_ptr< PrivateData > m_data;
65};
66
67inline void QskSimpleListBox::append( const QStringList& entries )
68{
69 insert( entries, -1 );
70}
71
72inline void QskSimpleListBox::append( const QString& entry )
73{
74 insert( entry, -1 );
75}
76
77inline QString QskSimpleListBox::selectedEntry() const
78{
79 return entryAt( selectedRow() );
80}
81
82#endif