Medical Imaging Interaction Toolkit  2016.11.0
Medical Imaging Interaction Toolkit
QmitkFileReaderOptionsDialog.cpp
Go to the documentation of this file.
1 /*===================================================================
2 
3 The Medical Imaging Interaction Toolkit (MITK)
4 
5 Copyright (c) German Cancer Research Center,
6 Division of Medical and Biological Informatics.
7 All rights reserved.
8 
9 This software is distributed WITHOUT ANY WARRANTY; without
10 even the implied warranty of MERCHANTABILITY or FITNESS FOR
11 A PARTICULAR PURPOSE.
12 
13 See LICENSE.txt or http://www.mitk.org for details.
14 
15 ===================================================================*/
16 
18 #include "ui_QmitkFileReaderOptionsDialog.h"
19 
21 #include "mitkIFileReader.h"
22 
24  : QDialog(parent, Qt::WindowStaysOnTopHint), ui(new Ui::QmitkFileReaderOptionsDialog), m_LoadInfo(loadInfo)
25 
26 {
27  ui->setupUi(this);
28 
29  m_ReaderItems = loadInfo.m_ReaderSelector.Get();
30 
31  bool hasOptions = false;
32  int selectedIndex = 0;
33  long selectedReaderId = loadInfo.m_ReaderSelector.GetSelectedId();
34  int i = 0;
35  for (std::vector<mitk::FileReaderSelector::Item>::const_reverse_iterator iter = m_ReaderItems.rbegin(),
36  iterEnd = m_ReaderItems.rend();
37  iter != iterEnd;
38  ++iter)
39  {
40  ui->m_ReaderComboBox->addItem(QString::fromStdString(iter->GetDescription()));
41  mitk::IFileReader::Options options = iter->GetReader()->GetOptions();
42  if (!options.empty())
43  {
44  hasOptions = true;
45  }
46  ui->m_StackedOptionsWidget->addWidget(new QmitkFileReaderWriterOptionsWidget(options));
47  if (iter->GetServiceId() == selectedReaderId)
48  {
49  selectedIndex = i;
50  }
51  }
52  ui->m_ReaderComboBox->setCurrentIndex(selectedIndex);
53 
54  if (!hasOptions)
55  {
56  ui->m_OptionsBox->setVisible(false);
57  }
58 
59  if (m_ReaderItems.size() < 2)
60  {
61  ui->m_ReaderLabel->setVisible(false);
62  ui->m_ReaderComboBox->setVisible(false);
63  ui->m_FilePathLabel->setText(QString("File: %1").arg(QString::fromStdString(loadInfo.m_Path)));
64  }
65  else
66  {
67  ui->m_FilePathLabel->setText(QString("for %1").arg(QString::fromStdString(loadInfo.m_Path)));
68  }
69 
70  this->setWindowTitle("File reading options");
71 }
72 
74 {
75  delete ui;
76 }
77 
79 {
80  return ui->m_ReuseOptionsCheckBox->isChecked();
81 }
82 
84 {
85  const int index = m_ReaderItems.size() - ui->m_ReaderComboBox->currentIndex() - 1;
86  m_ReaderItems[index].GetReader()->SetOptions(
87  qobject_cast<QmitkFileReaderWriterOptionsWidget *>(ui->m_StackedOptionsWidget->currentWidget())->GetOptions());
88  m_LoadInfo.m_ReaderSelector.Select(m_ReaderItems[index]);
89  QDialog::accept();
90 }
std::vector< Item > Get() const
Get a sorted list of file reader items.
std::map< std::string, us::Any > Options
Options for reading or writing data.
Definition: mitkIFileIO.h:73
std::string m_Path
Definition: mitkIOUtil.h:57
QmitkFileReaderOptionsDialog(mitk::IOUtil::LoadInfo &loadInfo, QWidget *parent=0)
FileReaderSelector m_ReaderSelector
Definition: mitkIOUtil.h:60