File indexing completed on 2024-04-28 05:49:04
0001 /* 0002 SPDX-FileCopyrightText: 2021 Waqar Ahmed <waqar.17a@gmail.com> 0003 0004 SPDX-License-Identifier: LGPL-2.0-or-later 0005 */ 0006 #pragma once 0007 0008 #include <QAbstractTableModel> 0009 #include <QList> 0010 #include <QVariant> 0011 0012 #include "git/gitutils.h" 0013 0014 class BranchesDialogModel : public QAbstractTableModel 0015 { 0016 Q_OBJECT 0017 public: 0018 enum Role { FuzzyScore = Qt::UserRole + 1, CheckoutName, RefType, Creator, ItemTypeRole }; 0019 enum ItemType { BranchItem, CreateBranch, CreateBranchFrom }; 0020 0021 explicit BranchesDialogModel(QObject *parent = nullptr); 0022 int rowCount(const QModelIndex &parent = QModelIndex()) const override; 0023 int columnCount(const QModelIndex &parent) const override; 0024 QVariant data(const QModelIndex &idx, int role) const override; 0025 void refresh(const QList<GitUtils::Branch> &branches, bool checkingOut = false); 0026 void clear(); 0027 void clearBranchCreationItems(); 0028 0029 bool setData(const QModelIndex &index, const QVariant &value, int role) override 0030 { 0031 if (!index.isValid()) { 0032 return false; 0033 } 0034 if (role == Role::FuzzyScore) { 0035 auto row = index.row(); 0036 m_modelEntries[row].score = value.toInt(); 0037 } 0038 return QAbstractTableModel::setData(index, value, role); 0039 } 0040 0041 private: 0042 struct Branch { 0043 QString name; 0044 QString remote; 0045 GitUtils::RefType refType; 0046 int score; 0047 ItemType itemType; 0048 }; 0049 0050 QList<BranchesDialogModel::Branch> m_modelEntries; 0051 };