CustusX  22.04-rc2
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 }
boost::shared_ptr< class SpaceProvider > SpaceProviderPtr
boost::shared_ptr< class FileManagerService > FileManagerServicePtr
QColor string2color(QString input, QColor defaultValue)
void addXml(QDomNode &dataNode)
adds xml information about the data and its variabels
QString color2string(QColor color)
void setColor(const QColor &color)
static RegistrationHistoryPtr getNullObject()
void propertiesChanged()
emitted when one of the metadata properties (uid, name etc) changes
boost::shared_ptr< DataMetric > DataMetricPtr
Definition: cxDataMetric.h:73
PatientModelServicePtr mDataManager
Definition: cxDataMetric.h:67
virtual void addXml(QDomNode &dataNode)
adds xml information about the data and its variabels
Definition: cxData.cpp:123
virtual QString getSpace()
SpaceProviderPtr mSpaceProvider
Definition: cxDataMetric.h:68
virtual bool load(QString path, FileManagerServicePtr filemanager)
metrics don&#39;t store info in file, xml only.
virtual ~DataMetric()
void parseXml(QDomNode &dataNode)
Use a XML node to load data.
DataMetric(const QString &uid, const QString &name, PatientModelServicePtr dataManager, SpaceProviderPtr spaceProvider)
virtual void parseXml(QDomNode &dataNode)
Use a XML node to load data.
Definition: cxData.cpp:149
boost::shared_ptr< class PatientModelService > PatientModelServicePtr
QColor getColor()
RegistrationHistoryPtr m_rMd_History
Definition: cxData.h:160
#define CX_LOG_DEBUG
Definition: cxLogger.h:95
Superclass for all data objects.
Definition: cxData.h:89
Namespace for all CustusX production code.