diff --git a/Modules/Qmitk/QmitkFileDialog.cpp b/Modules/Qmitk/QmitkFileDialog.cpp index 9b5a9207c6..399fca55fa 100644 --- a/Modules/Qmitk/QmitkFileDialog.cpp +++ b/Modules/Qmitk/QmitkFileDialog.cpp @@ -1,59 +1,233 @@ /*=================================================================== 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 +#include + // STL Headers #include //microservices #include #include #include +//QT +#include +#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(extension, "This is a dummy description") + { + m_Priority = priority; + //std::list options; + m_Options.push_front(std::make_pair("isANiceGuy", true)); + m_Options.push_front(std::make_pair("canFly", false)); + m_Options.push_front(std::make_pair("isAwesome", true)); + m_Options.push_front(std::make_pair("hasOptions", true)); + m_Options.push_front(std::make_pair("has more Options", true)); + m_Options.push_front(std::make_pair("has maaaaaaaany Options", true)); + m_ServiceReg = this->RegisterService(); + } + + ~DummyReader() + { + if (m_ServiceReg) m_ServiceReg.Unregister(); + } + + using mitk::AbstractFileReader::Read; + + virtual std::list< itk::SmartPointer > Read(const std::istream& /*stream*/, mitk::DataStorage* /*ds*/ = 0) + { + std::list result; + return result; + } + + virtual void SetOptions(const std::list< mitk::FileServiceOption >& options ) + { + m_Options = options; + //m_Registration.SetProperties(GetServiceProperties()); + } + +private: + + DummyReader* Clone() const + { + return new DummyReader(*this); + } + + us::ServiceRegistration m_ServiceReg; +}; // End of internal dummy reader + const std::string QmitkFileDialog::VIEW_ID = "org.mitk.views.QmitkFileDialog"; +// +// +// +// + +// + +// + +// +// +// + QmitkFileDialog::QmitkFileDialog(QWidget* parent, Qt::WindowFlags f): QFileDialog(parent, f) { - //m_controls = null; - //CreateQtPartControl(this); + this->setOption(QFileDialog::DontUseNativeDialog); + this->setFileMode(QFileDialog::ExistingFile); + + DummyReader* dr = new DummyReader(".xsfd", 1000); + + CreateQtPartControl(this); } QmitkFileDialog::~QmitkFileDialog() { } //////////////////// INITIALIZATION ///////////////////// -//void QmitkFileDialog::CreateQtPartControl(QWidget *parent) -//{ -// if (!m_Controls) -// { -// // create GUI widgets -// m_Controls = new Ui::QmitkFileDialogControls; -// m_Controls->setupUi(parent); -// this->CreateConnections(); -// } -// m_Context = us::GetModuleContext(); -//} +void QmitkFileDialog::CreateQtPartControl(QWidget *parent) +{ + // cast own layout to gridLayout + QGridLayout *layout = (QGridLayout*)this->layout(); + + // creat groupbox for options + QGroupBox *box = new QGroupBox(this); + box->setTitle("Options:"); + box->setVisible(true); + m_BoxLayout = new QGridLayout(box); + box->setLayout(m_BoxLayout); + layout->addWidget(box,4,0,1,3); + + this->CreateConnections(); + + // m_context = us::getmodulecontext(); +} void QmitkFileDialog::CreateConnections() { - //connect( m_Controls->m_ServiceList, SIGNAL(currentItemChanged( QListWidgetItem *, QListWidgetItem *)), this, SLOT(OnServiceSelectionChanged()) ); + connect( this, SIGNAL(currentChanged( const QString &)), this, SLOT(DisplayOptions( QString)) ); + connect( this, SIGNAL(fileSelected( const QString &)), this, SLOT(ProcessSelectedFile()) ); } + +/////////////////////////// OPTIONS /////////////////////////////// + +void QmitkFileDialog::DisplayOptions(QString path) +{ + std::string extension = path.toStdString(); + extension.erase(0, extension.find_last_of('.')); + + ClearOptionsBox(); + + us::ModuleContext* context = us::GetModuleContext(); + mitk::FileReaderManager manager; + mitk::IFileReader* reader = manager.GetReader(extension); + + if (reader == NULL) + { + // MITK_WARN << "Did not find ReaderService for registered Extension. This should be looked into by a developer."; + return; + } + + std::list< mitk::FileServiceOption > options = reader->GetOptions(); + int i = 0; + while (options.size() > 0) + { + QCheckBox *checker = new QCheckBox(this); + checker->setText( options.front().first.c_str() ); + checker->setChecked( options.front().second ); + options.pop_front(); + m_BoxLayout->addWidget(checker, i / 4, i % 4); + i++; + } +} + +void QmitkFileDialog::ClearOptionsBox() +{ + if ( m_BoxLayout != NULL ) + { + QLayoutItem* item; + while ( ( item = m_BoxLayout->takeAt( 0 ) ) != NULL ) + { + delete item->widget(); + delete item; + } + } +} + +void QmitkFileDialog::ProcessSelectedFile() +{ + std::string file = this->selectedFiles().front().toStdString(); + std::string extension = file; + extension.erase(0, extension.find_last_of('.')); + + 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. + + m_FileReader = m_FileReaderManager.GetReader(extension); + m_FileReader->GetOptions(); +} + +std::list< mitk::FileServiceOption > QmitkFileDialog::GetSelectedOptions() +{ + std::list result; + + if ( m_BoxLayout != NULL ) + { + QLayoutItem* item; + while ( ( item = m_BoxLayout->takeAt( 0 ) ) != NULL ) + { + QCheckBox* checker = dynamic_cast (item->widget()); + if (checker) + { + mitk::FileServiceOption option = std::make_pair( checker->text().toStdString() , checker->isChecked() ); + result.push_back(option); + } + + delete item->widget(); + delete item; + } + } + return result; +} + +mitk::IFileReader* QmitkFileDialog::GetReader() +{ + return 0; +} \ No newline at end of file diff --git a/Modules/Qmitk/QmitkFileDialog.h b/Modules/Qmitk/QmitkFileDialog.h index a471bb0a8a..684c57fd87 100644 --- a/Modules/Qmitk/QmitkFileDialog.h +++ b/Modules/Qmitk/QmitkFileDialog.h @@ -1,77 +1,96 @@ /*=================================================================== 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. ===================================================================*/ #ifndef _QmitkFileDialog_H_INCLUDED #define _QmitkFileDialog_H_INCLUDED #include "QmitkExports.h" #include //QT headers #include #include -#include +#include //Microservices #include "usServiceReference.h" #include "usModuleContext.h" #include "usServiceEvent.h" #include "usServiceInterface.h" +// MITK +#include +#include + /** * \ingroup QmitkModule * * \brief */ class QMITK_EXPORT QmitkFileDialog :public QFileDialog { //this is needed for all Qt objects that should have a MOC object (everything that derives from QObject) Q_OBJECT private: //us::ModuleContext* m_Context; ///** \brief a filter to further narrow down the list of results*/ //std::string m_Filter; ///** \brief The name of the ServiceInterface that this class should list */ //std::string m_Interface; ///** \brief The name of the ServiceProperty that will be displayed in the list to represent the service */ //std::string m_NamingProperty; public: static const std::string VIEW_ID; QmitkFileDialog(QWidget* p = 0, Qt::WindowFlags f1 = 0); virtual ~QmitkFileDialog(); /** \brief This method is part of the widget and needs not to be called separately. */ - //virtual void CreateQtPartControl(QWidget *parent); + virtual void CreateQtPartControl(QWidget *parent); /** \brief This method is part of the widget and needs not to be called separately. (Creation of the connections of main and control widget.)*/ virtual void CreateConnections(); + virtual std::list< mitk::FileServiceOption > GetSelectedOptions(); + + virtual mitk::IFileReader* GetReader(); + signals: public slots: + virtual void DisplayOptions(QString path); + protected slots: + virtual void ProcessSelectedFile(); + protected: + QGridLayout* m_BoxLayout; + mitk::IFileReader* m_FileReader; + std::list m_Options; + mitk::FileReaderManager m_FileReaderManager; + + virtual void ClearOptionsBox(); + //Ui::QmitkFileDialogControls* m_Controls; ///< member holding the UI elements of this widget }; #endif // _QmitkFileDialog_H_INCLUDED