File indexing completed on 2024-05-12 05:44:27

0001 /***************************************************************************
0002  *   Copyright (C) 2008 by Rajko Albrecht  ral@alwins-world.de             *
0003  *   https://kde.org/applications/development/org.kde.kdesvn               *
0004  *                                                                         *
0005  *   This program is free software; you can redistribute it and/or modify  *
0006  *   it under the terms of the GNU General Public License as published by  *
0007  *   the Free Software Foundation; either version 2 of the License, or     *
0008  *   (at your option) any later version.                                   *
0009  *                                                                         *
0010  *   This program is distributed in the hope that it will be useful,       *
0011  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
0012  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
0013  *   GNU General Public License for more details.                          *
0014  *                                                                         *
0015  *   You should have received a copy of the GNU General Public License     *
0016  *   along with this program; if not, write to the                         *
0017  *   Free Software Foundation, Inc.,                                       *
0018  *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.         *
0019  ***************************************************************************/
0020 #ifndef SVNITEMMODEL_H
0021 #define SVNITEMMODEL_H
0022 
0023 #include <QAbstractItemModel>
0024 #include <QScopedPointer>
0025 
0026 #include "svnitemmodelfwd.h"
0027 #include "svnqt/svnqttypes.h"
0028 
0029 class SvnItemModelData;
0030 class QItemSelectionModel;
0031 class MainTreeWidget;
0032 class SvnActions;
0033 class QMimeData;
0034 
0035 namespace svn
0036 {
0037 class Path;
0038 }
0039 
0040 #define SORT_ROLE Qt::UserRole + 1
0041 #define FILTER_ROLE Qt::UserRole + 2
0042 #define BG_ROLE Qt::UserRole + 3
0043 
0044 class SvnItemModel : public QAbstractItemModel
0045 {
0046     Q_OBJECT
0047 public:
0048     explicit SvnItemModel(MainTreeWidget *display, QObject *parent = nullptr);
0049     ~SvnItemModel() override;
0050 
0051     void clear();
0052 
0053     enum Column { Name = 0, Status, LastRevision, LastAuthor, LastDate, Locked, ColumnCount };
0054 
0055     QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const override;
0056     QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
0057     QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override;
0058     int columnCount(const QModelIndex &parent = QModelIndex()) const override;
0059     int rowCount(const QModelIndex &parent = QModelIndex()) const override;
0060     QModelIndex parent(const QModelIndex &index) const override;
0061     bool hasChildren(const QModelIndex &parent = QModelIndex()) const override;
0062     bool canFetchMore(const QModelIndex &parent) const override;
0063     void fetchMore(const QModelIndex &parent) override;
0064     Qt::ItemFlags flags(const QModelIndex &index) const override;
0065 
0066     //! Returns the very first item in list.
0067     /*!
0068      * This item marks the working copy itself when a working copy is opened.
0069      * When opened a repository it is just an entry.
0070      */
0071     SvnItemModelNode *firstRootChild();
0072     SvnItemModelNode *nodeForIndex(const QModelIndex &index);
0073     QModelIndex firstRootIndex();
0074     void setRootNodeStat(const svn::StatusPtr &);
0075 
0076     SvnActions *svnWrapper();
0077 
0078     int checkDirs(const QString &_what, SvnItemModelNode *parent);
0079     Qt::DropActions supportedDropActions() const override;
0080     QStringList mimeTypes() const override;
0081     QMimeData *mimeData(const QModelIndexList &indexes) const override;
0082 
0083     bool dropUrls(const QList<QUrl> &data, Qt::DropAction action, int row, int column, const QModelIndex &parent, bool intern);
0084 
0085     bool filterIndex(const QModelIndex &, int, svnmodel::ItemTypeFlag) const;
0086 
0087     /* svn actions starts here */
0088     void makeIgnore(const QModelIndex &);
0089 
0090     //! looks if \a aPath exists in tree
0091     /*! Looks always for perfect match,
0092      * \return node of matched item or 0
0093      */
0094     SvnItemModelNode *findPath(const svn::Path &aPath);
0095     //! looks if \a aPath exists in tree
0096     /*! Looks always for perfect match,
0097      * \return QModelIndex of matched item or invalid QModelIndex
0098      */
0099     QModelIndex findIndex(const svn::Path &aPath);
0100     void initDirWatch();
0101     bool refreshCurrentTree();
0102     bool refreshDirnode(SvnItemModelNodeDir *, bool check_empty = false, bool notrec = false);
0103     bool refreshItem(SvnItemModelNode *);
0104     bool refreshIndex(const QModelIndex &idx);
0105     void emitDataChangedRow(const QModelIndex &idx);
0106 
0107     void clearNodeDir(SvnItemModelNodeDir *);
0108 
0109     const QString &uniqueIdentifier() const;
0110 
0111 Q_SIGNALS:
0112     void urlDropped(const QList<QUrl> &, Qt::DropAction, const QModelIndex &, bool);
0113     void clientException(const QString &);
0114     void itemsFetched(const QModelIndex &);
0115 
0116 protected:
0117     /* the parent entry must removed from list before */
0118     void insertDirs(SvnItemModelNode *_parent, svn::StatusEntries &);
0119     //! \a ind must be a directory index
0120     void checkAddNewItems(const QModelIndex &ind);
0121     bool checkRootNode();
0122     int checkUnversionedDirs(SvnItemModelNode *_parent);
0123     void beginRemoveRows(const QModelIndex &parent, int first, int last);
0124 
0125 public Q_SLOTS:
0126     virtual void slotNotifyMessage(const QString &);
0127 
0128 protected Q_SLOTS:
0129     void slotCreated(const QString &);
0130     void slotDeleted(const QString &);
0131     void slotDirty(const QString &);
0132 
0133 private:
0134     friend class SvnItemModelData;
0135     QScopedPointer<SvnItemModelData> m_Data;
0136     bool insertRows(int, int, const QModelIndex & = QModelIndex()) override;
0137     bool insertColumns(int, int, const QModelIndex & = QModelIndex()) override;
0138     bool removeRows(int, int, const QModelIndex & = QModelIndex()) override;
0139     bool removeColumns(int, int, const QModelIndex & = QModelIndex()) override;
0140 };
0141 
0142 #endif