2021-09-30 11:20:43 +08:00
|
|
|
#ifndef CODESNIPPETSMANAGER_H
|
|
|
|
#define CODESNIPPETSMANAGER_H
|
|
|
|
|
|
|
|
#include <QObject>
|
|
|
|
#include "parser/parserutils.h"
|
2021-09-30 12:52:22 +08:00
|
|
|
#include <QAbstractListModel>
|
2021-09-30 11:20:43 +08:00
|
|
|
|
2021-09-30 12:52:22 +08:00
|
|
|
class CodeSnippetsModel: public QAbstractListModel {
|
2021-09-30 11:20:43 +08:00
|
|
|
Q_OBJECT
|
|
|
|
public:
|
|
|
|
void addSnippet(
|
|
|
|
const QString& caption,
|
|
|
|
const QString& prefix,
|
|
|
|
const QString& code,
|
|
|
|
const QString& description,
|
|
|
|
int menuSection);
|
|
|
|
void remove(int index);
|
|
|
|
void clear();
|
2021-09-30 20:10:48 +08:00
|
|
|
QModelIndex lastSnippetCaption();
|
2021-09-30 12:52:22 +08:00
|
|
|
|
|
|
|
// QAbstractItemModel interface
|
|
|
|
public:
|
|
|
|
int rowCount(const QModelIndex &parent) const override;
|
|
|
|
int columnCount(const QModelIndex &parent) const override;
|
|
|
|
QVariant data(const QModelIndex &index, int role) const override;
|
|
|
|
bool setData(const QModelIndex &index, const QVariant &value, int role) override;
|
|
|
|
QVariant headerData(int section, Qt::Orientation orientation, int role) const override;
|
|
|
|
Qt::ItemFlags flags(const QModelIndex &index) const override;
|
2021-09-30 11:20:43 +08:00
|
|
|
const QList<PCodeSnippet> &snippets() const;
|
2021-09-30 12:52:22 +08:00
|
|
|
void updateSnippets(const QList<PCodeSnippet>& snippets);
|
2021-09-30 11:20:43 +08:00
|
|
|
|
|
|
|
private:
|
|
|
|
QList<PCodeSnippet> mSnippets;
|
2021-09-30 12:52:22 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
class CodeSnippetsManager : public QObject
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
public:
|
|
|
|
explicit CodeSnippetsManager(QObject *parent = nullptr);
|
|
|
|
|
|
|
|
void load();
|
|
|
|
void save();
|
|
|
|
const QList<PCodeSnippet> &snippets() const;
|
|
|
|
|
|
|
|
void setSnippets(const QList<PCodeSnippet> &newSnippets);
|
|
|
|
|
|
|
|
signals:
|
2021-09-30 11:20:43 +08:00
|
|
|
|
|
|
|
private:
|
2021-09-30 12:52:22 +08:00
|
|
|
QList<PCodeSnippet> mSnippets;
|
2021-09-30 11:20:43 +08:00
|
|
|
};
|
|
|
|
|
2021-09-30 12:52:22 +08:00
|
|
|
using PCodeSnippetManager = std::shared_ptr<CodeSnippetsManager>;
|
|
|
|
|
2021-09-30 11:20:43 +08:00
|
|
|
#endif // CODESNIPPETSMANAGER_H
|