LineEditValidatable.h 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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 <AzCore/Memory/Memory.h>
  11. #include <AzCore/std/functional.h>
  12. #include <QLineEdit>
  13. #include <QRegExpValidator>
  14. #endif
  15. namespace EMStudio
  16. {
  17. class LineEditValidatable
  18. : public QLineEdit
  19. {
  20. Q_OBJECT //AUTOMOC
  21. public:
  22. AZ_CLASS_ALLOCATOR_DECL
  23. explicit LineEditValidatable(QWidget* parent, const QRegExp& regExp = s_defaultRegExp);
  24. ~LineEditValidatable() override = default;
  25. void SetPreviousText(const QString& previousText);
  26. QString GetPreviousText() const;
  27. void SetValidatorFunc(const AZStd::function<bool()>& func) { m_validatorFunc = func; }
  28. bool IsValid() const;
  29. static const QRegExp s_defaultRegExp;
  30. signals:
  31. void TextEditingFinished();
  32. void TextChanged();
  33. public slots:
  34. void OnTextChanged();
  35. void OnEditingFinished();
  36. private:
  37. void focusInEvent(QFocusEvent* event) override;
  38. QString m_previousText;
  39. QRegExp m_validationExp;
  40. QRegExpValidator m_lineValidator;
  41. AZStd::function<bool()> m_validatorFunc;
  42. };
  43. } // namespace EMStudio