NorMIT-nav  2023.01.05-dev+develop.0da12
An IGT application
cxFilePathPropertyBase.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 #include "cxFilePathPropertyBase.h"
12 #include <QDir>
13 
14 namespace cx
15 {
16 
18 {
19  mRoots << path;
20 }
21 
22 void EmbeddedFilepath::setFilepath(QString filename)
23 {
24  mFilePath = filename;
25 }
26 
27 void EmbeddedFilepath::evaluate(QString* foundRoot, bool* found, QString* foundRelative, QString* foundAbsolute) const
28 {
29  *foundRelative = mFilePath;
30  if (!mRoots.empty())
31  *foundRoot = mRoots.front();
32  *foundAbsolute = mFilePath;
33  *found = false;
34 
35  foreach (QString root, mRoots)
36  {
37  root = QDir::cleanPath(root);
38  if (!mFilePath.isEmpty() && QDir(root).exists(mFilePath))
39  {
40  *foundRelative = QDir(root).relativeFilePath(mFilePath);
41  *foundRoot = root;
42  *foundAbsolute = QDir(root).absoluteFilePath(mFilePath);
43  *found = true;
44 
45  if (foundRelative->contains(".."))
46  {
47  // dont use relative paths outside of the roots
48  *foundRelative = *foundAbsolute;
49  }
50  else
51  {
52  // if the current hit is inside the root, accept immediately
53  return;
54  }
55  }
56  }
57 
58 }
59 
61 {
62  bool found = false;
63  QString root, relative, absolute;
64  this->evaluate(&root, &found, &relative, &absolute);
65 
66  return relative;
67 }
68 
70 {
71  bool found = false;
72  QString root, relative, absolute;
73  this->evaluate(&root, &found, &relative, &absolute);
74 
75  return absolute;
76 }
77 
79 {
80  bool found = false;
81  QString root, relative, absolute;
82  this->evaluate(&root, &found, &relative, &absolute);
83 
84  return found;
85 }
86 
88 {
89  bool found = false;
90  QString root, relative, absolute;
91  this->evaluate(&root, &found, &relative, &absolute);
92 
93  return root;
94 }
95 
96 QStringList EmbeddedFilepath::getRootPaths() const
97 {
98  return mRoots;
99 }
100 
101 
103 {
104 
105 }
106 
108 {
109  return mName;
110 }
111 
113 {
115 }
116 
117 bool FilePathPropertyBase::setValue(const QString& val)
118 {
119  if (val == this->getValue())
120  return false;
121 
122  mFilePath.setFilepath(val);
124  emit valueWasSet();
125  emit changed();
126  return true;
127 }
128 
130 {
131  return mFilePath;
132 }
133 
134 }//cx
cx::EmbeddedFilepath::setFilepath
void setFilepath(QString filename)
relative to one of the root paths or absolute
Definition: cxFilePathPropertyBase.cpp:22
cx
Namespace for all CustusX production code.
Definition: cx_dev_group_definitions.h:13
cx::Property::changed
void changed()
emit when the underlying data value is changed: The user interface will be updated.
cx::FilePathPropertyBase::mName
QString mName
emitted when the value is set using setValue() (similar to changed(), but more constrained)
Definition: cxFilePathPropertyBase.h:86
cx::FilePathPropertyBase::getDisplayName
virtual QString getDisplayName() const
name of data entity. Used for display to user.
Definition: cxFilePathPropertyBase.cpp:107
cx::EmbeddedFilepath::appendRootPath
void appendRootPath(QString path)
Definition: cxFilePathPropertyBase.cpp:17
cx::FilePathPropertyBase::mStore
XmlOptionItem mStore
Definition: cxFilePathPropertyBase.h:90
cx::FilePathPropertyBase::getEmbeddedPath
EmbeddedFilepath getEmbeddedPath()
Definition: cxFilePathPropertyBase.cpp:129
cx::EmbeddedFilepath::getRelativeFilepath
QString getRelativeFilepath() const
return filepath relative to root.
Definition: cxFilePathPropertyBase.cpp:60
cx::EmbeddedFilepath
Definition: cxFilePathPropertyBase.h:31
cx::EmbeddedFilepath::exists
bool exists() const
Definition: cxFilePathPropertyBase.cpp:78
cx::EmbeddedFilepath::getAbsoluteFilepath
QString getAbsoluteFilepath() const
return absolute filepath, select the existing root
Definition: cxFilePathPropertyBase.cpp:69
cx::FilePathPropertyBase::getValue
virtual QString getValue() const
Definition: cxFilePathPropertyBase.cpp:112
cx::EmbeddedFilepath::getRootPaths
QStringList getRootPaths() const
return the root of the existing root, first if no existing.
Definition: cxFilePathPropertyBase.cpp:96
cx::FilePathPropertyBase::mFilePath
EmbeddedFilepath mFilePath
Definition: cxFilePathPropertyBase.h:89
cx::FilePathPropertyBase::FilePathPropertyBase
FilePathPropertyBase()
Definition: cxFilePathPropertyBase.cpp:102
cx::FilePathPropertyBase::setValue
virtual bool setValue(const QString &value)
Definition: cxFilePathPropertyBase.cpp:117
cx::FilePathPropertyBase::valueWasSet
void valueWasSet()
cx::XmlOptionItem::writeValue
void writeValue(const QString &val)
Definition: cxXmlOptionItem.cpp:189
cxFilePathPropertyBase.h
cx::EmbeddedFilepath::getRootPath
QString getRootPath() const
return the root of the existing root, first if no existing.
Definition: cxFilePathPropertyBase.cpp:87