PeriDyno 1.0.0
Loading...
Searching...
No Matches
QEnumFieldWidget.cpp
Go to the documentation of this file.
1#include "QEnumFieldWidget.h"
2
3#include <QHBoxLayout>
4#include <QComboBox>
5
6#include "DeclareEnum.h"
7
8namespace dyno
9{
11
14 {
16 if (f == nullptr || f->constDataPtr() == nullptr) {
17 return;
18 }
19
20 QHBoxLayout* layout = new QHBoxLayout;
21 layout->setContentsMargins(0, 0, 0, 0);
22 layout->setSpacing(0);
23
24 QLabel* name = new QLabel();
25 name->setFixedHeight(24);
26 name->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
27 name->setText(FormatFieldWidgetName(field->getObjectName()));
28 layout->addWidget(name, 0);
29
30 QComboBox* combox = new QComboBox;
31 combox->setMaximumWidth(256);
32
33 auto& enums = f->constDataPtr()->enumMap();
34 int num = 0;
35 int curIndex = 0;
36 for (auto e : enums)
37 {
38 mComboxIndexMap[num] = e.first;
39 combox->addItem(QString::fromStdString(e.second));
40
41 if (e.first == f->constDataPtr()->currentKey()) {
42 curIndex = num;
43 }
44
45 num++;
46 }
47
48 combox->setCurrentIndex(curIndex);
49
50 layout->addWidget(combox, 1);
51
52 this->setLayout(layout);
53
54 connect(combox, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged), this, &QEnumFieldWidget::updateField);
55 }
56
58 {
60 if (f == nullptr || f->constDataPtr() == nullptr) {
61 return;
62 }
63
64 auto& enums = f->getDataPtr()->enumMap();
65
66 f->getDataPtr()->setCurrentKey(mComboxIndexMap[index]);
67 //To notify the field is updated
68 f->update();
69 }
70}
#define IMPL_FIELD_WIDGET(_data_type_, _type_)
for(uint32_t i=0;i< queueCount;i++)
std::map< int, int > mComboxIndexMap
DECLARE_FIELD_WIDGET QEnumFieldWidget(FBase *field)
QFieldWidget(FBase *field)
TA * cast(TB *b)
Definition Typedef.inl:286
This is an implementation of AdditiveCCD based on peridyno.
Definition Array.h:25
QString FormatFieldWidgetName(std::string name)
Definition Format.cpp:9