Warning, file /maui/strike/src/models/cmaketargetsmodel.cpp was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).
0001 #include "cmaketargetsmodel.h" 0002 #include <QDebug> 0003 0004 CMakeTargetsModel::CMakeTargetsModel(QObject *parent) : QAbstractListModel(parent) 0005 { 0006 0007 } 0008 0009 void CMakeTargetsModel::setTargetData(const CMakeProjectTargets &data) 0010 { 0011 qDebug() << "Setting the targets model" << data.keys(); 0012 m_data = data; 0013 this->setList(); 0014 emit dataChanged(m_data); 0015 } 0016 0017 QVector<CMakeTarget> CMakeTargetsModel::filterBy(const CMakeTarget::Type &type) 0018 { 0019 QVector<CMakeTarget> res; 0020 for(const auto &key : m_data.keys()) 0021 { 0022 for(const auto &target : m_data.value(key)) 0023 { 0024 if(target.type == type) 0025 { 0026 res.append(target); 0027 } 0028 } 0029 } 0030 0031 return res; 0032 } 0033 0034 void CMakeTargetsModel::setList() 0035 { 0036 this->beginResetModel(); 0037 m_targets = this->filterBy(CMakeTarget::Executable); 0038 this->endResetModel(); 0039 0040 } 0041 0042 int CMakeTargetsModel::rowCount(const QModelIndex &parent) const 0043 { 0044 if (parent.isValid()) 0045 { 0046 return 0; 0047 } 0048 0049 return m_targets.size(); 0050 } 0051 0052 QVariant CMakeTargetsModel::data(const QModelIndex &index, int role) const 0053 { 0054 if (!index.isValid()) 0055 return QVariant(); 0056 0057 auto value = m_targets.at(index.row()); 0058 0059 switch(role) 0060 { 0061 case Roles::Name : return QVariant(value.name); 0062 case Roles::Type : return QVariant(value.type); 0063 case Roles::Target : return QVariant::fromValue(value); 0064 case Roles::Sources : return QVariant::fromValue(value.sources); 0065 case Roles::Artifacts : return QVariant::fromValue(value.artifacts); 0066 default: return QVariant(); 0067 } 0068 } 0069 0070 QHash<int, QByteArray> CMakeTargetsModel::roleNames() const 0071 { 0072 return QHash<int, QByteArray> { 0073 {Roles::Url, "url"}, 0074 {Roles::Target, "target"}, 0075 {Roles::Name, "name"}, 0076 {Roles::Type, "Type"}, 0077 {Roles::Sources, "Sources"}, 0078 {Roles::Data, "Data"}, 0079 {Roles::Artifacts, "artifacts"}, 0080 }; 0081 }