forked from qt-creator/qt-creator
QtSupport: Load examples / tutorials only when visible
This speeds up QtCreator startup a bit by not loading the examples all the time, but only when the user clicks on the "Examples" button. Change-Id: I8fb3656e871cf3f2f884c5eb12270eba427cd999 Reviewed-by: Eike Ziller <eike.ziller@qt.io> Reviewed-by: Cristian Adam <cristian.adam@qt.io>
This commit is contained in:
committed by
Eike Ziller
parent
e6a1d6685e
commit
edee2afe11
@@ -342,6 +342,12 @@ Q_GLOBAL_STATIC_WITH_ARGS(QStringList,
|
||||
|
||||
void ExamplesViewController::updateExamples()
|
||||
{
|
||||
if (!isVisible()) {
|
||||
m_needsUpdateExamples = true;
|
||||
return;
|
||||
}
|
||||
m_needsUpdateExamples = false;
|
||||
|
||||
QString examplesInstallPath;
|
||||
QString demosInstallPath;
|
||||
QVersionNumber qtVersion;
|
||||
@@ -395,6 +401,20 @@ void ExamplesViewController::updateExamples()
|
||||
}
|
||||
}
|
||||
|
||||
void ExamplesViewController::setVisible(bool visible)
|
||||
{
|
||||
if (m_isVisible == visible)
|
||||
return;
|
||||
m_isVisible = visible;
|
||||
if (m_isVisible && m_needsUpdateExamples)
|
||||
updateExamples();
|
||||
}
|
||||
|
||||
bool ExamplesViewController::isVisible() const
|
||||
{
|
||||
return m_isVisible;
|
||||
}
|
||||
|
||||
void ExampleSetModel::updateQtVersionList()
|
||||
{
|
||||
QtVersions versions = QtVersionManager::sortVersions(QtVersionManager::versions(
|
||||
|
||||
@@ -92,11 +92,15 @@ public:
|
||||
QObject *parent);
|
||||
|
||||
void updateExamples();
|
||||
void setVisible(bool isVisible);
|
||||
bool isVisible() const;
|
||||
|
||||
private:
|
||||
ExampleSetModel *m_exampleSetModel;
|
||||
Core::SectionedGridView *m_view;
|
||||
bool m_isExamples;
|
||||
bool m_isVisible = false;
|
||||
bool m_needsUpdateExamples = false;
|
||||
};
|
||||
|
||||
} // namespace Internal
|
||||
|
||||
@@ -304,7 +304,7 @@ public:
|
||||
grid->addWidget(WelcomePageHelpers::panelBar(this), 0, 2);
|
||||
|
||||
auto gridView = new SectionedGridView(this);
|
||||
new ExamplesViewController(s_exampleSetModel, gridView, isExamples, this);
|
||||
m_viewController = new ExamplesViewController(s_exampleSetModel, gridView, isExamples, this);
|
||||
|
||||
gridView->setItemDelegate(&m_exampleDelegate);
|
||||
grid->addWidget(gridView, 1, 1, 1, 2);
|
||||
@@ -321,9 +321,22 @@ public:
|
||||
+ QString("tag:\"%1\" ").arg(tag));
|
||||
}
|
||||
|
||||
void showEvent(QShowEvent *event) override
|
||||
{
|
||||
m_viewController->setVisible(true);
|
||||
QWidget::showEvent(event);
|
||||
}
|
||||
|
||||
void hideEvent(QHideEvent *event) override
|
||||
{
|
||||
m_viewController->setVisible(false);
|
||||
QWidget::hideEvent(event);
|
||||
}
|
||||
|
||||
const bool m_isExamples;
|
||||
ExampleDelegate m_exampleDelegate;
|
||||
QLineEdit *m_searcher;
|
||||
ExamplesViewController *m_viewController = nullptr;
|
||||
};
|
||||
|
||||
QWidget *ExamplesWelcomePage::createWidget() const
|
||||
|
||||
Reference in New Issue
Block a user