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

This commit is contained in:
Uwe Kindler 2018-11-01 08:52:14 +01:00
parent 5e6c82b68d
commit 3f5697554a
4 changed files with 31 additions and 18 deletions

View File

@ -451,13 +451,20 @@ CDockWidget* CDockAreaWidget::currentDockWidget() const
//============================================================================
void CDockAreaWidget::setCurrentDockWidget(CDockWidget* DockWidget)
{
int Index = index(DockWidget);
if (Index < 0)
if (dockManager()->isRestoringState())
{
return;
}
if (dockManager()->isRestoringState())
internalSetCurrentDockWidget(DockWidget);
}
//============================================================================
void CDockAreaWidget::internalSetCurrentDockWidget(CDockWidget* DockWidget)
{
int Index = index(DockWidget);
if (Index < 0)
{
return;
}
@ -607,9 +614,9 @@ void CDockAreaWidget::saveState(QXmlStreamWriter& s) const
{
s.writeStartElement("DockAreaWidget");
s.writeAttribute("Tabs", QString::number(d->ContentsLayout->count()));
s.writeAttribute("CurrentIndex", QString::number(d->ContentsLayout->currentIndex()));
s.writeAttribute("CurrentDockWidget", currentDockWidget()->objectName());
qDebug() << "CDockAreaWidget::saveState TabCount: " << d->ContentsLayout->count()
<< " CurrentIndex: " << d->ContentsLayout->currentIndex();
<< " CurrentDockWidge: " << currentDockWidget()->objectName();
for (int i = 0; i < d->ContentsLayout->count(); ++i)
{
dockWidget(i)->saveState(s);

View File

@ -61,6 +61,7 @@ private:
friend class CDockWidgetTab;
friend struct DockWidgetPrivate;
friend class CDockWidget;
friend struct DockManagerPrivate;
private slots:
void onTabCloseRequested(int Index);
@ -121,6 +122,13 @@ protected:
*/
void updateTabBarVisibility();
/**
* This is the internal private function for setting the current widget.
* This function is called by the public setCurrentDockWidget() function
* and by the dock manager when restoring the state
*/
void internalSetCurrentDockWidget(CDockWidget* DockWidget);
public:
using Super = QFrame;

View File

@ -526,13 +526,14 @@ bool DockContainerWidgetPrivate::restoreDockArea(QXmlStreamReader& s,
return false;
}
int CurrentIndex = s.attributes().value("CurrentIndex").toInt(&Ok);
if (!Ok)
QString CurrentDockWidget = s.attributes().value("CurrentDockWidget").toString();
if (CurrentDockWidget.isEmpty())
{
return false;
}
qDebug() << "Restore NodeDockArea Tabs: " << Tabs << " CurrentIndex: "
<< CurrentIndex;
qDebug() << "Restore NodeDockArea Tabs: " << Tabs << " CurrentDockWidget: "
<< CurrentDockWidget;
CDockAreaWidget* DockArea = nullptr;
if (!Testing)
@ -590,7 +591,7 @@ bool DockContainerWidgetPrivate::restoreDockArea(QXmlStreamReader& s,
}
else
{
DockArea->setProperty("currentIndex", CurrentIndex);
DockArea->setProperty("currentDockWidget", CurrentDockWidget);
DockAreas.append(DockArea);
}

View File

@ -269,15 +269,12 @@ bool DockManagerPrivate::restoreState(const QByteArray &state, int version)
for (int i = 0; i < DockContainer->dockAreaCount(); ++i)
{
CDockAreaWidget* DockArea = DockContainer->dockArea(i);
int CurrentIndex = DockArea->property("currentIndex").toInt();
int DockWidgetCount = DockArea->dockWidgetsCount();
if (CurrentIndex < DockWidgetCount && DockWidgetCount > 1 && CurrentIndex > -1)
QString DockWidgetName = DockArea->property("currentDockWidget").toString();
CDockWidget* DockWidget = _this->findDockWidget(DockWidgetName);
std::cout << "restore DockWIdgetName " << DockWidget->objectName().toStdString() << std::endl;
if (!DockWidget->isClosed())
{
auto DockWidget = DockArea->dockWidget(CurrentIndex);
if (!DockWidget->isClosed())
{
DockArea->setCurrentIndex(CurrentIndex);
}
DockArea->internalSetCurrentDockWidget(DockWidget);
}
}
}