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 = 0);
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 = NULL);
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 = NULL);
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:
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:
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 private:
180  Q_DISABLE_COPY(pqPropertyLinks)
181 
182  class pqInternals;
183  pqInternals* Internals;
184  bool UseUncheckedProperties;
185  bool AutoUpdateVTKObjects;
186 };
187 
188 //-----------------------------------------------------------------------------
189 template <class ConnectionType>
190 ConnectionType* pqPropertyLinks::addPropertyLinkInternal(QObject* qobject, const char* qproperty,
191  const char* qsignal, vtkSMProxy* smproxy, vtkSMProperty* smproperty, int smindex)
192 {
193  if (!qobject || !qproperty || !qsignal || !smproxy || !smproperty)
194  {
195  qCritical() << "Invalid parameters to pqPropertyLinks::addPropertyLinkInternal";
196  qDebug() << "(" << qobject << ", " << qproperty << ", " << qsignal << ") <==> ("
197  << (smproxy ? smproxy->GetXMLName() : "(none)") << ","
198  << (smproperty ? smproperty->GetXMLLabel() : "(none)") << smindex << ")";
199  return nullptr;
200  }
201 
202  ConnectionType* connection = new ConnectionType(qobject, qproperty, qsignal, smproxy, smproperty,
203  smindex, this->useUncheckedProperties(), this);
204  this->addNewConnection(connection);
205 
206  return connection;
207 }
208 
209 //-----------------------------------------------------------------------------
210 template <class ConnectionType>
211 bool pqPropertyLinks::addPropertyLink(QObject* qobject, const char* qproperty, const char* qsignal,
212  vtkSMProxy* smproxy, vtkSMProperty* smproperty, int smindex, ConnectionType*)
213 {
214  auto connection = this->addPropertyLinkInternal<ConnectionType>(
215  qobject, qproperty, qsignal, smproxy, smproperty, smindex);
216  return connection != nullptr;
217 }
218 
219 //-----------------------------------------------------------------------------
220 template <class ConnectionType>
221 bool pqPropertyLinks::addTraceablePropertyLink(QObject* qobject, const char* qproperty,
222  const char* qsignal, vtkSMProxy* smproxy, vtkSMProperty* smproperty, int smindex, ConnectionType*)
223 {
224  auto connection = this->addPropertyLinkInternal<ConnectionType>(
225  qobject, qproperty, qsignal, smproxy, smproperty, smindex);
226  if (connection)
227  {
228  connection->setTraceChanges(true);
229  return true;
230  }
231  return false;
232 }
233 
234 #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.