2023-07-31 12:21:14 +00:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <QAbstractListModel>
|
2023-09-27 10:56:10 +00:00
|
|
|
#include <QDateTime>
|
|
|
|
|
2023-10-03 09:48:40 +00:00
|
|
|
#include "figmalinksmodel.h"
|
|
|
|
|
2023-10-09 20:26:50 +00:00
|
|
|
class DirectoryFilesWatcher;
|
2023-07-31 12:21:14 +00:00
|
|
|
|
|
|
|
struct PagesModelItem {
|
2023-09-27 10:56:10 +00:00
|
|
|
QString path;
|
|
|
|
QDateTime lastModified;
|
2023-07-31 12:21:14 +00:00
|
|
|
QString title;
|
|
|
|
QString category;
|
2024-10-30 11:19:53 +00:00
|
|
|
int status = 0;
|
2023-10-03 09:48:40 +00:00
|
|
|
QStringList figmaLinks;
|
2023-07-31 12:21:14 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class PagesModel : public QAbstractListModel
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
public:
|
|
|
|
explicit PagesModel(const QString &path, QObject *parent = nullptr);
|
|
|
|
|
|
|
|
enum Roles {
|
|
|
|
TitleRole = Qt::UserRole + 1,
|
2023-10-03 09:48:40 +00:00
|
|
|
CategoryRole,
|
2024-10-30 11:19:53 +00:00
|
|
|
StatusRole,
|
2023-10-03 09:48:40 +00:00
|
|
|
FigmaRole
|
2023-07-31 12:21:14 +00:00
|
|
|
};
|
|
|
|
|
2024-10-30 11:19:53 +00:00
|
|
|
enum Status : int {
|
|
|
|
Uncategorized = 0,
|
|
|
|
Bad,
|
|
|
|
Decent,
|
|
|
|
Good
|
|
|
|
};
|
|
|
|
|
|
|
|
Q_ENUM(Status)
|
|
|
|
|
2023-07-31 12:21:14 +00:00
|
|
|
QHash<int, QByteArray> roleNames() const override;
|
|
|
|
int rowCount(const QModelIndex &parent = QModelIndex()) const override;
|
|
|
|
QVariant data(const QModelIndex &index, int role) const override;
|
|
|
|
|
|
|
|
private:
|
2023-10-09 20:26:50 +00:00
|
|
|
void onPagesChanged(const QStringList& added, const QStringList& removed,
|
|
|
|
const QStringList& changed);
|
|
|
|
|
|
|
|
int getIndexByPath(const QString& path) const;
|
|
|
|
|
|
|
|
static PagesModelItem readMetadata(const QString& path);
|
|
|
|
static QList<PagesModelItem> readMetadata(const QStringList& paths);
|
2023-09-27 10:56:10 +00:00
|
|
|
|
|
|
|
static void readMetadata(PagesModelItem &item);
|
|
|
|
static void readMetadata(QList<PagesModelItem> &items);
|
|
|
|
|
2024-10-30 11:19:53 +00:00
|
|
|
static QString extractCategory(const QByteArray& content);
|
|
|
|
static PagesModel::Status extractStatus(const QByteArray& content);
|
|
|
|
static QStringList extractFigmaLinks(const QByteArray& content);
|
|
|
|
|
2023-10-03 09:48:40 +00:00
|
|
|
void setFigmaLinks(const QString& title, const QStringList& links);
|
|
|
|
|
2023-09-27 10:56:10 +00:00
|
|
|
QString m_path;
|
2023-07-31 12:21:14 +00:00
|
|
|
QList<PagesModelItem> m_items;
|
2023-10-03 09:48:40 +00:00
|
|
|
QMap<QString, FigmaLinksModel*> m_figmaSubmodels;
|
2023-10-09 20:26:50 +00:00
|
|
|
DirectoryFilesWatcher* m_pagesWatcher;
|
2023-07-31 12:21:14 +00:00
|
|
|
};
|