PeriDyno 1.0.0
Loading...
Searching...
No Matches
QVectorIntFieldWidget.h
Go to the documentation of this file.
1
19#pragma once
20#include "QFieldWidget.h"
22#include "Field.h"
23#include <QHBoxLayout>
24#include <QVBoxLayout>
25
26namespace dyno
27{
28
29 class mVectorItemLayout : public QHBoxLayout
30 {
31 Q_OBJECT
32 public:
35 {
36 mId = id;
37
38 index = new QLabel(std::to_string(id).c_str());
39 this->addWidget(index, 0);
40
41 inputSpin = new QSpinBox;
42 inputSpin->setValue(0);
43 this->addWidget(inputSpin, 0);
44
45 removeButton = new QPushButton("Delete");
46 this->addWidget(removeButton, 0);
47
48 //this->layout()->addWidget(index);
49 QObject::connect(removeButton, SIGNAL(pressed()), this, SLOT(emitSignal()));
50 QObject::connect(inputSpin, SIGNAL(valueChanged(int)), this, SLOT(emitChange(int)));
51
52
53 };
54
55
57 {
58 delete inputSpin;
59 delete removeButton;
60 delete index;
61 };
62
63 int value() { return inputSpin->value(); };
64 void setValue(int v) { inputSpin->setValue(v); }
65 void setId(int id) { mId = id; index->setText(std::to_string(id).c_str()); };
66
67 signals:
68 void removeById(int);
69 void valueChange(int);
70
71
72 public slots:
74 {
75 emit removeById(mId);
76 }
77 void emitChange(int v)
78 {
79 emit valueChange(v);
80 }
81
82
83
84 private:
85 int mId = -1;
86 QSpinBox* inputSpin = nullptr;
87 QPushButton* removeButton = nullptr;
88 QLabel* index = nullptr;
89 };
90
91
93 {
94 Q_OBJECT
95 public:
97
99
101
102 signals:
104
105
106 public slots:
107 //Called when the widget is updated
108
110 {
112 if (f != nullptr)
113 {
114 f->setValue(mVec);
115 }
116 };
117
118 //Called when the field is updated
119 void updateWidget();
120
121
122
123 void updateVector(int) { updateVector(); }
124
126 {
127 mVec.clear();
128 for (size_t i = 0; i < allItem.size(); i++)
129 {
130 mVec.push_back(allItem[i]->value());
131 }
132 emit vectorChange();
133 //printField();
134 }
135
137 {
138 mVectorItemLayout* itemLayout = new mVectorItemLayout(allItem.size());
139 QObject::connect(itemLayout, SIGNAL(removeById(int)), this, SLOT(removeItemWidgetById(int)));
140 QObject::connect(itemLayout, SIGNAL(valueChange(int)), this, SLOT(updateVector()));
141
142 mainLayout->addLayout(itemLayout);
143 allItem.push_back(itemLayout);
144
145 updateVector();
146 }
147
148
150 {
151 mainLayout->removeItem(allItem[id]);
152 delete allItem[id];
153 allItem.erase(allItem.begin() + id);
154 for (size_t i = 0; i < allItem.size(); i++)
155 {
156 allItem[i]->setId(i);
157 }
158
159 mainLayout->update();
160
161 updateVector();
162 }
163
164
165 private:
166
167
169 {
170 {
171 mVectorItemLayout* itemLayout = new mVectorItemLayout(allItem.size());
172 itemLayout->setValue(v);
173
174 QObject::connect(itemLayout, SIGNAL(removeById(int)), this, SLOT(removeItemWidgetById(int)));
175 QObject::connect(itemLayout, SIGNAL(valueChange(int)), this, SLOT(updateVector()));
176
177 mainLayout->addLayout(itemLayout);
178 allItem.push_back(itemLayout);
179 };
180 }
181
183 {
184 for (size_t i = 0; i < mVec.size(); i++)
185 {
186 std::cout << mVec[i] << ", ";
187 }
188 std::cout << std::endl;
189 }
190
191
192
193
194 private:
195
196 std::vector<int> mVec;
197
198
199 QVBoxLayout* mainLayout = nullptr;
200
201 std::vector<mVectorItemLayout*> allItem;
202
203
204 };
205
206
207
208}
#define DECLARE_FIELD_WIDGET
void setValue(T val)
Definition Field.h:111
QFieldWidget(FBase *field)
std::vector< mVectorItemLayout * > allItem
DECLARE_FIELD_WIDGET QVectorIntFieldWidget(FBase *field)
DECLARE_FIELD_WIDGET mVectorItemLayout(int id)
TA * cast(TB *b)
Definition Typedef.inl:286
This is an implementation of AdditiveCCD based on peridyno.
Definition Array.h:25