QSkinny 0.8.0
C++/Qt UI toolkit
Loading...
Searching...
No Matches
QskSelectionSubWindow.cpp
1/******************************************************************************
2 * QSkinny - Copyright (C) The authors
3 * SPDX-License-Identifier: BSD-3-Clause
4 *****************************************************************************/
5
6#include "QskSelectionSubWindow.h"
7#include "QskSimpleListBox.h"
8
9/*
10 QInputDialog uses a combo box instead of a list widget
11 Guess we should do the same TODO ...
12 */
13static inline QskSimpleListBox* qskListBox(
14 QskSelectionSubWindow* subWindow )
15{
16 return qobject_cast< QskSimpleListBox* >( subWindow->contentItem() );
17}
18
19static inline const QskSimpleListBox* qskListBox(
20 const QskSelectionSubWindow* subWindow )
21{
22 return qobject_cast< QskSimpleListBox* >( subWindow->contentItem() );
23}
24
25namespace
26{
27 class ListBox final : public QskSimpleListBox
28 {
29 public:
30 ListBox( QskSelectionSubWindow* subWindow )
31 {
32 setObjectName( QStringLiteral( "QskSelectionSubWindowListBox" ) );
33
34 connect( this, &QskSimpleListBox::selectedRowChanged,
35 subWindow, &QskSelectionSubWindow::selectedRowChanged );
36
37 connect( this, &QskSimpleListBox::selectedEntryChanged,
38 subWindow, &QskSelectionSubWindow::selectedEntryChanged );
39
40 connect( this, &QskSimpleListBox::entriesChanged,
41 subWindow, &QskSelectionSubWindow::entriesChanged );
42 }
43 };
44}
45
46QskSelectionSubWindow::QskSelectionSubWindow( QQuickItem* parent )
47 : Inherited( parent )
48{
49 auto listBox = new ListBox( this );
50#if 1
51 listBox->setPreferredSize( 500, 500 );
52#endif
53
54 setContentItem( listBox );
55 setDialogActions( QskDialog::Ok | QskDialog::Cancel );
56}
57
58QskSelectionSubWindow::~QskSelectionSubWindow()
59{
60}
61
62void QskSelectionSubWindow::setEntries( const QStringList& entries )
63{
64 if ( auto listBox = qskListBox( this ) )
65 listBox->setEntries( entries );
66}
67
68QStringList QskSelectionSubWindow::entries() const
69{
70 if ( auto listBox = qskListBox( this ) )
71 return listBox->entries();
72
73 return QStringList();
74}
75
76void QskSelectionSubWindow::setSelectedRow( int row )
77{
78 if ( auto listBox = qskListBox( this ) )
79 listBox->setSelectedRow( row );
80}
81
82int QskSelectionSubWindow::selectedRow() const
83{
84 if ( auto listBox = qskListBox( this ) )
85 return listBox->selectedRow();
86
87 return -1;
88}
89
90QString QskSelectionSubWindow::selectedEntry() const
91{
92 if ( auto listBox = qskListBox( this ) )
93 return listBox->selectedEntry();
94
95 return QString();
96}
97
98#include "moc_QskSelectionSubWindow.cpp"