folder view sorting

This commit is contained in:
2019-02-20 17:43:25 +01:00
parent 8e858d9376
commit 49d098c2d7
11 changed files with 137 additions and 69 deletions
+20
View File
@@ -0,0 +1,20 @@
/*!
\file cfoldersortfilterproxymodel.cpp
*/
#include "cfoldersortfilterproxymodel.h"
cFolderSortFilterProxyModel::cFolderSortFilterProxyModel(QObject* parent) :
QSortFilterProxyModel (parent)
{
}
bool cFolderSortFilterProxyModel::lessThan(const QModelIndex &left, const QModelIndex &right) const
{
QVariant leftData = sourceModel()->data(left);
QVariant rightData = sourceModel()->data(right);
return(leftData.toString() < rightData.toString());
}
+29
View File
@@ -0,0 +1,29 @@
/*!
\file cfoldersortfilterproxymodel.h
*/
#ifndef CFOLDERSORTFILTERPROXYMODEL_H
#define CFOLDERSORTFILTERPROXYMODEL_H
#include <QSortFilterProxyModel>
/*!
\brief
\class cFolderSortFilterProxyModel cfoldersortfilterproxymodel.h "cfoldersortfilterproxymodel.h"
*/
class cFolderSortFilterProxyModel : public QSortFilterProxyModel
{
Q_OBJECT
public:
cFolderSortFilterProxyModel(QObject* parent = nullptr);
protected:
bool lessThan(const QModelIndex &left, const QModelIndex &right) const override;
};
#endif // CFOLDERSORTFILTERPROXYMODEL_H
+1 -1
View File
@@ -62,7 +62,7 @@ void cImportDialog::initUI()
ui->m_lpFolderView->setModel(m_lpFolderViewModel);
m_lpThumbnailViewModel = new QStandardItemModel;
m_lpThumbnailFilterProxyModel = new cThumbnailFilterProxyModel(this);
m_lpThumbnailFilterProxyModel = new cThumbnailSortFilterProxyModel(this);
ui->m_lpThumbnailView->setModel(m_lpThumbnailFilterProxyModel);
m_lpThumbnailFilterProxyModel->setSourceModel(m_lpThumbnailViewModel);
+2 -2
View File
@@ -12,7 +12,7 @@
#include <QCloseEvent>
#include <QItemSelection>
#include "cthumbnailfilterproxymodel.h"
#include "cthumbnailsortfilterproxymodel.h"
namespace Ui {
@@ -93,7 +93,7 @@ private:
QString m_szRootPath; /*!< TODO: describe */
QStandardItemModel* m_lpFolderViewModel; /*!< TODO: describe */
QStandardItemModel* m_lpThumbnailViewModel; /*!< TODO: describe */
cThumbnailFilterProxyModel* m_lpThumbnailFilterProxyModel; /*!< TODO: describe */
cThumbnailSortFilterProxyModel* m_lpThumbnailFilterProxyModel; /*!< TODO: describe */
bool m_bLoading; /*!< TODO: describe */
bool m_bHasImported; /*!< TODO: describe */
QStandardItem* m_lpRootItem; /*!< TODO: describe */
+22 -12
View File
@@ -30,8 +30,9 @@ cMainWindow::cMainWindow(cSplashScreen* lpSplashScreen, QWidget *parent) :
ui(new Ui::cMainWindow),
m_lpProgressBar(nullptr),
m_lpFolderViewModel(nullptr),
m_lpFolderSortFilterProxyModel(nullptr),
m_lpThumbnailViewModel(nullptr),
m_lpThumbnailFilterProxyModel(nullptr),
m_lpThumbnailSortFilterProxyModel(nullptr),
m_lpRootItem(nullptr),
m_bLoading(false),
m_lpSplashScreen(lpSplashScreen),
@@ -50,7 +51,8 @@ cMainWindow::~cMainWindow()
{
delete m_lpThumbnailViewModel;
delete m_lpFolderViewModel;
delete m_lpThumbnailFilterProxyModel;
delete m_lpThumbnailSortFilterProxyModel;
delete m_lpFolderSortFilterProxyModel;
delete ui;
}
@@ -60,12 +62,14 @@ void cMainWindow::initUI()
ui->setupUi(this);
m_lpFolderViewModel = new QStandardItemModel;
ui->m_lpFolderView->setModel(m_lpFolderViewModel);
m_lpFolderSortFilterProxyModel = new cFolderSortFilterProxyModel(this);
ui->m_lpFolderView->setModel(m_lpFolderSortFilterProxyModel);
m_lpFolderSortFilterProxyModel->setSourceModel(m_lpFolderViewModel);
m_lpThumbnailViewModel = new QStandardItemModel;
m_lpThumbnailFilterProxyModel = new cThumbnailFilterProxyModel(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);
m_lpProgressBar = new QProgressBar(this);
m_lpProgressBar->setVisible(false);
@@ -232,7 +236,7 @@ void cMainWindow::onThumbnailSelected(const QItemSelection& /*selection*/, const
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);
}
}
@@ -242,11 +246,11 @@ void cMainWindow::onFolderSelected(const QItemSelection& /*selection*/, const QI
if(m_bLoading)
return;
QStandardItem* lpItem = m_lpFolderViewModel->itemFromIndex(ui->m_lpFolderView->currentIndex());
if(!lpItem)
QModelIndex index = ui->m_lpFolderView->selectionModel()->selectedIndexes()[0];
if(!index.isValid())
return;
m_lpThumbnailFilterProxyModel->setFilterPath(lpItem->data(Qt::UserRole+2).toString());
m_lpThumbnailSortFilterProxyModel->setFilterPath(m_lpFolderSortFilterProxyModel->data(index, Qt::UserRole+2).toString());
}
void cMainWindow::setCurrentFile(const QString& fileName)
@@ -439,7 +443,7 @@ void cMainWindow::onChangeDate()
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*>();
if(lpPicture->dateTime().isValid())
{
@@ -453,7 +457,13 @@ void cMainWindow::onChangeDate()
return;
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);
m_lpThumbnailFilterProxyModel->submit();
insertPath(szPath, m_lpRootItem);
m_lpFolderSortFilterProxyModel->sort(0);
m_lpThumbnailSortFilterProxyModel->invalidate();
}
}
+39 -37
View File
@@ -11,7 +11,8 @@
#include "csplashscreen.h"
#include "cpicture.h"
#include "cthumbnailfilterproxymodel.h"
#include "cfoldersortfilterproxymodel.h"
#include "cthumbnailsortfilterproxymodel.h"
#include "ctoolboxinfo.h"
@@ -59,43 +60,44 @@ public:
~cMainWindow();
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 */
Ui::cMainWindow* ui; /*!< TODO: describe */
QProgressBar* m_lpProgressBar; /*!< TODO: describe */
QStandardItemModel* m_lpFolderViewModel; /*!< TODO: describe */
cFolderSortFilterProxyModel* m_lpFolderSortFilterProxyModel; /*!< TODO: describe */
QStandardItemModel* m_lpThumbnailViewModel; /*!< TODO: describe */
cThumbnailSortFilterProxyModel* m_lpThumbnailSortFilterProxyModel; /*!< TODO: describe */
QStandardItem* m_lpRootItem; /*!< TODO: describe */
bool m_bLoading; /*!< TODO: describe */
bool m_bLoading; /*!< TODO: describe */
cSplashScreen* m_lpSplashScreen; /*!< TODO: describe */
cPictureLibrary m_pictureLibrary; /*!< TODO: describe */
cPictureList m_pictureList; /*!< TODO: describe */
cSplashScreen* m_lpSplashScreen; /*!< TODO: describe */
cPictureLibrary m_pictureLibrary; /*!< TODO: describe */
cPictureList m_pictureList; /*!< TODO: describe */
QMenu* m_lpFileMenu; /*!< TODO: describe */
QMenu* m_lpFileMenu; /*!< TODO: describe */
QToolBar* m_lpFileToolBar; /*!< TODO: describe */
QToolBar* m_lpFileToolBar; /*!< TODO: describe */
QAction* m_lpFileNewAction; /*!< TODO: describe */
QAction* m_lpFileOpenAction; /*!< TODO: describe */
QAction* m_lpFileImportAction; /*!< TODO: describe */
QAction* m_lpFileQuitAction; /*!< TODO: describe */
QAction* m_lpFileNewAction; /*!< TODO: describe */
QAction* m_lpFileOpenAction; /*!< TODO: describe */
QAction* m_lpFileImportAction; /*!< TODO: describe */
QAction* m_lpFileQuitAction; /*!< TODO: describe */
QAction* m_lpSeparatorRecent; /*!< TODO: describe */
enum { MaxRecentFiles = 5 }; /*!< TODO: describe */
QAction* m_lpRecentFileAction[MaxRecentFiles]; /*!< TODO: describe */
QAction* m_lpSeparatorRecent; /*!< TODO: describe */
enum { MaxRecentFiles = 5 }; /*!< TODO: describe */
QAction* m_lpRecentFileAction[MaxRecentFiles]; /*!< TODO: describe */
QAction* m_lpChangeDateAction; /*!< TODO: describe */
QAction* m_lpChangeDateAction; /*!< TODO: describe */
/*!
\brief
\fn initUI
*/
void initUI();
void createActions(); /*!< TODO: describe */
void createFileActions();
void createContextActions();
void initUI();
void createActions(); /*!< TODO: describe */
void createFileActions();
void createContextActions();
/*!
\brief
@@ -103,19 +105,19 @@ private:
\fn setCurrentFile
\param szFileName
*/
void setCurrentFile(const QString& szFileName);
void setCurrentFile(const QString& szFileName);
/*!
\brief
\fn updateRecentFileActions
*/
void updateRecentFileActions();
void updateRecentFileActions();
/*!
\brief
\fn openRecentFile
*/
void openRecentFile();
void openRecentFile();
/*!
\brief
@@ -123,7 +125,7 @@ private:
\fn loadData
\param bProgressBar
*/
void loadData(bool bProgressBar = false);
void loadData(bool bProgressBar = false);
protected:
/*!
@@ -132,7 +134,7 @@ protected:
\fn closeEvent
\param event
*/
void closeEvent(QCloseEvent* event);
void closeEvent(QCloseEvent* event);
private slots:
/*!
@@ -142,7 +144,7 @@ private slots:
\param selection
\param previous
*/
void onThumbnailSelected(const QItemSelection& selection, const QItemSelection& previous);
void onThumbnailSelected(const QItemSelection& selection, const QItemSelection& previous);
/*!
\brief
@@ -150,25 +152,25 @@ private slots:
\param selection
\param previous
*/
void onFolderSelected(const QItemSelection& selection, const QItemSelection& previous);
void onFolderSelected(const QItemSelection& selection, const QItemSelection& previous);
/*!
\brief
\fn onFileNew
*/
void onFileNew();
void onFileNew();
/*!
\brief
\fn onFileOpen
*/
void onFileOpen();
void onFileOpen();
/*!
\brief
\fn onFileImport
*/
void onFileImport();
void onFileImport();
/*!
\brief
@@ -176,14 +178,14 @@ private slots:
\fn onThumbnailViewContextMenu
\param pos
*/
void onThumbnailViewContextMenu(const QPoint& pos);
void onThumbnailViewContextMenu(const QPoint& pos);
/*!
\brief
\fn onChangeDate
*/
void onChangeDate();
void onChangeDate();
};
#endif // CMAINWINDOW_H
+10 -7
View File
@@ -38,16 +38,16 @@ QByteArray image2Blob(const QImage &image)
return(ba);
}
void insertPath(QString szPath, QStandardItem* lpRootItem)
QStandardItem* insertPath(QString szPath, QStandardItem* lpRootItem)
{
if(!lpRootItem)
return;
return(0);
QString szPath1 = szPath.replace("\\", "/");
QStringList szPathList = szPath1.split("/");
QStandardItem* lpCurRoot = lpRootItem;
int path;
bool bFound;
QString szPath1 = szPath.replace("\\", "/");
QStringList szPathList = szPath1.split("/");
QStandardItem* lpCurRoot = lpRootItem;
int path;
bool bFound;
szPath1 = "";
@@ -79,6 +79,9 @@ void insertPath(QString szPath, QStandardItem* lpRootItem)
lpCurRoot->appendRow(lpNewItem);
lpNewItem->setData(QVariant::fromValue(szPath1), Qt::UserRole+2);
szPath1.append(QDir::separator());
lpCurRoot = lpNewItem;
}
return(lpCurRoot);
}
+3 -1
View File
@@ -10,6 +10,7 @@
#include <QImage>
#include <QByteArray>
#include <QStandardItem>
#include <QTreeView>
#include <QDebug>
@@ -49,8 +50,9 @@ QByteArray image2Blob(const QImage& image);
\fn insertPath
\param szPath
\param lpRootItem
\return QStandardItem
*/
void insertPath(QString szPath, QStandardItem* lpRootItem);
QStandardItem* insertPath(QString szPath, QStandardItem* lpRootItem);
#endif // COMMON_H
@@ -3,15 +3,15 @@
*/
#include "cthumbnailfilterproxymodel.h"
#include "cthumbnailsortfilterproxymodel.h"
cThumbnailFilterProxyModel::cThumbnailFilterProxyModel(QObject* parent) :
cThumbnailSortFilterProxyModel::cThumbnailSortFilterProxyModel(QObject* parent) :
QSortFilterProxyModel (parent)
{
}
void cThumbnailFilterProxyModel::setFilterPath(const QString &szPath)
void cThumbnailSortFilterProxyModel::setFilterPath(const QString &szPath)
{
m_szPath = szPath;
m_szPath.replace("\\", "/");
@@ -19,12 +19,12 @@ void cThumbnailFilterProxyModel::setFilterPath(const QString &szPath)
invalidateFilter();
}
QString cThumbnailFilterProxyModel::filterPath()
QString cThumbnailSortFilterProxyModel::filterPath()
{
return(m_szPath);
}
bool cThumbnailFilterProxyModel::filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const
bool cThumbnailSortFilterProxyModel::filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const
{
QModelIndex index0 = sourceModel()->index(sourceRow, 0, sourceParent);
QString tmp = sourceModel()->data(index0, Qt::UserRole+2).toString();
@@ -15,12 +15,12 @@
\class cThumbnailFilterProxyModel cthumbnailfilterproxymodel.h "cthumbnailfilterproxymodel.h"
*/
class cThumbnailFilterProxyModel : public QSortFilterProxyModel
class cThumbnailSortFilterProxyModel : public QSortFilterProxyModel
{
Q_OBJECT
public:
cThumbnailFilterProxyModel(QObject* parent = nullptr);
cThumbnailSortFilterProxyModel(QObject* parent = nullptr);
/*!
\brief
+4 -2
View File
@@ -64,7 +64,8 @@ SOURCES += \
ctoolboxinfo.cpp \
cimportdialog.cpp \
cdatetimepicker.cpp \
cthumbnailfilterproxymodel.cpp
cthumbnailsortfilterproxymodel.cpp \
cfoldersortfilterproxymodel.cpp
HEADERS += \
cmainwindow.h \
@@ -77,7 +78,8 @@ HEADERS += \
ctoolboxinfo.h \
cimportdialog.h \
cdatetimepicker.h \
cthumbnailfilterproxymodel.h
cthumbnailsortfilterproxymodel.h \
cfoldersortfilterproxymodel.h
FORMS += \
cmainwindow.ui \