diff --git a/cbook.cpp b/cbook.cpp index 5495b08..645d494 100644 --- a/cbook.cpp +++ b/cbook.cpp @@ -1,4 +1,11 @@ #include "cbook.h" +#include "common.h" + +#include +#include + +#include +#include cBook::cBook(const QString &szTitle) : @@ -7,12 +14,73 @@ cBook::cBook(const QString &szTitle) : m_szShortDescription(""), m_szDescription(""), m_szAuthor(""), - m_startedAt(QDate(1, 1, 1)), - m_finishedAt(QDate(1, 1, 1)), - m_targetDate(QDate(1, 1, 1)) + m_startedAt(QDateTime(QDate(1, 1, 1))), + m_finishedAt(QDateTime(QDate(1, 1, 1))), + m_targetDate(QDateTime(QDate(1, 1, 1))) { } +bool cBook::load() +{ + QSqlQuery query; + + query.prepare("SELECT title, subTitle, shortDescription, description, author, startedAt, finishedAt, targetDate FROM book;"); + if(!query.exec()) + { + myDebug << query.lastError().text(); + return(false); + } + + query.first(); + + setTitle(query.value("title").toString()); + setSubTitle(query.value("subtitle").toString()); + setShortDescription(query.value("shortDescription").toString()); + setDescription(query.value("description").toString()); + setAuthor(query.value("author").toString()); + setStartedAt(query.value("startedAt").toDateTime()); + setFinishedAt(query.value("finishedAt").toDateTime()); + setTargetDate(query.value("targetDate").toDateTime()); + + return(true); +} + +bool cBook::save() +{ + QSqlQuery query; + + query.prepare("SELECT COUNT(1) CNT FROM book;"); + if(!query.exec()) + { + myDebug << query.lastError().text(); + return(false); + } + + query.first(); + + if(query.value("CNT").toInt() == 1) + query.prepare("UPDATE book SET title = :title, subTitle = :subTitle, shortDescription = :shortDescription, description = :description, author = :author, startedAt = :startedAt, finishedAt = :finishedAt, targetDate = :targetDate;"); + else + query.prepare("INSERT INTO book (title, subTitle, shortDesctiption, description, author, startedAt, finishedAt, targetDate) VALUES (:title, :subTitle, :shortDesctiption, :description, :author, :startedAt, :finishedAt, :targetDate);"); + + query.bindValue(":title", title()); + query.bindValue(":subTitle", subTitle()); + query.bindValue(":shortDescription", shortDescription()); + query.bindValue(":description", description()); + query.bindValue(":author", author()); + query.bindValue(":startedAt", startedAt()); + query.bindValue(":finishedAt", finishedAt()); + query.bindValue(":targetDate", targetDate()); + + if(!query.exec()) + { + myDebug << query.lastError().text(); + return(false); + } + + return(true); +} + void cBook::setTitle(const QString& szTitle) { m_szTitle = szTitle; @@ -63,32 +131,32 @@ QString cBook::author() return(m_szAuthor); } -void cBook::setStartedAt(const QDate& startedAt) +void cBook::setStartedAt(const QDateTime& startedAt) { m_startedAt = startedAt; } -QDate cBook::startedAt() +QDateTime cBook::startedAt() { return(m_startedAt); } -void cBook::setFinishedAt(const QDate& finishedAt) +void cBook::setFinishedAt(const QDateTime& finishedAt) { m_finishedAt = finishedAt; } -QDate cBook::finishedAt() +QDateTime cBook::finishedAt() { return(m_finishedAt); } -void cBook::setTargetDate(const QDate& targetDate) +void cBook::setTargetDate(const QDateTime& targetDate) { m_targetDate = targetDate; } -QDate cBook::targetDate() +QDateTime cBook::targetDate() { return(m_targetDate); } diff --git a/cbook.h b/cbook.h index 161bfe6..25581ae 100644 --- a/cbook.h +++ b/cbook.h @@ -3,7 +3,7 @@ #include -#include +#include class cBook @@ -11,6 +11,9 @@ class cBook public: cBook(const QString& szTitle = ""); + bool load(); + bool save(); + void setTitle(const QString& szTitle); QString title(); @@ -26,23 +29,23 @@ public: void setAuthor(const QString& szAuthor); QString author(); - void setStartedAt(const QDate& startedAt); - QDate startedAt(); + void setStartedAt(const QDateTime& startedAt); + QDateTime startedAt(); - void setFinishedAt(const QDate& finishedAt); - QDate finishedAt(); + void setFinishedAt(const QDateTime& finishedAt); + QDateTime finishedAt(); - void setTargetDate(const QDate& targetDate); - QDate targetDate(); + void setTargetDate(const QDateTime& targetDate); + QDateTime targetDate(); private: QString m_szTitle; QString m_szSubtitle; QString m_szShortDescription; QString m_szDescription; QString m_szAuthor; - QDate m_startedAt; - QDate m_finishedAt; - QDate m_targetDate; + QDateTime m_startedAt; + QDateTime m_finishedAt; + QDateTime m_targetDate; }; #endif // CBOOK_H diff --git a/cchapter.cpp b/cchapter.cpp new file mode 100644 index 0000000..f745e87 --- /dev/null +++ b/cchapter.cpp @@ -0,0 +1,131 @@ +#include "cchapter.h" + +#include "common.h" + +#include +#include + + +cChapter::cChapter(qint32 iID) : + m_iID(iID), + m_lpPart(0), + m_szName(""), + m_iSortOrder(-1), + m_szDescription(""), + m_szFile("") +{ +} + +void cChapter::setID(const qint32& iID) +{ + m_iID = iID; +} + +qint32 cChapter::id() +{ + return(m_iID); +} + +void cChapter::setPart(cPart* lpPart) +{ + m_lpPart = lpPart; +} + +cPart* cChapter::part() +{ + return(m_lpPart); +} + +void cChapter::setName(const QString& szName) +{ + m_szName = szName; +} + +QString cChapter::name() +{ + return(m_szName); +} + +void cChapter::setSortOrder(const qint32& iSortOrder) +{ + m_iSortOrder = iSortOrder; +} + +qint32 cChapter::sortOrder() +{ + return(m_iSortOrder); +} + +void cChapter::setDescription(const QString& szDescription) +{ + m_szDescription = szDescription; +} + +QString cChapter::description() +{ + return(m_szDescription); +} + +void cChapter::setFile(const QString& szFile) +{ + m_szFile = szFile; +} + +QString cChapter::file() +{ + return(m_szFile); +} + +cChapter* cChapterList::add(const qint32& iID) +{ + cChapter* lpChapter = find(iID); + + if(!lpChapter) + { + lpChapter = new cChapter(iID); + append(lpChapter); + } + + return(lpChapter); +} + +cChapter* cChapterList::find(const qint32& iID) +{ + for(int x = 0;x < count();x++) + { + if(at(x)->id() == iID) + return(at(x)); + } + + return(0); +} + +bool cChapterList::load(cPartList* lpPartList) +{ + QSqlQuery query; + + query.prepare("SELECT id, partID, name, sortOrder, description, file FROM chapter;"); + if(!query.exec()) + { + myDebug << query.lastError().text(); + return(false); + } + + while(query.next()) + { + cChapter* lpChapter = add(query.value("id").toInt()); + + lpChapter->setPart(lpPartList->find(query.value("partID").toInt())); + lpChapter->setName(query.value("name").toString()); + lpChapter->setSortOrder(query.value("sortOrder").toInt()); + lpChapter->setDescription(query.value("description").toString()); + lpChapter->setFile(query.value("file").toString()); + } + + return(true); +} + +bool cChapterList::save() +{ + return(true); +} diff --git a/cchapter.h b/cchapter.h new file mode 100644 index 0000000..8022cd8 --- /dev/null +++ b/cchapter.h @@ -0,0 +1,56 @@ +#ifndef CCHAPTER_H +#define CCHAPTER_H + + +#include "cpart.h" + +#include +#include +#include + + +class cChapter +{ +public: + cChapter(qint32 iID = -1); + + void setID(const qint32& iID); + qint32 id(); + + void setPart(cPart *lpPart); + cPart* part(); + + void setName(const QString& szName); + QString name(); + + void setSortOrder(const qint32& iSortOrder); + qint32 sortOrder(); + + void setDescription(const QString& szDescription); + QString description(); + + void setFile(const QString& szFile); + QString file(); + +private: + qint32 m_iID; + cPart* m_lpPart; + QString m_szName; + qint32 m_iSortOrder; + QString m_szDescription; + QString m_szFile; +}; + +Q_DECLARE_METATYPE(cChapter*) + +class cChapterList : public QList +{ +public: + bool load(cPartList *lpPartList); + bool save(); + + cChapter* add(const qint32& iID); + cChapter* find(const qint32& iID); +}; + +#endif // CCHAPTER_H diff --git a/cmainwindow.cpp b/cmainwindow.cpp index 2f3089a..66b644a 100644 --- a/cmainwindow.cpp +++ b/cmainwindow.cpp @@ -11,9 +11,12 @@ #include #include +#include + cMainWindow::cMainWindow(QWidget *parent) : QMainWindow(parent), + m_lpOutlineModel(0), ui(new Ui::cMainWindow), m_bUpdatingTab(false), m_lpStoryBook(0) @@ -21,7 +24,10 @@ cMainWindow::cMainWindow(QWidget *parent) : initUI(); createActions(); - m_lpStoryBook = new cStoryBook("c:/temp/qtStoryWriter/DerAdler"); + m_lpStoryBook = new cStoryBook("c:/temp/qtStoryWriter/DerAdler"); + m_lpStoryBook->fillOutlineList(m_lpOutlineModel); + + updateWindowTitle(); cStructureWindow* lpStructureWindow = new cStructureWindow(this); cWidget* lpWidget1 = new cWidget(lpStructureWindow); @@ -44,10 +50,46 @@ cMainWindow::~cMainWindow() delete ui; } +void cMainWindow::closeEvent(QCloseEvent *event) +{ + QSettings settings; + settings.setValue("main/width", QVariant::fromValue(size().width())); + settings.setValue("main/height", QVariant::fromValue(size().height())); + settings.setValue("main/x", QVariant::fromValue(x())); + settings.setValue("main/y", QVariant::fromValue(y())); + settings.setValue("main/splitter1", QVariant::fromValue(ui->m_lpMainSplitter->sizes()[0])); + settings.setValue("main/splitter2", QVariant::fromValue(ui->m_lpMainSplitter->sizes()[1])); + if(this->isMaximized()) + settings.setValue("main/maximized", QVariant::fromValue(true)); + else + settings.setValue("main/maximized", QVariant::fromValue(false)); + + event->accept(); +} + void cMainWindow::initUI() { ui->setupUi(this); + m_lpOutlineModel = new QStandardItemModel(0, 1); + ui->m_lpOutline->setModel(m_lpOutlineModel); + + QSettings settings; + qint16 iX = settings.value("main/x", QVariant::fromValue(-1)).toInt(); + qint16 iY = settings.value("main/y", QVariant::fromValue(-1)).toInt(); + qint16 iWidth = settings.value("main/width", QVariant::fromValue(-1)).toInt(); + qint16 iHeight = settings.value("main/height", QVariant::fromValue(-1)).toInt(); + qint16 iSplitter1 = settings.value("main/splitter1", QVariant::fromValue(-1)).toInt(); + qint16 iSplitter2 = settings.value("main/splitter2", QVariant::fromValue(-1)).toInt(); + + if(iWidth != -1 && iHeight != -1) + resize(iWidth, iHeight); + if(iX != -1 && iY != -1) + move(iX, iY); + + if(iSplitter1 != -1 && iSplitter2 != -1) + ui->m_lpMainSplitter->setSizes(QList() << iSplitter1 << iSplitter2); + ui->m_lpMainToolBox->setCurrentIndex(0); } @@ -58,6 +100,23 @@ void cMainWindow::createActions() connect(ui->m_lpMdiArea, SIGNAL(subWindowActivated(QMdiSubWindow*)), this, SLOT(onMdiAreaSubWindowActivated(QMdiSubWindow*))); } +void cMainWindow::updateWindowTitle() +{ + if(!m_lpStoryBook) + { + setWindowTitle("qtStoryWriter"); + return; + } + + QString szTitle = m_lpStoryBook->title(); + QString szAuthor = m_lpStoryBook->author(); + + if(szAuthor.isEmpty()) + setWindowTitle(QString("%1 - qtStoryWriter").arg(szTitle)); + else + setWindowTitle(QString("%1 by %2 - qtStoryWriter").arg(szTitle).arg(szAuthor)); +} + void cMainWindow::onMainTabCurrentChanged(int index) { if(m_bUpdatingTab) diff --git a/cmainwindow.h b/cmainwindow.h index 2ee6c20..c48883c 100644 --- a/cmainwindow.h +++ b/cmainwindow.h @@ -7,6 +7,10 @@ #include #include +#include + +#include + namespace Ui { class cMainWindow; @@ -20,6 +24,8 @@ public: explicit cMainWindow(QWidget *parent = 0); ~cMainWindow(); + void updateWindowTitle(); + private slots: void onMainTabCurrentChanged(int index); void onMainTabTabCloseRequested(int index); @@ -27,11 +33,15 @@ private slots: private: Ui::cMainWindow* ui; + QStandardItemModel* m_lpOutlineModel; bool m_bUpdatingTab; cStoryBook* m_lpStoryBook; void initUI(); void createActions(); + +protected: + void closeEvent(QCloseEvent *event); }; #endif // CMAINWINDOW_H diff --git a/cmainwindow.ui b/cmainwindow.ui index e119b24..3b7d773 100644 --- a/cmainwindow.ui +++ b/cmainwindow.ui @@ -11,31 +11,42 @@ - cMainWindow + qtStoryBook - + Qt::Horizontal + + QFrame::Box + + + QFrame::Sunken + - 3 + 0 0 0 - 69 - 481 + 89 + 460 Outline + + + + + @@ -43,7 +54,7 @@ 0 0 69 - 481 + 477 @@ -56,7 +67,7 @@ 0 0 69 - 481 + 477 @@ -69,7 +80,7 @@ 0 0 69 - 481 + 477 diff --git a/cpart.cpp b/cpart.cpp new file mode 100644 index 0000000..5d0514c --- /dev/null +++ b/cpart.cpp @@ -0,0 +1,118 @@ +#include "cpart.h" + +#include "common.h" + +#include +#include + + +cPart::cPart(qint32 iID) : + m_iID(iID), + m_szName(""), + m_iSortOrder(-1), + m_szDescription(""), + m_szFile("") +{ +} + +void cPart::setID(const qint32& iID) +{ + m_iID = iID; +} + +qint32 cPart::id() +{ + return(m_iID); +} + +void cPart::setName(const QString& szName) +{ + m_szName = szName; +} + +QString cPart::name() +{ + return(m_szName); +} + +void cPart::setSortOrder(const qint32& iSortOrder) +{ + m_iSortOrder = iSortOrder; +} + +qint32 cPart::sortOrder() +{ + return(m_iSortOrder); +} + +void cPart::setDescription(const QString& szDescription) +{ + m_szDescription = szDescription; +} + +QString cPart::description() +{ + return(m_szDescription); +} + +void cPart::setFile(const QString& szFile) +{ + m_szFile = szFile; +} + +QString cPart::file() +{ + return(m_szFile); +} + +cPart* cPartList::add(const qint32& iID) +{ + cPart* lpPart = find(iID); + + if(!lpPart) + { + lpPart = new cPart(iID); + append(lpPart); + } + + return(lpPart); +} + +cPart* cPartList::find(const qint32& iID) +{ + for(int x = 0;x < count();x++) + { + if(at(x)->id() == iID) + return(at(x)); + } + + return(0); +} + +bool cPartList::load() +{ + QSqlQuery query; + + query.prepare("SELECT id, name, sortOrder, description, file FROM part;"); + if(!query.exec()) + { + myDebug << query.lastError().text(); + return(false); + } + + while(query.next()) + { + cPart* lpPart = add(query.value("id").toInt()); + lpPart->setName(query.value("name").toString()); + lpPart->setSortOrder(query.value("sortOrder").toInt()); + lpPart->setDescription(query.value("description").toString()); + lpPart->setFile(query.value("file").toString()); + } + + return(true); +} + +bool cPartList::save() +{ + return(true); +} diff --git a/cpart.h b/cpart.h new file mode 100644 index 0000000..d7177cf --- /dev/null +++ b/cpart.h @@ -0,0 +1,50 @@ +#ifndef CPART_H +#define CPART_H + + +#include +#include +#include + + +class cPart +{ +public: + cPart(qint32 iID = -1); + + void setID(const qint32& iID); + qint32 id(); + + void setName(const QString& szName); + QString name(); + + void setSortOrder(const qint32& iSortOrder); + qint32 sortOrder(); + + void setDescription(const QString& szDescription); + QString description(); + + void setFile(const QString& szFile); + QString file(); + +private: + qint32 m_iID; + QString m_szName; + qint32 m_iSortOrder; + QString m_szDescription; + QString m_szFile; +}; + +Q_DECLARE_METATYPE(cPart*) + +class cPartList : public QList +{ +public: + bool load(); + bool save(); + + cPart* add(const qint32& iID); + cPart* find(const qint32& iID); +}; + +#endif // CPART_H diff --git a/cscene.cpp b/cscene.cpp new file mode 100644 index 0000000..1fba3f5 --- /dev/null +++ b/cscene.cpp @@ -0,0 +1,176 @@ +#include "cscene.h" + +#include "common.h" + +#include +#include + + +cScene::cScene(qint32 iID) : + m_iID(iID), + m_lpChapter(0), + m_szName(""), + m_iSortOrder(-1), + m_szDescription(""), + m_state(STATE::STATE_unknown), + m_szFile("") +{ +} + +void cScene::setID(const qint32& iID) +{ + m_iID = iID; +} + +qint32 cScene::id() +{ + return(m_iID); +} + +void cScene::setChapter(cChapter* lpChapter) +{ + m_lpChapter = lpChapter; +} + +cChapter* cScene::chapter() +{ + return(m_lpChapter); +} + +void cScene::setName(const QString& szName) +{ + m_szName = szName; +} + +QString cScene::name() +{ + return(m_szName); +} + +void cScene::setSortOrder(const qint32& iSortOrder) +{ + m_iSortOrder = iSortOrder; +} + +qint32 cScene::sortOrder() +{ + return(m_iSortOrder); +} + +void cScene::setDescription(const QString& szDescription) +{ + m_szDescription = szDescription; +} + +QString cScene::description() +{ + return(m_szDescription); +} + +void cScene::setState(const cScene::STATE state) +{ + m_state = state; +} + +cScene::STATE cScene::state() +{ + return(m_state); +} + +void cScene::setStartedAt(const QDateTime& startedAt) +{ + m_startedAt = startedAt; +} + +QDateTime cScene::startedAt() +{ + return(m_startedAt); +} + +void cScene::setFinishedAt(const QDateTime& finishedAt) +{ + m_finishedAt = finishedAt; +} + +QDateTime cScene::finishedAt() +{ + return(m_finishedAt); +} + +void cScene::setTargetDate(const QDateTime& targetDate) +{ + m_targetDate = targetDate; +} + +QDateTime cScene::targetDate() +{ + return(m_targetDate); +} + +void cScene::setFile(const QString& szFile) +{ + m_szFile = szFile; +} + +QString cScene::file() +{ + return(m_szFile); +} + +cScene* cSceneList::add(const qint32& iID) +{ + cScene* lpScene = find(iID); + + if(!lpScene) + { + lpScene = new cScene(iID); + append(lpScene); + } + + return(lpScene); +} + +cScene* cSceneList::find(const qint32& iID) +{ + for(int x = 0;x < count();x++) + { + if(at(x)->id() == iID) + return(at(x)); + } + + return(0); +} + +bool cSceneList::load(cChapterList* lpChapterList) +{ + QSqlQuery query; + + query.prepare("SELECT id, chapterID, name, sortOrder, description, state, startedAt, finishedAt, targetDate, file FROM scene;"); + if(!query.exec()) + { + myDebug << query.lastError().text(); + return(false); + } + + while(query.next()) + { + cScene* lpScene = add(query.value("id").toInt()); + + lpScene->setChapter(lpChapterList->find(query.value("chapterID").toInt())); + lpScene->setName(query.value("name").toString()); + lpScene->setSortOrder(query.value("sortOrder").toInt()); + lpScene->setDescription(query.value("description").toString()); + lpScene->setState((cScene::STATE)query.value("state").toInt()); + lpScene->setStartedAt(query.value("startedAt").toDateTime()); + lpScene->setFinishedAt(query.value("finishedAt").toDateTime()); + lpScene->setTargetDate(query.value("targetDate").toDateTime()); + lpScene->setFile(query.value("file").toString()); + } + + return(true); +} + +bool cSceneList::save() +{ + return(true); +} diff --git a/cscene.h b/cscene.h new file mode 100644 index 0000000..be023cb --- /dev/null +++ b/cscene.h @@ -0,0 +1,82 @@ +#ifndef CSCENE_H +#define CSCENE_H + + +#include "cchapter.h" + +#include +#include +#include +#include + + +class cScene +{ +public: + enum STATE + { + STATE_unknown = 0, + STATE_init = 1, + STATE_progress = 2, + STATE_delayed = 3, + STATE_finished = 4, + }; + + cScene(qint32 iID = -1); + + void setID(const qint32& iID); + qint32 id(); + + void setChapter(cChapter *lpChapter); + cChapter* chapter(); + + void setName(const QString& szName); + QString name(); + + void setSortOrder(const qint32& iSortOrder); + qint32 sortOrder(); + + void setDescription(const QString& szDescription); + QString description(); + + void setState(const STATE state); + STATE state(); + + void setStartedAt(const QDateTime& startedAt); + QDateTime startedAt(); + + void setFinishedAt(const QDateTime& finishedAt); + QDateTime finishedAt(); + + void setTargetDate(const QDateTime& targetDate); + QDateTime targetDate(); + + void setFile(const QString& szFile); + QString file(); + +private: + qint32 m_iID; + cChapter* m_lpChapter; + QString m_szName; + qint32 m_iSortOrder; + QString m_szDescription; + STATE m_state; + QDateTime m_startedAt; + QDateTime m_finishedAt; + QDateTime m_targetDate; + QString m_szFile; +}; + +Q_DECLARE_METATYPE(cScene*) + +class cSceneList : public QList +{ +public: + bool load(cChapterList *lpChapterList); + bool save(); + + cScene* add(const qint32& iID); + cScene* find(const qint32& iID); +}; + +#endif // CSCENE_H diff --git a/cstorybook.cpp b/cstorybook.cpp index 7dcbc28..d60e629 100644 --- a/cstorybook.cpp +++ b/cstorybook.cpp @@ -6,6 +6,10 @@ #include #include +#include + +#include + #include @@ -19,6 +23,15 @@ cStoryBook::cStoryBook(const QString &szProjectPath) : if(!loadBook()) return; + if(!loadPartList()) + return; + + if(!loadChapterList()) + return; + + if(!loadSceneList()) + return; + m_bIsOpen = true; } @@ -101,9 +114,9 @@ bool cStoryBook::createDatabase() " shortDescription TEXT, " " description TEXT, " " author TEXT, " - " startedAt DATE, " - " finishedAt DATE, " - " targetDate DATE " + " startedAt DATETIME, " + " finishedAt DATETIME, " + " targetDate DATETIME " ");")) return(false); @@ -244,9 +257,9 @@ bool cStoryBook::createDatabase() " [order] INTEGER, " " description TEXT, " " state INTEGER, " - " startedAt DATE, " - " finishedAt DATE, " - " targetDate DATE, " + " startedAt DATETIME, " + " finishedAt DATETIME, " + " targetDate DATETIME, " " file TEXT " ");")) return(false); @@ -287,25 +300,82 @@ bool cStoryBook::verify() bool cStoryBook::loadBook() { - QSqlQuery query; + return(m_book.load()); +} - query.prepare("SELECT title, subTitle, shortDescription, description, author, startedAt, finishedAt, targetDate FROM book;"); - if(!query.exec()) +bool cStoryBook::loadPartList() +{ + return(m_partList.load()); +} + +bool cStoryBook::loadChapterList() +{ + return(m_chapterList.load(&m_partList)); +} + +bool cStoryBook::loadSceneList() +{ + return(m_sceneList.load(&m_chapterList)); +} + +QString cStoryBook::title() +{ + if(!m_bIsOpen) + return("Untitled"); + else + return(m_book.title()); +} + +QString cStoryBook::author() +{ + if(!m_bIsOpen) + return(""); + else + return(m_book.author()); +} + +bool cStoryBook::fillOutlineList(QStandardItemModel* lpModel) +{ + QMap part; + QMap chapter; + + lpModel->clear(); + + for(int x = 0;x < m_partList.count();x++) { - myDebug << query.lastError().text(); - return(false); + cPart* lpPart = m_partList.at(x); + QStandardItem* lpItem = new QStandardItem(lpPart->name()); + lpItem->setData(QVariant::fromValue(lpPart)); + part.insert(lpPart->id(), lpItem); + lpModel->appendRow(lpItem); } - query.first(); + for(int x = 0;x < m_chapterList.count();x++) + { + cChapter* lpChapter = m_chapterList.at(x); + QStandardItem* lpRoot = part.value(lpChapter->part()->id()); - m_book.setTitle(query.value("title").toString()); - m_book.setSubTitle(query.value("subtitle").toString()); - m_book.setShortDescription(query.value("shortDescription").toString()); - m_book.setDescription(query.value("description").toString()); - m_book.setAuthor(query.value("author").toString()); - m_book.setStartedAt(query.value("startedAt").toDate()); - m_book.setFinishedAt(query.value("finishedAt").toDate()); - m_book.setTargetDate(query.value("targetDate").toDate()); + if(lpRoot) + { + QStandardItem* lpItem = new QStandardItem(lpChapter->name()); + lpItem->setData(QVariant::fromValue(lpChapter)); + chapter.insert(lpChapter->id(), lpItem); + lpRoot->appendRow(lpItem); + } + } + + for(int x = 0;x < m_sceneList.count();x++) + { + cScene* lpScene = m_sceneList.at(x); + QStandardItem* lpRoot = chapter.value(lpScene->chapter()->id()); + + if(lpRoot) + { + QStandardItem* lpItem = new QStandardItem(lpScene->name()); + lpItem->setData(QVariant::fromValue(lpScene)); + lpRoot->appendRow(lpItem); + } + } return(true); } diff --git a/cstorybook.h b/cstorybook.h index 039ff4e..d9d7e39 100644 --- a/cstorybook.h +++ b/cstorybook.h @@ -3,9 +3,14 @@ #include "cbook.h" +#include "cpart.h" +#include "cchapter.h" +#include "cscene.h" #include +#include + #include @@ -17,17 +22,28 @@ public: bool openDatabase(); bool verify(); + + QString title(); + QString author(); + + bool fillOutlineList(QStandardItemModel* lpModel); private: QString m_szProjectPath; bool m_bIsOpen; QSqlDatabase m_db; cBook m_book; + cPartList m_partList; + cChapterList m_chapterList; + cSceneList m_sceneList; bool createDatabase(); bool updateDatabase(); bool createTable(const QString& szSQL); bool loadBook(); + bool loadPartList(); + bool loadChapterList(); + bool loadSceneList(); }; #endif // CSTORYBOOK_H diff --git a/main.cpp b/main.cpp index a90eb7a..c258647 100644 --- a/main.cpp +++ b/main.cpp @@ -1,11 +1,23 @@ #include "cmainwindow.h" #include +#include + int main(int argc, char *argv[]) { QApplication a(argc, argv); + + QCoreApplication::setOrganizationName("WIN-DESIGN"); + QCoreApplication::setOrganizationDomain("windesign.at"); + QCoreApplication::setApplicationName("qtStoryWriter"); + + QSettings settings; + cMainWindow w; - w.show(); + if(settings.value("main/maximized").toBool()) + w.showMaximized(); + else + w.show(); return a.exec(); } diff --git a/qtStoryWriter.pro b/qtStoryWriter.pro index aa0444b..3d9888a 100644 --- a/qtStoryWriter.pro +++ b/qtStoryWriter.pro @@ -63,7 +63,10 @@ SOURCES += \ cstructurewindow.cpp \ cwidget.cpp \ cstorybook.cpp \ - cbook.cpp + cbook.cpp \ + cpart.cpp \ + cchapter.cpp \ + cscene.cpp HEADERS += \ cmainwindow.h \ @@ -76,7 +79,10 @@ HEADERS += \ cwidget.h \ cstorybook.h \ common.h \ - cbook.h + cbook.h \ + cpart.h \ + cchapter.h \ + cscene.h FORMS += \ cmainwindow.ui \