mirror of
https://github.com/zealdocs/zeal.git
synced 2024-11-22 12:33:20 +03:00
feat(registry,ui): show docset search keywords/prefixes
This commit is contained in:
parent
4bcc896eaa
commit
07a357cab0
@ -13,6 +13,12 @@ enum ItemDataRole {
|
||||
UrlRole
|
||||
};
|
||||
|
||||
enum SectionIndex {
|
||||
Name,
|
||||
SearchPrefix,
|
||||
Actions
|
||||
};
|
||||
|
||||
} // namespace Registry
|
||||
} // namespace Zeal
|
||||
|
||||
|
@ -47,6 +47,22 @@ ListModel::~ListModel()
|
||||
}
|
||||
}
|
||||
|
||||
QVariant ListModel::headerData(int section, Qt::Orientation orientation, int role) const
|
||||
{
|
||||
if (orientation != Qt::Horizontal || role != Qt::DisplayRole) {
|
||||
return QAbstractItemModel::headerData(section, orientation, role);
|
||||
}
|
||||
|
||||
switch (section) {
|
||||
case SectionIndex::Name:
|
||||
return tr("Name");
|
||||
case SectionIndex::SearchPrefix:
|
||||
return tr("Search prefix");
|
||||
default:
|
||||
return QLatin1String();
|
||||
}
|
||||
}
|
||||
|
||||
QVariant ListModel::data(const QModelIndex &index, int role) const
|
||||
{
|
||||
if (!index.isValid()) {
|
||||
@ -55,6 +71,10 @@ QVariant ListModel::data(const QModelIndex &index, int role) const
|
||||
|
||||
switch (role) {
|
||||
case Qt::DecorationRole:
|
||||
if (index.column() != SectionIndex::Name) {
|
||||
return QVariant();
|
||||
}
|
||||
|
||||
switch (indexLevel(index)) {
|
||||
case IndexLevel::Docset:
|
||||
return itemInRow(index.row())->docset->icon();
|
||||
@ -73,7 +93,14 @@ QVariant ListModel::data(const QModelIndex &index, int role) const
|
||||
case Qt::DisplayRole:
|
||||
switch (indexLevel(index)) {
|
||||
case IndexLevel::Docset:
|
||||
return itemInRow(index.row())->docset->title();
|
||||
switch (index.column()) {
|
||||
case SectionIndex::Name:
|
||||
return itemInRow(index.row())->docset->title();
|
||||
case SectionIndex::SearchPrefix:
|
||||
return itemInRow(index.row())->docset->keywords().join(QLatin1String(", "));
|
||||
default:
|
||||
return QVariant();
|
||||
}
|
||||
case IndexLevel::Group: {
|
||||
auto docsetItem = static_cast<DocsetItem *>(index.internalPointer());
|
||||
const QString symbolType = docsetItem->groups.at(index.row())->symbolType;
|
||||
@ -90,6 +117,10 @@ QVariant ListModel::data(const QModelIndex &index, int role) const
|
||||
return QVariant();
|
||||
}
|
||||
case Qt::ToolTipRole:
|
||||
if (index.column() != SectionIndex::Name) {
|
||||
return QVariant();
|
||||
}
|
||||
|
||||
switch (indexLevel(index)) {
|
||||
case IndexLevel::Docset: {
|
||||
const auto docset = itemInRow(index.row())->docset;
|
||||
@ -173,7 +204,10 @@ QModelIndex ListModel::parent(const QModelIndex &child) const
|
||||
|
||||
int ListModel::columnCount(const QModelIndex &parent) const
|
||||
{
|
||||
Q_UNUSED(parent)
|
||||
if (indexLevel(parent) == IndexLevel::Root) {
|
||||
return 3;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
@ -41,7 +41,9 @@ class ListModel final : public QAbstractItemModel
|
||||
public:
|
||||
~ListModel() override;
|
||||
|
||||
QVariant data(const QModelIndex &index, int role) const override;
|
||||
QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const;
|
||||
|
||||
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
|
||||
QModelIndex index(int row, int column, const QModelIndex &parent) const override;
|
||||
QModelIndex parent(const QModelIndex &child) const override;
|
||||
int columnCount(const QModelIndex &parent) const override;
|
||||
|
@ -48,10 +48,16 @@ void DocsetListItemDelegate::paint(QPainter *painter,
|
||||
return;
|
||||
}
|
||||
|
||||
if (index.column() != Registry::SectionIndex::Actions) {
|
||||
QStyledItemDelegate::paint(painter, option, index);
|
||||
return;
|
||||
}
|
||||
|
||||
QStyledItemDelegate::paint(painter, option, index);
|
||||
|
||||
if (!index.model()->data(index, Registry::ItemDataRole::UpdateAvailableRole).toBool())
|
||||
if (!index.model()->data(index, Registry::ItemDataRole::UpdateAvailableRole).toBool()) {
|
||||
return;
|
||||
}
|
||||
|
||||
const QString text = tr("Update available");
|
||||
|
||||
|
@ -501,11 +501,19 @@ void DocsetsDialog::setupInstalledDocsetsTab()
|
||||
ui->installedDocsetList->setItemDelegate(new DocsetListItemDelegate(this));
|
||||
ui->installedDocsetList->setModel(m_docsetRegistry->model());
|
||||
|
||||
ui->installedDocsetList->setItemsExpandable(false);
|
||||
ui->installedDocsetList->setRootIsDecorated(false);
|
||||
|
||||
ui->installedDocsetList->header()->setStretchLastSection(true);
|
||||
ui->installedDocsetList->header()->setSectionsMovable(false);
|
||||
ui->installedDocsetList->header()->setSectionResizeMode(0, QHeaderView::ResizeToContents);
|
||||
ui->installedDocsetList->header()->setSectionResizeMode(1, QHeaderView::ResizeToContents);
|
||||
|
||||
if (m_isStorageReadOnly) {
|
||||
return;
|
||||
}
|
||||
|
||||
connect(ui->installedDocsetList, &QListView::activated, this, [this](const QModelIndex &index) {
|
||||
connect(ui->installedDocsetList, &QTreeView::activated, this, [this](const QModelIndex &index) {
|
||||
if (!index.data(Registry::ItemDataRole::UpdateAvailableRole).toBool()) {
|
||||
return;
|
||||
}
|
||||
|
@ -28,7 +28,7 @@
|
||||
</attribute>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_5">
|
||||
<item>
|
||||
<widget class="QListView" name="installedDocsetList">
|
||||
<widget class="QTreeView" name="installedDocsetList">
|
||||
<property name="selectionMode">
|
||||
<enum>QAbstractItemView::ExtendedSelection</enum>
|
||||
</property>
|
||||
|
@ -273,6 +273,11 @@ void SearchSidebar::setTreeViewModel(QAbstractItemModel *model, bool isRootDecor
|
||||
m_treeView->setModel(model);
|
||||
m_treeView->setRootIsDecorated(isRootDecorated);
|
||||
|
||||
// Hide all but the first column.
|
||||
for (int i = 1; i < model->columnCount(); ++i) {
|
||||
m_treeView->setColumnHidden(i, true);
|
||||
}
|
||||
|
||||
QItemSelectionModel *newSelectionModel = m_treeView->selectionModel();
|
||||
if (newSelectionModel != oldSelectionModel) {
|
||||
// TODO: Remove once QTBUG-49966 is addressed.
|
||||
|
Loading…
Reference in New Issue
Block a user