Fixed double emission of focusedDockWidgetChanged() signal

This commit is contained in:
Uwe Kindler 2020-07-07 14:38:03 +02:00
parent 8cf4134125
commit 9974256d71
3 changed files with 30 additions and 7 deletions

View File

@ -14,7 +14,8 @@ int main(int argc, char *argv[])
ads::CDockManager::setConfigFlag(ads::CDockManager::AllTabsHaveCloseButton, true);
auto dockManager = new ads::CDockManager(&w);
QObject::connect(dockManager, &ads::CDockManager::focusedDockWidgetChanged, [] (ads::CDockWidget* old, ads::CDockWidget* now) {
qDebug() << "CDockManager::focusedDockWidgetChanged: " << now->objectName() << " visible: " << now->isVisible();
static int Count = 0;
qDebug() << Count++ << " CDockManager::focusedDockWidgetChanged old: " << (old ? old->objectName() : "-") << " now: " << now->objectName() << " visible: " << now->isVisible();
now->widget()->setFocus();
});

View File

@ -447,7 +447,8 @@ void CDockAreaWidget::insertDockWidget(int index, CDockWidget* DockWidget,
void CDockAreaWidget::removeDockWidget(CDockWidget* DockWidget)
{
ADS_PRINT("CDockAreaWidget::removeDockWidget");
auto NextOpenDockWidget = nextOpenDockWidget(DockWidget);
auto CurrentDockWidget = currentDockWidget();
auto NextOpenDockWidget = (DockWidget == CurrentDockWidget) ? nextOpenDockWidget(DockWidget) : nullptr;
d->ContentsLayout->removeWidget(DockWidget);
auto TabWidget = DockWidget->tabWidget();
@ -466,7 +467,7 @@ void CDockAreaWidget::removeDockWidget(CDockWidget* DockWidget)
DockContainer->removeDockArea(this);
this->deleteLater();
}
else
else if (DockWidget == CurrentDockWidget)
{
// if contents layout is not empty but there are no more open dock
// widgets, then we need to hide the dock area because it does not

View File

@ -160,6 +160,11 @@ void DockFocusControllerPrivate::updateDockWidgetFocus(CDockWidget* DockWidget)
}
#endif
if (old == DockWidget)
{
return;
}
if (DockWidget->isVisible())
{
emit DockManager->focusedDockWidgetChanged(old, DockWidget);
@ -212,6 +217,8 @@ void CDockFocusController::onApplicationFocusChanged(QWidget* focusedOld, QWidge
return;
}
//qDebug() << "\n----------------------------";
//qDebug() << "CDockFocusController::onApplicationFocusChanged " << " old: " << focusedOld << " new: " << focusedNow;
Q_UNUSED(focusedOld)
if (!focusedNow)
{
@ -223,6 +230,14 @@ void CDockFocusController::onApplicationFocusChanged(QWidget* focusedOld, QWidge
if (DockWidgetTab)
{
DockWidget = DockWidgetTab->dockWidget();
// If the DockWidgetTab "steals" the focus from a widget in the same
// DockWidget, then we immediately give the focus back to the previous
// focused widget focusedOld
if (DockWidget == d->FocusedDockWidget && focusedOld && focusedOld != focusedNow)
{
focusedOld->setFocus();
return;
}
}
if (!DockWidget)
@ -278,7 +293,8 @@ void CDockFocusController::onFocusedDockAreaViewToggled(bool Open)
return;
}
CDockManager::setWidgetFocus(OpenedDockAreas[0]->currentDockWidget()->tabWidget());
//CDockManager::setWidgetFocus(OpenedDockAreas[0]->currentDockWidget()->tabWidget());
d->updateDockWidgetFocus(OpenedDockAreas[0]->currentDockWidget());
}
@ -293,7 +309,8 @@ void CDockFocusController::notifyWidgetOrAreaRelocation(QWidget* DroppedWidget)
CDockWidget* DockWidget = qobject_cast<CDockWidget*>(DroppedWidget);
if (DockWidget)
{
CDockManager::setWidgetFocus(DockWidget->tabWidget());
//CDockManager::setWidgetFocus(DockWidget->tabWidget());
d->updateDockWidgetFocus(DockWidget);
return;
}
@ -304,7 +321,8 @@ void CDockFocusController::notifyWidgetOrAreaRelocation(QWidget* DroppedWidget)
}
DockWidget = DockArea->currentDockWidget();
CDockManager::setWidgetFocus(DockWidget->tabWidget());
//CDockManager::setWidgetFocus(DockWidget->tabWidget());
d->updateDockWidgetFocus(DockWidget);
}
@ -325,8 +343,11 @@ void CDockFocusController::notifyFloatingWidgetDrop(CFloatingDockContainer* Floa
auto DockWidget = vDockWidget.value<CDockWidget*>();
if (DockWidget)
{
d->FocusedDockWidget = nullptr;
DockWidget->dockAreaWidget()->setCurrentDockWidget(DockWidget);
CDockManager::setWidgetFocus(DockWidget->tabWidget());
//CDockManager::setWidgetFocus(DockWidget->tabWidget());
//qDebug() << "CDockFocusController::notifyFloatingWidgetDrop";
d->updateDockWidgetFocus(DockWidget);
}
}