From 953ec9867fd2437447161c6ebec62738450f7e9e Mon Sep 17 00:00:00 2001 From: Thomas Hartmann Date: Fri, 24 Jun 2016 15:49:26 +0200 Subject: [PATCH] QmlDesigner: Improve performance of item library If there are manu components (e.g. 200) in the same directory, the model was updated for each component. This patch compresses the signal and therefore reduced the updates. Change-Id: I80b38df59952dda7e67e258ecd6e5f29d6a036e6 Reviewed-by: Tim Jenssen --- .../components/itemlibrary/itemlibrarywidget.cpp | 13 +++++++++++-- .../components/itemlibrary/itemlibrarywidget.h | 3 +++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/plugins/qmldesigner/components/itemlibrary/itemlibrarywidget.cpp b/src/plugins/qmldesigner/components/itemlibrary/itemlibrarywidget.cpp index cb023421f95..2a292bf4c2b 100644 --- a/src/plugins/qmldesigner/components/itemlibrary/itemlibrarywidget.cpp +++ b/src/plugins/qmldesigner/components/itemlibrary/itemlibrarywidget.cpp @@ -66,6 +66,8 @@ ItemLibraryWidget::ItemLibraryWidget(QWidget *parent) : m_resourcesView(new ItemLibraryTreeView(this)), m_filterFlag(QtBasic) { + m_compressionTimer.setInterval(200); + m_compressionTimer.setSingleShot(true); ItemLibraryModel::registerQmlTypes(); setWindowTitle(tr("Library", "Title of library view")); @@ -145,6 +147,8 @@ ItemLibraryWidget::ItemLibraryWidget(QWidget *parent) : m_qmlSourceUpdateShortcut = new QShortcut(QKeySequence(Qt::CTRL + Qt::Key_F5), this); connect(m_qmlSourceUpdateShortcut, SIGNAL(activated()), this, SLOT(reloadQmlSource())); + connect(&m_compressionTimer, SIGNAL(timeout()), this, SLOT(updateModel())); + // init the first load of the QML UI elements reloadQmlSource(); } @@ -156,11 +160,11 @@ void ItemLibraryWidget::setItemLibraryInfo(ItemLibraryInfo *itemLibraryInfo) if (m_itemLibraryInfo) disconnect(m_itemLibraryInfo.data(), SIGNAL(entriesChanged()), - this, SLOT(updateModel())); + this, SLOT(delayedUpdateModel())); m_itemLibraryInfo = itemLibraryInfo; if (itemLibraryInfo) connect(m_itemLibraryInfo.data(), SIGNAL(entriesChanged()), - this, SLOT(updateModel())); + this, SLOT(delayedUpdateModel())); updateModel(); } @@ -209,6 +213,11 @@ void ItemLibraryWidget::setSearchFilter(const QString &searchFilter) } } +void ItemLibraryWidget::delayedUpdateModel() +{ + m_compressionTimer.start(); +} + void ItemLibraryWidget::setModel(Model *model) { m_model = model; diff --git a/src/plugins/qmldesigner/components/itemlibrary/itemlibrarywidget.h b/src/plugins/qmldesigner/components/itemlibrary/itemlibrarywidget.h index 3d4bc503e25..df0a1e9b909 100644 --- a/src/plugins/qmldesigner/components/itemlibrary/itemlibrarywidget.h +++ b/src/plugins/qmldesigner/components/itemlibrary/itemlibrarywidget.h @@ -34,6 +34,7 @@ #include #include #include +#include QT_BEGIN_NAMESPACE class QFileSystemModel; @@ -86,6 +87,7 @@ public: static QString qmlSourcesPath(); public slots: void setSearchFilter(const QString &searchFilter); + void delayedUpdateModel(); void updateModel(); void updateSearch(); @@ -107,6 +109,7 @@ private slots: void reloadQmlSource(); private: + QTimer m_compressionTimer; QSize m_itemIconSize; QSize m_resIconSize; ItemLibraryFileIconProvider m_iconProvider;