File indexing completed on 2024-05-12 17:21:06
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 m_historyList.append(string); 0036 this->save(); 0037 Q_EMIT layoutChanged(); 0038 }; 0039 Q_INVOKABLE void clearHistory(); 0040 0041 private: 0042 QList<QString> m_historyList; 0043 void save(); 0044 HistoryManager(); 0045 };