PathValidator.h 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  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 <QValidator>
  11. #endif
  12. QT_FORWARD_DECLARE_CLASS(QWidget)
  13. namespace O3DE::ProjectManager
  14. {
  15. class PathValidator
  16. : public QValidator
  17. {
  18. public:
  19. enum class PathMode {
  20. ExistingFile, //!< A single, existings file. Useful for "Open file"
  21. ExistingFolder, //!< A single, existing directory. Useful for "Open Folder"
  22. AnyFile //!< A single, valid file, doesn't have to exist but the directory must. Useful for "Save File"
  23. };
  24. explicit PathValidator(PathMode pathMode, QWidget* parent = nullptr);
  25. ~PathValidator() = default;
  26. void setAllowEmpty(bool allowEmpty);
  27. void setPathMode(PathMode pathMode);
  28. QValidator::State validate(QString &text, int &) const override;
  29. private:
  30. PathMode m_pathMode = PathMode::AnyFile;
  31. bool m_allowEmpty = false;
  32. };
  33. } // namespace O3DE::ProjectManager