initial commit
This commit is contained in:
@@ -14,6 +14,7 @@
|
||||
|
||||
#include <QSqlDatabase>
|
||||
#include <QSqlQuery>
|
||||
#include <QSqlError>
|
||||
|
||||
#include <exiv2/exiv2.hpp>
|
||||
|
||||
@@ -28,10 +29,16 @@ cEXIF::cEXIF(cEXIFTagList* lpEXIFTagList, cEXIFCompressionList* lpEXIFCompressio
|
||||
m_lpEXIFLightSourceList(lpEXIFLightSourceList),
|
||||
m_lpEXIFFlashList(lpEXIFFlashList),
|
||||
m_lpIPTCTagList(lpIPTCTagList),
|
||||
m_lpXMPTagList(lpXMPTagList)
|
||||
m_lpXMPTagList(lpXMPTagList),
|
||||
m_lpCacheDB(nullptr)
|
||||
{
|
||||
}
|
||||
|
||||
void cEXIF::setCacheDB(QSqlDatabase* lpCacheDB)
|
||||
{
|
||||
m_lpCacheDB = lpCacheDB;
|
||||
}
|
||||
|
||||
bool cEXIF::fromFile(const QString& szFileName)
|
||||
{
|
||||
if(!QFile::exists(szFileName))
|
||||
@@ -155,32 +162,86 @@ bool cEXIF::fromFile(const QString& szFileName)
|
||||
if(!m_previewList.count())
|
||||
{
|
||||
QImage image;
|
||||
if(image.load(szFileName))
|
||||
|
||||
if(m_lpCacheDB && m_lpCacheDB->isOpen())
|
||||
{
|
||||
QTransform rotation;
|
||||
int angle = 0;
|
||||
QSqlQuery query(*m_lpCacheDB);
|
||||
QFileInfo fileInfo(szFileName);
|
||||
|
||||
switch(imageOrientation())
|
||||
query.prepare("SELECT thumbnail FROM files WHERE fileName=:fileName AND fileSize=:fileSize AND fileDate=:fileDate;");
|
||||
query.bindValue(":fileName", szFileName);
|
||||
query.bindValue(":fileSize", fileInfo.size());
|
||||
query.bindValue(":fileDate", fileInfo.birthTime());
|
||||
|
||||
if(!query.exec())
|
||||
qDebug() << query.lastError().text();
|
||||
else
|
||||
{
|
||||
case 8:
|
||||
angle = 270;
|
||||
break;
|
||||
case 3:
|
||||
angle = 180;
|
||||
break;
|
||||
case 6:
|
||||
angle = 90;
|
||||
break;
|
||||
if(query.first())
|
||||
image = blob2Image(query.value("thumbnail").toByteArray());
|
||||
}
|
||||
|
||||
if(angle != 0)
|
||||
{
|
||||
rotation.rotate(angle);
|
||||
image = image.transformed(rotation);
|
||||
}
|
||||
|
||||
m_thumbnail = image.scaled(THUMBNAIL_WIDTH, THUMBNAIL_HEIGHT, Qt::KeepAspectRatio, Qt::SmoothTransformation);
|
||||
}
|
||||
|
||||
if(image.isNull())
|
||||
{
|
||||
if(image.load(szFileName))
|
||||
{
|
||||
QTransform rotation;
|
||||
int angle = 0;
|
||||
|
||||
switch(imageOrientation())
|
||||
{
|
||||
case 8:
|
||||
angle = 270;
|
||||
break;
|
||||
case 3:
|
||||
angle = 180;
|
||||
break;
|
||||
case 6:
|
||||
angle = 90;
|
||||
break;
|
||||
}
|
||||
|
||||
if(angle != 0)
|
||||
{
|
||||
rotation.rotate(angle);
|
||||
image = image.transformed(rotation);
|
||||
}
|
||||
|
||||
m_thumbnail = image.scaled(THUMBNAIL_WIDTH, THUMBNAIL_HEIGHT, Qt::KeepAspectRatio, Qt::SmoothTransformation);
|
||||
|
||||
if(m_lpCacheDB && m_lpCacheDB->isOpen())
|
||||
{
|
||||
QSqlQuery query(*m_lpCacheDB);
|
||||
QFileInfo fileInfo(szFileName);
|
||||
|
||||
query.prepare("SELECT COUNT(1) cnt FROM files WHERE fileName=:fileName AND fileSize=:fileSize AND fileDate=:fileDate;");
|
||||
query.bindValue(":fileName", szFileName);
|
||||
query.bindValue(":fileSize", fileInfo.size());
|
||||
query.bindValue(":fileDate", fileInfo.birthTime());
|
||||
|
||||
if(!query.exec())
|
||||
qDebug() << query.lastError().text();
|
||||
else
|
||||
{
|
||||
query.first();
|
||||
if(!query.value("cnt").toInt())
|
||||
{
|
||||
query.prepare("INSERT INTO files (fileName, fileSize, fileDate, thumbnail) VALUES (:fileName, :fileSize, :fileDate, :thumbnail);");
|
||||
query.bindValue(":fileName", szFileName);
|
||||
query.bindValue(":fileSize", fileInfo.size());
|
||||
query.bindValue(":fileDate", fileInfo.birthTime());
|
||||
query.bindValue(":thumbnail", image2Blob(m_thumbnail));
|
||||
|
||||
if(!query.exec())
|
||||
qDebug() << query.lastError().text();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
m_thumbnail = image;
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -537,14 +598,14 @@ cEXIFCompression::cEXIFCompression(const qint32& iID, const QString& szCompressi
|
||||
|
||||
cEXIFCompressionList::cEXIFCompressionList()
|
||||
{
|
||||
QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE");
|
||||
QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE", "exifCompressionList");
|
||||
db.setHostName("localhost");
|
||||
db.setDatabaseName("picturePrint.db");
|
||||
|
||||
if(!db.open())
|
||||
return;
|
||||
|
||||
QSqlQuery query;
|
||||
QSqlQuery query(db);
|
||||
|
||||
query.prepare("SELECT id, compression FROM exifCompression;");
|
||||
if(!query.exec())
|
||||
@@ -599,14 +660,14 @@ cEXIFLightSource::cEXIFLightSource(const qint32& iID, const QString& szLightSour
|
||||
|
||||
cEXIFLightSourceList::cEXIFLightSourceList()
|
||||
{
|
||||
QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE");
|
||||
QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE", "exifLightSourceList");
|
||||
db.setHostName("localhost");
|
||||
db.setDatabaseName("picturePrint.db");
|
||||
|
||||
if(!db.open())
|
||||
return;
|
||||
|
||||
QSqlQuery query;
|
||||
QSqlQuery query(db);
|
||||
|
||||
query.prepare("SELECT id, lightsource FROM exifLightSource;");
|
||||
if(!query.exec())
|
||||
@@ -661,14 +722,14 @@ cEXIFFlash::cEXIFFlash(const qint32& iID, const QString& szFlash) :
|
||||
|
||||
cEXIFFlashList::cEXIFFlashList()
|
||||
{
|
||||
QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE");
|
||||
QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE", "exifFlashList");
|
||||
db.setHostName("localhost");
|
||||
db.setDatabaseName("picturePrint.db");
|
||||
|
||||
if(!db.open())
|
||||
return;
|
||||
|
||||
QSqlQuery query;
|
||||
QSqlQuery query(db);
|
||||
|
||||
query.prepare("SELECT id, lightsource FROM exifLightSource;");
|
||||
if(!query.exec())
|
||||
@@ -727,14 +788,14 @@ cEXIFTag::cEXIFTag(const qint32& iTAGID, const QString& szTAGName, const QString
|
||||
|
||||
cEXIFTagList::cEXIFTagList()
|
||||
{
|
||||
QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE");
|
||||
QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE", "exifTagList");
|
||||
db.setHostName("localhost");
|
||||
db.setDatabaseName("picturePrint.db");
|
||||
|
||||
if(!db.open())
|
||||
return;
|
||||
|
||||
QSqlQuery query;
|
||||
QSqlQuery query(db);
|
||||
|
||||
query.prepare("SELECT tag, ifd, key, type, description FROM exifTags;");
|
||||
if(!query.exec())
|
||||
@@ -1037,14 +1098,14 @@ cXMPTag::cXMPTag(const QString& szTAGName, const qint32& iTypeID, const QString&
|
||||
|
||||
cXMPTagList::cXMPTagList()
|
||||
{
|
||||
QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE");
|
||||
QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE", "xmpTagList");
|
||||
db.setHostName("localhost");
|
||||
db.setDatabaseName("picturePrint.db");
|
||||
|
||||
if(!db.open())
|
||||
return;
|
||||
|
||||
QSqlQuery query;
|
||||
QSqlQuery query(db);
|
||||
|
||||
query.prepare("SELECT tag, type, description FROM xmpTags;");
|
||||
if(!query.exec())
|
||||
|
||||
@@ -609,6 +609,14 @@ class cEXIF
|
||||
public:
|
||||
cEXIF(cEXIFTagList* lpEXIFTagList, cEXIFCompressionList* lpEXIFCompressionList, cEXIFLightSourceList* lpEXIFLightSourceList, cEXIFFlashList* lpEXIFFlashList, cIPTCTagList* lpIPTCTagList, cXMPTagList* lpXMPTagList);
|
||||
|
||||
/*!
|
||||
\brief
|
||||
|
||||
\fn setCacheDB
|
||||
\param lpCacheDB
|
||||
*/
|
||||
void setCacheDB(QSqlDatabase* lpCacheDB);
|
||||
|
||||
/*!
|
||||
\brief
|
||||
|
||||
@@ -829,6 +837,8 @@ private:
|
||||
|
||||
cXMPTagList* m_lpXMPTagList; /*!< TODO: describe */
|
||||
|
||||
QSqlDatabase* m_lpCacheDB; /*!< TODO: describe */
|
||||
|
||||
/*!
|
||||
\brief
|
||||
|
||||
|
||||
+47
-2
@@ -13,13 +13,18 @@
|
||||
|
||||
#include <QPainter>
|
||||
|
||||
#include <QElapsedTimer>
|
||||
|
||||
#include <QSqlQuery>
|
||||
|
||||
|
||||
cFileBrowser::cFileBrowser(QProgressBar* lpProgressBar, QList<IMAGEFORMAT>* lpImageFormats, QWidget *parent) :
|
||||
QWidget(parent),
|
||||
ui(new Ui::cFileBrowser),
|
||||
m_lpFileListModel(nullptr),
|
||||
m_lpProgressBar(lpProgressBar),
|
||||
m_lpImageFormats(lpImageFormats)
|
||||
m_lpImageFormats(lpImageFormats),
|
||||
m_working(false)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
|
||||
@@ -36,17 +41,50 @@ cFileBrowser::cFileBrowser(QProgressBar* lpProgressBar, QList<IMAGEFORMAT>* lpIm
|
||||
m_lpFileListModel = new QStandardItemModel(0, 0);
|
||||
ui->m_lpFileList->setModel(m_lpFileListModel);
|
||||
|
||||
m_cacheDB = QSqlDatabase::addDatabase("QSQLITE", "cacheDB");
|
||||
m_cacheDB.setHostName("localhost");
|
||||
m_cacheDB.setDatabaseName("C:\\Temp\\picturePrint.db");
|
||||
|
||||
m_cacheDB.open();
|
||||
if(!m_cacheDB.open())
|
||||
return;
|
||||
|
||||
QSqlQuery query(m_cacheDB);
|
||||
|
||||
if(!m_cacheDB.tables().contains("files"))
|
||||
{
|
||||
query.prepare("CREATE TABLE files "
|
||||
"( "
|
||||
" fileName TEXT, "
|
||||
" fileSize BIGINT, "
|
||||
" fileDate DATETIME, "
|
||||
" thumbnail BLOB "
|
||||
");");
|
||||
|
||||
if(!query.exec())
|
||||
{
|
||||
m_cacheDB.close();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
connect(ui->m_lpDirectoryList->selectionModel(), &QItemSelectionModel::selectionChanged, this, &cFileBrowser::onDirectoryChanged);
|
||||
}
|
||||
|
||||
cFileBrowser::~cFileBrowser()
|
||||
{
|
||||
if(m_cacheDB.isOpen())
|
||||
m_cacheDB.close();
|
||||
|
||||
delete ui;
|
||||
}
|
||||
|
||||
void cFileBrowser::onDirectoryChanged(const QItemSelection& selected, const QItemSelection& /*deselected*/)
|
||||
{
|
||||
m_working = true;
|
||||
|
||||
m_lpProgressBar->setVisible(true);
|
||||
ui->m_lpDirectoryList->setEnabled(false);
|
||||
|
||||
m_lpFileListModel->clear();
|
||||
|
||||
@@ -57,20 +95,25 @@ void cFileBrowser::onDirectoryChanged(const QItemSelection& selected, const QIte
|
||||
|
||||
m_lpProgressBar->setRange(0, list.count());
|
||||
|
||||
m_cacheDB.transaction();
|
||||
for(int x = 0;x < list.count();x++)
|
||||
{
|
||||
addFile(list[x]);
|
||||
m_lpProgressBar->setValue(x);
|
||||
// qApp->sendPostedEvents();
|
||||
qApp->processEvents();
|
||||
}
|
||||
m_cacheDB.commit();
|
||||
|
||||
ui->m_lpDirectoryList->setEnabled(true);
|
||||
m_lpProgressBar->setVisible(false);
|
||||
|
||||
m_working = false;
|
||||
}
|
||||
|
||||
void cFileBrowser::addFile(const QFileInfo& fileInfo)
|
||||
{
|
||||
cEXIF* lpExif = new cEXIF(&m_exifTAGList, &m_exifCompressionList, &m_exifLightSourceList, &m_exifFlashList, &m_iptcTagList, &m_xmpTagList);
|
||||
lpExif->setCacheDB(&m_cacheDB);
|
||||
|
||||
if(!lpExif->fromFile(fileInfo.filePath()))
|
||||
{
|
||||
@@ -91,4 +134,6 @@ void cFileBrowser::addFile(const QFileInfo& fileInfo)
|
||||
|
||||
m_lpFileListModel->appendRow(lpItem);
|
||||
ui->m_lpFileList->setIndexWidget(m_lpFileListModel->index(m_lpFileListModel->rowCount()-1, 0), lpFileViewer);
|
||||
|
||||
delete lpExif;
|
||||
}
|
||||
|
||||
@@ -13,6 +13,8 @@
|
||||
|
||||
#include <QFileInfo>
|
||||
|
||||
#include <QSqlDatabase>
|
||||
|
||||
|
||||
namespace Ui {
|
||||
class cFileBrowser;
|
||||
@@ -42,6 +44,10 @@ private:
|
||||
|
||||
cXMPTagList m_xmpTagList;
|
||||
|
||||
QSqlDatabase m_cacheDB;
|
||||
|
||||
bool m_working;
|
||||
|
||||
void addFile(const QFileInfo& fileInfo);
|
||||
|
||||
private slots:
|
||||
|
||||
+2
-2
@@ -140,14 +140,14 @@ void cMainWindow::setImageFormats()
|
||||
QList<QByteArray> readList = QImageReader::supportedImageFormats();
|
||||
QList<QByteArray> writeList = QImageWriter::supportedImageFormats();
|
||||
|
||||
QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE");
|
||||
QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE", "picturePrint");
|
||||
db.setHostName("localhost");
|
||||
db.setDatabaseName("picturePrint.db");
|
||||
|
||||
if(!db.open())
|
||||
return;
|
||||
|
||||
QSqlQuery query;
|
||||
QSqlQuery query(db);
|
||||
|
||||
query.prepare("SELECT shortname, description, extension FROM imageFormat;");
|
||||
if(!query.exec())
|
||||
|
||||
+27
@@ -1,5 +1,8 @@
|
||||
#include "common.h"
|
||||
|
||||
#include <QImage>
|
||||
#include <QBuffer>
|
||||
|
||||
|
||||
QStringList generateReadList(const QList<IMAGEFORMAT>& imageFormats)
|
||||
{
|
||||
@@ -30,3 +33,27 @@ QStringList generateWriteList(const QList<IMAGEFORMAT>& imageFormats)
|
||||
|
||||
return(writeList);
|
||||
}
|
||||
|
||||
QImage blob2Image(const QByteArray& ba)
|
||||
{
|
||||
QImage image;
|
||||
|
||||
if(!ba.isEmpty())
|
||||
{
|
||||
if(!image.loadFromData(ba))
|
||||
myDebug << "image load error.";
|
||||
}
|
||||
|
||||
return(image);
|
||||
}
|
||||
|
||||
QByteArray image2Blob(const QImage &image)
|
||||
{
|
||||
QByteArray ba;
|
||||
QBuffer buffer(&ba);
|
||||
buffer.open(QIODevice::WriteOnly);
|
||||
image.save(&buffer, "JPG");
|
||||
buffer.close();
|
||||
|
||||
return(ba);
|
||||
}
|
||||
|
||||
@@ -32,8 +32,11 @@ typedef struct tagIMAGEFORMAT
|
||||
} IMAGEFORMAT;
|
||||
|
||||
|
||||
QStringList generateReadList(const QList<IMAGEFORMAT>& imageFormats);
|
||||
QStringList generateWriteList(const QList<IMAGEFORMAT>& imageFormats);
|
||||
QStringList generateReadList(const QList<IMAGEFORMAT>& imageFormats);
|
||||
QStringList generateWriteList(const QList<IMAGEFORMAT>& imageFormats);
|
||||
|
||||
QImage blob2Image(const QByteArray& ba);
|
||||
QByteArray image2Blob(const QImage& image);
|
||||
|
||||
|
||||
#endif // COMMON_H
|
||||
|
||||
Reference in New Issue
Block a user