From cbaacbe0e99b6a340a0525c812086f1e202642f7 Mon Sep 17 00:00:00 2001 From: Herwig Birke Date: Fri, 15 Feb 2019 15:10:44 +0100 Subject: [PATCH] initial commit --- cdatetimepicker.h | 35 +++++++- cimportdialog.cpp | 2 +- cmainwindow.cpp | 148 ++++++++++++++++++++------------- cmainwindow.h | 26 ++++++ cmainwindow.ui | 6 ++ cpicture.cpp | 13 +-- cpicture.h | 2 +- cthumbnailfilterproxymodel.cpp | 24 ++++++ cthumbnailfilterproxymodel.h | 46 ++++++++++ pictureLibrary.pro | 6 +- 10 files changed, 234 insertions(+), 74 deletions(-) create mode 100644 cthumbnailfilterproxymodel.cpp create mode 100644 cthumbnailfilterproxymodel.h diff --git a/cdatetimepicker.h b/cdatetimepicker.h index bd90102..627e63b 100644 --- a/cdatetimepicker.h +++ b/cdatetimepicker.h @@ -10,20 +10,53 @@ namespace Ui { class cDateTimePicker; } +/** + * @brief + * + */ class cDateTimePicker : public QDialog { Q_OBJECT public: + /** + * @brief + * + * @param parent + */ explicit cDateTimePicker(QWidget *parent = nullptr); + /** + * @brief + * + */ ~cDateTimePicker(); + /** + * @brief + * + * @param szText + */ void setText(const QString& szText); + /** + * @brief + * + * @param image + */ void setImage(const QImage& image); + /** + * @brief + * + * @param dateTime + */ void setDateTime(const QDateTime dateTime); + /** + * @brief + * + * @return QDateTime + */ QDateTime dateTime(); private: - Ui::cDateTimePicker* ui; + Ui::cDateTimePicker* ui; /**< TODO: describe */ }; #endif // CDATETIMEPICKER_H diff --git a/cimportdialog.cpp b/cimportdialog.cpp index cc4c55d..eecd638 100644 --- a/cimportdialog.cpp +++ b/cimportdialog.cpp @@ -214,7 +214,7 @@ void cImportDialog::onImport() ui->m_lpProgress->setValue(x); qApp->processEvents(); - lpPicture->setFilePath(szDestPath); + lpPicture->setFilePath(szDestPath.left(szDestPath.length()-1)); lpPicture->toDB(); if(ui->m_lpMove->isChecked()) diff --git a/cmainwindow.cpp b/cmainwindow.cpp index b1a347b..0ab0736 100644 --- a/cmainwindow.cpp +++ b/cmainwindow.cpp @@ -7,6 +7,7 @@ #include #include +#include #include #include #include @@ -21,12 +22,18 @@ cMainWindow::cMainWindow(cSplashScreen* lpSplashScreen, QWidget *parent) : QMainWindow(parent), ui(new Ui::cMainWindow), m_lpProgressBar(nullptr), + m_lpFolderViewModel(nullptr), + m_lpThumbnailViewModel(nullptr), + m_lpThumbnailFilterProxyModel(nullptr), + m_lpRootItem(nullptr), + m_bLoading(false), m_lpSplashScreen(lpSplashScreen), m_lpFileMenu(nullptr), m_lpFileToolBar(nullptr) { initUI(); createActions(); + loadData(); updateRecentFileActions(); @@ -41,9 +48,15 @@ cMainWindow::~cMainWindow() void cMainWindow::initUI() { ui->setupUi(this); - m_lpThumbnailViewModel = new QStandardItemModel; - ui->m_lpThumbnailView->setModel(m_lpThumbnailViewModel); + m_lpFolderViewModel = new QStandardItemModel; + ui->m_lpFolderView->setModel(m_lpFolderViewModel); + + m_lpThumbnailViewModel = new QStandardItemModel; +// ui->m_lpThumbnailView->setModel(m_lpThumbnailViewModel); + m_lpThumbnailFilterProxyModel = new cThumbnailFilterProxyModel(this); + ui->m_lpThumbnailView->setModel(m_lpThumbnailFilterProxyModel); + m_lpThumbnailFilterProxyModel->setSourceModel(m_lpThumbnailViewModel); m_lpProgressBar = new QProgressBar(this); m_lpProgressBar->setVisible(false); @@ -78,38 +91,21 @@ void cMainWindow::createActions() setToolButtonStyle(Qt::ToolButtonFollowStyle); createFileActions(); -// createEditActions(); -// createTextActions(); -// createToolsActions(); -// createWindowActions(); -// createHelpActions(); - -// createContextActions(); connect(ui->m_lpThumbnailView->selectionModel(), &QItemSelectionModel::selectionChanged, this, &cMainWindow::onThumbnailSelected); -// connect(ui->m_lpMainTab, &QTabWidget::currentChanged, this, &cMainWindow::onMainTabCurrentChanged); -// connect(ui->m_lpMainTab, &QTabWidget::tabCloseRequested, this, &cMainWindow::onMainTabTabCloseRequested); -// connect(ui->m_lpMdiArea, &QMdiArea::subWindowActivated, this, &cMainWindow::onMdiAreaSubWindowActivated); - -// connect(ui->m_lpOutlineList, &QTreeView::doubleClicked, this, &cMainWindow::onOutlineDoubleClicked); -// connect(ui->m_lpCharacterList, &QTreeView::doubleClicked, this, &cMainWindow::onCharacterDoubleClicked); -// connect(ui->m_lpPlaceList, &QTreeView::doubleClicked, this, &cMainWindow::onPlaceDoubleClicked); -// connect(ui->m_lpObjectList, &QTreeView::doubleClicked, this, &cMainWindow::onObjectDoubleClicked); -// connect(ui->m_lpRechercheList, &QTreeView::doubleClicked, this, &cMainWindow::onRechercheDoubleClicked); - -// connect(ui->m_lpOutlineList, &QTreeView::customContextMenuRequested, this, &cMainWindow::onOutlineContextMenu); -// connect(ui->m_lpCharacterList, &QTreeView::customContextMenuRequested, this, &cMainWindow::onCharacterContextMenu); -// connect(ui->m_lpPlaceList, &QTreeView::customContextMenuRequested, this, &cMainWindow::onPlaceContextMenu); -// connect(ui->m_lpObjectList, &QTreeView::customContextMenuRequested, this, &cMainWindow::onObjectContextMenu); -// connect(ui->m_lpRechercheList, &QTreeView::customContextMenuRequested, this, &cMainWindow::onRechercheContextMenu); - -// connect(ui->m_lpOutlineList, &cTreeView::dropped, this, &cMainWindow::onOutlineDropped); + connect(ui->m_lpFolderView->selectionModel(), &QItemSelectionModel::selectionChanged, this, &cMainWindow::onFolderSelected); } void cMainWindow::loadData(bool bProgressBar) { + m_bLoading = true; + m_pictureList.clear(); m_lpThumbnailViewModel->clear(); + m_lpFolderViewModel->clear(); + + m_lpRootItem = new QStandardItem("library"); + m_lpFolderViewModel->appendRow(m_lpRootItem); m_pictureList.load(m_lpSplashScreen, bProgressBar ? m_lpProgressBar : nullptr); @@ -133,7 +129,59 @@ void cMainWindow::loadData(bool bProgressBar) QStandardItem* lpItem = new QStandardItem(icon, m_pictureList[x]->fileName()); lpItem->setTextAlignment(Qt::AlignCenter); lpItem->setData(QVariant::fromValue(m_pictureList[x])); + lpItem->setData(QVariant::fromValue(m_pictureList[x]->filePath()), Qt::UserRole+2); m_lpThumbnailViewModel->appendRow(lpItem); + + insertPath(m_pictureList[x]->filePath()); + } + + ui->m_lpFolderView->expandAll(); + + m_bLoading = false; +} + +void cMainWindow::insertPath(QString szPath) +{ + if(!m_lpRootItem) + return; + + QString szPath1 = szPath.replace("\\", "/"); + QStringList szPathList = szPath1.split("/"); + QStandardItem* lpCurRoot = m_lpRootItem; + int path; + bool bFound; + + szPath1 = ""; + + for(path = 0;path < szPathList.count();path++) + { + bFound = false; + for(int x = 0;x < lpCurRoot->rowCount();x++) + { + QStandardItem* lpCurItem = lpCurRoot->child(x, 0); + + if(!lpCurItem->text().compare(szPathList[path], Qt::CaseInsensitive)) + { + lpCurRoot = lpCurItem; + bFound = true; + break; + } + } + + if(!bFound) + break; + + szPath1.append(szPathList[path]+QDir::separator()); + } + + for(;path < szPathList.count();path++) + { + szPath1.append(szPathList[path]); + QStandardItem* lpNewItem = new QStandardItem(szPathList[path]); + lpCurRoot->appendRow(lpNewItem); + lpNewItem->setData(QVariant::fromValue(szPath1), Qt::UserRole+2); + szPath1.append(QDir::separator()); + lpCurRoot = lpNewItem; } } @@ -180,39 +228,6 @@ void cMainWindow::createFileActions() m_lpFileMenu->addSeparator(); -// const QIcon saveIcon = QIcon::fromTheme("document-save"); -// m_lpFileSaveAction = m_lpFileMenu->addAction(saveIcon, tr("&Save"), this, &cMainWindow::onFileSave); -// m_lpFileSaveAction->setShortcut(QKeySequence::Save); -// m_lpFileSaveAction->setEnabled(false); -// m_lpFileToolBar->addAction(m_lpFileSaveAction); - -// m_lpFileSaveAsAction = m_lpFileMenu->addAction(tr("Save &As..."), this, &cMainWindow::onFileSaveAs); -// m_lpFileSaveAsAction->setPriority(QAction::LowPriority); -// m_lpFileMenu->addSeparator(); - -//#ifndef QT_NO_PRINTER -// const QIcon printIcon = QIcon::fromTheme("document-print"); -// m_lpFilePrintAction = m_lpFileMenu->addAction(printIcon, tr("&Print..."), this, &cMainWindow::onFilePrint); -// m_lpFilePrintAction->setPriority(QAction::LowPriority); -// m_lpFilePrintAction->setShortcut(QKeySequence::Print); -// m_lpFileToolBar->addAction(m_lpFilePrintAction); - -// const QIcon filePrintIcon = QIcon::fromTheme("document-print"); -// m_lpFilePrintPreviewAction = m_lpFileMenu->addAction(filePrintIcon, tr("Print Preview..."), this, &cMainWindow::onFilePrintPreview); - -// const QIcon exportPdfIcon = QIcon::fromTheme("document-pdf"); -// m_lpFileExportPDFAction = m_lpFileMenu->addAction(exportPdfIcon, tr("&Export PDF..."), this, &cMainWindow::onFilePrintPdf); -// m_lpFileExportPDFAction->setPriority(QAction::LowPriority); -// m_lpFileExportPDFAction->setShortcut(Qt::CTRL + Qt::Key_D); -// m_lpFileToolBar->addAction(m_lpFileExportPDFAction); - -// m_lpFileMenu->addSeparator(); -//#endif - -// m_lpFilePropertiesAction = m_lpFileMenu->addAction(tr("P&roperties..."), this, &cMainWindow::onFileProperties); -// m_lpFilePropertiesAction->setPriority(QAction::LowPriority); -// m_lpFileMenu->addSeparator(); - for(int i = 0; i < MaxRecentFiles;i++) { m_lpRecentFileAction[i] = new QAction(this); @@ -242,6 +257,18 @@ void cMainWindow::onThumbnailSelected(const QItemSelection& /*selection*/, const lpToolBoxInfo->setPicture(lpPicture); } +void cMainWindow::onFolderSelected(const QItemSelection& /*selection*/, const QItemSelection& /*previous*/) +{ + if(m_bLoading) + return; + + QStandardItem* lpItem = m_lpFolderViewModel->itemFromIndex(ui->m_lpFolderView->currentIndex()); + if(!lpItem) + return; + + m_lpThumbnailFilterProxyModel->setFilterPath(lpItem->data(Qt::UserRole+2).toString()); +} + void cMainWindow::setCurrentFile(const QString& fileName) { QSettings settings; @@ -261,7 +288,7 @@ void cMainWindow::updateRecentFileActions() QSettings settings; QStringList files = settings.value("file/recentFiles").toStringList(); - int numRecentFiles = qMin(files.size(), (int)MaxRecentFiles); + int numRecentFiles = qMin(files.size(), static_cast(MaxRecentFiles)); for(int i = 0; i < numRecentFiles; i++) { @@ -320,6 +347,7 @@ void cMainWindow::openRecentFile() // updateWindowTitle(); } } + void cMainWindow::onFileNew() { // if(m_bSomethingChanged) diff --git a/cmainwindow.h b/cmainwindow.h index 93d45d9..d7aeca0 100644 --- a/cmainwindow.h +++ b/cmainwindow.h @@ -6,6 +6,8 @@ #include "csplashscreen.h" #include "cpicture.h" +#include "cthumbnailfilterproxymodel.h" + #include "ctoolboxinfo.h" #include @@ -24,6 +26,8 @@ namespace Ui { class cMainWindow; } +Q_DECLARE_METATYPE(QList*) + /** * @brief * @@ -49,7 +53,13 @@ public: private: Ui::cMainWindow* ui; /**< TODO: describe */ QProgressBar* m_lpProgressBar; /**< TODO: describe */ + QStandardItemModel* m_lpFolderViewModel; /**< TODO: describe */ QStandardItemModel* m_lpThumbnailViewModel; /**< TODO: describe */ + cThumbnailFilterProxyModel* m_lpThumbnailFilterProxyModel; /**< TODO: describe */ + QStandardItem* m_lpRootItem; /**< TODO: describe */ + + bool m_bLoading; /**< TODO: describe */ + cSplashScreen* m_lpSplashScreen; /*!< Splash Screen */ cPictureLibrary m_pictureLibrary; /**< TODO: describe */ cPictureList m_pictureList; /**< TODO: describe */ @@ -113,6 +123,15 @@ private: */ void loadData(bool bProgressBar = false); + /*! + \brief + + \param szPath + \param lpItem + \fn insertPath + */ + void insertPath(QString szPath); + protected: /*! \brief @@ -130,6 +149,13 @@ private slots: \fn onThumbnailSelected */ void onThumbnailSelected(const QItemSelection& selection, const QItemSelection& previous); + /*! + \brief + \param selection + \param previous + \fn onThumbnailSelected + */ + void onFolderSelected(const QItemSelection& selection, const QItemSelection& previous); /*! \brief diff --git a/cmainwindow.ui b/cmainwindow.ui index 42f7ec1..22fc0d0 100644 --- a/cmainwindow.ui +++ b/cmainwindow.ui @@ -39,6 +39,12 @@ 0 + + true + + + true + diff --git a/cpicture.cpp b/cpicture.cpp index fa70e9d..74b2e20 100644 --- a/cpicture.cpp +++ b/cpicture.cpp @@ -72,11 +72,6 @@ bool cPicture::fromFile(const QString& szFileName) m_focalLength35 = exif.focalLength35(); m_gps = exif.gps(); -// if(!m_dateTime.isValid()) -// { -// setDateTime(fileInfo.birthTime()); -// } - return(true); } @@ -466,7 +461,7 @@ bool cPictureList::load(cSplashScreen *lpSplashScreen, QProgressBar *lpProgressB " gps, " " thumbnail " "FROM picture " - "ORDER BY dateTime, " + "ORDER BY filePath, " " UPPER(fileName);"); if(!query.exec()) @@ -480,7 +475,7 @@ bool cPictureList::load(cSplashScreen *lpSplashScreen, QProgressBar *lpProgressB while(query.next()) { - cPicture* lpPicture = add(query.value("id").toInt()); + cPicture* lpPicture = add(query.value("id").toInt(), true); lpPicture->setFileName(query.value("fileName").toString()); lpPicture->setFilePath(query.value("filePath").toString()); lpPicture->setFileSize(query.value("fileSize").toLongLong()); @@ -521,9 +516,9 @@ bool cPictureList::load(cSplashScreen *lpSplashScreen, QProgressBar *lpProgressB return(true); } -cPicture* cPictureList::add(qint32 iID) +cPicture* cPictureList::add(qint32 iID, bool bNoCheck) { - if(iID != -1) + if(iID != -1 && !bNoCheck) { if(find(iID)) return(nullptr); diff --git a/cpicture.h b/cpicture.h index fc656f6..3904f87 100644 --- a/cpicture.h +++ b/cpicture.h @@ -436,7 +436,7 @@ public: * @param iID * @return cPicture */ - cPicture* add(qint32 iID = -1); + cPicture* add(qint32 iID = -1, bool bNoCheck = false); /** * @brief * diff --git a/cthumbnailfilterproxymodel.cpp b/cthumbnailfilterproxymodel.cpp new file mode 100644 index 0000000..27a0431 --- /dev/null +++ b/cthumbnailfilterproxymodel.cpp @@ -0,0 +1,24 @@ +#include "cthumbnailfilterproxymodel.h" + + +cThumbnailFilterProxyModel::cThumbnailFilterProxyModel(QObject* parent) : + QSortFilterProxyModel (parent) +{ +} + +void cThumbnailFilterProxyModel::setFilterPath(const QString &szPath) +{ + m_szPath = szPath; + invalidateFilter(); +} + +QString cThumbnailFilterProxyModel::filterPath() +{ + return(m_szPath); +} + +bool cThumbnailFilterProxyModel::filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const +{ + QModelIndex index0 = sourceModel()->index(sourceRow, 0, sourceParent); + return(sourceModel()->data(index0, Qt::UserRole+2).toString().contains(m_szPath)); +} diff --git a/cthumbnailfilterproxymodel.h b/cthumbnailfilterproxymodel.h new file mode 100644 index 0000000..8e944b2 --- /dev/null +++ b/cthumbnailfilterproxymodel.h @@ -0,0 +1,46 @@ +#ifndef CTHUMBNAILFILTERPROXYMODEL_H +#define CTHUMBNAILFILTERPROXYMODEL_H + + +#include + + +/** + * @brief + * + */ +class cThumbnailFilterProxyModel : public QSortFilterProxyModel +{ + Q_OBJECT + +public: + cThumbnailFilterProxyModel(QObject* parent = nullptr); + + /** + * @brief + * + * @return QString + */ + QString filterPath(); + /** + * @brief + * + * @param szPath + */ + void setFilterPath(const QString& szPath); + +protected: + /** + * @brief + * + * @param sourceRow + * @param sourceParent + * @return bool + */ + bool filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const override; + +private: + QString m_szPath; /**< TODO: describe */ +}; + +#endif // CTHUMBNAILFILTERPROXYMODEL_H diff --git a/pictureLibrary.pro b/pictureLibrary.pro index a582e38..139cbc2 100644 --- a/pictureLibrary.pro +++ b/pictureLibrary.pro @@ -63,7 +63,8 @@ SOURCES += \ cimage.cpp \ ctoolboxinfo.cpp \ cimportdialog.cpp \ - cdatetimepicker.cpp + cdatetimepicker.cpp \ + cthumbnailfilterproxymodel.cpp HEADERS += \ cmainwindow.h \ @@ -75,7 +76,8 @@ HEADERS += \ cimage.h \ ctoolboxinfo.h \ cimportdialog.h \ - cdatetimepicker.h + cdatetimepicker.h \ + cthumbnailfilterproxymodel.h FORMS += \ cmainwindow.ui \