Fraxinus  22.04
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 {
114  return mFilePath.getRelativeFilepath();
115 }
116 
117 bool FilePathPropertyBase::setValue(const QString& val)
118 {
119  if (val == this->getValue())
120  return false;
121 
122  mFilePath.setFilepath(val);
123  mStore.writeValue(mFilePath.getRelativeFilepath());
124  emit valueWasSet();
125  emit changed();
126  return true;
127 }
128 
130 {
131  return mFilePath;
132 }
133 
134 }//cx
QStringList getRootPaths() const
return the root of the existing root, first if no existing.
QString getAbsoluteFilepath() const
return absolute filepath, select the existing root
void setFilepath(QString filename)
relative to one of the root paths or absolute
virtual QString getDisplayName() const
name of data entity. Used for display to user.
virtual QString getValue() const
void appendRootPath(QString path)
QString getRelativeFilepath() const
return filepath relative to root.
virtual bool setValue(const QString &value)
QString getRootPath() const
return the root of the existing root, first if no existing.
Namespace for all CustusX production code.