forked from qt-creator/qt-creator
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:
@@ -718,6 +718,9 @@ ListModel *SectionedGridView::addSection(const Section §ion, const QList<Lis
|
|||||||
auto allProducts = static_cast<ListModel *>(m_filteredAllItemsModel->sourceModel());
|
auto allProducts = static_cast<ListModel *>(m_filteredAllItemsModel->sourceModel());
|
||||||
allProducts->appendItems(items);
|
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;
|
return model;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -3,6 +3,8 @@
|
|||||||
|
|
||||||
#include "exampleslistmodel.h"
|
#include "exampleslistmodel.h"
|
||||||
|
|
||||||
|
#include "qtsupporttr.h"
|
||||||
|
|
||||||
#include <QBuffer>
|
#include <QBuffer>
|
||||||
#include <QApplication>
|
#include <QApplication>
|
||||||
#include <QDir>
|
#include <QDir>
|
||||||
@@ -263,24 +265,26 @@ static QPixmap fetchPixmapAndUpdatePixmapCache(const QString &url)
|
|||||||
return pixmap;
|
return pixmap;
|
||||||
}
|
}
|
||||||
|
|
||||||
ExamplesListModel::ExamplesListModel(ExampleSetModel *exampleSetModel,
|
ExamplesViewController::ExamplesViewController(ExampleSetModel *exampleSetModel,
|
||||||
bool isExamples,
|
SectionedGridView *view,
|
||||||
QObject *parent)
|
bool isExamples,
|
||||||
: Core::ListModel(parent)
|
QObject *parent)
|
||||||
|
: QObject(parent)
|
||||||
, m_exampleSetModel(exampleSetModel)
|
, m_exampleSetModel(exampleSetModel)
|
||||||
|
, m_view(view)
|
||||||
, m_isExamples(isExamples)
|
, m_isExamples(isExamples)
|
||||||
{
|
{
|
||||||
if (isExamples) {
|
if (isExamples) {
|
||||||
connect(m_exampleSetModel,
|
connect(m_exampleSetModel,
|
||||||
&ExampleSetModel::selectedExampleSetChanged,
|
&ExampleSetModel::selectedExampleSetChanged,
|
||||||
this,
|
this,
|
||||||
&ExamplesListModel::updateExamples);
|
&ExamplesViewController::updateExamples);
|
||||||
}
|
}
|
||||||
connect(Core::HelpManager::Signals::instance(),
|
connect(Core::HelpManager::Signals::instance(),
|
||||||
&Core::HelpManager::Signals::documentationChanged,
|
&Core::HelpManager::Signals::documentationChanged,
|
||||||
this,
|
this,
|
||||||
&ExamplesListModel::updateExamples);
|
&ExamplesViewController::updateExamples);
|
||||||
setPixmapFunction(fetchPixmapAndUpdatePixmapCache);
|
view->setPixmapFunction(fetchPixmapAndUpdatePixmapCache);
|
||||||
updateExamples();
|
updateExamples();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -493,7 +497,7 @@ static QList<ExampleItem *> parseTutorials(QXmlStreamReader *reader, const QStri
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ExamplesListModel::updateExamples()
|
void ExamplesViewController::updateExamples()
|
||||||
{
|
{
|
||||||
QString examplesInstallPath;
|
QString examplesInstallPath;
|
||||||
QString demosInstallPath;
|
QString demosInstallPath;
|
||||||
@@ -501,7 +505,7 @@ void ExamplesListModel::updateExamples()
|
|||||||
const QStringList sources = m_exampleSetModel->exampleSources(&examplesInstallPath,
|
const QStringList sources = m_exampleSetModel->exampleSources(&examplesInstallPath,
|
||||||
&demosInstallPath);
|
&demosInstallPath);
|
||||||
|
|
||||||
clear();
|
m_view->clear();
|
||||||
|
|
||||||
QList<ExampleItem *> items;
|
QList<ExampleItem *> items;
|
||||||
for (const QString &exampleSource : sources) {
|
for (const QString &exampleSource : sources) {
|
||||||
@@ -550,8 +554,21 @@ void ExamplesListModel::updateExamples()
|
|||||||
[](ExampleItem *item) { return item->tags.contains("ios"); });
|
[](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()
|
void ExampleSetModel::updateQtVersionList()
|
||||||
|
@@ -16,7 +16,7 @@
|
|||||||
namespace QtSupport {
|
namespace QtSupport {
|
||||||
namespace Internal {
|
namespace Internal {
|
||||||
|
|
||||||
class ExamplesListModel;
|
class ExamplesViewController;
|
||||||
|
|
||||||
class ExampleSetModel : public QStandardItemModel
|
class ExampleSetModel : public QStandardItemModel
|
||||||
{
|
{
|
||||||
@@ -100,16 +100,20 @@ public:
|
|||||||
QStringList platforms;
|
QStringList platforms;
|
||||||
};
|
};
|
||||||
|
|
||||||
class ExamplesListModel : public Core::ListModel
|
class ExamplesViewController : public QObject
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
explicit ExamplesListModel(ExampleSetModel *exampleSetModel, bool isExamples, QObject *parent);
|
explicit ExamplesViewController(ExampleSetModel *exampleSetModel,
|
||||||
|
Core::SectionedGridView *view,
|
||||||
|
bool isExamples,
|
||||||
|
QObject *parent);
|
||||||
|
|
||||||
void updateExamples();
|
void updateExamples();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
ExampleSetModel *m_exampleSetModel;
|
ExampleSetModel *m_exampleSetModel;
|
||||||
|
Core::SectionedGridView *m_view;
|
||||||
bool m_isExamples;
|
bool m_isExamples;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@@ -261,9 +261,6 @@ public:
|
|||||||
{
|
{
|
||||||
m_exampleDelegate.setShowExamples(isExamples);
|
m_exampleDelegate.setShowExamples(isExamples);
|
||||||
|
|
||||||
auto examplesModel = new ExamplesListModel(s_exampleSetModel, isExamples, this);
|
|
||||||
auto filteredModel = new ListModelFilter(examplesModel, this);
|
|
||||||
|
|
||||||
auto searchBox = new SearchBox(this);
|
auto searchBox = new SearchBox(this);
|
||||||
m_searcher = searchBox->m_lineEdit;
|
m_searcher = searchBox->m_lineEdit;
|
||||||
|
|
||||||
@@ -306,19 +303,15 @@ public:
|
|||||||
grid->addWidget(searchBar, 0, 1);
|
grid->addWidget(searchBar, 0, 1);
|
||||||
grid->addWidget(WelcomePageHelpers::panelBar(this), 0, 2);
|
grid->addWidget(WelcomePageHelpers::panelBar(this), 0, 2);
|
||||||
|
|
||||||
auto gridView = new GridView(this);
|
auto gridView = new SectionedGridView(this);
|
||||||
gridView->setModel(filteredModel);
|
new ExamplesViewController(s_exampleSetModel, gridView, isExamples, this);
|
||||||
|
|
||||||
gridView->setItemDelegate(&m_exampleDelegate);
|
gridView->setItemDelegate(&m_exampleDelegate);
|
||||||
if (auto sb = gridView->verticalScrollBar())
|
|
||||||
sb->setSingleStep(25);
|
|
||||||
grid->addWidget(gridView, 1, 1, 1, 2);
|
grid->addWidget(gridView, 1, 1, 1, 2);
|
||||||
|
|
||||||
connect(&m_exampleDelegate, &ExampleDelegate::tagClicked,
|
connect(&m_exampleDelegate, &ExampleDelegate::tagClicked,
|
||||||
this, &ExamplesPageWidget::onTagClicked);
|
this, &ExamplesPageWidget::onTagClicked);
|
||||||
connect(m_searcher,
|
connect(m_searcher, &QLineEdit::textChanged, gridView, &SectionedGridView::setSearchString);
|
||||||
&QLineEdit::textChanged,
|
|
||||||
filteredModel,
|
|
||||||
&ListModelFilter::setSearchString);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void onTagClicked(const QString &tag)
|
void onTagClicked(const QString &tag)
|
||||||
|
Reference in New Issue
Block a user