Skip to content

Commit d034722

Browse files
committed
LayoutSaver: Add some utilities
1 parent e1e07c9 commit d034722

File tree

2 files changed

+48
-0
lines changed

2 files changed

+48
-0
lines changed

src/LayoutSaver.cpp

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -528,6 +528,19 @@ bool LayoutSaver::Frame::isValid() const
528528
return true;
529529
}
530530

531+
bool LayoutSaver::Frame::hasSingleDockWidget() const
532+
{
533+
return dockWidgets.size() == 1;
534+
}
535+
536+
LayoutSaver::DockWidget::Ptr LayoutSaver::Frame::singleDockWidget() const
537+
{
538+
if (!hasSingleDockWidget())
539+
return {};
540+
541+
return dockWidgets.first();
542+
}
543+
531544
void LayoutSaver::Frame::scaleSizes(const ScalingInfo &scalingInfo)
532545
{
533546
scalingInfo.applyFactorsTo(geometry);
@@ -621,6 +634,16 @@ bool LayoutSaver::FloatingWindow::isValid() const
621634
return true;
622635
}
623636

637+
bool LayoutSaver::FloatingWindow::hasSingleDockWidget() const
638+
{
639+
return multiSplitterLayout.hasSingleDockWidget();
640+
}
641+
642+
LayoutSaver::DockWidget::Ptr LayoutSaver::FloatingWindow::singleDockWidget() const
643+
{
644+
return multiSplitterLayout.singleDockWidget();
645+
}
646+
624647
void LayoutSaver::FloatingWindow::scaleSizes(const ScalingInfo &scalingInfo)
625648
{
626649
scalingInfo.applyFactorsTo(/*by-ref*/geometry);
@@ -747,6 +770,19 @@ bool LayoutSaver::MultiSplitter::isValid() const
747770
return true;
748771
}
749772

773+
bool LayoutSaver::MultiSplitter::hasSingleDockWidget() const
774+
{
775+
return frames.size() == 1 && frames.cbegin()->hasSingleDockWidget();
776+
}
777+
778+
LayoutSaver::DockWidget::Ptr LayoutSaver::MultiSplitter::singleDockWidget() const
779+
{
780+
if (!hasSingleDockWidget())
781+
return {};
782+
783+
return frames.cbegin()->singleDockWidget();
784+
}
785+
750786
void LayoutSaver::MultiSplitter::scaleSizes(const ScalingInfo &)
751787
{
752788
// scalingInfo.applyFactorsTo(/*by-ref*/size);

src/LayoutSaver_p.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,11 @@ struct LayoutSaver::Frame
173173
{
174174
bool isValid() const;
175175

176+
bool hasSingleDockWidget() const;
177+
178+
/// @brief in case this frame only has one frame, returns the name of that dock widget
179+
LayoutSaver::DockWidget::Ptr singleDockWidget() const;
180+
176181
/// Iterates through the layout and patches all absolute sizes. See RestoreOption_RelativeToMainWindow.
177182
void scaleSizes(const ScalingInfo &scalingInfo);
178183

@@ -192,6 +197,10 @@ struct LayoutSaver::Frame
192197
struct LayoutSaver::MultiSplitter
193198
{
194199
bool isValid() const;
200+
201+
bool hasSingleDockWidget() const;
202+
LayoutSaver::DockWidget::Ptr singleDockWidget() const;
203+
195204
/// Iterates through the layout and patches all absolute sizes. See RestoreOption_RelativeToMainWindow.
196205
void scaleSizes(const ScalingInfo &scalingInfo);
197206

@@ -208,6 +217,9 @@ struct LayoutSaver::FloatingWindow
208217

209218
bool isValid() const;
210219

220+
bool hasSingleDockWidget() const;
221+
LayoutSaver::DockWidget::Ptr singleDockWidget() const;
222+
211223
/// Iterates through the layout and patches all absolute sizes. See RestoreOption_RelativeToMainWindow.
212224
void scaleSizes(const ScalingInfo &);
213225

0 commit comments

Comments
 (0)