CFilePathFinder.cpp 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. #include "CFilePathFinder.h"
  2. #include <QDir>
  3. void CFilePathFinder::FindImagePaths(QString ImagePath)
  4. {
  5. m_ListFilePath.clear();
  6. QDir dir(ImagePath);
  7. if (!dir.exists())
  8. {
  9. return;
  10. }
  11. QStringList ImageList;
  12. ImageList << "*.bmp" << "*.jpg" << "*.png" << "*.jpeg";//向字符串列表添加图片类型
  13. dir.setNameFilters(ImageList);//获得文件夹下图片的名字
  14. int ImageCount = dir.count();//获得dir里名字的个数,也表示文件夹下图片的个数
  15. for (int i = 0; i < ImageCount; i++)
  16. {
  17. QString ImageName = ImagePath + "//"+dir[i];
  18. m_ListFilePath.append(ImageName);
  19. }
  20. }
  21. CFilePathFinder::CFilePathFinder()
  22. {
  23. m_eFileFrom = E_FileFrom::e_filePath;
  24. m_nListIndex = 0;
  25. }
  26. CFilePathFinder::~CFilePathFinder()
  27. {
  28. }
  29. void CFilePathFinder::SetFilePath(E_FileFrom filefrom, QString path)
  30. {
  31. m_eFileFrom = filefrom;
  32. switch (filefrom)
  33. {
  34. case e_filePath:
  35. m_strFileFolderPath = path;
  36. m_ListFilePath.clear();
  37. m_ListFilePath.push_back(path);
  38. break;
  39. case e_fileFolder:
  40. m_nListIndex = 0;
  41. m_strFileFolderPath = path;
  42. FindImagePaths(path);
  43. break;
  44. default:
  45. break;
  46. }
  47. }
  48. QString CFilePathFinder::GetOneFilePath()
  49. {
  50. switch (m_eFileFrom)
  51. {
  52. case e_filePath:
  53. return m_strFileFolderPath;
  54. break;
  55. case e_fileFolder:
  56. m_nListIndex++;
  57. if (m_ListFilePath.size() <= 0)
  58. {
  59. return QString();
  60. }
  61. return m_ListFilePath[(m_nListIndex-1)% m_ListFilePath.size()];
  62. break;
  63. default:
  64. break;
  65. }
  66. return QString();
  67. }
  68. QList<QString> CFilePathFinder::GetAllPath()
  69. {
  70. return m_ListFilePath;
  71. }