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"
23 #include "multisplitter/Item_p.h"
31 m_placeholders.clear();
34 void Position::addPlaceholderItem(Layouting::Item *placeholder)
36 Q_ASSERT(placeholder);
39 if (containsPlaceholder(placeholder))
42 if (DockRegistry::self()->itemIsInMainWindow(placeholder)) {
48 removeNonMainWindowPlaceholders();
53 removePlaceholder(placeholder);
56 m_placeholders.push_back(std::unique_ptr<ItemRef>(
new ItemRef(connection, placeholder)));
64 Layouting::Item *Position::layoutItem()
const
69 for (
const auto &itemref : m_placeholders) {
70 if (itemref->isInMainWindow())
77 bool Position::containsPlaceholder(Layouting::Item *item)
const
79 for (
const auto &itemRef : m_placeholders)
80 if (itemRef->item == item)
86 void Position::removePlaceholders()
89 m_placeholders.clear();
92 void Position::removePlaceholders(
const LayoutWidget *ms)
94 m_placeholders.erase(std::remove_if(m_placeholders.begin(), m_placeholders.end(), [ms](
const std::unique_ptr<ItemRef> &itemref) {
95 return itemref->item->hostWidget() == *ms;
97 m_placeholders.end());
100 void Position::removeNonMainWindowPlaceholders()
102 auto it = m_placeholders.begin();
103 while (it != m_placeholders.end()) {
104 ItemRef *itemref = it->get();
105 if (!itemref->isInMainWindow())
106 it = m_placeholders.erase(it);
112 void Position::removePlaceholder(Layouting::Item *placeholder)
117 m_placeholders.erase(std::remove_if(m_placeholders.begin(), m_placeholders.end(), [placeholder](
const std::unique_ptr<ItemRef> &itemref) {
118 return itemref->item == placeholder;
120 m_placeholders.end());
123 void Position::deserialize(
const LayoutSaver::Position &lp)
125 m_lastFloatingGeometry = lp.lastFloatingGeometry;
126 m_lastOverlayedGeometries = lp.lastOverlayedGeometries;
128 for (
const auto &placeholder : qAsConst(lp.placeholders)) {
129 LayoutWidget *layout;
130 int itemIndex = placeholder.itemIndex;
131 if (placeholder.isFloatingWindow) {
132 const int index = placeholder.indexOfFloatingWindow;
136 auto serializedFw = LayoutSaver::Layout::s_currentLayoutBeingRestored->floatingWindowForIndex(index);
137 if (serializedFw.isValid()) {
138 if (FloatingWindow *fw = serializedFw.floatingWindowInstance) {
139 layout = fw->layoutWidget();
144 qWarning() <<
"Invalid floating window position to restore" << index;
149 MainWindowBase *mainWindow = DockRegistry::self()->mainWindowByName(placeholder.mainWindowUniqueName);
153 const Layouting::Item::List &items = layout->items();
154 if (itemIndex >= 0 && itemIndex < items.size()) {
155 Layouting::Item *item = items.at(itemIndex);
156 addPlaceholderItem(item);
159 qWarning() << Q_FUNC_INFO <<
"Couldn't find item index" << itemIndex <<
"in" << items;
163 m_tabIndex = lp.tabIndex;
164 m_wasFloating = lp.wasFloating;
167 LayoutSaver::Position Position::serialize()
const
169 LayoutSaver::Position l;
171 for (
auto &itemRef : m_placeholders) {
172 LayoutSaver::Placeholder p;
174 Layouting::Item *item = itemRef->item;
175 LayoutWidget *layout = DockRegistry::self()->layoutForItem(item);
176 const auto itemIndex = layout->items().indexOf(item);
178 auto fw = layout->floatingWindow();
179 auto mainWindow = layout->mainWindow();
180 Q_ASSERT(mainWindow || fw);
181 p.isFloatingWindow = fw;
183 if (p.isFloatingWindow) {
184 p.indexOfFloatingWindow = fw->beingDeleted() ? -1 : DockRegistry::self()->floatingWindows().indexOf(fw);
186 p.mainWindowUniqueName = mainWindow->
uniqueName();
187 Q_ASSERT(!p.mainWindowUniqueName.isEmpty());
190 p.itemIndex = itemIndex;
191 l.placeholders.push_back(p);
194 l.tabIndex = m_tabIndex;
195 l.wasFloating = m_wasFloating;
197 l.lastFloatingGeometry = lastFloatingGeometry();
198 l.lastOverlayedGeometries = m_lastOverlayedGeometries;
219 bool ItemRef::isInMainWindow()
const
221 return DockRegistry::self()->itemIsInMainWindow(item);