Commit 909323f6 authored by Timothee Chabat's avatar Timothee Chabat
Browse files

Cleanup pqInteractivePropertyWidget

 - Organize code and check for nullptr
 - Remove parent proxy handling
parent b88ffc08
......@@ -61,23 +61,49 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <cassert>
//-----------------------------------------------------------------------------
namespace details
{
vtkSMSourceProxy* GetTrueSourceInPipeline(vtkSMProxy* current)
{
vtkSMProxy* res = nullptr;
if (current != nullptr)
{
res = current;
vtkSMProxy* parent = current;
if (current->GetNumberOfConsumers())
{
parent = current->GetConsumerProxy(0);
}
while (parent != res && parent->GetNumberOfConsumers())
{
res = parent;
parent = res->GetConsumerProxy(0);
}
}
return vtkSMSourceProxy::SafeDownCast(res);
}
}
//-----------------------------------------------------------------------------
struct pqInteractivePropertyWidget::SourceTracker
{
vtkSMProxy* Proxy = nullptr;
vtkSMRepresentationProxy* Representation = nullptr;
vtkWeakPointer<vtkSMSourceProxy> Proxy;
vtkWeakPointer<vtkSMRepresentationProxy> Representation;
int Visibility = 0;
// Try to find the representation of our current Proxy in the view. If found
// we link its visibility property to trigger an update of the widget visibility.
void RegisterRepresentation(
bool RegisterRepresentation(
pqInteractivePropertyWidget* self, vtkSMViewProxy* view, const char* prop)
{
if (vtkSMSourceProxy* source = vtkSMSourceProxy::SafeDownCast(this->Proxy))
if (this->Proxy)
{
// XXX: for now we only consider port 0
// This is coherent with the pqInteractivePropertyWidget::dataBounds method
vtkSMRepresentationProxy* repr = view ? view->FindRepresentation(source, 0) : nullptr;
vtkSMRepresentationProxy* repr = view ? view->FindRepresentation(this->Proxy, 0) : nullptr;
// Links its visibility property to trigger a render
if (repr)
......@@ -92,6 +118,7 @@ struct pqInteractivePropertyWidget::SourceTracker
vtkSMPropertyHelper(visibility, true).Get(&visValue, 1);
self->setProperty(prop, visValue);
}
return true;
}
}
else
......@@ -99,6 +126,7 @@ struct pqInteractivePropertyWidget::SourceTracker
self->setProperty(prop, 0);
}
}
return false;
}
// Reset Representation to nullptr and remove the associated events
......@@ -113,6 +141,10 @@ struct pqInteractivePropertyWidget::SourceTracker
this->Representation = nullptr;
}
}
// Make sure that if we don't detect any valid source the behavior fall back
// to the previous one ie the widget is always visible
bool GetVisibility() const { return (this->Proxy == nullptr) || this->Visibility; }
};
//-----------------------------------------------------------------------------
......@@ -120,24 +152,15 @@ class pqInteractivePropertyWidget::pqInternals
{
public:
vtkSmartPointer<vtkSMNewWidgetRepresentationProxy> WidgetProxy;
// This pointer is the proxy of the property and not the filter itself
vtkWeakPointer<vtkSMProxy> DataSource;
vtkSmartPointer<vtkSMPropertyGroup> SMGroup;
bool WidgetVisibility;
bool ViewRepresentationSynchronized = false;
unsigned long UserEventObserverId;
// When false, HasSourceBeenApplied indicate that the filter the widget
// is attached to has not been applied yet.
bool HasSourceBeenApplied = false;
// Connection to destroy once we have detected the source has been applied
QMetaObject::Connection ApplyConnectionObserver;
// Tracker for the filter the widget is attached to. Its visibility is used when
// HasSourceBeenApplied == true
// Tracker for the filter the widget is attached to.
SourceTracker Source;
// Tracker for the parent filter of the this->Source filter. Its visibility is
// used when HasSourceBeenApplied == false
SourceTracker Parent;
bool ViewRepresentationSynchronized = false;
QMetaObject::Connection RepresentationConnection;
pqInternals()
: WidgetVisibility(false)
......@@ -165,14 +188,11 @@ pqInteractivePropertyWidget::pqInteractivePropertyWidget(const char* widget_smgr
// Initialize related proxies. For example with a `Sphere -> Transform` pipeline,
// proxies will be :
// - this->proxy() : property the widget is linked to
// - this->proxy() : the proxy the filter is attached to.
// For a tranform this is the ProxyProperty Tranform3 (see filters_fitlersgeneral.xml)
// - internals.Source.Proxy : the actual filter (ie Transform)
// - internals.Parent.Proxy : the parent filter (ie Sphere)
internals.Source.Proxy = this->proxy()->GetConsumerProxy(0);
if (this->proxy()->GetNumberOfProducers() > 0)
{
internals.Parent.Proxy = this->proxy()->GetProducerProxy(0);
}
internals.Source.Proxy = details::GetTrueSourceInPipeline(this->proxy());
pqServer* server =
pqApplicationCore::instance()->getServerManagerModel()->findServer(smproxy->GetSession());
......@@ -236,19 +256,6 @@ pqInteractivePropertyWidget::pqInteractivePropertyWidget(const char* widget_smgr
this->setDataSource(nullptr);
}
internals.ApplyConnectionObserver =
QObject::connect(pqApplicationCore::instance()->getServerManagerModel(),
&pqServerManagerModel::dataUpdated, [this, &internals](pqPipelineSource* source) {
if (!internals.HasSourceBeenApplied && source->getProxy() == internals.Source.Proxy)
{
internals.HasSourceBeenApplied = true;
this->updateWidgetVisibility();
// Unregister this connection once we know the filter has been applied
QObject::disconnect(internals.ApplyConnectionObserver);
}
});
// This ensures that when the user changes the Qt widget, we re-render to show
// the update widget.
this->connect(&this->links(), SIGNAL(qtWidgetChanged()), SLOT(render()));
......@@ -304,25 +311,27 @@ void pqInteractivePropertyWidget::setView(pqView* pqview)
if (oldview)
{
QObject::disconnect(oldview, &pqView::representationAdded, this,
&pqInteractivePropertyWidget::onRepresentationAdded);
QObject::disconnect(this->Internals->RepresentationConnection);
vtkSMPropertyHelper(oldview->getProxy(), "HiddenRepresentations").Remove(this->widgetProxy());
oldview->getProxy()->UpdateVTKObjects();
this->Internals->Source.UnregisterRepresentation(this, "sourceVisibility");
this->Internals->Parent.UnregisterRepresentation(this, "parentVisibility");
}
this->Superclass::setView(rview);
if (rview)
{
QObject::connect(rview, &pqView::representationAdded, this,
&pqInteractivePropertyWidget::onRepresentationAdded);
vtkSMViewProxy* view = vtkSMViewProxy::SafeDownCast(rview->getProxy());
bool registered =
this->Internals->Source.RegisterRepresentation(this, view, "sourceVisibility");
if (!registered)
{
this->Internals->RepresentationConnection = QObject::connect(rview,
&pqView::representationAdded, this, &pqInteractivePropertyWidget::onRepresentationAdded);
}
vtkSMPropertyHelper(rview->getProxy(), "HiddenRepresentations").Add(this->widgetProxy());
vtkSMPropertyHelper(view, "HiddenRepresentations").Add(this->widgetProxy());
rview->getProxy()->UpdateVTKObjects();
this->setupCurrentDataRepresentation();
}
this->updateWidgetVisibility();
}
......@@ -368,9 +377,8 @@ void pqInteractivePropertyWidget::setWidgetVisible(bool val)
//-----------------------------------------------------------------------------
void pqInteractivePropertyWidget::updateWidgetVisibility()
{
bool dataVisible = this->Internals->HasSourceBeenApplied ? this->Internals->Source.Visibility
: this->Internals->Parent.Visibility;
bool visible = this->isSelected() && this->isWidgetVisible() && this->view() && dataVisible;
bool visible = this->isSelected() && this->isWidgetVisible() && this->view() &&
this->Internals->Source.GetVisibility();
vtkSMProxy* wdgProxy = this->widgetProxy();
assert(wdgProxy);
......@@ -384,15 +392,12 @@ void pqInteractivePropertyWidget::updateWidgetVisibility()
//-----------------------------------------------------------------------------
void pqInteractivePropertyWidget::onRepresentationAdded(pqRepresentation* representation)
{
if (this->Internals->ViewRepresentationSynchronized)
{
return;
}
this->Internals->Source.RegisterRepresentation(
this, representation->getViewProxy(), "sourceVisibility");
this->setupCurrentDataRepresentation();
if (this->Internals->Source.Representation == representation->getProxy())
{
this->Internals->ViewRepresentationSynchronized = true;
QObject::disconnect(this->Internals->RepresentationConnection);
}
this->updateWidgetVisibility();
......@@ -417,25 +422,12 @@ void pqInteractivePropertyWidget::setSourceVisibility(int vis)
this->updateWidgetVisibility();
}
//-----------------------------------------------------------------------------
void pqInteractivePropertyWidget::setParentVisibility(int vis)
{
this->Internals->Parent.Visibility = vis;
this->updateWidgetVisibility();
}
//-----------------------------------------------------------------------------
int pqInteractivePropertyWidget::sourceVisibility() const
{
return this->Internals->Source.Visibility;
}
//-----------------------------------------------------------------------------
int pqInteractivePropertyWidget::parentVisibility() const
{
return this->Internals->Parent.Visibility;
}
//-----------------------------------------------------------------------------
vtkBoundingBox pqInteractivePropertyWidget::dataBounds() const
{
......@@ -491,19 +483,6 @@ void pqInteractivePropertyWidget::handleUserEvent(
}
}
//-----------------------------------------------------------------------------
void pqInteractivePropertyWidget::setupCurrentDataRepresentation()
{
if (this->Internals->ViewRepresentationSynchronized)
{
return;
}
vtkSMViewProxy* view = vtkSMViewProxy::SafeDownCast(this->view()->getProxy());
this->Internals->Source.RegisterRepresentation(this, view, "sourceVisibility");
this->Internals->Parent.RegisterRepresentation(this, view, "parentVisibility");
}
//-----------------------------------------------------------------------------
void pqInteractivePropertyWidget::hideEvent(QHideEvent*)
{
......
......@@ -60,7 +60,6 @@ class PQAPPLICATIONCOMPONENTS_EXPORT pqInteractivePropertyWidget : public pqProp
typedef pqPropertyWidget Superclass;
Q_PROPERTY(pqSMProxy dataSource READ dataSource WRITE setDataSource);
Q_PROPERTY(int sourceVisibility READ sourceVisibility WRITE setSourceVisibility);
Q_PROPERTY(int parentVisibility READ parentVisibility WRITE setParentVisibility);
public:
pqInteractivePropertyWidget(const char* widget_smgroup, const char* widget_smname,
......@@ -101,11 +100,6 @@ public:
*/
int sourceVisibility() const;
/**
* Returns the representation of the parent filter visibility.
*/
int parentVisibility() const;
//@{
/**
* In these methods, we show/hide the widget since the interactive widget is not
......@@ -157,12 +151,6 @@ public Q_SLOTS:
*/
void setSourceVisibility(int vis);
/**
* Triggered when the visibility of the representation of the parent filter
* has changed.
*/
void setParentVisibility(int vis);
protected Q_SLOTS:
/**
* Places the interactive widget using current data source information.
......@@ -202,14 +190,12 @@ private Q_SLOTS:
/**
* This method is called to update the state of Visibility and Enabled
* properties on the widget based on the state of isWidgetVisible() and
* isSelected(). Also verify that in pre_apply state the parent filter is
* visible, and after the first apply that the filter itself is visible.
* isSelected(). Also check for the visibility of the represented filter.
*/
void updateWidgetVisibility();
/**
* Slot to catch the representation for the parent filter representation
* and the current filter representation.
* Slot to catch the creation of the representation for the represented filter.
*/
void onRepresentationAdded(pqRepresentation* representation);
......@@ -219,13 +205,6 @@ protected:
private:
void handleUserEvent(vtkObject*, unsigned long, void*);
/**
* Try to find the representation of the filter that the widget is attached to
* and its parent. If it finds it, links their "Visibility" property to trigger
* a render on the current view.
*/
void setupCurrentDataRepresentation();
private:
Q_DISABLE_COPY(pqInteractivePropertyWidget)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment