QtMvvm  1.0.0
A mvvm oriented library for Qt, to create Projects for Widgets and Quick in parallel
qqmlmvvmbinding.h
1 #ifndef QTMVVM_QQMLMVVMBINDING_H
2 #define QTMVVM_QQMLMVVMBINDING_H
3 
4 #include <QtCore/QObject>
5 #include <QtQml/QQmlParserStatus>
6 
7 #include <QtMvvmCore/Binding>
8 
9 #ifdef DOXYGEN_RUN
11 
24 class MvvmBinding : public QtObject
25 #else
26 namespace QtMvvm {
27 
28 class QQmlMvvmBinding : public QObject, public QQmlParserStatus
29 #endif
30 {
31  Q_OBJECT
32  Q_INTERFACES(QQmlParserStatus)
33 
34 
43  Q_PROPERTY(QObject* viewModel MEMBER _viewModel NOTIFY viewModelChanged)
53  Q_PROPERTY(QString viewModelProperty MEMBER _viewModelProperty NOTIFY viewModelPropertyChanged)
63  Q_PROPERTY(QObject* view MEMBER _view NOTIFY viewChanged)
73  Q_PROPERTY(QString viewProperty MEMBER _viewProperty NOTIFY viewPropertyChanged)
84  Q_PROPERTY(QString viewModelChangeSignal MEMBER _viewModelChangeSignal NOTIFY viewModelChangeSignalChanged)
95  Q_PROPERTY(QString viewChangeSignal MEMBER _viewChangeSignal NOTIFY viewChangeSignalChanged)
105  Q_PROPERTY(BindingDirection type READ type WRITE setType NOTIFY typeChanged) //MEMBER is broken for flags
106 
107 public:
109  enum BindingDirectionFlag { //copy flags from binding
110  SingleInit = Binding::SingleInit,
111  OneWayToView = Binding::OneWayToView,
112  OneWayToViewModel = Binding::OneWayToViewModel,
113  TwoWay = Binding::TwoWay
114  };
115  Q_DECLARE_FLAGS(BindingDirection, BindingDirectionFlag)
116  Q_FLAG(BindingDirection)
117 
118 
119  explicit QQmlMvvmBinding(QObject *parent = nullptr);
120 
122  void classBegin() override;
124  void componentComplete() override;
125 
127  BindingDirection type() const;
129  Q_INVOKABLE bool isValid() const;
130 
131 #ifdef DOXYGEN_RUN
132 public:
133 #else
134 public Q_SLOTS:
135 #endif
136  void setType(BindingDirection type);
139  void unbind();
140 
141 Q_SIGNALS:
147  void viewChanged(QObject* view);
151  void typeChanged(BindingDirection type);
156 
157 private Q_SLOTS:
158  void resetBinding();
159 
160 private:
161  Binding _binding;
162  bool _completed;
163 
164  QObject* _viewModel;
165  QString _viewModelProperty;
166  QObject* _view;
167  QString _viewProperty;
168  BindingDirection _type;
169  QString _viewModelChangeSignal;
170  QString _viewChangeSignal;
171 };
172 
173 }
174 
175 #endif // QTMVVM_QQMLMVVMBINDING_H
All changes on both sides are propagated to the other one.
A QML class to create a local mvvm multiway binding.
void viewChanged(QObject *view)
NOTIFY accessor for MvvmBinding::view.
All changes done to the view are propagated to the viewmodel.
Only initialize the view by settings it to the viewmodels value on creation.
All changes done to the viewmodel are propagated to the view.
QString viewModelProperty
The property of the viewmodel to use in the binding.
void unbind()
Remove the binding by disconnecting all change signals.
void viewModelChangeSignalChanged(const QString &viewModelChangeSignal)
NOTIFY accessor for MvvmBinding::viewChangeSignal.
The QML import for the QtMvvmCore QML module.
void viewPropertyChanged(const QString &viewProperty)
NOTIFY accessor for MvvmBinding::viewProperty.
QString viewModelChangeSignal
An alternative signal to be used instead of the viewModelProperty notify signal to detect property ch...
void viewModelPropertyChanged(const QString &viewModelProperty)
NOTIFY accessor for MvvmBinding::viewModelProperty.
Q_INVOKABLE bool isValid() const
Specifies whether the binding is a valid and active binding.
void viewChangeSignalChanged(const QString &viewChangeSignal)
NOTIFY accessor for MvvmBinding::type.
QString viewProperty
The property of the view to use in the binding.
QString viewChangeSignal
An alternative signal to be used instead of the viewProperty notify signal to detect property changes...
QObject viewModel
The object in the role of a viewmodel.
void typeChanged(BindingDirection type)
NOTIFY accessor for MvvmBinding::viewModelChangeSignal.
void viewModelChanged(QObject *viewModel)
NOTIFY accessor for MvvmBinding::viewModel.
QObject view
The object in the role of a view.
The primary namespace of the QtMvvm library.
Definition: binding.h:10
BindingDirectionFlag
Flags to control how to bind the properties.