diff options
author | Tobias Hunger <tobias.hunger@nokia.com> | 2011-05-30 12:14:49 +0000 |
---|---|---|
committer | Tobias Hunger <tobias.hunger@nokia.com> | 2011-06-22 10:46:48 +0200 |
commit | 5f6a91e0095989b6f978cd2b347890110a101d33 (patch) | |
tree | d4bca1310157ceb58ee0b7ccaa3b8c9598affa41 /src/plugins/git/branchmodel.h | |
parent | 9197596000763f1d6eed9c2a25b1605a6fbf8347 (diff) | |
download | qt-creator-5f6a91e0095989b6f978cd2b347890110a101d33.tar.gz |
Git: Rework branch dialog
* Make adding new branches more discoverable
* Make adding tracking branches more discoverable
* Update UI
Task-number: QTCREATORBUG-4943
Task-number: QTCREATORBUG-4944
Change-Id: Idcbf5f8321a3bd04c925e33d094bb479788a7d9b
Reviewed-on: http://codereview.qt.nokia.com/588
Reviewed-by: Qt Sanity Bot <qt_sanity_bot@ovi.com>
Reviewed-by: Tobias Hunger <tobias.hunger@nokia.com>
Diffstat (limited to 'src/plugins/git/branchmodel.h')
-rw-r--r-- | src/plugins/git/branchmodel.h | 116 |
1 files changed, 37 insertions, 79 deletions
diff --git a/src/plugins/git/branchmodel.h b/src/plugins/git/branchmodel.h index 0516baf1eb..c56d209138 100644 --- a/src/plugins/git/branchmodel.h +++ b/src/plugins/git/branchmodel.h @@ -38,105 +38,63 @@ #include <QtCore/QVariant> namespace Git { - namespace Internal { +namespace Internal { class GitClient; -/* A read-only model to list git remote branches in a simple list of branch names. - * The tooltip describes the latest commit (delayed creation). - * Provides virtuals to be able to derive a local branch model with the notion - * of a "current branch". */ +class BranchNode; -class RemoteBranchModel : public QAbstractListModel { +// -------------------------------------------------------------------------- +// BranchModel: +// -------------------------------------------------------------------------- + +class BranchModel : public QAbstractItemModel { Q_OBJECT -public: - explicit RemoteBranchModel(GitClient *client, QObject *parent = 0); - virtual void clear(); - virtual bool refresh(const QString &workingDirectory, QString *errorMessage); +public: + explicit BranchModel(GitClient *client, QObject *parent = 0); + ~BranchModel(); - QString branchName(int row) const; + // QAbstractItemModel + QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const; + QModelIndex parent(const QModelIndex &index) const; + int rowCount(const QModelIndex &parent = QModelIndex()) const; + int columnCount(const QModelIndex &parent = QModelIndex()) const; + QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const; + bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole); + Qt::ItemFlags flags(const QModelIndex &index) const; - // QAbstractListModel - virtual int rowCount(const QModelIndex &parent = QModelIndex()) const; - virtual QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const; - virtual Qt::ItemFlags flags(const QModelIndex &index) const; + void clear(); + bool refresh(const QString &workingDirectory, QString *errorMessage); - int branchCount() const; + void renameBranch(const QString &oldName, const QString &newName); QString workingDirectory() const; - int findBranchByName(const QString &name) const; + GitClient *client() const; -protected: - struct Branch { - bool parse(const QString &line, bool *isCurrent); + QModelIndex currentBranch() const; + QString branchName(const QModelIndex &idx) const; + QStringList localBranchNames() const; + QString sha(const QModelIndex &idx) const; + bool isLocal(const QModelIndex &idx) const; + bool isLeaf(const QModelIndex &idx) const; - QString name; - QString currentSHA; - mutable QString toolTip; - }; - typedef QList<Branch> BranchList; - - /* Parse git output and populate m_branches. */ - bool refreshBranches(const QString &workingDirectory, bool remoteBranches, - int *currentBranch, QString *errorMessage); - bool runGitBranchCommand(const QString &workingDirectory, const QStringList &additionalArgs, QString *output, QString *errorMessage); + void removeBranch(const QModelIndex &idx); + void checkoutBranch(const QModelIndex &idx); + bool branchIsMerged(const QModelIndex &idx); + QModelIndex addBranch(const QString &branchName, bool track, const QString &trackedBranch); private: - QString toolTip(const QString &sha) const; + void parseOutputLine(const QString &line); - const Qt::ItemFlags m_flags; + QString toolTip(const QString &sha) const; GitClient *m_client; QString m_workingDirectory; - BranchList m_branches; -}; - -/* LocalBranchModel: Extends RemoteBranchModel by a read-only - * checkable column indicating the current branch. Provides an - * editable "Type here" new-branch-row at the bottom to create - * a new branch. */ - -class LocalBranchModel : public RemoteBranchModel { - Q_OBJECT -public: - - explicit LocalBranchModel(GitClient *client, - QObject *parent = 0); - - virtual void clear(); - virtual bool refresh(const QString &workingDirectory, QString *errorMessage); - - // is this the "type here" row? - bool isNewBranchRow(int row) const; - bool isNewBranchRow(const QModelIndex & index) const { return isNewBranchRow(index.row()); } - - int currentBranch() const; - - // QAbstractListModel - virtual int rowCount(const QModelIndex &parent = QModelIndex()) const; - virtual QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const; - virtual bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole); - virtual Qt::ItemFlags flags(const QModelIndex &index) const; - -signals: - void newBranchCreated(const QString &); - void newBranchEntered(const QString &); - -private slots: - void slotNewBranchDelayedRefresh(); - -private: - bool checkNewBranchName(const QString &name) const; - - const QVariant m_typeHere; - const QVariant m_typeHereToolTip; - - int m_currentBranch; - QString m_newBranch; + BranchNode *m_rootNode; }; -} -} +} // namespace Internal +} // namespace Git #endif // BRANCHMODEL_H |