qt5base-lts/examples/corelib/serialization/savegame/game.h
Marc Mutz 6f1e53943d savegame ex.: revamp the way print() works
Basically, instead of re-creating QTextStreams all the time, create it
once, in main(), and then pass it to print() alongside the int
indentation.

Also fix a hard-coded indentation value that should have been relative
to the caller's indentation level.

Pick-to: 6.5 6.2
Task-number: QTBUG-108857
Change-Id: I811447295c9c3fdef23f61aff31ebe82941eb3b4
Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
2023-05-09 08:21:10 +02:00

41 lines
740 B
C++

// Copyright (C) 2016 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
#ifndef GAME_H
#define GAME_H
#include "character.h"
#include "level.h"
#include <QJsonObject>
#include <QList>
QT_FORWARD_DECLARE_CLASS(QTextStream)
//! [0]
class Game
{
public:
enum SaveFormat {
Json, Binary
};
Character player() const;
QList<Level> levels() const;
void newGame();
bool loadGame(SaveFormat saveFormat);
bool saveGame(SaveFormat saveFormat) const;
void read(const QJsonObject &json);
QJsonObject toJson() const;
void print(QTextStream &s, int indentation = 0) const;
private:
Character mPlayer;
QList<Level> mLevels;
};
//! [0]
#endif // GAME_H