mirror of
https://github.com/githubuser0xFFFF/Qt-Advanced-Docking-System.git
synced 2025-01-14 00:52:05 +08:00
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:
parent
5e6c82b68d
commit
3f5697554a
@ -451,13 +451,20 @@ CDockWidget* CDockAreaWidget::currentDockWidget() const
|
|||||||
//============================================================================
|
//============================================================================
|
||||||
void CDockAreaWidget::setCurrentDockWidget(CDockWidget* DockWidget)
|
void CDockAreaWidget::setCurrentDockWidget(CDockWidget* DockWidget)
|
||||||
{
|
{
|
||||||
int Index = index(DockWidget);
|
if (dockManager()->isRestoringState())
|
||||||
if (Index < 0)
|
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (dockManager()->isRestoringState())
|
internalSetCurrentDockWidget(DockWidget);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//============================================================================
|
||||||
|
void CDockAreaWidget::internalSetCurrentDockWidget(CDockWidget* DockWidget)
|
||||||
|
{
|
||||||
|
int Index = index(DockWidget);
|
||||||
|
if (Index < 0)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -607,9 +614,9 @@ void CDockAreaWidget::saveState(QXmlStreamWriter& s) const
|
|||||||
{
|
{
|
||||||
s.writeStartElement("DockAreaWidget");
|
s.writeStartElement("DockAreaWidget");
|
||||||
s.writeAttribute("Tabs", QString::number(d->ContentsLayout->count()));
|
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()
|
qDebug() << "CDockAreaWidget::saveState TabCount: " << d->ContentsLayout->count()
|
||||||
<< " CurrentIndex: " << d->ContentsLayout->currentIndex();
|
<< " CurrentDockWidge: " << currentDockWidget()->objectName();
|
||||||
for (int i = 0; i < d->ContentsLayout->count(); ++i)
|
for (int i = 0; i < d->ContentsLayout->count(); ++i)
|
||||||
{
|
{
|
||||||
dockWidget(i)->saveState(s);
|
dockWidget(i)->saveState(s);
|
||||||
|
@ -61,6 +61,7 @@ private:
|
|||||||
friend class CDockWidgetTab;
|
friend class CDockWidgetTab;
|
||||||
friend struct DockWidgetPrivate;
|
friend struct DockWidgetPrivate;
|
||||||
friend class CDockWidget;
|
friend class CDockWidget;
|
||||||
|
friend struct DockManagerPrivate;
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void onTabCloseRequested(int Index);
|
void onTabCloseRequested(int Index);
|
||||||
@ -121,6 +122,13 @@ protected:
|
|||||||
*/
|
*/
|
||||||
void updateTabBarVisibility();
|
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:
|
public:
|
||||||
using Super = QFrame;
|
using Super = QFrame;
|
||||||
|
|
||||||
|
@ -526,13 +526,14 @@ bool DockContainerWidgetPrivate::restoreDockArea(QXmlStreamReader& s,
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
int CurrentIndex = s.attributes().value("CurrentIndex").toInt(&Ok);
|
|
||||||
if (!Ok)
|
QString CurrentDockWidget = s.attributes().value("CurrentDockWidget").toString();
|
||||||
|
if (CurrentDockWidget.isEmpty())
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
qDebug() << "Restore NodeDockArea Tabs: " << Tabs << " CurrentIndex: "
|
qDebug() << "Restore NodeDockArea Tabs: " << Tabs << " CurrentDockWidget: "
|
||||||
<< CurrentIndex;
|
<< CurrentDockWidget;
|
||||||
|
|
||||||
CDockAreaWidget* DockArea = nullptr;
|
CDockAreaWidget* DockArea = nullptr;
|
||||||
if (!Testing)
|
if (!Testing)
|
||||||
@ -590,7 +591,7 @@ bool DockContainerWidgetPrivate::restoreDockArea(QXmlStreamReader& s,
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
DockArea->setProperty("currentIndex", CurrentIndex);
|
DockArea->setProperty("currentDockWidget", CurrentDockWidget);
|
||||||
DockAreas.append(DockArea);
|
DockAreas.append(DockArea);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -269,15 +269,12 @@ bool DockManagerPrivate::restoreState(const QByteArray &state, int version)
|
|||||||
for (int i = 0; i < DockContainer->dockAreaCount(); ++i)
|
for (int i = 0; i < DockContainer->dockAreaCount(); ++i)
|
||||||
{
|
{
|
||||||
CDockAreaWidget* DockArea = DockContainer->dockArea(i);
|
CDockAreaWidget* DockArea = DockContainer->dockArea(i);
|
||||||
int CurrentIndex = DockArea->property("currentIndex").toInt();
|
QString DockWidgetName = DockArea->property("currentDockWidget").toString();
|
||||||
int DockWidgetCount = DockArea->dockWidgetsCount();
|
CDockWidget* DockWidget = _this->findDockWidget(DockWidgetName);
|
||||||
if (CurrentIndex < DockWidgetCount && DockWidgetCount > 1 && CurrentIndex > -1)
|
std::cout << "restore DockWIdgetName " << DockWidget->objectName().toStdString() << std::endl;
|
||||||
|
if (!DockWidget->isClosed())
|
||||||
{
|
{
|
||||||
auto DockWidget = DockArea->dockWidget(CurrentIndex);
|
DockArea->internalSetCurrentDockWidget(DockWidget);
|
||||||
if (!DockWidget->isClosed())
|
|
||||||
{
|
|
||||||
DockArea->setCurrentIndex(CurrentIndex);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user