Introduce main window affinity
By default a dock widget can dock into any main window. With affinities, we can now have a dock widget "belong" to a main window and only be able to dock into it (or into other floating dock widgets with the same affinity). See DockWidgetBase::setAffinity() and MainWindowBase::setAffinity().
This commit is contained in:
@@ -99,6 +99,7 @@ public:
|
||||
void saveTabIndex();
|
||||
|
||||
const QString name;
|
||||
QString affinityName;
|
||||
QString title;
|
||||
QIcon icon;
|
||||
QWidget *widget = nullptr;
|
||||
@@ -143,6 +144,12 @@ void DockWidgetBase::addDockWidgetAsTab(DockWidgetBase *other)
|
||||
return;
|
||||
}
|
||||
|
||||
if (other->affinityName() != affinityName()) {
|
||||
qWarning() << Q_FUNC_INFO << "Refusing to dock widget with incompatible affinity."
|
||||
<< other->affinityName() << affinityName();
|
||||
return;
|
||||
}
|
||||
|
||||
Frame *frame = this->frame();
|
||||
|
||||
if (frame) {
|
||||
@@ -171,6 +178,12 @@ void DockWidgetBase::addDockWidgetToContainingWindow(DockWidgetBase *other, Loca
|
||||
return;
|
||||
}
|
||||
|
||||
if (other->affinityName() != affinityName()) {
|
||||
qWarning() << Q_FUNC_INFO << "Refusing to dock widget with incompatible affinity."
|
||||
<< other->affinityName() << affinityName();
|
||||
return;
|
||||
}
|
||||
|
||||
if (isWindow())
|
||||
morphIntoFloatingWindow();
|
||||
|
||||
@@ -325,6 +338,26 @@ bool DockWidgetBase::isOpen() const
|
||||
return d->toggleAction->isChecked();
|
||||
}
|
||||
|
||||
QString DockWidgetBase::affinityName() const
|
||||
{
|
||||
return d->affinityName;
|
||||
}
|
||||
|
||||
void DockWidgetBase::setAffinityName(const QString &name)
|
||||
{
|
||||
if (d->affinityName == name)
|
||||
return;
|
||||
|
||||
if (!d->affinityName.isEmpty()) {
|
||||
qWarning() << Q_FUNC_INFO
|
||||
<< "Affinity is already set, refusing to change."
|
||||
<< "Submit a feature request with a good justification.";
|
||||
return;
|
||||
}
|
||||
|
||||
d->affinityName = name;
|
||||
}
|
||||
|
||||
FloatingWindow *DockWidgetBase::morphIntoFloatingWindow()
|
||||
{
|
||||
qCDebug(creation) << "DockWidget::morphIntoFloatingWindow() this=" << this
|
||||
|
||||
Reference in New Issue
Block a user