18 #include "Position_p.h"
19 #include "DockRegistry_p.h"
20 #include "FloatingWindow_p.h"
21 #include "LayoutSaver_p.h"
22 #include "LayoutWidget_p.h"
30 m_placeholders.clear();
33 void Position::addPlaceholderItem(Layouting::Item *placeholder)
35 Q_ASSERT(placeholder);
38 if (containsPlaceholder(placeholder))
41 if (DockRegistry::self()->itemIsInMainWindow(placeholder)) {
47 removeNonMainWindowPlaceholders();
52 removePlaceholder(placeholder);
55 m_placeholders.push_back(std::unique_ptr<ItemRef>(
new ItemRef(connection, placeholder)));
63 Layouting::Item *Position::layoutItem()
const
68 for (
const auto &itemref : m_placeholders) {
69 if (DockRegistry::self()->itemIsInMainWindow(itemref->item))
76 bool Position::containsPlaceholder(Layouting::Item *item)
const
78 for (
const auto &itemRef : m_placeholders)
79 if (itemRef->item == item)
85 void Position::removePlaceholders()
88 m_placeholders.clear();
91 void Position::removePlaceholders(
const LayoutWidget *ms)
93 m_placeholders.erase(std::remove_if(m_placeholders.begin(), m_placeholders.end(), [ms](
const std::unique_ptr<ItemRef> &itemref) {
94 return itemref->item->hostWidget() == *ms;
96 m_placeholders.end());
99 void Position::removeNonMainWindowPlaceholders()
101 auto it = m_placeholders.begin();
102 while (it != m_placeholders.end()) {
103 ItemRef *itemref = it->get();
104 if (!DockRegistry::self()->itemIsInMainWindow(itemref->item))
105 it = m_placeholders.erase(it);
111 void Position::removePlaceholder(Layouting::Item *placeholder)
116 m_placeholders.erase(std::remove_if(m_placeholders.begin(), m_placeholders.end(), [placeholder](
const std::unique_ptr<ItemRef> &itemref) {
117 return itemref->item == placeholder;
119 m_placeholders.end());
122 void Position::deserialize(
const LayoutSaver::Position &lp)
124 for (
const auto &placeholder : qAsConst(lp.placeholders)) {
125 LayoutWidget *layout;
126 int itemIndex = placeholder.itemIndex;
127 if (placeholder.isFloatingWindow) {
128 const int index = placeholder.indexOfFloatingWindow;
132 auto serializedFw = LayoutSaver::Layout::s_currentLayoutBeingRestored->floatingWindowForIndex(index);
133 if (serializedFw.isValid()) {
134 if (FloatingWindow *fw = serializedFw.floatingWindowInstance) {
135 layout = fw->layoutWidget();
140 qWarning() <<
"Invalid floating window position to restore" << index;
145 MainWindowBase *mainWindow = DockRegistry::self()->mainWindowByName(placeholder.mainWindowUniqueName);
149 const Layouting::Item::List &items = layout->items();
150 if (itemIndex >= 0 && itemIndex < items.size()) {
151 Layouting::Item *item = items.at(itemIndex);
152 addPlaceholderItem(item);
155 qWarning() << Q_FUNC_INFO <<
"Couldn't find item index" << itemIndex <<
"in" << items;
159 m_tabIndex = lp.tabIndex;
160 m_wasFloating = lp.wasFloating;
163 LayoutSaver::Position Position::serialize()
const
165 LayoutSaver::Position l;
167 for (
auto &itemRef : m_placeholders) {
168 LayoutSaver::Placeholder p;
170 Layouting::Item *item = itemRef->item;
171 LayoutWidget *layout = DockRegistry::self()->layoutForItem(item);
172 const auto itemIndex = layout->items().indexOf(item);
174 auto fw = layout->floatingWindow();
175 auto mainWindow = layout->mainWindow();
176 Q_ASSERT(mainWindow || fw);
177 p.isFloatingWindow = fw;
179 if (p.isFloatingWindow) {
180 p.indexOfFloatingWindow = fw->beingDeleted() ? -1 : DockRegistry::self()->floatingWindows().indexOf(fw);
182 p.mainWindowUniqueName = mainWindow->
uniqueName();
183 Q_ASSERT(!p.mainWindowUniqueName.isEmpty());
186 p.itemIndex = itemIndex;
187 l.placeholders.push_back(p);
190 l.tabIndex = m_tabIndex;
191 l.wasFloating = m_wasFloating;
212 LayoutSaver::Position LastPositions::serialize()
214 LayoutSaver::Position result = lastPosition->serialize();
215 result.lastFloatingGeometry = lastFloatingGeometry();
216 result.lastOverlayedGeometries = m_lastOverlayedGeometries;
220 void LastPositions::deserialize(
const LayoutSaver::Position &p)
222 m_lastFloatingGeometry = p.lastFloatingGeometry;
223 m_lastOverlayedGeometries = p.lastOverlayedGeometries;
224 lastPosition->deserialize(p);