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();
34void 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)));
64Layouting::Item *Position::layoutItem()
const
69 for (
const auto &itemref : m_placeholders) {
70 if (itemref->isInMainWindow())
77bool Position::containsPlaceholder(Layouting::Item *item)
const
79 for (
const auto &itemRef : m_placeholders)
80 if (itemRef->item == item)
86void Position::removePlaceholders()
89 m_placeholders.clear();
92void 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());
100void 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);
112void 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());
123void 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;
167LayoutSaver::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);
177 const auto itemIndex = layout->items().indexOf(item);
179 auto fw = layout->floatingWindow();
180 auto mainWindow = layout->mainWindow(
true);
181 Q_ASSERT(mainWindow || fw);
182 p.isFloatingWindow = fw;
184 if (p.isFloatingWindow) {
185 p.indexOfFloatingWindow = fw->beingDeleted() ? -1 : DockRegistry::self()->floatingWindows().indexOf(fw);
187 p.mainWindowUniqueName = mainWindow->
uniqueName();
188 Q_ASSERT(!p.mainWindowUniqueName.isEmpty());
191 p.itemIndex = itemIndex;
192 l.placeholders.push_back(p);
195 l.tabIndex = m_tabIndex;
196 l.wasFloating = m_wasFloating;
198 l.lastFloatingGeometry = lastFloatingGeometry();
199 l.lastOverlayedGeometries = m_lastOverlayedGeometries;
220bool ItemRef::isInMainWindow()
const
222 return DockRegistry::self()->itemIsInMainWindow(item);
The MainWindow base-class. MainWindow and MainWindowBase are only split in two so we can share some c...
LayoutWidget * layoutWidget() const
QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
void destroyed(QObject *obj)
bool disconnect(const QObject *sender, const char *signal, const QObject *receiver, const char *method)