1 | // Copyright (C) 2020 The Qt Company Ltd. |
---|---|
2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only |
3 | |
4 | #ifndef QOPTIONSWIDGET_H |
5 | #define QOPTIONSWIDGET_H |
6 | |
7 | // |
8 | // W A R N I N G |
9 | // ------------- |
10 | // |
11 | // This file is not part of the Qt API. It exists for the convenience |
12 | // of the help generator tools. This header file may change from version |
13 | // to version without notice, or even be removed. |
14 | // |
15 | // We mean it. |
16 | // |
17 | |
18 | #include <QtCore/qhash.h> |
19 | #include <QtWidgets/qwidget.h> |
20 | |
21 | QT_BEGIN_NAMESPACE |
22 | |
23 | class QListWidget; |
24 | class QListWidgetItem; |
25 | |
26 | class QOptionsWidget : public QWidget |
27 | { |
28 | Q_OBJECT |
29 | public: |
30 | QOptionsWidget(QWidget *parent = nullptr); |
31 | |
32 | void clear() { setOptions(validOptions: {}, selectedOptions: {}); } |
33 | void setOptions(const QStringList &validOptions, const QStringList &selectedOptions); |
34 | QStringList validOptions() const { return m_validOptions; } |
35 | QStringList selectedOptions() const { return m_selectedOptions; } |
36 | |
37 | void setNoOptionText(const QString &text); |
38 | void setInvalidOptionText(const QString &text); |
39 | |
40 | signals: |
41 | void optionSelectionChanged(const QStringList &options); |
42 | |
43 | private: |
44 | QString optionText(const QString &optionName, bool valid) const; |
45 | QListWidgetItem *appendItem(const QString &optionName, bool valid, bool selected); |
46 | void appendSeparator(); |
47 | void itemChanged(QListWidgetItem *item); |
48 | |
49 | QListWidget *m_listWidget = nullptr; |
50 | QString m_noOptionText; |
51 | QString m_invalidOptionText; |
52 | QStringList m_validOptions; |
53 | QStringList m_invalidOptions; |
54 | QStringList m_selectedOptions; |
55 | QHash<QString, QListWidgetItem *> m_optionToItem; |
56 | QHash<QListWidgetItem *, QString> m_itemToOption; |
57 | }; |
58 | |
59 | QT_END_NAMESPACE |
60 | |
61 | #endif // QOPTIONSWIDGET_H |
62 |