CustusX  2023.01.05-dev+develop.0da12
An IGT application
cxExportDataTypeWidget.h
Go to the documentation of this file.
1 /*=========================================================================
2 This file is part of CustusX, an Image Guided Therapy Application.
3 
4 Copyright (c) SINTEF Department of Medical Technology.
5 All rights reserved.
6 
7 CustusX is released under a BSD 3-Clause license.
8 
9 See Lisence.txt (https://github.com/SINTEFMedtek/CustusX/blob/master/License.txt) for details.
10 =========================================================================*/
11 
12 #ifndef CXEXPORTDATATYPEWIDGET_H
13 #define CXEXPORTDATATYPEWIDGET_H
14 
15 #include "org_custusx_core_filemanager_Export.h"
16 #include "cxBaseWidget.h"
17 #include <QPushButton>
18 #include <QCheckBox>
19 #include "cxForwardDeclarations.h"
21 #include "cxImage.h"
22 #include "cxLogger.h"
23 #include "cxVisServices.h"
24 #include "cxPatientModelService.h"
26 #include "cxFileManagerService.h"
27 
28 namespace cx
29 {
30 
31 //Note: Workaround for: Template classes not supported by Q_OBJECT
33 {
34  Q_OBJECT
35 public:
36  Q_OBJECTExportDataTypeWidget(QWidget *parent, QString dataType, FileManagerServicePtr filemanager, VisServicesPtr services, SelectDataStringPropertyBasePtr property);
37 
38 protected slots:
39  virtual void exportButtonClicked();
40  virtual void exportAllButtonClicked();
41 
42 protected:
46  QString mDataType;
47 
48  std::vector<QCheckBox*> mCheckboxes;
49  QPushButton *mExportButton;
50  QPushButton *mExportAllButton;
51 };
52 
53 //---------
54 
55 template<typename TYPE>
56 class org_custusx_core_filemanager_EXPORT ExportDataTypeWidget : public Q_OBJECTExportDataTypeWidget
57 {
58 public:
60  Q_OBJECTExportDataTypeWidget(parent, TYPE::getTypeName(), filemanager, services, property)
61  {
62  connect(mExportButton, &QPushButton::clicked, this, &ExportDataTypeWidget::exportButtonClicked);
63  connect(mExportAllButton, &QPushButton::clicked, this, &ExportDataTypeWidget::exportAllButtonClicked);
64  }
65 
66 protected:
67  void save(QString suffix, QString data_uid)
68  {
69  boost::shared_ptr<TYPE> data = boost::dynamic_pointer_cast<TYPE>(mServices->patient()->getData(data_uid));
70  if(!data)
71  CX_LOG_ERROR() << "Data with uid: " << data_uid << " not found";
72  QString export_folder = mServices->session()->getSubFolder("Export");
73  QString filename = export_folder+"/"+data_uid+"."+suffix;
74  mFileManager->save(data,filename);
75  }
76 
77  void saveAsSelected(QString uid)
78  {
79  CX_LOG_DEBUG() << "Saving " << uid;
80  for(int i=0; i<mCheckboxes.size(); ++i)
81  {
82  if((mCheckboxes[i]->checkState() == Qt::Checked))
83  {
84  CX_LOG_DEBUG() << " -> " << mCheckboxes[i]->text();
85  QString suffix = mCheckboxes[i]->text();
86  this->save(suffix, uid);
87  }
88  }
89  }
90 
91  virtual void exportButtonClicked()
92  {
93  CX_LOG_DEBUG() << "EXPORTING " << mSelectedData->getValue();
94  QString uid = mSelectedData->getValue();
95  this->saveAsSelected(uid);
96  }
97 
98  virtual void exportAllButtonClicked()
99  {
100  CX_LOG_DEBUG() << "EXPORTING ALL " << mDataType;
101 
102  std::map<QString, boost::shared_ptr<TYPE> > all_data = mServices->patient()->getDataOfType<TYPE>();
103  for (typename std::map<QString, boost::shared_ptr<TYPE> >::const_iterator iter = all_data.begin(); iter != all_data.end(); ++iter)
104  {
105  this->saveAsSelected(iter->first);
106  }
107  }
108 
109 };
110 
111 }
112 
113 #endif // CXEXPORTDATATYPEWIDGET_H
Q_OBJECTExportDataTypeWidget(QWidget *parent, QString dataType, FileManagerServicePtr filemanager, VisServicesPtr services, SelectDataStringPropertyBasePtr property)
boost::shared_ptr< class FileManagerService > FileManagerServicePtr
std::vector< QCheckBox * > mCheckboxes
boost::shared_ptr< class VisServices > VisServicesPtr
Definition: cxMainWindow.h:40
void save(QString suffix, QString data_uid)
SelectDataStringPropertyBasePtr mSelectedData
ExportDataTypeWidget(QWidget *parent, FileManagerServicePtr filemanager, VisServicesPtr services, SelectDataStringPropertyBasePtr property)
boost::shared_ptr< class SelectDataStringPropertyBase > SelectDataStringPropertyBasePtr
#define CX_LOG_ERROR
Definition: cxLogger.h:99
Interface for QWidget which handles widgets uniformly for the system.
Definition: cxBaseWidget.h:88
#define CX_LOG_DEBUG
Definition: cxLogger.h:95
Namespace for all CustusX production code.