Orfeo Toolbox  3.16
otbWrapperQtWidgetInputVectorDataListParameter.cxx
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: ORFEO Toolbox
4  Language: C++
5  Date: $Date$
6  Version: $Revision$
7 
8 
9  Copyright (c) Centre National d'Etudes Spatiales. All rights reserved.
10  See OTBCopyright.txt for details.
11 
12 
13  This software is distributed WITHOUT ANY WARRANTY; without even
14  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15  PURPOSE. See the above copyright notices for more information.
16 
17 =========================================================================*/
19 
20 namespace otb
21 {
22 namespace Wrapper
23 {
24 
26  QtWidgetModel* m)
27 : QtWidgetParameterBase(param, m),
28  m_InputVectorDataListParam(param)
29 {
30  connect(this, SIGNAL(Change()), GetModel(), SLOT(NotifyUpdate()));
31 }
32 
34 {
35 }
36 
38 {
39 
40 }
41 
43 {
44  m_FileSelectionList.clear();
45  const unsigned int sp(2);
46  const unsigned int buttonSize(30);
47 
48  // Global layout
49  QHBoxLayout * hLayout = new QHBoxLayout;
50  hLayout->setSpacing(sp);
51  hLayout->setContentsMargins(sp, sp, sp, sp);
52 
53  // Button layout
54  QVBoxLayout * buttonLayout = new QVBoxLayout;
55  buttonLayout->setSpacing(sp);
56  buttonLayout->setContentsMargins(sp, sp, sp, sp);
57 
58  QHBoxLayout * addSupLayout = new QHBoxLayout;
59  addSupLayout->setSpacing(sp);
60  addSupLayout->setContentsMargins(sp, sp, sp, sp);
61 
62  QHBoxLayout * upDownLayout = new QHBoxLayout;
63  upDownLayout->setSpacing(sp);
64  upDownLayout->setContentsMargins(sp, sp, sp, sp);
65 
66  // Add file button
67  QPushButton * addButton = new QPushButton;
68  addButton->setText("+");
69  addButton->setFixedWidth(buttonSize);
70  addButton->setToolTip("Add a file selector...");
71  connect(addButton, SIGNAL(clicked()), this, SLOT(AddFile()));
72  addSupLayout->addWidget(addButton);
73 
74  // Supress file button
75  QPushButton * supButton = new QPushButton;
76  supButton->setText("-");
77  supButton->setFixedWidth(buttonSize);
78  supButton->setToolTip("Supress the selected file...");
79  connect(supButton, SIGNAL(clicked()), this, SLOT(SupressFile()));
80  addSupLayout->addWidget(supButton);
81  buttonLayout->addLayout(addSupLayout);
82 
83  // Up file edit
84  QPushButton * upButton = new QPushButton;
85  upButton->setText("Up");
86  upButton->setFixedWidth(buttonSize);
87  upButton->setToolTip("Up the selected file in the list...");
88  connect(upButton, SIGNAL(clicked()), this, SLOT(UpFile()));
89  upDownLayout->addWidget(upButton);
90 
91  // Down file edit
92  QPushButton * downButton = new QPushButton;
93  downButton->setText("Down");
94  downButton->setFixedWidth(buttonSize);
95  downButton->setToolTip("Down the selected file in the list...");
96  connect(downButton, SIGNAL(clicked()), this, SLOT(DownFile()));
97  upDownLayout->addWidget(downButton);
98  buttonLayout->addLayout(upDownLayout);
99 
100  // Erase file edit
101  QPushButton * eraseButton = new QPushButton;
102  eraseButton->setText("Erase");
103  eraseButton->setFixedWidth(2*(buttonSize+sp));
104  eraseButton->setToolTip("Erase the selected file of the list...");
105  connect(eraseButton, SIGNAL(clicked()), this, SLOT(EraseFile()));
106  buttonLayout->addWidget(eraseButton);
107 
108  QVBoxLayout * fileLayout = new QVBoxLayout();
109  fileLayout->setSpacing(0);
110 
111  QtFileSelectionWidget * fileSelection = new QtFileSelectionWidget();
112  fileSelection->setFixedHeight(30);
113  fileLayout->addWidget(fileSelection);
114  m_InputVectorDataListParam->AddNullElement();
115  connect(fileSelection->GetInput(), SIGNAL(textChanged(const QString&)), this, SLOT(UpdateVectorDataList()));
116 
117  m_FileSelectionList.push_back(fileSelection);
118 
119  QGroupBox *mainGroup = new QGroupBox();
120  mainGroup->setLayout(fileLayout);
121  QScrollArea * scroll = new QScrollArea();
122  scroll->setWidget(mainGroup);
123  scroll->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
124  scroll->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn);
125  scroll->setWidgetResizable(true);
126 
127  hLayout->addWidget(scroll);
128  hLayout->addLayout(buttonLayout);
129 
130  this->setLayout(hLayout);
131 
132  m_FileLayout = fileLayout;
133  m_HLayout = hLayout;
134  m_Scroll = scroll;
135 
136 }
137 
138 void
140 {
141  for(unsigned int j = 0; j < m_InputVectorDataListParam->GetVectorDataList()->Size(); j++)
142  {
143  if(m_InputVectorDataListParam->SetNthFileName(j, m_FileSelectionList[j]->GetFilename()) == false)
144  {
145  std::ostringstream oss;
146  oss << "The given file " << m_FileSelectionList[j]->GetFilename() << " is not valid.";
147  this->GetModel()->SendLogWARNING(oss.str());
148  }
149  }
150 
151  emit Change();
152 }
153 
154 
155 void
157 {
158  if(m_FileSelectionList.size() < 2)
159  return;
160 
161  m_FileLayout = new QVBoxLayout();
162  m_FileLayout->setSpacing(2);
163 
164  // Map link between old and new index in the list
165  std::map<unsigned int, unsigned int> idMap;
166 
167  // Init map
168  for(unsigned int i = 0; i < m_FileSelectionList.size(); i++)
169  {
170  idMap[i] = i;
171  }
172 
173  // If the first item is checked, uncheck it...
174  // It won't be moved
175  if(m_FileSelectionList[0]->IsChecked())
176  {
177  m_FileSelectionList[0]->SetChecked(false);
178  }
179 
180 
181  // If other item are checked, up the index
182  // Starts at 1 because the first item mustn't move
183  for(unsigned int i = 1; i < m_FileSelectionList.size(); i++)
184  {
185  if(m_FileSelectionList[i]->IsChecked())
186  {
187  unsigned int tmp = idMap[i];
188  idMap[i] = i-1;
189  idMap[idMap[i-1]] = tmp;
190  }
191  }
192 
193  this->UpdateFileList(idMap);
194 
195  this->RecreateVectorDataList();
196 }
197 
198 void
200 {
201  if(m_FileSelectionList.size() < 2) return;
202 
203  m_FileLayout = new QVBoxLayout();
204  m_FileLayout->setSpacing(0);
205 
206  // Map link between old and new index in the list
207  std::map<unsigned int, unsigned int> idMap;
208 
209  // Init map
210  for(unsigned int i = 0; i < m_FileSelectionList.size(); i++)
211  {
212  idMap[i] = i;
213  }
214 
215  // If the last item is checked, uncheck it...
216  // It won't be moved
217  if(m_FileSelectionList[m_FileSelectionList.size() - 1]->IsChecked())
218  {
219  m_FileSelectionList[m_FileSelectionList.size() - 1]->SetChecked(false);
220  }
221 
222  // If other item are checked, up the index
223  // Stops at size-1 because the last item mustn't move
224  for(int i = m_FileSelectionList.size() - 2; i >= 0; i--)
225  {
226  if(m_FileSelectionList[i]->IsChecked())
227  {
228  unsigned int tmp = idMap[i];
229  idMap[i] = i + 1;
230  idMap[idMap[i + 1]] = tmp;
231  }
232  }
233 
234  this->UpdateFileList(idMap);
235 
236  this->RecreateVectorDataList();
237 }
238 
239 
240 void
241 QtWidgetInputVectorDataListParameter::UpdateFileList(std::map<unsigned int, unsigned int> idMap)
242 {
243  std::vector<QtFileSelectionWidget *> tmpList;
244  // Keys become values and inverse
245  std::map<unsigned int, unsigned int> idMapBis;
246  for(unsigned int i = 0; i < idMap.size(); i++)
247  {
248  idMapBis[idMap[i]] = i;
249  }
250 
251  // Create the new item list
252  for(unsigned int i = 0; i < m_FileSelectionList.size(); i++)
253  {
254  m_FileLayout->addWidget(m_FileSelectionList[idMapBis[i]]);
255  tmpList.push_back(m_FileSelectionList[idMapBis[i]]);
256  }
257 
258  m_FileSelectionList = tmpList;
259  QGroupBox *mainGroup = new QGroupBox();
260  mainGroup->setLayout(m_FileLayout);
261  m_Scroll->setWidget(mainGroup);
262 
263  this->update();
264 
265  // notify of value change
266  QString key(m_InputVectorDataListParam->GetKey());
267  emit ParameterChanged(key);
268 }
269 
270 
271 void
273 {
274  m_FileLayout = new QVBoxLayout();
275  m_FileLayout->setSpacing(0);
276 
277  for(unsigned int i = 0; i < m_FileSelectionList.size(); i++)
278  {
279  m_FileLayout->addWidget(m_FileSelectionList[i]);
280  }
281 
282  QtFileSelectionWidget * fileSelection = new QtFileSelectionWidget();
283  fileSelection->setFixedHeight(30);
284  m_FileLayout->addWidget(fileSelection);
285  m_FileSelectionList.push_back(fileSelection);
286  m_InputVectorDataListParam->AddNullElement();
287  connect(fileSelection->GetInput(), SIGNAL(textChanged(const QString&)), this, SLOT(UpdateVectorDataList()));
288 
289  QGroupBox *mainGroup = new QGroupBox();
290  mainGroup->setLayout(m_FileLayout);
291  m_Scroll->setWidget(mainGroup);
292 
293  this->update();
294 }
295 
296 void
298 {
299  m_FileLayout = new QVBoxLayout();
300  m_FileLayout->setSpacing(0);
301  std::vector<QtFileSelectionWidget *> tmpList;
302  for(unsigned int i = 0; i < m_FileSelectionList.size(); i++)
303  {
304  if(!m_FileSelectionList[i]->IsChecked())
305  {
306  m_FileLayout->addWidget(m_FileSelectionList[i]);
307  tmpList.push_back(m_FileSelectionList[i]);
308  }
309  }
310 
311  m_FileSelectionList = tmpList;
312 
313  QGroupBox *mainGroup = new QGroupBox();
314  mainGroup->setLayout(m_FileLayout);
315  m_Scroll->setWidget(mainGroup);
316 
317  this->update();
318  this->RecreateVectorDataList();
319 }
320 
321 
322 void
324 {
325  m_FileSelectionList.clear();
326 
327  m_FileLayout = new QVBoxLayout();
328 
329  QtFileSelectionWidget * fileSelection = new QtFileSelectionWidget();
330  fileSelection->setFixedHeight(30);
331  m_FileLayout->addWidget(fileSelection);
332  m_FileSelectionList.push_back(fileSelection);
333  m_InputVectorDataListParam->AddNullElement();
334  connect(fileSelection->GetInput(), SIGNAL(textChanged(const QString&)), this, SLOT(UpdateVectorDataList()));
335 
336  QGroupBox *mainGroup = new QGroupBox();
337  mainGroup->setLayout(m_FileLayout);
338  m_Scroll->setWidget(mainGroup);
339 
340  this->update();
341  this->RecreateVectorDataList();
342 }
343 
344 
346 {
347  // save value
348  m_InputVectorDataListParam->ClearValue();
349 
350  if(m_FileSelectionList.size() == 0)
351  {
352  this->AddFile();
353  }
354  else
355  {
356  for(unsigned int j = 0; j < m_FileSelectionList.size(); j++)
357  {
358  m_InputVectorDataListParam->AddFromFileName(m_FileSelectionList[j]->GetFilename());
359  connect(m_FileSelectionList[j]->GetInput(), SIGNAL(textChanged(const QString&)),
360  this, SLOT(UpdateVectorDataList()));
361  }
362 
363  emit Change();
364  // notify of value change
365  QString key(m_InputVectorDataListParam->GetKey());
366  emit ParameterChanged(key);
367  }
368 }
369 
370 
371 }
372 }

Generated at Sun May 19 2013 01:01:50 for Orfeo Toolbox with doxygen 1.8.3.1