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 
103  int getNumberOfPropertyLinks() const;
104 
108  pqPropertyLinksConnection* getPropertyLink(int index) const;
109 
110 public Q_SLOTS: // NOLINT(readability-redundant-access-specifiers)
114  void removeAllPropertyLinks() { this->clear(); }
115  void clear();
116 
122  void accept();
123 
128  void reset();
129 
135  void setUseUncheckedProperties(bool val);
136 
140  void setAutoUpdateVTKObjects(bool val) { this->AutoUpdateVTKObjects = val; }
141 
142 Q_SIGNALS:
143  void qtWidgetChanged();
144  void smPropertyChanged();
145 
146 private Q_SLOTS:
151  void onQtPropertyModified();
152  void onSMPropertyModified();
153 
154 private: // NOLINT(readability-redundant-access-specifiers)
155  bool addNewConnection(pqPropertyLinksConnection*);
156 
157  template <class ConnectionType>
158  ConnectionType* addPropertyLinkInternal(QObject* qobject, const char* qproperty,
159  const char* qsignal, vtkSMProxy* smproxy, vtkSMProperty* smproperty, int smindex = -1);
160 
161  Q_DISABLE_COPY(pqPropertyLinks)
162 
163  class pqInternals;
164  pqInternals* Internals;
165  bool UseUncheckedProperties;
166  bool AutoUpdateVTKObjects;
167 };
168 
169 //-----------------------------------------------------------------------------
170 template <class ConnectionType>
171 ConnectionType* pqPropertyLinks::addPropertyLinkInternal(QObject* qobject, const char* qproperty,
172  const char* qsignal, vtkSMProxy* smproxy, vtkSMProperty* smproperty, int smindex)
173 {
174  if (!qobject || !qproperty || !qsignal || !smproxy || !smproperty)
175  {
176  qCritical() << "Invalid parameters to pqPropertyLinks::addPropertyLinkInternal";
177  qDebug() << "(" << qobject << ", " << qproperty << ", " << qsignal << ") <==> ("
178  << (smproxy ? smproxy->GetXMLName() : "(none)") << ","
179  << (smproperty ? smproperty->GetXMLLabel() : "(none)") << smindex << ")";
180  return nullptr;
181  }
182 
183  ConnectionType* connection = new ConnectionType(qobject, qproperty, qsignal, smproxy, smproperty,
184  smindex, this->useUncheckedProperties(), this);
185  this->addNewConnection(connection);
186 
187  return connection;
188 }
189 
190 //-----------------------------------------------------------------------------
191 template <class ConnectionType>
192 bool pqPropertyLinks::addPropertyLink(QObject* qobject, const char* qproperty, const char* qsignal,
193  vtkSMProxy* smproxy, vtkSMProperty* smproperty, int smindex, ConnectionType*)
194 {
195  auto connection = this->addPropertyLinkInternal<ConnectionType>(
196  qobject, qproperty, qsignal, smproxy, smproperty, smindex);
197  return connection != nullptr;
198 }
199 
200 //-----------------------------------------------------------------------------
201 template <class ConnectionType>
202 bool pqPropertyLinks::addTraceablePropertyLink(QObject* qobject, const char* qproperty,
203  const char* qsignal, vtkSMProxy* smproxy, vtkSMProperty* smproperty, int smindex, ConnectionType*)
204 {
205  auto connection = this->addPropertyLinkInternal<ConnectionType>(
206  qobject, qproperty, qsignal, smproxy, smproperty, smindex);
207  if (connection)
208  {
209  connection->setTraceChanges(true);
210  return true;
211  }
212  return false;
213 }
214 
215 #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...
index
virtual char * GetXMLName()
Assigned by the XML parser.