Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add load project data functiuonality #13

Merged
merged 6 commits into from
Dec 14, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ include_directories(
src/editor
src/gui
src/project
src/tools
src
)

Expand All @@ -90,6 +91,7 @@ list(APPEND SRC_FILES
src/project/project
src/project/storyitem
src/project/storymodel
src/tools/datautils
src/data
src/guimain
src/main
Expand Down
30 changes: 20 additions & 10 deletions i18n/collett_en_US.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,50 +133,60 @@
<context>
<name>Collett::Project</name>
<message>
<location filename="../src/project/project.cpp" line="75"/>
<location filename="../src/project/project.cpp" line="87"/>
<location filename="../src/project/project.cpp" line="55"/>
<location filename="../src/project/project.cpp" line="67"/>
<source>Project not found at: %1</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../src/project/project.cpp" line="102"/>
<location filename="../src/project/project.cpp" line="110"/>
<location filename="../src/project/project.cpp" line="82"/>
<location filename="../src/project/project.cpp" line="90"/>
<source>Could not create folder: %1</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../src/project/project.cpp" line="258"/>
<source>Unnamed Project</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>Collett::StoryItem</name>
<message>
<location filename="../src/project/storyitem.cpp" line="232"/>
<location filename="../src/project/storyitem.cpp" line="136"/>
<source>Unnamed</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../src/project/storyitem.cpp" line="314"/>
<source>Book</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../src/project/storyitem.cpp" line="233"/>
<location filename="../src/project/storyitem.cpp" line="315"/>
<source>Partition</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../src/project/storyitem.cpp" line="234"/>
<location filename="../src/project/storyitem.cpp" line="316"/>
<source>Chapter</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../src/project/storyitem.cpp" line="235"/>
<location filename="../src/project/storyitem.cpp" line="317"/>
<source>Scene</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../src/project/storyitem.cpp" line="236"/>
<location filename="../src/project/storyitem.cpp" line="318"/>
<source>Page</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>Collett::StoryModel</name>
<message>
<location filename="../src/project/storymodel.cpp" line="110"/>
<location filename="../src/project/storymodel.cpp" line="154"/>
<source>New %1</source>
<translation type="unfinished"></translation>
</message>
Expand Down
30 changes: 20 additions & 10 deletions i18n/collett_nb_NO.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,50 +133,60 @@
<context>
<name>Collett::Project</name>
<message>
<location filename="../src/project/project.cpp" line="75"/>
<location filename="../src/project/project.cpp" line="87"/>
<location filename="../src/project/project.cpp" line="55"/>
<location filename="../src/project/project.cpp" line="67"/>
<source>Project not found at: %1</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../src/project/project.cpp" line="102"/>
<location filename="../src/project/project.cpp" line="110"/>
<location filename="../src/project/project.cpp" line="82"/>
<location filename="../src/project/project.cpp" line="90"/>
<source>Could not create folder: %1</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../src/project/project.cpp" line="258"/>
<source>Unnamed Project</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>Collett::StoryItem</name>
<message>
<location filename="../src/project/storyitem.cpp" line="232"/>
<location filename="../src/project/storyitem.cpp" line="136"/>
<source>Unnamed</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../src/project/storyitem.cpp" line="314"/>
<source>Book</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../src/project/storyitem.cpp" line="233"/>
<location filename="../src/project/storyitem.cpp" line="315"/>
<source>Partition</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../src/project/storyitem.cpp" line="234"/>
<location filename="../src/project/storyitem.cpp" line="316"/>
<source>Chapter</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../src/project/storyitem.cpp" line="235"/>
<location filename="../src/project/storyitem.cpp" line="317"/>
<source>Scene</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../src/project/storyitem.cpp" line="236"/>
<location filename="../src/project/storyitem.cpp" line="318"/>
<source>Page</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>Collett::StoryModel</name>
<message>
<location filename="../src/project/storymodel.cpp" line="110"/>
<location filename="../src/project/storymodel.cpp" line="154"/>
<source>New %1</source>
<translation type="unfinished"></translation>
</message>
Expand Down
7 changes: 3 additions & 4 deletions sample/data/project.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
{
"meta": {
"created": "2021-12-06T00:18:31",
"updated": "2021-12-06T00:18:49"
"created": "2021-12-14T22:24:25",
"updated": "2021-12-14T22:44:03"
},
"project": {
"bookTitle": "New Project",
"projectName": "New Project"
"projectName": "Sample Project"
},
"settings": {
}
Expand Down
20 changes: 10 additions & 10 deletions sample/data/story.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,35 +2,35 @@
"type": "ROOT",
"xItems": [
{
"handle": "095f8c2e-89df-4611-a592-d5752adcdcbf",
"name": "Sample Novel",
"handle": "e709ba3f-3141-4b4b-95df-4a8d3e91a8ba",
"name": "Novel",
"order": 0,
"type": "BOOK",
"wCount": 1234,
"xItems": [
{
"handle": "4cbbd3f1-0c15-48ab-8cf0-512dd5d28b29",
"handle": "c2290a95-ca41-4181-89f2-18cb610ab716",
"name": "Title Page",
"order": 0,
"type": "PAGE",
"wCount": 1234
},
{
"handle": "2484aee2-80a4-47c8-bae9-04c7b4780aa7",
"handle": "af3dc4a4-5f66-462d-b63b-9c4d7a7dec77",
"name": "Chapter 1",
"order": 1,
"type": "CHAPTER",
"wCount": 1234,
"xItems": [
{
"handle": "7361ce56-9035-4a33-a825-0220c3364496",
"handle": "63913842-121f-43ed-8d9c-b3e2432599ab",
"name": "Scene 1.1",
"order": 0,
"type": "SCENE",
"wCount": 1234
},
{
"handle": "09a42313-3345-46ed-b272-8c56117b9428",
"handle": "7e5a1a98-d1a3-44a1-ab4e-2b5d21d92201",
"name": "Scene 1.2",
"order": 1,
"type": "SCENE",
Expand All @@ -39,21 +39,21 @@
]
},
{
"handle": "f0af1424-89bc-4ec8-87d5-a985d1603b04",
"handle": "61fc6238-87cf-4b78-b2c7-a430776a2b7a",
"name": "Chapter 2",
"order": 2,
"type": "CHAPTER",
"wCount": 1234,
"xItems": [
{
"handle": "8878261c-2082-4ceb-bdfe-22ccb09ffa87",
"handle": "f3993444-4e43-4ace-bfdb-55ca659ca914",
"name": "Scene 2.1",
"order": 0,
"type": "SCENE",
"wCount": 1234
},
{
"handle": "04925f10-f6ea-453c-9c7b-b898c4ea22eb",
"handle": "ab6ba4f4-5658-4ff0-941d-2e0c687fe88d",
"name": "Scene 2.2",
"order": 1,
"type": "SCENE",
Expand All @@ -62,7 +62,7 @@
]
},
{
"handle": "fcee8ed9-c2a0-4560-9e3b-afe7f2438525",
"handle": "f1dffe99-3583-4f9c-9f0b-1a8f323b0670",
"name": "Very long title on this element here",
"order": 3,
"type": "PAGE",
Expand Down
100 changes: 47 additions & 53 deletions src/data.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,93 +23,87 @@
#include "project.h"
#include "storymodel.h"

#include <QString>
#include <QWidget>
#include <QDir>
#include <QVariant>

namespace Collett {

/**
* Private Class Declaration
* =========================
* Class Constructor/Destructor/Instance
* =====================================
*/

class CollettDataPrivate
{
public:
static CollettData *instance;

CollettDataPrivate() {};
~CollettDataPrivate() {
qDebug() << "Deconstructing: CollettDataPrivate";
delete m_project;
};

Project *m_project;

bool m_hasProject = false;
};

/**
* Public Class Contruction/Deconstruction
* =======================================
*/

CollettData *CollettDataPrivate::instance = nullptr;

CollettData *CollettData::staticInstance = nullptr;
CollettData *CollettData::instance() {
if (CollettDataPrivate::instance == nullptr) {
CollettDataPrivate::instance = new CollettData();
qDebug() << "CollettData instance created";
if (staticInstance == nullptr) {
staticInstance = new CollettData();
qDebug() << "Constructor: CollettData";
}
return CollettDataPrivate::instance;
return staticInstance;
}

CollettData::CollettData() : d_ptr(new CollettDataPrivate()) {
Q_D(CollettData);
CollettData::CollettData() {}
CollettData::~CollettData() {
qDebug() << "Destructor: CollettData";
m_project.reset();
}

CollettData::~CollettData() {}

/**
* Public Class Methods
* ====================
* Class Methods
* =============
*/

bool CollettData::openProject(const QString &path) {
Q_D(CollettData);

d->m_project = new Project(path);
bool status = d->m_project->openProject();
d->m_hasProject = d->m_project->hasProject();
m_project.reset(new Project(path));
if (!m_project.data()->hasError()) {
m_project.data()->openProject();
}
if (!m_project.data()->isValid()) {
m_project.reset(nullptr);
return false;
}

return status;
return true;
}

bool CollettData::saveProject() {
Q_D(CollettData);

if (d->m_hasProject) {
return d->m_project->saveProject();
if (hasProject()) {
return m_project.data()->saveProject();
} else {
return false;
}
}

Project *CollettData::project() {
Q_D(CollettData);
void CollettData::closeProject() {
m_project.reset(nullptr);
}

/**
* Class Getters
* =============
*/

bool CollettData::hasProject() const {
if (m_project.isNull()) {
return false;
} else {
return m_project.data()->isValid();
}
}

if (d->m_hasProject) {
return d->m_project;
Project *CollettData::project() {
if (hasProject()) {
return m_project.data();
} else {
return nullptr;
}
}

StoryModel *CollettData::storyModel() {
Q_D(CollettData);

if (d->m_hasProject) {
return d->m_project->storyModel();
if (hasProject()) {
return m_project.data()->storyModel();
} else {
return nullptr;
}
Expand Down
Loading