Medical Imaging Interaction Toolkit  2016.11.0
Medical Imaging Interaction Toolkit
QmitkFileWriterOptionsDialog.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_QmitkFileWriterOptionsDialog.h"
19 
21 #include "mitkFileWriterSelector.h"
22 #include "mitkIFileWriter.h"
23 
25  : QDialog(parent), ui(new Ui::QmitkFileWriterOptionsDialog), m_SaveInfo(saveInfo)
26 {
27  ui->setupUi(this);
28 
29  m_WriterItems = saveInfo.m_WriterSelector.Get(saveInfo.m_MimeType.GetName());
30 
31  bool hasOptions = false;
32  int selectedIndex = 0;
33  long selectedWriterId = saveInfo.m_WriterSelector.GetSelectedId();
34  int i = 0;
35  // Fill the combo box such that at the first entry is the best matching writer
36  for (std::vector<mitk::FileWriterSelector::Item>::const_reverse_iterator iter = m_WriterItems.rbegin(),
37  iterEnd = m_WriterItems.rend();
38  iter != iterEnd;
39  ++iter, ++i)
40  {
41  ui->m_WriterComboBox->addItem(QString::fromStdString(iter->GetDescription()));
42  mitk::IFileWriter::Options options = iter->GetWriter()->GetOptions();
43  if (!options.empty())
44  {
45  hasOptions = true;
46  }
47  ui->m_StackedOptionsWidget->addWidget(new QmitkFileReaderWriterOptionsWidget(options));
48  if (iter->GetServiceId() == selectedWriterId)
49  {
50  selectedIndex = i;
51  }
52  }
53  ui->m_WriterComboBox->setCurrentIndex(selectedIndex);
54 
55  if (!hasOptions)
56  {
57  ui->m_OptionsBox->setVisible(false);
58  }
59 
60  if (m_WriterItems.size() < 2)
61  {
62  ui->m_WriterLabel->setVisible(false);
63  ui->m_WriterComboBox->setVisible(false);
64  ui->m_FilePathLabel->setText(QString("File: %1").arg(QString::fromStdString(saveInfo.m_Path)));
65  }
66  else
67  {
68  ui->m_FilePathLabel->setText(QString("for %1").arg(QString::fromStdString(saveInfo.m_Path)));
69  }
70 
71  this->setWindowTitle("File writing options");
72 }
73 
75 {
76  delete ui;
77 }
78 
80 {
81  return ui->m_ReuseOptionsCheckBox->isChecked();
82 }
83 
85 {
86  const int index = m_WriterItems.size() - ui->m_WriterComboBox->currentIndex() - 1;
87  m_WriterItems[index].GetWriter()->SetOptions(
88  qobject_cast<QmitkFileReaderWriterOptionsWidget *>(ui->m_StackedOptionsWidget->currentWidget())->GetOptions());
89  m_SaveInfo.m_WriterSelector.Select(m_WriterItems[index]);
90  QDialog::accept();
91 }
FileWriterSelector m_WriterSelector
Contains a set of IFileWriter objects.
Definition: mitkIOUtil.h:74
bool Select(const std::string &mimeType)
std::map< std::string, us::Any > Options
Options for reading or writing data.
Definition: mitkIFileIO.h:73
std::string GetName() const
MimeType m_MimeType
The selected mime-type, used to restrict results from FileWriterSelector.
Definition: mitkIOUtil.h:76
std::vector< Item > Get(const std::string &mimeType) const
Get a sorted list of file writer info objects.
std::string m_Path
The path to write the BaseData object to.
Definition: mitkIOUtil.h:78
QmitkFileWriterOptionsDialog(mitk::IOUtil::SaveInfo &saveInfo, QWidget *parent=0)