1 /**************************************************************************** 2 ** 3 ** Copyright (C) 2016 The Qt Company Ltd. 4 ** Contact: https://www.qt.io/licensing/ 5 ** 6 ** This file is part of Qt Creator. 7 ** 8 ** Commercial License Usage 9 ** Licensees holding valid commercial Qt licenses may use this file in 10 ** accordance with the commercial license agreement provided with the 11 ** Software or, alternatively, in accordance with the terms contained in 12 ** a written agreement between you and The Qt Company. For licensing terms 13 ** and conditions see https://www.qt.io/terms-conditions. For further 14 ** information use the contact form at https://www.qt.io/contact-us. 15 ** 16 ** GNU General Public License Usage 17 ** Alternatively, this file may be used under the terms of the GNU 18 ** General Public License version 3 as published by the Free Software 19 ** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT 20 ** included in the packaging of this file. Please review the following 21 ** information to ensure the GNU General Public License requirements will 22 ** be met: https://www.gnu.org/licenses/gpl-3.0.html. 23 ** 24 ****************************************************************************/ 25 26 #pragma once 27 28 #include "vcsbase_global.h" 29 30 #include <QStandardItemModel> 31 32 #include <functional> 33 34 namespace VcsBase { 35 36 enum CheckMode 37 { 38 Unchecked, 39 Checked, 40 Uncheckable 41 }; 42 43 class VCSBASE_EXPORT SubmitFileModel : public QStandardItemModel 44 { 45 Q_OBJECT 46 public: 47 explicit SubmitFileModel(QObject *parent = nullptr); 48 49 const QString &repositoryRoot() const; 50 void setRepositoryRoot(const QString &repoRoot); 51 52 // Convenience to create and add rows containing a file plus status text. 53 QList<QStandardItem *> addFile(const QString &fileName, const QString &status = QString(), 54 CheckMode checkMode = Checked, const QVariant &data = QVariant()); 55 56 QString state(int row) const; 57 QString file(int row) const; 58 bool isCheckable(int row) const; 59 bool checked(int row) const; 60 void setChecked(int row, bool check); 61 void setAllChecked(bool check); 62 QVariant extraData(int row) const; 63 64 bool hasCheckedFiles() const; 65 66 // Filter for entries contained in the filter list. Returns the 67 // number of deleted entries. 68 unsigned int filterFiles(const QStringList &filter); 69 70 virtual void updateSelections(SubmitFileModel *source); 71 72 enum FileStatusHint 73 { 74 FileStatusUnknown, 75 FileAdded, 76 FileModified, 77 FileDeleted, 78 FileRenamed, 79 FileUnmerged 80 }; 81 82 // Function that converts(qualifies) a QString/QVariant pair to FileStatusHint 83 // 1st arg is the file status string as passed to addFile() 84 // 2nd arg is the file extra data as passed to addFile() 85 typedef std::function<FileStatusHint (const QString &, const QVariant &)> 86 FileStatusQualifier; 87 88 const FileStatusQualifier &fileStatusQualifier() const; 89 void setFileStatusQualifier(FileStatusQualifier &&func); 90 91 private: 92 QString m_repositoryRoot; 93 FileStatusQualifier m_fileStatusQualifier; 94 }; 95 96 } // namespace VcsBase 97