changed image handling
This commit is contained in:
+15
-12
@@ -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<cImageDescription *> cCharacter::images()
|
||||
QList<cImage*> 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<cImageDescription*> images = lpCharacter->images();
|
||||
QList<cImage*> 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();
|
||||
|
||||
+4
-4
@@ -469,14 +469,14 @@ public:
|
||||
\fn addImage
|
||||
\param lpImage
|
||||
*/
|
||||
void addImage(cImage* lpImage, cTextDocument* lpDescription);
|
||||
void addImage(cImage* lpImage);
|
||||
/*!
|
||||
\brief
|
||||
|
||||
\fn images
|
||||
\return QList<cImage *>
|
||||
*/
|
||||
QList<cImageDescription*> images();
|
||||
QList<cImage*> images();
|
||||
|
||||
/*!
|
||||
\brief
|
||||
@@ -534,7 +534,7 @@ private:
|
||||
QString m_szSchool; /*!< TODO: describe */
|
||||
QString m_szJob; /*!< TODO: describe */
|
||||
cTextDocument* m_lpDescription; /*!< TODO: describe */
|
||||
QList<cImageDescription*> m_imageList; /*!< TODO: describe */
|
||||
QList<cImage*> m_imageList; /*!< TODO: describe */
|
||||
QList<QStandardItem*> 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
|
||||
|
||||
|
||||
@@ -148,15 +148,14 @@ void cCharacterWindow::setCharacter(cCharacter* lpCharacter)
|
||||
ui->m_lpJob->setHtml(lpCharacter->job());
|
||||
ui->m_lpDescription->setDocument(lpCharacter->description());
|
||||
|
||||
QList<cImageDescription*> images = lpCharacter->images();
|
||||
QList<cImage*> 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);
|
||||
}
|
||||
|
||||
|
||||
+2
-176
@@ -12,25 +12,11 @@
|
||||
#include <QBuffer>
|
||||
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
@@ -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<cImage*>
|
||||
{
|
||||
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
|
||||
|
||||
+1
-2
@@ -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));
|
||||
|
||||
+1
-2
@@ -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 */
|
||||
};
|
||||
|
||||
+5
-12
@@ -19,13 +19,10 @@
|
||||
<property name="title">
|
||||
<string>GroupBox</string>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout_2">
|
||||
<layout class="QGridLayout" name="gridLayout">
|
||||
<item row="0" column="0">
|
||||
<layout class="QGridLayout" name="gridLayout">
|
||||
<item row="1" column="1">
|
||||
<widget class="cTextEdit" name="m_lpDescription"/>
|
||||
</item>
|
||||
<item row="0" column="0" rowspan="2">
|
||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||
<item>
|
||||
<widget class="QLabel" name="m_lpImage">
|
||||
<property name="frameShape">
|
||||
<enum>QFrame::Box</enum>
|
||||
@@ -38,12 +35,8 @@
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="1">
|
||||
<widget class="QLabel" name="m_lpType">
|
||||
<property name="text">
|
||||
<string>TextLabel</string>
|
||||
</property>
|
||||
</widget>
|
||||
<item>
|
||||
<widget class="cTextEdit" name="m_lpDescription"/>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
|
||||
+16
-14
@@ -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<cImageDescription*> cObject::images()
|
||||
QList<cImage*> 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<cImageDescription*> images = lpObject->images();
|
||||
QList<cImage*> 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();
|
||||
|
||||
@@ -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<cImageDescription *>
|
||||
\return QList<cImage *>
|
||||
*/
|
||||
QList<cImageDescription*> images();
|
||||
QList<cImage*> images();
|
||||
|
||||
/*!
|
||||
\brief
|
||||
@@ -147,7 +146,7 @@ private:
|
||||
QString m_szName; /*!< TODO: describe */
|
||||
QString m_szType; /*!< TODO: describe */
|
||||
cTextDocument* m_lpDescription; /*!< TODO: describe */
|
||||
QList<cImageDescription*> m_imageList; /*!< TODO: describe */
|
||||
QList<cImage*> m_imageList; /*!< TODO: describe */
|
||||
QList<QStandardItem*> 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
|
||||
|
||||
|
||||
+3
-4
@@ -46,15 +46,14 @@ void cObjectWindow::setObject(cObject* lpObject)
|
||||
ui->m_lpType->setText(lpObject->type());
|
||||
ui->m_lpDescription->setDocument(lpObject->description());
|
||||
|
||||
QList<cImageDescription*> images = lpObject->images();
|
||||
QList<cImage*> 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);
|
||||
}
|
||||
|
||||
|
||||
+27
@@ -5,6 +5,9 @@
|
||||
|
||||
#include "common.h"
|
||||
|
||||
#include <QBuffer>
|
||||
|
||||
|
||||
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;
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
|
||||
#include <QString>
|
||||
#include <QByteArray>
|
||||
#include <QPixmap>
|
||||
|
||||
#include <QDebug>
|
||||
|
||||
@@ -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
|
||||
|
||||
+16
-14
@@ -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<cImageDescription*> cPlace::images()
|
||||
QList<cImage*> 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<cImageDescription*> images = lpPlace->images();
|
||||
QList<cImage*> 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();
|
||||
|
||||
@@ -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<cImageDescription *>
|
||||
\return QList<cImage *>
|
||||
*/
|
||||
QList<cImageDescription*> images();
|
||||
QList<cImage*> images();
|
||||
|
||||
/*!
|
||||
\brief
|
||||
@@ -163,7 +162,7 @@ private:
|
||||
QString m_szLocation; /*!< TODO: describe */
|
||||
QString m_szType; /*!< TODO: describe */
|
||||
cTextDocument* m_lpDescription; /*!< TODO: describe */
|
||||
QList<cImageDescription*> m_imageList; /*!< TODO: describe */
|
||||
QList<cImage*> m_imageList; /*!< TODO: describe */
|
||||
QList<QStandardItem*> 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
|
||||
|
||||
|
||||
+3
-4
@@ -50,15 +50,14 @@ void cPlaceWindow::setPlace(cPlace* lpPlace)
|
||||
ui->m_lpLocation->setText(lpPlace->location());
|
||||
ui->m_lpDescription->setDocument(lpPlace->description());
|
||||
|
||||
QList<cImageDescription*> images = lpPlace->images();
|
||||
QList<cImage*> 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);
|
||||
}
|
||||
|
||||
|
||||
+16
-14
@@ -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<cImageDescription*> cRecherche::images()
|
||||
QList<cImage*> cRecherche::images()
|
||||
{
|
||||
return(m_imageList);
|
||||
}
|
||||
@@ -223,7 +223,7 @@ QList<cRecherche*> 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<cImageDescription*> images = lpRecherche->images();
|
||||
QList<cImage*> 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();
|
||||
|
||||
+5
-5
@@ -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<cImageDescription *>
|
||||
\return QList<cImage *>
|
||||
*/
|
||||
QList<cImageDescription*> images();
|
||||
QList<cImage*> images();
|
||||
|
||||
/*!
|
||||
\brief
|
||||
@@ -219,7 +219,7 @@ private:
|
||||
QString m_szName; /*!< TODO: describe */
|
||||
QString m_szLink; /*!< TODO: describe */
|
||||
cTextDocument* m_lpDescription; /*!< TODO: describe */
|
||||
QList<cImageDescription*> m_imageList; /*!< TODO: describe */
|
||||
QList<cImage*> m_imageList; /*!< TODO: describe */
|
||||
QList<cCharacterDescription*> m_characterList; /*!< TODO: describe */
|
||||
QList<cObjectDescription*> m_objectList; /*!< TODO: describe */
|
||||
QList<cPlaceDescription*> 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
|
||||
|
||||
|
||||
@@ -77,15 +77,14 @@ void cRechercheWindow::setRecherche(cRecherche* lpRecherche, cCharacterList* lpC
|
||||
ui->m_lpLink->setText(lpRecherche->link());
|
||||
ui->m_lpDescription->setDocument(lpRecherche->description());
|
||||
|
||||
QList<cImageDescription*> images = lpRecherche->images();
|
||||
QList<cImage*> 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);
|
||||
}
|
||||
|
||||
|
||||
+13
-38
@@ -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)
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user