This commit is contained in:
2018-04-23 19:55:38 +02:00
parent bc97f35058
commit 970984264e
13 changed files with 351 additions and 20 deletions
+26 -1
View File
@@ -339,6 +339,13 @@ cTextDocument* cCharacter::description()
return(m_lpDescription);
}
void cCharacter::addImage(cImage* lpImage)
{
if(m_imageList.contains(lpImage))
return;
m_imageList.append(lpImage);
}
cCharacter* cCharacterList::add(const qint32& iID)
{
cCharacter* lpCharacter = find(iID);
@@ -363,7 +370,7 @@ cCharacter* cCharacterList::find(const qint32& iID)
return(0);
}
bool cCharacterList::load()
bool cCharacterList::load(cImageList *lpImageList)
{
QSqlQuery query;
@@ -403,6 +410,24 @@ bool cCharacterList::load()
lpCharacter->setDescription(blob2TextDocument(query.value("description").toByteArray()));
}
query.prepare("SELECT characterID, imageID FROM characterImage;");
if(!query.exec())
{
myDebug << query.lastError().text();
return(false);
}
while(query.next())
{
cCharacter* lpCharacter = find(query.value("characterID").toInt());
if(lpCharacter)
{
cImage* lpImage = lpImageList->find(query.value("imageID").toInt());
if(lpImage)
lpCharacter->addImage(lpImage);
}
}
return(true);
}
+6 -1
View File
@@ -3,6 +3,7 @@
#include "ctextdocument.h"
#include "cimage.h"
#include <QMetaType>
#include <QList>
@@ -106,6 +107,9 @@ public:
void setDescription(cTextDocument* lpDescription);
cTextDocument* description();
void addImage(cImage* lpImage);
private:
qint32 m_id;
bool m_bMainCharacter;
@@ -133,6 +137,7 @@ private:
QString m_szSchool;
QString m_szJob;
cTextDocument* m_lpDescription;
QList<cImage*> m_imageList;
signals:
public slots:
@@ -143,7 +148,7 @@ Q_DECLARE_METATYPE(cCharacter*)
class cCharacterList : public QList<cCharacter*>
{
public:
bool load();
bool load(cImageList* lpImageList);
bool save();
cCharacter* add(const qint32& iID);
+141
View File
@@ -0,0 +1,141 @@
#include "cimage.h"
#include "common.h"
#include <QSqlQuery>
#include <QSqlError>
cImage::cImage(qint32 iID, QObject *parent) :
QObject(parent),
m_iID(iID),
m_szName(""),
m_szType(""),
m_lpDescription(0)
{
}
void cImage::setID(const qint32& iID)
{
m_iID = iID;
}
qint32 cImage::id()
{
return(m_iID);
}
void cImage::setName(const QString& szName)
{
m_szName = szName;
}
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;
}
cTextDocument* cImage::description()
{
return(m_lpDescription);
}
QPixmap cImage::load()
{
QSqlQuery query;
QPixmap image;
query.prepare("SELECT image FROM image WHERE id = :id;");
query.bindValue(":id", m_iID);
if(!query.exec())
{
myDebug << query.lastError().text();
return(image);
}
if(!query.first())
{
myDebug << query.lastError().text();
return(image);
}
QByteArray ba = query.value("image").toByteArray();
if(!ba.isEmpty())
{
if(!image.loadFromData(ba))
{
myDebug << "image load error.";
return(image);
}
}
myDebug << "image load error.";
return(image);
}
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;
query.prepare("SELECT id, name, type, description 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()));
}
return(true);
}
bool cImageList::save()
{
return(true);
}
+52
View File
@@ -0,0 +1,52 @@
#ifndef CIMAGE_H
#define CIMAGE_H
#include "ctextdocument.h"
#include <QMetaType>
#include <QList>
#include <QString>
#include <QPixmap>
class cImage : public QObject
{
Q_OBJECT
public:
cImage(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();
QPixmap load();
private:
qint32 m_iID;
QString m_szName;
QString m_szType;
cTextDocument* m_lpDescription;
};
Q_DECLARE_METATYPE(cImage*)
class cImageList : public QList<cImage*>
{
public:
bool load();
bool save();
cImage* add(const qint32& iID);
cImage* find(const qint32& iID);
};
#endif // CIMAGE_H
+26 -1
View File
@@ -55,6 +55,13 @@ cTextDocument* cObject::description()
return(m_lpDescription);
}
void cObject::addImage(cImage* lpImage)
{
if(m_imageList.contains(lpImage))
return;
m_imageList.append(lpImage);
}
cObject* cObjectList::add(const qint32& iID)
{
cObject* lpObject = find(iID);
@@ -79,7 +86,7 @@ cObject* cObjectList::find(const qint32& iID)
return(0);
}
bool cObjectList::load()
bool cObjectList::load(cImageList *lpImageList)
{
QSqlQuery query;
@@ -99,6 +106,24 @@ bool cObjectList::load()
lpObject->setDescription(blob2TextDocument(query.value("description").toByteArray()));
}
query.prepare("SELECT objectID, imageID FROM objectImage;");
if(!query.exec())
{
myDebug << query.lastError().text();
return(false);
}
while(query.next())
{
cObject* lpObject = find(query.value("objectID").toInt());
if(lpObject)
{
cImage* lpImage = lpImageList->find(query.value("imageID").toInt());
if(lpImage)
lpObject->addImage(lpImage);
}
}
return(true);
}
+5 -1
View File
@@ -3,6 +3,7 @@
#include "ctextdocument.h"
#include "cimage.h"
#include <QMetaType>
#include <QList>
@@ -28,11 +29,14 @@ public:
void setDescription(cTextDocument* lpDescription);
cTextDocument* description();
void addImage(cImage* lpImage);
private:
qint32 m_iID;
QString m_szName;
QString m_szType;
cTextDocument* m_lpDescription;
QList<cImage*> m_imageList;
signals:
@@ -44,7 +48,7 @@ Q_DECLARE_METATYPE(cObject*)
class cObjectList : public QList<cObject*>
{
public:
bool load();
bool load(cImageList* lpImageList);
bool save();
cObject* add(const qint32& iID);
+26 -1
View File
@@ -66,6 +66,13 @@ cTextDocument* cPlace::description()
return(m_lpDescription);
}
void cPlace::addImage(cImage* lpImage)
{
if(m_imageList.contains(lpImage))
return;
m_imageList.append(lpImage);
}
cPlace* cPlaceList::add(const qint32& iID)
{
cPlace* lpPlace = find(iID);
@@ -90,7 +97,7 @@ cPlace* cPlaceList::find(const qint32& iID)
return(0);
}
bool cPlaceList::load()
bool cPlaceList::load(cImageList *lpImageList)
{
QSqlQuery query;
@@ -111,6 +118,24 @@ bool cPlaceList::load()
lpPlace->setDescription(blob2TextDocument(query.value("description").toByteArray()));
}
query.prepare("SELECT placeID, imageID FROM placeImage;");
if(!query.exec())
{
myDebug << query.lastError().text();
return(false);
}
while(query.next())
{
cPlace* lpPlace = find(query.value("placeID").toInt());
if(lpPlace)
{
cImage* lpImage = lpImageList->find(query.value("imageID").toInt());
if(lpImage)
lpPlace->addImage(lpImage);
}
}
return(true);
}
+5 -1
View File
@@ -3,6 +3,7 @@
#include "ctextdocument.h"
#include "cimage.h"
#include <QMetaType>
#include <QList>
@@ -31,12 +32,15 @@ public:
void setDescription(cTextDocument* lpDescription);
cTextDocument* description();
void addImage(cImage* lpImage);
private:
qint32 m_iID;
QString m_szName;
QString m_szLocation;
QString m_szType;
cTextDocument* m_lpDescription;
QList<cImage*> m_imageList;
signals:
@@ -48,7 +52,7 @@ Q_DECLARE_METATYPE(cPlace*)
class cPlaceList : public QList<cPlace*>
{
public:
bool load();
bool load(cImageList* lpImageList);
bool save();
cPlace* add(const qint32& iID);
+26 -1
View File
@@ -55,6 +55,13 @@ cTextDocument* cRecherche::description()
return(m_lpDescription);
}
void cRecherche::addImage(cImage* lpImage)
{
if(m_imageList.contains(lpImage))
return;
m_imageList.append(lpImage);
}
cRecherche* cRechercheList::add(const qint32& iID)
{
cRecherche* lpRecherche = find(iID);
@@ -79,7 +86,7 @@ cRecherche* cRechercheList::find(const qint32& iID)
return(0);
}
bool cRechercheList::load()
bool cRechercheList::load(cImageList *lpImageList)
{
QSqlQuery query;
@@ -99,6 +106,24 @@ bool cRechercheList::load()
lpObject->setDescription(blob2TextDocument(query.value("description").toByteArray()));
}
query.prepare("SELECT rechercheID, imageID FROM rechercheImage;");
if(!query.exec())
{
myDebug << query.lastError().text();
return(false);
}
while(query.next())
{
cRecherche* lpRecherche = find(query.value("rechercheID").toInt());
if(lpRecherche)
{
cImage* lpImage = lpImageList->find(query.value("imageID").toInt());
if(lpImage)
lpRecherche->addImage(lpImage);
}
}
return(true);
}
+5 -1
View File
@@ -3,6 +3,7 @@
#include "ctextdocument.h"
#include "cimage.h"
#include <QMetaType>
#include <QList>
@@ -28,11 +29,14 @@ public:
void setDescription(cTextDocument* lpDescription);
cTextDocument* description();
void addImage(cImage* lpImage);
private:
qint32 m_iID;
QString m_szName;
QString m_szLink;
cTextDocument* m_lpDescription;
QList<cImage*> m_imageList;
signals:
@@ -44,7 +48,7 @@ Q_DECLARE_METATYPE(cRecherche*)
class cRechercheList : public QList<cRecherche*>
{
public:
bool load();
bool load(cImageList* lpImageList);
bool save();
cRecherche* add(const qint32& iID);
+26 -10
View File
@@ -18,6 +18,14 @@
#include <QThread>
//rechercheCharacter
//rechercheObject
//recherchePlace
//sceneCharacter
//sceneObject
//scenePlace
//config
cStoryBook::cStoryBook(const QString &szProject, QObject *parent) :
QObject(parent),
m_szProject(szProject),
@@ -26,6 +34,9 @@ cStoryBook::cStoryBook(const QString &szProject, QObject *parent) :
if(!openDatabase())
return;
if(!loadImageList())
return;
if(!loadBook())
return;
@@ -187,12 +198,6 @@ bool cStoryBook::createDatabase()
");"))
return(false);
if(!createTable("CREATE TABLE characterImage ( "
" characterID INTEGER REFERENCES character (id), "
" imageID INTEGER REFERENCES image (id) "
");"))
return(false);
if(!createTable("CREATE TABLE image ( "
" id INTEGER PRIMARY KEY AUTOINCREMENT "
" UNIQUE, "
@@ -203,6 +208,12 @@ bool cStoryBook::createDatabase()
");"))
return(false);
if(!createTable("CREATE TABLE characterImage ( "
" characterID INTEGER REFERENCES character (id), "
" imageID INTEGER REFERENCES image (id) "
");"))
return(false);
if(!createTable("CREATE TABLE object ( "
" id INTEGER PRIMARY KEY AUTOINCREMENT "
" UNIQUE, "
@@ -348,22 +359,27 @@ bool cStoryBook::loadSceneList()
bool cStoryBook::loadCharacterList()
{
return(m_characterList.load());
return(m_characterList.load(&m_imageList));
}
bool cStoryBook::loadPlaceList()
{
return(m_placeList.load());
return(m_placeList.load(&m_imageList));
}
bool cStoryBook::loadObjectList()
{
return(m_objectList.load());
return(m_objectList.load(&m_imageList));
}
bool cStoryBook::loadRechercheList()
{
return(m_rechercheList.load());
return(m_rechercheList.load(&m_imageList));
}
bool cStoryBook::loadImageList()
{
return(m_imageList.load());
}
QString cStoryBook::title()
+3
View File
@@ -10,6 +10,7 @@
#include "cplace.h"
#include "cobject.h"
#include "crecherche.h"
#include "cimage.h"
#include <QString>
#include <QObject>
@@ -51,6 +52,7 @@ private:
cPlaceList m_placeList;
cObjectList m_objectList;
cRechercheList m_rechercheList;
cImageList m_imageList;
bool createDatabase();
bool updateDatabase();
@@ -64,6 +66,7 @@ private:
bool loadPlaceList();
bool loadObjectList();
bool loadRechercheList();
bool loadImageList();
};
#endif // CSTORYBOOK_H
+4 -2
View File
@@ -57,7 +57,8 @@ SOURCES += \
cpartwindow.cpp \
cplace.cpp \
cobject.cpp \
crecherche.cpp
crecherche.cpp \
cimage.cpp
HEADERS += \
cmainwindow.h \
@@ -76,7 +77,8 @@ HEADERS += \
cpartwindow.h \
cplace.h \
cobject.h \
crecherche.h
crecherche.h \
cimage.h
FORMS += \
cmainwindow.ui \