diff --git a/Modules/Qmitk/QmitkFileDialog.cpp b/Modules/Qmitk/QmitkFileDialog.cpp index 2d6830a41f..7dae51e49e 100644 --- a/Modules/Qmitk/QmitkFileDialog.cpp +++ b/Modules/Qmitk/QmitkFileDialog.cpp @@ -1,195 +1,195 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ //#define _USE_MATH_DEFINES #include //QT #include #include #include // Test imports, delete later #include class DummyReader : public mitk::AbstractFileReader { public: DummyReader(const DummyReader& other) : mitk::AbstractFileReader(other) { } DummyReader(const std::string& extension, int priority) - : mitk::AbstractFileReader("application/dummy", extension, "This is a dummy description") + : mitk::AbstractFileReader(extension, "This is a dummy description") { - this->SetPriority(priority); + this->SetRanking(priority); //std::vector options; OptionList options; options.push_back(std::make_pair("isANiceGuy", true)); options.push_back(std::make_pair("canFly", false)); options.push_back(std::make_pair("isAwesome", true)); options.push_back(std::make_pair("hasOptions", true)); options.push_back(std::make_pair("has more Options", true)); options.push_back(std::make_pair("has maaaaaaaany Options", true)); this->SetOptions(options); m_ServiceReg = this->RegisterService(); } ~DummyReader() { if (m_ServiceReg) m_ServiceReg.Unregister(); } using mitk::AbstractFileReader::Read; virtual std::vector< itk::SmartPointer > Read(std::istream& /*stream*/) { std::vector result; return result; } private: DummyReader* Clone() const { return new DummyReader(*this); } us::ServiceRegistration m_ServiceReg; }; // End of internal dummy reader // // // // // // // // // class QmitkFileDialogPrivate { public: /** \brief This method is part of the widget and needs not to be called separately. */ void CreateQtPartControl(QWidget *parent); /** \brief Remove all checkboxes from the options box.*/ void ClearOptionsBox(); /** \brief Contains the checkboxes for the options*/ QGridLayout* m_BoxLayout; /** \brief The Options the user has set for the reader / writer*/ mitk::IFileReader::OptionList m_Options; }; QmitkFileDialog::QmitkFileDialog(QWidget* parent, Qt::WindowFlags f) : QFileDialog(parent, f) , d(new QmitkFileDialogPrivate) { this->setOption(QFileDialog::DontUseNativeDialog); DummyReader* dr = new DummyReader(".xsfd", 1000); d->CreateQtPartControl(this); } QmitkFileDialog::~QmitkFileDialog() { } //////////////////// INITIALIZATION ///////////////////// void QmitkFileDialogPrivate::CreateQtPartControl(QWidget *parent) { // cast own layout to gridLayout QGridLayout *layout = qobject_cast(parent->layout()); // creat groupbox for options QGroupBox *box = new QGroupBox(parent); box->setTitle("Options:"); box->setVisible(true); m_BoxLayout = new QGridLayout(box); box->setLayout(m_BoxLayout); layout->addWidget(box,4,0,1,3); parent->connect( parent, SIGNAL(currentChanged(QString)), parent, SLOT(DisplayOptions( QString)) ); parent->connect( parent, SIGNAL(fileSelected(QString)), parent, SLOT(ProcessSelectedFile()) ); } /////////////////////////// OPTIONS /////////////////////////////// void QmitkFileDialog::DisplayOptions(const QString& path) { d->ClearOptionsBox(); mitk::IFileReader::OptionList options = QueryAvailableOptions(path); int i = 0; for (mitk::IFileReader::OptionList::const_iterator iter = options.begin(), end = options.end(); iter != end; ++iter) { QCheckBox *checker = new QCheckBox(this); checker->setText( QString::fromStdString(iter->first) ); checker->setChecked( iter->second ); d->m_BoxLayout->addWidget(checker, i / 4, i % 4); ++i; } } void QmitkFileDialogPrivate::ClearOptionsBox() { if ( m_BoxLayout != NULL ) { QLayoutItem* item; while ( ( item = m_BoxLayout->takeAt( 0 ) ) != NULL ) { delete item->widget(); delete item; } } } mitk::IFileReader::OptionList QmitkFileDialog::GetSelectedOptions() { mitk::IFileReader::OptionList result; if ( d->m_BoxLayout != NULL ) { QLayoutItem* item; while ( ( item = d->m_BoxLayout->takeAt( 0 ) ) != NULL ) { QCheckBox* checker = dynamic_cast (item->widget()); if (checker) { mitk::IFileReader::Option option( checker->text().toStdString() , checker->isChecked() ); result.push_back(option); } delete item->widget(); delete item; } } return result; } diff --git a/Modules/Qmitk/QmitkFileSaveDialog.cpp b/Modules/Qmitk/QmitkFileSaveDialog.cpp index 74d6a58d24..eca0a71cf5 100644 --- a/Modules/Qmitk/QmitkFileSaveDialog.cpp +++ b/Modules/Qmitk/QmitkFileSaveDialog.cpp @@ -1,149 +1,149 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ //#define _USE_MATH_DEFINES #include // MITK #include // Test imports, delete later #include class DummyReader : public mitk::AbstractFileReader { public: DummyReader(const DummyReader& other) : mitk::AbstractFileReader(other) { } DummyReader(const std::string& extension, int priority) - : mitk::AbstractFileReader("application/dummy", extension, "This is a dummy description") + : mitk::AbstractFileReader(extension, "This is a dummy description") { - this->SetPriority(priority); + this->SetRanking(priority); //std::vector options; OptionList options; options.push_back(std::make_pair("isANiceGuy", true)); options.push_back(std::make_pair("canFly", false)); options.push_back(std::make_pair("isAwesome", true)); options.push_back(std::make_pair("hasOptions", true)); options.push_back(std::make_pair("has more Options", true)); options.push_back(std::make_pair("has maaaaaaaany Options", true)); this->SetOptions(options); m_ServiceReg = this->RegisterService(); } ~DummyReader() { if (m_ServiceReg) m_ServiceReg.Unregister(); } using mitk::AbstractFileReader::Read; virtual std::vector< itk::SmartPointer > Read(std::istream& /*stream*/) { std::vector result; return result; } private: DummyReader* Clone() const { return new DummyReader(*this); } us::ServiceRegistration m_ServiceReg; }; // End of internal dummy reader // // // // // // // // // class QmitkFileSaveDialogPrivate { public: mitk::IFileWriter* m_FileWriter; mitk::IFileWriter::OptionList m_Options; mitk::FileWriterRegistry m_FileWriterRegistry; mitk::BaseData::Pointer m_BaseData; }; QmitkFileSaveDialog::QmitkFileSaveDialog(mitk::BaseData::Pointer baseData, QWidget* parent, Qt::WindowFlags f) : QmitkFileDialog(parent, f) , d(new QmitkFileSaveDialogPrivate) { d->m_BaseData = baseData; this->setFileMode(QFileDialog::AnyFile); } QmitkFileSaveDialog::~QmitkFileSaveDialog() { } void QmitkFileSaveDialog::ProcessSelectedFile() { std::string file = this->selectedFiles().front().toStdString(); std::string extension = file; extension.erase(0, extension.find_last_of('.')); d->m_Options = GetSelectedOptions(); // We are not looking for specific Options here, which is okay, since the dialog currently only shows the // reader with the highest priority. Better behaviour required, if we want selectable readers. d->m_FileWriter = d->m_FileWriterRegistry.GetWriter(extension); d->m_FileWriter->SetOptions(d->m_Options); } mitk::IFileWriter::OptionList QmitkFileSaveDialog::QueryAvailableOptions(const QString& /*path*/) { mitk::IFileWriter* writer = d->m_FileWriterRegistry.GetWriter(d->m_BaseData->GetNameOfClass()); if (writer == NULL) { // MITK_WARN << "Did not find WriterService for registered Extension. This should be looked into by a developer."; return mitk::IFileWriter::OptionList(); } return writer->GetOptions(); } mitk::IFileWriter* QmitkFileSaveDialog::GetWriter() { return d->m_FileWriter; } void QmitkFileSaveDialog::WriteBaseData() { if (d->m_FileWriter == NULL ) { MITK_WARN << "Tried go write BaseData while no FileWriter was selected in Dialog. Aborting."; return; } d->m_FileWriter->Write(d->m_BaseData, this->selectedFiles().front().toStdString()); }