CTK  0.1.0
The Common Toolkit is a community effort to provide support code for medical image analysis, surgical navigation, and related projects.
ctkBooleanMapper.h
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Library: CTK
4 
5  Copyright (c) Kitware Inc.
6 
7  Licensed under the Apache License, Version 2.0 (the "License");
8  you may not use this file except in compliance with the License.
9  You may obtain a copy of the License at
10 
11  http://www.apache.org/licenses/LICENSE-2.0.txt
12 
13  Unless required by applicable law or agreed to in writing, software
14  distributed under the License is distributed on an "AS IS" BASIS,
15  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  See the License for the specific language governing permissions and
17  limitations under the License.
18 
19 =========================================================================*/
20 
21 #ifndef __ctkBooleanMapper_h
22 #define __ctkBooleanMapper_h
23 
24 // Qt includes
25 #include <QObject>
26 #include <QVariant>
27 
28 // CTK includes
29 #include "ctkCoreExport.h"
30 class ctkBooleanMapperPrivate;
31 
32 //---------------------------------------------------------------------------
51 class CTK_CORE_EXPORT ctkBooleanMapper : public QObject
52 {
53  Q_OBJECT
55  Q_PROPERTY(QByteArray propertyName READ propertyName)
56 
57 
58  Q_PROPERTY(bool value READ value WRITE setValue NOTIFY complementChanged STORED false);
60 
63  Q_PROPERTY(bool complement READ complement WRITE setComplement NOTIFY complementChanged STORED false)
64 
65  Q_PROPERTY(int valueAsInt READ valueAsInt WRITE setValueAsInt NOTIFY valueAsIntChanged STORED false )
66  Q_PROPERTY(QString valueAsString READ valueAsString WRITE setValueAsString NOTIFY valueAsStringChanged STORED false )
67 
69  Q_PROPERTY(QVariant trueValue READ trueValue WRITE setTrueValue )
70 
72  Q_PROPERTY(QVariant falseValue READ falseValue WRITE setFalseValue )
73 public:
79  ctkBooleanMapper(QObject* targetObject, const QByteArray& propertyName, const QByteArray& signal);
80  virtual ~ctkBooleanMapper();
81 
82  QByteArray propertyName()const;
83 
85  QObject* targetObject()const;
86 
87  bool value()const;
88  bool complement()const;
89  int valueAsInt()const;
90  QString valueAsString()const;
91 
92  QVariant trueValue()const;
93  QVariant falseValue()const;
94 
95  void setTrueValue(const QVariant& value);
96  void setFalseValue(const QVariant& value);
97 
98 public Q_SLOTS:
99  void setValue(bool value);
100  void setComplement(bool complement);
101  void setValueAsInt(int value);
102  void setValueAsString(const QString& value);
103 
104  void toggle();
105 
106 Q_SIGNALS:
107  void valueChanged(bool value);
108  void complementChanged(bool complement);
109  void valueAsIntChanged(int value);
110  void valueAsStringChanged(const QString& value);
111 
112 protected Q_SLOTS:
113  void emitValueChanged();
114  void emitValueAsChanged();
115 
116 protected:
117  QScopedPointer<ctkBooleanMapperPrivate> d_ptr;
118 
119 private:
120  Q_DECLARE_PRIVATE(ctkBooleanMapper);
121  Q_DISABLE_COPY(ctkBooleanMapper);
122 };
123 
124 #endif
125