From 02e37df49a922af337eb877fa76e64e9aa458adb Mon Sep 17 00:00:00 2001 From: Veronica Berglyd Olsen <1619840+vkbo@users.noreply.github.com> Date: Sun, 28 Nov 2021 17:20:59 +0100 Subject: [PATCH 1/9] Add menu entries to the project menu --- src/gui/maintoolbar.cpp | 32 +++++++++++++++++++++++++++++++- src/gui/maintoolbar.h | 12 ++++++++++++ 2 files changed, 43 insertions(+), 1 deletion(-) diff --git a/src/gui/maintoolbar.cpp b/src/gui/maintoolbar.cpp index 5348675..db61651 100644 --- a/src/gui/maintoolbar.cpp +++ b/src/gui/maintoolbar.cpp @@ -25,6 +25,8 @@ along with this program. If not, see . #include #include #include +#include +#include namespace Collett { @@ -39,7 +41,7 @@ GuiMainToolBar::GuiMainToolBar(QWidget *parent) m_projectName = new QLabel(tr("No Project")); this->setOrientation(Qt::Horizontal); - this->addAction(tr("Project")); + this->buildProjectMenu(); this->addWidget(stretch1); this->addWidget(m_projectName); this->addWidget(stretch2); @@ -50,4 +52,32 @@ void GuiMainToolBar::setProjectName(const QString &name) { m_projectName->setText(name); } +/* + Build Functions + =============== +*/ + +void GuiMainToolBar::buildProjectMenu() { + + // Menu + m_projectMenu = new QMenu(this); + + // New Project + m_newProject = m_projectMenu->addAction(tr("New Project")); + + // Open Project + m_openProject = m_projectMenu->addAction(tr("Open Project")); + + // Save Project + m_saveProject = m_projectMenu->addAction(tr("Save Project")); + + // Assemble + m_projectButton = new QToolButton(this); + m_projectButton->setText(tr("Project")); + m_projectButton->setMenu(m_projectMenu); + m_projectButton->setPopupMode(QToolButton::InstantPopup); + this->addWidget(m_projectButton); + +} + } // namespace Collett diff --git a/src/gui/maintoolbar.h b/src/gui/maintoolbar.h index ab5856e..a41de8e 100644 --- a/src/gui/maintoolbar.h +++ b/src/gui/maintoolbar.h @@ -26,6 +26,9 @@ along with this program. If not, see . #include #include #include +#include +#include +#include namespace Collett { @@ -42,6 +45,15 @@ class GuiMainToolBar : public QToolBar private: QLabel *m_projectName; + // Main Actions + QToolButton *m_projectButton; + QMenu *m_projectMenu; + QAction *m_newProject; + QAction *m_openProject; + QAction *m_saveProject; + + void buildProjectMenu(); + }; } // namespace Collett From b80f7439313754c3fed615cb041b226c634086d5 Mon Sep 17 00:00:00 2001 From: Veronica Berglyd Olsen <1619840+vkbo@users.noreply.github.com> Date: Sun, 28 Nov 2021 18:07:24 +0100 Subject: [PATCH 2/9] Copy over a bunch of core classes from old project --- CMakeLists.txt | 5 +- i18n/collett_en_US.ts | 49 ++++++++---- i18n/collett_nb_NO.ts | 49 ++++++++---- src/data.cpp | 122 +++++++++++++++++++++++++++++ src/data.h | 60 ++++++++++++++ src/gui/storytreeview.cpp | 35 +++++++++ src/gui/storytreeview.h | 41 ++++++++++ src/guimain.cpp | 36 +++++++-- src/guimain.h | 19 +++-- src/main.cpp | 6 +- src/project/project.cpp | 62 +++++++++++++++ src/project/project.h | 57 ++++++++++++++ src/project/storyitem.cpp | 20 ++--- src/project/storyitem.h | 16 ++-- src/project/storymodel.cpp | 60 +++++++------- src/project/storymodel.h | 16 ++-- src/{gui => project}/storytree.cpp | 14 ++-- src/{gui => project}/storytree.h | 17 ++-- 18 files changed, 561 insertions(+), 123 deletions(-) create mode 100644 src/data.cpp create mode 100644 src/data.h create mode 100644 src/gui/storytreeview.cpp create mode 100644 src/gui/storytreeview.h create mode 100644 src/project/project.cpp create mode 100644 src/project/project.h rename src/{gui => project}/storytree.cpp (77%) rename src/{gui => project}/storytree.h (75%) diff --git a/CMakeLists.txt b/CMakeLists.txt index 0870dee..7b49283 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -84,10 +84,13 @@ list(APPEND SRC_FILES src/editor/doceditor src/gui/maintoolbar src/gui/statusbar - src/gui/storytree + src/gui/storytreeview src/gui/treetoolbar + src/project/project src/project/storyitem src/project/storymodel + src/project/storytree + src/data src/guimain src/main src/settings diff --git a/i18n/collett_en_US.ts b/i18n/collett_en_US.ts index 6335660..3c0ad8b 100644 --- a/i18n/collett_en_US.ts +++ b/i18n/collett_en_US.ts @@ -1,23 +1,10 @@ - - Collett::CollettStoryModel - - - Title - - - - - Words - - - Collett::GuiMain - + %1 %2 Version %3 @@ -25,17 +12,32 @@ Collett::GuiMainToolBar - + No Project - + + New Project + + + + + Open Project + + + + + Save Project + + + + Project - + Menu @@ -53,6 +55,19 @@ + + Collett::StoryModel + + + Title + + + + + Words + + + main diff --git a/i18n/collett_nb_NO.ts b/i18n/collett_nb_NO.ts index 08fde80..6af7db7 100644 --- a/i18n/collett_nb_NO.ts +++ b/i18n/collett_nb_NO.ts @@ -1,23 +1,10 @@ - - Collett::CollettStoryModel - - - Title - - - - - Words - - - Collett::GuiMain - + %1 %2 Version %3 @@ -25,17 +12,32 @@ Collett::GuiMainToolBar - + No Project - + + New Project + + + + + Open Project + + + + + Save Project + + + + Project - + Menu @@ -53,6 +55,19 @@ + + Collett::StoryModel + + + Title + + + + + Words + + + main diff --git a/src/data.cpp b/src/data.cpp new file mode 100644 index 0000000..e734a93 --- /dev/null +++ b/src/data.cpp @@ -0,0 +1,122 @@ +/* +Collett – Core Data Class +========================= + +This file is a part of Collett +Copyright 2020–2021, Veronica Berglyd Olsen + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program. If not, see . +*/ + +#include "data.h" +#include "project.h" +#include "storymodel.h" + +#include +#include + +namespace Collett { + +/* + Private Class Declaration + ========================= +*/ + +class CollettDataPrivate +{ +public: + static CollettData *instance; + + CollettDataPrivate() {}; + ~CollettDataPrivate() { + qDebug() << "Deconstructing: CollettDataPrivate"; + delete m_project; + delete m_storyModel; + }; + + Project *m_project; + StoryModel *m_storyModel; + + bool m_hasProject = false; +}; + +/* + Public Class Contruction/Deconstruction + ======================================= +*/ + +CollettData *CollettDataPrivate::instance = nullptr; + +CollettData *CollettData::instance() { + if (CollettDataPrivate::instance == nullptr) { + CollettDataPrivate::instance = new CollettData(); + qDebug() << "CollettData instance created"; + } + return CollettDataPrivate::instance; +} + +CollettData::CollettData() : d_ptr(new CollettDataPrivate()) { + Q_D(CollettData); +} + +CollettData::~CollettData() {} + +/* + Public 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(); + + d->m_storyModel = new StoryModel(d->m_project); + + return status; +} + +bool CollettData::saveProject() { + Q_D(CollettData); + + if (d->m_hasProject) { + return d->m_project->saveProject(); + } else { + return false; + } +} + +Project *CollettData::project() { + Q_D(CollettData); + + if (d->m_hasProject) { + return d->m_project; + } else { + return nullptr; + } +} + +StoryModel *CollettData::storyModel() { + Q_D(CollettData); + + if (d->m_hasProject) { + return d->m_storyModel; + } else { + return nullptr; + } +} + +} // namespace Collett diff --git a/src/data.h b/src/data.h new file mode 100644 index 0000000..94d6de2 --- /dev/null +++ b/src/data.h @@ -0,0 +1,60 @@ +/* +Collett – Core Data Class +========================= + +This file is a part of Collett +Copyright 2020–2021, Veronica Berglyd Olsen + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program. If not, see . +*/ + +#ifndef COLLETT_DATA_H +#define COLLETT_DATA_H + +#include "collett.h" +#include "project.h" +#include "storymodel.h" + +#include +#include +#include +#include + +namespace Collett { + +class CollettDataPrivate; +class CollettData : public QObject +{ + Q_OBJECT + Q_DECLARE_PRIVATE(CollettData) + +public: + static CollettData *instance(); + ~CollettData(); + +private: + QScopedPointer d_ptr; + CollettData(); + +public: + bool openProject(const QString &path); + bool saveProject(); + + Project *project(); + StoryModel *storyModel(); + +}; +} // namespace Collett + +#endif // COLLETT_DATA_H diff --git a/src/gui/storytreeview.cpp b/src/gui/storytreeview.cpp new file mode 100644 index 0000000..4e8779d --- /dev/null +++ b/src/gui/storytreeview.cpp @@ -0,0 +1,35 @@ +/* +Collett – GUI Story Tree Class +============================== + +This file is a part of Collett +Copyright 2020–2021, Veronica Berglyd Olsen + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program. If not, see . +*/ + +#include "storytreeview.h" +#include "storymodel.h" + +#include +#include + +namespace Collett { + +GuiStoryTreeView::GuiStoryTreeView(QWidget *parent) + : QTreeView(parent) +{ +} + +} // namespace Collett diff --git a/src/gui/storytreeview.h b/src/gui/storytreeview.h new file mode 100644 index 0000000..ec09fce --- /dev/null +++ b/src/gui/storytreeview.h @@ -0,0 +1,41 @@ +/* +Collett – GUI Story Tree Class +============================== + +This file is a part of Collett +Copyright 2020–2021, Veronica Berglyd Olsen + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program. If not, see . +*/ + +#ifndef GUI_STORYTREEVIEW_H +#define GUI_STORYTREEVIEW_H + +#include +#include + +namespace Collett { + +class GuiStoryTreeView : public QTreeView +{ + Q_OBJECT + +public: + GuiStoryTreeView(QWidget *parent=nullptr); + ~GuiStoryTreeView() {}; + +}; +} // namespace Collett + +#endif // GUI_STORYTREEVIEW_H diff --git a/src/guimain.cpp b/src/guimain.cpp index 508efb9..6630223 100644 --- a/src/guimain.cpp +++ b/src/guimain.cpp @@ -20,11 +20,12 @@ along with this program. If not, see . */ #include "guimain.h" +#include "data.h" #include "settings.h" #include "maintoolbar.h" #include "treetoolbar.h" #include "statusbar.h" -#include "storytree.h" +#include "storytreeview.h" #include "doceditor.h" #include @@ -34,18 +35,21 @@ namespace Collett { GuiMain::GuiMain(QWidget *parent) : QMainWindow(parent) { + // Create Main Data Object + m_data = CollettData::instance(); + // Collett Widgets - m_mainToolBar = new GuiMainToolBar(this); - m_treeToolBar = new GuiTreeToolBar(this); - m_storyTree = new GuiStoryTree(this); - m_mainStatus = new GuiMainStatus(this); - m_docEditor = new GuiDocEditor(this); + m_mainToolBar = new GuiMainToolBar(this); + m_treeToolBar = new GuiTreeToolBar(this); + m_storyTreeView = new GuiStoryTreeView(this); + m_mainStatus = new GuiMainStatus(this); + m_docEditor = new GuiDocEditor(this); // Assemble Main Window m_splitMain = new QSplitter(Qt::Horizontal, this); m_splitMain->setContentsMargins(4, 4, 4, 4); m_splitMain->setOpaqueResize(false); - m_splitMain->addWidget(m_storyTree); + m_splitMain->addWidget(m_storyTreeView); m_splitMain->addWidget(m_docEditor); this->addToolBar(Qt::TopToolBarArea, m_mainToolBar); @@ -66,6 +70,24 @@ GuiMain::GuiMain(QWidget *parent) : QMainWindow(parent) { return; } +/* + Project Functions + ================= +*/ + +void GuiMain::openProject(const QString &path) { + m_data->openProject(path); + m_storyTreeView->setModel(m_data->storyModel()); +}; + +bool GuiMain::saveProject() { + return m_data->saveProject(); +} + +bool GuiMain::closeProject() { + return true; +}; + /* GUI Functions ============= diff --git a/src/guimain.h b/src/guimain.h index 4d77cff..ffd5f6c 100644 --- a/src/guimain.h +++ b/src/guimain.h @@ -23,16 +23,18 @@ along with this program. If not, see . #define GUIMAIN_H #include "collett.h" +#include "data.h" #include "maintoolbar.h" #include "treetoolbar.h" #include "statusbar.h" -#include "storytree.h" +#include "storytreeview.h" #include "doceditor.h" #include #include #include #include +#include namespace Collett { @@ -44,16 +46,21 @@ class GuiMain : public QMainWindow GuiMain(QWidget *parent=nullptr); ~GuiMain() {}; + void openProject(const QString &path); + bool saveProject(); + bool closeProject(); + bool closeMain(); private: + CollettData *m_data; // Collett Widgets - GuiMainToolBar *m_mainToolBar; - GuiTreeToolBar *m_treeToolBar; - GuiStoryTree *m_storyTree; - GuiDocEditor *m_docEditor; - GuiMainStatus *m_mainStatus; + GuiMainToolBar *m_mainToolBar; + GuiTreeToolBar *m_treeToolBar; + GuiStoryTreeView *m_storyTreeView; + GuiDocEditor *m_docEditor; + GuiMainStatus *m_mainStatus; // GUI Widgets QSplitter *m_splitMain; diff --git a/src/main.cpp b/src/main.cpp index a91e110..10a14e5 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -82,9 +82,9 @@ int main(int argc, char *argv[]) { Collett::GuiMain mainGUI; mainGUI.show(); - // if (parser.isSet(openFlag)) { - // mainGUI.openProject(parser.value(openFlag)); - // } + if (parser.isSet(openFlag)) { + mainGUI.openProject(parser.value(openFlag)); + } return app.exec(); } diff --git a/src/project/project.cpp b/src/project/project.cpp new file mode 100644 index 0000000..fe4eb0e --- /dev/null +++ b/src/project/project.cpp @@ -0,0 +1,62 @@ +/* +Collett – Project Class +======================= + +This file is a part of Collett +Copyright 2020–2021, Veronica Berglyd Olsen + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program. If not, see . +*/ + +#include "project.h" + +namespace Collett { + +Project::Project(const QString &path) { +} + +Project::~Project() { +} + +/* + Class Methods + ============= +*/ + +void Project::clearError() { + +} + +bool Project::openProject() { + return true; +} + +bool Project::saveProject() { + return true; +} + +/* + Class Getters + ============= +*/ + +bool Project::hasProject() const { + return m_hasProject; +} + +bool Project::hasError() const { + return m_hasError; +} + +} // namespace Collett diff --git a/src/project/project.h b/src/project/project.h new file mode 100644 index 0000000..c4e8b63 --- /dev/null +++ b/src/project/project.h @@ -0,0 +1,57 @@ +/* +Collett – Project Class +======================= + +This file is a part of Collett +Copyright 2020–2021, Veronica Berglyd Olsen + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program. If not, see . +*/ + +#ifndef COLLETT_PROJECT_H +#define COLLETT_PROJECT_H + +#include "collett.h" + +#include +#include + +namespace Collett { + +class Project : public QObject +{ + Q_OBJECT + +public: + Project(const QString &path); + ~Project(); + + // Class Methods + void clearError(); + bool openProject(); + bool saveProject(); + + // Getters + bool hasProject() const; + bool hasError() const; + +private: + bool m_hasProject; + bool m_hasError; + QString m_lastError; + +}; +} // namespace Collett + +#endif // COLLETT_PROJECT_H diff --git a/src/project/storyitem.cpp b/src/project/storyitem.cpp index 1ae1ec6..d73758a 100644 --- a/src/project/storyitem.cpp +++ b/src/project/storyitem.cpp @@ -26,42 +26,42 @@ along with this program. If not, see . namespace Collett { -CollettStoryItem::CollettStoryItem(const QVector &data, CollettStoryItem *parent) +StoryItem::StoryItem(const QVector &data, StoryItem *parent) : m_itemData(data), m_parentItem(parent) {} -CollettStoryItem::~CollettStoryItem() { +StoryItem::~StoryItem() { qDeleteAll(m_childItems); } -void CollettStoryItem::appendChild(CollettStoryItem *item) { +void StoryItem::appendChild(StoryItem *item) { m_childItems.append(item); } -CollettStoryItem *CollettStoryItem::child(int row) { +StoryItem *StoryItem::child(int row) { if (row < 0 || row >= m_childItems.size()) { return nullptr; } return m_childItems.at(row); } -int CollettStoryItem::childCount() const { +int StoryItem::childCount() const { return m_childItems.count(); } -int CollettStoryItem::row() const { +int StoryItem::row() const { if (m_parentItem) { - return m_parentItem->m_childItems.indexOf(const_cast(this)); + return m_parentItem->m_childItems.indexOf(const_cast(this)); } else { return 0; } } -int CollettStoryItem::columnCount() const { +int StoryItem::columnCount() const { return m_itemData.count(); } -QVariant CollettStoryItem::data(int column) const { +QVariant StoryItem::data(int column) const { if (column < 0 || column >= m_itemData.size()) { return QVariant(); } else { @@ -69,7 +69,7 @@ QVariant CollettStoryItem::data(int column) const { } } -CollettStoryItem *CollettStoryItem::parentItem() { +StoryItem *StoryItem::parentItem() { return m_parentItem; } diff --git a/src/project/storyitem.h b/src/project/storyitem.h index 9879366..9317f89 100644 --- a/src/project/storyitem.h +++ b/src/project/storyitem.h @@ -27,25 +27,25 @@ along with this program. If not, see . namespace Collett { -class CollettStoryItem +class StoryItem { public: - explicit CollettStoryItem(const QVector &data, CollettStoryItem *parentItem=nullptr); - ~CollettStoryItem(); + explicit StoryItem(const QVector &data, StoryItem *parentItem=nullptr); + ~StoryItem(); - void appendChild(CollettStoryItem *child); + void appendChild(StoryItem *child); - CollettStoryItem *child(int row); + StoryItem *child(int row); int childCount() const; int columnCount() const; QVariant data(int column) const; int row() const; - CollettStoryItem *parentItem(); + StoryItem *parentItem(); private: - QVector m_childItems; + QVector m_childItems; QVector m_itemData; - CollettStoryItem *m_parentItem; + StoryItem *m_parentItem; }; } // namespace Collett diff --git a/src/project/storymodel.cpp b/src/project/storymodel.cpp index 1210235..279c570 100644 --- a/src/project/storymodel.cpp +++ b/src/project/storymodel.cpp @@ -28,38 +28,38 @@ along with this program. If not, see . namespace Collett { /* - CollettStoryModel - ----------------- + StoryModel + ---------- The data model of the project's stroy content. Example: https://doc.qt.io/qt-5/qtwidgets-itemviews-simpletreemodel-example.html */ -CollettStoryModel::CollettStoryModel(const QString &data, QObject *parent) - : QAbstractItemModel(parent) +StoryModel::StoryModel(Project *project, QObject *parent) + : m_project(project), QAbstractItemModel(parent) { - rootItem = new CollettStoryItem({tr("Title"), tr("Words")}); - rootItem->appendChild(new CollettStoryItem({"Title Page", 100}, rootItem)); - rootItem->appendChild(new CollettStoryItem({"Chapter 1", 150}, rootItem)); + m_rootItem = new StoryItem({tr("Title"), tr("Words")}); + m_rootItem->appendChild(new StoryItem({"Title Page", 100}, m_rootItem)); + m_rootItem->appendChild(new StoryItem({"Chapter 1", 150}, m_rootItem)); } -CollettStoryModel::~CollettStoryModel() { - delete rootItem; +StoryModel::~StoryModel() { + delete m_rootItem; } -QModelIndex CollettStoryModel::index(int row, int column, const QModelIndex &parent) const { +QModelIndex StoryModel::index(int row, int column, const QModelIndex &parent) const { if (!hasIndex(row, column, parent)) { return QModelIndex(); } - CollettStoryItem *parentItem; + StoryItem *parentItem; if (!parent.isValid()) { - parentItem = rootItem; + parentItem = m_rootItem; } else { - parentItem = static_cast(parent.internalPointer()); + parentItem = static_cast(parent.internalPointer()); } - CollettStoryItem *childItem = parentItem->child(row); + StoryItem *childItem = parentItem->child(row); if (childItem) { return createIndex(row, column, childItem); } else { @@ -67,47 +67,47 @@ QModelIndex CollettStoryModel::index(int row, int column, const QModelIndex &par } } -QModelIndex CollettStoryModel::parent(const QModelIndex &index) const { +QModelIndex StoryModel::parent(const QModelIndex &index) const { if (!index.isValid()) { return QModelIndex(); } - CollettStoryItem *childItem = static_cast(index.internalPointer()); - CollettStoryItem *parentItem = childItem->parentItem(); + StoryItem *childItem = static_cast(index.internalPointer()); + StoryItem *parentItem = childItem->parentItem(); - if (parentItem == rootItem) { + if (parentItem == m_rootItem) { return QModelIndex(); } else { return createIndex(parentItem->row(), 0, parentItem); } } -int CollettStoryModel::rowCount(const QModelIndex &parent) const { +int StoryModel::rowCount(const QModelIndex &parent) const { - CollettStoryItem *parentItem; + StoryItem *parentItem; if (parent.column() > 0) { return 0; } if (!parent.isValid()) { - parentItem = rootItem; + parentItem = m_rootItem; } else { - parentItem = static_cast(parent.internalPointer()); + parentItem = static_cast(parent.internalPointer()); } return parentItem->childCount(); } -int CollettStoryModel::columnCount(const QModelIndex &parent) const { +int StoryModel::columnCount(const QModelIndex &parent) const { if (parent.isValid()) { - return static_cast(parent.internalPointer())->columnCount(); + return static_cast(parent.internalPointer())->columnCount(); } else { - return rootItem->columnCount(); + return m_rootItem->columnCount(); } } -QVariant CollettStoryModel::data(const QModelIndex &index, int role) const { +QVariant StoryModel::data(const QModelIndex &index, int role) const { if (!index.isValid()) { return QVariant(); @@ -116,12 +116,12 @@ QVariant CollettStoryModel::data(const QModelIndex &index, int role) const { return QVariant(); } - CollettStoryItem *item = static_cast(index.internalPointer()); + StoryItem *item = static_cast(index.internalPointer()); return item->data(index.column()); } -Qt::ItemFlags CollettStoryModel::flags(const QModelIndex &index) const { +Qt::ItemFlags StoryModel::flags(const QModelIndex &index) const { if (!index.isValid()) { return Qt::NoItemFlags; } else { @@ -129,10 +129,10 @@ Qt::ItemFlags CollettStoryModel::flags(const QModelIndex &index) const { } } -QVariant CollettStoryModel::headerData(int section, Qt::Orientation orientation, int role) const { +QVariant StoryModel::headerData(int section, Qt::Orientation orientation, int role) const { if (orientation == Qt::Horizontal && role == Qt::DisplayRole) { - return rootItem->data(section); + return m_rootItem->data(section); } else { return QVariant(); } diff --git a/src/project/storymodel.h b/src/project/storymodel.h index 81f6f03..eaa9c98 100644 --- a/src/project/storymodel.h +++ b/src/project/storymodel.h @@ -19,9 +19,10 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . */ -#ifndef COLLETTSTORYMODEL_H -#define COLLETTSTORYMODEL_H +#ifndef COLLETT_STORYMODEL_H +#define COLLETT_STORYMODEL_H +#include "project.h" #include "storyitem.h" #include @@ -31,13 +32,13 @@ along with this program. If not, see . namespace Collett { -class CollettStoryModel : public QAbstractItemModel +class StoryModel : public QAbstractItemModel { Q_OBJECT public: - explicit CollettStoryModel(const QString &data, QObject *parent=nullptr); - ~CollettStoryModel(); + explicit StoryModel(Project *project, QObject *parent=nullptr); + ~StoryModel(); QVariant data(const QModelIndex &index, int role) const override; Qt::ItemFlags flags(const QModelIndex &index) const override; @@ -48,9 +49,10 @@ class CollettStoryModel : public QAbstractItemModel int columnCount(const QModelIndex &parent = QModelIndex()) const override; private: - CollettStoryItem *rootItem; + Project *m_project; + StoryItem *m_rootItem; }; } // namespace Collett -#endif // COLLETTSTORYMODEL_H +#endif // COLLETT_STORYMODEL_H diff --git a/src/gui/storytree.cpp b/src/project/storytree.cpp similarity index 77% rename from src/gui/storytree.cpp rename to src/project/storytree.cpp index 755a307..1a111ae 100644 --- a/src/gui/storytree.cpp +++ b/src/project/storytree.cpp @@ -1,6 +1,6 @@ /* -Collett – GUI Story Tree Class -============================== +Collett – Project Tree Class +============================ This file is a part of Collett Copyright 2020–2021, Veronica Berglyd Olsen @@ -20,17 +20,15 @@ along with this program. If not, see . */ #include "storytree.h" -#include "storymodel.h" #include -#include namespace Collett { -GuiStoryTree::GuiStoryTree(QWidget *parent) - : QTreeView(parent) -{ - this->setModel(new CollettStoryModel("", this)); +StoryTree::StoryTree(QObject *parent) : QObject(parent) { +} + +StoryTree::~StoryTree() { } } // namespace Collett diff --git a/src/gui/storytree.h b/src/project/storytree.h similarity index 75% rename from src/gui/storytree.h rename to src/project/storytree.h index ece84d7..ab93f09 100644 --- a/src/gui/storytree.h +++ b/src/project/storytree.h @@ -1,6 +1,6 @@ /* -Collett – GUI Story Tree Class -============================== +Collett – Project Tree Class +============================ This file is a part of Collett Copyright 2020–2021, Veronica Berglyd Olsen @@ -19,23 +19,22 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . */ -#ifndef GUISTORYTREE_H -#define GUISTORYTREE_H +#ifndef COLLETT_STORYTREE_H +#define COLLETT_STORYTREE_H #include -#include namespace Collett { -class GuiStoryTree : public QTreeView +class StoryTree : public QObject { Q_OBJECT public: - GuiStoryTree(QWidget *parent=nullptr); - ~GuiStoryTree() {}; + StoryTree(QObject *parent=nullptr); + ~StoryTree(); }; } // namespace Collett -#endif // GUISTORYTREE_H +#endif // COLLETT_STORYTREE_H From 9aa9791bf62f53a2d4da3b047199285dd41e0f08 Mon Sep 17 00:00:00 2001 From: Veronica Berglyd Olsen <1619840+vkbo@users.noreply.github.com> Date: Sun, 28 Nov 2021 18:56:33 +0100 Subject: [PATCH 3/9] Read the main project file --- sample/project.collett | 2 + src/collett.h | 2 + src/project/project.cpp | 115 +++++++++++++++++++++++++++++++++++-- src/project/project.h | 26 ++++++++- src/project/storymodel.cpp | 2 +- 5 files changed, 139 insertions(+), 8 deletions(-) create mode 100644 sample/project.collett diff --git a/sample/project.collett b/sample/project.collett new file mode 100644 index 0000000..566a247 --- /dev/null +++ b/sample/project.collett @@ -0,0 +1,2 @@ +Collett 0.0.1-alpha0 +Project 0.1 diff --git a/src/collett.h b/src/collett.h index d0ec981..699c6fd 100644 --- a/src/collett.h +++ b/src/collett.h @@ -26,4 +26,6 @@ along with this program. If not, see . #define COL_VERSION_NUM 0x000001a0 #define COL_VERSION_DATE "2021-11-14" +#define COL_PROJECT_FILE_NAME "project.collett" + #endif // COLLETT_H diff --git a/src/project/project.cpp b/src/project/project.cpp index fe4eb0e..0b30aab 100644 --- a/src/project/project.cpp +++ b/src/project/project.cpp @@ -19,11 +19,69 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . */ +#include "collett.h" #include "project.h" +#include +#include +#include +#include +#include + namespace Collett { Project::Project(const QString &path) { + + this->clearError(); + m_hasProject = false; + m_pathValid = false; + + QFileInfo fObj(path); + if (!fObj.exists()) { + setError(tr("Project not found at: %1").arg(path)); + return; + } + + // If the path is a file, go one level up + QDir projDir = QDir(path).absolutePath(); + if (fObj.isFile()) { + projDir = fObj.dir().absolutePath(); + } + + QDir projFile = projDir.filePath(COL_PROJECT_FILE_NAME); + if (!QFileInfo::exists(projFile.path())) { + setError(tr("Project not found at: %1").arg(projFile.path())); + return; + } + + // Set the path variables + m_projectPath = projDir; + m_projectFile = projFile; + m_contentPath = QDir(m_projectPath.path() + "/content"); + + qInfo() << "Loading Project:" << m_projectPath.path(); + + // Check the main project file + if (!this->loadProjectFile()) { + setError(tr("Not a Collett project: %1").arg(projFile.path())); + return; + } + + // Verify that the needed project folders exist + if (!m_contentPath.exists()) { + if (m_contentPath.mkdir("content")) { + qDebug() << "Created folder:" << m_contentPath.path(); + } else { + setError(tr("Could not create folder: %1").arg(m_contentPath.path())); + return; + } + } + + m_pathValid = true; + + qDebug() << "Project Path:" << m_projectPath.path(); + qDebug() << "Project File:" << m_projectFile.path(); + qDebug() << "Content Path:" << m_contentPath.path(); } Project::~Project() { @@ -34,10 +92,6 @@ Project::~Project() { ============= */ -void Project::clearError() { - -} - bool Project::openProject() { return true; } @@ -47,16 +101,65 @@ bool Project::saveProject() { } /* - Class Getters - ============= + Project Getters + =============== */ bool Project::hasProject() const { return m_hasProject; } +/* + Handler Functions + ================= +*/ + +bool Project::loadProjectFile() { + + QFile prjFile(m_projectFile.path()); + + if (prjFile.open(QIODevice::ReadOnly)) { + QString line; + QTextStream inStream(&prjFile); + while (!inStream.atEnd()) { + line = inStream.readLine(); + if (line.startsWith("Collett ")) { + m_collettVersion = line.remove(0, 8); + } else if (line.startsWith("Project ")) { + m_projectVersion = line.remove(0, 8); + } + } + prjFile.close(); + qInfo() << "File Collett Version:" << m_collettVersion; + qInfo() << "File Project Version:" << m_projectVersion; + return true; + } else { + return false; + } +} + +/* + Error Handling + ============== +*/ + bool Project::hasError() const { return m_hasError; } +QString Project::lastError() const { + return m_lastError; +} + +void Project::clearError() { + m_hasError = false; + m_lastError = ""; +} + +void Project::setError(const QString &error) { + m_hasError = true; + m_lastError = error; + qCritical() << error; +} + } // namespace Collett diff --git a/src/project/project.h b/src/project/project.h index c4e8b63..b5ce848 100644 --- a/src/project/project.h +++ b/src/project/project.h @@ -23,9 +23,11 @@ along with this program. If not, see . #define COLLETT_PROJECT_H #include "collett.h" +#include "storytree.h" #include #include +#include namespace Collett { @@ -38,7 +40,6 @@ class Project : public QObject ~Project(); // Class Methods - void clearError(); bool openProject(); bool saveProject(); @@ -46,11 +47,34 @@ class Project : public QObject bool hasProject() const; bool hasError() const; + // Error Handling + void clearError(); + QString lastError() const; + private: bool m_hasProject; bool m_hasError; QString m_lastError; + // Project Paths + QDir m_projectPath; + QDir m_projectFile; + QDir m_contentPath; + bool m_pathValid; + + // Project Meta + QString m_collettVersion = ""; + QString m_projectVersion = ""; + + // Content + StoryTree *m_storyTree; + + // Handler Functions + bool loadProjectFile(); + + // Error Handling + void setError(const QString &error); + }; } // namespace Collett diff --git a/src/project/storymodel.cpp b/src/project/storymodel.cpp index 279c570..2428fe0 100644 --- a/src/project/storymodel.cpp +++ b/src/project/storymodel.cpp @@ -35,7 +35,7 @@ namespace Collett { */ StoryModel::StoryModel(Project *project, QObject *parent) - : m_project(project), QAbstractItemModel(parent) + : QAbstractItemModel(parent), m_project(project) { m_rootItem = new StoryItem({tr("Title"), tr("Words")}); m_rootItem->appendChild(new StoryItem({"Title Page", 100}, m_rootItem)); From 9b2e67f53591910d2f3024ea557e49cc60a716ac Mon Sep 17 00:00:00 2001 From: Veronica Berglyd Olsen <1619840+vkbo@users.noreply.github.com> Date: Sun, 28 Nov 2021 22:53:25 +0100 Subject: [PATCH 4/9] Basic loading and saving of core project --- CMakeLists.txt | 3 +- i18n/collett_en_US.ts | 14 +++++ i18n/collett_nb_NO.ts | 14 +++++ src/data.cpp | 8 +-- src/{project => gui}/storytree.cpp | 13 +++-- src/gui/{storytreeview.h => storytree.h} | 12 ++-- src/gui/storytreeview.cpp | 35 ------------ src/guimain.cpp | 6 +- src/guimain.h | 4 +- src/project/project.cpp | 73 +++++++++++++++++++----- src/project/project.h | 10 ++-- src/project/storymodel.cpp | 4 +- src/project/storymodel.h | 6 +- src/project/storytree.h | 40 ------------- 14 files changed, 118 insertions(+), 124 deletions(-) rename src/{project => gui}/storytree.cpp (81%) rename src/gui/{storytreeview.h => storytree.h} (81%) delete mode 100644 src/gui/storytreeview.cpp delete mode 100644 src/project/storytree.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 7b49283..8c6113e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -84,12 +84,11 @@ list(APPEND SRC_FILES src/editor/doceditor src/gui/maintoolbar src/gui/statusbar - src/gui/storytreeview + src/gui/storytree src/gui/treetoolbar src/project/project src/project/storyitem src/project/storymodel - src/project/storytree src/data src/guimain src/main diff --git a/i18n/collett_en_US.ts b/i18n/collett_en_US.ts index 3c0ad8b..8d294cb 100644 --- a/i18n/collett_en_US.ts +++ b/i18n/collett_en_US.ts @@ -55,6 +55,20 @@ + + Collett::Project + + + + Project not found at: %1 + + + + + Could not create folder: %1 + + + Collett::StoryModel diff --git a/i18n/collett_nb_NO.ts b/i18n/collett_nb_NO.ts index 6af7db7..79a3b99 100644 --- a/i18n/collett_nb_NO.ts +++ b/i18n/collett_nb_NO.ts @@ -55,6 +55,20 @@ + + Collett::Project + + + + Project not found at: %1 + + + + + Could not create folder: %1 + + + Collett::StoryModel diff --git a/src/data.cpp b/src/data.cpp index e734a93..8365baa 100644 --- a/src/data.cpp +++ b/src/data.cpp @@ -42,11 +42,9 @@ class CollettDataPrivate ~CollettDataPrivate() { qDebug() << "Deconstructing: CollettDataPrivate"; delete m_project; - delete m_storyModel; }; - Project *m_project; - StoryModel *m_storyModel; + Project *m_project; bool m_hasProject = false; }; @@ -84,8 +82,6 @@ bool CollettData::openProject(const QString &path) { bool status = d->m_project->openProject(); d->m_hasProject = d->m_project->hasProject(); - d->m_storyModel = new StoryModel(d->m_project); - return status; } @@ -113,7 +109,7 @@ StoryModel *CollettData::storyModel() { Q_D(CollettData); if (d->m_hasProject) { - return d->m_storyModel; + return d->m_project->storyModel(); } else { return nullptr; } diff --git a/src/project/storytree.cpp b/src/gui/storytree.cpp similarity index 81% rename from src/project/storytree.cpp rename to src/gui/storytree.cpp index 1a111ae..ced05c0 100644 --- a/src/project/storytree.cpp +++ b/src/gui/storytree.cpp @@ -1,6 +1,6 @@ /* -Collett – Project Tree Class -============================ +Collett – GUI Story Tree Class +============================== This file is a part of Collett Copyright 2020–2021, Veronica Berglyd Olsen @@ -20,15 +20,16 @@ along with this program. If not, see . */ #include "storytree.h" +#include "storymodel.h" #include +#include namespace Collett { -StoryTree::StoryTree(QObject *parent) : QObject(parent) { -} - -StoryTree::~StoryTree() { +GuiStoryTree::GuiStoryTree(QWidget *parent) + : QTreeView(parent) +{ } } // namespace Collett diff --git a/src/gui/storytreeview.h b/src/gui/storytree.h similarity index 81% rename from src/gui/storytreeview.h rename to src/gui/storytree.h index ec09fce..712110d 100644 --- a/src/gui/storytreeview.h +++ b/src/gui/storytree.h @@ -19,23 +19,23 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . */ -#ifndef GUI_STORYTREEVIEW_H -#define GUI_STORYTREEVIEW_H +#ifndef GUI_STORYTREE_H +#define GUI_STORYTREE_H #include #include namespace Collett { -class GuiStoryTreeView : public QTreeView +class GuiStoryTree : public QTreeView { Q_OBJECT public: - GuiStoryTreeView(QWidget *parent=nullptr); - ~GuiStoryTreeView() {}; + GuiStoryTree(QWidget *parent=nullptr); + ~GuiStoryTree() {}; }; } // namespace Collett -#endif // GUI_STORYTREEVIEW_H +#endif // GUI_STORYTREE_H diff --git a/src/gui/storytreeview.cpp b/src/gui/storytreeview.cpp deleted file mode 100644 index 4e8779d..0000000 --- a/src/gui/storytreeview.cpp +++ /dev/null @@ -1,35 +0,0 @@ -/* -Collett – GUI Story Tree Class -============================== - -This file is a part of Collett -Copyright 2020–2021, Veronica Berglyd Olsen - -This program is free software: you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation, either version 3 of the License, or -(at your option) any later version. - -This program is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program. If not, see . -*/ - -#include "storytreeview.h" -#include "storymodel.h" - -#include -#include - -namespace Collett { - -GuiStoryTreeView::GuiStoryTreeView(QWidget *parent) - : QTreeView(parent) -{ -} - -} // namespace Collett diff --git a/src/guimain.cpp b/src/guimain.cpp index 6630223..9f792ad 100644 --- a/src/guimain.cpp +++ b/src/guimain.cpp @@ -25,7 +25,7 @@ along with this program. If not, see . #include "maintoolbar.h" #include "treetoolbar.h" #include "statusbar.h" -#include "storytreeview.h" +#include "storytree.h" #include "doceditor.h" #include @@ -41,7 +41,7 @@ GuiMain::GuiMain(QWidget *parent) : QMainWindow(parent) { // Collett Widgets m_mainToolBar = new GuiMainToolBar(this); m_treeToolBar = new GuiTreeToolBar(this); - m_storyTreeView = new GuiStoryTreeView(this); + m_storyTreeView = new GuiStoryTree(this); m_mainStatus = new GuiMainStatus(this); m_docEditor = new GuiDocEditor(this); @@ -95,6 +95,8 @@ bool GuiMain::closeProject() { bool GuiMain::closeMain() { + m_data->saveProject(); + // Save Settings CollettSettings *mainConf = CollettSettings::instance(); if (!this->isFullScreen()) { diff --git a/src/guimain.h b/src/guimain.h index ffd5f6c..6eda3cd 100644 --- a/src/guimain.h +++ b/src/guimain.h @@ -27,7 +27,7 @@ along with this program. If not, see . #include "maintoolbar.h" #include "treetoolbar.h" #include "statusbar.h" -#include "storytreeview.h" +#include "storytree.h" #include "doceditor.h" #include @@ -58,7 +58,7 @@ class GuiMain : public QMainWindow // Collett Widgets GuiMainToolBar *m_mainToolBar; GuiTreeToolBar *m_treeToolBar; - GuiStoryTreeView *m_storyTreeView; + GuiStoryTree *m_storyTreeView; GuiDocEditor *m_docEditor; GuiMainStatus *m_mainStatus; diff --git a/src/project/project.cpp b/src/project/project.cpp index 0b30aab..c4f0d8c 100644 --- a/src/project/project.cpp +++ b/src/project/project.cpp @@ -21,12 +21,15 @@ along with this program. If not, see . #include "collett.h" #include "project.h" +#include "storymodel.h" -#include -#include #include #include +#include +#include #include +#include +#include namespace Collett { @@ -36,6 +39,8 @@ Project::Project(const QString &path) { m_hasProject = false; m_pathValid = false; + m_storyModel = new StoryModel(this); + QFileInfo fObj(path); if (!fObj.exists()) { setError(tr("Project not found at: %1").arg(path)); @@ -59,17 +64,9 @@ Project::Project(const QString &path) { m_projectFile = projFile; m_contentPath = QDir(m_projectPath.path() + "/content"); - qInfo() << "Loading Project:" << m_projectPath.path(); - - // Check the main project file - if (!this->loadProjectFile()) { - setError(tr("Not a Collett project: %1").arg(projFile.path())); - return; - } - // Verify that the needed project folders exist if (!m_contentPath.exists()) { - if (m_contentPath.mkdir("content")) { + if (m_projectPath.mkdir("content")) { qDebug() << "Created folder:" << m_contentPath.path(); } else { setError(tr("Could not create folder: %1").arg(m_contentPath.path())); @@ -85,6 +82,7 @@ Project::Project(const QString &path) { } Project::~Project() { + delete m_storyModel; } /* @@ -93,11 +91,31 @@ Project::~Project() { */ bool Project::openProject() { - return true; + + qInfo() << "Loading Project:" << m_projectPath.path(); + if (!m_pathValid) { + qWarning() << "Cannot load project from this path"; + return false; + } + + bool mainFile = loadProjectFile(); + + m_hasProject = mainFile; + + return m_hasProject; } bool Project::saveProject() { - return true; + + qInfo() << "Saving Project:" << m_projectPath.path(); + if (!m_hasProject) { + qWarning() << "No project open, nothing to save"; + return false; + } + + bool mainFile = saveProjectFile(); + + return mainFile; } /* @@ -109,15 +127,21 @@ bool Project::hasProject() const { return m_hasProject; } +StoryModel *Project::storyModel() { + return m_storyModel; +} + /* - Handler Functions + Main Project File ================= */ bool Project::loadProjectFile() { - QFile prjFile(m_projectFile.path()); + bool hasCol = false; + bool hasPro = false; + QFile prjFile(m_projectFile.path()); if (prjFile.open(QIODevice::ReadOnly)) { QString line; QTextStream inStream(&prjFile); @@ -125,13 +149,32 @@ bool Project::loadProjectFile() { line = inStream.readLine(); if (line.startsWith("Collett ")) { m_collettVersion = line.remove(0, 8); + hasCol = true; } else if (line.startsWith("Project ")) { m_projectVersion = line.remove(0, 8); + hasPro = true; } } prjFile.close(); qInfo() << "File Collett Version:" << m_collettVersion; qInfo() << "File Project Version:" << m_projectVersion; + return hasCol & hasPro; + } else { + return false; + } +} + +bool Project::saveProjectFile() { + + QByteArray colLine = "Collett " + QByteArray(COL_VERSION_STR); + QByteArray proLine = "Project 0.1"; + + QFile prjFile(m_projectFile.path()); + if (prjFile.open(QIODevice::WriteOnly)) { + QTextStream outData(&prjFile); + outData << "Collett " << QString(COL_VERSION_STR) << Qt::endl; + outData << "Project 0.1" << Qt::endl; + prjFile.close(); return true; } else { return false; diff --git a/src/project/project.h b/src/project/project.h index b5ce848..055982d 100644 --- a/src/project/project.h +++ b/src/project/project.h @@ -23,11 +23,11 @@ along with this program. If not, see . #define COLLETT_PROJECT_H #include "collett.h" -#include "storytree.h" +#include "storymodel.h" +#include #include #include -#include namespace Collett { @@ -46,6 +46,7 @@ class Project : public QObject // Getters bool hasProject() const; bool hasError() const; + StoryModel *storyModel(); // Error Handling void clearError(); @@ -67,10 +68,11 @@ class Project : public QObject QString m_projectVersion = ""; // Content - StoryTree *m_storyTree; + StoryModel *m_storyModel; - // Handler Functions + // Main Project File bool loadProjectFile(); + bool saveProjectFile(); // Error Handling void setError(const QString &error); diff --git a/src/project/storymodel.cpp b/src/project/storymodel.cpp index 2428fe0..d670131 100644 --- a/src/project/storymodel.cpp +++ b/src/project/storymodel.cpp @@ -34,8 +34,8 @@ namespace Collett { Example: https://doc.qt.io/qt-5/qtwidgets-itemviews-simpletreemodel-example.html */ -StoryModel::StoryModel(Project *project, QObject *parent) - : QAbstractItemModel(parent), m_project(project) +StoryModel::StoryModel(QObject *parent) + : QAbstractItemModel(parent) { m_rootItem = new StoryItem({tr("Title"), tr("Words")}); m_rootItem->appendChild(new StoryItem({"Title Page", 100}, m_rootItem)); diff --git a/src/project/storymodel.h b/src/project/storymodel.h index eaa9c98..528442a 100644 --- a/src/project/storymodel.h +++ b/src/project/storymodel.h @@ -22,13 +22,12 @@ along with this program. If not, see . #ifndef COLLETT_STORYMODEL_H #define COLLETT_STORYMODEL_H -#include "project.h" #include "storyitem.h" #include #include -#include #include +#include namespace Collett { @@ -37,7 +36,7 @@ class StoryModel : public QAbstractItemModel Q_OBJECT public: - explicit StoryModel(Project *project, QObject *parent=nullptr); + explicit StoryModel(QObject *parent=nullptr); ~StoryModel(); QVariant data(const QModelIndex &index, int role) const override; @@ -49,7 +48,6 @@ class StoryModel : public QAbstractItemModel int columnCount(const QModelIndex &parent = QModelIndex()) const override; private: - Project *m_project; StoryItem *m_rootItem; }; diff --git a/src/project/storytree.h b/src/project/storytree.h deleted file mode 100644 index ab93f09..0000000 --- a/src/project/storytree.h +++ /dev/null @@ -1,40 +0,0 @@ -/* -Collett – Project Tree Class -============================ - -This file is a part of Collett -Copyright 2020–2021, Veronica Berglyd Olsen - -This program is free software: you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation, either version 3 of the License, or -(at your option) any later version. - -This program is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program. If not, see . -*/ - -#ifndef COLLETT_STORYTREE_H -#define COLLETT_STORYTREE_H - -#include - -namespace Collett { - -class StoryTree : public QObject -{ - Q_OBJECT - -public: - StoryTree(QObject *parent=nullptr); - ~StoryTree(); - -}; -} // namespace Collett - -#endif // COLLETT_STORYTREE_H From c0df8db5f5ddaa8f99c8932bf7b5dbd4baaf8c11 Mon Sep 17 00:00:00 2001 From: Veronica Berglyd Olsen <1619840+vkbo@users.noreply.github.com> Date: Mon, 29 Nov 2021 00:10:09 +0100 Subject: [PATCH 5/9] Implement story tree save functionality --- i18n/collett_en_US.ts | 13 ++++---- i18n/collett_nb_NO.ts | 13 ++++---- sample/data/story.json | 15 +++++++++ src/collett.h | 4 +++ src/project/project.cpp | 37 ++++++++++++++++++--- src/project/project.h | 5 ++- src/project/storyitem.cpp | 66 ++++++++++++++++++++++++++++++++++---- src/project/storyitem.h | 29 ++++++++++++----- src/project/storymodel.cpp | 37 ++++++++++++++++++--- src/project/storymodel.h | 5 +++ 10 files changed, 188 insertions(+), 36 deletions(-) create mode 100644 sample/data/story.json diff --git a/i18n/collett_en_US.ts b/i18n/collett_en_US.ts index 8d294cb..c87e960 100644 --- a/i18n/collett_en_US.ts +++ b/i18n/collett_en_US.ts @@ -58,13 +58,14 @@ Collett::Project - - + + Project not found at: %1 - + + Could not create folder: %1 @@ -72,12 +73,12 @@ Collett::StoryModel - - Title + + Label - + Words diff --git a/i18n/collett_nb_NO.ts b/i18n/collett_nb_NO.ts index 79a3b99..056b5c8 100644 --- a/i18n/collett_nb_NO.ts +++ b/i18n/collett_nb_NO.ts @@ -58,13 +58,14 @@ Collett::Project - - + + Project not found at: %1 - + + Could not create folder: %1 @@ -72,12 +73,12 @@ Collett::StoryModel - - Title + + Label - + Words diff --git a/sample/data/story.json b/sample/data/story.json new file mode 100644 index 0000000..af6fd9b --- /dev/null +++ b/sample/data/story.json @@ -0,0 +1,15 @@ +{ + "handle": "ROOT", + "xItems": [ + { + "handle": "5487e205-3957-4d80-b76d-0720f9972948", + "label": "Title Page", + "wCount": 0 + }, + { + "handle": "0baa14de-53b8-44c1-b60a-1ccde2efb76b", + "label": "Chapter 1", + "wCount": 0 + } + ] +} diff --git a/src/collett.h b/src/collett.h index 699c6fd..cf68c95 100644 --- a/src/collett.h +++ b/src/collett.h @@ -27,5 +27,9 @@ along with this program. If not, see . #define COL_VERSION_DATE "2021-11-14" #define COL_PROJECT_FILE_NAME "project.collett" +#define COL_STORY_FILE_NAME "story.json" +#define COL_NOTES_FILE_NAME "notes.json" + +#define COL_STORY_TREE_COL_COUNT 2 #endif // COLLETT_H diff --git a/src/project/project.cpp b/src/project/project.cpp index c4f0d8c..5d97920 100644 --- a/src/project/project.cpp +++ b/src/project/project.cpp @@ -30,6 +30,7 @@ along with this program. If not, see . #include #include #include +#include namespace Collett { @@ -63,6 +64,7 @@ Project::Project(const QString &path) { m_projectPath = projDir; m_projectFile = projFile; m_contentPath = QDir(m_projectPath.path() + "/content"); + m_dataPath = QDir(m_projectPath.path() + "/data"); // Verify that the needed project folders exist if (!m_contentPath.exists()) { @@ -73,12 +75,19 @@ Project::Project(const QString &path) { return; } } + if (!m_dataPath.exists()) { + if (m_projectPath.mkdir("data")) { + qDebug() << "Created folder:" << m_dataPath.path(); + } else { + setError(tr("Could not create folder: %1").arg(m_dataPath.path())); + return; + } + } m_pathValid = true; qDebug() << "Project Path:" << m_projectPath.path(); qDebug() << "Project File:" << m_projectFile.path(); - qDebug() << "Content Path:" << m_contentPath.path(); } Project::~Project() { @@ -114,8 +123,9 @@ bool Project::saveProject() { } bool mainFile = saveProjectFile(); + bool storyFile = saveStoryFile(); - return mainFile; + return mainFile & storyFile; } /* @@ -132,8 +142,8 @@ StoryModel *Project::storyModel() { } /* - Main Project File - ================= + Project Files + ============= */ bool Project::loadProjectFile() { @@ -181,6 +191,25 @@ bool Project::saveProjectFile() { } } +bool Project::loadStoryFile() { + return true; +} + +bool Project::saveStoryFile() { + + QFile storyFile(m_dataPath.filePath(COL_STORY_FILE_NAME)); + if (!storyFile.open(QIODevice::WriteOnly)) { + qWarning() << "Could not open story file"; + return false; + } + + QJsonDocument doc(m_storyModel->toJsonObject()); + storyFile.write(doc.toJson()); + storyFile.close(); + + return true; +} + /* Error Handling ============== diff --git a/src/project/project.h b/src/project/project.h index 055982d..f9ae550 100644 --- a/src/project/project.h +++ b/src/project/project.h @@ -61,6 +61,7 @@ class Project : public QObject QDir m_projectPath; QDir m_projectFile; QDir m_contentPath; + QDir m_dataPath; bool m_pathValid; // Project Meta @@ -70,9 +71,11 @@ class Project : public QObject // Content StoryModel *m_storyModel; - // Main Project File + // Project Files bool loadProjectFile(); bool saveProjectFile(); + bool loadStoryFile(); + bool saveStoryFile(); // Error Handling void setError(const QString &error); diff --git a/src/project/storyitem.cpp b/src/project/storyitem.cpp index d73758a..47dbd78 100644 --- a/src/project/storyitem.cpp +++ b/src/project/storyitem.cpp @@ -19,25 +19,68 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . */ +#include "collett.h" #include "storyitem.h" +#include #include #include +#include +#include +#include namespace Collett { -StoryItem::StoryItem(const QVector &data, StoryItem *parent) - : m_itemData(data), m_parentItem(parent) -{} +StoryItem::StoryItem(const QString &label, StoryItem *parent) + : m_parentItem(parent) +{ + m_handle = QUuid::createUuid(); + m_label = label; + m_wCount = 0; +} StoryItem::~StoryItem() { qDeleteAll(m_childItems); } +/* + Item Structure + ============== +*/ + void StoryItem::appendChild(StoryItem *item) { m_childItems.append(item); } +QJsonObject StoryItem::toJsonObject() { + + QJsonObject item; + QJsonArray children; + + for (qsizetype i=0; itoJsonObject()); + } + + if (m_parentItem == nullptr) { + item["handle"] = "ROOT"; + item["xItems"] = children; + } else { + item["handle"] = m_handle.toString(QUuid::WithoutBraces); + item["label"] = m_label; + item["wCount"] = m_wCount; + if (children.size() > 0) { + item["xItems"] = children; + } + } + + return item; +} + +/* + Model Access + ============ +*/ + StoryItem *StoryItem::child(int row) { if (row < 0 || row >= m_childItems.size()) { return nullptr; @@ -58,14 +101,23 @@ int StoryItem::row() const { } int StoryItem::columnCount() const { - return m_itemData.count(); + return COL_STORY_TREE_COL_COUNT; } QVariant StoryItem::data(int column) const { - if (column < 0 || column >= m_itemData.size()) { + switch (column) + { + case 0: + return QVariant(m_label); + break; + + case 1: + return QVariant(m_wCount); + break; + + default: return QVariant(); - } else { - return m_itemData.at(column); + break; } } diff --git a/src/project/storyitem.h b/src/project/storyitem.h index 9317f89..1fab18d 100644 --- a/src/project/storyitem.h +++ b/src/project/storyitem.h @@ -19,35 +19,48 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . */ -#ifndef COLLETTSTORYITEM_H -#define COLLETTSTORYITEM_H +#ifndef COLLETT_STORYITEM_H +#define COLLETT_STORYITEM_H +#include #include #include +#include namespace Collett { class StoryItem { public: - explicit StoryItem(const QVector &data, StoryItem *parentItem=nullptr); + explicit StoryItem(const QString &label, StoryItem *parentItem=nullptr); ~StoryItem(); + // Structure void appendChild(StoryItem *child); + QJsonObject toJsonObject(); - StoryItem *child(int row); + // Setters + void setLabel(const QString &label); + void setWordCount(int count); + + // Model Access + int row() const; int childCount() const; int columnCount() const; QVariant data(int column) const; - int row() const; + StoryItem *child(int row); StoryItem *parentItem(); private: QVector m_childItems; - QVector m_itemData; - StoryItem *m_parentItem; + StoryItem *m_parentItem; + + // Values + QUuid m_handle; + QString m_label; + int m_wCount; }; } // namespace Collett -#endif // COLLETTSTORYITEM_H +#endif // COLLETT_STORYITEM_H diff --git a/src/project/storymodel.cpp b/src/project/storymodel.cpp index d670131..da408af 100644 --- a/src/project/storymodel.cpp +++ b/src/project/storymodel.cpp @@ -23,6 +23,9 @@ along with this program. If not, see . #include "storyitem.h" #include +#include +#include +#include #include namespace Collett { @@ -37,15 +40,29 @@ namespace Collett { StoryModel::StoryModel(QObject *parent) : QAbstractItemModel(parent) { - m_rootItem = new StoryItem({tr("Title"), tr("Words")}); - m_rootItem->appendChild(new StoryItem({"Title Page", 100}, m_rootItem)); - m_rootItem->appendChild(new StoryItem({"Chapter 1", 150}, m_rootItem)); + m_rootItem = new StoryItem(""); + m_rootItem->appendChild(new StoryItem("Title Page", m_rootItem)); + m_rootItem->appendChild(new StoryItem("Chapter 1", m_rootItem)); } StoryModel::~StoryModel() { delete m_rootItem; } +/* + Class Methods + ============= +*/ + +QJsonObject StoryModel::toJsonObject() { + return m_rootItem->toJsonObject(); +} + +/* + Model Access + ============ +*/ + QModelIndex StoryModel::index(int row, int column, const QModelIndex &parent) const { if (!hasIndex(row, column, parent)) { @@ -132,7 +149,19 @@ Qt::ItemFlags StoryModel::flags(const QModelIndex &index) const { QVariant StoryModel::headerData(int section, Qt::Orientation orientation, int role) const { if (orientation == Qt::Horizontal && role == Qt::DisplayRole) { - return m_rootItem->data(section); + switch (section) { + case 0: + return QVariant(tr("Label")); + break; + + case 1: + return QVariant(tr("Words")); + break; + + default: + return QVariant(); + break; + } } else { return QVariant(); } diff --git a/src/project/storymodel.h b/src/project/storymodel.h index 528442a..57f8b51 100644 --- a/src/project/storymodel.h +++ b/src/project/storymodel.h @@ -26,6 +26,7 @@ along with this program. If not, see . #include #include +#include #include #include @@ -39,6 +40,10 @@ class StoryModel : public QAbstractItemModel explicit StoryModel(QObject *parent=nullptr); ~StoryModel(); + // Class Methods + QJsonObject toJsonObject(); + + // Model Access QVariant data(const QModelIndex &index, int role) const override; Qt::ItemFlags flags(const QModelIndex &index) const override; QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override; From 57bf6b65af51204d3d1939bbb305ea70cbc33a07 Mon Sep 17 00:00:00 2001 From: Veronica Berglyd Olsen <1619840+vkbo@users.noreply.github.com> Date: Thu, 2 Dec 2021 22:27:31 +0100 Subject: [PATCH 6/9] Add StoryItem setters and getters --- src/project/storyitem.cpp | 40 +++++++++++++++++++++++++++++++++++---- src/project/storyitem.h | 4 ++++ 2 files changed, 40 insertions(+), 4 deletions(-) diff --git a/src/project/storyitem.cpp b/src/project/storyitem.cpp index 47dbd78..38bd3d2 100644 --- a/src/project/storyitem.cpp +++ b/src/project/storyitem.cpp @@ -61,12 +61,13 @@ QJsonObject StoryItem::toJsonObject() { children.append(m_childItems.at(i)->toJsonObject()); } - if (m_parentItem == nullptr) { + if (!m_parentItem) { item["handle"] = "ROOT"; item["xItems"] = children; } else { item["handle"] = m_handle.toString(QUuid::WithoutBraces); item["label"] = m_label; + item["order"] = row(); item["wCount"] = m_wCount; if (children.size() > 0) { item["xItems"] = children; @@ -76,6 +77,37 @@ QJsonObject StoryItem::toJsonObject() { return item; } +/* + Setters + ======= +*/ + +void StoryItem::setLabel(const QString &label) { + m_label = label; +} + + +void StoryItem::setWordCount(int count) { + m_wCount = count > 0 ? count : 0; +} + +/* + Getters + ======= +*/ + +int StoryItem::wordCount() { + return m_wCount; +} + +int StoryItem::childWordCounts() { + int tCount = 0; + for (StoryItem* child : m_childItems) { + tCount += child->childWordCounts(); + } + return tCount; +} + /* Model Access ============ @@ -84,8 +116,9 @@ QJsonObject StoryItem::toJsonObject() { StoryItem *StoryItem::child(int row) { if (row < 0 || row >= m_childItems.size()) { return nullptr; + } else { + return m_childItems.at(row); } - return m_childItems.at(row); } int StoryItem::childCount() const { @@ -105,8 +138,7 @@ int StoryItem::columnCount() const { } QVariant StoryItem::data(int column) const { - switch (column) - { + switch (column) { case 0: return QVariant(m_label); break; diff --git a/src/project/storyitem.h b/src/project/storyitem.h index 1fab18d..9dca57d 100644 --- a/src/project/storyitem.h +++ b/src/project/storyitem.h @@ -43,6 +43,10 @@ class StoryItem void setLabel(const QString &label); void setWordCount(int count); + // Getters + int wordCount(); + int childWordCounts(); + // Model Access int row() const; int childCount() const; From 684662eeca0e4f05bc78de51d03c4a748b0bfd53 Mon Sep 17 00:00:00 2001 From: Veronica Berglyd Olsen <1619840+vkbo@users.noreply.github.com> Date: Sat, 4 Dec 2021 16:42:32 +0100 Subject: [PATCH 7/9] Added functionality to save project data --- i18n/collett_en_US.ts | 8 +-- i18n/collett_nb_NO.ts | 8 +-- sample/data/project.json | 12 ++++ sample/data/story.json | 6 +- src/collett.h | 7 ++- src/project/project.cpp | 128 ++++++++++++++++++++++++++++++++------- src/project/project.h | 10 ++- 7 files changed, 142 insertions(+), 37 deletions(-) create mode 100644 sample/data/project.json diff --git a/i18n/collett_en_US.ts b/i18n/collett_en_US.ts index c87e960..11c506d 100644 --- a/i18n/collett_en_US.ts +++ b/i18n/collett_en_US.ts @@ -58,14 +58,14 @@ Collett::Project - - + + Project not found at: %1 - - + + Could not create folder: %1 diff --git a/i18n/collett_nb_NO.ts b/i18n/collett_nb_NO.ts index 056b5c8..4727c28 100644 --- a/i18n/collett_nb_NO.ts +++ b/i18n/collett_nb_NO.ts @@ -58,14 +58,14 @@ Collett::Project - - + + Project not found at: %1 - - + + Could not create folder: %1 diff --git a/sample/data/project.json b/sample/data/project.json new file mode 100644 index 0000000..3bce656 --- /dev/null +++ b/sample/data/project.json @@ -0,0 +1,12 @@ +{ + "meta": { + "created": "2021-12-04T16:18:21", + "updated": "2021-12-04T16:18:23" + }, + "project": { + "bookTitle": "New Project", + "projectName": "New Project" + }, + "settings": { + } +} diff --git a/sample/data/story.json b/sample/data/story.json index af6fd9b..6bdeec9 100644 --- a/sample/data/story.json +++ b/sample/data/story.json @@ -2,13 +2,15 @@ "handle": "ROOT", "xItems": [ { - "handle": "5487e205-3957-4d80-b76d-0720f9972948", + "handle": "b32008d7-5b44-43a6-ace3-a7343b2ad496", "label": "Title Page", + "order": 0, "wCount": 0 }, { - "handle": "0baa14de-53b8-44c1-b60a-1ccde2efb76b", + "handle": "ff608d47-2fac-4d48-9a9c-13d787bc76c2", "label": "Chapter 1", + "order": 1, "wCount": 0 } ] diff --git a/src/collett.h b/src/collett.h index cf68c95..f3816d0 100644 --- a/src/collett.h +++ b/src/collett.h @@ -26,9 +26,10 @@ along with this program. If not, see . #define COL_VERSION_NUM 0x000001a0 #define COL_VERSION_DATE "2021-11-14" -#define COL_PROJECT_FILE_NAME "project.collett" -#define COL_STORY_FILE_NAME "story.json" -#define COL_NOTES_FILE_NAME "notes.json" +#define COL_PROJECT_FILE_NAME "project.collett" +#define COL_SETTINGS_FILE_NAME "project.json" +#define COL_STORY_FILE_NAME "story.json" +#define COL_NOTES_FILE_NAME "notes.json" #define COL_STORY_TREE_COL_COUNT 2 diff --git a/src/project/project.cpp b/src/project/project.cpp index 5d97920..f7adf58 100644 --- a/src/project/project.cpp +++ b/src/project/project.cpp @@ -26,6 +26,7 @@ along with this program. If not, see . #include #include #include +#include #include #include #include @@ -34,7 +35,34 @@ along with this program. If not, see . namespace Collett { -Project::Project(const QString &path) { +/** + * Project Private Class + * ===================== + */ + +class ProjectPrivate +{ +public: + ProjectPrivate() {}; + ~ProjectPrivate() {}; + + // Project + QString m_projectName = "New Project"; + QString m_bookTitle = "New Project"; + + // Meta + QDateTime m_createdTime = QDateTime::currentDateTime(); +}; + +/** + * Project Class Constructor/Destructor + * ==================================== + */ + +Project::Project(const QString &path) + : d_ptr(new ProjectPrivate()) +{ + Q_D(Project); this->clearError(); m_hasProject = false; @@ -94,10 +122,10 @@ Project::~Project() { delete m_storyModel; } -/* - Class Methods - ============= -*/ +/** + * Class Methods + * ============= + */ bool Project::openProject() { @@ -123,15 +151,16 @@ bool Project::saveProject() { } bool mainFile = saveProjectFile(); + bool settFile = saveSettingsFile(); bool storyFile = saveStoryFile(); - return mainFile & storyFile; + return mainFile & settFile & storyFile; } -/* - Project Getters - =============== -*/ +/** + * Project Getters + * =============== + */ bool Project::hasProject() const { return m_hasProject; @@ -141,10 +170,11 @@ StoryModel *Project::storyModel() { return m_storyModel; } -/* - Project Files - ============= -*/ +/** + * Project File + * ============ + * Load and save functions for the project.collett file. + */ bool Project::loadProjectFile() { @@ -191,29 +221,81 @@ bool Project::saveProjectFile() { } } +/** + * Settings FIle + * ============= + * Load and save functions for the data/project.json file. + * + * This file contains all the meta data and options for the Collett project, + * except for the project content itself (the documents). + */ + +bool Project::loadSettingsFile() { + return true; +} + +bool Project::saveSettingsFile() { + Q_D(Project); + + QJsonObject jData, jMeta, jProject, jSettings; + + jMeta["created"] = d->m_createdTime.toString(Qt::ISODate); + jMeta["updated"] = QDateTime::currentDateTime().toString(Qt::ISODate); + + jProject["bookTitle"] = d->m_bookTitle; + jProject["projectName"] = d->m_projectName; + + jData["meta"] = jMeta; + jData["project"] = jProject; + jData["settings"] = jSettings; + + QFile file(m_dataPath.filePath(COL_SETTINGS_FILE_NAME)); + if (!file.open(QIODevice::WriteOnly)) { + qWarning() << "Could not open settings file"; + return false; + } + + QJsonDocument doc(jData); + file.write(doc.toJson()); + file.close(); + + return true; +} + +/** + * Story File + * ========== + * Load and save functions for the data/story.json file. + * + * This file contains the structure of StoryItems contained in the StoryModel. + * The structure is contained as child items under a single root item, and is + * saved to a QJsonDocument by recursively calling the StoryItem->toJsonObject + * function. +`*/ + bool Project::loadStoryFile() { return true; } bool Project::saveStoryFile() { - QFile storyFile(m_dataPath.filePath(COL_STORY_FILE_NAME)); - if (!storyFile.open(QIODevice::WriteOnly)) { + QFile file(m_dataPath.filePath(COL_STORY_FILE_NAME)); + if (!file.open(QIODevice::WriteOnly)) { qWarning() << "Could not open story file"; return false; } - + QJsonDocument doc(m_storyModel->toJsonObject()); - storyFile.write(doc.toJson()); - storyFile.close(); + file.write(doc.toJson()); + file.close(); return true; } -/* - Error Handling - ============== -*/ +/** + * Error Handling + * ============== + */ bool Project::hasError() const { return m_hasError; diff --git a/src/project/project.h b/src/project/project.h index f9ae550..51ebd81 100644 --- a/src/project/project.h +++ b/src/project/project.h @@ -31,14 +31,20 @@ along with this program. If not, see . namespace Collett { +class ProjectPrivate; class Project : public QObject { Q_OBJECT + Q_DECLARE_PRIVATE(Project) public: Project(const QString &path); ~Project(); +private: + QScopedPointer d_ptr; + +public: // Class Methods bool openProject(); bool saveProject(); @@ -71,9 +77,11 @@ class Project : public QObject // Content StoryModel *m_storyModel; - // Project Files + // File Load & Save bool loadProjectFile(); bool saveProjectFile(); + bool loadSettingsFile(); + bool saveSettingsFile(); bool loadStoryFile(); bool saveStoryFile(); From d1887014d5a3dbc7e8de85a97b0b6b66d1f7eff5 Mon Sep 17 00:00:00 2001 From: Veronica Berglyd Olsen <1619840+vkbo@users.noreply.github.com> Date: Sat, 4 Dec 2021 16:56:57 +0100 Subject: [PATCH 8/9] Add getters and setters --- src/guimain.cpp | 1 + src/project/project.cpp | 25 +++++++++++++++++++++++++ src/project/project.h | 6 ++++++ 3 files changed, 32 insertions(+) diff --git a/src/guimain.cpp b/src/guimain.cpp index 9f792ad..56ef3f1 100644 --- a/src/guimain.cpp +++ b/src/guimain.cpp @@ -78,6 +78,7 @@ GuiMain::GuiMain(QWidget *parent) : QMainWindow(parent) { void GuiMain::openProject(const QString &path) { m_data->openProject(path); m_storyTreeView->setModel(m_data->storyModel()); + m_mainToolBar->setProjectName(m_data->project()->projectName()); }; bool GuiMain::saveProject() { diff --git a/src/project/project.cpp b/src/project/project.cpp index f7adf58..90383c9 100644 --- a/src/project/project.cpp +++ b/src/project/project.cpp @@ -162,6 +162,16 @@ bool Project::saveProject() { * =============== */ +QString Project::projectName() const { + Q_D(const Project); + return d->m_projectName; +} + +QString Project::bookTitle() const { + Q_D(const Project); + return d->m_bookTitle; +} + bool Project::hasProject() const { return m_hasProject; } @@ -170,6 +180,21 @@ StoryModel *Project::storyModel() { return m_storyModel; } +/** + * Project Setters + * =============== + */ + +void Project::setProjectName(const QString &name) { + Q_D(Project); + d->m_projectName = name.simplified(); +} + +void Project::setBookTitle(const QString &title) { + Q_D(Project); + d->m_bookTitle = title.simplified(); +} + /** * Project File * ============ diff --git a/src/project/project.h b/src/project/project.h index 51ebd81..48120d6 100644 --- a/src/project/project.h +++ b/src/project/project.h @@ -50,10 +50,16 @@ class Project : public QObject bool saveProject(); // Getters + QString projectName() const; + QString bookTitle() const; bool hasProject() const; bool hasError() const; StoryModel *storyModel(); + // Setters + void setProjectName(const QString &name); + void setBookTitle(const QString &title); + // Error Handling void clearError(); QString lastError() const; From 46e5c3ef9fff2ca35d9bb56fed01ac48ba7d1050 Mon Sep 17 00:00:00 2001 From: Veronica Berglyd Olsen <1619840+vkbo@users.noreply.github.com> Date: Sat, 4 Dec 2021 17:00:53 +0100 Subject: [PATCH 9/9] Restore previously changed variable name --- src/guimain.cpp | 14 +++++++------- src/guimain.h | 10 +++++----- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/guimain.cpp b/src/guimain.cpp index 56ef3f1..3edbc32 100644 --- a/src/guimain.cpp +++ b/src/guimain.cpp @@ -39,17 +39,17 @@ GuiMain::GuiMain(QWidget *parent) : QMainWindow(parent) { m_data = CollettData::instance(); // Collett Widgets - m_mainToolBar = new GuiMainToolBar(this); - m_treeToolBar = new GuiTreeToolBar(this); - m_storyTreeView = new GuiStoryTree(this); - m_mainStatus = new GuiMainStatus(this); - m_docEditor = new GuiDocEditor(this); + m_mainToolBar = new GuiMainToolBar(this); + m_treeToolBar = new GuiTreeToolBar(this); + m_storyTree = new GuiStoryTree(this); + m_mainStatus = new GuiMainStatus(this); + m_docEditor = new GuiDocEditor(this); // Assemble Main Window m_splitMain = new QSplitter(Qt::Horizontal, this); m_splitMain->setContentsMargins(4, 4, 4, 4); m_splitMain->setOpaqueResize(false); - m_splitMain->addWidget(m_storyTreeView); + m_splitMain->addWidget(m_storyTree); m_splitMain->addWidget(m_docEditor); this->addToolBar(Qt::TopToolBarArea, m_mainToolBar); @@ -77,7 +77,7 @@ GuiMain::GuiMain(QWidget *parent) : QMainWindow(parent) { void GuiMain::openProject(const QString &path) { m_data->openProject(path); - m_storyTreeView->setModel(m_data->storyModel()); + m_storyTree->setModel(m_data->storyModel()); m_mainToolBar->setProjectName(m_data->project()->projectName()); }; diff --git a/src/guimain.h b/src/guimain.h index 6eda3cd..4f8b4ee 100644 --- a/src/guimain.h +++ b/src/guimain.h @@ -56,11 +56,11 @@ class GuiMain : public QMainWindow CollettData *m_data; // Collett Widgets - GuiMainToolBar *m_mainToolBar; - GuiTreeToolBar *m_treeToolBar; - GuiStoryTree *m_storyTreeView; - GuiDocEditor *m_docEditor; - GuiMainStatus *m_mainStatus; + GuiMainToolBar *m_mainToolBar; + GuiTreeToolBar *m_treeToolBar; + GuiStoryTree *m_storyTree; + GuiDocEditor *m_docEditor; + GuiMainStatus *m_mainStatus; // GUI Widgets QSplitter *m_splitMain;