Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: 添加照片分类视图页 #192

Merged
merged 1 commit into from
Dec 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions src/album/albumgloabl.h
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,32 @@ struct DBImgInfo {
typedef QList<DBImgInfo> DBImgInfoList;
typedef QList<DBImgInfo*> DBImgInfoListPtr;

#define CLASS_PLANT "Plants"
#define CLASS_Scenery "Scenery"
#define CLASS_FOOD "Food"
#define CLASS_SCENE "Scene"
#define CLASS_ANIMALS "Animals"
#define CLASS_HUMANS "Humans"
#define CLASS_ITEMS "Items"
#define CLASS_OTHER "Other"

const QStringList g_classList = {
CLASS_Scenery,
CLASS_FOOD,
CLASS_HUMANS,
CLASS_ANIMALS,
CLASS_SCENE,
CLASS_PLANT,
CLASS_ITEMS,
CLASS_OTHER};

struct ClassifyDBImgInfo {
QString className;
QList<DBImgInfo> infos;
};

typedef QList<ClassifyDBImgInfo> ClassifyDBImgInfoList;

enum OpenImgViewType {
VIEW_MAINWINDOW_ALLPIC = 0,
VIEW_MAINWINDOW_TIMELINE = 1,
Expand Down
181 changes: 150 additions & 31 deletions src/album/albumview/albumview.cpp

Large diffs are not rendered by default.

9 changes: 8 additions & 1 deletion src/album/albumview/albumview.h
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ class AlbumView : public QWidget, public ImageEngineImportObject, public ImageMo
void updateRightImportView();
void updateRightMyFavoriteView();
void updateRightClassView();
void updateRightClassViewDetail(const QString &className);
void updateRightMountView();
//打开图片
void onOpenImageClass(int row, const QString &path, bool bFullScreen);
Expand Down Expand Up @@ -206,11 +207,14 @@ private slots:
void onMonitorDestroyed(int UID);
//筛选条件按钮宽度变化响应槽
void onFilterBtnWidthChanged(int width);

void slotClassBackClicked();
public:
int m_iAlubmPicsNum;
QString m_currentAlbum;
int m_currentUID;
QString m_currentType;
QString m_currentClassName;
AblumType m_currentItemType = photosType;
int m_selPicNum;
bool m_itemClicked;
Expand All @@ -226,7 +230,8 @@ private slots:

ThumbnailListView *m_customThumbnailList = nullptr; //自定义
ThumbnailListView *m_pRightTrashThumbnailList = nullptr; //最近删除
ThumbnailListView *m_classThumbnailList = nullptr; //图片分类
ThumbnailListView *m_classThumbnailList = nullptr; //图片分类封面页
ThumbnailListView *m_classDetailThumbnailList = nullptr; //图片分类详情页
ThumbnailListView *m_favoriteThumbnailList = nullptr; //我的收藏

DWidget *pImportTimeLineWidget;
Expand All @@ -253,9 +258,11 @@ private slots:
DWidget *m_ClassTitleWidget = nullptr;
DLabel *m_pClassTitle = nullptr;
DLabel *m_pClassPicTotal = nullptr;
DPushButton *m_pClassBackBtn = nullptr;
BatchOperateWidget *m_classBatchOperateWidget = nullptr;
NoResultWidget *m_classNoResultWidget = nullptr;
QString m_ClassPicTotalFullStr;
bool m_bHasClassified = false;
//我的收藏标题栏
DWidget *m_pFavoriteWidget = nullptr;
DWidget *m_FavoriteTitleWidget = nullptr;
Expand Down
4 changes: 3 additions & 1 deletion src/album/controller/signalmanager.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,14 +74,16 @@ class SignalManager : public QObject

// 图片分类已完成信号
void sigImageClassifyDone();
// 打开分类详情页
void sigOpenClassDetail(const QString &className);

// Handle by album
void createAlbum(QStringList imgPath = QStringList());
void viewCreateAlbum(QString path, bool bmodel = true);
void sigCreateNewAlbumFrom(const QString &albumname, int UID);
void insertedIntoAlbum(int UID, const QStringList &paths);
void removedFromAlbum(int UID, const QStringList &paths);
void sigSendKeywordsIntoALLPic(QString keywords, QString album = nullptr, int UID = -1);
void sigSendKeywordsIntoALLPic(QString keywords, QString album = nullptr, int UID = -1, const QString& className = "");
void sigCreateNewAlbumFromDialog(const QString &albumname, int UID);
void sigMainwindowSliderValueChg(int value);
// void sigESCKeyActivated();
Expand Down
60 changes: 60 additions & 0 deletions src/album/dbmanager/dbmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,66 @@ void DBManager::removeImgInfosNoSignal(const QStringList &paths)
}
}

