Skip to content

Commit

Permalink
feat(registry,ui): show docset search keywords/prefixes
Browse files Browse the repository at this point in the history
  • Loading branch information
trollixx committed Jun 17, 2024
1 parent 4bcc896 commit 07a357c
Show file tree
Hide file tree
Showing 7 changed files with 67 additions and 6 deletions.
6 changes: 6 additions & 0 deletions src/libs/registry/itemdatarole.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@ enum ItemDataRole {
UrlRole
};

enum SectionIndex {
Name,
SearchPrefix,
Actions
};

} // namespace Registry
} // namespace Zeal

Expand Down
38 changes: 36 additions & 2 deletions src/libs/registry/listmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand All @@ -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();
Expand All @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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;
}

Expand Down
4 changes: 3 additions & 1 deletion src/libs/registry/listmodel.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
8 changes: 7 additions & 1 deletion src/libs/ui/docsetlistitemdelegate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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");

Expand Down
10 changes: 9 additions & 1 deletion src/libs/ui/docsetsdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion src/libs/ui/docsetsdialog.ui
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
5 changes: 5 additions & 0 deletions src/libs/ui/searchsidebar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 07a357c

Please sign in to comment.