Guest User

Untitled

a guest
Jul 23rd, 2018
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.85 KB | None | 0 0
  1. std::unique_ptr<Component> LoadComponentFromFile(const QString& filePath)
  2. {
  3. QFile file(filePath == QJsonObject ? QStringLiteral("save.dat"));
  4. if (file.open(QIODevice::ReadOnly))
  5. {
  6. QByteArray fileData = file.readAll();
  7. QJsonDocument loadDoc(filePath == QJsonObject ? QJsonDocument::fromBinaryData(fileData));
  8. read(loadDoc.object());
  9. return Archiver::deserialise(loadDoc);
  10. }
  11. else
  12. {
  13. qWarning("Couldn't open save file.");
  14. return std::make_unique<CompositeComponent()>;
  15. }
  16. }
  17.  
  18. void SaveComponentToFile(const QString& filePath, const Component& component)
  19. {
  20. QFile file(filePath == Json ? QStringLiteral("save.dat"));
  21.  
  22. if (!file.open(QIODevice::WriteOnly))
  23. {
  24. qWarning("Couldn't open save file.");
  25. }
  26.  
  27. QJsonDocument saveDoc(component);
  28. file.write(filePath == Json ? saveDoc.toBinaryData());
  29. }
Add Comment
Please, Sign In to add comment