Welcome/Qt: Show featured examples in separate section

Task-number: QTCREATORBUG-28546
Change-Id: I9cf42cd11b442f720070c250da789d23001a1375
Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
This commit is contained in:
Eike Ziller
2023-01-17 10:35:24 +01:00
parent ad643fdd30
commit 4d71a24cb9
4 changed files with 41 additions and 24 deletions

View File

@@ -718,6 +718,9 @@ ListModel *SectionedGridView::addSection(const Section &section, const QList<Lis
auto allProducts = static_cast<ListModel *>(m_filteredAllItemsModel->sourceModel());
allProducts->appendItems(items);
// only show section label(s) if there is more than one section
m_sectionLabels.at(0)->setVisible(m_sectionLabels.size() > 1);
return model;
}

View File

@@ -3,6 +3,8 @@
#include "exampleslistmodel.h"
#include "qtsupporttr.h"
#include <QBuffer>
#include <QApplication>
#include <QDir>
@@ -263,24 +265,26 @@ static QPixmap fetchPixmapAndUpdatePixmapCache(const QString &url)
return pixmap;
}
ExamplesListModel::ExamplesListModel(ExampleSetModel *exampleSetModel,
bool isExamples,
QObject *parent)
: Core::ListModel(parent)
ExamplesViewController::ExamplesViewController(ExampleSetModel *exampleSetModel,
SectionedGridView *view,
bool isExamples,
QObject *parent)
: QObject(parent)
, m_exampleSetModel(exampleSetModel)
, m_view(view)
, m_isExamples(isExamples)
{
if (isExamples) {
connect(m_exampleSetModel,
&ExampleSetModel::selectedExampleSetChanged,
this,
&ExamplesListModel::updateExamples);
&ExamplesViewController::updateExamples);
}
connect(Core::HelpManager::Signals::instance(),
&Core::HelpManager::Signals::documentationChanged,
this,
&ExamplesListModel::updateExamples);
setPixmapFunction(fetchPixmapAndUpdatePixmapCache);
&ExamplesViewController::updateExamples);
view->setPixmapFunction(fetchPixmapAndUpdatePixmapCache);
updateExamples();
}
@@ -493,7 +497,7 @@ static QList<ExampleItem *> parseTutorials(QXmlStreamReader *reader, const QStri
return result;
}
void ExamplesListModel::updateExamples()
void ExamplesViewController::updateExamples()
{
QString examplesInstallPath;
QString demosInstallPath;
@@ -501,7 +505,7 @@ void ExamplesListModel::updateExamples()
const QStringList sources = m_exampleSetModel->exampleSources(&examplesInstallPath,
&demosInstallPath);
clear();
m_view->clear();
QList<ExampleItem *> items;
for (const QString &exampleSource : sources) {
@@ -550,8 +554,21 @@ void ExamplesListModel::updateExamples()
[](ExampleItem *item) { return item->tags.contains("ios"); });
}
}
Utils::sort(items, [](ExampleItem *first, ExampleItem *second) {
return first->name.compare(second->name, Qt::CaseInsensitive) < 0;
});
appendItems(static_container_cast<ListItem *>(items));
QList<ExampleItem *> featured;
QList<ExampleItem *> other;
std::tie(featured, other) = Utils::partition(items,
[](ExampleItem *i) { return i->isHighlighted; });
if (!featured.isEmpty()) {
m_view->addSection({Tr::tr("Featured", "Category for highlighted examples"), 0},
static_container_cast<ListItem *>(featured));
}
m_view->addSection({Tr::tr("Other", "Category for all other examples"), 1},
static_container_cast<ListItem *>(other));
}
void ExampleSetModel::updateQtVersionList()

View File

@@ -16,7 +16,7 @@
namespace QtSupport {
namespace Internal {
class ExamplesListModel;
class ExamplesViewController;
class ExampleSetModel : public QStandardItemModel
{
@@ -100,16 +100,20 @@ public:
QStringList platforms;
};
class ExamplesListModel : public Core::ListModel
class ExamplesViewController : public QObject
{
Q_OBJECT
public:
explicit ExamplesListModel(ExampleSetModel *exampleSetModel, bool isExamples, QObject *parent);
explicit ExamplesViewController(ExampleSetModel *exampleSetModel,
Core::SectionedGridView *view,
bool isExamples,
QObject *parent);
void updateExamples();
private:
ExampleSetModel *m_exampleSetModel;
Core::SectionedGridView *m_view;
bool m_isExamples;
};

View File

@@ -261,9 +261,6 @@ public:
{
m_exampleDelegate.setShowExamples(isExamples);
auto examplesModel = new ExamplesListModel(s_exampleSetModel, isExamples, this);
auto filteredModel = new ListModelFilter(examplesModel, this);
auto searchBox = new SearchBox(this);
m_searcher = searchBox->m_lineEdit;
@@ -306,19 +303,15 @@ public:
grid->addWidget(searchBar, 0, 1);
grid->addWidget(WelcomePageHelpers::panelBar(this), 0, 2);
auto gridView = new GridView(this);
gridView->setModel(filteredModel);
auto gridView = new SectionedGridView(this);
new ExamplesViewController(s_exampleSetModel, gridView, isExamples, this);
gridView->setItemDelegate(&m_exampleDelegate);
if (auto sb = gridView->verticalScrollBar())
sb->setSingleStep(25);
grid->addWidget(gridView, 1, 1, 1, 2);
connect(&m_exampleDelegate, &ExampleDelegate::tagClicked,
this, &ExamplesPageWidget::onTagClicked);
connect(m_searcher,
&QLineEdit::textChanged,
filteredModel,
&ListModelFilter::setSearchString);
connect(m_searcher, &QLineEdit::textChanged, gridView, &SectionedGridView::setSearchString);
}
void onTagClicked(const QString &tag)