File indexing completed on 2025-01-05 05:14:39
0001 /* 0002 SPDX-FileCopyrightText: 2021 Hamed Masafi <hamed.masfi@gmail.com> 0003 0004 SPDX-License-Identifier: GPL-3.0-or-later 0005 */ 0006 0007 #include "filesmodel.h" 0008 0009 FilesModel::FilesModel(QObject *parent) 0010 : QAbstractListModel(parent) 0011 { 0012 } 0013 0014 int FilesModel::rowCount(const QModelIndex &parent) const 0015 { 0016 Q_UNUSED(parent) 0017 return mFiles.size(); 0018 } 0019 0020 int FilesModel::columnCount(const QModelIndex &parent) const 0021 { 0022 Q_UNUSED(parent) 0023 return 2; 0024 } 0025 0026 QVariant FilesModel::data(const QModelIndex &index, int role) const 0027 { 0028 if (index.row() < 0 || index.row() >= mFiles.size()) 0029 return {}; 0030 0031 if (role == Qt::DisplayRole || role == Qt::EditRole) { 0032 auto row = mFiles[index.row()]; 0033 0034 if (index.column() == 1) 0035 return row.second; 0036 return row.first; 0037 } 0038 0039 return {}; 0040 } 0041 0042 void FilesModel::append(const QString &data) 0043 { 0044 const auto i = data.lastIndexOf(QLatin1Char('/')); 0045 if (i != -1) 0046 mFiles.append({data.mid(i + 1), data}); 0047 else 0048 mFiles.append({data, data}); 0049 } 0050 0051 void FilesModel::addFile(const Git::FileStatus &file) 0052 { 0053 Q_UNUSED(file) 0054 } 0055 0056 #include "moc_filesmodel.cpp"