12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182 |
- #include "CFilePathFinder.h"
- #include <QDir>
- void CFilePathFinder::FindImagePaths(QString ImagePath)
- {
- m_ListFilePath.clear();
- QDir dir(ImagePath);
- if (!dir.exists())
- {
- return;
- }
- QStringList ImageList;
- ImageList << "*.bmp" << "*.jpg" << "*.png" << "*.jpeg";//向字符串列表添加图片类型
- dir.setNameFilters(ImageList);//获得文件夹下图片的名字
- int ImageCount = dir.count();//获得dir里名字的个数,也表示文件夹下图片的个数
- for (int i = 0; i < ImageCount; i++)
- {
- QString ImageName = ImagePath + "//"+dir[i];
- m_ListFilePath.append(ImageName);
- }
- }
- CFilePathFinder::CFilePathFinder()
- {
- m_eFileFrom = E_FileFrom::e_filePath;
- m_nListIndex = 0;
- }
- CFilePathFinder::~CFilePathFinder()
- {
- }
- void CFilePathFinder::SetFilePath(E_FileFrom filefrom, QString path)
- {
- m_eFileFrom = filefrom;
- switch (filefrom)
- {
- case e_filePath:
- m_strFileFolderPath = path;
- m_ListFilePath.clear();
- m_ListFilePath.push_back(path);
- break;
- case e_fileFolder:
- m_nListIndex = 0;
- m_strFileFolderPath = path;
- FindImagePaths(path);
- break;
- default:
- break;
- }
- }
- QString CFilePathFinder::GetOneFilePath()
- {
- switch (m_eFileFrom)
- {
- case e_filePath:
- return m_strFileFolderPath;
- break;
- case e_fileFolder:
- m_nListIndex++;
- if (m_ListFilePath.size() <= 0)
- {
- return QString();
- }
- return m_ListFilePath[(m_nListIndex-1)% m_ListFilePath.size()];
- break;
- default:
- break;
- }
- return QString();
- }
- QList<QString> CFilePathFinder::GetAllPath()
- {
- return m_ListFilePath;
- }
|