const DBImgInfoList DBManager::getInfosForClass(const QString &className) const
{
QMutexLocker mutex(&m_dbMutex);
DBImgInfoList infos;
m_query->setForwardOnly(true);

//切换到UID后,纯关键字搜索应该不受影响
QString queryStr = "SELECT FilePath, FileName, Dir, Time, ChangeTime, ImportTime, FileType, ClassName, PathHash FROM ImageTable3 "
"WHERE ClassName='" + className + "' ORDER BY Time DESC";

bool b = m_query->prepare(queryStr);

if (!b || !m_query->exec()) {
} else {
using namespace utils::base;
while (m_query->next()) {
DBImgInfo info;
info.filePath = m_query->value(0).toString();
info.time = m_query->value(3).toDateTime();
info.changeTime = m_query->value(4).toDateTime();
info.importTime = m_query->value(5).toDateTime();
info.itemType = ItemType(m_query->value(6).toInt());
info.className = m_query->value(7).toString();
info.pathHash = m_query->value(8).toString();
infos << info;
}
}
return infos;
}

const DBImgInfoList DBManager::getInfosForClassAndKeyword(const QString &className, const QString &keywords) const
{
QMutexLocker mutex(&m_dbMutex);
DBImgInfoList infos;
m_query->setForwardOnly(true);

//切换到UID后,纯关键字搜索应该不受影响
QString queryStr = "SELECT FilePath, FileName, Dir, Time, ChangeTime, ImportTime, FileType, ClassName, PathHash FROM ImageTable3 "
"WHERE ClassName='" + className + "' AND FileName like '%" + keywords + "%' ORDER BY Time DESC";

bool b = m_query->prepare(queryStr);

if (!b || !m_query->exec()) {
} else {
using namespace utils::base;
while (m_query->next()) {
DBImgInfo info;
info.filePath = m_query->value(0).toString();
info.time = m_query->value(3).toDateTime();
info.changeTime = m_query->value(4).toDateTime();
info.importTime = m_query->value(5).toDateTime();
info.itemType = ItemType(m_query->value(6).toInt());
info.className = m_query->value(7).toString();
info.pathHash = m_query->value(8).toString();
infos << info;
}
}
return infos;
}

