NorMIT-nav  22.09
An IGT application
cxDataMetric.cpp
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 
13 #include "cxDataMetric.h"
14 #include <QFileInfo>
16 #include "cxTypeConversions.h"
17 #include "cxNullDeleter.h"
18 #include "cxFileManagerService.h"
19 #include "cxLogger.h"
20 
21 namespace cx
22 {
23 
24 DataMetric::DataMetric(const QString& uid, const QString& name, PatientModelServicePtr dataManager, SpaceProviderPtr spaceProvider) :
25  Data(uid, name)
26 {
27  mDataManager = dataManager;
28  mSpaceProvider = spaceProvider;
29 
30  mColor = QColor(240, 170, 255, 255);
32 }
33 
35 {
36 }
37 
39 {
40  return "";
41 }
42 
43 void DataMetric::setColor(const QColor& color)
44 {
45  mColor = color;
46  emit propertiesChanged();
47 }
48 
50 {
51  return mColor;
52 }
53 
54 
55 void DataMetric::addXml(QDomNode& dataNode)
56 {
57  Data::addXml(dataNode);
58  QDomDocument doc = dataNode.ownerDocument();
59 
60  QDomElement colorNode = doc.createElement("color");
61  colorNode.appendChild(doc.createTextNode(color2string(mColor)));
62  dataNode.appendChild(colorNode);
63 }
64 
65 void DataMetric::parseXml(QDomNode& dataNode)
66 {
67  Data::parseXml(dataNode);
68 
69  if (dataNode.isNull())
70  return;
71 
72  QDomNode colorNode = dataNode.namedItem("color");
73  if (!colorNode.isNull())
74  {
75  mColor = string2color(colorNode.toElement().text(), mColor);
76  }
77 
78  emit propertiesChanged();
79 }
80 
81 bool DataMetric::load(QString path, FileManagerServicePtr filemanager)
82 {
83  //TODO is this good enough????
84 
85  QFileInfo to_be_loaded(path);
86  CX_LOG_DEBUG() << "TRYING TO LOAD DATAMETRIC WITH PATH: " << path ;
87  CX_LOG_DEBUG() << "Sym: "<< to_be_loaded.isSymLink();
88  CX_LOG_DEBUG() << "Dir: "<< to_be_loaded.isDir();
89  CX_LOG_DEBUG() << "File: "<< to_be_loaded.isFile();
90 
91  if(to_be_loaded.isDir() || !to_be_loaded.exists())
92  {
93  CX_LOG_DEBUG() << "does not exist";
94  //when trying to load metrics from xml file, this function will be called without a valid path
95  return true; //simulating old behaviour
96  }
97  else
98  {
99  CX_LOG_DEBUG() << "exist";
100  //when trying to use the import functionality to read MNI Tag Point files for example the path will be valid
101  DataMetricPtr self = DataMetricPtr(this, null_deleter());
102  return filemanager->readInto(self, path);
103  }
104  return false;
105 }
106 
107 
108 }
cx::DataMetric::DataMetric
DataMetric(const QString &uid, const QString &name, PatientModelServicePtr dataManager, SpaceProviderPtr spaceProvider)
Definition: cxDataMetric.cpp:24
cx::null_deleter
Definition: cxNullDeleter.h:8
cxLogger.h
cxFileManagerService.h
cx::Data::addXml
virtual void addXml(QDomNode &dataNode)
adds xml information about the data and its variabels
Definition: cxData.cpp:123
cx::DataMetric::getColor
QColor getColor()
Definition: cxDataMetric.cpp:49
cx
Namespace for all CustusX production code.
Definition: cx_dev_group_definitions.h:13
string2color
QColor string2color(QString input, QColor defaultValue)
Definition: cxTypeConversions.cpp:64
cx::DataMetric::mDataManager
PatientModelServicePtr mDataManager
Definition: cxDataMetric.h:67
cxDataMetric.h
cx::DataMetricPtr
boost::shared_ptr< DataMetric > DataMetricPtr
Definition: cxDataMetric.h:73
cx::DataMetric::addXml
void addXml(QDomNode &dataNode)
adds xml information about the data and its variabels
Definition: cxDataMetric.cpp:55
cx::FileManagerServicePtr
boost::shared_ptr< class FileManagerService > FileManagerServicePtr
Definition: cxLogicManager.h:31
color2string
QString color2string(QColor color)
Definition: cxTypeConversions.cpp:52
cxNullDeleter.h
cx::RegistrationHistory::getNullObject
static RegistrationHistoryPtr getNullObject()
Definition: cxRegistrationTransform.cpp:209
cx::Data::m_rMd_History
RegistrationHistoryPtr m_rMd_History
Definition: cxData.h:160
cx::PatientModelServicePtr
boost::shared_ptr< class PatientModelService > PatientModelServicePtr
Definition: cxLogicManager.h:25
cx::DataMetric::mSpaceProvider
SpaceProviderPtr mSpaceProvider
Definition: cxDataMetric.h:68
cxTypeConversions.h
cx::DataMetric::load
virtual bool load(QString path, FileManagerServicePtr filemanager)
metrics don't store info in file, xml only.
Definition: cxDataMetric.cpp:81
cxRegistrationTransform.h
cx::DataMetric::setColor
void setColor(const QColor &color)
Definition: cxDataMetric.cpp:43
cx::DataMetric::mColor
QColor mColor
Definition: cxDataMetric.h:70
cx::Data::propertiesChanged
void propertiesChanged()
emitted when one of the metadata properties (uid, name etc) changes
CX_LOG_DEBUG
#define CX_LOG_DEBUG
Definition: cxLogger.h:95
cx::Data::parseXml
virtual void parseXml(QDomNode &dataNode)
Use a XML node to load data.
Definition: cxData.cpp:149
cx::DataMetric::getSpace
virtual QString getSpace()
Definition: cxDataMetric.cpp:38
cx::Data
Superclass for all data objects.
Definition: cxData.h:89
cx::DataMetric::parseXml
void parseXml(QDomNode &dataNode)
Use a XML node to load data.
Definition: cxDataMetric.cpp:65
cx::SpaceProviderPtr
boost::shared_ptr< class SpaceProvider > SpaceProviderPtr
Definition: cxLogicManager.h:23
cx::DataMetric::~DataMetric
virtual ~DataMetric()
Definition: cxDataMetric.cpp:34