diff options
author | Dennis Oberst <dennis.oberst@qt.io> | 2023-06-27 15:54:20 +0200 |
---|---|---|
committer | Dennis Oberst <dennis.oberst@qt.io> | 2023-08-21 14:10:04 +0200 |
commit | 959f88e4b5371edff0b344e5f768c70aa5202402 (patch) | |
tree | 4c634d55d552af545eed705a98b1916f62ea0ed9 /examples/quickcontrols/filesystemexplorer/filesystemmodel.h | |
parent | 4f9687927da504c344a6e1805fe32f0b2d650d8e (diff) |
Filesystem Explorer Example: Introduce version 2
This updated version addresses several bugs and misbehaviors that were
identified in the previous version. I have rewritten and improved
various aspects of the application to provide a more stable and reliable
user experience.
Here are some of the key changes and enhancements in version 2:
- Fix qmllint warnings.
- Reduce the number of redundant items
- Apply the custom window decorations inside MyMenuBar
to the contentItem instead of the background to scale
properly.
- Fix additional scaling and UI misbehaviors
- Add an application icon
- Add an editor with line numbers
- Add command line options to specify an initial directory
- Since rootIndex is exposed inside TreeView since 6.6
this is an excellent opportunity to make use of it
- Crosslink the python version of this example in the docs
Pick-to: 6.6
Change-Id: Ib816a95f843b3f4b84b11db893facda0ffc6f482
Reviewed-by: Mitch Curtis <mitch.curtis@qt.io>
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Diffstat (limited to 'examples/quickcontrols/filesystemexplorer/filesystemmodel.h')
-rw-r--r-- | examples/quickcontrols/filesystemexplorer/filesystemmodel.h | 24 |
1 files changed, 21 insertions, 3 deletions
diff --git a/examples/quickcontrols/filesystemexplorer/filesystemmodel.h b/examples/quickcontrols/filesystemexplorer/filesystemmodel.h index 24f3d658b2..c79af4aa82 100644 --- a/examples/quickcontrols/filesystemexplorer/filesystemmodel.h +++ b/examples/quickcontrols/filesystemexplorer/filesystemmodel.h @@ -5,18 +5,36 @@ #define FILESYSTEMMODEL_H #include <QFileSystemModel> -#include <QtQml/qqml.h> +#include <QQuickTextDocument> class FileSystemModel : public QFileSystemModel { Q_OBJECT QML_ELEMENT QML_SINGLETON - + Q_PROPERTY(QModelIndex rootIndex READ rootIndex WRITE setRootIndex NOTIFY rootIndexChanged) public: explicit FileSystemModel(QObject *parent = nullptr); - int columnCount(const QModelIndex &parent) const override; + + // Functions invokable from QML Q_INVOKABLE QString readFile(const QString &filePath); + Q_INVOKABLE int currentLineNumber(QQuickTextDocument *textDocument, int cursorPosition); + + // Overridden functions + int columnCount(const QModelIndex &parent) const override; + + // Member functions from here + QModelIndex rootIndex() const; + void setRootIndex(const QModelIndex index); + void setInitialDirectory(const QString &path = getDefaultRootDir()); + + static QString getDefaultRootDir(); + +signals: + void rootIndexChanged(); + +private: + QModelIndex m_rootIndex; }; #endif |