Skip to content
Extraits de code Groupes Projets
Vérifiée Valider 05ea1cf6 rédigé par Kubat's avatar Kubat
Parcourir les fichiers

LIB: A default `loadDocument(const QString &)` is implemented inside the CRTPStore class

parent 91a9284c
Branches
Aucune étiquette associée trouvée
1 requête de fusion!12Script store
......@@ -7,6 +7,8 @@
#include "Utils.hh"
#include "Uuid.hh"
#include <QString>
#include <QMap>
#include <memory>
#define VIVY_STORAGE_CLASS(theClassName, theDocumentName) \
VIVY_UNMOVABLE_OBJECT(theClassName) \
......@@ -30,6 +32,15 @@ protected:
explicit CRTPStore() noexcept = default;
public:
// Load a document by its name
std::shared_ptr<Document> loadDocument(const QString &file)
{
auto ret = std::make_shared<Document>(file);
const Uuid id = ret->getUuid();
documents[id] = ret;
return ret;
}
// Close a document, please be sure to not used any of the dangling
// references to the closed document...
void closeDocument(const Uuid &uuid) noexcept
......
......@@ -5,24 +5,6 @@
using namespace Vivy;
std::shared_ptr<VivyDocument>
VivyDocumentStore::loadDocument(const QString &file)
{
const QFileInfo fileinfo(file);
const QString baseName = fileinfo.baseName();
auto ret = std::make_shared<VivyDocument>(file);
if (ret) {
qDebug() << "Register document " << baseName << ret->getDocumentCapabilitiesString();
const Uuid uuid = ret->getUuid();
documents[uuid] = ret;
return documents[uuid];
} else {
qDebug() << "Failed to create document from " << file;
throw std::runtime_error("Failed to create the document");
}
}
std::shared_ptr<VivyDocument>
VivyDocumentStore::newDocument(VivyDocument::Options opt)
{
......
......@@ -8,10 +8,6 @@
#include "../Utils.hh"
#include "../CRTPStore.hh"
#include <QMap>
#include <QString>
#include <memory>
namespace Vivy
{
class VivyDocumentStore final : public CRTPStore<VivyDocumentStore, VivyDocument> {
......@@ -20,8 +16,7 @@ class VivyDocumentStore final : public CRTPStore<VivyDocumentStore, VivyDocument
public:
explicit VivyDocumentStore() noexcept = default;
// Create/load documents
std::shared_ptr<VivyDocument> loadDocument(const QString &file);
// Create a new empty document with no backing file for the moment
std::shared_ptr<VivyDocument> newDocument(VivyDocument::Options opt = VivyDocument::NoOption);
};
......
......@@ -2,17 +2,3 @@
#include "../Uuid.hh"
using namespace Vivy::Script;
std::shared_ptr<ScriptDocument>
ScriptStore::loadDocument(const QString &file)
{
try {
auto ret = std::make_shared<ScriptDocument>(file);
const Uuid uuid = ret->getUuid();
documents[uuid] = ret;
return ret;
} catch (const std::runtime_error &e) {
qCritical() << "Failed to create the Script document with:" << e.what();
return std::shared_ptr<ScriptDocument>(nullptr);
}
}
......@@ -10,7 +10,5 @@ class ScriptStore final : public CRTPStore<ScriptStore, ScriptDocument> {
public:
explicit ScriptStore() noexcept = default;
std::shared_ptr<ScriptDocument> loadDocument(const QString &file);
};
}
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Veuillez vous inscrire ou vous pour commenter