File indexing completed on 2025-01-05 03:29:15
0001 // SPDX-FileCopyrightText: 2020 Carl Schwan <carl@carlschwan.eu> 0002 // SPDX-FileCopyrightText: 2020 Carson Black <uhhadd@gmail.com> 0003 // 0004 // SPDX-License-Identifier: GPL-3.0-or-later 0005 0006 #pragma once 0007 0008 #include <QColor> 0009 #include <QSqlDatabase> 0010 #include <QSqlTableModel> 0011 0012 #include <memory> 0013 0014 class ThreadedDatabase; 0015 0016 struct ColorEntry { 0017 using ColumnTypes = std::tuple<int, QString, QColor, QColor>; 0018 0019 int id; 0020 QString name; 0021 QColor textColor; 0022 QColor backgroundColor; 0023 }; 0024 0025 /** 0026 * @brief Store all the user's favorite color combinations. 0027 */ 0028 class SavedColorModel : public QAbstractListModel 0029 { 0030 Q_OBJECT 0031 0032 public: 0033 enum ColorRoles { 0034 Id = Qt::UserRole + 1, 0035 Name, 0036 TextColor, 0037 BackgroundColor, 0038 }; 0039 0040 public: 0041 explicit SavedColorModel(QObject *parent = nullptr); 0042 ~SavedColorModel() override; 0043 0044 QHash<int, QByteArray> roleNames() const override; 0045 QVariant data(const QModelIndex &index, int role) const override; 0046 int rowCount(const QModelIndex &parent) const override; 0047 0048 Q_INVOKABLE void addColor(const QString &name, const QColor &foreground, const QColor &background); 0049 Q_INVOKABLE void removeColor(int index); 0050 0051 private: 0052 std::vector<ColorEntry> m_colors; 0053 std::unique_ptr<ThreadedDatabase> m_database; 0054 };