pqVectorWidget.h
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: Copyright (c) Kitware Inc.
2 // SPDX-FileCopyrightText: Copyright (c) Sandia Corporation
3 // SPDX-License-Identifier: BSD-3-Clause
4 #ifndef pqVectorWidget_h
5 #define pqVectorWidget_h
6 
7 #include "pqWidgetsModule.h"
8 
9 #include <QVariant>
10 #include <QVector2D>
11 #include <QVector3D>
12 #include <QWidget>
13 
17 class PQWIDGETS_EXPORT pqVectorWidget : public QWidget
18 {
19  Q_OBJECT
20  Q_PROPERTY(QVariant value READ value USER true);
21 
22 public:
23  pqVectorWidget(const QVariant& value, QWidget* parent = nullptr);
24  ~pqVectorWidget() override = default;
25 
29  const QVariant& value() const { return this->Vector; }
30 
31 Q_SIGNALS:
35  void valueChanged(const QVariant&);
36 
37 public Q_SLOTS:
38 
43  virtual void setValue(int index, float value) = 0;
44 
45 protected:
46  QVariant Vector;
47 
52  void CreateUI(unsigned int nbElem);
53  virtual float getValue(int index) = 0;
54 
55 private:
56  Q_DISABLE_COPY(pqVectorWidget);
57 };
58 
63 template <class T, unsigned int S>
65 {
66 public:
67  pqVectorWidgetImpl(const T& value, QWidget* parent = nullptr)
68  : pqVectorWidget(value, parent)
69  {
70  // Create the UI with the specified templated number of elements
71  this->CreateUI(S);
72  }
73 
74  T value() const { return this->Vector.template value<T>(); }
75 
76  void setValue(int index, float value) override
77  {
78  T vec = this->Vector.template value<T>();
79  vec[index] = value;
80  this->Vector = QVariant::fromValue(vec);
81  Q_EMIT this->valueChanged(this->Vector);
82  }
83 
84 protected:
85  float getValue(int index) override { return this->Vector.template value<T>()[index]; }
86 };
87 
88 #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.