File indexing completed on 2024-05-19 05:51:34
0001 /* 0002 * SPDX-FileCopyrightText: 2020-2021 Han Young <hanyoung@protonmail.com> 0003 * 0004 * SPDX-License-Identifier: GPL-3.0-or-later 0005 */ 0006 0007 #pragma once 0008 0009 #include <QAbstractListModel> 0010 #include <QObject> 0011 0012 class HistoryManager : public QAbstractListModel 0013 { 0014 Q_OBJECT 0015 Q_PROPERTY(QString expression WRITE addHistory) 0016 public: 0017 static HistoryManager *inst() 0018 { 0019 static HistoryManager singleton; 0020 return &singleton; 0021 } 0022 int rowCount(const QModelIndex &parent) const override 0023 { 0024 Q_UNUSED(parent) 0025 return m_historyList.count(); 0026 }; 0027 QVariant data(const QModelIndex &index, int role) const override 0028 { 0029 Q_UNUSED(index) 0030 Q_UNUSED(role) 0031 return m_historyList.at(index.row()); 0032 }; 0033 void addHistory(const QString &string) 0034 { 0035 beginInsertRows({}, m_historyList.count(), m_historyList.count()); 0036 m_historyList.append(string); 0037 endInsertRows(); 0038 0039 this->save(); 0040 }; 0041 Q_INVOKABLE void clearHistory(); 0042 Q_INVOKABLE void deleteFromHistory(const int index); 0043 0044 private: 0045 QList<QString> m_historyList; 0046 void save(); 0047 HistoryManager(); 0048 };