From bc97f3505841600d7ecd9da48fbf37db89a61cc4 Mon Sep 17 00:00:00 2001 From: Herwig Birke Date: Mon, 23 Apr 2018 15:42:47 +0200 Subject: [PATCH] . --- cchapter.cpp | 17 ++-- cchapter.h | 6 +- ccharacter.cpp | 27 +++++-- ccharacter.h | 2 + cmainwindow.cpp | 31 ++++++-- cmainwindow.h | 3 + cmainwindow.ui | 89 +++++++++++++++++---- cobject.cpp | 108 +++++++++++++++++++++++++ cobject.h | 54 +++++++++++++ common.cpp | 12 ++- common.h | 3 + cpart.cpp | 19 ++--- cpart.h | 6 +- cpartwindow.cpp | 2 +- cpartwindow.ui | 6 +- cpartwindow1.ui | 73 ----------------- cplace.cpp | 120 ++++++++++++++++++++++++++++ cplace.h | 58 ++++++++++++++ crecherche.cpp | 108 +++++++++++++++++++++++++ crecherche.h | 54 +++++++++++++ cstorybook.cpp | 196 ++++++++++++++++++++++++++++++++++++++++------ cstorybook.h | 17 +++- qtStoryWriter.pro | 11 ++- 23 files changed, 857 insertions(+), 165 deletions(-) create mode 100644 cobject.cpp create mode 100644 cobject.h delete mode 100644 cpartwindow1.ui create mode 100644 cplace.cpp create mode 100644 cplace.h create mode 100644 crecherche.cpp create mode 100644 crecherche.h diff --git a/cchapter.cpp b/cchapter.cpp index 73137b4..a3d22f5 100644 --- a/cchapter.cpp +++ b/cchapter.cpp @@ -12,7 +12,7 @@ cChapter::cChapter(qint32 iID, QObject *parent) : m_lpPart(0), m_szName(""), m_iSortOrder(-1), - m_szDescription(""), + m_lpDescription(0), m_lpText(0) { } @@ -57,14 +57,14 @@ qint32 cChapter::sortOrder() return(m_iSortOrder); } -void cChapter::setDescription(const QString& szDescription) +void cChapter::setDescription(cTextDocument* lpDescription) { - m_szDescription = szDescription; + m_lpDescription = lpDescription; } -QString cChapter::description() +cTextDocument* cChapter::description() { - return(m_szDescription); + return(m_lpDescription); } void cChapter::setText(cTextDocument* lpText) @@ -119,11 +119,8 @@ bool cChapterList::load(cPartList* lpPartList) 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()); - - cTextDocument* lpText = new cTextDocument; - lpText->setHtml(uncompressText(query.value("text").toByteArray())); - lpChapter->setText(lpText); + lpChapter->setDescription(blob2TextDocument(query.value("description").toByteArray())); + lpChapter->setText(blob2TextDocument(query.value("text").toByteArray())); } return(true); diff --git a/cchapter.h b/cchapter.h index 9dc089a..413fcf9 100644 --- a/cchapter.h +++ b/cchapter.h @@ -30,8 +30,8 @@ public: void setSortOrder(const qint32& iSortOrder); qint32 sortOrder(); - void setDescription(const QString& szDescription); - QString description(); + void setDescription(cTextDocument* lpDescription); + cTextDocument* description(); void setText(cTextDocument* lpText); cTextDocument* text(); @@ -41,7 +41,7 @@ private: cPart* m_lpPart; QString m_szName; qint32 m_iSortOrder; - QString m_szDescription; + cTextDocument* m_lpDescription; cTextDocument* m_lpText; }; diff --git a/ccharacter.cpp b/ccharacter.cpp index 1ff9d33..14563e6 100644 --- a/ccharacter.cpp +++ b/ccharacter.cpp @@ -77,6 +77,25 @@ cCharacter::GENDER cCharacter::gender() return(m_gender); } +QString cCharacter::genderText() +{ + return(genderText(m_gender)); +} + +QString cCharacter::genderText(GENDER gender) const +{ + switch(gender) + { + case GENDER::GENDER_female: + return(tr("female")); + case GENDER::GENDER_male: + return(tr("male")); + case GENDER::GENDER_undefined: + return(tr("undefined")); + } + return(tr("undefined")); +} + void cCharacter::setTitle(const QString& szTitle) { m_szTitle = szTitle; @@ -348,7 +367,7 @@ bool cCharacterList::load() { QSqlQuery query; - query.prepare("SELECT id, mainCharacter, gender, title, firstName, middleName, lastName, height, weight, dateOfBirth, placeOfBirth, dateOfDeath, placeOfDeath, hairColor, hairCut, hairLength, figure, nature, spokenLanguages, skin, school, job, description FROM character ORDER BY mainCharacter DESC, lastName, middleName, firstName;"); + query.prepare("SELECT id, mainCharacter, creature, gender, title, firstName, middleName, lastName, height, weight, dateOfBirth, placeOfBirth, dateOfDeath, placeOfDeath, hairColor, hairCut, hairLength, figure, nature, spokenLanguages, skin, school, job, description FROM character ORDER BY mainCharacter DESC, lastName, middleName, firstName;"); if(!query.exec()) { myDebug << query.lastError().text(); @@ -360,6 +379,7 @@ bool cCharacterList::load() cCharacter* lpCharacter = add(query.value("id").toInt()); lpCharacter->setMainCharacter(query.value("mainCharacter").toBool()); + lpCharacter->setCreature(query.value("creature").toString()); lpCharacter->setGender((cCharacter::GENDER)query.value("gender").toInt()); lpCharacter->setTitle(query.value("title").toString()); lpCharacter->setFirstName(query.value("firstName").toString()); @@ -380,10 +400,7 @@ bool cCharacterList::load() lpCharacter->setSkin(query.value("skin").toString()); lpCharacter->setSchool(query.value("school").toString()); lpCharacter->setJob(query.value("job").toString()); - - cTextDocument* lpText = new cTextDocument; - lpText->setHtml(uncompressText(query.value("description").toByteArray())); - lpCharacter->setDescription(lpText); + lpCharacter->setDescription(blob2TextDocument(query.value("description").toByteArray())); } return(true); diff --git a/ccharacter.h b/ccharacter.h index 853d66f..51b8402 100644 --- a/ccharacter.h +++ b/ccharacter.h @@ -36,6 +36,8 @@ public: void setGender(GENDER gender); GENDER gender(); + QString genderText(); + QString genderText(GENDER gender) const; void setTitle(const QString& szTitle); QString title(); diff --git a/cmainwindow.cpp b/cmainwindow.cpp index eea6353..f2f084a 100644 --- a/cmainwindow.cpp +++ b/cmainwindow.cpp @@ -23,28 +23,34 @@ cMainWindow::cMainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::cMainWindow), m_lpOutlineModel(0), + m_lpCharacterModel(0), + m_lpPlaceModel(0), + m_lpObjectModel(0), m_bUpdatingTab(false), m_lpStoryBook(0) { initUI(); createActions(); - QString szPath = QDir::homePath() + QDir::separator() + "OneDrive - WINDESIGN" + QDir::separator() + "__BOOKS__" + QDir::separator() + "qtStoryWriter" + QDir::separator() + "DerAdler"; + QString szPath = QDir::homePath() + QDir::separator() + "OneDrive - WINDESIGN" + QDir::separator() + "__BOOKS__" + QDir::separator() + "qtStoryWriter" + QDir::separator() + "rückwärts.storyWriter" ; m_lpStoryBook = new cStoryBook(szPath); m_lpStoryBook->fillOutlineList(ui->m_lpOutlineList); m_lpStoryBook->fillCharacterList(ui->m_lpCharacterList); + m_lpStoryBook->fillPlaceList(ui->m_lpPlaceList); + m_lpStoryBook->fillObjectList(ui->m_lpObjectList); + m_lpStoryBook->fillRechercheList(ui->m_lpRechercheList); updateWindowTitle(); - cPartWindow* lpPartWindow = new cPartWindow(this); +// cPartWindow* lpPartWindow = new cPartWindow(this); - QStandardItem* lpItem = m_lpOutlineModel->item(0, 0); - cPart* lpPart = qvariant_cast(lpItem->data()); +// QStandardItem* lpItem = m_lpOutlineModel->item(0, 0); +// cPart* lpPart = qvariant_cast(lpItem->data()); - lpPartWindow->setPart(lpPart); - cWidget* lpWidget1 = new cWidget(lpPartWindow); - lpWidget1->setWindow(ui->m_lpMdiArea->addSubWindow(lpPartWindow)); - ui->m_lpMainTab->addTab((QWidget*)lpWidget1, lpPartWindow->windowTitle()); +// lpPartWindow->setPart(lpPart); +// cWidget* lpWidget1 = new cWidget(lpPartWindow); +// lpWidget1->setWindow(ui->m_lpMdiArea->addSubWindow(lpPartWindow)); +// ui->m_lpMainTab->addTab((QWidget*)lpWidget1, lpPartWindow->windowTitle()); // cStructureWindow* lpStructureWindow = new cStructureWindow(this); // cWidget* lpWidget1 = new cWidget(lpStructureWindow); @@ -95,6 +101,15 @@ void cMainWindow::initUI() m_lpCharacterModel = new QStandardItemModel(0, 1); ui->m_lpCharacterList->setModel(m_lpCharacterModel); + m_lpPlaceModel = new QStandardItemModel(0, 1); + ui->m_lpPlaceList->setModel(m_lpPlaceModel); + + m_lpObjectModel = new QStandardItemModel(0, 1); + ui->m_lpObjectList->setModel(m_lpObjectModel); + + m_lpRechercheModel = new QStandardItemModel(0, 1); + ui->m_lpRechercheList->setModel(m_lpRechercheModel); + QSettings settings; qint16 iX = settings.value("main/x", QVariant::fromValue(-1)).toInt(); qint16 iY = settings.value("main/y", QVariant::fromValue(-1)).toInt(); diff --git a/cmainwindow.h b/cmainwindow.h index 737c81e..c1cad10 100644 --- a/cmainwindow.h +++ b/cmainwindow.h @@ -35,6 +35,9 @@ private: Ui::cMainWindow* ui; QStandardItemModel* m_lpOutlineModel; QStandardItemModel* m_lpCharacterModel; + QStandardItemModel* m_lpPlaceModel; + QStandardItemModel* m_lpObjectModel; + QStandardItemModel* m_lpRechercheModel; bool m_bUpdatingTab; cStoryBook* m_lpStoryBook; diff --git a/cmainwindow.ui b/cmainwindow.ui index ca7fa8d..0dadbd0 100644 --- a/cmainwindow.ui +++ b/cmainwindow.ui @@ -28,15 +28,15 @@ QFrame::Sunken - 0 + 4 0 0 - 147 - 450 + 89 + 433 @@ -72,8 +72,8 @@ 0 0 - 147 - 450 + 89 + 433 @@ -94,9 +94,6 @@ false - - false - true @@ -109,40 +106,102 @@ 0 0 - 147 - 450 + 89 + 433 Place + + + + + QAbstractItemView::NoEditTriggers + + + false + + + true + + + false + + + true + + + + 0 0 - 147 - 450 + 89 + 433 Object - + + + + + QAbstractItemView::NoEditTriggers + + + false + + + true + + + false + + + true + + + + 0 0 - 147 - 450 + 89 + 433 Recherche + + + + + QAbstractItemView::NoEditTriggers + + + false + + + true + + + false + + + true + + + + diff --git a/cobject.cpp b/cobject.cpp new file mode 100644 index 0000000..1134c08 --- /dev/null +++ b/cobject.cpp @@ -0,0 +1,108 @@ +#include "cobject.h" + +#include "common.h" + +#include +#include + + +cObject::cObject(qint32 iID, QObject *parent) : + QObject(parent), + m_iID(iID), + m_szName(""), + m_szType(""), + m_lpDescription(0) +{ +} + +void cObject::setID(const qint32& iID) +{ + m_iID = iID; +} + +qint32 cObject::id() +{ + return(m_iID); +} + +void cObject::setName(const QString& szName) +{ + m_szName = szName; +} + +QString cObject::name() +{ + return(m_szName); +} + +void cObject::setType(const QString& szType) +{ + m_szType = szType; +} + +QString cObject::type() +{ + return(m_szType); +} + +void cObject::setDescription(cTextDocument* lpDescription) +{ + m_lpDescription = lpDescription; +} + +cTextDocument* cObject::description() +{ + return(m_lpDescription); +} + +cObject* cObjectList::add(const qint32& iID) +{ + cObject* lpObject = find(iID); + + if(!lpObject) + { + lpObject = new cObject(iID); + append(lpObject); + } + + return(lpObject); +} + +cObject* cObjectList::find(const qint32& iID) +{ + for(int x = 0;x < count();x++) + { + if(at(x)->id() == iID) + return(at(x)); + } + + return(0); +} + +bool cObjectList::load() +{ + QSqlQuery query; + + query.prepare("SELECT id, name, type, description FROM object ORDER BY name, type;"); + if(!query.exec()) + { + myDebug << query.lastError().text(); + return(false); + } + + while(query.next()) + { + cObject* lpObject = add(query.value("id").toInt()); + + lpObject->setName(query.value("name").toString()); + lpObject->setType(query.value("type").toString()); + lpObject->setDescription(blob2TextDocument(query.value("description").toByteArray())); + } + + return(true); +} + +bool cObjectList::save() +{ + return(true); +} diff --git a/cobject.h b/cobject.h new file mode 100644 index 0000000..c69c420 --- /dev/null +++ b/cobject.h @@ -0,0 +1,54 @@ +#ifndef COBJECT_H +#define COBJECT_H + + +#include "ctextdocument.h" + +#include +#include +#include +#include + + +class cObject : public QObject +{ + Q_OBJECT +public: + explicit cObject(qint32 iID = -1, QObject *parent = nullptr); + + void setID(const qint32& iID); + qint32 id(); + + void setName(const QString& szName); + QString name(); + + void setType(const QString& szType); + QString type(); + + void setDescription(cTextDocument* lpDescription); + cTextDocument* description(); + +private: + qint32 m_iID; + QString m_szName; + QString m_szType; + cTextDocument* m_lpDescription; + +signals: + +public slots: +}; + +Q_DECLARE_METATYPE(cObject*) + +class cObjectList : public QList +{ +public: + bool load(); + bool save(); + + cObject* add(const qint32& iID); + cObject* find(const qint32& iID); +}; + +#endif // COBJECT_H diff --git a/common.cpp b/common.cpp index dccb387..2537776 100644 --- a/common.cpp +++ b/common.cpp @@ -12,4 +12,14 @@ QByteArray compressText(const QString& uncompressed) if(uncompressed.isNull() || uncompressed.isEmpty()) return(QByteArray()); return(qCompress(uncompressed.toUtf8())); -} \ No newline at end of file +} + +cTextDocument* blob2TextDocument(const QByteArray& ba) +{ + cTextDocument* lpTextDocument = new cTextDocument; + if(ba.isEmpty()) + return(lpTextDocument); + + lpTextDocument->setHtml(uncompressText(ba)); + return(lpTextDocument); +} diff --git a/common.h b/common.h index 700ad1e..4283352 100644 --- a/common.h +++ b/common.h @@ -2,6 +2,8 @@ #define COMMON_H +#include "ctextdocument.h" + #include #include @@ -17,5 +19,6 @@ QString uncompressText(const QByteArray& compressed); QByteArray compressText(const QString& uncompressed); +cTextDocument* blob2TextDocument(const QByteArray& ba); #endif // COMMON_H diff --git a/cpart.cpp b/cpart.cpp index 1220fec..374c244 100644 --- a/cpart.cpp +++ b/cpart.cpp @@ -11,7 +11,7 @@ cPart::cPart(qint32 iID, QObject *parent) : m_iID(iID), m_szName(""), m_iSortOrder(-1), - m_szDescription(""), + m_lpDescription(0), m_lpText(0) { } @@ -46,14 +46,14 @@ qint32 cPart::sortOrder() return(m_iSortOrder); } -void cPart::setDescription(const QString& szDescription) +void cPart::setDescription(cTextDocument* lpDescription) { - m_szDescription = szDescription; + m_lpDescription = lpDescription; } -QString cPart::description() +cTextDocument* cPart::description() { - return(m_szDescription); + return(m_lpDescription); } void cPart::setText(cTextDocument* lpText) @@ -106,13 +106,8 @@ bool cPartList::load() 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()); - - QByteArray ba = query.value("text").toByteArray(); - cTextDocument* lpText = new cTextDocument; - if(!ba.isEmpty()) - lpText->setHtml(qUncompress(ba)); - lpPart->setText(lpText); + lpPart->setDescription(blob2TextDocument(query.value("description").toByteArray())); + lpPart->setText(blob2TextDocument(query.value("text").toByteArray())); } return(true); diff --git a/cpart.h b/cpart.h index 0105e62..25b97c6 100644 --- a/cpart.h +++ b/cpart.h @@ -25,8 +25,8 @@ public: void setSortOrder(const qint32& iSortOrder); qint32 sortOrder(); - void setDescription(const QString& szDescription); - QString description(); + void setDescription(cTextDocument* lpDescription); + cTextDocument* description(); void setText(cTextDocument* lpText); cTextDocument* text(); @@ -35,7 +35,7 @@ private: qint32 m_iID; QString m_szName; qint32 m_iSortOrder; - QString m_szDescription; + cTextDocument* m_lpDescription; cTextDocument* m_lpText; }; diff --git a/cpartwindow.cpp b/cpartwindow.cpp index 413d075..d5bc3ee 100644 --- a/cpartwindow.cpp +++ b/cpartwindow.cpp @@ -19,7 +19,7 @@ void cPartWindow::setPart(cPart* lpPart) { m_lpPart = lpPart; ui->m_lpName->setText(lpPart->name()); - ui->m_lpDescription->document()->setPlainText(lpPart->description()); + ui->m_lpDescription->setDocument(lpPart->description()); ui->m_lpText->setDocument(lpPart->text()); setWindowTitle(tr("[part] - ") + lpPart->name()); diff --git a/cpartwindow.ui b/cpartwindow.ui index adee7b4..b666fe8 100644 --- a/cpartwindow.ui +++ b/cpartwindow.ui @@ -33,12 +33,12 @@ - - - + + + diff --git a/cpartwindow1.ui b/cpartwindow1.ui deleted file mode 100644 index 390e498..0000000 --- a/cpartwindow1.ui +++ /dev/null @@ -1,73 +0,0 @@ - - - cPartWindow - - - - 0 - 0 - 800 - 580 - - - - MainWindow - - - - - - - - - - - - Name: - - - - - - - Description: - - - - - - - - - - - - - - - - - 0 - 0 - 800 - 21 - - - - - - - - cTextEdit - QTextEdit -
ctextedit.h
-
-
- - m_lpName - m_lpDescription - m_lpText - - - -
diff --git a/cplace.cpp b/cplace.cpp new file mode 100644 index 0000000..2f36cef --- /dev/null +++ b/cplace.cpp @@ -0,0 +1,120 @@ +#include "cplace.h" + +#include "common.h" + +#include +#include + + +cPlace::cPlace(qint32 iID, QObject *parent) : + QObject(parent), + m_iID(iID), + m_szName(""), + m_szLocation(""), + m_szType(""), + m_lpDescription(0) +{ +} + +void cPlace::setID(const qint32& iID) +{ + m_iID = iID; +} + +qint32 cPlace::id() +{ + return(m_iID); +} + +void cPlace::setName(const QString& szName) +{ + m_szName = szName; +} + +QString cPlace::name() +{ + return(m_szName); +} + +void cPlace::setLocation(const QString& szLocation) +{ + m_szLocation = szLocation; +} + +QString cPlace::location() +{ + return(m_szLocation); +} + +void cPlace::setType(const QString& szType) +{ + m_szType = szType; +} + +QString cPlace::type() +{ + return(m_szType); +} + +void cPlace::setDescription(cTextDocument* lpDescription) +{ + m_lpDescription = lpDescription; +} + +cTextDocument* cPlace::description() +{ + return(m_lpDescription); +} + +cPlace* cPlaceList::add(const qint32& iID) +{ + cPlace* lpPlace = find(iID); + + if(!lpPlace) + { + lpPlace = new cPlace(iID); + append(lpPlace); + } + + return(lpPlace); +} + +cPlace* cPlaceList::find(const qint32& iID) +{ + for(int x = 0;x < count();x++) + { + if(at(x)->id() == iID) + return(at(x)); + } + + return(0); +} + +bool cPlaceList::load() +{ + QSqlQuery query; + + query.prepare("SELECT id, name, location, type, description FROM place ORDER BY name, location, type;"); + if(!query.exec()) + { + myDebug << query.lastError().text(); + return(false); + } + + while(query.next()) + { + cPlace* lpPlace = add(query.value("id").toInt()); + + lpPlace->setName(query.value("name").toString()); + lpPlace->setLocation(query.value("location").toString()); + lpPlace->setType(query.value("type").toString()); + lpPlace->setDescription(blob2TextDocument(query.value("description").toByteArray())); + } + + return(true); +} + +bool cPlaceList::save() +{ + return(true); +} diff --git a/cplace.h b/cplace.h new file mode 100644 index 0000000..5ce5b3d --- /dev/null +++ b/cplace.h @@ -0,0 +1,58 @@ +#ifndef CPLACE_H +#define CPLACE_H + + +#include "ctextdocument.h" + +#include +#include +#include +#include + + +class cPlace : public QObject +{ + Q_OBJECT +public: + explicit cPlace(qint32 iID = -1, QObject *parent = nullptr); + + void setID(const qint32& iID); + qint32 id(); + + void setName(const QString& szName); + QString name(); + + void setLocation(const QString& szLocation); + QString location(); + + void setType(const QString& szType); + QString type(); + + void setDescription(cTextDocument* lpDescription); + cTextDocument* description(); + +private: + qint32 m_iID; + QString m_szName; + QString m_szLocation; + QString m_szType; + cTextDocument* m_lpDescription; + +signals: + +public slots: +}; + +Q_DECLARE_METATYPE(cPlace*) + +class cPlaceList : public QList +{ +public: + bool load(); + bool save(); + + cPlace* add(const qint32& iID); + cPlace* find(const qint32& iID); +}; + +#endif // CPLACE_H diff --git a/crecherche.cpp b/crecherche.cpp new file mode 100644 index 0000000..8235114 --- /dev/null +++ b/crecherche.cpp @@ -0,0 +1,108 @@ +#include "crecherche.h" + +#include "common.h" + +#include +#include + + +cRecherche::cRecherche(qint32 iID, QObject *parent) : + QObject(parent), + m_iID(iID), + m_szName(""), + m_szLink(""), + m_lpDescription(0) +{ +} + +void cRecherche::setID(const qint32& iID) +{ + m_iID = iID; +} + +qint32 cRecherche::id() +{ + return(m_iID); +} + +void cRecherche::setName(const QString& szName) +{ + m_szName = szName; +} + +QString cRecherche::name() +{ + return(m_szName); +} + +void cRecherche::setLink(const QString& szLink) +{ + m_szLink = szLink; +} + +QString cRecherche::link() +{ + return(m_szLink); +} + +void cRecherche::setDescription(cTextDocument* lpDescription) +{ + m_lpDescription = lpDescription; +} + +cTextDocument* cRecherche::description() +{ + return(m_lpDescription); +} + +cRecherche* cRechercheList::add(const qint32& iID) +{ + cRecherche* lpRecherche = find(iID); + + if(!lpRecherche) + { + lpRecherche = new cRecherche(iID); + append(lpRecherche); + } + + return(lpRecherche); +} + +cRecherche* cRechercheList::find(const qint32& iID) +{ + for(int x = 0;x < count();x++) + { + if(at(x)->id() == iID) + return(at(x)); + } + + return(0); +} + +bool cRechercheList::load() +{ + QSqlQuery query; + + query.prepare("SELECT id, name, link, description FROM recherche ORDER BY name, link;"); + if(!query.exec()) + { + myDebug << query.lastError().text(); + return(false); + } + + while(query.next()) + { + cRecherche* lpObject = add(query.value("id").toInt()); + + lpObject->setName(query.value("name").toString()); + lpObject->setLink(query.value("link").toString()); + lpObject->setDescription(blob2TextDocument(query.value("description").toByteArray())); + } + + return(true); +} + +bool cRechercheList::save() +{ + return(true); +} diff --git a/crecherche.h b/crecherche.h new file mode 100644 index 0000000..d7b62b5 --- /dev/null +++ b/crecherche.h @@ -0,0 +1,54 @@ +#ifndef CRECHERCHE_H +#define CRECHERCHE_H + + +#include "ctextdocument.h" + +#include +#include +#include +#include + + +class cRecherche : public QObject +{ + Q_OBJECT +public: + explicit cRecherche(qint32 iID = -1, QObject *parent = nullptr); + + void setID(const qint32& iID); + qint32 id(); + + void setName(const QString& szName); + QString name(); + + void setLink(const QString& szLink); + QString link(); + + void setDescription(cTextDocument* lpDescription); + cTextDocument* description(); + +private: + qint32 m_iID; + QString m_szName; + QString m_szLink; + cTextDocument* m_lpDescription; + +signals: + +public slots: +}; + +Q_DECLARE_METATYPE(cRecherche*) + +class cRechercheList : public QList +{ +public: + bool load(); + bool save(); + + cRecherche* add(const qint32& iID); + cRecherche* find(const qint32& iID); +}; + +#endif // CRECHERCHE_H diff --git a/cstorybook.cpp b/cstorybook.cpp index 4b664af..53f9218 100644 --- a/cstorybook.cpp +++ b/cstorybook.cpp @@ -18,9 +18,9 @@ #include -cStoryBook::cStoryBook(const QString &szProjectPath, QObject *parent) : +cStoryBook::cStoryBook(const QString &szProject, QObject *parent) : QObject(parent), - m_szProjectPath(szProjectPath), + m_szProject(szProject), m_bIsOpen(false) { if(!openDatabase()) @@ -41,6 +41,15 @@ cStoryBook::cStoryBook(const QString &szProjectPath, QObject *parent) : if(!loadCharacterList()) return; + if(!loadPlaceList()) + return; + + if(!loadObjectList()) + return; + + if(!loadRechercheList()) + return; + m_bIsOpen = true; } @@ -52,8 +61,7 @@ cStoryBook::~cStoryBook() bool cStoryBook::openDatabase() { - QString szDatabase = QString("%1%2storyBook.project").arg(m_szProjectPath).arg(QDir::separator()); - QFile file(szDatabase); + QFile file(m_szProject); if(!file.exists()) { @@ -63,7 +71,7 @@ bool cStoryBook::openDatabase() } m_db = QSqlDatabase::addDatabase("QSQLITE"); m_db.setHostName("localhost"); - m_db.setDatabaseName(szDatabase); + m_db.setDatabaseName(m_szProject); if(!m_db.open()) { @@ -144,7 +152,7 @@ bool cStoryBook::createDatabase() " partID INTEGER REFERENCES part (id), " " name TEXT, " " sortOrder INTEGER, " - " description TEXT, " + " description BLOB, " " text BLOB " ");")) return(false); @@ -190,7 +198,7 @@ bool cStoryBook::createDatabase() " UNIQUE, " " type TEXT, " " name TEXT, " - " description TEXT, " + " description BLOB, " " image BLOB " ");")) return(false); @@ -200,7 +208,7 @@ bool cStoryBook::createDatabase() " UNIQUE, " " name TEXT, " " type TEXT, " - " description TEXT " + " description BLOB " ");")) return(false); @@ -215,7 +223,7 @@ bool cStoryBook::createDatabase() " UNIQUE, " " name TEXT, " " [order] INTEGER, " - " description TEXT, " + " description BLOB, " " text BLOB " ");")) return(false); @@ -240,7 +248,7 @@ bool cStoryBook::createDatabase() " id INTEGER PRIMARY KEY AUTOINCREMENT " " UNIQUE, " " name TEXT, " - " description TEXT, " + " description BLOB, " " link TEXT " ");")) return(false); @@ -287,7 +295,7 @@ bool cStoryBook::createDatabase() if(!createTable("CREATE TABLE sceneCharacter ( " " sceneID INTEGER REFERENCES scene (id), " " characterID INTEGER REFERENCES character (id), " - " description TEXT " + " description BLOB " ");")) return(false); @@ -343,6 +351,21 @@ bool cStoryBook::loadCharacterList() return(m_characterList.load()); } +bool cStoryBook::loadPlaceList() +{ + return(m_placeList.load()); +} + +bool cStoryBook::loadObjectList() +{ + return(m_objectList.load()); +} + +bool cStoryBook::loadRechercheList() +{ + return(m_rechercheList.load()); +} + QString cStoryBook::title() { if(!m_bIsOpen) @@ -385,7 +408,7 @@ bool cStoryBook::fillOutlineList(QTreeView* lpView) lpItem->setData(QVariant::fromValue(lpPart)); lpItem->setFont(fontPart); lpItem->setBackground(QBrush(background)); - lpItem->setToolTip(lpPart->description()); + lpItem->setToolTip(lpPart->description()->toPlainText()); part.insert(lpPart->id(), lpItem); lpModel->appendRow(lpItem); @@ -404,7 +427,7 @@ bool cStoryBook::fillOutlineList(QTreeView* lpView) lpItem->setFont(fontChapter); lpItem->setForeground(QBrush(Qt::darkBlue)); lpItem->setBackground(QBrush(background)); - lpItem->setToolTip(lpChapter->description()); + lpItem->setToolTip(lpChapter->description()->toPlainText()); chapter.insert(lpChapter->id(), lpItem); lpRoot->appendRow(lpItem); lpView->setFirstColumnSpanned(lpRoot->rowCount()-1, lpRoot->index(), true); @@ -442,8 +465,10 @@ bool cStoryBook::fillOutlineList(QTreeView* lpView) lpView->header()->setSectionResizeMode(1, QHeaderView::Interactive); lpView->expandAll(); - lpView->resizeColumnToContents(0); - lpView->resizeColumnToContents(1); + + + for(int i = 0;i < headerLabels.count();i++) + lpView->resizeColumnToContents(i); return(true); } @@ -457,7 +482,7 @@ bool cStoryBook::fillCharacterList(QTreeView* lpView) lpModel->clear(); - QStringList headerLabels = QStringList() << tr("name"); + QStringList headerLabels = QStringList() << tr("name") << tr("creature") << tr("gender"); lpModel->setHorizontalHeaderLabels(headerLabels); fontMainCharacter.setBold(true); @@ -465,23 +490,142 @@ bool cStoryBook::fillCharacterList(QTreeView* lpView) for(int x = 0;x < m_characterList.count();x++) { - cCharacter* lpCharacter = m_characterList.at(x); - QStandardItem* lpItem = new QStandardItem(lpCharacter->name()); - lpItem->setData(QVariant::fromValue(lpCharacter)); + cCharacter* lpCharacter = m_characterList.at(x); + QList lpItems; - if(lpCharacter->mainCharacter()) - lpItem->setFont(fontMainCharacter); - else - lpItem->setFont(fontNonMainCharacter); + lpItems.append(new QStandardItem(lpCharacter->name())); + lpItems.append(new QStandardItem(lpCharacter->creature())); + lpItems.append(new QStandardItem(lpCharacter->genderText())); -// lpItem->setToolTip(lpPart->description()); - lpModel->appendRow(lpItem); + for(int i = 0;i < headerLabels.count();i++) + { + lpItems[i]->setData(QVariant::fromValue(lpCharacter)); + if(lpCharacter->mainCharacter()) + lpItems[i]->setFont(fontMainCharacter); + else + lpItems[i]->setFont(fontNonMainCharacter); + + lpItems[i]->setToolTip(lpCharacter->description()->toPlainText()); + } + + lpModel->appendRow(lpItems); } lpView->header()->setStretchLastSection(true); lpView->expandAll(); - lpView->resizeColumnToContents(0); + + for(int i = 0;i < headerLabels.count();i++) + lpView->resizeColumnToContents(i); + + return(true); +} + +bool cStoryBook::fillPlaceList(QTreeView* lpView) +{ + QStandardItemModel* lpModel = (QStandardItemModel*)lpView->model(); + + lpModel->clear(); + + QStringList headerLabels = QStringList() << tr("name") << tr("location") << tr("type"); + lpModel->setHorizontalHeaderLabels(headerLabels); + + for(int x = 0;x < m_placeList.count();x++) + { + cPlace* lpPlace = m_placeList.at(x); + QList lpItems; + + lpItems.append(new QStandardItem(lpPlace->name())); + lpItems.append(new QStandardItem(lpPlace->location())); + lpItems.append(new QStandardItem(lpPlace->type())); + + for(int i = 0;i < headerLabels.count();i++) + { + lpItems[i]->setData(QVariant::fromValue(lpPlace)); + lpItems[i]->setToolTip(lpPlace->description()->toPlainText()); + } + + lpModel->appendRow(lpItems); + } + + lpView->header()->setStretchLastSection(true); + + lpView->expandAll(); + + for(int i = 0;i < headerLabels.count();i++) + lpView->resizeColumnToContents(i); + + return(true); +} + +bool cStoryBook::fillObjectList(QTreeView* lpView) +{ + QStandardItemModel* lpModel = (QStandardItemModel*)lpView->model(); + + lpModel->clear(); + + QStringList headerLabels = QStringList() << tr("name") << tr("type"); + lpModel->setHorizontalHeaderLabels(headerLabels); + + for(int x = 0;x < m_objectList.count();x++) + { + cObject* lpObject = m_objectList.at(x); + QList lpItems; + + lpItems.append(new QStandardItem(lpObject->name())); + lpItems.append(new QStandardItem(lpObject->type())); + + for(int i = 0;i < headerLabels.count();i++) + { + lpItems[i]->setData(QVariant::fromValue(lpObject)); + lpItems[i]->setToolTip(lpObject->description()->toPlainText()); + } + + lpModel->appendRow(lpItems); + } + + lpView->header()->setStretchLastSection(true); + + lpView->expandAll(); + + for(int i = 0;i < headerLabels.count();i++) + lpView->resizeColumnToContents(i); + + return(true); +} + +bool cStoryBook::fillRechercheList(QTreeView* lpView) +{ + QStandardItemModel* lpModel = (QStandardItemModel*)lpView->model(); + + lpModel->clear(); + + QStringList headerLabels = QStringList() << tr("name") << tr("link"); + lpModel->setHorizontalHeaderLabels(headerLabels); + + for(int x = 0;x < m_rechercheList.count();x++) + { + cRecherche* lpRecherche = m_rechercheList.at(x); + QList lpItems; + + lpItems.append(new QStandardItem(lpRecherche->name())); + lpItems.append(new QStandardItem(lpRecherche->link())); + + for(int i = 0;i < headerLabels.count();i++) + { + lpItems[i]->setData(QVariant::fromValue(lpRecherche)); + lpItems[i]->setToolTip(lpRecherche->description()->toPlainText()); + } + + lpModel->appendRow(lpItems); + } + + lpView->header()->setStretchLastSection(true); + + lpView->expandAll(); + + for(int i = 0;i < headerLabels.count();i++) + lpView->resizeColumnToContents(i); return(true); } diff --git a/cstorybook.h b/cstorybook.h index 2b8b69a..5b7760b 100644 --- a/cstorybook.h +++ b/cstorybook.h @@ -7,6 +7,9 @@ #include "cchapter.h" #include "cscene.h" #include "ccharacter.h" +#include "cplace.h" +#include "cobject.h" +#include "crecherche.h" #include #include @@ -21,7 +24,7 @@ class cStoryBook : public QObject { Q_OBJECT public: - explicit cStoryBook(const QString& szProjectPath, QObject *parent = nullptr); + explicit cStoryBook(const QString& szProject, QObject *parent = nullptr); ~cStoryBook(); bool openDatabase(); @@ -32,8 +35,12 @@ public: bool fillOutlineList(QTreeView* lpView); bool fillCharacterList(QTreeView* lpView); + bool fillPlaceList(QTreeView* lpView); + bool fillObjectList(QTreeView* lpView); + bool fillRechercheList(QTreeView* lpView); + private: - QString m_szProjectPath; + QString m_szProject; bool m_bIsOpen; QSqlDatabase m_db; cBook m_book; @@ -41,6 +48,9 @@ private: cChapterList m_chapterList; cSceneList m_sceneList; cCharacterList m_characterList; + cPlaceList m_placeList; + cObjectList m_objectList; + cRechercheList m_rechercheList; bool createDatabase(); bool updateDatabase(); @@ -51,6 +61,9 @@ private: bool loadChapterList(); bool loadSceneList(); bool loadCharacterList(); + bool loadPlaceList(); + bool loadObjectList(); + bool loadRechercheList(); }; #endif // CSTORYBOOK_H diff --git a/qtStoryWriter.pro b/qtStoryWriter.pro index 80ec1df..dd5c1ba 100644 --- a/qtStoryWriter.pro +++ b/qtStoryWriter.pro @@ -54,7 +54,10 @@ SOURCES += \ cchapter.cpp \ cscene.cpp \ ccharacter.cpp \ - cpartwindow.cpp + cpartwindow.cpp \ + cplace.cpp \ + cobject.cpp \ + crecherche.cpp HEADERS += \ cmainwindow.h \ @@ -70,12 +73,14 @@ HEADERS += \ cchapter.h \ cscene.h \ ccharacter.h \ - cpartwindow.h + cpartwindow.h \ + cplace.h \ + cobject.h \ + crecherche.h FORMS += \ cmainwindow.ui \ cstructurewindow.ui \ - cpartwindow1.ui \ cpartwindow.ui DISTFILES += \