RecentFiles.h 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. /*
  2. * Copyright (c) Contributors to the Open 3D Engine Project.
  3. * For complete copyright and license terms please see the LICENSE at the root of this distribution.
  4. *
  5. * SPDX-License-Identifier: Apache-2.0 OR MIT
  6. *
  7. */
  8. #pragma once
  9. #if !defined(Q_MOC_RUN)
  10. #include "MysticQtConfig.h"
  11. #include <MCore/Source/StandardHeaders.h>
  12. #include <AzCore/std/containers/vector.h>
  13. #include <QMenu>
  14. #include <QObject>
  15. #endif
  16. namespace MysticQt
  17. {
  18. class MYSTICQT_API RecentFiles
  19. : public QObject
  20. {
  21. Q_OBJECT
  22. MCORE_MEMORYOBJECTCATEGORY(RecentFiles, MCore::MCORE_DEFAULT_ALIGNMENT, MEMCATEGORY_MYSTICQT)
  23. public:
  24. RecentFiles();
  25. ~RecentFiles() = default;
  26. void Init(QMenu* parentMenu, size_t numRecentFiles, const char* subMenuName, const char* configStringName);
  27. void SetMaxRecentFiles(size_t numRecentFiles);
  28. void AddRecentFile(AZStd::string filename);
  29. AZStd::string GetLastRecentFileName() const;
  30. signals:
  31. void OnRecentFile(QAction* action);
  32. private slots:
  33. void OnClearRecentFiles();
  34. void OnRecentFileSlot();
  35. private:
  36. void UpdateMenu();
  37. void RemoveDuplicates();
  38. void Save();
  39. void Load();
  40. QStringList m_recentFiles;
  41. size_t m_maxNumRecentFiles;
  42. QMenu* m_recentFilesMenu;
  43. QAction* m_resetRecentFilesAction;
  44. QString m_configStringName;
  45. };
  46. } // namespace MysticQt