pqVectorWidget.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 pqVectorWidget_h
33 #define pqVectorWidget_h
34 
35 #include "pqWidgetsModule.h"
36 
37 #include <QVariant>
38 #include <QVector2D>
39 #include <QVector3D>
40 #include <QWidget>
41 
45 class PQWIDGETS_EXPORT pqVectorWidget : public QWidget
46 {
47  Q_OBJECT
48  Q_PROPERTY(QVariant value READ value USER true);
49 
50 public:
51  pqVectorWidget(const QVariant& value, QWidget* parent = nullptr);
52  ~pqVectorWidget() override = default;
53 
57  const QVariant& value() const { return this->Vector; }
58 
59 Q_SIGNALS:
63  void valueChanged(const QVariant&);
64 
65 public Q_SLOTS:
66 
71  virtual void setValue(int index, float value) = 0;
72 
73 protected:
74  QVariant Vector;
75 
80  void CreateUI(unsigned int nbElem);
81  virtual float getValue(int index) = 0;
82 
83 private:
84  Q_DISABLE_COPY(pqVectorWidget);
85 };
86 
91 template <class T, unsigned int S>
93 {
94 public:
95  pqVectorWidgetImpl(const T& value, QWidget* parent = nullptr)
96  : pqVectorWidget(value, parent)
97  {
98  // Create the UI with the specified templated number of elements
99  this->CreateUI(S);
100  }
101 
102  T value() const { return this->Vector.template value<T>(); }
103 
104  void setValue(int index, float value) override
105  {
106  T vec = this->Vector.template value<T>();
107  vec[index] = value;
108  this->Vector = QVariant::fromValue(vec);
109  Q_EMIT this->valueChanged(this->Vector);
110  }
111 
112 protected:
113  float getValue(int index) override { return this->Vector.template value<T>()[index]; }
114 };
115 
116 #endif
void setValue(int index, float value) override
Set the value at index index of the QVariant with value.
const QVariant & value() const
Get the value directly in vector form.
pqVectorWidgetImpl(const T &value, QWidget *parent=nullptr)
#define PQWIDGETS_EXPORT
float getValue(int index) override
value
index
pqVectorWidgetImpl is a templated class inherited from pqVectorWidget to be used with QVector classes...
pqVectorWidget is an abstract widget that can be used to edit a vector.