Skip to content

Commit 3f56975

Browse files
author
Uwe Kindler
committed
Changed store and restore functioality to save the current dock widget name of an dock area instead of the current index because if some dock widgets are missing when loading the configuration, the dock index might be wrong
1 parent 5e6c82b commit 3f56975

File tree

4 files changed

+31
-18
lines changed

4 files changed

+31
-18
lines changed

src/DockAreaWidget.cpp

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -451,13 +451,20 @@ CDockWidget* CDockAreaWidget::currentDockWidget() const
451451
//============================================================================
452452
void CDockAreaWidget::setCurrentDockWidget(CDockWidget* DockWidget)
453453
{
454-
int Index = index(DockWidget);
455-
if (Index < 0)
454+
if (dockManager()->isRestoringState())
456455
{
457456
return;
458457
}
459458

460-
if (dockManager()->isRestoringState())
459+
internalSetCurrentDockWidget(DockWidget);
460+
}
461+
462+
463+
//============================================================================
464+
void CDockAreaWidget::internalSetCurrentDockWidget(CDockWidget* DockWidget)
465+
{
466+
int Index = index(DockWidget);
467+
if (Index < 0)
461468
{
462469
return;
463470
}
@@ -607,9 +614,9 @@ void CDockAreaWidget::saveState(QXmlStreamWriter& s) const
607614
{
608615
s.writeStartElement("DockAreaWidget");
609616
s.writeAttribute("Tabs", QString::number(d->ContentsLayout->count()));
610-
s.writeAttribute("CurrentIndex", QString::number(d->ContentsLayout->currentIndex()));
617+
s.writeAttribute("CurrentDockWidget", currentDockWidget()->objectName());
611618
qDebug() << "CDockAreaWidget::saveState TabCount: " << d->ContentsLayout->count()
612-
<< " CurrentIndex: " << d->ContentsLayout->currentIndex();
619+
<< " CurrentDockWidge: " << currentDockWidget()->objectName();
613620
for (int i = 0; i < d->ContentsLayout->count(); ++i)
614621
{
615622
dockWidget(i)->saveState(s);

src/DockAreaWidget.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ class ADS_EXPORT CDockAreaWidget : public QFrame
6161
friend class CDockWidgetTab;
6262
friend struct DockWidgetPrivate;
6363
friend class CDockWidget;
64+
friend struct DockManagerPrivate;
6465

6566
private slots:
6667
void onTabCloseRequested(int Index);
@@ -121,6 +122,13 @@ private slots:
121122
*/
122123
void updateTabBarVisibility();
123124

125+
/**
126+
* This is the internal private function for setting the current widget.
127+
* This function is called by the public setCurrentDockWidget() function
128+
* and by the dock manager when restoring the state
129+
*/
130+
void internalSetCurrentDockWidget(CDockWidget* DockWidget);
131+
124132
public:
125133
using Super = QFrame;
126134

src/DockContainerWidget.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -526,13 +526,14 @@ bool DockContainerWidgetPrivate::restoreDockArea(QXmlStreamReader& s,
526526
return false;
527527
}
528528

529-
int CurrentIndex = s.attributes().value("CurrentIndex").toInt(&Ok);
530-
if (!Ok)
529+
530+
QString CurrentDockWidget = s.attributes().value("CurrentDockWidget").toString();
531+
if (CurrentDockWidget.isEmpty())
531532
{
532533
return false;
533534
}
534-
qDebug() << "Restore NodeDockArea Tabs: " << Tabs << " CurrentIndex: "
535-
<< CurrentIndex;
535+
qDebug() << "Restore NodeDockArea Tabs: " << Tabs << " CurrentDockWidget: "
536+
<< CurrentDockWidget;
536537

537538
CDockAreaWidget* DockArea = nullptr;
538539
if (!Testing)
@@ -590,7 +591,7 @@ bool DockContainerWidgetPrivate::restoreDockArea(QXmlStreamReader& s,
590591
}
591592
else
592593
{
593-
DockArea->setProperty("currentIndex", CurrentIndex);
594+
DockArea->setProperty("currentDockWidget", CurrentDockWidget);
594595
DockAreas.append(DockArea);
595596
}
596597

src/DockManager.cpp

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -269,15 +269,12 @@ bool DockManagerPrivate::restoreState(const QByteArray &state, int version)
269269
for (int i = 0; i < DockContainer->dockAreaCount(); ++i)
270270
{
271271
CDockAreaWidget* DockArea = DockContainer->dockArea(i);
272-
int CurrentIndex = DockArea->property("currentIndex").toInt();
273-
int DockWidgetCount = DockArea->dockWidgetsCount();
274-
if (CurrentIndex < DockWidgetCount && DockWidgetCount > 1 && CurrentIndex > -1)
272+
QString DockWidgetName = DockArea->property("currentDockWidget").toString();
273+
CDockWidget* DockWidget = _this->findDockWidget(DockWidgetName);
274+
std::cout << "restore DockWIdgetName " << DockWidget->objectName().toStdString() << std::endl;
275+
if (!DockWidget->isClosed())
275276
{
276-
auto DockWidget = DockArea->dockWidget(CurrentIndex);
277-
if (!DockWidget->isClosed())
278-
{
279-
DockArea->setCurrentIndex(CurrentIndex);
280-
}
277+
DockArea->internalSetCurrentDockWidget(DockWidget);
281278
}
282279
}
283280
}

0 commit comments

Comments
 (0)