forked from qt-creator/qt-creator
Help: Inline docsettingspage UI
Change-Id: Ifd4b44ba248f1e4b696477eb127a102762d9fbd9 Reviewed-by: hjk <hjk@qt.io> Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
This commit is contained in:
@@ -4,7 +4,7 @@ add_qtc_plugin(Help
|
||||
PLUGIN_DEPENDS Core ProjectExplorer
|
||||
PLUGIN_RECOMMENDS TextEditor
|
||||
SOURCES
|
||||
docsettingspage.cpp docsettingspage.h docsettingspage.ui
|
||||
docsettingspage.cpp docsettingspage.h
|
||||
filtersettingspage.cpp filtersettingspage.h
|
||||
generalsettingspage.cpp generalsettingspage.h generalsettingspage.ui
|
||||
help.qrc
|
||||
|
||||
@@ -27,9 +27,10 @@
|
||||
|
||||
#include "helpconstants.h"
|
||||
#include "helpmanager.h"
|
||||
#include "ui_docsettingspage.h"
|
||||
|
||||
#include <coreplugin/icore.h>
|
||||
#include <utils/algorithm.h>
|
||||
#include <utils/fancylineedit.h>
|
||||
#include <utils/fileutils.h>
|
||||
|
||||
#include <QFileDialog>
|
||||
@@ -39,7 +40,12 @@
|
||||
#include <QAbstractListModel>
|
||||
#include <QCoreApplication>
|
||||
#include <QDir>
|
||||
#include <QGroupBox>
|
||||
#include <QHBoxLayout>
|
||||
#include <QListView>
|
||||
#include <QPushButton>
|
||||
#include <QSortFilterProxyModel>
|
||||
#include <QVBoxLayout>
|
||||
#include <QVariant>
|
||||
#include <QVector>
|
||||
|
||||
@@ -98,8 +104,6 @@ private:
|
||||
|
||||
QList<QModelIndex> currentSelection() const;
|
||||
|
||||
Ui::DocSettingsPage m_ui;
|
||||
|
||||
FilePath m_recentDialogPath;
|
||||
|
||||
using NameSpaceToPathHash = QMultiHash<QString, QString>;
|
||||
@@ -107,6 +111,7 @@ private:
|
||||
QHash<QString, bool> m_filesToRegisterUserManaged;
|
||||
NameSpaceToPathHash m_filesToUnregister;
|
||||
|
||||
QListView *m_docsListView = nullptr;
|
||||
QSortFilterProxyModel m_proxyModel;
|
||||
DocModel m_model;
|
||||
};
|
||||
@@ -165,7 +170,39 @@ using namespace Help::Internal;
|
||||
|
||||
DocSettingsPageWidget::DocSettingsPageWidget()
|
||||
{
|
||||
m_ui.setupUi(this);
|
||||
auto groupBox = new QGroupBox(this);
|
||||
|
||||
auto filterLineEdit = new Utils::FancyLineEdit(groupBox);
|
||||
m_docsListView = new QListView(groupBox);
|
||||
m_docsListView->setSelectionMode(QAbstractItemView::ExtendedSelection);
|
||||
m_docsListView->setUniformItemSizes(true);
|
||||
|
||||
auto treeLayout = new QVBoxLayout();
|
||||
treeLayout->addWidget(filterLineEdit);
|
||||
treeLayout->addWidget(m_docsListView);
|
||||
|
||||
auto addButton = new QPushButton(groupBox);
|
||||
auto removeButton = new QPushButton(groupBox);
|
||||
|
||||
auto buttonLayout = new QVBoxLayout();
|
||||
buttonLayout->addWidget(addButton);
|
||||
buttonLayout->addWidget(removeButton);
|
||||
buttonLayout->addStretch(1);
|
||||
|
||||
auto horizontalLayout = new QHBoxLayout(groupBox);
|
||||
horizontalLayout->addLayout(treeLayout);
|
||||
horizontalLayout->addLayout(buttonLayout);
|
||||
|
||||
setLayout(new QVBoxLayout);
|
||||
layout()->addWidget(groupBox);
|
||||
|
||||
setToolTip(QCoreApplication::translate("Help::Internal::DocSettingsPage",
|
||||
"Add and remove compressed help files, .qch.",
|
||||
nullptr));
|
||||
groupBox->setTitle(
|
||||
QCoreApplication::translate("Help::Internal::DocSettingsPage", "Registered Documentation"));
|
||||
addButton->setText(QCoreApplication::translate("Help::Internal::DocSettingsPage", "Add..."));
|
||||
removeButton->setText(QCoreApplication::translate("Help::Internal::DocSettingsPage", "Remove"));
|
||||
|
||||
const QStringList nameSpaces = HelpManager::registeredNamespaces();
|
||||
const QSet<QString> userDocumentationPaths = HelpManager::userDocumentationPaths();
|
||||
@@ -183,29 +220,27 @@ DocSettingsPageWidget::DocSettingsPageWidget()
|
||||
m_model.setEntries(entries);
|
||||
|
||||
m_proxyModel.setSourceModel(&m_model);
|
||||
m_ui.docsListView->setModel(&m_proxyModel);
|
||||
m_ui.filterLineEdit->setFiltering(true);
|
||||
connect(m_ui.filterLineEdit,
|
||||
m_docsListView->setModel(&m_proxyModel);
|
||||
filterLineEdit->setFiltering(true);
|
||||
connect(filterLineEdit,
|
||||
&QLineEdit::textChanged,
|
||||
&m_proxyModel,
|
||||
&QSortFilterProxyModel::setFilterFixedString);
|
||||
|
||||
connect(m_ui.addButton,
|
||||
&QAbstractButton::clicked,
|
||||
this,
|
||||
&DocSettingsPageWidget::addDocumentation);
|
||||
connect(m_ui.removeButton, &QAbstractButton::clicked, this, [this]() {
|
||||
connect(addButton, &QAbstractButton::clicked, this, &DocSettingsPageWidget::addDocumentation);
|
||||
connect(removeButton, &QAbstractButton::clicked, this, [this]() {
|
||||
removeDocumentation(currentSelection());
|
||||
});
|
||||
|
||||
m_ui.docsListView->installEventFilter(this);
|
||||
m_docsListView->installEventFilter(this);
|
||||
}
|
||||
|
||||
void DocSettingsPageWidget::addDocumentation()
|
||||
{
|
||||
const FilePaths files =
|
||||
FileUtils::getOpenFilePaths(m_ui.addButton->parentWidget(),
|
||||
tr("Add Documentation"), m_recentDialogPath, tr("Qt Help Files (*.qch)"));
|
||||
const FilePaths files = FileUtils::getOpenFilePaths(Core::ICore::dialogParent(),
|
||||
tr("Add Documentation"),
|
||||
m_recentDialogPath,
|
||||
tr("Qt Help Files (*.qch)"));
|
||||
|
||||
if (files.isEmpty())
|
||||
return;
|
||||
@@ -266,8 +301,10 @@ void DocSettingsPageWidget::addDocumentation()
|
||||
}
|
||||
|
||||
if (!formatedFail.isEmpty()) {
|
||||
QMessageBox::information(m_ui.addButton->parentWidget(), tr("Registration Failed"),
|
||||
tr("Unable to register documentation.") + formatedFail, QMessageBox::Ok);
|
||||
QMessageBox::information(Core::ICore::dialogParent(),
|
||||
tr("Registration Failed"),
|
||||
tr("Unable to register documentation.") + formatedFail,
|
||||
QMessageBox::Ok);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -288,7 +325,7 @@ void DocSettingsPageWidget::apply()
|
||||
|
||||
bool DocSettingsPageWidget::eventFilter(QObject *object, QEvent *event)
|
||||
{
|
||||
if (object != m_ui.docsListView)
|
||||
if (object != m_docsListView)
|
||||
return IOptionsPageWidget::eventFilter(object, event);
|
||||
|
||||
if (event->type() == QEvent::KeyPress) {
|
||||
@@ -327,13 +364,15 @@ void DocSettingsPageWidget::removeDocumentation(const QList<QModelIndex> &items)
|
||||
|
||||
const int newlySelectedRow = qMax(itemsByDecreasingRow.last().row() - 1, 0);
|
||||
const QModelIndex index = m_proxyModel.mapFromSource(m_model.index(newlySelectedRow));
|
||||
m_ui.docsListView->selectionModel()->select(index, QItemSelectionModel::ClearAndSelect);
|
||||
m_docsListView->selectionModel()->select(index, QItemSelectionModel::ClearAndSelect);
|
||||
}
|
||||
|
||||
QList<QModelIndex> DocSettingsPageWidget::currentSelection() const
|
||||
{
|
||||
return Utils::transform(m_ui.docsListView->selectionModel()->selectedRows(),
|
||||
[this](const QModelIndex &index) { return m_proxyModel.mapToSource(index); });
|
||||
return Utils::transform(m_docsListView->selectionModel()->selectedRows(),
|
||||
[this](const QModelIndex &index) {
|
||||
return m_proxyModel.mapToSource(index);
|
||||
});
|
||||
}
|
||||
|
||||
DocSettingsPage::DocSettingsPage()
|
||||
|
||||
@@ -1,85 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>Help::Internal::DocSettingsPage</class>
|
||||
<widget class="QWidget" name="Help::Internal::DocSettingsPage">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>400</width>
|
||||
<height>300</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="toolTip">
|
||||
<string>Add and remove compressed help files, .qch.</string>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<item>
|
||||
<widget class="QGroupBox" name="groupBox">
|
||||
<property name="title">
|
||||
<string>Registered Documentation</string>
|
||||
</property>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||
<item>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_2">
|
||||
<item>
|
||||
<widget class="Utils::FancyLineEdit" name="filterLineEdit"/>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QListView" name="docsListView">
|
||||
<property name="selectionMode">
|
||||
<enum>QAbstractItemView::ExtendedSelection</enum>
|
||||
</property>
|
||||
<property name="uniformItemSizes">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QVBoxLayout" name="_4">
|
||||
<item>
|
||||
<widget class="QPushButton" name="addButton">
|
||||
<property name="text">
|
||||
<string>Add...</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="removeButton">
|
||||
<property name="text">
|
||||
<string>Remove</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<spacer>
|
||||
<property name="orientation">
|
||||
<enum>Qt::Vertical</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>20</width>
|
||||
<height>40</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<customwidgets>
|
||||
<customwidget>
|
||||
<class>Utils::FancyLineEdit</class>
|
||||
<extends>QLineEdit</extends>
|
||||
<header location="global">utils/fancylineedit.h</header>
|
||||
</customwidget>
|
||||
</customwidgets>
|
||||
<resources/>
|
||||
<connections/>
|
||||
</ui>
|
||||
@@ -35,7 +35,7 @@ Project {
|
||||
Group {
|
||||
name: "Sources"
|
||||
files: [
|
||||
"docsettingspage.cpp", "docsettingspage.h", "docsettingspage.ui",
|
||||
"docsettingspage.cpp", "docsettingspage.h",
|
||||
"filtersettingspage.cpp", "filtersettingspage.h",
|
||||
"generalsettingspage.cpp", "generalsettingspage.h", "generalsettingspage.ui",
|
||||
"help.qrc",
|
||||
|
||||
Reference in New Issue
Block a user