const QList<std::pair<int, QString>> DBManager::getAllAlbumNames(AlbumDBType atype) const
{
QMutexLocker mutex(&m_dbMutex);
Expand Down
2 changes: 2 additions & 0 deletions src/album/dbmanager/dbmanager.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ class DBManager : public QObject
void insertImgInfo(const DBImgInfo &info);
void removeImgInfos(const QStringList &paths);
void removeImgInfosNoSignal(const QStringList &paths);
const DBImgInfoList getInfosForClass(const QString &className) const;
const DBImgInfoList getInfosForClassAndKeyword(const QString &className, const QString &keywords) const;
const DBImgInfoList getInfosForKeyword(const QString &keywords) const;
const DBImgInfoList getTrashInfosForKeyword(const QString &keywords) const;
const DBImgInfoList getInfosForKeyword(int UID, const QString &keywords) const;
Expand Down
9 changes: 5 additions & 4 deletions src/album/imageengine/imageenginethread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,11 @@ DBImgInfo getDBInfo(const QString &srcpath, bool isVideo)
QString value = mds.value("DateTimeOriginal");
dbi.itemType = ItemTypePic;
if (Classifyutils::GetInstance()->isDBusExist()) {
if (srcfi.exists() && utils::base::isSupportClassify(srcpath))
if (srcfi.exists() && utils::base::isSupportClassify(srcpath) && srcfi.isReadable())
dbi.className = Classifyutils::GetInstance()->imageClassify(srcpath.toStdString().c_str());
else
dbi.className = "";
if (dbi.className.isEmpty())
if (dbi.className.isEmpty() && srcfi.isReadable())
dbi.className = "Other";
}
dbi.changeTime = QDateTime::fromString(mds.value("DateTimeDigitized"), "yyyy/MM/dd hh:mm");
Expand Down Expand Up @@ -718,12 +718,13 @@ void ImagesClassifyThread::runDetail()
for (auto &info : m_infos) {
if (info.className.isEmpty()) {
QFileInfo srcfi(info.filePath);
if (srcfi.exists() && utils::base::isSupportClassify(info.filePath))
if (srcfi.exists() && utils::base::isSupportClassify(info.filePath) && srcfi.isReadable())
info.className = Classifyutils::GetInstance()->imageClassify(info.filePath.toStdString().c_str());
else
info.className = "";
if (info.className.isEmpty())
if (info.className.isEmpty() && srcfi.isReadable())
info.className = "Other";

emit dApp->signalM->progressOfWaitDialog(infoCount, i++);
}
}
Expand Down
12 changes: 8 additions & 4 deletions src/album/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1266,17 +1266,21 @@ void MainWindow::onSearchEditFinished()
albumBtnClicked();
// donothing
} else {
if (COMMON_STR_CLASS == m_pAlbumview->m_currentAlbum)
return;

if (COMMON_STR_RECENT_IMPORTED == m_pAlbumview->m_pLeftListView->getItemCurrentType()) {
emit dApp->signalM->sigSendKeywordsIntoALLPic(keywords, COMMON_STR_RECENT_IMPORTED);
}
//LMH0514,为了解决26092 【相册】【5.6.9.14】在我的收藏相册下无法搜索到收藏的照片,加入我的收藏枚举
else if (COMMON_STR_FAVORITES == m_pAlbumview->m_pLeftListView->getItemCurrentType()) {
} else if (COMMON_STR_CLASSDETAIL == m_pAlbumview->m_currentAlbum) {
emit dApp->signalM->sigSendKeywordsIntoALLPic(keywords, COMMON_STR_CLASSDETAIL, -1, m_pAlbumview->m_currentClassName);
} else if (COMMON_STR_FAVORITES == m_pAlbumview->m_pLeftListView->getItemCurrentType()) {
//LMH0514,为了解决26092 【相册】【5.6.9.14】在我的收藏相册下无法搜索到收藏的照片,加入我的收藏枚举
emit dApp->signalM->sigSendKeywordsIntoALLPic(keywords, COMMON_STR_FAVORITES, DBManager::SpUID::u_Favorite);
} else if (COMMON_STR_CUSTOM == m_pAlbumview->m_pLeftListView->getItemCurrentType()) {
emit dApp->signalM->sigSendKeywordsIntoALLPic(keywords, m_pAlbumview->m_pLeftListView->getItemCurrentName(), m_pAlbumview->m_pLeftListView->getItemCurrentUID());
}

m_pAlbumview->m_pRightStackWidget->setCurrentIndex(4);
m_pAlbumview->m_pRightStackWidget->setCurrentIndex(5);
m_pAlbumview->restorePicNum();
}
}
Expand Down
7 changes: 5 additions & 2 deletions src/album/searchview/searchview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -165,18 +165,21 @@
layout->addWidget(m_stackWidget);
}

void SearchView::improtSearchResultsIntoThumbnailView(QString s, const QString &album, int UID)
void SearchView::improtSearchResultsIntoThumbnailView(QString s, const QString &album, int UID, const QString& className)
{
m_albumName = album;
m_UID = UID;
using namespace utils::image;
m_keywords = s;
m_className = className;
QList<DBImgInfo> thumbnaiItemList;

Check warning on line 175 in src/album/searchview/searchview.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Unused variable: thumbnaiItemList
DBImgInfoList infos;
if (COMMON_STR_ALLPHOTOS == m_albumName
|| COMMON_STR_TIMELINE == m_albumName
|| COMMON_STR_RECENT_IMPORTED == m_albumName) {
infos = DBManager::instance()->getInfosForKeyword(s);
} else if (COMMON_STR_CLASSDETAIL == m_albumName) {
infos = DBManager::instance()->getInfosForClassAndKeyword(className, s);
} else if (COMMON_STR_TRASH == m_albumName) {
infos = DBManager::instance()->getTrashInfosForKeyword(s);
} else {
Expand Down Expand Up @@ -318,7 +321,7 @@

void SearchView::updateSearchResultsIntoThumbnailView()
{
improtSearchResultsIntoThumbnailView(m_keywords, m_albumName, m_UID);
improtSearchResultsIntoThumbnailView(m_keywords, m_albumName, m_UID, m_className);
}

void SearchView::changeTheme()
Expand Down
3 changes: 2 additions & 1 deletion src/album/searchview/searchview.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class SearchView : public QWidget

public:
SearchView();
void improtSearchResultsIntoThumbnailView(QString s, const QString &album, int UID);
void improtSearchResultsIntoThumbnailView(QString s, const QString &album, int UID, const QString& className);

public slots:
void onSlideShowBtnClicked();
Expand Down Expand Up @@ -75,6 +75,7 @@ public slots:
DLabel *pLabel1;
QString m_albumName;
int m_UID;
QString m_className;
int m_currentFontSize;
public:
int m_searchPicNum;
Expand Down
Loading
Loading