diff --git a/ccharacter.cpp b/ccharacter.cpp index 30d2d7e..8cadb25 100644 --- a/ccharacter.cpp +++ b/ccharacter.cpp @@ -365,12 +365,12 @@ bool cCharacter::deleted() return(m_bDeleted); } -void cCharacter::addImage(cImage* lpImage, cTextDocument* lpDescription) +void cCharacter::addImage(cImage* lpImage) { - m_imageList.append(new cImageDescription(lpImage, lpDescription)); + m_imageList.append(lpImage); } -QList cCharacter::images() +QList cCharacter::images() { return(m_imageList); } @@ -429,7 +429,7 @@ cCharacter* cCharacterList::find(const qint32& iID) return(0); } -bool cCharacterList::load(cImageList *lpImageList) +bool cCharacterList::load() { QSqlQuery query; @@ -470,7 +470,7 @@ bool cCharacterList::load(cImageList *lpImageList) lpCharacter->setDescription(blob2TextDocument(query.value("description").toByteArray())); } - query.prepare("SELECT characterID, imageID, description FROM characterImage;"); + query.prepare("SELECT characterID, name, image, description FROM characterImage;"); if(!query.exec()) { myDebug << query.lastError().text(); @@ -482,9 +482,11 @@ bool cCharacterList::load(cImageList *lpImageList) cCharacter* lpCharacter = find(query.value("characterID").toInt()); if(lpCharacter) { - cImage* lpImage = lpImageList->find(query.value("imageID").toInt()); - if(lpImage) - lpCharacter->addImage(lpImage, blob2TextDocument(query.value("description").toByteArray())); + cImage* lpImage = new cImage; + lpImage->setName(query.value("name").toString()); + lpImage->setDescription(blob2TextDocument(query.value("description").toByteArray())); + lpImage->setImage(blob2Image(query.value("image").toByteArray())); + lpCharacter->addImage(lpImage); } } @@ -507,7 +509,7 @@ bool cCharacterList::save() QSqlQuery imageAdd; imageDelete.prepare("DELETE FROM characterImage WHERE characterID=:characterID;"); - imageAdd.prepare("INSERT INTO characterImage (characterID, imageID, description) VALUES (:characterID, :imageID, :description);"); + imageAdd.prepare("INSERT INTO characterImage (characterID, name, description, image) VALUES (:characterID, :name, :description, :image);"); for(int x = 0;x < count();x++) { @@ -607,15 +609,16 @@ bool cCharacterList::save() return(false); } - QList images = lpCharacter->images(); + QList images = lpCharacter->images(); for(int x = 0;x < images.count();x++) { - cImageDescription* lpImage = images.at(x); + cImage* lpImage = images.at(x); imageAdd.bindValue(":characterID", lpCharacter->id()); - imageAdd.bindValue(":imageID", lpImage->image()->id()); + imageAdd.bindValue(":name", lpImage->name()); imageAdd.bindValue(":description", textDocument2Blob(lpImage->description())); + imageAdd.bindValue(":image", image2Blob(lpImage->image())); if(!imageAdd.exec()) { myDebug << imageAdd.lastError().text(); diff --git a/ccharacter.h b/ccharacter.h index b14696a..90e3611 100644 --- a/ccharacter.h +++ b/ccharacter.h @@ -469,14 +469,14 @@ public: \fn addImage \param lpImage */ - void addImage(cImage* lpImage, cTextDocument* lpDescription); + void addImage(cImage* lpImage); /*! \brief \fn images \return QList */ - QList images(); + QList images(); /*! \brief @@ -534,7 +534,7 @@ private: QString m_szSchool; /*!< TODO: describe */ QString m_szJob; /*!< TODO: describe */ cTextDocument* m_lpDescription; /*!< TODO: describe */ - QList m_imageList; /*!< TODO: describe */ + QList m_imageList; /*!< TODO: describe */ QList m_itemList; /*!< TODO: describe */ bool m_bDeleted; /*!< TODO: describe */ signals: @@ -604,7 +604,7 @@ public: \param lpImageList \return bool */ - bool load(cImageList* lpImageList); + bool load(); /*! \brief diff --git a/ccharacterwindow.cpp b/ccharacterwindow.cpp index 2378ad5..915dad1 100644 --- a/ccharacterwindow.cpp +++ b/ccharacterwindow.cpp @@ -148,15 +148,14 @@ 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++) { - cImageDescription* lpImageDescription = images[x]; - cImage* lpImage = lpImageDescription->image(); + cImage* lpImage = images[x]; QPixmap pixmap = lpImage->image(); cImageWidget* lpImageWidget = new cImageWidget; - lpImageWidget->setValues(lpImage->name(), lpImage->type(), lpImage->description(), pixmap); + lpImageWidget->setValues(lpImage->name(), lpImage->description(), pixmap); ui->m_lpLayout->addWidget(lpImageWidget); } diff --git a/cimage.cpp b/cimage.cpp index 209978e..2d5794e 100644 --- a/cimage.cpp +++ b/cimage.cpp @@ -12,25 +12,11 @@ #include -cImage::cImage(qint32 iID, QObject *parent) : - QObject(parent), - m_iID(iID), - m_szName(""), - m_szType(""), - m_lpDescription(0) +cImage::cImage(QObject *parent) : + QObject(parent) { } -void cImage::setID(const qint32& iID) -{ - m_iID = iID; -} - -qint32 cImage::id() -{ - return(m_iID); -} - void cImage::setName(const QString& szName) { m_szName = szName; @@ -41,16 +27,6 @@ QString cImage::name() return(m_szName); } -void cImage::setType(const QString& szType) -{ - m_szType = szType; -} - -QString cImage::type() -{ - return(m_szType); -} - void cImage::setDescription(cTextDocument* lpDescription) { m_lpDescription = lpDescription; @@ -70,153 +46,3 @@ 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); - - if(!lpImage) - { - lpImage = new cImage(iID); - append(lpImage); - } - - return(lpImage); -} - -cImage* cImageList::find(const qint32& iID) -{ - for(int x = 0;x < count();x++) - { - if(at(x)->id() == iID) - return(at(x)); - } - - return(0); -} - -bool cImageList::load() -{ - QSqlQuery query; - QPixmap image; - - query.prepare("SELECT id, name, type, description, image FROM image ORDER BY name, type;"); - if(!query.exec()) - { - myDebug << query.lastError().text(); - return(false); - } - - while(query.next()) - { - cImage* lpImage = add(query.value("id").toInt()); - - lpImage->setName(query.value("name").toString()); - lpImage->setType(query.value("type").toString()); - lpImage->setDescription(blob2TextDocument(query.value("description").toByteArray())); - - QByteArray ba = query.value("image").toByteArray(); - if(!ba.isEmpty()) - { - if(!image.loadFromData(ba)) - { - myDebug << "image load error."; - return(false); - } - lpImage->setImage(image); - } - } - - return(true); -} - -bool cImageList::save() -{ - QSqlQuery queryUpdate; - QSqlQuery queryInsert; - QSqlQuery querySelect; - - queryUpdate.prepare("UPDATE image SET type=:type, name=:name, description=:description, image=:image WHERE id=:id;"); - queryInsert.prepare("INSERT INTO image (type, name, description, image) VALUES (:type, :name, :description, :image);"); - querySelect.prepare("SELECT id FROM image WHERE _rowid_=(SELECT MAX(_rowid_) FROM image);"); - - for(int x = 0;x < count();x++) - { - cImage* lpImage = at(x); - - if(lpImage->id() != -1) - { - queryUpdate.bindValue(":id", lpImage->id()); - queryUpdate.bindValue(":type", lpImage->type()); - queryUpdate.bindValue(":name", lpImage->name()); - queryUpdate.bindValue(":description", textDocument2Blob(lpImage->description())); - - QByteArray ba; - QBuffer buffer(&ba); - buffer.open(QIODevice::WriteOnly); - lpImage->image().save(&buffer, "JPG"); - queryUpdate.bindValue(":image", ba); - - if(!queryUpdate.exec()) - { - myDebug << queryUpdate.lastError().text(); - return(false); - } - } - else - { - queryInsert.bindValue(":type", lpImage->type()); - queryInsert.bindValue(":name", lpImage->name()); - queryInsert.bindValue(":description", textDocument2Blob(lpImage->description())); - - QByteArray ba; - QBuffer buffer(&ba); - buffer.open(QIODevice::WriteOnly); - lpImage->image().save(&buffer, "JPG"); - queryInsert.bindValue(":image", ba); - - if(!queryInsert.exec()) - { - myDebug << queryInsert.lastError().text(); - return(false); - } - - if(!querySelect.exec()) - { - myDebug << querySelect.lastError().text(); - return(false); - } - querySelect.next(); - lpImage->setID(querySelect.value("id").toInt()); - } - } - - return(true); -} diff --git a/cimage.h b/cimage.h index 22ed830..690bf6c 100644 --- a/cimage.h +++ b/cimage.h @@ -24,53 +24,23 @@ class cImage : public QObject { Q_OBJECT public: - cImage(qint32 iID = -1, QObject* parent = nullptr); + cImage(QObject* parent = nullptr); /*! \brief - \fn setID - \param iID - */ - void setID(const qint32& iID); - /*! - \brief - - \fn id - \return qint32 - */ - qint32 id(); - - /*! - \brief - - \fn setName - \param szName + \fn setImage + \param image */ void setName(const QString& szName); /*! \brief - \fn name - \return QString + \fn image + \return QPixmap */ QString name(); - /*! - \brief - - \fn setType - \param szType - */ - void setType(const QString& szType); - /*! - \brief - - \fn type - \return QString - */ - QString type(); - /*! \brief @@ -101,99 +71,11 @@ public: */ QPixmap image(); private: - qint32 m_iID; /*!< TODO: describe */ - QString m_szName; /*!< TODO: describe */ - QString m_szType; /*!< TODO: describe */ - cTextDocument* m_lpDescription; /*!< TODO: describe */ - 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 */ + QString m_szName; /*!< TODO: describe */ + cTextDocument* m_lpDescription; /*!< TODO: describe */ + QPixmap m_image; /*!< TODO: describe */ }; Q_DECLARE_METATYPE(cImage*) -/*! - \brief - - \class cImageList cimage.h "cimage.h" -*/ -class cImageList : public QList -{ -public: - /*! - \brief - - \fn load - \return bool - */ - bool load(); - /*! - \brief - - \fn save - \return bool - */ - bool save(); - - /*! - \brief - - \fn add - \param iID - \return cImage - */ - cImage* add(const qint32& iID); - /*! - \brief - - \fn find - \param iID - \return cImage - */ - cImage* find(const qint32& iID); -}; - #endif // CIMAGE_H diff --git a/cimagewidget.cpp b/cimagewidget.cpp index 7183fd3..175aef6 100644 --- a/cimagewidget.cpp +++ b/cimagewidget.cpp @@ -27,10 +27,9 @@ cImageWidget::~cImageWidget() delete ui; } -void cImageWidget::setValues(const QString &szName, const QString &szType, cTextDocument* lpDocument, const QPixmap &pixmap) +void cImageWidget::setValues(const QString &szName, cTextDocument* lpDocument, const QPixmap &pixmap) { ui->m_lpName->setTitle(szName); - ui->m_lpType->setText(szType); ui->m_lpDescription->setDocument(lpDocument); if(pixmap.width() > 200) ui->m_lpImage->setPixmap(pixmap.scaled(200, 9999, Qt::KeepAspectRatio)); diff --git a/cimagewidget.h b/cimagewidget.h index 8d61703..4f1db54 100644 --- a/cimagewidget.h +++ b/cimagewidget.h @@ -45,11 +45,10 @@ public: \fn setValues \param szName - \param szType \param lpDocument \param pixmap */ - void setValues(const QString& szName, const QString& szType, cTextDocument* lpDocument, const QPixmap& pixmap); + void setValues(const QString& szName, cTextDocument* lpDocument, const QPixmap& pixmap); private: Ui::cImageWidget* ui; /*!< TODO: describe */ }; diff --git a/cimagewidget.ui b/cimagewidget.ui index de7ffef..0176877 100644 --- a/cimagewidget.ui +++ b/cimagewidget.ui @@ -19,13 +19,10 @@ GroupBox - + - - - - - + + QFrame::Box @@ -38,12 +35,8 @@ - - - - TextLabel - - + + diff --git a/cobject.cpp b/cobject.cpp index 6585163..e253210 100644 --- a/cobject.cpp +++ b/cobject.cpp @@ -81,12 +81,12 @@ bool cObject::deleted() return(m_bDeleted); } -void cObject::addImage(cImage* lpImage, cTextDocument* lpDescription) +void cObject::addImage(cImage* lpImage) { - m_imageList.append(new cImageDescription(lpImage, lpDescription)); + m_imageList.append(lpImage); } -QList cObject::images() +QList cObject::images() { return(m_imageList); } @@ -145,7 +145,7 @@ cObject* cObjectList::find(const qint32& iID) return(0); } -bool cObjectList::load(cImageList *lpImageList) +bool cObjectList::load() { QSqlQuery query; @@ -165,7 +165,7 @@ bool cObjectList::load(cImageList *lpImageList) lpObject->setDescription(blob2TextDocument(query.value("description").toByteArray())); } - query.prepare("SELECT objectID, imageID, description FROM objectImage;"); + query.prepare("SELECT objectID, name, image, description FROM objectImage;"); if(!query.exec()) { myDebug << query.lastError().text(); @@ -177,9 +177,11 @@ bool cObjectList::load(cImageList *lpImageList) cObject* lpObject = find(query.value("objectID").toInt()); if(lpObject) { - cImage* lpImage = lpImageList->find(query.value("imageID").toInt()); - if(lpImage) - lpObject->addImage(lpImage, blob2TextDocument(query.value(":description").toByteArray())); + cImage* lpImage = new cImage; + lpImage->setName(query.value("name").toString()); + lpImage->setDescription(blob2TextDocument(query.value("description").toByteArray())); + lpImage->setImage(blob2Image(query.value("image").toByteArray())); + lpObject->addImage(lpImage); } } @@ -202,7 +204,7 @@ bool cObjectList::save() QSqlQuery imageAdd; imageDelete.prepare("DELETE FROM objectImage WHERE objectID=:objectID;"); - imageAdd.prepare("INSERT INTO objectImage (objectID, imageID, description) VALUES (:objectID, :imageID, :description);"); + imageAdd.prepare("INSERT INTO objectImage (objectID, name, description, image) VALUES (:objectID, :name, :description, :image);"); for(int x = 0;x < count();x++) { @@ -260,16 +262,16 @@ bool cObjectList::save() return(false); } - QList images = lpObject->images(); + QList images = lpObject->images(); for(int x = 0;x < images.count();x++) { - cImageDescription* lpImageDescription = images.at(x); - cImage* lpImage = lpImageDescription->image(); + cImage* lpImage = images.at(x); imageAdd.bindValue(":objectID", lpObject->id()); - imageAdd.bindValue(":imageID", lpImage->id()); - imageAdd.bindValue(":description", textDocument2Blob(lpImageDescription->description())); + imageAdd.bindValue(":name", lpImage->name()); + imageAdd.bindValue(":description", textDocument2Blob(lpImage->description())); + imageAdd.bindValue(":image", image2Blob(lpImage->image())); if(!imageAdd.exec()) { myDebug << imageAdd.lastError().text(); diff --git a/cobject.h b/cobject.h index d1fce25..2025514 100644 --- a/cobject.h +++ b/cobject.h @@ -101,16 +101,15 @@ public: \fn addImage \param lpImage - \param lpDescription */ - void addImage(cImage* lpImage, cTextDocument* lpDescription); + void addImage(cImage* lpImage); /*! \brief \fn images - \return QList + \return QList */ - QList images(); + QList images(); /*! \brief @@ -147,7 +146,7 @@ private: QString m_szName; /*!< TODO: describe */ QString m_szType; /*!< TODO: describe */ cTextDocument* m_lpDescription; /*!< TODO: describe */ - QList m_imageList; /*!< TODO: describe */ + QList m_imageList; /*!< TODO: describe */ QList m_itemList; /*!< TODO: describe */ bool m_bDeleted; /*!< TODO: describe */ @@ -218,7 +217,7 @@ public: \param lpImageList \return bool */ - bool load(cImageList* lpImageList); + bool load(); /*! \brief diff --git a/cobjectwindow.cpp b/cobjectwindow.cpp index 93b2fdb..f3ec98f 100644 --- a/cobjectwindow.cpp +++ b/cobjectwindow.cpp @@ -46,15 +46,14 @@ 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++) { - cImageDescription* lpImageDescription = images[x]; - cImage* lpImage = lpImageDescription->image(); + cImage* lpImage = images[x]; QPixmap pixmap = lpImage->image(); cImageWidget* lpImageWidget = new cImageWidget; - lpImageWidget->setValues(lpImage->name(), lpImage->type(), lpImage->description(), pixmap); + lpImageWidget->setValues(lpImage->name(), lpImage->description(), pixmap); ui->m_lpLayout->addWidget(lpImageWidget); } diff --git a/common.cpp b/common.cpp index bd2320d..2760de7 100644 --- a/common.cpp +++ b/common.cpp @@ -5,6 +5,9 @@ #include "common.h" +#include + + QString uncompressText(const QByteArray& compressed) { if(compressed.isNull() || compressed.isEmpty()) @@ -19,6 +22,30 @@ QByteArray compressText(const QString& uncompressed) return(qCompress(uncompressed.toUtf8())); } +QPixmap blob2Image(const QByteArray& ba) +{ + QPixmap image; + + if(!ba.isEmpty()) + { + if(!image.loadFromData(ba)) + myDebug << "image load error."; + } + + return(image); +} + +QByteArray image2Blob(const QPixmap &image) +{ + QByteArray ba; + QBuffer buffer(&ba); + buffer.open(QIODevice::WriteOnly); + image.save(&buffer, "JPG"); + buffer.close(); + + return(ba); +} + cTextDocument* blob2TextDocument(const QByteArray& ba) { cTextDocument* lpTextDocument = new cTextDocument; diff --git a/common.h b/common.h index 0d8967e..ef82a24 100644 --- a/common.h +++ b/common.h @@ -11,6 +11,7 @@ #include #include +#include #include @@ -41,6 +42,22 @@ QByteArray compressText(const QString& uncompressed); /*! \brief + \fn blob2Image + \param ba + \return QPixmap +*/ +QPixmap blob2Image(const QByteArray& ba); +/*! + \brief + + \fn image2Blob + \param image + \return QByteArray +*/ +QByteArray image2Blob(const QPixmap& image); +/*! + \brief + \fn blob2TextDocument \param ba \return cTextDocument diff --git a/cplace.cpp b/cplace.cpp index 2140bdf..3afed17 100644 --- a/cplace.cpp +++ b/cplace.cpp @@ -92,12 +92,12 @@ bool cPlace::deleted() return(m_bDeleted); } -void cPlace::addImage(cImage* lpImage, cTextDocument* lpDescription) +void cPlace::addImage(cImage* lpImage) { - m_imageList.append(new cImageDescription(lpImage, lpDescription)); + m_imageList.append(lpImage); } -QList cPlace::images() +QList cPlace::images() { return(m_imageList); } @@ -156,7 +156,7 @@ cPlace* cPlaceList::find(const qint32& iID) return(0); } -bool cPlaceList::load(cImageList *lpImageList) +bool cPlaceList::load() { QSqlQuery query; @@ -177,7 +177,7 @@ bool cPlaceList::load(cImageList *lpImageList) lpPlace->setDescription(blob2TextDocument(query.value("description").toByteArray())); } - query.prepare("SELECT placeID, imageID, description FROM placeImage;"); + query.prepare("SELECT placeID, name, image, description FROM placeImage;"); if(!query.exec()) { myDebug << query.lastError().text(); @@ -189,9 +189,11 @@ bool cPlaceList::load(cImageList *lpImageList) cPlace* lpPlace = find(query.value("placeID").toInt()); if(lpPlace) { - cImage* lpImage = lpImageList->find(query.value("imageID").toInt()); - if(lpImage) - lpPlace->addImage(lpImage, blob2TextDocument(query.value("description").toByteArray())); + cImage* lpImage = new cImage; + lpImage->setName(query.value("name").toString()); + lpImage->setDescription(blob2TextDocument(query.value("description").toByteArray())); + lpImage->setImage(blob2Image(query.value("image").toByteArray())); + lpPlace->addImage(lpImage); } } @@ -214,7 +216,7 @@ bool cPlaceList::save() QSqlQuery imageAdd; imageDelete.prepare("DELETE FROM placeImage WHERE placeID=:placeID;"); - imageAdd.prepare("INSERT INTO placeImage (placeID, imageID, description) VALUES (:placeID, :imageID, :description);"); + imageAdd.prepare("INSERT INTO placeImage (placeID, name, description, image) VALUES (:placeID, :name, :description, :image);"); for(int x = 0;x < count();x++) { @@ -274,16 +276,16 @@ bool cPlaceList::save() return(false); } - QList images = lpPlace->images(); + QList images = lpPlace->images(); for(int x = 0;x < images.count();x++) { - cImageDescription* lpImageDescription = images.at(x); - cImage* lpImage = lpImageDescription->image(); + cImage* lpImage = images.at(x); imageAdd.bindValue(":placeID", lpPlace->id()); - imageAdd.bindValue(":imageID", lpImage->id()); - imageAdd.bindValue(":description", textDocument2Blob(lpImageDescription->description())); + imageAdd.bindValue(":name", lpImage->name()); + imageAdd.bindValue(":description", textDocument2Blob(lpImage->description())); + imageAdd.bindValue(":image", image2Blob(lpImage->image())); if(!imageAdd.exec()) { myDebug << imageAdd.lastError().text(); diff --git a/cplace.h b/cplace.h index e76556c..17b8560 100644 --- a/cplace.h +++ b/cplace.h @@ -116,16 +116,15 @@ public: \fn addImage \param lpImage - \param lpDescription */ - void addImage(cImage* lpImage, cTextDocument* lpDescription); + void addImage(cImage* lpImage); /*! \brief \fn images - \return QList + \return QList */ - QList images(); + QList images(); /*! \brief @@ -163,7 +162,7 @@ private: QString m_szLocation; /*!< TODO: describe */ QString m_szType; /*!< TODO: describe */ cTextDocument* m_lpDescription; /*!< TODO: describe */ - QList m_imageList; /*!< TODO: describe */ + QList m_imageList; /*!< TODO: describe */ QList m_itemList; /*!< TODO: describe */ bool m_bDeleted; /*!< TODO: describe */ @@ -234,7 +233,7 @@ public: \param lpImageList \return bool */ - bool load(cImageList* lpImageList); + bool load(); /*! \brief diff --git a/cplacewindow.cpp b/cplacewindow.cpp index e4e0fb3..2273870 100644 --- a/cplacewindow.cpp +++ b/cplacewindow.cpp @@ -50,15 +50,14 @@ 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++) { - cImageDescription* lpImageDescription = images[x]; - cImage* lpImage = lpImageDescription->image(); + cImage* lpImage = images[x]; QPixmap pixmap = lpImage->image(); cImageWidget* lpImageWidget = new cImageWidget; - lpImageWidget->setValues(lpImage->name(), lpImage->type(), lpImage->description(), pixmap); + lpImageWidget->setValues(lpImage->name(), lpImage->description(), pixmap); ui->m_lpLayout->addWidget(lpImageWidget); } diff --git a/crecherche.cpp b/crecherche.cpp index 88fe63d..5708f54 100644 --- a/crecherche.cpp +++ b/crecherche.cpp @@ -81,9 +81,9 @@ bool cRecherche::deleted() return(m_bDeleted); } -void cRecherche::addImage(cImage* lpImage, cTextDocument* lpDescription) +void cRecherche::addImage(cImage* lpImage) { - m_imageList.append(new cImageDescription(lpImage, lpDescription)); + m_imageList.append(lpImage); } void cRecherche::addCharacter(cCharacter* lpCharacter, cTextDocument* lpDescription) @@ -116,7 +116,7 @@ void cRecherche::removePlace(cPlaceDescription* lpPlace) m_placeList.removeOne(lpPlace); } -QList cRecherche::images() +QList cRecherche::images() { return(m_imageList); } @@ -223,7 +223,7 @@ QList cRechercheList::find(cObject* lpObject) return(rechercheList); } -bool cRechercheList::load(cImageList *lpImageList, cCharacterList *lpCharacterList, cObjectList *lpObjectList, cPlaceList *lpPlaceList) +bool cRechercheList::load(cCharacterList *lpCharacterList, cObjectList *lpObjectList, cPlaceList *lpPlaceList) { QSqlQuery query; @@ -243,7 +243,7 @@ bool cRechercheList::load(cImageList *lpImageList, cCharacterList *lpCharacterLi lpObject->setDescription(blob2TextDocument(query.value("description").toByteArray())); } - query.prepare("SELECT rechercheID, imageID, description FROM rechercheImage;"); + query.prepare("SELECT rechercheID, name, image, description FROM rechercheImage;"); if(!query.exec()) { myDebug << query.lastError().text(); @@ -255,9 +255,11 @@ bool cRechercheList::load(cImageList *lpImageList, cCharacterList *lpCharacterLi cRecherche* lpRecherche = find(query.value("rechercheID").toInt()); if(lpRecherche) { - cImage* lpImage = lpImageList->find(query.value("imageID").toInt()); - if(lpImage) - lpRecherche->addImage(lpImage, blob2TextDocument(query.value("description").toByteArray())); + cImage* lpImage = new cImage; + lpImage->setName(query.value("name").toString()); + lpImage->setDescription(blob2TextDocument(query.value("description").toByteArray())); + lpImage->setImage(blob2Image(query.value("image").toByteArray())); + lpRecherche->addImage(lpImage); } } @@ -334,7 +336,7 @@ bool cRechercheList::save() QSqlQuery imageAdd; imageDelete.prepare("DELETE FROM rechercheImage WHERE rechercheID=:rechercheID;"); - imageAdd.prepare("INSERT INTO rechercheImage (rechercheID, imageID, description) VALUES (:rechercheID, :imageID, :description);"); + imageAdd.prepare("INSERT INTO rechercheImage (rechercheID, name, description, image) VALUES (:rechercheID, :name, :description, :image);"); QSqlQuery characterDelete; QSqlQuery characterAdd; @@ -428,16 +430,16 @@ bool cRechercheList::save() lpRecherche->setID(querySelect.value("id").toInt()); } - QList images = lpRecherche->images(); + QList images = lpRecherche->images(); for(int x = 0;x < images.count();x++) { - cImageDescription* lpImageDescription = images.at(x); - cImage* lpImage = lpImageDescription->image(); + cImage* lpImage = images.at(x); imageAdd.bindValue(":rechercheID", lpRecherche->id()); - imageAdd.bindValue(":imageID", lpImage->id()); - imageAdd.bindValue(":description", textDocument2Blob(lpImageDescription->description())); + imageAdd.bindValue(":name", lpImage->name()); + imageAdd.bindValue(":description", textDocument2Blob(lpImage->description())); + imageAdd.bindValue(":image", image2Blob(lpImage->image())); if(!imageAdd.exec()) { myDebug << imageAdd.lastError().text(); diff --git a/crecherche.h b/crecherche.h index b45b835..3826eeb 100644 --- a/crecherche.h +++ b/crecherche.h @@ -106,7 +106,7 @@ public: \param lpImage \param lpDescription */ - void addImage(cImage* lpImage, cTextDocument* lpDescription); + void addImage(cImage* lpImage); /*! \brief @@ -180,9 +180,9 @@ public: \brief \fn images - \return QList + \return QList */ - QList images(); + QList images(); /*! \brief @@ -219,7 +219,7 @@ private: QString m_szName; /*!< TODO: describe */ QString m_szLink; /*!< TODO: describe */ cTextDocument* m_lpDescription; /*!< TODO: describe */ - QList m_imageList; /*!< TODO: describe */ + QList m_imageList; /*!< TODO: describe */ QList m_characterList; /*!< TODO: describe */ QList m_objectList; /*!< TODO: describe */ QList m_placeList; /*!< TODO: describe */ @@ -251,7 +251,7 @@ public: \param lpPlaceList \return bool */ - bool load(cImageList* lpImageList, cCharacterList* lpCharacterList, cObjectList* lpObjectList, cPlaceList* lpPlaceList); + bool load(cCharacterList* lpCharacterList, cObjectList* lpObjectList, cPlaceList* lpPlaceList); /*! \brief diff --git a/crecherchewindow.cpp b/crecherchewindow.cpp index 4d52d22..0d580c9 100644 --- a/crecherchewindow.cpp +++ b/crecherchewindow.cpp @@ -77,15 +77,14 @@ void cRechercheWindow::setRecherche(cRecherche* lpRecherche, cCharacterList* lpC 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++) { - cImageDescription* lpImageDescription = images[x]; - cImage* lpImage = lpImageDescription->image(); + cImage* lpImage = images[x]; QPixmap pixmap = lpImage->image(); cImageWidget* lpImageWidget = new cImageWidget; - lpImageWidget->setValues(lpImage->name(), lpImage->type(), lpImage->description(), pixmap); + lpImageWidget->setValues(lpImage->name(), lpImage->description(), pixmap); ui->m_lpLayout->addWidget(lpImageWidget); } diff --git a/cstorybook.cpp b/cstorybook.cpp index cd104c3..5526df4 100644 --- a/cstorybook.cpp +++ b/cstorybook.cpp @@ -41,9 +41,6 @@ cStoryBook::cStoryBook(const QString &szProject, QObject *parent) : if(!openDatabase()) return; - if(!loadImageList()) - return; - if(!loadCharacterList()) return; @@ -85,9 +82,6 @@ bool cStoryBook::save() if(!m_db.isOpen()) return(false); - if(!saveImageList()) - return(false); - if(!saveCharacterList()) return(false); @@ -133,9 +127,6 @@ bool cStoryBook::saveAs(const QString& szProject) if(!openDatabase()) return(false); - for(int x = 0;x < m_imageList.count();x++) - m_imageList.at(x)->setID(-1); - for(int x = 0;x < m_characterList.count();x++) m_characterList.at(x)->setID(-1); @@ -283,15 +274,6 @@ bool cStoryBook::createDatabase() if(!createTable("CREATE TABLE characterImage ( " " characterID INTEGER REFERENCES character (id), " - " imageID INTEGER REFERENCES image (id), " - " description BLOB " - "); ")) - return(false); - - if(!createTable("CREATE TABLE image ( " - " id INTEGER PRIMARY KEY AUTOINCREMENT " - " UNIQUE, " - " type TEXT, " " name TEXT, " " description BLOB, " " image BLOB " @@ -309,8 +291,9 @@ bool cStoryBook::createDatabase() if(!createTable("CREATE TABLE objectImage ( " " objectID INTEGER REFERENCES object (id), " - " imageID INTEGER REFERENCES image (id), " - " description BLOB " + " name TEXT, " + " description BLOB, " + " image BLOB " "); ")) return(false); @@ -336,8 +319,9 @@ bool cStoryBook::createDatabase() if(!createTable("CREATE TABLE placeImage ( " " placeID INTEGER REFERENCES place (id), " - " imageID INTEGER REFERENCES image (id), " - " description BLOB " + " name TEXT, " + " description BLOB, " + " image BLOB " "); ")) return(false); @@ -359,8 +343,9 @@ bool cStoryBook::createDatabase() if(!createTable("CREATE TABLE rechercheImage ( " " rechercheID INTEGER REFERENCES recherche (id), " - " imageID INTEGER REFERENCES image (id), " - " description BLOB " + " name TEXT, " + " description BLOB, " + " image BLOB " "); ")) return(false); @@ -449,27 +434,22 @@ bool cStoryBook::loadSceneList() bool cStoryBook::loadCharacterList() { - return(m_characterList.load(&m_imageList)); + return(m_characterList.load()); } bool cStoryBook::loadPlaceList() { - return(m_placeList.load(&m_imageList)); + return(m_placeList.load()); } bool cStoryBook::loadObjectList() { - return(m_objectList.load(&m_imageList)); + return(m_objectList.load()); } bool cStoryBook::loadRechercheList() { - return(m_rechercheList.load(&m_imageList, &m_characterList, &m_objectList, &m_placeList)); -} - -bool cStoryBook::loadImageList() -{ - return(m_imageList.load()); + return(m_rechercheList.load(&m_characterList, &m_objectList, &m_placeList)); } bool cStoryBook::saveBook() @@ -512,11 +492,6 @@ bool cStoryBook::saveRechercheList() return(m_rechercheList.save()); } -bool cStoryBook::saveImageList() -{ - return(m_imageList.save()); -} - QString cStoryBook::title() { if(!m_bIsOpen) diff --git a/cstorybook.h b/cstorybook.h index 06110f7..8e9ca84 100644 --- a/cstorybook.h +++ b/cstorybook.h @@ -325,7 +325,6 @@ private: cPlaceList m_placeList; /*!< TODO: describe */ cObjectList m_objectList; /*!< TODO: describe */ cRechercheList m_rechercheList; /*!< TODO: describe */ - cImageList m_imageList; /*!< TODO: describe */ /*! \brief @@ -406,13 +405,6 @@ private: \return bool */ bool loadRechercheList(); - /*! - \brief - - \fn loadImageList - \return bool - */ - bool loadImageList(); /*! \brief