Reduce the number of times syncToMainItemSize is called in Dialog

syncToMainItemSize is rather expensive and gets called a lot in item
initalisation as various properties get set.
This commit is contained in:
David Edmundson 2014-01-29 18:48:59 +01:00
parent 9de921e34d
commit 60e0754f90
2 changed files with 16 additions and 18 deletions

View File

@ -61,8 +61,8 @@ DialogProxy::DialogProxy(QQuickItem *parent)
m_syncTimer->setInterval(0); m_syncTimer->setInterval(0);
connect(m_syncTimer, &QTimer::timeout, this, &DialogProxy::syncToMainItemSize); connect(m_syncTimer, &QTimer::timeout, this, &DialogProxy::syncToMainItemSize);
connect(this, &QWindow::xChanged, [=](){m_syncTimer->start(150);}); connect(this, &QWindow::xChanged, [=](){requestSyncToMainItemSize(true);});
connect(this, &QWindow::yChanged, [=](){m_syncTimer->start(150);}); connect(this, &QWindow::yChanged, [=](){requestSyncToMainItemSize(true);});
connect(this, &QWindow::visibleChanged, this, &DialogProxy::updateInputShape); connect(this, &QWindow::visibleChanged, this, &DialogProxy::updateInputShape);
connect(this, &DialogProxy::outputOnlyChanged, this, &DialogProxy::updateInputShape); connect(this, &DialogProxy::outputOnlyChanged, this, &DialogProxy::updateInputShape);
// connect(this, &QWindow::visibleChanged, this, &DialogProxy::onVisibleChanged); // connect(this, &QWindow::visibleChanged, this, &DialogProxy::onVisibleChanged);
@ -103,12 +103,7 @@ void DialogProxy::setMainItem(QQuickItem *mainItem)
if (mainItem->metaObject()->indexOfSignal("heightChanged")) { if (mainItem->metaObject()->indexOfSignal("heightChanged")) {
connect(mainItem, &QQuickItem::heightChanged, [=](){m_syncTimer->start(0);}); connect(mainItem, &QQuickItem::heightChanged, [=](){m_syncTimer->start(0);});
} }
if (isVisible()) { requestSyncToMainItemSize();
m_syncTimer->start(0);
} else {
m_syncTimer->stop();
syncToMainItemSize();
}
} }
//if this is called in Component.onCompleted we have to wait a loop the item is added to a scene //if this is called in Component.onCompleted we have to wait a loop the item is added to a scene
@ -130,12 +125,7 @@ void DialogProxy::setVisualParent(QQuickItem *visualParent)
m_visualParent = visualParent; m_visualParent = visualParent;
emit visualParentChanged(); emit visualParentChanged();
if (visualParent) { if (visualParent) {
if (isVisible()) { requestSyncToMainItemSize();
m_syncTimer->start(0);
} else {
m_syncTimer->stop();
syncToMainItemSize();
}
} }
} }
@ -157,8 +147,6 @@ void DialogProxy::updateVisibility(bool visible)
syncMainItemToSize(); syncMainItemToSize();
m_cachedGeometry = QRect(); m_cachedGeometry = QRect();
} }
m_syncTimer->stop();
syncToMainItemSize(); syncToMainItemSize();
} }
} }
@ -368,6 +356,9 @@ void DialogProxy::syncMainItemToSize()
void DialogProxy::syncToMainItemSize() void DialogProxy::syncToMainItemSize()
{ {
//if manually sync a sync timer was running cancel it so we don't get called twice
m_syncTimer->stop();
if (!m_mainItem) { if (!m_mainItem) {
return; return;
} }
@ -385,10 +376,16 @@ void DialogProxy::syncToMainItemSize()
} else { } else {
resize(s); resize(s);
} }
} }
void DialogProxy::requestSyncToMainItemSize(bool delayed)
{
if (delayed && !m_syncTimer->isActive()) {
m_syncTimer->start(150);
} else {
m_syncTimer->start(0);
}
}
void DialogProxy::setType(WindowType type) void DialogProxy::setType(WindowType type)
{ {

View File

@ -150,6 +150,7 @@ Q_SIGNALS:
public Q_SLOTS: public Q_SLOTS:
void syncMainItemToSize(); void syncMainItemToSize();
void syncToMainItemSize(); void syncToMainItemSize();
void requestSyncToMainItemSize(bool delayed = false);
protected: protected:
// bool eventFilter(QObject *watched, QEvent *event); // bool eventFilter(QObject *watched, QEvent *event);