Commit 71007df8 authored by hjk's avatar hjk

QtSupport: Simplify welcome page examples model handling further

Use the ExampleSetModel directly in the combobox, rely on normal
model reset behavior behavior for gui updates.

Change-Id: Icdb34ff0f572caaf92259530823e90bfd783b933
Task-number: QTCREATORBUG-17678
Reviewed-by: Christian Stenger's avatarChristian Stenger <christian.stenger@qt.io>
parent f16bd243
This diff is collapsed.
......@@ -25,12 +25,13 @@
#pragma once
#include <qtsupport/baseqtversion.h>
#include <QAbstractListModel>
#include <QSortFilterProxyModel>
#include <QStandardItemModel>
#include <QStringList>
#include <QXmlStreamReader>
#include <qtsupport/baseqtversion.h>
namespace QtSupport {
namespace Internal {
......@@ -42,28 +43,54 @@ class ExampleSetModel : public QStandardItemModel
Q_OBJECT
public:
ExampleSetModel();
int selectedExampleSet() const { return m_selectedExampleSetIndex; }
void selectExampleSet(int index);
QStringList exampleSources(QString *examplesInstallPath, QString *demosInstallPath);
signals:
void selectedExampleSetChanged(int);
private:
struct ExtraExampleSet {
QString displayName;
QString manifestPath;
QString examplesPath;
};
enum ExampleSetType {
InvalidExampleSet,
QtExampleSet,
ExtraExampleSet
ExtraExampleSetType
};
ExampleSetModel(ExamplesListModel *examplesModel, QObject *parent);
void writeCurrentIdToSettings(int currentIndex) const;
int readCurrentIndexFromSettings() const;
int indexForQtVersion(BaseQtVersion *qtVersion) const;
void update();
QVariant getDisplayName(int index) const;
QVariant getId(int index) const;
ExampleSetType getType(int i) const;
int getQtId(int index) const;
int getExtraExampleSetIndex(int index) const;
private:
ExamplesListModel *examplesModel;
BaseQtVersion *findHighestQtVersion() const;
int indexForQtVersion(BaseQtVersion *qtVersion) const;
void recreateModel();
void updateQtVersionList();
void qtVersionManagerLoaded();
void helpManagerInitialized();
void tryToInitialize();
QList<ExtraExampleSet> m_extraExampleSets;
QList<BaseQtVersion*> m_qtVersions;
int m_selectedExampleSetIndex = -1;
bool m_qtVersionManagerInitialized = false;
bool m_helpManagerInitialized = false;
bool m_initalized = false;
};
enum InstructionalType
......@@ -98,49 +125,30 @@ class ExamplesListModel : public QAbstractListModel
Q_OBJECT
public:
struct ExtraExampleSet {
QString displayName;
QString manifestPath;
QString examplesPath;
};
explicit ExamplesListModel(QObject *parent);
int rowCount(const QModelIndex &parent = QModelIndex()) const final;
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const final;
void beginReset() { beginResetModel(); }
void endReset() { endResetModel(); }
void update();
int selectedExampleSet() const;
void selectExampleSet(int index);
void updateExamples();
QList<ExtraExampleSet> extraExampleSets() const { return m_extraExampleSets; }
QStringList exampleSets() const;
ExampleSetModel *exampleSetModel() { return &m_exampleSetModel; }
signals:
void selectedExampleSetChanged(int);
private:
void updateQtVersions();
void updateExamples();
void updateSelectedQtVersion();
BaseQtVersion *findHighestQtVersion() const;
void parseExamples(QXmlStreamReader *reader, const QString &projectsOffset,
const QString &examplesInstallPath);
void parseDemos(QXmlStreamReader *reader, const QString &projectsOffset,
const QString &demosInstallPath);
void parseTutorials(QXmlStreamReader *reader, const QString &projectsOffset);
QStringList exampleSources(QString *examplesInstallPath, QString *demosInstallPath);
ExampleSetModel* m_exampleSetModel;
QList<ExtraExampleSet> m_extraExampleSets;
ExampleSetModel m_exampleSetModel;
QList<ExampleItem> m_exampleItems;
int m_selectedExampleSetIndex = -1;
};
class ExamplesListModelFilter : public QSortFilterProxyModel
......@@ -150,41 +158,19 @@ class ExamplesListModelFilter : public QSortFilterProxyModel
public:
ExamplesListModelFilter(ExamplesListModel *sourceModel, bool showTutorialsOnly, QObject *parent);
bool filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const;
int rowCount(const QModelIndex &parent = QModelIndex()) const final;
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const final;
void setSearchString(const QString &arg);
void setFilterTags(const QStringList &arg);
void updateFilter();
void handleQtVersionsChanged();
signals:
void filterTagsChanged(const QStringList &arg);
void searchStringChanged(const QString &arg);
private:
void setFilterStrings(const QStringList &arg);
void qtVersionManagerLoaded();
void helpManagerInitialized();
bool filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const final;
void timerEvent(QTimerEvent *event) final;
void exampleDataRequested() const;
void tryToInitialize();
void timerEvent(QTimerEvent *event);
void delayedUpdateFilter();
const bool m_showTutorialsOnly;
QString m_searchString;
QStringList m_filterTags;
QStringList m_filterStrings;
ExamplesListModel *m_sourceModel;
int m_timerId = 0;
bool m_qtVersionManagerInitialized = false;
bool m_helpManagerInitialized = false;
bool m_initalized = false;
bool m_exampleDataRequested = false;
};
} // namespace Internal
......
......@@ -247,7 +247,7 @@ static QString resourcePath()
class SearchBox : public QFrame
{
public:
SearchBox(const QString &placeHolderText, QWidget *parent)
SearchBox(QWidget *parent)
: QFrame(parent)
{
setFrameShape(QFrame::Box);
......@@ -257,7 +257,6 @@ public:
pal.setColor(QPalette::Base, themeColor(Theme::Welcome_BackgroundColor));
m_lineEdit = new QLineEdit;
m_lineEdit->setPlaceholderText(placeHolderText);
m_lineEdit->setFrame(false);
m_lineEdit->setFont(sizedFont(14, this));
m_lineEdit->setAttribute(Qt::WA_MacShowFocusRect, false);
......@@ -586,44 +585,48 @@ public:
static ExamplesListModel *s_examplesModel = new ExamplesListModel(this);
m_examplesModel = s_examplesModel;
m_filteredModel = new ExamplesListModelFilter(m_examplesModel, !m_isExamples, this);
auto filteredModel = new ExamplesListModelFilter(m_examplesModel, !m_isExamples, this);
auto searchBox = new SearchBox(this);
m_searcher = searchBox->m_lineEdit;
auto vbox = new QVBoxLayout(this);
vbox->setContentsMargins(30, 27, 20, 20);
if (m_isExamples) {
m_qtVersionSelector = new QComboBox(this);
m_qtVersionSelector->setMinimumWidth(itemWidth);
m_qtVersionSelector->setMaximumWidth(itemWidth);
m_searchBox = new SearchBox(tr("Search in Examples..."), this);
m_searcher->setPlaceholderText(tr("Search in Examples..."));
auto exampleSetSelector = new QComboBox(this);
exampleSetSelector->setMinimumWidth(itemWidth);
exampleSetSelector->setMaximumWidth(itemWidth);
ExampleSetModel *exampleSetModel = m_examplesModel->exampleSetModel();
exampleSetSelector->setModel(exampleSetModel);
exampleSetSelector->setCurrentIndex(exampleSetModel->selectedExampleSet());
connect(exampleSetSelector, static_cast<void(QComboBox::*)(int)>(&QComboBox::activated),
exampleSetModel, &ExampleSetModel::selectExampleSet);
connect(exampleSetModel, &ExampleSetModel::selectedExampleSetChanged,
exampleSetSelector, &QComboBox::setCurrentIndex);
auto hbox = new QHBoxLayout;
hbox->setSpacing(17);
hbox->addWidget(m_qtVersionSelector);
hbox->addWidget(m_searchBox);
hbox->addWidget(exampleSetSelector);
hbox->addWidget(searchBox);
vbox->addItem(hbox);
connect(m_qtVersionSelector, static_cast<void(QComboBox::*)(int)>(&QComboBox::activated),
m_examplesModel, &ExamplesListModel::selectExampleSet);
connect(m_examplesModel, &ExamplesListModel::selectedExampleSetChanged,
this, &ExamplesPageWidget::updateStuff);
} else {
m_searchBox = new SearchBox(tr("Search in Tutorials..."), this);
vbox->addWidget(m_searchBox);
m_searcher->setPlaceholderText(tr("Search in Tutorials..."));
vbox->addWidget(searchBox);
}
m_gridModel.setSourceModel(m_filteredModel);
m_gridModel.setSourceModel(filteredModel);
m_gridView = new GridView(this);
m_gridView->setModel(&m_gridModel);
m_gridView->setItemDelegate(&m_exampleDelegate);
vbox->addWidget(m_gridView);
auto gridView = new GridView(this);
gridView->setModel(&m_gridModel);
gridView->setItemDelegate(&m_exampleDelegate);
vbox->addWidget(gridView);
connect(&m_exampleDelegate, &ExampleDelegate::tagClicked,
this, &ExamplesPageWidget::onTagClicked);
connect(m_filteredModel, &ExamplesListModelFilter::filterTagsChanged,
this, &ExamplesPageWidget::updateStuff);
connect(m_filteredModel, &ExamplesListModelFilter::searchStringChanged,
this, &ExamplesPageWidget::updateStuff);
connect(m_searchBox->m_lineEdit, &QLineEdit::textChanged,
m_filteredModel, &ExamplesListModelFilter::setSearchString);
connect(m_searcher, &QLineEdit::textChanged,
filteredModel, &ExamplesListModelFilter::setSearchString);
}
int bestColumnCount() const
......@@ -639,26 +642,14 @@ public:
void onTagClicked(const QString &tag)
{
QString text = m_searchBox->m_lineEdit->text();
m_searchBox->m_lineEdit->setText(text + QString("tag:\"%1\" ").arg(tag));
}
void updateStuff()
{
if (m_isExamples) {
m_qtVersionSelector->clear();
m_qtVersionSelector->addItems(m_examplesModel->exampleSets());
m_qtVersionSelector->setCurrentIndex(m_examplesModel->selectedExampleSet());
}
QString text = m_searcher->text();
m_searcher->setText(text + QString("tag:\"%1\" ").arg(tag));
}
const bool m_isExamples;
ExampleDelegate m_exampleDelegate;
QPointer<ExamplesListModel> m_examplesModel;
ExamplesListModelFilter *m_filteredModel;
SearchBox *m_searchBox;
QComboBox *m_qtVersionSelector = nullptr;
GridView *m_gridView;
QLineEdit *m_searcher;
GridProxyModel m_gridModel;
};
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment