/*! * * Copyright (c) 2021-2023 Diality Inc. - All Rights Reserved. * \copyright * THIS CODE MAY NOT BE COPIED OR REPRODUCED IN ANY FORM, IN PART OR IN * WHOLE, WITHOUT THE EXPLICIT PERMISSION OF THE COPYRIGHT OWNER. * * \file VLogFileListModel.h * \author (last) Vy Duong * \date (last) 10-Aug-2023 * \author (original) Vy Duong * \date (original) 10-Aug-2023 * */ #pragma once // Qt #include #include #include #include // Project #include "main.h" #include "VView.h" #include "Logger.h" // forward declarations class tst_views; namespace View { /*! * \brief The VLogFileListModel class * Interface between QML and the log files * \details Exposes log files to QML and provides an interface to list and select the files * References: https://doc.qt.io/qt-5.12/qtquick-modelviewsdata-cppmodels.html * */ class VLogFileListModel : public QAbstractListModel { Q_OBJECT PROPERTY(QString , folder , "" ) PROPERTY(bool , includeSubFolders , true ) public: // Note: VIEW_DEC_CLASS(VLogFileListModel) requires QObject as the parent, so it's necessary to define it here // Otherwise a VIEW_DEC_CLASS macro could allow specifying the parent class with QObject as the default explicit VLogFileListModel(QAbstractListModel *parent = nullptr); enum LogFileDataRole { FilePathRole = Qt::UserRole + 1 , FileNameRole , FileSizeRole , }; int rowCount (const QModelIndex &parent = QModelIndex()) const; QVariant data (const QModelIndex &index, int role = Qt::DisplayRole) const; public slots: void doInit(); void removeAllRows(); void refreshModel(); virtual void updateFolderWithType(const int &vType) = 0; void updateModelWithFolder(const QString &vPath); private slots: void onLogsRemoved(bool vInProgress); protected: QHash roleNames() const; private: void initConnections(); QFileInfoList getLogListFromDir(const QString &vDirectory); QFileInfoList _logFiles; QString _currentPath; }; class VSDCardLogFileListModel : public VLogFileListModel { Q_OBJECT public: explicit VSDCardLogFileListModel(QAbstractListModel *parent = nullptr); public slots: virtual void updateFolderWithType(const int &vType) override; }; class VUSBLogFileListModel : public VLogFileListModel { Q_OBJECT public: explicit VUSBLogFileListModel(QAbstractListModel *parent = nullptr); public slots: virtual void updateFolderWithType(const int &vType) override; }; }