From 849a3e1f854bd637e2a7aba42e5837bddac8e64b Mon Sep 17 00:00:00 2001 From: Herwig Birke Date: Thu, 17 May 2018 15:07:20 +0200 Subject: [PATCH] . --- cbook.h | 33 ++++++++----- ccharacter.cpp | 48 ++++++++++++++----- ccharacter.h | 103 ++++++++++++++++++++++++++++----------- ccharacterwindow.cpp | 9 ++-- cimage.cpp | 27 +++++++++++ cimage.h | 45 +++++++++++++++++ cmainwindow.cpp | 1 + cobject.cpp | 47 ++++++++++++++---- cobject.h | 78 +++++++++++++++++++++++------- cobjectwindow.cpp | 9 ++-- cplace.cpp | 47 ++++++++++++++---- cplace.h | 112 ++++++++++++++++++++++++++++++------------- cplacewindow.cpp | 9 ++-- crecherche.cpp | 80 +++++++++++++++---------------- crecherche.h | 60 ++++++++++++----------- crecherchewindow.cpp | 24 ++++++---- cstorybook.cpp | 21 +++++--- 17 files changed, 536 insertions(+), 217 deletions(-) diff --git a/cbook.h b/cbook.h index e3e7d74..0329de4 100644 --- a/cbook.h +++ b/cbook.h @@ -16,7 +16,18 @@ /*! - \brief + \brief The cStoryBook class provides basic values of a book project. + +With the constructor, the title of the book may be set. + + cBook* lpBook = new cBook("My title"); + +If the database has already been loaded, the book class may be initialized like this: + + cBook* lpBook = new cBook; + lpBook->load(); + +This class should always be initialized by cStoryBook. \class cBook cbook.h "cbook.h" */ @@ -25,7 +36,7 @@ class cBook : public QObject Q_OBJECT public: /*! - \brief constructor of cBook + \brief Creates a new cBook with the given title and parent to hold basic book project values. Use load() to load the values from the database. \fn cBook \param szTitle title of the book @@ -56,7 +67,7 @@ public: */ void setTitle(const QString& szTitle); /*! - \brief Returns the title of the book. + \brief Return the title of the book. \fn title \return title of the book @@ -168,14 +179,14 @@ public: */ QDateTime targetDate(); private: - QString m_szTitle; /*!< title of the document */ - QString m_szSubtitle; /*!< subtitle of the document */ - cTextDocument* m_lpShortDescription; /*!< short description of the document. The text may be formatted */ - cTextDocument* m_lpDescription; /*!< description of the document. The text may be formatted */ - QString m_szAuthor; /*!< name of the author of the document */ - QDateTime m_startedAt; /*!< date and time when the document has been startd */ - QDateTime m_finishedAt; /*!< date and time when the document has been finished */ - QDateTime m_targetDate; /*!< date and time when the document should be finished */ + QString m_szTitle; /*!< This property holds the title of the document.
The default value is empty.
Access functions:
QStringtitle()
voidsetTitle(const QString& szTitle)
*/ + QString m_szSubtitle; /*!< subtitle of the document */ + cTextDocument* m_lpShortDescription; /*!< short description of the document. The text may be formatted */ + cTextDocument* m_lpDescription; /*!< description of the document. The text may be formatted */ + QString m_szAuthor; /*!< name of the author of the document */ + QDateTime m_startedAt; /*!< date and time when the document has been startd */ + QDateTime m_finishedAt; /*!< date and time when the document has been finished */ + QDateTime m_targetDate; /*!< date and time when the document should be finished */ }; Q_DECLARE_METATYPE(cBook*) diff --git a/ccharacter.cpp b/ccharacter.cpp index 99923a6..69fcfe1 100644 --- a/ccharacter.cpp +++ b/ccharacter.cpp @@ -344,18 +344,43 @@ cTextDocument* cCharacter::description() return(m_lpDescription); } -void cCharacter::addImage(cImage* lpImage) +void cCharacter::addImage(cImage* lpImage, cTextDocument* lpDescription) { - if(m_imageList.contains(lpImage)) - return; - m_imageList.append(lpImage); + m_imageList.append(new cImageDescription(lpImage, lpDescription)); } -QList cCharacter::images() +QList cCharacter::images() { return(m_imageList); } +cCharacterDescription::cCharacterDescription(cCharacter* lpCharacter, cTextDocument* lpDescription, QObject* parent) : + QObject(parent) +{ + setCharacter(lpCharacter); + setDescription(lpDescription); +} + +void cCharacterDescription::setCharacter(cCharacter* lpCharacter) +{ + m_lpCharacter = lpCharacter; +} + +cCharacter* cCharacterDescription::character() +{ + return(m_lpCharacter); +} + +void cCharacterDescription::setDescription(cTextDocument* lpDescription) +{ + m_lpDescription = lpDescription; +} + +cTextDocument* cCharacterDescription::description() +{ + return(m_lpDescription); +} + cCharacter* cCharacterList::add(const qint32& iID) { cCharacter* lpCharacter = find(iID); @@ -424,7 +449,7 @@ bool cCharacterList::load(cImageList *lpImageList) lpCharacter->setDescription(blob2TextDocument(query.value("description").toByteArray())); } - query.prepare("SELECT characterID, imageID FROM characterImage;"); + query.prepare("SELECT characterID, imageID, description FROM characterImage;"); if(!query.exec()) { myDebug << query.lastError().text(); @@ -438,7 +463,7 @@ bool cCharacterList::load(cImageList *lpImageList) { cImage* lpImage = lpImageList->find(query.value("imageID").toInt()); if(lpImage) - lpCharacter->addImage(lpImage); + lpCharacter->addImage(lpImage, blob2TextDocument(query.value("description").toByteArray())); } } @@ -459,7 +484,7 @@ bool cCharacterList::save() QSqlQuery imageAdd; imageDelete.prepare("DELETE FROM characterImage WHERE characterID=:characterID;"); - imageAdd.prepare("INSERT INTO characterImage (characterID, imageID) VALUES (:characterID, :imageID);"); + imageAdd.prepare("INSERT INTO characterImage (characterID, imageID, description) VALUES (:characterID, :imageID, :description);"); for(int x = 0;x < count();x++) { @@ -548,14 +573,15 @@ bool cCharacterList::save() return(false); } - QList images = lpCharacter->images(); + QList images = lpCharacter->images(); for(int x = 0;x < images.count();x++) { - cImage* lpImage = images.at(x); + cImageDescription* lpImage = images.at(x); imageAdd.bindValue(":characterID", lpCharacter->id()); - imageAdd.bindValue(":imageID", lpImage->id()); + imageAdd.bindValue(":imageID", lpImage->image()->id()); + imageAdd.bindValue(":description", textDocument2Blob(lpImage->description())); if(!imageAdd.exec()) { myDebug << imageAdd.lastError().text(); diff --git a/ccharacter.h b/ccharacter.h index 4df56f8..6fd0851 100644 --- a/ccharacter.h +++ b/ccharacter.h @@ -467,47 +467,92 @@ public: \fn addImage \param lpImage */ - void addImage(cImage* lpImage); + void addImage(cImage* lpImage, cTextDocument* lpDescription); /*! \brief \fn images \return QList */ - QList images(); + QList images(); private: - qint32 m_id; /*!< TODO: describe */ - bool m_bMainCharacter; /*!< TODO: describe */ - QString m_szCreature; /*!< TODO: describe */ - GENDER m_gender; /*!< TODO: describe */ - QString m_szTitle; /*!< TODO: describe */ - QString m_szFirstName; /*!< TODO: describe */ - QString m_szMiddleName; /*!< TODO: describe */ - QString m_szLastName; /*!< TODO: describe */ - QString m_szNickName; /*!< TODO: describe */ - qreal m_dHeight; /*!< TODO: describe */ - qreal m_dWeight; /*!< TODO: describe */ - qreal m_dAge; /*!< TODO: describe */ - QDate m_dateOfBirth; /*!< TODO: describe */ - QString m_szPlaceOfBirth; /*!< TODO: describe */ - QDate m_dateOfDeath; /*!< TODO: describe */ - QString m_szPlaceOfDeath; /*!< TODO: describe */ - QString m_szHairColor; /*!< TODO: describe */ - QString m_szHairCut; /*!< TODO: describe */ - QString m_szHairLength; /*!< TODO: describe */ - QString m_szFigure; /*!< TODO: describe */ - QString m_szNature; /*!< TODO: describe */ - QString m_szSpokenLanguages; /*!< TODO: describe */ - QString m_szSkin; /*!< TODO: describe */ - QString m_szSchool; /*!< TODO: describe */ - QString m_szJob; /*!< TODO: describe */ - cTextDocument* m_lpDescription; /*!< TODO: describe */ - QList m_imageList; /*!< TODO: describe */ + qint32 m_id; /*!< TODO: describe */ + bool m_bMainCharacter; /*!< TODO: describe */ + QString m_szCreature; /*!< TODO: describe */ + GENDER m_gender; /*!< TODO: describe */ + QString m_szTitle; /*!< TODO: describe */ + QString m_szFirstName; /*!< TODO: describe */ + QString m_szMiddleName; /*!< TODO: describe */ + QString m_szLastName; /*!< TODO: describe */ + QString m_szNickName; /*!< TODO: describe */ + qreal m_dHeight; /*!< TODO: describe */ + qreal m_dWeight; /*!< TODO: describe */ + qreal m_dAge; /*!< TODO: describe */ + QDate m_dateOfBirth; /*!< TODO: describe */ + QString m_szPlaceOfBirth; /*!< TODO: describe */ + QDate m_dateOfDeath; /*!< TODO: describe */ + QString m_szPlaceOfDeath; /*!< TODO: describe */ + QString m_szHairColor; /*!< TODO: describe */ + QString m_szHairCut; /*!< TODO: describe */ + QString m_szHairLength; /*!< TODO: describe */ + QString m_szFigure; /*!< TODO: describe */ + QString m_szNature; /*!< TODO: describe */ + QString m_szSpokenLanguages; /*!< TODO: describe */ + QString m_szSkin; /*!< TODO: describe */ + QString m_szSchool; /*!< TODO: describe */ + QString m_szJob; /*!< TODO: describe */ + cTextDocument* m_lpDescription; /*!< TODO: describe */ + QList m_imageList; /*!< TODO: describe */ signals: public slots: }; +/*! + \brief + + \class cCharacterDescription ccharacter.h "ccharacter.h" +*/ +class cCharacterDescription : public QObject +{ + Q_OBJECT +public: + cCharacterDescription(cCharacter* lpCharacter, cTextDocument* lpDescription, QObject* parent = nullptr); + + /*! + \brief + + \fn setCharacter + \param lpCharacter + */ + void setCharacter(cCharacter* lpCharacter); + /*! + \brief + + \fn character + \return cCharacter + */ + cCharacter* character(); + + /*! + \brief + + \fn setDescription + \param lpDescription + */ + void setDescription(cTextDocument* lpDescription); + /*! + \brief + + \fn description + \return cTextDocument + */ + cTextDocument* description(); +private: + cCharacter* m_lpCharacter; /*!< TODO: describe */ + cTextDocument* m_lpDescription; /*!< TODO: describe */ +}; + Q_DECLARE_METATYPE(cCharacter*) /*! diff --git a/ccharacterwindow.cpp b/ccharacterwindow.cpp index 9e29cc9..955143a 100644 --- a/ccharacterwindow.cpp +++ b/ccharacterwindow.cpp @@ -148,12 +148,13 @@ void cCharacterWindow::setCharacter(cCharacter* lpCharacter) ui->m_lpJob->setHtml(lpCharacter->job()); ui->m_lpDescription->setDocument(lpCharacter->description()); - QList images = lpCharacter->images(); + QList images = lpCharacter->images(); for(int x = 0;x < images.count();x++) { - cImage* lpImage = images[x]; - QPixmap pixmap = lpImage->image(); - cImageWidget* lpImageWidget = new cImageWidget; + cImageDescription* lpImageDescription = images[x]; + cImage* lpImage = lpImageDescription->image(); + QPixmap pixmap = lpImage->image(); + cImageWidget* lpImageWidget = new cImageWidget; lpImageWidget->setValues(lpImage->name(), lpImage->type(), lpImage->description(), pixmap); ui->m_lpLayout->addWidget(lpImageWidget); diff --git a/cimage.cpp b/cimage.cpp index 9e70cd9..209978e 100644 --- a/cimage.cpp +++ b/cimage.cpp @@ -71,6 +71,33 @@ QPixmap cImage::image() return(m_image); } +cImageDescription::cImageDescription(cImage* lpImage, cTextDocument* lpDescription, QObject* parent) : + QObject(parent) +{ + setImage(lpImage); + setDescription(lpDescription); +} + +void cImageDescription::setImage(cImage* lpImage) +{ + m_lpImage = lpImage; +} + +cImage* cImageDescription::image() +{ + return(m_lpImage); +} + +void cImageDescription::setDescription(cTextDocument* lpDescription) +{ + m_lpDescription = lpDescription; +} + +cTextDocument* cImageDescription::description() +{ + return(m_lpDescription); +} + cImage* cImageList::add(const qint32& iID) { cImage* lpImage = find(iID); diff --git a/cimage.h b/cimage.h index ed0f037..22ed830 100644 --- a/cimage.h +++ b/cimage.h @@ -108,6 +108,51 @@ private: QPixmap m_image; /*!< TODO: describe */ }; +/*! + \brief + + \class cImageDescription cimage.h "cimage.h" +*/ +class cImageDescription : public QObject +{ + Q_OBJECT +public: + cImageDescription(cImage* lpImage, cTextDocument* lpDescription, QObject* parent = nullptr); + + /*! + \brief + + \fn setImage + \param lpImage + */ + void setImage(cImage* lpImage); + /*! + \brief + + \fn image + \return cImage + */ + cImage* image(); + + /*! + \brief + + \fn setDescription + \param lpDescription + */ + void setDescription(cTextDocument* lpDescription); + /*! + \brief + + \fn description + \return cTextDocument + */ + cTextDocument* description(); +private: + cImage* m_lpImage; /*!< TODO: describe */ + cTextDocument* m_lpDescription; /*!< TODO: describe */ +}; + Q_DECLARE_METATYPE(cImage*) /*! diff --git a/cmainwindow.cpp b/cmainwindow.cpp index 90608d9..0401105 100644 --- a/cmainwindow.cpp +++ b/cmainwindow.cpp @@ -1969,6 +1969,7 @@ void cMainWindow::openRecentFile() m_lpStoryBook->fillObjectList(ui->m_lpObjectList); m_lpStoryBook->fillRechercheList(ui->m_lpRechercheList); + setCurrentFile(szProjectName); updateWindowTitle(); } } diff --git a/cobject.cpp b/cobject.cpp index ff19809..2c9edcc 100644 --- a/cobject.cpp +++ b/cobject.cpp @@ -60,18 +60,43 @@ cTextDocument* cObject::description() return(m_lpDescription); } -void cObject::addImage(cImage* lpImage) +void cObject::addImage(cImage* lpImage, cTextDocument* lpDescription) { - if(m_imageList.contains(lpImage)) - return; - m_imageList.append(lpImage); + m_imageList.append(new cImageDescription(lpImage, lpDescription)); } -QList cObject::images() +QList cObject::images() { return(m_imageList); } +cObjectDescription::cObjectDescription(cObject* lpObject, cTextDocument* lpDescription, QObject* parent) : + QObject(parent) +{ + setObject(lpObject); + setDescription(lpDescription); +} + +void cObjectDescription::setObject(cObject* lpObject) +{ + m_lpObject = lpObject; +} + +cObject* cObjectDescription::object() +{ + return(m_lpObject); +} + +void cObjectDescription::setDescription(cTextDocument* lpDescription) +{ + m_lpDescription = lpDescription; +} + +cTextDocument* cObjectDescription::description() +{ + return(m_lpDescription); +} + cObject* cObjectList::add(const qint32& iID) { cObject* lpObject = find(iID); @@ -119,7 +144,7 @@ bool cObjectList::load(cImageList *lpImageList) lpObject->setDescription(blob2TextDocument(query.value("description").toByteArray())); } - query.prepare("SELECT objectID, imageID FROM objectImage;"); + query.prepare("SELECT objectID, imageID, description FROM objectImage;"); if(!query.exec()) { myDebug << query.lastError().text(); @@ -133,7 +158,7 @@ bool cObjectList::load(cImageList *lpImageList) { cImage* lpImage = lpImageList->find(query.value("imageID").toInt()); if(lpImage) - lpObject->addImage(lpImage); + lpObject->addImage(lpImage, blob2TextDocument(query.value(":description").toByteArray())); } } @@ -154,7 +179,7 @@ bool cObjectList::save() QSqlQuery imageAdd; imageDelete.prepare("DELETE FROM objectImage WHERE objectID=:objectID;"); - imageAdd.prepare("INSERT INTO objectImage (objectID, imageID) VALUES (:objectID, :imageID);"); + imageAdd.prepare("INSERT INTO objectImage (objectID, imageID, description) VALUES (:objectID, :imageID, :description);"); for(int x = 0;x < count();x++) { @@ -201,14 +226,16 @@ bool cObjectList::save() return(false); } - QList images = lpObject->images(); + QList images = lpObject->images(); for(int x = 0;x < images.count();x++) { - cImage* lpImage = images.at(x); + cImageDescription* lpImageDescription = images.at(x); + cImage* lpImage = lpImageDescription->image(); imageAdd.bindValue(":objectID", lpObject->id()); imageAdd.bindValue(":imageID", lpImage->id()); + imageAdd.bindValue(":description", textDocument2Blob(lpImageDescription->description())); if(!imageAdd.exec()) { myDebug << imageAdd.lastError().text(); diff --git a/cobject.h b/cobject.h index 9f37923..fd147b9 100644 --- a/cobject.h +++ b/cobject.h @@ -40,14 +40,14 @@ public: \fn setID \param iID */ - void setID(const qint32& iID); + void setID(const qint32& iID); /*! \brief \fn id \return qint32 */ - qint32 id(); + qint32 id(); /*! \brief @@ -55,14 +55,14 @@ public: \fn setName \param szName */ - void setName(const QString& szName); + void setName(const QString& szName); /*! \brief \fn name \return QString */ - QString name(); + QString name(); /*! \brief @@ -70,14 +70,14 @@ public: \fn setType \param szType */ - void setType(const QString& szType); + void setType(const QString& szType); /*! \brief \fn type \return QString */ - QString type(); + QString type(); /*! \brief @@ -85,42 +85,88 @@ public: \fn setDescription \param lpDescription */ - void setDescription(cTextDocument* lpDescription); + void setDescription(cTextDocument* lpDescription); /*! \brief \fn description \return cTextDocument */ - cTextDocument* description(); + cTextDocument* description(); /*! \brief \fn addImage \param lpImage + \param lpDescription */ - void addImage(cImage* lpImage); + void addImage(cImage* lpImage, cTextDocument* lpDescription); /*! \brief \fn images - \return QList + \return QList */ - QList images(); + QList images(); private: - qint32 m_iID; /*!< TODO: describe */ - QString m_szName; /*!< TODO: describe */ - QString m_szType; /*!< TODO: describe */ - cTextDocument* m_lpDescription; /*!< TODO: describe */ - QList m_imageList; /*!< TODO: describe */ + qint32 m_iID; /*!< TODO: describe */ + QString m_szName; /*!< TODO: describe */ + QString m_szType; /*!< TODO: describe */ + cTextDocument* m_lpDescription; /*!< TODO: describe */ + QList m_imageList; /*!< TODO: describe */ signals: public slots: }; +/*! + \brief + + \class cObjectDescription cobject.h "cobject.h" +*/ +class cObjectDescription : public QObject +{ + Q_OBJECT +public: + cObjectDescription(cObject* lpObject, cTextDocument* lpDescription, QObject* parent = nullptr); + + /*! + \brief + + \fn setObject + \param lpObject + */ + void setObject(cObject* lpObject); + /*! + \brief + + \fn object + \return cObject + */ + cObject* object(); + + /*! + \brief + + \fn setDescription + \param lpDescription + */ + void setDescription(cTextDocument* lpDescription); + /*! + \brief + + \fn description + \return cTextDocument + */ + cTextDocument* description(); +private: + cObject* m_lpObject; /*!< TODO: describe */ + cTextDocument* m_lpDescription; /*!< TODO: describe */ +}; + Q_DECLARE_METATYPE(cObject*) /*! diff --git a/cobjectwindow.cpp b/cobjectwindow.cpp index a01be13..696b548 100644 --- a/cobjectwindow.cpp +++ b/cobjectwindow.cpp @@ -46,12 +46,13 @@ void cObjectWindow::setObject(cObject* lpObject) ui->m_lpType->setText(lpObject->type()); ui->m_lpDescription->setDocument(lpObject->description()); - QList images = lpObject->images(); + QList images = lpObject->images(); for(int x = 0;x < images.count();x++) { - cImage* lpImage = images[x]; - QPixmap pixmap = lpImage->image(); - cImageWidget* lpImageWidget = new cImageWidget; + cImageDescription* lpImageDescription = images[x]; + cImage* lpImage = lpImageDescription->image(); + QPixmap pixmap = lpImage->image(); + cImageWidget* lpImageWidget = new cImageWidget; lpImageWidget->setValues(lpImage->name(), lpImage->type(), lpImage->description(), pixmap); ui->m_lpLayout->addWidget(lpImageWidget); diff --git a/cplace.cpp b/cplace.cpp index f6b9300..d1a316e 100644 --- a/cplace.cpp +++ b/cplace.cpp @@ -71,18 +71,43 @@ cTextDocument* cPlace::description() return(m_lpDescription); } -void cPlace::addImage(cImage* lpImage) +void cPlace::addImage(cImage* lpImage, cTextDocument* lpDescription) { - if(m_imageList.contains(lpImage)) - return; - m_imageList.append(lpImage); + m_imageList.append(new cImageDescription(lpImage, lpDescription)); } -QList cPlace::images() +QList cPlace::images() { return(m_imageList); } +cPlaceDescription::cPlaceDescription(cPlace* lpPlace, cTextDocument* lpDescription, QObject* parent) : + QObject(parent) +{ + setPlace(lpPlace); + setDescription(lpDescription); +} + +void cPlaceDescription::setPlace(cPlace* lpPlace) +{ + m_lpPlace = lpPlace; +} + +cPlace* cPlaceDescription::place() +{ + return(m_lpPlace); +} + +void cPlaceDescription::setDescription(cTextDocument* lpDescription) +{ + m_lpDescription = lpDescription; +} + +cTextDocument* cPlaceDescription::description() +{ + return(m_lpDescription); +} + cPlace* cPlaceList::add(const qint32& iID) { cPlace* lpPlace = find(iID); @@ -131,7 +156,7 @@ bool cPlaceList::load(cImageList *lpImageList) lpPlace->setDescription(blob2TextDocument(query.value("description").toByteArray())); } - query.prepare("SELECT placeID, imageID FROM placeImage;"); + query.prepare("SELECT placeID, imageID, description FROM placeImage;"); if(!query.exec()) { myDebug << query.lastError().text(); @@ -145,7 +170,7 @@ bool cPlaceList::load(cImageList *lpImageList) { cImage* lpImage = lpImageList->find(query.value("imageID").toInt()); if(lpImage) - lpPlace->addImage(lpImage); + lpPlace->addImage(lpImage, blob2TextDocument(query.value("description").toByteArray())); } } @@ -166,7 +191,7 @@ bool cPlaceList::save() QSqlQuery imageAdd; imageDelete.prepare("DELETE FROM placeImage WHERE placeID=:placeID;"); - imageAdd.prepare("INSERT INTO placeImage (placeID, imageID) VALUES (:placeID, :imageID);"); + imageAdd.prepare("INSERT INTO placeImage (placeID, imageID, description) VALUES (:placeID, :imageID, :description);"); for(int x = 0;x < count();x++) { @@ -215,14 +240,16 @@ bool cPlaceList::save() return(false); } - QList images = lpPlace->images(); + QList images = lpPlace->images(); for(int x = 0;x < images.count();x++) { - cImage* lpImage = images.at(x); + cImageDescription* lpImageDescription = images.at(x); + cImage* lpImage = lpImageDescription->image(); imageAdd.bindValue(":placeID", lpPlace->id()); imageAdd.bindValue(":imageID", lpImage->id()); + imageAdd.bindValue(":description", textDocument2Blob(lpImageDescription->description())); if(!imageAdd.exec()) { myDebug << imageAdd.lastError().text(); diff --git a/cplace.h b/cplace.h index 9c4a875..c0787d5 100644 --- a/cplace.h +++ b/cplace.h @@ -40,14 +40,14 @@ public: \fn setID \param iID */ - void setID(const qint32& iID); + void setID(const qint32& iID); /*! \brief \fn id \return qint32 */ - qint32 id(); + qint32 id(); /*! \brief @@ -55,14 +55,14 @@ public: \fn setName \param szName */ - void setName(const QString& szName); + void setName(const QString& szName); /*! \brief \fn name \return QString */ - QString name(); + QString name(); /*! \brief @@ -70,14 +70,14 @@ public: \fn setLocation \param szLocation */ - void setLocation(const QString& szLocation); + void setLocation(const QString& szLocation); /*! \brief \fn location \return QString */ - QString location(); + QString location(); /*! \brief @@ -85,14 +85,84 @@ public: \fn setType \param szType */ - void setType(const QString& szType); + void setType(const QString& szType); /*! \brief \fn type \return QString */ - QString type(); + QString type(); + + /*! + \brief + + \fn setDescription + \param lpDescription + */ + void setDescription(cTextDocument* lpDescription); + /*! + \brief + + \fn description + \return cTextDocument + */ + cTextDocument* description(); + + /*! + \brief + + \fn addImage + \param lpImage + \param lpDescription + */ + void addImage(cImage* lpImage, cTextDocument* lpDescription); + /*! + \brief + + \fn images + \return QList + */ + QList images(); + +private: + qint32 m_iID; /*!< TODO: describe */ + QString m_szName; /*!< TODO: describe */ + QString m_szLocation; /*!< TODO: describe */ + QString m_szType; /*!< TODO: describe */ + cTextDocument* m_lpDescription; /*!< TODO: describe */ + QList m_imageList; /*!< TODO: describe */ + +signals: + +public slots: +}; + +/*! + \brief + + \class cPlaceDescription cplace.h "cplace.h" +*/ +class cPlaceDescription : public QObject +{ + Q_OBJECT +public: + cPlaceDescription(cPlace* lpPlace, cTextDocument* lpDescription, QObject* parent = nullptr); + + /*! + \brief + + \fn setPlace + \param lpPlace + */ + void setPlace(cPlace* lpPlace); + /*! + \brief + + \fn place + \return cPlace + */ + cPlace* place(); /*! \brief @@ -108,33 +178,9 @@ public: \return cTextDocument */ cTextDocument* description(); - - /*! - \brief - - \fn addImage - \param lpImage - */ - void addImage(cImage* lpImage); - /*! - \brief - - \fn images - \return QList - */ - QList images(); - private: - qint32 m_iID; /*!< TODO: describe */ - QString m_szName; /*!< TODO: describe */ - QString m_szLocation; /*!< TODO: describe */ - QString m_szType; /*!< TODO: describe */ + cPlace* m_lpPlace; /*!< TODO: describe */ cTextDocument* m_lpDescription; /*!< TODO: describe */ - QList m_imageList; /*!< TODO: describe */ - -signals: - -public slots: }; Q_DECLARE_METATYPE(cPlace*) diff --git a/cplacewindow.cpp b/cplacewindow.cpp index 8a81114..2175c00 100644 --- a/cplacewindow.cpp +++ b/cplacewindow.cpp @@ -50,12 +50,13 @@ void cPlaceWindow::setPlace(cPlace* lpPlace) ui->m_lpLocation->setText(lpPlace->location()); ui->m_lpDescription->setDocument(lpPlace->description()); - QList images = lpPlace->images(); + QList images = lpPlace->images(); for(int x = 0;x < images.count();x++) { - cImage* lpImage = images[x]; - QPixmap pixmap = lpImage->image(); - cImageWidget* lpImageWidget = new cImageWidget; + cImageDescription* lpImageDescription = images[x]; + cImage* lpImage = lpImageDescription->image(); + QPixmap pixmap = lpImage->image(); + cImageWidget* lpImageWidget = new cImageWidget; lpImageWidget->setValues(lpImage->name(), lpImage->type(), lpImage->description(), pixmap); ui->m_lpLayout->addWidget(lpImageWidget); diff --git a/crecherche.cpp b/crecherche.cpp index bb652e2..768a14a 100644 --- a/crecherche.cpp +++ b/crecherche.cpp @@ -60,50 +60,42 @@ cTextDocument* cRecherche::description() return(m_lpDescription); } -void cRecherche::addImage(cImage* lpImage) +void cRecherche::addImage(cImage* lpImage, cTextDocument* lpDescription) { - if(m_imageList.contains(lpImage)) - return; - m_imageList.append(lpImage); + m_imageList.append(new cImageDescription(lpImage, lpDescription)); } -void cRecherche::addCharacter(cCharacter* lpCharacter) +void cRecherche::addCharacter(cCharacter* lpCharacter, cTextDocument* lpDescription) { - if(m_characterList.contains(lpCharacter)) - return; - m_characterList.append(lpCharacter); + m_characterList.append(new cCharacterDescription(lpCharacter, lpDescription)); } -void cRecherche::addObject(cObject* lpObject) +void cRecherche::addObject(cObject* lpObject, cTextDocument* lpDescription) { - if(m_objectList.contains(lpObject)) - return; - m_objectList.append(lpObject); + m_objectList.append(new cObjectDescription(lpObject, lpDescription)); } -void cRecherche::addPlace(cPlace* lpPlace) +void cRecherche::addPlace(cPlace* lpPlace, cTextDocument* lpDescription) { - if(m_placeList.contains(lpPlace)) - return; - m_placeList.append(lpPlace); + m_placeList.append(new cPlaceDescription(lpPlace, lpDescription)); } -QList cRecherche::images() +QList cRecherche::images() { return(m_imageList); } -QList cRecherche::characterList() +QList cRecherche::characterList() { return(m_characterList); } -QList cRecherche::objectList() +QList cRecherche::objectList() { return(m_objectList); } -QList cRecherche::placeList() +QList cRecherche::placeList() { return(m_placeList); } @@ -155,7 +147,7 @@ bool cRechercheList::load(cImageList *lpImageList, cCharacterList *lpCharacterLi lpObject->setDescription(blob2TextDocument(query.value("description").toByteArray())); } - query.prepare("SELECT rechercheID, imageID FROM rechercheImage;"); + query.prepare("SELECT rechercheID, imageID, description FROM rechercheImage;"); if(!query.exec()) { myDebug << query.lastError().text(); @@ -169,11 +161,11 @@ bool cRechercheList::load(cImageList *lpImageList, cCharacterList *lpCharacterLi { cImage* lpImage = lpImageList->find(query.value("imageID").toInt()); if(lpImage) - lpRecherche->addImage(lpImage); + lpRecherche->addImage(lpImage, blob2TextDocument(query.value("description").toByteArray())); } } - query.prepare("SELECT rechercheID, characterID FROM rechercheCharacter;"); + query.prepare("SELECT rechercheID, characterID, description FROM rechercheCharacter;"); if(!query.exec()) { myDebug << query.lastError().text(); @@ -187,11 +179,11 @@ bool cRechercheList::load(cImageList *lpImageList, cCharacterList *lpCharacterLi { cCharacter* lpCharacter = lpCharacterList->find(query.value("characterID").toInt()); if(lpCharacter) - lpRecherche->addCharacter(lpCharacter); + lpRecherche->addCharacter(lpCharacter, blob2TextDocument(query.value("description").toByteArray())); } } - query.prepare("SELECT rechercheID, objectID FROM rechercheObject;"); + query.prepare("SELECT rechercheID, objectID, description FROM rechercheObject;"); if(!query.exec()) { myDebug << query.lastError().text(); @@ -205,11 +197,11 @@ bool cRechercheList::load(cImageList *lpImageList, cCharacterList *lpCharacterLi { cObject* lpObject = lpObjectList->find(query.value("objectID").toInt()); if(lpObject) - lpRecherche->addObject(lpObject); + lpRecherche->addObject(lpObject, blob2TextDocument(query.value("description").toByteArray())); } } - query.prepare("SELECT rechercheID, placeID FROM recherchePlace;"); + query.prepare("SELECT rechercheID, placeID, description FROM recherchePlace;"); if(!query.exec()) { myDebug << query.lastError().text(); @@ -223,7 +215,7 @@ bool cRechercheList::load(cImageList *lpImageList, cCharacterList *lpCharacterLi { cPlace* lpPlace = lpPlaceList->find(query.value("placeID").toInt()); if(lpPlace) - lpRecherche->addPlace(lpPlace); + lpRecherche->addPlace(lpPlace, blob2TextDocument(query.value("description").toByteArray())); } } @@ -243,22 +235,22 @@ bool cRechercheList::save() QSqlQuery imageDelete; QSqlQuery imageAdd; imageDelete.prepare("DELETE FROM rechercheImage WHERE rechercheID=:rechercheID;"); - imageAdd.prepare("INSERT INTO rechercheImage (rechercheID, imageID) VALUES (:rechercheID, :imageID);"); + imageAdd.prepare("INSERT INTO rechercheImage (rechercheID, imageID, description) VALUES (:rechercheID, :imageID, :description);"); QSqlQuery characterDelete; QSqlQuery characterAdd; characterDelete.prepare("DELETE FROM rechercheCharacter WHERE rechercheID=:rechercheID;"); - characterAdd.prepare("INSERT INTO rechercheCharacter (rechercheID, characterID) VALUES (:rechercheID, :characterID);"); + characterAdd.prepare("INSERT INTO rechercheCharacter (rechercheID, characterID, description) VALUES (:rechercheID, :characterID, :description);"); QSqlQuery objectDelete; QSqlQuery objectAdd; objectDelete.prepare("DELETE FROM rechercheObject WHERE rechercheID=:rechercheID;"); - objectAdd.prepare("INSERT INTO rechercheObject (rechercheID, ObjectID) VALUES (:rechercheID, :objectID);"); + objectAdd.prepare("INSERT INTO rechercheObject (rechercheID, ObjectID, description) VALUES (:rechercheID, :objectID, :description);"); QSqlQuery placeDelete; QSqlQuery placeAdd; placeDelete.prepare("DELETE FROM recherchePlace WHERE rechercheID=:rechercheID;"); - placeAdd.prepare("INSERT INTO recherchePlace (rechercheID, placeID) VALUES (:rechercheID, :placeID);"); + placeAdd.prepare("INSERT INTO recherchePlace (rechercheID, placeID, description) VALUES (:rechercheID, :placeID, :description);"); for(int x = 0;x < count();x++) { @@ -326,14 +318,16 @@ bool cRechercheList::save() return(false); } - QList images = lpRecherche->images(); + QList images = lpRecherche->images(); for(int x = 0;x < images.count();x++) { - cImage* lpImage = images.at(x); + cImageDescription* lpImageDescription = images.at(x); + cImage* lpImage = lpImageDescription->image(); imageAdd.bindValue(":rechercheID", lpRecherche->id()); imageAdd.bindValue(":imageID", lpImage->id()); + imageAdd.bindValue(":description", textDocument2Blob(lpImageDescription->description())); if(!imageAdd.exec()) { myDebug << imageAdd.lastError().text(); @@ -341,14 +335,16 @@ bool cRechercheList::save() } } - QList characters = lpRecherche->characterList(); + QList characters = lpRecherche->characterList(); for(int x = 0;x < characters.count();x++) { - cCharacter* lpCharacter = characters.at(x); + cCharacterDescription* lpCharacterDescription = characters.at(x); + cCharacter* lpCharacter = lpCharacterDescription->character(); characterAdd.bindValue(":rechercheID", lpRecherche->id()); characterAdd.bindValue(":characterID", lpCharacter->id()); + characterAdd.bindValue(":description", textDocument2Blob(lpCharacterDescription->description())); if(!characterAdd.exec()) { myDebug << characterAdd.lastError().text(); @@ -356,14 +352,16 @@ bool cRechercheList::save() } } - QList objects = lpRecherche->objectList(); + QList objects = lpRecherche->objectList(); for(int x = 0;x < objects.count();x++) { - cObject* lpObject = objects.at(x); + cObjectDescription* lpObjectDescription = objects.at(x); + cObject* lpObject = lpObjectDescription->object(); objectAdd.bindValue(":rechercheID", lpRecherche->id()); objectAdd.bindValue(":objectID", lpObject->id()); + objectAdd.bindValue(":description", textDocument2Blob(lpObjectDescription->description())); if(!objectAdd.exec()) { myDebug << objectAdd.lastError().text(); @@ -371,14 +369,16 @@ bool cRechercheList::save() } } - QList places = lpRecherche->placeList(); + QList places = lpRecherche->placeList(); for(int x = 0;x < places.count();x++) { - cPlace* lpPlace = places.at(x); + cPlaceDescription* lpPlaceDescription = places.at(x); + cPlace* lpPlace = lpPlaceDescription->place(); placeAdd.bindValue(":rechercheID", lpRecherche->id()); placeAdd.bindValue(":placeID", lpPlace->id()); + placeAdd.bindValue(":description", textDocument2Blob(lpPlaceDescription->description())); if(!placeAdd.exec()) { myDebug << placeAdd.lastError().text(); diff --git a/crecherche.h b/crecherche.h index 5200482..550bf3f 100644 --- a/crecherche.h +++ b/crecherche.h @@ -43,14 +43,14 @@ public: \fn setID \param iID */ - void setID(const qint32& iID); + void setID(const qint32& iID); /*! \brief \fn id \return qint32 */ - qint32 id(); + qint32 id(); /*! \brief @@ -58,14 +58,14 @@ public: \fn setName \param szName */ - void setName(const QString& szName); + void setName(const QString& szName); /*! \brief \fn name \return QString */ - QString name(); + QString name(); /*! \brief @@ -73,14 +73,14 @@ public: \fn setLink \param szLink */ - void setLink(const QString& szLink); + void setLink(const QString& szLink); /*! \brief \fn link \return QString */ - QString link(); + QString link(); /*! \brief @@ -88,82 +88,86 @@ public: \fn setDescription \param lpDescription */ - void setDescription(cTextDocument* lpDescription); + void setDescription(cTextDocument* lpDescription); /*! \brief \fn description \return cTextDocument */ - cTextDocument* description(); + cTextDocument* description(); /*! \brief \fn addImage \param lpImage + \param lpDescription */ - void addImage(cImage* lpImage); + void addImage(cImage* lpImage, cTextDocument* lpDescription); /*! \brief \fn addCharacter \param lpCharacter + \param lpDescription */ - void addCharacter(cCharacter* lpCharacter); + void addCharacter(cCharacter* lpCharacter, cTextDocument* lpDescription); /*! \brief \fn addObject \param lpObject + \param lpDescription */ - void addObject(cObject* lpObject); + void addObject(cObject* lpObject, cTextDocument* lpDescription); /*! \brief \fn addPlace \param lpPlace + \param lpDescription */ - void addPlace(cPlace* lpPlace); + void addPlace(cPlace* lpPlace, cTextDocument* lpDescription); /*! \brief \fn images - \return QList + \return QList */ - QList images(); + QList images(); /*! \brief \fn characterList - \return QList + \return QList */ - QList characterList(); + QList characterList(); /*! \brief \fn objectList - \return QList + \return QList */ - QList objectList(); + QList objectList(); /*! \brief \fn placeList - \return QList + \return QList */ - QList placeList(); + QList placeList(); private: - qint32 m_iID; /*!< TODO: describe */ - QString m_szName; /*!< TODO: describe */ - QString m_szLink; /*!< TODO: describe */ - cTextDocument* m_lpDescription; /*!< TODO: describe */ - QList m_imageList; /*!< TODO: describe */ - QList m_characterList; /*!< TODO: describe */ - QList m_objectList; /*!< TODO: describe */ - QList m_placeList; /*!< TODO: describe */ + qint32 m_iID; /*!< TODO: describe */ + QString m_szName; /*!< TODO: describe */ + QString m_szLink; /*!< TODO: describe */ + cTextDocument* m_lpDescription; /*!< TODO: describe */ + QList m_imageList; /*!< TODO: describe */ + QList m_characterList; /*!< TODO: describe */ + QList m_objectList; /*!< TODO: describe */ + QList m_placeList; /*!< TODO: describe */ signals: diff --git a/crecherchewindow.cpp b/crecherchewindow.cpp index 917d107..8fd8469 100644 --- a/crecherchewindow.cpp +++ b/crecherchewindow.cpp @@ -71,12 +71,13 @@ void cRechercheWindow::setRecherche(cRecherche* lpRecherche) ui->m_lpLink->setText(lpRecherche->link()); ui->m_lpDescription->setDocument(lpRecherche->description()); - QList images = lpRecherche->images(); + QList images = lpRecherche->images(); for(int x = 0;x < images.count();x++) { - cImage* lpImage = images[x]; - QPixmap pixmap = lpImage->image(); - cImageWidget* lpImageWidget = new cImageWidget; + cImageDescription* lpImageDescription = images[x]; + cImage* lpImage = lpImageDescription->image(); + QPixmap pixmap = lpImage->image(); + cImageWidget* lpImageWidget = new cImageWidget; lpImageWidget->setValues(lpImage->name(), lpImage->type(), lpImage->description(), pixmap); ui->m_lpLayout->addWidget(lpImageWidget); @@ -85,9 +86,9 @@ void cRechercheWindow::setRecherche(cRecherche* lpRecherche) QSpacerItem* lpSpacer = new QSpacerItem(20, 40, QSizePolicy::Minimum, QSizePolicy::Expanding); ui->m_lpLayout->addItem(lpSpacer); - QList characterList = lpRecherche->characterList(); - QList placeList = lpRecherche->placeList(); - QList objectList = lpRecherche->objectList(); + QList characterList = lpRecherche->characterList(); + QList placeList = lpRecherche->placeList(); + QList objectList = lpRecherche->objectList(); QStringList headerLabels; @@ -95,7 +96,8 @@ void cRechercheWindow::setRecherche(cRecherche* lpRecherche) m_lpCharacterModel->setHorizontalHeaderLabels(headerLabels); for(int x = 0;x < characterList.count();x++) { - cCharacter* lpCharacter = characterList[x]; + cCharacterDescription* lpCharacterDescription = characterList[x]; + cCharacter* lpCharacter = lpCharacterDescription->character(); QList items; items.append(new QStandardItem(lpCharacter->name())); @@ -130,7 +132,8 @@ void cRechercheWindow::setRecherche(cRecherche* lpRecherche) m_lpPlaceModel->setHorizontalHeaderLabels(headerLabels); for(int x = 0;x < placeList.count();x++) { - cPlace* lpPlace = placeList[x]; + cPlaceDescription* lpPlaceDescription = placeList[x]; + cPlace* lpPlace = lpPlaceDescription->place(); QList items; items.append(new QStandardItem(lpPlace->name())); @@ -155,7 +158,8 @@ void cRechercheWindow::setRecherche(cRecherche* lpRecherche) m_lpObjectModel->setHorizontalHeaderLabels(headerLabels); for(int x = 0;x < objectList.count();x++) { - cObject* lpObject = objectList[x]; + cObjectDescription* lpObjectDescription = objectList[x]; + cObject* lpObject = lpObjectDescription->object(); QList items; items.append(new QStandardItem(lpObject->name())); diff --git a/cstorybook.cpp b/cstorybook.cpp index e0825e4..ae2b651 100644 --- a/cstorybook.cpp +++ b/cstorybook.cpp @@ -283,7 +283,8 @@ bool cStoryBook::createDatabase() if(!createTable("CREATE TABLE characterImage ( " " characterID INTEGER REFERENCES character (id), " - " imageID INTEGER REFERENCES image (id) " + " imageID INTEGER REFERENCES image (id), " + " description BLOB " "); ")) return(false); @@ -308,7 +309,8 @@ bool cStoryBook::createDatabase() if(!createTable("CREATE TABLE objectImage ( " " objectID INTEGER REFERENCES object (id), " - " imageID INTEGER REFERENCES image (id) " + " imageID INTEGER REFERENCES image (id), " + " description BLOB " "); ")) return(false); @@ -334,7 +336,8 @@ bool cStoryBook::createDatabase() if(!createTable("CREATE TABLE placeImage ( " " placeID INTEGER REFERENCES place (id), " - " imageID INTEGER REFERENCES image (id) " + " imageID INTEGER REFERENCES image (id), " + " description BLOB " "); ")) return(false); @@ -349,25 +352,29 @@ bool cStoryBook::createDatabase() if(!createTable("CREATE TABLE rechercheCharacter ( " " rechercheID INTEGER REFERENCES recherche (id), " - " characterID INTEGER REFERENCES character (id) " + " characterID INTEGER REFERENCES character (id), " + " description BLOB " "); ")) return(false); if(!createTable("CREATE TABLE rechercheImage ( " " rechercheID INTEGER REFERENCES recherche (id), " - " imageID INTEGER REFERENCES image (id) " + " imageID INTEGER REFERENCES image (id), " + " description BLOB " "); ")) return(false); if(!createTable("CREATE TABLE rechercheObject ( " " rechercheID INTEGER REFERENCES recherche (id), " - " objectID INTEGER REFERENCES object (id) " + " objectID INTEGER REFERENCES object (id), " + " description BLOB " "); ")) return(false); if(!createTable("CREATE TABLE recherchePlace ( " " rechercheID INTEGER REFERENCES recherche (id), " - " placeID INTEGER REFERENCES place (id) " + " placeID INTEGER REFERENCES place (id), " + " description BLOB " "); ")) return(false);