1 | #include "ComboBox.h"
|
---|
2 | #include "Layout.h"
|
---|
3 | #include <QComboBox>
|
---|
4 | #include <QFormLayout>
|
---|
5 |
|
---|
6 | ComboBox::ComboBox(Layout* parent,int row, int col,QString name,int value): FormLayout(parent,row,col,name,"ComboBox")
|
---|
7 | {
|
---|
8 | combobox = new QComboBox();
|
---|
9 | combobox->setCurrentIndex(value);
|
---|
10 |
|
---|
11 | combobox_value=value;
|
---|
12 |
|
---|
13 | object_layout->addRow(name,combobox);
|
---|
14 |
|
---|
15 | connect(combobox,SIGNAL(currentIndexChanged(int)),this, SLOT(valuechanged(int)));
|
---|
16 |
|
---|
17 | SetValue(QString::number(combobox_value));
|
---|
18 |
|
---|
19 | //pour ne pas faire de doublons qd on ajoute des items
|
---|
20 | SetIsExpandable(true);
|
---|
21 | }
|
---|
22 |
|
---|
23 | ComboBox::~ComboBox()
|
---|
24 | {
|
---|
25 | delete combobox;
|
---|
26 | }
|
---|
27 |
|
---|
28 | void ComboBox::XmlEvent(QDomElement dom)
|
---|
29 | {
|
---|
30 | if(dom.attribute("item")!="") {
|
---|
31 | QString item=dom.attribute("item");
|
---|
32 | combobox->addItem(item);
|
---|
33 | combobox->setCurrentIndex(combobox_value);
|
---|
34 | }
|
---|
35 | }
|
---|
36 |
|
---|
37 | void ComboBox::SetUptodate(void)
|
---|
38 | {
|
---|
39 | ui_to_var();
|
---|
40 | ui_to_xml();
|
---|
41 | visible_widget->setPalette(black_pal);
|
---|
42 |
|
---|
43 | }
|
---|
44 |
|
---|
45 | void ComboBox::ui_to_var(void)
|
---|
46 | {
|
---|
47 | combobox_value=combobox->currentIndex();
|
---|
48 | }
|
---|
49 |
|
---|
50 | void ComboBox::ui_to_xml(void)
|
---|
51 | {
|
---|
52 | SetValue(QString::number(combobox->currentIndex()));
|
---|
53 | }
|
---|
54 |
|
---|
55 | void ComboBox::Reset(void)
|
---|
56 | {
|
---|
57 | combobox->setCurrentIndex(combobox_value);
|
---|
58 | }
|
---|
59 |
|
---|
60 | void ComboBox::LoadEvent(QDomElement dom)
|
---|
61 | {
|
---|
62 | if(combobox->isEnabled()==true)
|
---|
63 | {
|
---|
64 | combobox->setCurrentIndex((dom.attribute("value")).toInt());
|
---|
65 | }
|
---|
66 | }
|
---|
67 |
|
---|
68 | void ComboBox::valuechanged(int value)
|
---|
69 | {
|
---|
70 | if(value!=combobox_value)
|
---|
71 | {
|
---|
72 | visible_widget->setPalette(red_pal);
|
---|
73 | }
|
---|
74 | else
|
---|
75 | {
|
---|
76 | visible_widget->setPalette(black_pal);
|
---|
77 | }
|
---|
78 | }
|
---|