2021-10-21 08:19:15 +08:00
|
|
|
#ifndef BOOKMARKMODEL_H
|
|
|
|
#define BOOKMARKMODEL_H
|
|
|
|
|
2021-10-21 17:31:25 +08:00
|
|
|
#include <QAbstractTableModel>
|
|
|
|
#include <memory>
|
|
|
|
#include <QDebug>
|
2021-10-21 08:19:15 +08:00
|
|
|
|
2021-10-21 17:31:25 +08:00
|
|
|
struct Bookmark {
|
|
|
|
QString filename;
|
|
|
|
int line;
|
|
|
|
QString description;
|
|
|
|
};
|
|
|
|
|
|
|
|
using PBookmark=std::shared_ptr<Bookmark>;
|
|
|
|
|
|
|
|
class BookmarkModel : public QAbstractTableModel
|
2021-10-21 08:19:15 +08:00
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
public:
|
|
|
|
BookmarkModel(QObject* parent=nullptr);
|
2021-10-21 17:31:25 +08:00
|
|
|
QSet<int> bookmarksInFile(const QString& filename);
|
|
|
|
void addBookmark(const QString&filename, int line, const QString& description);
|
|
|
|
PBookmark bookmark(int i);
|
|
|
|
PBookmark bookmark(const QString&filename, int line);
|
|
|
|
bool removeBookmark(const QString&filename, int line);
|
2021-10-21 19:33:11 +08:00
|
|
|
void removeBookmarks(const QString& filename);
|
2021-10-21 17:31:25 +08:00
|
|
|
void clear();
|
|
|
|
bool updateDescription(const QString&filename, int line, const QString& description);
|
|
|
|
void save(const QString& filename);
|
|
|
|
void load(const QString& filename);
|
|
|
|
void removeBookmarkAt(int i);
|
|
|
|
public slots:
|
|
|
|
void onFileDeleteLines(const QString& filename, int startLine, int count);
|
|
|
|
void onFileInsertLines(const QString& filename, int startLine, int count);
|
|
|
|
private:
|
|
|
|
bool isBookmarkExists(const QString&filename, int line);
|
2021-10-22 16:43:53 +08:00
|
|
|
|
2021-10-21 17:31:25 +08:00
|
|
|
private:
|
|
|
|
QList<PBookmark> mBookmarks;
|
|
|
|
|
|
|
|
// QAbstractItemModel interface
|
|
|
|
public:
|
|
|
|
int rowCount(const QModelIndex &parent) const override;
|
|
|
|
QVariant data(const QModelIndex &index, int role) const override;
|
|
|
|
int columnCount(const QModelIndex &parent) const override;
|
|
|
|
|
|
|
|
// QAbstractItemModel interface
|
|
|
|
public:
|
|
|
|
QVariant headerData(int section, Qt::Orientation orientation, int role) const override;
|
2021-10-21 08:19:15 +08:00
|
|
|
};
|
|
|
|
|
2021-10-21 17:31:25 +08:00
|
|
|
using PBookmarkModel = std::shared_ptr<BookmarkModel>;
|
|
|
|
|
2021-10-21 08:19:15 +08:00
|
|
|
#endif // BOOKMARKMODEL_H
|