Skip to content

Commit

Permalink
feat: return document name
Browse files Browse the repository at this point in the history
  • Loading branch information
Montel committed Oct 29, 2024
1 parent 9dd6015 commit 6b09728
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 0 deletions.
5 changes: 5 additions & 0 deletions docs/API/knut/document.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import Knut

| | Name |
|-|-|
|string|**[documentName](#documentName)**|
|string|**[errorString](#errorString)**|
|bool|**[exists](#exists)**|
|string|**[fileName](#fileName)**|
Expand All @@ -32,6 +33,10 @@ A document is a file loaded by Knut and that can be used in script (either to ge

## Property Documentation

#### <a name="documentName"></a>string **documentName**

Returns the name on the file system.

#### <a name="errorString"></a>string **errorString**

Returns the error string if an error occurred while loading the document, otherwise returns an empty string.
Expand Down
15 changes: 15 additions & 0 deletions src/core/document.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,12 @@ namespace Core {
* - put an error in `errorString` if it can't be loaded
* \sa Document::load
*/

/*!
* \qmlproperty string Document::documentName
* Returns the name on the file system.
*/

/*!
* \qmlproperty bool Document::exists
* Returns true if the document is a file on the disk, otherwise returns false.
Expand Down Expand Up @@ -89,6 +95,15 @@ Document::Type Document::type() const
return m_type;
}

const QString Document::documentName() const
{
if (!exists()) {
return {};
}
const QFileInfo fi(m_fileName);
return fi.fileName();
}

const QString &Document::errorString() const
{
return m_errorString;
Expand Down
3 changes: 3 additions & 0 deletions src/core/document.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ class Document : public QObject
{
Q_OBJECT
Q_PROPERTY(QString fileName READ fileName WRITE setFileName NOTIFY fileNameChanged)
Q_PROPERTY(QString documentName READ documentName NOTIFY fileNameChanged)
Q_PROPERTY(bool exists READ exists NOTIFY existsChanged)
Q_PROPERTY(Type type READ type CONSTANT)
Q_PROPERTY(QString errorString READ errorString NOTIFY errorStringChanged)
Expand Down Expand Up @@ -50,6 +51,8 @@ class Document : public QObject

Type type() const;

const QString documentName() const;

const QString &errorString() const;

bool hasChanged() const;
Expand Down

0 comments on commit 6b09728

Please sign in to comment.