Commit 367eed82 authored by Kyle Lutz's avatar Kyle Lutz
Browse files

Add command button property widget

This adds a new custom property widget which displays a button
on the properties panel and will invoke the property's command
when clicked.

For example:

  <Property name="New Instance Button"
            command="New"
            panel_widget="command_button">
  </Property>

Will show a button that when clicked will call the "New()" method
on the proxy.

Change-Id: Iba4a9af38670cff1e641dc0ba970b69a99adb229
parent 4a1d587e
...@@ -65,6 +65,8 @@ set (Module_SRCS ...@@ -65,6 +65,8 @@ set (Module_SRCS
pqColorEditorPropertyWidget.h pqColorEditorPropertyWidget.h
pqColorToolbar.cxx pqColorToolbar.cxx
pqColorToolbar.h pqColorToolbar.h
pqCommandButtonPropertyWidget.cxx
pqCommandButtonPropertyWidget.h
pqCommandLineOptionsBehavior.cxx pqCommandLineOptionsBehavior.cxx
pqCommandLineOptionsBehavior.h pqCommandLineOptionsBehavior.h
pqCopyReaction.cxx pqCopyReaction.cxx
...@@ -230,6 +232,7 @@ set (Module_MOC_HDRS ...@@ -230,6 +232,7 @@ set (Module_MOC_HDRS
pqColorSelectorPropertyWidget.h pqColorSelectorPropertyWidget.h
pqColorEditorPropertyWidget.h pqColorEditorPropertyWidget.h
pqColorToolbar.h pqColorToolbar.h
pqCommandButtonPropertyWidget.h
pqCommandLineOptionsBehavior.h pqCommandLineOptionsBehavior.h
pqCopyReaction.h pqCopyReaction.h
pqCrashRecoveryBehavior.h pqCrashRecoveryBehavior.h
......
/*=========================================================================
Program: ParaView
Module: pqCommandButtonPropertyWidget.cxx
Copyright (c) 2005-2012 Kitware Inc.
All rights reserved.
ParaView is a free software; you can redistribute it and/or modify it
under the terms of the ParaView license version 1.2.
See License_v1.2.txt for the full ParaView license.
A copy of this license can be obtained by contacting
Kitware Inc.
28 Corporate Drive
Clifton Park, NY 12065
USA
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
=========================================================================*/
#include "pqCommandButtonPropertyWidget.h"
#include "vtkSMProxy.h"
#include "vtkSMProperty.h"
#include <QVBoxLayout>
#include <QPushButton>
pqCommandButtonPropertyWidget::pqCommandButtonPropertyWidget(vtkSMProxy *proxy,
vtkSMProperty *property,
QWidget *parent)
: pqPropertyWidget(proxy, parent),
Property(property)
{
QVBoxLayout *l = new QVBoxLayout;
l->setSpacing(0);
l->setMargin(0);
QPushButton *button = new QPushButton(property->GetXMLLabel());
connect(button, SIGNAL(clicked()), this, SLOT(buttonClicked()));
l->addWidget(button);
this->setShowLabel(false);
this->setLayout(l);
this->setReason() << "pqCommandButtonPropertyWidget for a property with "
<< "the panel_widget=\"command_button\" attribute";
}
pqCommandButtonPropertyWidget::~pqCommandButtonPropertyWidget()
{
}
void pqCommandButtonPropertyWidget::buttonClicked()
{
this->Property->Modified();
this->proxy()->UpdateProperty(this->proxy()->GetPropertyName(this->Property));
}
/*=========================================================================
Program: ParaView
Module: pqCommandButtonPropertyWidget.h
Copyright (c) 2005-2012 Kitware Inc.
All rights reserved.
ParaView is a free software; you can redistribute it and/or modify it
under the terms of the ParaView license version 1.2.
See License_v1.2.txt for the full ParaView license.
A copy of this license can be obtained by contacting
Kitware Inc.
28 Corporate Drive
Clifton Park, NY 12065
USA
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
=========================================================================*/
#ifndef _pqCommandButtonPropertyWidget_h
#define _pqCommandButtonPropertyWidget_h
#include "pqApplicationComponentsModule.h"
#include "pqPropertyWidget.h"
/// A property widget with a push button for invoking a command on a proxy.
///
/// To use this widget for a property add the 'panel_widget="command_button"'
/// to the property's XML.
class PQAPPLICATIONCOMPONENTS_EXPORT pqCommandButtonPropertyWidget : public pqPropertyWidget
{
Q_OBJECT
public:
explicit pqCommandButtonPropertyWidget(vtkSMProxy *proxy,
vtkSMProperty *property,
QWidget *parent = 0);
~pqCommandButtonPropertyWidget();
private slots:
void buttonClicked();
private:
vtkSMProperty* Property;
};
#endif // _pqCommandButtonPropertyWidget_h
...@@ -37,6 +37,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ...@@ -37,6 +37,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "pqCalculatorWidget.h" #include "pqCalculatorWidget.h"
#include "pqColorEditorPropertyWidget.h" #include "pqColorEditorPropertyWidget.h"
#include "pqColorSelectorPropertyWidget.h" #include "pqColorSelectorPropertyWidget.h"
#include "pqCommandButtonPropertyWidget.h"
#include "pqCubeAxesPropertyWidget.h" #include "pqCubeAxesPropertyWidget.h"
#include "pqDisplayRepresentationWidget.h" #include "pqDisplayRepresentationWidget.h"
#include "pqPipelineRepresentation.h" #include "pqPipelineRepresentation.h"
...@@ -84,6 +85,10 @@ pqStandardPropertyWidgetInterface::createWidgetForProperty(vtkSMProxy *smProxy, ...@@ -84,6 +85,10 @@ pqStandardPropertyWidgetInterface::createWidgetForProperty(vtkSMProxy *smProxy,
{ {
return new pqCalculatorWidget(smProxy, smProperty); return new pqCalculatorWidget(smProxy, smProperty);
} }
else if(name == "command_button")
{
return new pqCommandButtonPropertyWidget(smProxy, smProperty);
}
else else
{ {
qDebug() << "Unknown \"panel_widget\" '" << name.c_str() << "' specified."; qDebug() << "Unknown \"panel_widget\" '" << name.c_str() << "' specified.";
......
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