pqPropertyLinks.h
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: ParaView
4  Module: $RCSfile$
5 
6  Copyright (c) 2005,2006 Sandia Corporation, Kitware Inc.
7  All rights reserved.
8 
9  ParaView is a free software; you can redistribute it and/or modify it
10  under the terms of the ParaView license version 1.2.
11 
12  See License_v1.2.txt for the full ParaView license.
13  A copy of this license can be obtained by contacting
14  Kitware Inc.
15  28 Corporate Drive
16  Clifton Park, NY 12065
17  USA
18 
19 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20 ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR
23 CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
24 EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
25 PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
26 PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
27 LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
28 NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
29 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 
31 ========================================================================*/
32 #ifndef pqPropertyLinks_h
33 #define pqPropertyLinks_h
34 
35 #include <QObject>
36 #include <QtDebug>
37 
38 #include "pqCoreModule.h"
39 #include "pqPropertyLinksConnection.h" // needed for pqPropertyLinksConnection.
40 
41 class vtkSMProperty;
42 class vtkSMProxy;
43 
66 class PQCORE_EXPORT pqPropertyLinks : public QObject
67 {
68  Q_OBJECT
69  typedef QObject Superclass;
70 
71 public:
72  pqPropertyLinks(QObject* parent = nullptr);
73  ~pqPropertyLinks() override;
74 
92  bool addPropertyLink(QObject* qobject, const char* qproperty, const char* qsignal,
93  vtkSMProxy* smproxy, vtkSMProperty* smproperty, int smindex = -1);
94 
98  bool addTraceablePropertyLink(QObject* qobject, const char* qproperty, const char* qsignal,
99  vtkSMProxy* smproxy, vtkSMProperty* smproperty, int smindex = -1);
100 
104  template <class ConnectionType>
105  bool addPropertyLink(QObject* qobject, const char* qproperty, const char* qsignal,
106  vtkSMProxy* smproxy, vtkSMProperty* smproperty, int smindex = -1,
107  ConnectionType* notused = nullptr);
108 
114  template <class ConnectionType>
115  bool addTraceablePropertyLink(QObject* qobject, const char* qproperty, const char* qsignal,
116  vtkSMProxy* smproxy, vtkSMProperty* smproperty, int smindex = -1,
117  ConnectionType* notused = nullptr);
118 
122  bool removePropertyLink(QObject* qobject, const char* qproperty, const char* qsignal,
123  vtkSMProxy* smproxy, vtkSMProperty* smproperty, int smindex = -1);
124 
125  bool autoUpdateVTKObjects() const { return this->AutoUpdateVTKObjects; }
126  bool useUncheckedProperties() const { return this->UseUncheckedProperties; }
127 
128 public Q_SLOTS: // NOLINT(readability-redundant-access-specifiers)
132  void removeAllPropertyLinks() { this->clear(); }
133  void clear();
134 
140  void accept();
141 
146  void reset();
147 
153  void setUseUncheckedProperties(bool val);
154 
158  void setAutoUpdateVTKObjects(bool val) { this->AutoUpdateVTKObjects = val; }
159 
160 Q_SIGNALS:
161  void qtWidgetChanged();
162  void smPropertyChanged();
163 
164 private Q_SLOTS:
169  void onQtPropertyModified();
170  void onSMPropertyModified();
171 
172 private: // NOLINT(readability-redundant-access-specifiers)
173  bool addNewConnection(pqPropertyLinksConnection*);
174 
175  template <class ConnectionType>
176  ConnectionType* addPropertyLinkInternal(QObject* qobject, const char* qproperty,
177  const char* qsignal, vtkSMProxy* smproxy, vtkSMProperty* smproperty, int smindex = -1);
178 
179  Q_DISABLE_COPY(pqPropertyLinks)
180 
181  class pqInternals;
182  pqInternals* Internals;
183  bool UseUncheckedProperties;
184  bool AutoUpdateVTKObjects;
185 };
186 
187 //-----------------------------------------------------------------------------
188 template <class ConnectionType>
189 ConnectionType* pqPropertyLinks::addPropertyLinkInternal(QObject* qobject, const char* qproperty,
190  const char* qsignal, vtkSMProxy* smproxy, vtkSMProperty* smproperty, int smindex)
191 {
192  if (!qobject || !qproperty || !qsignal || !smproxy || !smproperty)
193  {
194  qCritical() << "Invalid parameters to pqPropertyLinks::addPropertyLinkInternal";
195  qDebug() << "(" << qobject << ", " << qproperty << ", " << qsignal << ") <==> ("
196  << (smproxy ? smproxy->GetXMLName() : "(none)") << ","
197  << (smproperty ? smproperty->GetXMLLabel() : "(none)") << smindex << ")";
198  return nullptr;
199  }
200 
201  ConnectionType* connection = new ConnectionType(qobject, qproperty, qsignal, smproxy, smproperty,
202  smindex, this->useUncheckedProperties(), this);
203  this->addNewConnection(connection);
204 
205  return connection;
206 }
207 
208 //-----------------------------------------------------------------------------
209 template <class ConnectionType>
210 bool pqPropertyLinks::addPropertyLink(QObject* qobject, const char* qproperty, const char* qsignal,
211  vtkSMProxy* smproxy, vtkSMProperty* smproperty, int smindex, ConnectionType*)
212 {
213  auto connection = this->addPropertyLinkInternal<ConnectionType>(
214  qobject, qproperty, qsignal, smproxy, smproperty, smindex);
215  return connection != nullptr;
216 }
217 
218 //-----------------------------------------------------------------------------
219 template <class ConnectionType>
220 bool pqPropertyLinks::addTraceablePropertyLink(QObject* qobject, const char* qproperty,
221  const char* qsignal, vtkSMProxy* smproxy, vtkSMProperty* smproperty, int smindex, ConnectionType*)
222 {
223  auto connection = this->addPropertyLinkInternal<ConnectionType>(
224  qobject, qproperty, qsignal, smproxy, smproperty, smindex);
225  if (connection)
226  {
227  connection->setTraceChanges(true);
228  return true;
229  }
230  return false;
231 }
232 
233 #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:152
pqPropertyLinksConnection is used by pqPropertyLinks to keep a QObject and vtkSMProperty linked toget...
virtual char * GetXMLName()
Assigned by the XML parser.