File indexing completed on 2025-01-05 04:24:55
0001 #include "colorschemesmodel.h" 0002 #include "lib/tools.h" 0003 #include "lib/ColorScheme.h" 0004 #include <QDebug> 0005 0006 ColorSchemesModel::ColorSchemesModel(QObject *parent) : QAbstractListModel(parent) 0007 { 0008 0009 } 0010 0011 void ColorSchemesModel::classBegin() 0012 { 0013 } 0014 0015 void ColorSchemesModel::componentComplete() 0016 { 0017 this->setList(); 0018 } 0019 0020 void ColorSchemesModel::setList() 0021 { 0022 m_list.clear(); 0023 0024 beginResetModel(); 0025 0026 auto manager = Konsole::ColorSchemeManager::instance() ; 0027 0028 m_list = manager->allColorSchemes(); 0029 0030 // qDebug() << "SETTING CS MODEL" << m_list; 0031 0032 endResetModel(); 0033 } 0034 0035 0036 int ColorSchemesModel::rowCount(const QModelIndex &parent) const 0037 { 0038 if (parent.isValid()) 0039 { 0040 return 0; 0041 } 0042 0043 return m_list.count(); 0044 } 0045 0046 QVariant ColorSchemesModel::data(const QModelIndex &index, int role) const 0047 { 0048 if (!index.isValid()) 0049 return QVariant(); 0050 0051 auto item = m_list[index.row()]; 0052 0053 switch(role) 0054 { 0055 case Role::Name: return item->name(); 0056 case Role::Background: return item->backgroundColor(); 0057 case Role::Foreground: return item->foregroundColor(); 0058 case Role::Highlight: return item->colorEntry(2).color; 0059 case Role::Color3: return item->colorEntry(3).color; 0060 case Role::Color4: return item->colorEntry(4).color; 0061 case Role::Description: return item->description(); 0062 default: return QVariant(); 0063 } 0064 } 0065 0066 QHash<int, QByteArray> ColorSchemesModel::roleNames() const 0067 { 0068 return {{Role::Name, "name"}, 0069 {Role::Background, "background"}, 0070 {Role::Foreground, "foreground"}, 0071 {Role::Highlight, "highlight"}, 0072 {Role::Color3, "color3"}, 0073 {Role::Color4, "color4"}, 0074 {Role::Description, "description"}}; 0075 }