import
This commit is contained in:
+18
-29
@@ -8,8 +8,6 @@
|
||||
|
||||
#include "common.h"
|
||||
|
||||
#include "cpicture.h"
|
||||
|
||||
#include "cdatetimepicker.h"
|
||||
|
||||
#include <QSettings>
|
||||
@@ -28,13 +26,14 @@
|
||||
#include <QDebug>
|
||||
|
||||
|
||||
cImportDialog::cImportDialog(const QString& szRootPath, QWidget *parent) :
|
||||
cImportDialog::cImportDialog(const QString& szRootPath, cPictureList& pictureList, QWidget *parent) :
|
||||
QDialog(parent),
|
||||
ui(new Ui::cImportDialog),
|
||||
m_szRootPath(szRootPath),
|
||||
m_pictureList(pictureList),
|
||||
m_lpFolderViewModel(nullptr),
|
||||
m_lpThumbnailViewModel(nullptr),
|
||||
m_lpThumbnailFilterProxyModel(nullptr),
|
||||
m_lpThumbnailSortFilterProxyModel(nullptr),
|
||||
m_bLoading(false),
|
||||
m_bHasImported(false),
|
||||
m_lpRootItem(nullptr)
|
||||
@@ -47,7 +46,7 @@ cImportDialog::~cImportDialog()
|
||||
{
|
||||
delete m_lpThumbnailViewModel;
|
||||
delete m_lpFolderViewModel;
|
||||
delete m_lpThumbnailFilterProxyModel;
|
||||
delete m_lpThumbnailSortFilterProxyModel;
|
||||
|
||||
delete ui;
|
||||
}
|
||||
@@ -62,9 +61,9 @@ void cImportDialog::initUI()
|
||||
ui->m_lpFolderView->setModel(m_lpFolderViewModel);
|
||||
|
||||
m_lpThumbnailViewModel = new QStandardItemModel;
|
||||
m_lpThumbnailFilterProxyModel = new cThumbnailSortFilterProxyModel(this);
|
||||
ui->m_lpThumbnailView->setModel(m_lpThumbnailFilterProxyModel);
|
||||
m_lpThumbnailFilterProxyModel->setSourceModel(m_lpThumbnailViewModel);
|
||||
m_lpThumbnailSortFilterProxyModel = new cThumbnailSortFilterProxyModel(this);
|
||||
ui->m_lpThumbnailView->setModel(m_lpThumbnailSortFilterProxyModel);
|
||||
m_lpThumbnailSortFilterProxyModel->setSourceModel(m_lpThumbnailViewModel);
|
||||
|
||||
QSettings settings;
|
||||
|
||||
@@ -143,7 +142,7 @@ void cImportDialog::onThumbnailSelected(const QItemSelection& /*selection*/, con
|
||||
if(!index.isValid())
|
||||
return;
|
||||
|
||||
cPicture* lpPicture = m_lpThumbnailFilterProxyModel->data(index, Qt::UserRole+1).value<cPicture*>();
|
||||
cPicture* lpPicture = m_lpThumbnailSortFilterProxyModel->data(index, Qt::UserRole+1).value<cPicture*>();
|
||||
lpToolBoxInfo->setPicture(lpPicture);
|
||||
}
|
||||
|
||||
@@ -156,7 +155,7 @@ void cImportDialog::onFolderSelected(const QItemSelection& /*selection*/, const
|
||||
if(!lpItem)
|
||||
return;
|
||||
|
||||
m_lpThumbnailFilterProxyModel->setFilterPath(lpItem->data(Qt::UserRole+2).toString());
|
||||
m_lpThumbnailSortFilterProxyModel->setFilterPath(lpItem->data(Qt::UserRole+2).toString());
|
||||
}
|
||||
|
||||
void cImportDialog::accept()
|
||||
@@ -220,20 +219,18 @@ void cImportDialog::onRead()
|
||||
|
||||
void cImportDialog::onImport()
|
||||
{
|
||||
QModelIndexList selected = ui->m_lpThumbnailView->selectionModel()->selectedRows();
|
||||
QDir dir;
|
||||
QFile file;
|
||||
|
||||
ui->m_lpProgress->setVisible(true);
|
||||
ui->m_lpProgress->setRange(0, selected.count());
|
||||
ui->m_lpProgress->setRange(0, ui->m_lpThumbnailView->selectionModel()->selectedIndexes().count());
|
||||
|
||||
for(int x = 0;x < selected.count();x++)
|
||||
for(int x = 0;x < ui->m_lpThumbnailView->selectionModel()->selectedIndexes().count();x++)
|
||||
{
|
||||
QStandardItem* lpItem = m_lpThumbnailViewModel->itemFromIndex(selected[x]);
|
||||
|
||||
if(lpItem)
|
||||
QModelIndex index = ui->m_lpThumbnailView->selectionModel()->selectedIndexes()[x];
|
||||
if(index.isValid())
|
||||
{
|
||||
cPicture* lpPicture = lpItem->data().value<cPicture*>();
|
||||
cPicture* lpPicture = m_lpThumbnailSortFilterProxyModel->data(index, Qt::UserRole+1).value<cPicture*>();
|
||||
|
||||
if(lpPicture)
|
||||
{
|
||||
@@ -251,26 +248,18 @@ void cImportDialog::onImport()
|
||||
szDestPath.append(lpPicture->cameraModel() + QDir::separator());
|
||||
|
||||
szDest.append(szDestPath);
|
||||
szDest.append(lpPicture->fileName());
|
||||
|
||||
if(dir.mkpath(szDest))
|
||||
// if(copyFile(szSource, szDest, ui->m_lpMove->isChecked()))
|
||||
if(copyFile(szSource, szDest, false))
|
||||
{
|
||||
szDest.append(lpPicture->fileName());
|
||||
|
||||
if(file.exists(szDest))
|
||||
file.remove(szDest);
|
||||
|
||||
file.copy(szSource, szDest);
|
||||
|
||||
ui->m_lpProgress->setValue(x);
|
||||
qApp->processEvents();
|
||||
|
||||
lpPicture->setFilePath(szDestPath.left(szDestPath.length()-1).replace("\\", "/"));
|
||||
lpPicture->toDB();
|
||||
|
||||
if(ui->m_lpMove->isChecked())
|
||||
{
|
||||
// file.remove(szSource);
|
||||
}
|
||||
m_pictureList.add(lpPicture);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+23
-21
@@ -12,6 +12,7 @@
|
||||
#include <QCloseEvent>
|
||||
#include <QItemSelection>
|
||||
|
||||
#include "cpicture.h"
|
||||
#include "cthumbnailsortfilterproxymodel.h"
|
||||
|
||||
|
||||
@@ -36,7 +37,7 @@ public:
|
||||
\param szRootPath
|
||||
\param parent
|
||||
*/
|
||||
explicit cImportDialog(const QString& szRootPath, QWidget *parent = nullptr);
|
||||
explicit cImportDialog(const QString& szRootPath, cPictureList& pictureList, QWidget *parent = nullptr);
|
||||
/*!
|
||||
\brief
|
||||
|
||||
@@ -50,7 +51,7 @@ public:
|
||||
\fn hasImported
|
||||
\return bool
|
||||
*/
|
||||
bool hasImported();
|
||||
bool hasImported();
|
||||
|
||||
private slots:
|
||||
/*!
|
||||
@@ -58,19 +59,19 @@ private slots:
|
||||
|
||||
\fn onPathSelect
|
||||
*/
|
||||
void onPathSelect();
|
||||
void onPathSelect();
|
||||
/*!
|
||||
\brief
|
||||
|
||||
\fn onRead
|
||||
*/
|
||||
void onRead();
|
||||
void onRead();
|
||||
/*!
|
||||
\brief
|
||||
|
||||
\fn onImport
|
||||
*/
|
||||
void onImport();
|
||||
void onImport();
|
||||
/*!
|
||||
\brief
|
||||
|
||||
@@ -78,7 +79,7 @@ private slots:
|
||||
\param selection
|
||||
\param previous
|
||||
*/
|
||||
void onThumbnailSelected(const QItemSelection& selection, const QItemSelection& previous);
|
||||
void onThumbnailSelected(const QItemSelection& selection, const QItemSelection& previous);
|
||||
/*!
|
||||
\brief
|
||||
|
||||
@@ -86,30 +87,31 @@ private slots:
|
||||
\param selection
|
||||
\param previous
|
||||
*/
|
||||
void onFolderSelected(const QItemSelection& selection, const QItemSelection& previous);
|
||||
void onFolderSelected(const QItemSelection& selection, const QItemSelection& previous);
|
||||
|
||||
private:
|
||||
Ui::cImportDialog* ui; /*!< TODO: describe */
|
||||
QString m_szRootPath; /*!< TODO: describe */
|
||||
QStandardItemModel* m_lpFolderViewModel; /*!< TODO: describe */
|
||||
QStandardItemModel* m_lpThumbnailViewModel; /*!< TODO: describe */
|
||||
cThumbnailSortFilterProxyModel* m_lpThumbnailFilterProxyModel; /*!< TODO: describe */
|
||||
bool m_bLoading; /*!< TODO: describe */
|
||||
bool m_bHasImported; /*!< TODO: describe */
|
||||
QStandardItem* m_lpRootItem; /*!< TODO: describe */
|
||||
Ui::cImportDialog* ui; /*!< TODO: describe */
|
||||
QString m_szRootPath; /*!< TODO: describe */
|
||||
cPictureList& m_pictureList; /*!< TODO: describe */
|
||||
QStandardItemModel* m_lpFolderViewModel; /*!< TODO: describe */
|
||||
QStandardItemModel* m_lpThumbnailViewModel; /*!< TODO: describe */
|
||||
cThumbnailSortFilterProxyModel* m_lpThumbnailSortFilterProxyModel; /*!< TODO: describe */
|
||||
bool m_bLoading; /*!< TODO: describe */
|
||||
bool m_bHasImported; /*!< TODO: describe */
|
||||
QStandardItem* m_lpRootItem; /*!< TODO: describe */
|
||||
|
||||
/*!
|
||||
\brief
|
||||
|
||||
\fn initUI
|
||||
*/
|
||||
void initUI();
|
||||
void initUI();
|
||||
/*!
|
||||
\brief
|
||||
|
||||
\fn createActions
|
||||
*/
|
||||
void createActions();
|
||||
void createActions();
|
||||
|
||||
/*!
|
||||
\brief
|
||||
@@ -118,27 +120,27 @@ private:
|
||||
\param szPath
|
||||
\param bRecursive
|
||||
*/
|
||||
void readDirectory(const QString& szPath, bool bRecursive);
|
||||
void readDirectory(const QString& szPath, bool bRecursive);
|
||||
|
||||
/*!
|
||||
\brief
|
||||
|
||||
\fn accept
|
||||
*/
|
||||
void accept();
|
||||
void accept();
|
||||
/*!
|
||||
\brief
|
||||
|
||||
\fn reject
|
||||
*/
|
||||
void reject();
|
||||
void reject();
|
||||
|
||||
/*!
|
||||
\brief
|
||||
|
||||
\fn savePosition
|
||||
*/
|
||||
void savePosition();
|
||||
void savePosition();
|
||||
protected:
|
||||
};
|
||||
|
||||
|
||||
+23
-14
@@ -124,14 +124,23 @@ void cMainWindow::loadData(bool bProgressBar)
|
||||
m_bLoading = true;
|
||||
|
||||
m_pictureList.clear();
|
||||
m_pictureList.load(m_lpSplashScreen, bProgressBar ? m_lpProgressBar : nullptr);
|
||||
|
||||
displayData();
|
||||
|
||||
m_bLoading = false;
|
||||
}
|
||||
|
||||
void cMainWindow::displayData()
|
||||
{
|
||||
m_lpThumbnailViewModel->clear();
|
||||
m_lpFolderViewModel->clear();
|
||||
ui->m_lpStatusBar->showMessage(tr("refreshing..."));
|
||||
qApp->processEvents();
|
||||
|
||||
m_lpRootItem = new QStandardItem("library");
|
||||
m_lpFolderViewModel->appendRow(m_lpRootItem);
|
||||
|
||||
m_pictureList.load(m_lpSplashScreen, bProgressBar ? m_lpProgressBar : nullptr);
|
||||
|
||||
for(int x = 0;x < m_pictureList.count();x++)
|
||||
{
|
||||
QIcon icon;
|
||||
@@ -159,8 +168,7 @@ void cMainWindow::loadData(bool bProgressBar)
|
||||
}
|
||||
|
||||
ui->m_lpFolderView->expandAll();
|
||||
|
||||
m_bLoading = false;
|
||||
ui->m_lpStatusBar->showMessage(tr("done."), 3);
|
||||
}
|
||||
|
||||
void cMainWindow::closeEvent(QCloseEvent *event)
|
||||
@@ -412,15 +420,11 @@ void cMainWindow::onFileOpen()
|
||||
|
||||
void cMainWindow::onFileImport()
|
||||
{
|
||||
cImportDialog importDialog(m_pictureLibrary.rootPath(), this);
|
||||
cImportDialog importDialog(m_pictureLibrary.rootPath(), m_pictureList, this);
|
||||
|
||||
importDialog.exec();
|
||||
if(importDialog.hasImported())
|
||||
{
|
||||
m_lpProgressBar->setVisible(true);
|
||||
loadData(true);
|
||||
m_lpProgressBar->setVisible(false);
|
||||
}
|
||||
displayData();
|
||||
}
|
||||
|
||||
void cMainWindow::onThumbnailViewContextMenu(const QPoint& pos)
|
||||
@@ -458,12 +462,17 @@ void cMainWindow::onChangeDate()
|
||||
|
||||
lpPicture->setDateTime(dateTimePicker.dateTime());
|
||||
QString szPath = QString::number(lpPicture->dateTime().date().year()) + "/" + lpPicture->dateTime().date().toString("yyyy-MM-dd");
|
||||
lpPicture->setFilePath(szPath);
|
||||
m_lpThumbnailSortFilterProxyModel->setData(index, QVariant::fromValue(szPath), Qt::UserRole+2);
|
||||
|
||||
insertPath(szPath, m_lpRootItem);
|
||||
m_lpFolderSortFilterProxyModel->sort(0);
|
||||
if(copyFile(m_pictureLibrary.rootPath() + QDir::separator() + lpPicture->filePath() + QDir::separator() + lpPicture->fileName(),
|
||||
m_pictureLibrary.rootPath() + QDir::separator() + szPath + QDir::separator() + lpPicture->fileName(), true))
|
||||
{
|
||||
lpPicture->setFilePath(szPath);
|
||||
lpPicture->toDB();
|
||||
insertPath(szPath, m_lpRootItem);
|
||||
m_lpFolderSortFilterProxyModel->sort(0);
|
||||
|
||||
m_lpThumbnailSortFilterProxyModel->invalidate();
|
||||
m_lpThumbnailSortFilterProxyModel->invalidate();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -126,6 +126,12 @@ private:
|
||||
\param bProgressBar
|
||||
*/
|
||||
void loadData(bool bProgressBar = false);
|
||||
/*!
|
||||
\brief
|
||||
|
||||
\fn displayData
|
||||
*/
|
||||
void displayData();
|
||||
|
||||
protected:
|
||||
/*!
|
||||
|
||||
+25
-1
@@ -41,7 +41,7 @@ QByteArray image2Blob(const QImage &image)
|
||||
QStandardItem* insertPath(QString szPath, QStandardItem* lpRootItem)
|
||||
{
|
||||
if(!lpRootItem)
|
||||
return(0);
|
||||
return(nullptr);
|
||||
|
||||
QString szPath1 = szPath.replace("\\", "/");
|
||||
QStringList szPathList = szPath1.split("/");
|
||||
@@ -85,3 +85,27 @@ QStandardItem* insertPath(QString szPath, QStandardItem* lpRootItem)
|
||||
|
||||
return(lpCurRoot);
|
||||
}
|
||||
|
||||
bool copyFile(const QString& szSource, const QString& szDest, bool bDelete)
|
||||
{
|
||||
QString szDestPath;
|
||||
QString szDestFilePath = szDest;
|
||||
QDir dir;
|
||||
QFile file;
|
||||
|
||||
szDestFilePath.replace("\\", "/");
|
||||
|
||||
szDestPath = szDestFilePath.left(szDestFilePath.lastIndexOf("/"));
|
||||
|
||||
dir.mkpath(szDestPath);
|
||||
|
||||
if(file.exists(szDestFilePath))
|
||||
file.remove(szDestFilePath);
|
||||
|
||||
file.copy(szSource, szDestFilePath);
|
||||
|
||||
if(bDelete)
|
||||
file.remove(szSource);
|
||||
|
||||
return(true);
|
||||
}
|
||||
|
||||
@@ -54,5 +54,15 @@ QByteArray image2Blob(const QImage& image);
|
||||
*/
|
||||
QStandardItem* insertPath(QString szPath, QStandardItem* lpRootItem);
|
||||
|
||||
/*!
|
||||
\brief
|
||||
|
||||
\fn copyFile
|
||||
\param szSource
|
||||
\param szDest
|
||||
\param bDelete
|
||||
\return bool
|
||||
*/
|
||||
bool copyFile(const QString& szSource, const QString& szDest, bool bDelete = false);
|
||||
|
||||
#endif // COMMON_H
|
||||
|
||||
+16
-1
@@ -86,7 +86,7 @@ bool cPicture::toDB()
|
||||
|
||||
if(m_iID != -1)
|
||||
{
|
||||
query.prepare("SELECT id FROM file WHERE id=:id;");
|
||||
query.prepare("SELECT id FROM picture WHERE id=:id;");
|
||||
query.bindValue(":id", m_iID);
|
||||
if(!query.exec())
|
||||
{
|
||||
@@ -534,6 +534,21 @@ cPicture* cPictureList::add(qint32 iID, bool bNoCheck)
|
||||
return(lpNew);
|
||||
}
|
||||
|
||||
bool cPictureList::add(cPicture* lpPicture, bool bNoCheck)
|
||||
{
|
||||
if(bNoCheck)
|
||||
{
|
||||
append(lpPicture);
|
||||
return(true);
|
||||
}
|
||||
|
||||
if(contains(lpPicture))
|
||||
return(false);
|
||||
|
||||
append(lpPicture);
|
||||
return(true);
|
||||
}
|
||||
|
||||
cPicture* cPictureList::find(qint32 iID)
|
||||
{
|
||||
for(int i = 0;i < count();i++)
|
||||
|
||||
@@ -517,6 +517,15 @@ public:
|
||||
/*!
|
||||
\brief
|
||||
|
||||
\fn add
|
||||
\param cPicture
|
||||
\param bNoCheck
|
||||
\return bool
|
||||
*/
|
||||
bool add(cPicture* lpPicture, bool bNoCheck = false);
|
||||
/*!
|
||||
\brief
|
||||
|
||||
\fn find
|
||||
\param iID
|
||||
\return cPicture
|
||||
|
||||
Reference in New Issue
Block a user