ctkLinearValueProxy.h 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. /*=========================================================================
  2. Library: CTK
  3. Copyright (c) Kitware Inc.
  4. Licensed under the Apache License, Version 2.0 (the "License");
  5. you may not use this file except in compliance with the License.
  6. You may obtain a copy of the License at
  7. http://www.apache.org/licenses/LICENSE-2.0.txt
  8. Unless required by applicable law or agreed to in writing, software
  9. distributed under the License is distributed on an "AS IS" BASIS,
  10. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  11. See the License for the specific language governing permissions and
  12. limitations under the License.
  13. =========================================================================*/
  14. #ifndef __ctkLinearValueProxy_h
  15. #define __ctkLinearValueProxy_h
  16. // CTK includes
  17. #include "ctkCoreExport.h"
  18. #include "ctkValueProxy.h"
  19. #include "ctkPimpl.h"
  20. class ctkLinearValueProxyPrivate;
  21. /// \ingroup Core
  22. /// \brief Implementation of an affine value proxy.
  23. /// The ctkLinearValueProxy takes a coefficient and an offset,
  24. /// effectively implementing a value proxy such as:
  25. /// valueProxy = coefficient * value + offset
  26. /// Note: If the coefficient is null then the property value given
  27. /// by value = (valueProxy - offset) / coefficient can give bad results
  28. /// (+ or - infinity depending on the sign of valueProxy - offset).
  29. /// \sa ctkValueProxy
  30. class CTK_CORE_EXPORT ctkLinearValueProxy : public ctkValueProxy
  31. {
  32. Q_OBJECT
  33. Q_PROPERTY(double coefficient READ coefficient WRITE setCoefficient)
  34. Q_PROPERTY(double offset READ offset WRITE setOffset)
  35. public:
  36. typedef ctkValueProxy Superclass;
  37. explicit ctkLinearValueProxy(QObject* parent = 0);
  38. virtual ~ctkLinearValueProxy();
  39. virtual double proxyValueFromValue(double value) const;
  40. virtual double valueFromProxyValue(double proxyValue) const;
  41. virtual double coefficient() const;
  42. virtual double offset() const;
  43. public Q_SLOTS:
  44. virtual void setCoefficient(double newCoeff);
  45. virtual void setOffset(double newOffset);
  46. protected:
  47. QScopedPointer<ctkLinearValueProxyPrivate> d_ptr;
  48. private:
  49. Q_DECLARE_PRIVATE(ctkLinearValueProxy);
  50. Q_DISABLE_COPY(ctkLinearValueProxy);
  51. };
  52. #endif