Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
helpdocsettingswidget.cpp
Go to the documentation of this file.
1// Copyright (C) 2020 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
3
6#include "ui_helpdocsettingswidget.h"
7
8#include <QtCore/QMap>
9#include <QtWidgets/QFileDialog>
10#include <QtWidgets/QPushButton>
11
12#include <QtCore/QMap>
13
15
17{
19 Q_DECLARE_PUBLIC(HelpDocSettingsWidget)
20public:
22
25 void applyDocListFilter(QListWidgetItem *item);
26
29
31 HelpDocSettings m_settings;
32};
33
35{
36 Q_Q(HelpDocSettingsWidget);
37
38 const QStringList &fileNames =
39 QFileDialog::getOpenFileNames(q, HelpDocSettingsWidget::tr("Add Documentation"), {},
40 HelpDocSettingsWidget::tr("Qt Compressed Help Files (*.qch)"));
41 if (fileNames.isEmpty())
42 return;
43
44 bool added = false;
45
46 for (const QString &fileName : fileNames) {
47 if (!m_settings.addDocumentation(fileName))
48 continue;
49
50 if (!added) {
51 added = true;
52 m_ui.registeredDocsListWidget->clearSelection();
53 }
54
55 const QString namespaceName = m_settings.namespaceName(fileName);
56 QListWidgetItem *item = new QListWidgetItem(namespaceName);
57 m_namespaceToItem.insert(namespaceName, item);
58 m_itemToNamespace.insert(item, namespaceName);
59 m_ui.registeredDocsListWidget->insertItem(m_namespaceToItem.keys().indexOf(namespaceName), item);
60
61 item->setSelected(true);
62 applyDocListFilter(item);
63 }
64
65 if (added)
66 emit q->docSettingsChanged(m_settings);
67}
68
70{
71 Q_Q(HelpDocSettingsWidget);
72
73 const QList<QListWidgetItem *> selectedItems = m_ui.registeredDocsListWidget->selectedItems();
74 if (selectedItems.isEmpty())
75 return;
76
77 for (QListWidgetItem *item : selectedItems) {
78 const QString namespaceName = m_itemToNamespace.value(item);
79 m_itemToNamespace.remove(item);
80 m_namespaceToItem.remove(namespaceName);
81 delete item;
82
83 m_settings.removeDocumentation(namespaceName);
84 }
85
86 emit q->docSettingsChanged(m_settings);
87}
88
90{
91 const QString namespaceName = m_itemToNamespace.value(item);
92 const QString nameFilter = m_ui.registeredDocsFilterLineEdit->text();
93
94 const bool matches = nameFilter.isEmpty() || namespaceName.contains(nameFilter);
95
96 if (!matches)
97 item->setSelected(false);
98 item->setHidden(!matches);
99}
100
101HelpDocSettingsWidget::HelpDocSettingsWidget(QWidget *parent)
102 : QWidget(parent)
103 , d_ptr(new HelpDocSettingsWidgetPrivate())
104{
105 Q_D(HelpDocSettingsWidget);
106 d->q_ptr = this;
107 d->m_ui.setupUi(this);
108
109 connect(d->m_ui.docAddButton, &QAbstractButton::clicked, this,
110 [this]() {
111 Q_D(HelpDocSettingsWidget);
112 d->addDocumentation();
113 });
114 connect(d->m_ui.docRemoveButton, &QAbstractButton::clicked, this,
115 [this]() {
116 Q_D(HelpDocSettingsWidget);
117 d->removeDocumentation();
118 });
119 connect(d->m_ui.registeredDocsFilterLineEdit, &QLineEdit::textChanged, this,
120 [this](const QString &) {
121 Q_D(HelpDocSettingsWidget);
122 for (const auto item : d->m_namespaceToItem)
123 d->applyDocListFilter(item);
124 });
125 connect(d->m_ui.registeredDocsListWidget, &QListWidget::itemSelectionChanged, this,
126 [this]() {
127 Q_D(HelpDocSettingsWidget);
128 d->m_ui.docRemoveButton->setEnabled(
129 !d->m_ui.registeredDocsListWidget->selectedItems().isEmpty());
130 });
131}
132
134
135void HelpDocSettingsWidget::setDocSettings(const HelpDocSettings &settings)
136{
137 Q_D(HelpDocSettingsWidget);
138 d->m_settings = settings;
139
140 d->m_ui.registeredDocsListWidget->clear();
141 d->m_namespaceToItem.clear();
142 d->m_itemToNamespace.clear();
143
144 for (const QString &namespaceName : d->m_settings.namespaces()) {
145 QListWidgetItem *item = new QListWidgetItem(namespaceName);
146 d->m_namespaceToItem.insert(namespaceName, item);
147 d->m_itemToNamespace.insert(item, namespaceName);
148 d->m_ui.registeredDocsListWidget->addItem(item);
149 d->applyDocListFilter(item);
150 }
151
152 d->m_ui.docRemoveButton->setEnabled(
153 !d->m_ui.registeredDocsListWidget->selectedItems().isEmpty());
154}
155
156HelpDocSettings HelpDocSettingsWidget::docSettings() const
157{
158 Q_D(const HelpDocSettingsWidget);
159 return d->m_settings;
160}
161
162QT_END_NAMESPACE
QMap< QString, QListWidgetItem * > m_namespaceToItem
void applyDocListFilter(QListWidgetItem *item)
QHash< QListWidgetItem *, QString > m_itemToNamespace
HelpDocSettings docSettings() const
void setDocSettings(const HelpDocSettings &settings)
Combined button and popup list for selecting options.