pqPropertyLinks.h
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: Copyright (c) Kitware Inc.
2 // SPDX-FileCopyrightText: Copyright (c) Sandia Corporation
3 // SPDX-License-Identifier: BSD-3-Clause
4 #ifndef pqPropertyLinks_h
5 #define pqPropertyLinks_h
6 
7 #include <QObject>
8 #include <QtDebug>
9 
10 #include "pqCoreModule.h"
11 #include "pqPropertyLinksConnection.h" // needed for pqPropertyLinksConnection.
12 
13 class vtkSMProperty;
14 class vtkSMProxy;
15 
38 class PQCORE_EXPORT pqPropertyLinks : public QObject
39 {
40  Q_OBJECT
41  typedef QObject Superclass;
42 
43 public:
44  pqPropertyLinks(QObject* parent = nullptr);
45  ~pqPropertyLinks() override;
46 
64  bool addPropertyLink(QObject* qobject, const char* qproperty, const char* qsignal,
65  vtkSMProxy* smproxy, vtkSMProperty* smproperty, int smindex = -1);
66 
70  bool addTraceablePropertyLink(QObject* qobject, const char* qproperty, const char* qsignal,
71  vtkSMProxy* smproxy, vtkSMProperty* smproperty, int smindex = -1);
72 
76  template <class ConnectionType>
77  bool addPropertyLink(QObject* qobject, const char* qproperty, const char* qsignal,
78  vtkSMProxy* smproxy, vtkSMProperty* smproperty, int smindex = -1,
79  ConnectionType* notused = nullptr);
80 
86  template <class ConnectionType>
87  bool addTraceablePropertyLink(QObject* qobject, const char* qproperty, const char* qsignal,
88  vtkSMProxy* smproxy, vtkSMProperty* smproperty, int smindex = -1,
89  ConnectionType* notused = nullptr);
90 
94  bool removePropertyLink(QObject* qobject, const char* qproperty, const char* qsignal,
95  vtkSMProxy* smproxy, vtkSMProperty* smproperty, int smindex = -1);
96 
97  bool autoUpdateVTKObjects() const { return this->AutoUpdateVTKObjects; }
98  bool useUncheckedProperties() const { return this->UseUncheckedProperties; }
99 
100 public Q_SLOTS: // NOLINT(readability-redundant-access-specifiers)
104  void removeAllPropertyLinks() { this->clear(); }
105  void clear();
106 
112  void accept();
113 
118  void reset();
119 
125  void setUseUncheckedProperties(bool val);
126 
130  void setAutoUpdateVTKObjects(bool val) { this->AutoUpdateVTKObjects = val; }
131 
132 Q_SIGNALS:
133  void qtWidgetChanged();
134  void smPropertyChanged();
135 
136 private Q_SLOTS:
141  void onQtPropertyModified();
142  void onSMPropertyModified();
143 
144 private: // NOLINT(readability-redundant-access-specifiers)
145  bool addNewConnection(pqPropertyLinksConnection*);
146 
147  template <class ConnectionType>
148  ConnectionType* addPropertyLinkInternal(QObject* qobject, const char* qproperty,
149  const char* qsignal, vtkSMProxy* smproxy, vtkSMProperty* smproperty, int smindex = -1);
150 
151  Q_DISABLE_COPY(pqPropertyLinks)
152 
153  class pqInternals;
154  pqInternals* Internals;
155  bool UseUncheckedProperties;
156  bool AutoUpdateVTKObjects;
157 };
158 
159 //-----------------------------------------------------------------------------
160 template <class ConnectionType>
161 ConnectionType* pqPropertyLinks::addPropertyLinkInternal(QObject* qobject, const char* qproperty,
162  const char* qsignal, vtkSMProxy* smproxy, vtkSMProperty* smproperty, int smindex)
163 {
164  if (!qobject || !qproperty || !qsignal || !smproxy || !smproperty)
165  {
166  qCritical() << "Invalid parameters to pqPropertyLinks::addPropertyLinkInternal";
167  qDebug() << "(" << qobject << ", " << qproperty << ", " << qsignal << ") <==> ("
168  << (smproxy ? smproxy->GetXMLName() : "(none)") << ","
169  << (smproperty ? smproperty->GetXMLLabel() : "(none)") << smindex << ")";
170  return nullptr;
171  }
172 
173  ConnectionType* connection = new ConnectionType(qobject, qproperty, qsignal, smproxy, smproperty,
174  smindex, this->useUncheckedProperties(), this);
175  this->addNewConnection(connection);
176 
177  return connection;
178 }
179 
180 //-----------------------------------------------------------------------------
181 template <class ConnectionType>
182 bool pqPropertyLinks::addPropertyLink(QObject* qobject, const char* qproperty, const char* qsignal,
183  vtkSMProxy* smproxy, vtkSMProperty* smproperty, int smindex, ConnectionType*)
184 {
185  auto connection = this->addPropertyLinkInternal<ConnectionType>(
186  qobject, qproperty, qsignal, smproxy, smproperty, smindex);
187  return connection != nullptr;
188 }
189 
190 //-----------------------------------------------------------------------------
191 template <class ConnectionType>
192 bool pqPropertyLinks::addTraceablePropertyLink(QObject* qobject, const char* qproperty,
193  const char* qsignal, vtkSMProxy* smproxy, vtkSMProperty* smproperty, int smindex, ConnectionType*)
194 {
195  auto connection = this->addPropertyLinkInternal<ConnectionType>(
196  qobject, qproperty, qsignal, smproxy, smproperty, smindex);
197  if (connection)
198  {
199  connection->setTraceChanges(true);
200  return true;
201  }
202  return false;
203 }
204 
205 #endif
superclass for all SM properties
virtual char * GetXMLLabel()
The label assigned by the xml parser.
#define PQCORE_EXPORT
Definition: pqCoreModule.h:15
proxy for a VTK object(s) on a server
Definition: vtkSMProxy.h:140
pqPropertyLinksConnection is used by pqPropertyLinks to keep a QObject and vtkSMProperty linked toget...
virtual char * GetXMLName()
Assigned by the XML parser.