Rename LastPosition to Position
so we can have a list of them, the dock widget might have been in several main windows
This commit is contained in:
@@ -17,7 +17,7 @@ set(DOCKSLIBS_SRCS
|
||||
MainWindow.cpp
|
||||
MainWindowBase.cpp
|
||||
LayoutSaver.cpp
|
||||
private/LastPosition.cpp
|
||||
private/Position.cpp
|
||||
private/ObjectViewer.cpp
|
||||
private/DropIndicatorOverlayInterface.cpp
|
||||
private/indicators/ClassicIndicators.cpp
|
||||
|
||||
@@ -28,7 +28,7 @@
|
||||
#include "DockRegistry_p.h"
|
||||
#include "WidgetResizeHandler_p.h"
|
||||
#include "DropArea_p.h"
|
||||
#include "LastPosition_p.h"
|
||||
#include "Position_p.h"
|
||||
#include "multisplitter/Item_p.h"
|
||||
#include "Config.h"
|
||||
#include "FrameworkWidgetFactory.h"
|
||||
@@ -116,7 +116,7 @@ public:
|
||||
DockWidgetBase::Options options;
|
||||
QAction *const toggleAction;
|
||||
QAction *const floatAction;
|
||||
LastPosition m_lastPosition;
|
||||
Position m_lastPosition;
|
||||
bool m_updatingToggleAction = false;
|
||||
bool m_updatingFloatAction = false;
|
||||
bool m_isForceClosing = false;
|
||||
@@ -483,7 +483,7 @@ void DockWidgetBase::addPlaceholderItem(Layouting::Item *item)
|
||||
d->m_lastPosition.addPlaceholderItem(item);
|
||||
}
|
||||
|
||||
LastPosition *DockWidgetBase::lastPosition() const
|
||||
Position *DockWidgetBase::lastPosition() const
|
||||
{
|
||||
return &d->m_lastPosition;
|
||||
}
|
||||
|
||||
@@ -49,7 +49,7 @@ namespace KDDockWidgets {
|
||||
class Frame;
|
||||
class FloatingWindow;
|
||||
class DragController;
|
||||
class LastPosition;
|
||||
class Position;
|
||||
class DockRegistry;
|
||||
class LayoutSaver;
|
||||
class TabWidget;
|
||||
@@ -370,7 +370,7 @@ private:
|
||||
void addPlaceholderItem(Layouting::Item*);
|
||||
|
||||
///@brief returns the last position, just for tests. TODO Make tests just use the d-pointer.
|
||||
LastPosition *lastPosition() const;
|
||||
Position *lastPosition() const;
|
||||
|
||||
class Private;
|
||||
Private *const d;
|
||||
|
||||
@@ -33,7 +33,7 @@
|
||||
#include "DropArea_p.h"
|
||||
#include "Logging_p.h"
|
||||
#include "Frame_p.h"
|
||||
#include "LastPosition_p.h"
|
||||
#include "Position_p.h"
|
||||
#include "multisplitter/Item_p.h"
|
||||
#include "FrameworkWidgetFactory.h"
|
||||
#include "MainWindow.h"
|
||||
@@ -713,12 +713,12 @@ void LayoutSaver::MultiSplitterLayout::fromVariantMap(const QVariantMap &map)
|
||||
}
|
||||
}
|
||||
|
||||
void LayoutSaver::LastPosition::scaleSizes(const ScalingInfo &scalingInfo)
|
||||
void LayoutSaver::Position::scaleSizes(const ScalingInfo &scalingInfo)
|
||||
{
|
||||
scalingInfo.applyFactorsTo(/*by-ref*/lastFloatingGeometry);
|
||||
}
|
||||
|
||||
QVariantMap LayoutSaver::LastPosition::toVariantMap() const
|
||||
QVariantMap LayoutSaver::Position::toVariantMap() const
|
||||
{
|
||||
QVariantMap map;
|
||||
map.insert(QStringLiteral("lastFloatingGeometry"), Layouting::rectToMap(lastFloatingGeometry));
|
||||
@@ -729,7 +729,7 @@ QVariantMap LayoutSaver::LastPosition::toVariantMap() const
|
||||
return map;
|
||||
}
|
||||
|
||||
void LayoutSaver::LastPosition::fromVariantMap(const QVariantMap &map)
|
||||
void LayoutSaver::Position::fromVariantMap(const QVariantMap &map)
|
||||
{
|
||||
lastFloatingGeometry = Layouting::mapToRect(map.value(QStringLiteral("lastFloatingGeometry")).toMap());
|
||||
tabIndex = map.value(QStringLiteral("tabIndex")).toInt();
|
||||
|
||||
@@ -106,7 +106,7 @@ public:
|
||||
struct MainWindow;
|
||||
struct FloatingWindow;
|
||||
struct DockWidget;
|
||||
struct LastPosition;
|
||||
struct Position;
|
||||
struct MultiSplitterLayout;
|
||||
struct Frame;
|
||||
struct Placeholder;
|
||||
|
||||
@@ -107,7 +107,7 @@ struct LayoutSaver::ScalingInfo
|
||||
double widthFactor = -1;
|
||||
};
|
||||
|
||||
struct LayoutSaver::LastPosition
|
||||
struct LayoutSaver::Position
|
||||
{
|
||||
QRect lastFloatingGeometry;
|
||||
int tabIndex;
|
||||
@@ -151,7 +151,7 @@ struct DOCKS_EXPORT LayoutSaver::DockWidget
|
||||
|
||||
QString uniqueName;
|
||||
QString affinityName;
|
||||
LayoutSaver::LastPosition lastPosition;
|
||||
LayoutSaver::Position lastPosition;
|
||||
|
||||
private:
|
||||
DockWidget() {}
|
||||
|
||||
@@ -22,7 +22,7 @@
|
||||
#include "DockWidgetBase.h"
|
||||
#include "Logging_p.h"
|
||||
#include "DebugWindow_p.h"
|
||||
#include "LastPosition_p.h"
|
||||
#include "Position_p.h"
|
||||
#include "multisplitter/MultiSplitterLayout_p.h"
|
||||
#include "multisplitter/MultiSplitter_p.h"
|
||||
#include "quick/QmlTypes.h"
|
||||
|
||||
@@ -32,7 +32,7 @@
|
||||
#include "DragController_p.h"
|
||||
#include "FloatingWindow_p.h"
|
||||
#include "Utils_p.h"
|
||||
#include "LastPosition_p.h"
|
||||
#include "Position_p.h"
|
||||
#include "DockRegistry_p.h"
|
||||
#include "Config.h"
|
||||
#include "FrameworkWidgetFactory.h"
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
* @author Sérgio Martins \<sergio.martins@kdab.com\>
|
||||
*/
|
||||
|
||||
#include "LastPosition_p.h"
|
||||
#include "Position_p.h"
|
||||
#include "DockRegistry_p.h"
|
||||
#include "multisplitter/MultiSplitterLayout_p.h"
|
||||
#include "multisplitter/MultiSplitter_p.h"
|
||||
@@ -33,12 +33,12 @@
|
||||
|
||||
using namespace KDDockWidgets;
|
||||
|
||||
LastPosition::~LastPosition()
|
||||
Position::~Position()
|
||||
{
|
||||
m_placeholders.clear();
|
||||
}
|
||||
|
||||
void LastPosition::addPlaceholderItem(Layouting::Item *placeholder)
|
||||
void Position::addPlaceholderItem(Layouting::Item *placeholder)
|
||||
{
|
||||
Q_ASSERT(placeholder);
|
||||
|
||||
@@ -68,7 +68,7 @@ void LastPosition::addPlaceholderItem(Layouting::Item *placeholder)
|
||||
// the same value always, hence we just shove them into a list, instead of giving them meaningful names in separated variables
|
||||
}
|
||||
|
||||
QWidgetOrQuick *LastPosition::window() const
|
||||
QWidgetOrQuick *Position::window() const
|
||||
{
|
||||
if (Layouting::Item *placeholder = layoutItem())
|
||||
return placeholder->window();
|
||||
@@ -76,7 +76,7 @@ QWidgetOrQuick *LastPosition::window() const
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
Layouting::Item *LastPosition::layoutItem() const
|
||||
Layouting::Item *Position::layoutItem() const
|
||||
{
|
||||
// Return the layout item that is in a MainWindow, that's where we restore the dock widget to.
|
||||
// In the future we might want to restore it to FloatingWindows.
|
||||
@@ -89,7 +89,7 @@ Layouting::Item *LastPosition::layoutItem() const
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
bool LastPosition::containsPlaceholder(Layouting::Item *item) const
|
||||
bool Position::containsPlaceholder(Layouting::Item *item) const
|
||||
{
|
||||
for (const auto &itemRef : m_placeholders)
|
||||
if (itemRef->item == item)
|
||||
@@ -98,14 +98,20 @@ bool LastPosition::containsPlaceholder(Layouting::Item *item) const
|
||||
return false;
|
||||
}
|
||||
|
||||
void LastPosition::removePlaceholders(const MultiSplitterLayout *layout)
|
||||
void Position::removePlaceholders()
|
||||
{
|
||||
QScopedValueRollback<bool>(m_clearing, true);
|
||||
m_placeholders.clear();
|
||||
}
|
||||
|
||||
void Position::removePlaceholders(const MultiSplitterLayout *layout)
|
||||
{
|
||||
m_placeholders.erase(std::remove_if(m_placeholders.begin(), m_placeholders.end(), [layout] (const std::unique_ptr<ItemRef> &itemref) {
|
||||
return DockRegistry::self()->layoutForItem(itemref->item) == layout;
|
||||
}), m_placeholders.end());
|
||||
}
|
||||
|
||||
void LastPosition::removeNonMainWindowPlaceholders()
|
||||
void Position::removeNonMainWindowPlaceholders()
|
||||
{
|
||||
auto it = m_placeholders.begin();
|
||||
while (it != m_placeholders.end()) {
|
||||
@@ -117,7 +123,7 @@ void LastPosition::removeNonMainWindowPlaceholders()
|
||||
}
|
||||
}
|
||||
|
||||
void LastPosition::removePlaceholder(Layouting::Item *placeholder)
|
||||
void Position::removePlaceholder(Layouting::Item *placeholder)
|
||||
{
|
||||
if (m_clearing) // reentrancy guard
|
||||
return;
|
||||
@@ -127,17 +133,17 @@ void LastPosition::removePlaceholder(Layouting::Item *placeholder)
|
||||
}), m_placeholders.end());
|
||||
}
|
||||
|
||||
void LastPosition::setLastFloatingGeometry(QRect geo)
|
||||
void Position::setLastFloatingGeometry(QRect geo)
|
||||
{
|
||||
m_lastFloatingGeo = geo;
|
||||
}
|
||||
|
||||
QRect LastPosition::lastFloatingGeometry() const
|
||||
QRect Position::lastFloatingGeometry() const
|
||||
{
|
||||
return m_lastFloatingGeo;
|
||||
}
|
||||
|
||||
void LastPosition::deserialize(const LayoutSaver::LastPosition &lp)
|
||||
void Position::deserialize(const LayoutSaver::Position &lp)
|
||||
{
|
||||
for (const auto &placeholder : qAsConst(lp.placeholders)) {
|
||||
MultiSplitterLayout *layout;
|
||||
@@ -171,9 +177,9 @@ void LastPosition::deserialize(const LayoutSaver::LastPosition &lp)
|
||||
|
||||
}
|
||||
|
||||
LayoutSaver::LastPosition LastPosition::serialize() const
|
||||
LayoutSaver::Position Position::serialize() const
|
||||
{
|
||||
LayoutSaver::LastPosition l;
|
||||
LayoutSaver::Position l;
|
||||
|
||||
for (auto &itemRef : m_placeholders) {
|
||||
LayoutSaver::Placeholder p;
|
||||
@@ -24,15 +24,17 @@
|
||||
* @author Sérgio Martins \<sergio.martins@kdab.com\>
|
||||
*/
|
||||
|
||||
#ifndef KD_LAST_POSITION_P_H
|
||||
#define KD_LAST_POSITION_P_H
|
||||
#ifndef KDDOCKWIDGETS_POSITION_P_H
|
||||
#define KDDOCKWIDGETS_POSITION_P_H
|
||||
|
||||
#include "docks_export.h"
|
||||
#include "Logging_p.h"
|
||||
#include "LayoutSaver_p.h"
|
||||
#include "QWidgetAdapter.h"
|
||||
|
||||
#include <QScopedValueRollback>
|
||||
#include <QPointer>
|
||||
|
||||
#include <memory>
|
||||
|
||||
namespace Layouting {
|
||||
@@ -59,25 +61,26 @@ private:
|
||||
|
||||
class DockWidgetBase;
|
||||
class Frame;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
* @brief Represents the DockWidget's last position.
|
||||
*
|
||||
* The DockWidget's position is saved when its closed and restored when it's shown.
|
||||
* The DockWidget's position is saved when it's closed and restored when it's shown.
|
||||
* This class holds that position.
|
||||
*/
|
||||
class DOCKS_EXPORT_FOR_UNIT_TESTS LastPosition
|
||||
class DOCKS_EXPORT_FOR_UNIT_TESTS Position
|
||||
{
|
||||
Q_DISABLE_COPY(LastPosition)
|
||||
Q_DISABLE_COPY(Position)
|
||||
public:
|
||||
LastPosition() = default;
|
||||
~LastPosition();
|
||||
Position() = default;
|
||||
~Position();
|
||||
|
||||
void deserialize(const LayoutSaver::LastPosition &);
|
||||
LayoutSaver::LastPosition serialize() const;
|
||||
void deserialize(const LayoutSaver::Position &);
|
||||
LayoutSaver::Position serialize() const;
|
||||
|
||||
/**
|
||||
* @brief Returns whether the LastPosition is valid. If invalid then the DockWidget was never
|
||||
* @brief Returns whether the Position is valid. If invalid then the DockWidget was never
|
||||
* in a MainWindow.
|
||||
*/
|
||||
bool isValid() const { return layoutItem() != nullptr; }
|
||||
@@ -105,7 +108,7 @@ public:
|
||||
Layouting::Item* layoutItem() const;
|
||||
|
||||
bool containsPlaceholder(Layouting::Item*) const;
|
||||
void removePlaceholders() { m_clearing = true; m_placeholders.clear(); m_clearing = false;}
|
||||
void removePlaceholders();
|
||||
|
||||
const std::vector<std::unique_ptr<ItemRef>>& placeholders() const { return m_placeholders; }
|
||||
|
||||
@@ -23,7 +23,7 @@
|
||||
#include "MultiSplitter_p.h"
|
||||
#include "Frame_p.h"
|
||||
#include "DockWidgetBase.h"
|
||||
#include "LastPosition_p.h"
|
||||
#include "Position_p.h"
|
||||
#include "DockRegistry_p.h"
|
||||
#include "Config.h"
|
||||
#include "FrameworkWidgetFactory.h"
|
||||
|
||||
@@ -35,7 +35,7 @@
|
||||
#include "LayoutSaver_p.h"
|
||||
#include "TabWidget_p.h"
|
||||
#include "multisplitter/MultiSplitter_p.h"
|
||||
#include "LastPosition_p.h"
|
||||
#include "Position_p.h"
|
||||
#include "utils.h"
|
||||
#include "FrameworkWidgetFactory.h"
|
||||
#include "DropAreaWithCentralFrame_p.h"
|
||||
@@ -2199,7 +2199,7 @@ void TestDocks::tst_setFloatingWhenWasTabbed()
|
||||
QVERIFY(!dock1->isFloating());
|
||||
QVERIFY(dock2->isFloating());
|
||||
|
||||
LastPosition *pos2 = dock2->lastPosition();
|
||||
Position *pos2 = dock2->lastPosition();
|
||||
QCOMPARE(pos2->m_tabIndex, 1);
|
||||
QVERIFY(pos2->isValid());
|
||||
dock2->setFloating(false);
|
||||
|
||||
Reference in New Issue
Block a user