wip
This commit is contained in:
@@ -444,7 +444,7 @@ LayoutSaver::MainWindow LayoutSaver::Layout::mainWindowForIndex(int index) const
|
||||
|
||||
bool LayoutSaver::Frame::isValid() const
|
||||
{
|
||||
if (!isNull)
|
||||
if (isNull)
|
||||
return true;
|
||||
|
||||
if (!geometry.isValid()) {
|
||||
@@ -452,6 +452,11 @@ bool LayoutSaver::Frame::isValid() const
|
||||
return false;
|
||||
}
|
||||
|
||||
if (id.isEmpty()) {
|
||||
qWarning() << Q_FUNC_INFO << "Invalid id";
|
||||
return false;
|
||||
}
|
||||
|
||||
if (options > 3) {
|
||||
qWarning() << Q_FUNC_INFO << "Invalid options" << options;
|
||||
return false;
|
||||
@@ -478,6 +483,7 @@ void LayoutSaver::Frame::scaleSizes(const ScalingInfo &scalingInfo)
|
||||
QVariantMap LayoutSaver::Frame::toVariantMap() const
|
||||
{
|
||||
QVariantMap map;
|
||||
map.insert(QStringLiteral("id"), id);
|
||||
map.insert(QStringLiteral("isNull"), isNull);
|
||||
map.insert(QStringLiteral("objectName"), objectName);
|
||||
map.insert(QStringLiteral("geometry"), rectToMap(geometry));
|
||||
@@ -497,6 +503,7 @@ void LayoutSaver::Frame::fromVariantMap(const QVariantMap &map)
|
||||
return;
|
||||
}
|
||||
|
||||
id = map.value(QStringLiteral("id")).toString();
|
||||
isNull = map.value(QStringLiteral("isNull")).toBool();
|
||||
objectName = map.value(QStringLiteral("objectName")).toString();
|
||||
geometry = mapToRect(map.value(QStringLiteral("geometry")).toMap());
|
||||
|
||||
@@ -280,6 +280,7 @@ bool FloatingWindow::beingDeleted() const
|
||||
if (m_beingDeleted)
|
||||
return true;
|
||||
|
||||
// TODO: Confusing logic
|
||||
for (Frame *f : frames()) {
|
||||
if (!f->beingDeletedLater())
|
||||
return false;
|
||||
|
||||
@@ -499,6 +499,9 @@ bool Frame::event(QEvent *e)
|
||||
|
||||
Frame *Frame::deserialize(const LayoutSaver::Frame &f)
|
||||
{
|
||||
if (!f.isValid())
|
||||
return nullptr;
|
||||
|
||||
auto frame = Config::self().frameworkWidgetFactory()->createFrame(/*parent=*/nullptr, FrameOptions(f.options));
|
||||
frame->setObjectName(f.objectName);
|
||||
|
||||
|
||||
@@ -1683,6 +1683,15 @@ void ItemContainer::updateChildPercentages()
|
||||
}
|
||||
}
|
||||
|
||||
void ItemContainer::updateChildPercentages_recursive()
|
||||
{
|
||||
updateChildPercentages();
|
||||
for (Item *item : m_children) {
|
||||
if (auto c = item->asContainer())
|
||||
c->updateChildPercentages_recursive();
|
||||
}
|
||||
}
|
||||
|
||||
QVector<double> ItemContainer::childPercentages() const
|
||||
{
|
||||
QVector<double> percentages;
|
||||
@@ -2363,7 +2372,12 @@ void ItemContainer::fillFromVariantMap(const QVariantMap &map,
|
||||
Item *child = isContainer ? new ItemContainer(hostWidget(), this)
|
||||
: new Item(hostWidget(), this);
|
||||
child->fillFromVariantMap(childMap, widgets);
|
||||
m_children.push_back(child);
|
||||
}
|
||||
|
||||
if (isRoot()) {
|
||||
updateChildPercentages_recursive();
|
||||
updateSeparators_recursive();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -473,6 +473,7 @@ public:
|
||||
QVariantList items() const;
|
||||
void dumpLayout(int level = 0) override;
|
||||
void updateChildPercentages();
|
||||
void updateChildPercentages_recursive();
|
||||
void restoreChild(Item *);
|
||||
void updateWidgetGeometries() override;
|
||||
int oppositeLength() const;
|
||||
|
||||
@@ -451,6 +451,7 @@ bool MultiSplitterLayout::deserialize(const LayoutSaver::MultiSplitterLayout &l)
|
||||
QHash<QString, GuestInterface*> frames;
|
||||
for (const LayoutSaver::Frame &frame : qAsConst(l.frames)) {
|
||||
Frame *f = Frame::deserialize(frame);
|
||||
Q_ASSERT(!frame.id.isEmpty());
|
||||
frames.insert(frame.id, f);
|
||||
}
|
||||
|
||||
|
||||
@@ -321,6 +321,7 @@ private Q_SLOTS:
|
||||
void tst_anchorFollowingItselfAssert();
|
||||
void tst_positionWhenShown();
|
||||
void tst_restoreEmpty();
|
||||
void tst_restoreSimplest();
|
||||
void tst_restoreSimple();
|
||||
// void tst_restoreNestedAndTabbed();
|
||||
// void tst_restoreCentralFrame();
|
||||
@@ -1138,6 +1139,22 @@ void TestDocks::tst_restoreEmpty()
|
||||
QVERIFY(layout->checkSanity());
|
||||
}
|
||||
|
||||
void TestDocks::tst_restoreSimplest()
|
||||
{
|
||||
EnsureTopLevelsDeleted e;
|
||||
// Tests restoring a very simple layout, composed of just 1 docked widget
|
||||
auto m = createMainWindow(QSize(800, 500), MainWindowOption_None);
|
||||
//auto layout = m->multiSplitterLayout();
|
||||
auto dock1 = createDockWidget("one", new QTextEdit());
|
||||
m->addDockWidget(dock1, Location_OnTop);
|
||||
|
||||
LayoutSaver saver;
|
||||
QVERIFY(saver.saveToFile(QStringLiteral("layout.json")));
|
||||
QTest::qWait(200);
|
||||
qDebug() << "About to restore";
|
||||
QVERIFY(saver.restoreFromFile(QStringLiteral("layout.json")));
|
||||
}
|
||||
|
||||
void TestDocks::tst_restoreSimple()
|
||||
{
|
||||
EnsureTopLevelsDeleted e;
|
||||
|
||||
Reference in New Issue
Block a user