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 SimulationElementsDock. |
---|
25 | |
---|
26 | Autor: Alejandro J. Mujica |
---|
27 | Fecha: |
---|
28 | */ |
---|
29 | |
---|
30 | # include <QCloseEvent> |
---|
31 | |
---|
32 | # include <simulationElementsDock.H> |
---|
33 | # include <guiCommon.H> |
---|
34 | |
---|
35 | SimulationElementsDock::SimulationElementsDock(QWidget * _parent) |
---|
36 | : QDockWidget(_parent), selected(NULL) { |
---|
37 | |
---|
38 | setWindowTitle("Elementos a modificar"); |
---|
39 | |
---|
40 | layout.setAlignment(Qt::AlignCenter); |
---|
41 | |
---|
42 | layout.addWidget(&elements, Qt::AlignCenter); |
---|
43 | |
---|
44 | btnRemove.setText("Eliminar"); |
---|
45 | btnRemove.setToolTip("Elimina el elemento selecionado"); |
---|
46 | btnRemove.setFixedWidth(150); |
---|
47 | |
---|
48 | btnLayout.addWidget(&btnRemove, Qt::AlignCenter); |
---|
49 | |
---|
50 | layout.addLayout(&btnLayout, Qt::AlignCenter); |
---|
51 | |
---|
52 | btnTop.setIcon(QIcon(":/icons/go-top-icon")); |
---|
53 | btnTop.setToolTip( |
---|
54 | "Mueve al elemento seleccionado al principio de la lista"); |
---|
55 | layoutMoveControl.addWidget(&btnTop); |
---|
56 | connect(&btnTop, SIGNAL(clicked()), this, SLOT(slotGoFirst())); |
---|
57 | |
---|
58 | btnUp.setIcon(QIcon(":/icons/go-up-icon")); |
---|
59 | btnUp.setToolTip("Mueve al elemento seleccionado una posición hacia arriba"); |
---|
60 | layoutMoveControl.addWidget(&btnUp); |
---|
61 | connect(&btnUp, SIGNAL(clicked()), this, SLOT(slotGoUp())); |
---|
62 | |
---|
63 | btnDown.setIcon(QIcon(":/icons/go-down-icon")); |
---|
64 | btnDown.setToolTip( |
---|
65 | "Mueve al elemento seleccionado una posición hacia abajo"); |
---|
66 | layoutMoveControl.addWidget(&btnDown); |
---|
67 | connect(&btnDown, SIGNAL(clicked()), this, SLOT(slotGoDown())); |
---|
68 | |
---|
69 | btnBottom.setIcon(QIcon(":/icons/go-bottom-icon")); |
---|
70 | btnBottom.setToolTip("Mueve al elemento seleccionado al final de la lista"); |
---|
71 | layoutMoveControl.addWidget(&btnBottom); |
---|
72 | connect(&btnBottom, SIGNAL(clicked()), this, SLOT(slotGoLast())); |
---|
73 | |
---|
74 | layout.addLayout(&layoutMoveControl, Qt::AlignCenter); |
---|
75 | |
---|
76 | widget.setLayout(&layout); |
---|
77 | |
---|
78 | setWidget(&widget); |
---|
79 | setAllowedAreas(Qt::RightDockWidgetArea | Qt::LeftDockWidgetArea); |
---|
80 | |
---|
81 | setButtonsDisabled(); |
---|
82 | |
---|
83 | connect(&elements, SIGNAL(itemClicked(QListWidgetItem*)), |
---|
84 | this, SLOT(slotElementSelected(QListWidgetItem*))); |
---|
85 | connect(&btnRemove, SIGNAL(clicked()), |
---|
86 | this, SLOT(slotRemoveSelectedItem())); |
---|
87 | } |
---|
88 | |
---|
89 | void SimulationElementsDock::loadSimulationList(DynDlist<AlterInfo> & list) { |
---|
90 | |
---|
91 | for (size_t i = 0; i < elements.count(); ++i) { |
---|
92 | |
---|
93 | QListWidgetItem * item = elements.item(i); |
---|
94 | |
---|
95 | Graph::Node * p = |
---|
96 | (Graph::Node *) item->data(Qt::UserRole).toULongLong(); |
---|
97 | |
---|
98 | AlterInfo info; |
---|
99 | |
---|
100 | info.numNode = NODE_COUNTER(p); |
---|
101 | info.value = simPercent(p); |
---|
102 | list.append(info); |
---|
103 | } |
---|
104 | } |
---|
105 | |
---|
106 | void SimulationElementsDock::slotAddElement(Graph::Node * p) { |
---|
107 | |
---|
108 | setButtonsDisabled(); |
---|
109 | |
---|
110 | if (map.search(p) != NULL) |
---|
111 | return; |
---|
112 | |
---|
113 | QString text; |
---|
114 | |
---|
115 | text.append(p->get_info()->getName().c_str()); |
---|
116 | |
---|
117 | if (p->get_info()->getType() == PRODUCT_GOOD) { |
---|
118 | |
---|
119 | text.append(" - "); |
---|
120 | text.append( |
---|
121 | (static_cast <Product *> ( |
---|
122 | p->get_info().get())-> |
---|
123 | getProducerPlant()->getName().c_str())); |
---|
124 | } |
---|
125 | |
---|
126 | QListWidgetItem * item = new QListWidgetItem(text); |
---|
127 | |
---|
128 | item->setData(Qt::UserRole, QVariant((unsigned long long) p)); |
---|
129 | |
---|
130 | elements.addItem(item); |
---|
131 | map.insert(p, item); |
---|
132 | |
---|
133 | selected = item; |
---|
134 | |
---|
135 | elements.setCurrentRow(elements.count() - 1); |
---|
136 | setButtonsEnabled(); |
---|
137 | } |
---|
138 | |
---|
139 | void SimulationElementsDock::slotElementSelected(QListWidgetItem * item) { |
---|
140 | |
---|
141 | setButtonsDisabled(); |
---|
142 | setButtonsEnabled(); |
---|
143 | selected = item; |
---|
144 | setButtonsEnabled(); |
---|
145 | |
---|
146 | Graph::Node * p = (Graph::Node *) item->data(Qt::UserRole).toULongLong(); |
---|
147 | |
---|
148 | emit signalItemSelected(p); |
---|
149 | } |
---|
150 | |
---|
151 | void SimulationElementsDock::slotSvgPanelClicked(Graph::Node * p) { |
---|
152 | |
---|
153 | setButtonsDisabled(); |
---|
154 | |
---|
155 | if (selected != NULL) |
---|
156 | elements.setCurrentRow(-1); |
---|
157 | |
---|
158 | selected = NULL; |
---|
159 | |
---|
160 | if (p == NULL) |
---|
161 | return; |
---|
162 | |
---|
163 | QListWidgetItem ** ptrItem = map.search(p); |
---|
164 | |
---|
165 | if (ptrItem == NULL) |
---|
166 | return; |
---|
167 | |
---|
168 | selected = *ptrItem; |
---|
169 | elements.setCurrentRow(elements.row(selected)); |
---|
170 | setButtonsEnabled(); |
---|
171 | } |
---|
172 | |
---|
173 | void SimulationElementsDock::slotRemoveSelectedItem() { |
---|
174 | |
---|
175 | I(selected != NULL); |
---|
176 | |
---|
177 | Graph::Node * p = |
---|
178 | (Graph::Node *) selected->data(Qt::UserRole).toULongLong(); |
---|
179 | |
---|
180 | map.remove(p); |
---|
181 | elements.removeItemWidget(selected); |
---|
182 | delete selected; |
---|
183 | selected = NULL; |
---|
184 | setButtonsDisabled(); |
---|
185 | elements.setCurrentRow(-1); |
---|
186 | } |
---|
187 | |
---|
188 | void SimulationElementsDock::slotGoFirst() { |
---|
189 | |
---|
190 | setButtonsDisabled(); |
---|
191 | |
---|
192 | int row = elements.currentRow(); |
---|
193 | |
---|
194 | QListWidgetItem * item = elements.takeItem(row); |
---|
195 | |
---|
196 | elements.insertItem(0, item); |
---|
197 | elements.setCurrentRow(0); |
---|
198 | |
---|
199 | setButtonsEnabled(); |
---|
200 | } |
---|
201 | |
---|
202 | void SimulationElementsDock::slotGoUp() { |
---|
203 | |
---|
204 | setButtonsDisabled(); |
---|
205 | |
---|
206 | int row = elements.currentRow(); |
---|
207 | |
---|
208 | QListWidgetItem * item = elements.takeItem(row); |
---|
209 | |
---|
210 | elements.insertItem(row - 1, item); |
---|
211 | elements.setCurrentRow(row - 1); |
---|
212 | |
---|
213 | setButtonsEnabled(); |
---|
214 | } |
---|
215 | |
---|
216 | void SimulationElementsDock::slotGoDown() { |
---|
217 | |
---|
218 | setButtonsDisabled(); |
---|
219 | |
---|
220 | int row = elements.currentRow(); |
---|
221 | |
---|
222 | QListWidgetItem * item = elements.takeItem(row); |
---|
223 | |
---|
224 | elements.insertItem(row + 1, item); |
---|
225 | elements.setCurrentRow(row + 1); |
---|
226 | |
---|
227 | setButtonsEnabled(); |
---|
228 | } |
---|
229 | |
---|
230 | void SimulationElementsDock::slotGoLast() { |
---|
231 | |
---|
232 | setButtonsDisabled(); |
---|
233 | |
---|
234 | int row = elements.currentRow(); |
---|
235 | |
---|
236 | QListWidgetItem * item = elements.takeItem(row); |
---|
237 | |
---|
238 | elements.insertItem(elements.count(), item); |
---|
239 | elements.setCurrentRow(elements.count() - 1); |
---|
240 | |
---|
241 | setButtonsEnabled(); |
---|
242 | } |
---|
243 | |
---|
244 | void SimulationElementsDock::closeEvent(QCloseEvent * evt) { |
---|
245 | emit signalClosing(); |
---|
246 | evt->ignore(); |
---|
247 | } |
---|
248 | |
---|
249 | void SimulationElementsDock::setButtonsEnabled() { |
---|
250 | |
---|
251 | btnRemove.setEnabled(true); |
---|
252 | |
---|
253 | if (elements.currentRow() > 0) { |
---|
254 | btnTop.setEnabled(true); |
---|
255 | btnUp.setEnabled(true); |
---|
256 | } |
---|
257 | |
---|
258 | if (elements.currentRow() < elements.count() - 1) { |
---|
259 | btnDown.setEnabled(true); |
---|
260 | btnBottom.setEnabled(true); |
---|
261 | } |
---|
262 | } |
---|
263 | |
---|
264 | void SimulationElementsDock::setButtonsDisabled() { |
---|
265 | btnRemove.setEnabled(false); |
---|
266 | btnTop.setEnabled(false); |
---|
267 | btnUp.setEnabled(false); |
---|
268 | btnDown.setEnabled(false); |
---|
269 | btnBottom.setEnabled(false); |
---|
270 | } |
---|