PropertyFuncValLineEdit.h 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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 "FunctorValidator.h"
  11. #include <AzToolsFramework/UI/PropertyEditor/PropertyStringLineEditCtrl.hxx>
  12. #endif
  13. namespace ProjectSettingsTool
  14. {
  15. // Forward Declare
  16. class ValidationHandler;
  17. class PropertyFuncValLineEditCtrl
  18. : public AzToolsFramework::PropertyStringLineEditCtrl
  19. {
  20. Q_OBJECT
  21. public:
  22. AZ_CLASS_ALLOCATOR(PropertyFuncValLineEditCtrl, AZ::SystemAllocator)
  23. PropertyFuncValLineEditCtrl(QWidget* pParent = nullptr);
  24. virtual QString GetValue() const;
  25. // Sets value programmtically and triggers validation
  26. virtual void SetValue(const QString& value);
  27. // Sets value as if user set it
  28. void SetValueUser(const QString& value);
  29. // Returns pointer to the validator used
  30. FunctorValidator* GetValidator();
  31. // Sets the validator for the lineedit
  32. void SetValidator(FunctorValidator* validator);
  33. // Sets the validator for the linedit
  34. void SetValidator(FunctorValidator::FunctorType validator);
  35. // Returns false if invalid and returns shows error as tooltip
  36. bool ValidateAndShowErrors();
  37. // Forces the values to up validated and style updated
  38. void ForceValidate();
  39. virtual void ConsumeAttribute(AZ::u32 attrib, AzToolsFramework::PropertyAttributeReader* attrValue, const char* debugName);
  40. signals:
  41. void ValueChangedByUser();
  42. protected:
  43. // Keeps track of the validator so no const_casts must be done
  44. FunctorValidator* m_validator;
  45. };
  46. class PropertyFuncValLineEditHandler
  47. : public AzToolsFramework::PropertyHandler <AZStd::string, PropertyFuncValLineEditCtrl>
  48. {
  49. AZ_CLASS_ALLOCATOR(PropertyFuncValLineEditHandler, AZ::SystemAllocator);
  50. public:
  51. PropertyFuncValLineEditHandler(ValidationHandler* valHdlr);
  52. AZ::u32 GetHandlerName(void) const override;
  53. // Need to unregister ourselves
  54. bool AutoDelete() const override { return false; }
  55. QWidget* CreateGUI(QWidget* pParent) override;
  56. void ConsumeAttribute(PropertyFuncValLineEditCtrl* GUI, AZ::u32 attrib, AzToolsFramework::PropertyAttributeReader* attrValue, const char* debugName) override;
  57. void WriteGUIValuesIntoProperty(size_t index, PropertyFuncValLineEditCtrl* GUI, property_t& instance, AzToolsFramework::InstanceDataNode* node) override;
  58. bool ReadValuesIntoGUI(size_t index, PropertyFuncValLineEditCtrl* GUI, const property_t& instance, AzToolsFramework::InstanceDataNode* node) override;
  59. static PropertyFuncValLineEditHandler* Register(ValidationHandler* valHdlr);
  60. private:
  61. ValidationHandler* m_validationHandler;
  62. };
  63. } // namespace ProjectSettingsTool