18#include "Position_p.h"
19#include "LayoutSaver_p.h"
21#include "ScopedValueRollback_p.h"
22#include "core/layouting/Item_p.h"
23#include "core/layouting/LayoutingHost_p.h"
24#include "kddockwidgets/core/FloatingWindow.h"
25#include "kddockwidgets/core/Layout.h"
26#include "kddockwidgets/core/MainWindow.h"
27#include "kddockwidgets/core/DockRegistry.h"
36 m_placeholders.clear();
39void Position::addPlaceholderItem(Core::Item *placeholder)
44 if (containsPlaceholder(placeholder))
54 removeNonMainWindowPlaceholders();
59 auto conn = placeholder->deleted.connect([
this, placeholder] { removePlaceholder(placeholder); });
61 m_placeholders.push_back(std::make_unique<ItemRef>(conn, placeholder));
70Core::Item *Position::layoutItem()
const
75 for (
const auto &itemref : m_placeholders) {
76 if (itemref->isInMainWindow())
83bool Position::containsPlaceholder(Core::Item *item)
const
85 for (
const auto &itemRef : m_placeholders)
86 if (itemRef->item == item)
92void Position::removePlaceholders()
94 ScopedValueRollback clearGuard(m_clearing,
true);
95 m_placeholders.clear();
98void Position::removePlaceholders(
const Core::LayoutingHost *host)
100 m_placeholders.erase(std::remove_if(m_placeholders.begin(), m_placeholders.end(),
101 [host](
const std::unique_ptr<ItemRef> &itemref) {
104 return host == itemref->item->host();
106 m_placeholders.end());
109void Position::removeNonMainWindowPlaceholders()
111 auto it = m_placeholders.begin();
112 while (it != m_placeholders.end()) {
113 ItemRef *itemref = it->get();
114 if (!itemref->isInMainWindow())
115 it = m_placeholders.erase(it);
121void Position::removePlaceholder(Core::Item *placeholder)
126 m_placeholders.erase(std::remove_if(m_placeholders.begin(), m_placeholders.end(),
127 [placeholder](
const std::unique_ptr<ItemRef> &itemref) {
128 return itemref->item == placeholder || !itemref->item;
130 m_placeholders.end());
133void Position::deserialize(
const LayoutSaver::Position &lp)
135 m_lastFloatingGeometry = lp.lastFloatingGeometry;
136 m_lastOverlayedGeometries = lp.lastOverlayedGeometries;
138 for (
const auto &placeholder :
std::as_const(lp.placeholders)) {
140 int itemIndex = placeholder.itemIndex;
141 if (placeholder.isFloatingWindow) {
142 const int index = placeholder.indexOfFloatingWindow;
146 assert(LayoutSaver::Layout::s_currentLayoutBeingRestored);
148 LayoutSaver::Layout::s_currentLayoutBeingRestored->floatingWindowForIndex(
150 if (serializedFw.isValid()) {
151 if (
auto fw = serializedFw.floatingWindowInstance) {
152 layout = fw->layout();
157 KDDW_ERROR(
"Invalid floating window position to restore. index={}", index);
164 layout = mainWindow->
layout();
167 const Core::Item::List &items = layout->
items();
168 if (itemIndex >= 0 && itemIndex < items.size()) {
169 Core::Item *item = items.at(itemIndex);
170 addPlaceholderItem(item);
173 KDDW_ERROR(
"Couldn't find item index {}", itemIndex);
177 m_tabIndex = lp.tabIndex;
178 m_wasFloating = lp.wasFloating;
181LayoutSaver::Position Position::serialize()
const
183 LayoutSaver::Position l;
185 for (
auto &itemRef : m_placeholders) {
186 LayoutSaver::Placeholder p;
188 Core::Item *item = itemRef->item;
190 const auto itemIndex = layout->
items().indexOf(item);
194 assert(mainWindow || fw);
195 p.isFloatingWindow = fw;
197 if (p.isFloatingWindow) {
198 p.indexOfFloatingWindow = fw->beingDeleted()
203 p.mainWindowUniqueName = mainWindow->
uniqueName();
204 assert(!p.mainWindowUniqueName.isEmpty());
207 p.itemIndex = itemIndex;
208 l.placeholders.push_back(p);
211 l.tabIndex = m_tabIndex;
212 l.wasFloating = m_wasFloating;
214 l.lastFloatingGeometry = lastFloatingGeometry();
215 l.lastOverlayedGeometries = m_lastOverlayedGeometries;
222 , connection(
std::move(conn))
229 if (item && !item->m_inDtor) {
230 connection.disconnect();
235bool ItemRef::isInMainWindow()
const
A ConnectionHandle represents the connection of a Signal to a slot (i.e. a function that is called wh...
The MainWindow base-class. MainWindow and MainWindowBase are only split in two so we can share some c...
QString uniqueName() const
Returns the unique name that was passed via constructor. Used internally by the save/restore mechanis...