ctkComplementMapper.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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 __ctkComplementMapper_h
  15. #define __ctkComplementMapper_h
  16. // Qt includes
  17. #include <QObject>
  18. // CTK includes
  19. #include "ctkCoreExport.h"
  20. class ctkComplementMapperPrivate;
  21. //---------------------------------------------------------------------------
  22. /// \ingroup Core
  23. /// QCheckBox* checkBox = new QCheckBox;
  24. /// ctkComplementMapper* inverter =
  25. /// new ctkComplementMapper("checked", SIGNAL("toggled(bool)"), checkBox);
  26. /// inverter->setComplementValue(true);
  27. /// // -> checkBox->checked() == false
  28. /// inverter->setValue(false);
  29. /// // -> checkBox->checked() == false
  30. class CTK_CORE_EXPORT ctkComplementMapper : public QObject
  31. {
  32. Q_OBJECT
  33. /// This property contains the name of the object mapped property.
  34. Q_PROPERTY(QByteArray propertyName READ propertyName)
  35. /// This property holds the mapped property.
  36. /// It is the value of the mapped object property
  37. Q_PROPERTY(bool value READ value WRITE setValue NOTIFY valueComplementChanged STORED false);
  38. /// This property is the complement of the mapped property.
  39. /// false if \a value is true and true if \a value is false
  40. Q_PROPERTY(bool valueComplement READ valueComplement WRITE setValueComplement NOTIFY valueComplementChanged STORED false)
  41. public:
  42. /// Map the property \a property of the object.
  43. /// The mapper becomes a child of \a object and will be destructed when
  44. /// \a object is destructed.
  45. /// property and object must be valid and non empty. If signal is 0,
  46. /// \a valueChanged(bool) and \a valueComplementChanged(bool) won't be fired.
  47. ctkComplementMapper(QObject* targetObject, const QByteArray& propertyName, const char* signal);
  48. virtual ~ctkComplementMapper();
  49. QByteArray propertyName()const;
  50. /// The mapped object (the mapper parent)
  51. QObject* targetObject()const;
  52. bool value()const;
  53. bool valueComplement()const;
  54. public Q_SLOTS:
  55. void setValue(bool value);
  56. void setValueComplement(bool valueComplement);
  57. void toggle();
  58. Q_SIGNALS:
  59. void valueChanged(bool value);
  60. void valueComplementChanged(bool valueComplement);
  61. protected Q_SLOTS:
  62. void emitValueChanged();
  63. protected:
  64. QScopedPointer<ctkComplementMapperPrivate> d_ptr;
  65. private:
  66. Q_DECLARE_PRIVATE(ctkComplementMapper);
  67. Q_DISABLE_COPY(ctkComplementMapper);
  68. };
  69. #endif