| 1 |
// SPDX-FileCopyrightText: 2017 - 2022 UnionTech Software Technology Co., Ltd. |
| 2 |
// |
| 3 |
// SPDX-License-Identifier: LGPL-3.0-or-later |
| 4 |
|
| 5 |
#pragma once |
| 6 |
|
| 7 |
#include <QDir> |
| 8 |
|
| 9 |
#include "dtkcore_global.h" |
| 10 |
|
| 11 |
DCORE_BEGIN_NAMESPACE |
| 12 |
|
| 13 |
class LIBDTKCORESHARED_EXPORT DPathBuf |
| 14 |
{ |
| 15 |
public: |
| 16 |
DPathBuf(); |
| 17 |
DPathBuf(const QString &path); |
| 18 |
|
| 19 |
DPathBuf operator/(const QString &p) const |
| 20 |
{ |
| 21 |
return DPathBuf(m_path + "/" + p); |
| 22 |
} |
| 23 |
|
| 24 |
DPathBuf &operator/=(const QString &p) |
| 25 |
{ |
| 26 |
return join(p); |
| 27 |
} |
| 28 |
|
| 29 |
DPathBuf operator/(const char *p) const |
| 30 |
{ |
| 31 |
return operator /(QString(p)); |
| 32 |
} |
| 33 |
|
| 34 |
DPathBuf &operator/=(const char *p) |
| 35 |
{ |
| 36 |
return operator /=(QString(p)); |
| 37 |
} |
| 38 |
|
| 39 |
DPathBuf &join(const QString &p) |
| 40 |
{ |
| 41 |
m_path += "/" + p; |
| 42 |
m_path = QDir(m_path).absolutePath(); |
| 43 |
return *this; |
| 44 |
} |
| 45 |
|
| 46 |
QString toString() const |
| 47 |
{ |
| 48 |
return QDir::toNativeSeparators(m_path); |
| 49 |
} |
| 50 |
|
| 51 |
private: |
| 52 |
QString m_path; |
| 53 |
}; |
| 54 |
|
| 55 |
DCORE_END_NAMESPACE |