1 | /* |
---|
2 | Copyright (C) 2012 |
---|
3 | Alejandro Mujica (amujica@cenditel.gob.ve) |
---|
4 | Erwin Paredes (eparedes@cenditel.gob.ve) |
---|
5 | José Ruiz (jruiz@cenditel.gob.ve) |
---|
6 | Rodolfo Rangel (rrangel@cenditel.gob.ve) |
---|
7 | Julie Vera (jvera@cenditel.gob.ve) |
---|
8 | |
---|
9 | CENDITEL Fundación Centro Nacional de Desarrollo e Investigación en |
---|
10 | Tecnologías Libres |
---|
11 | |
---|
12 | Este programa es software libre; Usted puede usarlo bajo los términos de la |
---|
13 | licencia de software GPL versión 2.0 de la Free Software Foundation. |
---|
14 | |
---|
15 | Este programa se distribuye con la esperanza de que sea útil, pero SIN |
---|
16 | NINGUNA GARANTÍA; tampoco las implícitas garantías de MERCANTILIDAD o |
---|
17 | ADECUACIÓN A UN PROPÓSITO PARTICULAR. |
---|
18 | Consulte la licencia GPL para más detalles. Usted debe recibir una copia |
---|
19 | de la GPL junto con este programa; si no, escriba a la Free Software |
---|
20 | Foundation Inc. 51 Franklin Street,5 Piso, Boston, MA 02110-1301, USA. |
---|
21 | */ |
---|
22 | |
---|
23 | /* |
---|
24 | Este archivo contiene la implementación de la clase SimulationDataDock. |
---|
25 | |
---|
26 | Autor: Alejandro J. Mujica |
---|
27 | Fecha: |
---|
28 | */ |
---|
29 | |
---|
30 | # include <QCloseEvent> |
---|
31 | # include <QValidator> |
---|
32 | |
---|
33 | # include <simulationDataDock.H> |
---|
34 | |
---|
35 | # include <guiCommon.H> |
---|
36 | |
---|
37 | # include <simType.H> |
---|
38 | |
---|
39 | const size_t SimulationDataDock::WIDHT_LBL = 80; |
---|
40 | |
---|
41 | const size_t SimulationDataDock::WIDTH_EDT = 150; |
---|
42 | |
---|
43 | SimulationDataDock::SimulationDataDock(QWidget * _parent) |
---|
44 | : QDockWidget(_parent), node(NULL) { |
---|
45 | |
---|
46 | QDoubleValidator * percent_validator = new QDoubleValidator(&edtPercent); |
---|
47 | |
---|
48 | double lowLimitDbl = SimType::getInstance().getType() == COST_CHANGE ? |
---|
49 | -99.9 : 0.0; |
---|
50 | |
---|
51 | percent_validator->setBottom(lowLimitDbl); |
---|
52 | percent_validator->setTop(999.9); |
---|
53 | percent_validator->setNotation(QDoubleValidator::StandardNotation); |
---|
54 | |
---|
55 | mainLayout.setAlignment(Qt::AlignCenter); |
---|
56 | |
---|
57 | lblValue.setText("Valor"); |
---|
58 | lblValue.setFixedWidth(WIDHT_LBL); |
---|
59 | edtValue.setReadOnly(true); |
---|
60 | edtValue.setFixedWidth(WIDTH_EDT); |
---|
61 | |
---|
62 | valueLayout.addWidget(&lblValue); |
---|
63 | valueLayout.addWidget(&edtValue); |
---|
64 | |
---|
65 | mainLayout.addLayout(&valueLayout); |
---|
66 | |
---|
67 | lblPercent.setText("Porcentaje"); |
---|
68 | lblPercent.setFixedWidth(WIDHT_LBL); |
---|
69 | edtPercent.setValidator(percent_validator); |
---|
70 | edtPercent.setFixedWidth(WIDTH_EDT); |
---|
71 | |
---|
72 | percentLayout.addWidget(&lblPercent); |
---|
73 | percentLayout.addWidget(&edtPercent); |
---|
74 | |
---|
75 | mainLayout.addLayout(&percentLayout); |
---|
76 | |
---|
77 | int lowLimit = SimType::getInstance().getType() == COST_CHANGE ? -9999 : 0; |
---|
78 | |
---|
79 | slider.setRange(lowLimit, 99999); |
---|
80 | slider.setOrientation(Qt::Horizontal); |
---|
81 | mainLayout.addWidget(&slider); |
---|
82 | |
---|
83 | btnAdd.setText("Añadir"); |
---|
84 | btnAdd.setToolTip("Asigna el nodo seleccionado a la lista de simulación"); |
---|
85 | |
---|
86 | mainLayout.addWidget(&btnAdd); |
---|
87 | |
---|
88 | widget.setLayout(&mainLayout); |
---|
89 | |
---|
90 | setFixedHeight(200); |
---|
91 | setWidget(&widget); |
---|
92 | setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea); |
---|
93 | |
---|
94 | reset(); |
---|
95 | setEnabled(false); |
---|
96 | |
---|
97 | setWindowTitle("Aumento / Disminución"); |
---|
98 | |
---|
99 | connect(&btnAdd, SIGNAL(clicked()), this, SLOT(slotBtnAddPushed())); |
---|
100 | } |
---|
101 | |
---|
102 | void SimulationDataDock::slotSvgPanelClicked(Graph::Node * node) { |
---|
103 | |
---|
104 | this->node = node; |
---|
105 | |
---|
106 | disconnectPrivateSlots(); |
---|
107 | |
---|
108 | reset(); |
---|
109 | |
---|
110 | if (this->node == NULL) { |
---|
111 | |
---|
112 | setEnabled(false); |
---|
113 | return; |
---|
114 | } |
---|
115 | |
---|
116 | connectPrivateSlots(); |
---|
117 | |
---|
118 | setEnabled(true); |
---|
119 | |
---|
120 | if (node->get_info()->getType() == INPUT_GOOD) |
---|
121 | edtValue.setEnabled(false); |
---|
122 | |
---|
123 | edtPercent.setText(QString(numtostr(simPercent(node)).c_str())); |
---|
124 | |
---|
125 | slotEdtPercentEdited(edtPercent.text()); |
---|
126 | } |
---|
127 | |
---|
128 | void SimulationDataDock::closeEvent(QCloseEvent * evt) { |
---|
129 | emit signalClosing(); |
---|
130 | evt->ignore(); |
---|
131 | } |
---|
132 | |
---|
133 | void SimulationDataDock::slotEdtPercentEdited(QString strPercent) { |
---|
134 | |
---|
135 | I(node != NULL); |
---|
136 | |
---|
137 | strPercent.replace(',', '.'); |
---|
138 | |
---|
139 | double per = strPercent.toDouble(); |
---|
140 | |
---|
141 | double val = SimType::getInstance().getType() == COST_CHANGE ? |
---|
142 | node->get_info()->getUnitarianPrice() * per / 100.0 : |
---|
143 | node->get_info()->getQuantity() * per / 100.0; |
---|
144 | |
---|
145 | edtValue.setText(QString(numtostr(val).c_str())); |
---|
146 | |
---|
147 | slider.setValue(int(per) * 100.0); |
---|
148 | } |
---|
149 | |
---|
150 | void SimulationDataDock::slotSliderMoved(int intPercent) { |
---|
151 | |
---|
152 | I(node != NULL); |
---|
153 | |
---|
154 | double per = double(intPercent) / 100.0; |
---|
155 | |
---|
156 | double val = SimType::getInstance().getType() == COST_CHANGE ? |
---|
157 | node->get_info()->getUnitarianPrice() * per / 100.0 : |
---|
158 | node->get_info()->getQuantity() * per / 100.0; |
---|
159 | |
---|
160 | edtValue.setText(QString(numtostr(val).c_str())); |
---|
161 | |
---|
162 | edtPercent.setText(locale.toString(per)); |
---|
163 | } |
---|
164 | |
---|
165 | void SimulationDataDock::slotBtnAddPushed() { |
---|
166 | |
---|
167 | double per = locale.toDouble(edtPercent.text()); |
---|
168 | |
---|
169 | if (per == 0) |
---|
170 | return; |
---|
171 | |
---|
172 | simPercent(node) = per; |
---|
173 | |
---|
174 | emit signalAddElement(node); |
---|
175 | } |
---|
176 | |
---|
177 | void SimulationDataDock::reset() { |
---|
178 | edtValue.setText("0"); |
---|
179 | edtPercent.setText("0"); |
---|
180 | slider.setValue(0); |
---|
181 | } |
---|
182 | |
---|
183 | void SimulationDataDock::setEnabled(bool enabled) { |
---|
184 | edtValue.setEnabled(enabled); |
---|
185 | edtPercent.setEnabled(enabled); |
---|
186 | slider.setEnabled(enabled); |
---|
187 | btnAdd.setEnabled(enabled); |
---|
188 | } |
---|
189 | |
---|
190 | void SimulationDataDock::connectPrivateSlots() { |
---|
191 | |
---|
192 | connect(&edtPercent, SIGNAL(textEdited(QString)), |
---|
193 | this, SLOT(slotEdtPercentEdited(QString))); |
---|
194 | |
---|
195 | connect(&slider, SIGNAL(sliderMoved(int)), |
---|
196 | this, SLOT(slotSliderMoved(int))); |
---|
197 | } |
---|
198 | |
---|
199 | void SimulationDataDock::disconnectPrivateSlots() { |
---|
200 | |
---|
201 | disconnect(&edtPercent, SIGNAL(textEdited(QString)), |
---|
202 | this, SLOT(slotEdtPercentEdited(QString))); |
---|
203 | |
---|
204 | disconnect(&slider, SIGNAL(sliderMoved(int)), |
---|
205 | this, SLOT(slotSliderMoved(int))); |
---|
206 | } |
---|