From 70a1d1cadf23425a72c7ffa15c601d20413912cb Mon Sep 17 00:00:00 2001 From: Nils Fenner Date: Wed, 21 Jan 2015 14:53:56 +0100 Subject: [PATCH 01/80] update history model, when a git reference was created --- History/HistoryModel.cpp | 9 +++++++++ History/HistoryModel.h | 9 +++++++++ 2 files changed, 18 insertions(+) diff --git a/History/HistoryModel.cpp b/History/HistoryModel.cpp index 8ce21a5..73858cd 100644 --- a/History/HistoryModel.cpp +++ b/History/HistoryModel.cpp @@ -21,6 +21,8 @@ #include #include "libMacGitverCore/App/MacGitver.hpp" +#include "libMacGitverCore/RepoMan/RepoMan.hpp" +#include "libMacGitverCore/RepoMan/Ref.hpp" #include "libGitWrap/Reference.hpp" @@ -37,6 +39,8 @@ HistoryModel::HistoryModel( const Git::Repository& repo, QObject* parent ) mDisplays = 0; + RM::RepoMan &rm = MacGitver::repoMan(); + connect( &rm, SIGNAL(refCreated(RM::Repo*,RM::Ref*)), this, SLOT(onRefCreated(RM::Repo*,RM::Ref*)) ); Q_ASSERT( mRepo.isValid() ); } @@ -223,6 +227,11 @@ void HistoryModel::afterAppend() endInsertRows(); } +void HistoryModel::onRefCreated(RM::Repo* repo, RM::Ref* ref) +{ + scanInlineReferences(); +} + void HistoryModel::ensurePopulated( int row ) { HistoryEntry* e = mEntries[ row ]; diff --git a/History/HistoryModel.h b/History/HistoryModel.h index baa83e2..614fa91 100644 --- a/History/HistoryModel.h +++ b/History/HistoryModel.h @@ -25,6 +25,12 @@ #include "libGitWrap/Repository.hpp" +namespace RM +{ + class Ref; + class Repo; +} + class HistoryEntry; class HistoryModel : public QAbstractTableModel @@ -104,6 +110,9 @@ private slots: void beforeAppend(); void afterAppend(); + // react on RepoMan signals + void onRefCreated(RM::Repo* repo, RM::Ref* ref); + private: InlineRefDisplays mDisplays; Git::Repository mRepo; From 2e9f861f32e971f19ac28a230a5063347703c55f Mon Sep 17 00:00:00 2001 From: Nils Fenner Date: Wed, 21 Jan 2015 14:56:10 +0100 Subject: [PATCH 02/80] privatized appending history entries --- History/HistoryModel.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/History/HistoryModel.h b/History/HistoryModel.h index 614fa91..eb89319 100644 --- a/History/HistoryModel.h +++ b/History/HistoryModel.h @@ -37,6 +37,7 @@ class HistoryModel : public QAbstractTableModel { friend class HistoryBuilder; Q_OBJECT + public: enum Columns { @@ -94,10 +95,10 @@ class HistoryModel : public QAbstractTableModel public: void setShowRoots( Roots roots ); void changeDisplays(InlineRefDisplays displays, bool activate); - void append( HistoryEntry* entry ); void buildHistory(); private: + void append( HistoryEntry* entry ); void updateRows( int firstRow, int lastRow ); void scanInlineReferences(); From 65e183e64441ce710bfe7cfe738b74c0d07d616f Mon Sep 17 00:00:00 2001 From: Nils Fenner Date: Wed, 21 Jan 2015 14:56:50 +0100 Subject: [PATCH 03/80] moved assertion to where it belongs --- History/HistoryModel.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/History/HistoryModel.cpp b/History/HistoryModel.cpp index 73858cd..f893b6f 100644 --- a/History/HistoryModel.cpp +++ b/History/HistoryModel.cpp @@ -34,6 +34,8 @@ HistoryModel::HistoryModel( const Git::Repository& repo, QObject* parent ) : QAbstractTableModel( parent ) { mRepo = repo; + Q_ASSERT( mRepo.isValid() ); + mMode = modeSimple; mShowRoots = ShowRootHeadOnly; @@ -41,7 +43,6 @@ HistoryModel::HistoryModel( const Git::Repository& repo, QObject* parent ) RM::RepoMan &rm = MacGitver::repoMan(); connect( &rm, SIGNAL(refCreated(RM::Repo*,RM::Ref*)), this, SLOT(onRefCreated(RM::Repo*,RM::Ref*)) ); - Q_ASSERT( mRepo.isValid() ); } HistoryModel::~HistoryModel() From a962bddd2a3315540721e346831d09f66b2c7a14 Mon Sep 17 00:00:00 2001 From: Nils Fenner Date: Wed, 21 Jan 2015 14:58:24 +0100 Subject: [PATCH 04/80] simplified readability of HistoryModel::scanInlineRefs() --- History/HistoryModel.cpp | 42 ++++++++++++++-------------------------- 1 file changed, 15 insertions(+), 27 deletions(-) diff --git a/History/HistoryModel.cpp b/History/HistoryModel.cpp index f893b6f..dcdec8f 100644 --- a/History/HistoryModel.cpp +++ b/History/HistoryModel.cpp @@ -390,43 +390,31 @@ void HistoryModel::scanInlineReferences() HistoryInlineRefs newRefs = refsById.value( e->id() ); HistoryInlineRefs oldRefs = e->refs(); - if( !newRefs.count() ) + if( oldRefs.count() != newRefs.count() ) { - if( !oldRefs.count() ) - { - continue; - } e->setInlineRefs( newRefs ); updateRows( i, i ); + continue; } - else - { - if( oldRefs.count() != newRefs.count() ) - { - e->setInlineRefs( newRefs ); - updateRows( i, i ); - continue; - } - int diffs = newRefs.count(); - for( int j = 0; j < newRefs.count(); j++ ) + int diffs = newRefs.count(); + for( int j = 0; j < newRefs.count(); j++ ) + { + QString newRef = newRefs.at( j ).mRefName; + for( int k = 0; k < oldRefs.count(); k++ ) { - QString newRef = newRefs.at( j ).mRefName; - for( int k = 0; k < oldRefs.count(); k++ ) + if( oldRefs.at( k ).mRefName == newRef ) { - if( oldRefs.at( k ).mRefName == newRef ) - { - diffs--; - break; - } + diffs--; + break; } } + } - if( diffs ) - { - e->setInlineRefs( newRefs ); - updateRows( i, i ); - } + if( diffs ) + { + e->setInlineRefs( newRefs ); + updateRows( i, i ); } } From ba083864cb5a61b1ef055499cd483018a9d351b1 Mon Sep 17 00:00:00 2001 From: Nils Fenner Date: Fri, 23 Jan 2015 14:38:44 +0100 Subject: [PATCH 05/80] added some documentation --- History/HistoryModel.h | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/History/HistoryModel.h b/History/HistoryModel.h index eb89319..c0427ea 100644 --- a/History/HistoryModel.h +++ b/History/HistoryModel.h @@ -31,6 +31,7 @@ namespace RM class Repo; } + class HistoryEntry; class HistoryModel : public QAbstractTableModel @@ -111,8 +112,13 @@ private slots: void beforeAppend(); void afterAppend(); - // react on RepoMan signals + /** + * @internal + * @see RM::EventInterface + */ + ///@{ void onRefCreated(RM::Repo* repo, RM::Ref* ref); + ///@} private: InlineRefDisplays mDisplays; From 5b63ba7f7c4906aa52ceaae7147477cc9aad1f8e Mon Sep 17 00:00:00 2001 From: Nils Fenner Date: Fri, 23 Jan 2015 14:45:51 +0100 Subject: [PATCH 06/80] Ref-Model: added method to lookup a RefScope item for a Git::Reference --- RefsViews/Branches/BranchesModel.cpp | 10 ++++++++++ RefsViews/Branches/BranchesModel.hpp | 4 ++++ 2 files changed, 14 insertions(+) diff --git a/RefsViews/Branches/BranchesModel.cpp b/RefsViews/Branches/BranchesModel.cpp index 0b3cbcd..adadb19 100644 --- a/RefsViews/Branches/BranchesModel.cpp +++ b/RefsViews/Branches/BranchesModel.cpp @@ -165,6 +165,16 @@ bool BranchesModel::hasChildren( const QModelIndex& parent ) const return parentItem->children.count() > 0; } +RefScope* BranchesModel::scopeForRef(const Git::Reference& ref) const +{ + RefItem* scope = NULL; + if ( ref.isLocal() ) scope = mRoot->children[0]; + else if ( ref.isRemote() ) scope = mRoot->children[1]; + else scope = mRoot->children[2]; + + return static_cast< RefScope* >( scope ); +} + void BranchesModel::rereadBranches() { beginResetModel(); diff --git a/RefsViews/Branches/BranchesModel.hpp b/RefsViews/Branches/BranchesModel.hpp index 48876b9..5257ba6 100644 --- a/RefsViews/Branches/BranchesModel.hpp +++ b/RefsViews/Branches/BranchesModel.hpp @@ -26,6 +26,7 @@ #include "Branches/BranchesViewData.hpp" class RefItem; +class RefScope; class BranchesModel : public QAbstractItemModel { @@ -50,6 +51,9 @@ class BranchesModel : public QAbstractItemModel signals: void gitError( const Git::Result& error ); +private: + inline RefScope* scopeForRef( const Git::Reference& ref ) const; + private: BranchesViewData* mData; RefItem* mRoot; From 83013aeff8e09d8d82ea4db70a2f032843ce5493 Mon Sep 17 00:00:00 2001 From: Nils Fenner Date: Fri, 23 Jan 2015 14:48:29 +0100 Subject: [PATCH 07/80] Ref-Model: added internal method to get a model index for a random RefItem --- RefsViews/Branches/BranchesModel.cpp | 11 +++++++++++ RefsViews/Branches/BranchesModel.hpp | 2 ++ 2 files changed, 13 insertions(+) diff --git a/RefsViews/Branches/BranchesModel.cpp b/RefsViews/Branches/BranchesModel.cpp index adadb19..d453cb1 100644 --- a/RefsViews/Branches/BranchesModel.cpp +++ b/RefsViews/Branches/BranchesModel.cpp @@ -244,3 +244,14 @@ void BranchesModel::rereadBranches() endResetModel(); } +QModelIndex BranchesModel::index(RefItem* item) const +{ + if ( !item || (item == mRoot) ) + { + return QModelIndex(); + } + + RefItem* parent = item->parent ? item->parent : mRoot; + int row = parent->children.indexOf( item ); + return createIndex( row, 0, item ); +} diff --git a/RefsViews/Branches/BranchesModel.hpp b/RefsViews/Branches/BranchesModel.hpp index 5257ba6..bca6d3a 100644 --- a/RefsViews/Branches/BranchesModel.hpp +++ b/RefsViews/Branches/BranchesModel.hpp @@ -52,6 +52,8 @@ class BranchesModel : public QAbstractItemModel void gitError( const Git::Result& error ); private: + QModelIndex index(RefItem* item) const; + inline RefScope* scopeForRef( const Git::Reference& ref ) const; private: From c6884a46d11ec5d44684a0162b35d56a9f39741d Mon Sep 17 00:00:00 2001 From: Nils Fenner Date: Fri, 23 Jan 2015 14:51:31 +0100 Subject: [PATCH 08/80] Ref-Model: added internal methods to insert a Git::Reference into the tree --- RefsViews/Branches/BranchesModel.cpp | 68 ++++++++++++++++++++++++++++ RefsViews/Branches/BranchesModel.hpp | 3 ++ 2 files changed, 71 insertions(+) diff --git a/RefsViews/Branches/BranchesModel.cpp b/RefsViews/Branches/BranchesModel.cpp index d453cb1..7c524a2 100644 --- a/RefsViews/Branches/BranchesModel.cpp +++ b/RefsViews/Branches/BranchesModel.cpp @@ -165,6 +165,74 @@ bool BranchesModel::hasChildren( const QModelIndex& parent ) const return parentItem->children.count() > 0; } +void BranchesModel::insertRef(bool notify, const Git::Reference &ref) +{ + RefScope* scope = scopeForRef( ref ); + Q_ASSERT( scope ); + + QStringList parts = ref.shorthand().split( QChar( L'/' ) ); + if ( parts.count() == 1 ) + { + insertBranch( notify, scope, parts.last(), ref ); + return; + } + + RefItem* ns = scope; + for( int j = 0; j < parts.count() - 1; j++ ) + { + RefItem* next = NULL; + QString partName = parts[ j ]; + foreach( RefItem* nsChild, ns->children ) + { + if( nsChild->text() == partName ) + { + next = nsChild; + break; + } + } + + if( !next ) + { + next = insertNamespace( notify, ns, partName ); + } + ns = next; + } + + Q_ASSERT( ns ); + + insertBranch( notify, ns, parts.last(), ref ); +} + +RefItem* BranchesModel::insertNamespace(const bool notify, RefItem* parent, const QString& name) +{ + RefItem* next = NULL; + if ( notify ) { + int fr = parent->children.count(); + beginInsertRows( index( parent ), fr, fr ); + } + + next = new RefNameSpace( parent, name ); + + if ( notify ) { + endInsertRows(); + } + return next; +} + +void BranchesModel::insertBranch(const bool notify, RefItem* parent, const QString& name, const Git::Reference& ref) +{ + if ( notify ) { + int row = parent->children.count(); + beginInsertRows( index( parent ), row, row ); + } + + new RefBranch( parent, name, ref ); + + if (notify) { + endInsertRows(); + } +} + RefScope* BranchesModel::scopeForRef(const Git::Reference& ref) const { RefItem* scope = NULL; diff --git a/RefsViews/Branches/BranchesModel.hpp b/RefsViews/Branches/BranchesModel.hpp index bca6d3a..b5e97a3 100644 --- a/RefsViews/Branches/BranchesModel.hpp +++ b/RefsViews/Branches/BranchesModel.hpp @@ -54,6 +54,9 @@ class BranchesModel : public QAbstractItemModel private: QModelIndex index(RefItem* item) const; + void insertRef(bool notify, const Git::Reference& ref); + inline RefItem* insertNamespace(const bool notify, RefItem* parent, const QString& name); + inline void insertBranch(const bool notify, RefItem *ns, const QString &name, const Git::Reference& ref); inline RefScope* scopeForRef( const Git::Reference& ref ) const; private: From 1c6b5265c1ee459bf3862d3d86be3093d8f055ad Mon Sep 17 00:00:00 2001 From: Nils Fenner Date: Fri, 23 Jan 2015 14:53:36 +0100 Subject: [PATCH 09/80] Ref-Model: actually clear the reference tree in case of a model reset --- RefsViews/Branches/BranchesModel.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/RefsViews/Branches/BranchesModel.cpp b/RefsViews/Branches/BranchesModel.cpp index 7c524a2..4b3544e 100644 --- a/RefsViews/Branches/BranchesModel.cpp +++ b/RefsViews/Branches/BranchesModel.cpp @@ -247,10 +247,11 @@ void BranchesModel::rereadBranches() { beginResetModel(); - Git::Repository repo = mData->repository(); qDeleteAll( mRoot->children ); - Q_ASSERT( mRoot->children.isEmpty() ); + mRoot->children.clear(); + + Git::Repository repo = mData->repository(); if( repo.isValid() ) { From 7e5ab6f1004648f9d089d926a99ee7134bc18a18 Mon Sep 17 00:00:00 2001 From: Nils Fenner Date: Fri, 23 Jan 2015 14:57:16 +0100 Subject: [PATCH 10/80] Ref-Model: outsourced creation of references during model reset --- RefsViews/Branches/BranchesModel.cpp | 41 +--------------------------- 1 file changed, 1 insertion(+), 40 deletions(-) diff --git a/RefsViews/Branches/BranchesModel.cpp b/RefsViews/Branches/BranchesModel.cpp index 4b3544e..df24ffb 100644 --- a/RefsViews/Branches/BranchesModel.cpp +++ b/RefsViews/Branches/BranchesModel.cpp @@ -266,46 +266,7 @@ void BranchesModel::rereadBranches() for( int i = 0; i < sl.count(); ++i ) { const Git::Reference ¤tRef = sl[ i ]; - RefScope* parentScope = NULL; - if ( currentRef.isLocal() ) - parentScope = scopeLocal; - else if ( currentRef.isRemote() ) - parentScope = scopeRemote; - else - parentScope = scopeOther; - - QStringList parts = currentRef.shorthand().split( QChar( L'/' ) ); - if ( parts.count() == 1 ) - { - new RefBranch( parentScope, parts.last(), currentRef ); - } - else - { - RefItem* ns = parentScope; - QString totPart; - for( int j = 0; j < parts.count() - 1; j++ ) - { - RefItem* next = NULL; - QString partName = parts[ j ]; - totPart += partName + QChar( L'/' ); - foreach( RefItem* nsChild, ns->children ) - { - if( nsChild->text() == partName ) // + Type - { - next = nsChild; - break; - } - } - if( !next ) - { - next = new RefNameSpace( ns, partName ); - } - ns = next; - } - - Q_ASSERT( ns ); - new RefBranch( ns, parts.last(), currentRef ); - } + insertRef( false, currentRef ); } } } From db0acf8e6bfdf13c088269cd114cb0041373337e Mon Sep 17 00:00:00 2001 From: Nils Fenner Date: Fri, 23 Jan 2015 14:59:39 +0100 Subject: [PATCH 11/80] Ref-Model: always create the RefScope items in a fixed order --- RefsViews/Branches/BranchesModel.cpp | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/RefsViews/Branches/BranchesModel.cpp b/RefsViews/Branches/BranchesModel.cpp index df24ffb..dabddd1 100644 --- a/RefsViews/Branches/BranchesModel.cpp +++ b/RefsViews/Branches/BranchesModel.cpp @@ -247,10 +247,13 @@ void BranchesModel::rereadBranches() { beginResetModel(); - qDeleteAll( mRoot->children ); mRoot->children.clear(); + new RefScope( mRoot, tr( "Local" ) ); + new RefScope( mRoot, tr( "Remote" ) ); + new RefScope( mRoot, tr( "Tags" ) ); + Git::Repository repo = mData->repository(); if( repo.isValid() ) @@ -259,10 +262,6 @@ void BranchesModel::rereadBranches() Git::ReferenceList sl = repo.allReferences( r ); if( !sl.isEmpty() ) { - RefScope* scopeLocal = new RefScope( mRoot, tr( "Local" ) ); - RefScope* scopeRemote = new RefScope( mRoot, tr( "Remote" ) ); - RefScope* scopeOther = new RefScope( mRoot, tr( "Tags" ) ); - for( int i = 0; i < sl.count(); ++i ) { const Git::Reference ¤tRef = sl[ i ]; From 868d3a4f786784fde40c5eb05979b7207e62ec89 Mon Sep 17 00:00:00 2001 From: Nils Fenner Date: Fri, 23 Jan 2015 15:03:59 +0100 Subject: [PATCH 12/80] Ref-Model: react to added references using RM::EventInterface This is to be optimized. Currently it triggers a "re-lookup" of the added reference, using its full qualified name. Instead, the RM::Ref object should be used directly. This needs a bigger re-design of the current code model. --- RefsViews/Branches/BranchesModel.cpp | 15 +++++++++++++++ RefsViews/Branches/BranchesModel.hpp | 15 +++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/RefsViews/Branches/BranchesModel.cpp b/RefsViews/Branches/BranchesModel.cpp index dabddd1..72bfb0d 100644 --- a/RefsViews/Branches/BranchesModel.cpp +++ b/RefsViews/Branches/BranchesModel.cpp @@ -18,6 +18,10 @@ #include +#include "libMacGitverCore/App/MacGitver.hpp" +#include "libMacGitverCore/RepoMan/RepoMan.hpp" +#include "libMacGitverCore/RepoMan/Ref.hpp" + #include "libGitWrap/Result.hpp" #include "libGitWrap/Reference.hpp" @@ -31,6 +35,8 @@ BranchesModel::BranchesModel( BranchesViewData* parent ) , mData( parent ) , mRoot( new RefItem ) { + RM::RepoMan& rm = MacGitver::repoMan(); + connect( &rm, SIGNAL(refCreated(RM::Repo*,RM::Ref*)), this, SLOT(onRefCreated(RM::Repo*,RM::Ref*)) ); } BranchesModel::~BranchesModel() @@ -273,6 +279,15 @@ void BranchesModel::rereadBranches() endResetModel(); } +void BranchesModel::onRefCreated(RM::Repo* repo, RM::Ref* ref) +{ + Git::Result r; + Git::Reference gref = repo->gitRepo().reference( r, ref->fullName() ); + Q_ASSERT( r ); + + insertRef( true, gref ); +} + QModelIndex BranchesModel::index(RefItem* item) const { if ( !item || (item == mRoot) ) diff --git a/RefsViews/Branches/BranchesModel.hpp b/RefsViews/Branches/BranchesModel.hpp index b5e97a3..49c2d01 100644 --- a/RefsViews/Branches/BranchesModel.hpp +++ b/RefsViews/Branches/BranchesModel.hpp @@ -25,6 +25,12 @@ #include "Branches/BranchesViewData.hpp" +namespace RM +{ + class Ref; + class Repo; +} + class RefItem; class RefScope; @@ -51,6 +57,15 @@ class BranchesModel : public QAbstractItemModel signals: void gitError( const Git::Result& error ); +private slots: + /** + * @internal + * @see RM::EventInterface + */ + ///@{ + void onRefCreated(RM::Repo* repo, RM::Ref* ref); + ///@} + private: QModelIndex index(RefItem* item) const; From a63bc26d1e55baa8d3ecc31d168e19210add1799 Mon Sep 17 00:00:00 2001 From: Nils Fenner Date: Tue, 27 Jan 2015 09:53:22 +0100 Subject: [PATCH 13/80] minor cleanup --- RefsViews/Branches/BranchesView.cpp | 2 +- RefsViews/Branches/BranchesView.hpp | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/RefsViews/Branches/BranchesView.cpp b/RefsViews/Branches/BranchesView.cpp index 310727d..c0fb555 100644 --- a/RefsViews/Branches/BranchesView.cpp +++ b/RefsViews/Branches/BranchesView.cpp @@ -37,9 +37,9 @@ BranchesView::BranchesView() : ContextView( "Branches" ) + , mTree( new QTreeView ) , mData( NULL ) { - mTree = new QTreeView; #ifdef Q_OS_MACX mTree->setAttribute( Qt::WA_MacShowFocusRect, false ); #endif diff --git a/RefsViews/Branches/BranchesView.hpp b/RefsViews/Branches/BranchesView.hpp index 0e567e2..022794b 100644 --- a/RefsViews/Branches/BranchesView.hpp +++ b/RefsViews/Branches/BranchesView.hpp @@ -19,13 +19,13 @@ #ifndef MGV_BRANCHES_VIEW_HPP #define MGV_BRANCHES_VIEW_HPP +#include "hic_BranchesViewActions.h" + #include "libBlueSky/Contexts.hpp" class QTreeView; class QModelIndex; -#include "hic_BranchesViewActions.h" - namespace Git { class Reference; From 9fefa6656126bb9f01c569b368309eeb8f03ec16 Mon Sep 17 00:00:00 2001 From: Nils Fenner Date: Tue, 27 Jan 2015 09:54:25 +0100 Subject: [PATCH 14/80] RefsView: expand tree in initial state --- RefsViews/Branches/BranchesView.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/RefsViews/Branches/BranchesView.cpp b/RefsViews/Branches/BranchesView.cpp index c0fb555..8475a0d 100644 --- a/RefsViews/Branches/BranchesView.cpp +++ b/RefsViews/Branches/BranchesView.cpp @@ -264,6 +264,7 @@ void BranchesView::attachedToContext(BlueSky::ViewContext* ctx, BlueSky::ViewCon , this, SLOT(actionFailed(const Git::Result&)) ); mTree->setModel( mData->mSortProxy ); + mTree->expandAll(); } void BranchesView::detachedFromContext(BlueSky::ViewContext* ctx ) From 9d4d7acf05421855cca246b99a482126b4b7e448 Mon Sep 17 00:00:00 2001 From: Nils Fenner Date: Tue, 27 Jan 2015 09:56:19 +0100 Subject: [PATCH 15/80] Commit Dialog: Show errors during commit as warning message. --- WorkingTree/CommitDialog.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/WorkingTree/CommitDialog.cpp b/WorkingTree/CommitDialog.cpp index 3335ad4..4326011 100644 --- a/WorkingTree/CommitDialog.cpp +++ b/WorkingTree/CommitDialog.cpp @@ -85,8 +85,8 @@ void CommitDialog::onCommit() if ( !r ) { - QMessageBox::information( this, trUtf8("Failed to commit"), - trUtf8("Failed to commit. Git message:\n%1").arg(r.errorText())); + QMessageBox::warning( this, tr("Failed to commit"), + tr("Failed to commit. Git message:\n%1").arg(r.errorText())); } } From 30984d5ccdfa9e89af1af8f3f5b2a1f272ede7be Mon Sep 17 00:00:00 2001 From: Nils Fenner Date: Tue, 27 Jan 2015 10:06:54 +0100 Subject: [PATCH 16/80] History-Diff: Moved "diff to parent commits" to top. This sets "Diff To: All parents" as "default" behaviour. Technically, there is no default, but it is the first entry in the list. Selecting a default behaviour is a possible candidate for "History Settings". --- History/HistoryDiff.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/History/HistoryDiff.cpp b/History/HistoryDiff.cpp index c5301bd..b05a436 100644 --- a/History/HistoryDiff.cpp +++ b/History/HistoryDiff.cpp @@ -52,6 +52,8 @@ HistoryDiff::HistoryDiff() mToolbar = new QToolBar; mDiffTo = new QComboBox; + mDiffTo->addItem( trUtf8( "All parents" ), DTT_AllParents ); + mDiffTo->addItem( trUtf8( "Parent" ), DTT_Parent ); mDiffTo->addItem( trUtf8( "Workingtree" ), DTT_WT ); mDiffTo->addItem( trUtf8( "Index" ), DTT_Index ); mDiffTo->addItem( trUtf8( "Workingtree + Index" ), DTT_WT_and_Index ); @@ -59,8 +61,6 @@ HistoryDiff::HistoryDiff() //mDiffTo->addItem( trUtf8( "SHA-1" ), DTT_AnySHA1 ); mDiffTo->addItem( trUtf8( "Branch" ), DTT_Branch ); mDiffTo->addItem( trUtf8( "Tag" ), DTT_Tag ); - mDiffTo->addItem( trUtf8( "All parents" ), DTT_AllParents ); - mDiffTo->addItem( trUtf8( "Parent" ), DTT_Parent ); mToolbar->addWidget( new QLabel( trUtf8( "Diff to:" ) ) ); mToolbar->addWidget( mDiffTo ); From a859d14344f486343659018b540dd7403f24600a Mon Sep 17 00:00:00 2001 From: Nils Fenner Date: Tue, 27 Jan 2015 15:52:46 +0100 Subject: [PATCH 17/80] RefsView: added RefsViewDelegate --- RefsViews/CMakeLists.txt | 2 ++ RefsViews/RefItem.cpp | 1 - RefsViews/RefItem.hpp | 4 ++- RefsViews/RefsViewDelegate.cpp | 47 ++++++++++++++++++++++++++++++++++ RefsViews/RefsViewDelegate.h | 17 ++++++++++++ 5 files changed, 69 insertions(+), 2 deletions(-) create mode 100644 RefsViews/RefsViewDelegate.cpp create mode 100644 RefsViews/RefsViewDelegate.h diff --git a/RefsViews/CMakeLists.txt b/RefsViews/CMakeLists.txt index e9d7df6..7a1d629 100644 --- a/RefsViews/CMakeLists.txt +++ b/RefsViews/CMakeLists.txt @@ -15,6 +15,7 @@ SET( SRC_FILES RefItem.cpp RefRenameDialog.cpp RefsSortProxy.cpp + RefsViewDelegate.cpp Branches/BranchesModel.cpp Branches/BranchesView.cpp @@ -28,6 +29,7 @@ SET( HDR_FILES RefItem.hpp RefRenameDialog.hpp RefsSortProxy.hpp + RefsViewDelegate.h Branches/BranchesModel.hpp Branches/BranchesView.hpp diff --git a/RefsViews/RefItem.cpp b/RefsViews/RefItem.cpp index 5e2c4be..09945a8 100644 --- a/RefsViews/RefItem.cpp +++ b/RefsViews/RefItem.cpp @@ -31,7 +31,6 @@ RefItem::RefItem() { } - RefItem::RefItem(RefItem *p) : parent( p ) { diff --git a/RefsViews/RefItem.hpp b/RefsViews/RefItem.hpp index c887942..e816ddf 100644 --- a/RefsViews/RefItem.hpp +++ b/RefsViews/RefItem.hpp @@ -30,7 +30,9 @@ class RefItem public: enum Role { - TypeRole = Qt::UserRole + TypeRole = Qt::UserRole, + RowBgRole = Qt::UserRole + 1, + RowBgGradientRole = Qt::UserRole + 2 }; enum ItemType diff --git a/RefsViews/RefsViewDelegate.cpp b/RefsViews/RefsViewDelegate.cpp new file mode 100644 index 0000000..d8ef327 --- /dev/null +++ b/RefsViews/RefsViewDelegate.cpp @@ -0,0 +1,47 @@ +#include "RefsViewDelegate.h" + +#include "RefItem.hpp" + +#include + + +RefsViewDelegate::RefsViewDelegate(QObject* parent) + : QStyledItemDelegate( parent ) +{ + +} + +RefsViewDelegate::~RefsViewDelegate() +{ + +} + +void RefsViewDelegate::paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const +{ + const QRect rowRect = option.rect.adjusted( -(option.rect.left()), 0, 0, 0 ); + const QVariant rowBg = index.data( RefItem::RowBgRole ); + const QVariant rowGradient = index.data( RefItem::RowBgGradientRole ); + + if ( rowGradient.isValid() ) + { + QColor back = rowGradient.value(); + QColor back2 = back.lighter(135); + + const qreal wLimit = qreal( qMin(30, rowRect.width()) ) / qreal( qMax(30, rowRect.width()) ); + QLinearGradient gradient( 0, 0, rowRect.width(), 0 ); + gradient.setColorAt( 0.0, back2 ); + gradient.setColorAt( wLimit, back ); + gradient.setColorAt( 1.0 - wLimit, back ); + gradient.setColorAt( 1.0, back2 ); + + painter->fillRect( rowRect, gradient ); + } + + else if ( rowBg.isValid() ) + { + painter->fillRect( rowRect, rowBg.value() ); + } + + QStyledItemDelegate::paint( painter, option, index ); +} + diff --git a/RefsViews/RefsViewDelegate.h b/RefsViews/RefsViewDelegate.h new file mode 100644 index 0000000..617b4f1 --- /dev/null +++ b/RefsViews/RefsViewDelegate.h @@ -0,0 +1,17 @@ +#ifndef REFSVIEWDELEGATE_H +#define REFSVIEWDELEGATE_H + +#include + + +class RefsViewDelegate : public QStyledItemDelegate +{ +public: + RefsViewDelegate( QObject* parent = 0 ); + ~RefsViewDelegate(); + +public: + void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const; +}; + +#endif From f3c547570dc2dafdcb6b5c0b6871a05a8cb4ed6e Mon Sep 17 00:00:00 2001 From: Nils Fenner Date: Tue, 27 Jan 2015 15:55:26 +0100 Subject: [PATCH 18/80] RefsView: Set item delegate for tree view. --- RefsViews/Branches/BranchesView.cpp | 1 + RefsViews/Branches/BranchesView.hpp | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/RefsViews/Branches/BranchesView.cpp b/RefsViews/Branches/BranchesView.cpp index 8475a0d..db24957 100644 --- a/RefsViews/Branches/BranchesView.cpp +++ b/RefsViews/Branches/BranchesView.cpp @@ -47,6 +47,7 @@ BranchesView::BranchesView() mTree->setIndentation( 12 ); mTree->setHeaderHidden( true ); mTree->setRootIsDecorated( false ); + mTree->setItemDelegate( &mRefDelegate ); setupActions( this ); diff --git a/RefsViews/Branches/BranchesView.hpp b/RefsViews/Branches/BranchesView.hpp index 022794b..b7a77f4 100644 --- a/RefsViews/Branches/BranchesView.hpp +++ b/RefsViews/Branches/BranchesView.hpp @@ -23,6 +23,8 @@ #include "libBlueSky/Contexts.hpp" +#include "RefsViewDelegate.h" + class QTreeView; class QModelIndex; @@ -32,6 +34,7 @@ namespace Git class Result; } + class BranchesViewData; class BranchesView : public BlueSky::ContextView, private BranchesViewActions @@ -65,6 +68,7 @@ public slots: inline bool checkRemoveRef(const Git::Reference &ref); private: + RefsViewDelegate mRefDelegate; QTreeView* mTree; BranchesViewData* mData; }; From 0cd36210b15d9424b7565ff7310252b2f1f56b16 Mon Sep 17 00:00:00 2001 From: Nils Fenner Date: Tue, 27 Jan 2015 16:05:44 +0100 Subject: [PATCH 19/80] RefsView: return the base color for RowBgGradientRole The gradient will be created in the item delegate. --- RefsViews/RefItem.cpp | 22 +++++++--------------- 1 file changed, 7 insertions(+), 15 deletions(-) diff --git a/RefsViews/RefItem.cpp b/RefsViews/RefItem.cpp index 09945a8..2b9671b 100644 --- a/RefsViews/RefItem.cpp +++ b/RefsViews/RefItem.cpp @@ -149,24 +149,16 @@ QVariant RefBranch::data(int col, int role) const } } - else if ( role == Qt::BackgroundRole ) + else if ( role == RefItem::RowBgGradientRole ) { Git::Result r; - if ( mRef.isCurrentBranch() ) - { - QLinearGradient g( 0, 0, 0, 30 ); - g.setColorAt( 0.0, QColor(255, 255, 255, 0) ); - g.setColorAt( 0.5, QColor(255, 181, 79) ); - g.setColorAt( 1.0, QColor(255, 255, 255, 0) ); - return QBrush(g); - } - else if ( mRef.compare( mRef.repository().HEAD(r) ) == 0 ) + + if ( mRef.compare( mRef.repository().HEAD(r) ) == 0 ) { - QLinearGradient g( 0, 0, 0, 30 ); - g.setColorAt( 0.0, QColor(255, 255, 255, 0) ); - g.setColorAt( 0.5, QColor(255, 181, 79).lighter() ); - g.setColorAt( 1.0, QColor(255, 255, 255, 0) ); - return QBrush(g); + QColor back = mRef.isCurrentBranch() + ? QColor::fromHsl(35, 255, 190) + : QColor::fromHsl(35, 255, 190).lighter(130); + return back; } } From b4d4bb6254ef39f2526b60ab56ca70252b9eae9c Mon Sep 17 00:00:00 2001 From: Nils Fenner Date: Tue, 27 Jan 2015 16:08:18 +0100 Subject: [PATCH 20/80] RefsView: let the row background be drawn by the item delegate --- RefsViews/RefItem.cpp | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/RefsViews/RefItem.cpp b/RefsViews/RefItem.cpp index 2b9671b..f64ac58 100644 --- a/RefsViews/RefItem.cpp +++ b/RefsViews/RefItem.cpp @@ -86,11 +86,8 @@ QVariant RefScope::data(int col, int role) const case Qt::DisplayRole: return mText; - case Qt::BackgroundRole: - QLinearGradient g( 0, 0, 100, 0 ); - g.setColorAt( 0.0, QColor(0, 0, 0, 0) ); - g.setColorAt( 1.0, QColor(216, 233, 255) ); - return QBrush( g ); + case RefItem::RowBgRole: + return QColor(216, 233, 255); } if ( role == RefItem::TypeRole ) From 5fbd2f059dfbd0f97fdf25ed7d61666435057ff0 Mon Sep 17 00:00:00 2001 From: Nils Fenner Date: Thu, 29 Jan 2015 02:08:13 +0100 Subject: [PATCH 21/80] RefItem: removed unused parameter --- RefsViews/Branches/BranchesModel.cpp | 2 +- RefsViews/RefItem.cpp | 2 +- RefsViews/RefItem.hpp | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/RefsViews/Branches/BranchesModel.cpp b/RefsViews/Branches/BranchesModel.cpp index 72bfb0d..39e94db 100644 --- a/RefsViews/Branches/BranchesModel.cpp +++ b/RefsViews/Branches/BranchesModel.cpp @@ -232,7 +232,7 @@ void BranchesModel::insertBranch(const bool notify, RefItem* parent, const QStri beginInsertRows( index( parent ), row, row ); } - new RefBranch( parent, name, ref ); + new RefBranch( parent, ref ); if (notify) { endInsertRows(); diff --git a/RefsViews/RefItem.cpp b/RefsViews/RefItem.cpp index f64ac58..478e86b 100644 --- a/RefsViews/RefItem.cpp +++ b/RefsViews/RefItem.cpp @@ -125,7 +125,7 @@ QVariant RefNameSpace::data(int col, int role) const } -RefBranch::RefBranch(RefItem *p, const QString &t, const Git::Reference &ref) +RefBranch::RefBranch(RefItem *p, const Git::Reference &ref) : RefItem( p ) , mRef( ref ) { diff --git a/RefsViews/RefItem.hpp b/RefsViews/RefItem.hpp index e816ddf..0ceb344 100644 --- a/RefsViews/RefItem.hpp +++ b/RefsViews/RefItem.hpp @@ -85,7 +85,7 @@ class RefNameSpace : public RefScope class RefBranch : public RefItem { public: - RefBranch( RefItem* p, const QString& t, const Git::Reference &ref ); + explicit RefBranch(RefItem* p, const Git::Reference &ref); QVariant data( int col, int role ) const; bool setData(Git::Result& result, const QVariant &value, int role, int col); From 7e28aae6fd7a6fae9bc51b278e6265c27b9fd7d4 Mon Sep 17 00:00:00 2001 From: Nils Fenner Date: Thu, 29 Jan 2015 04:08:19 +0100 Subject: [PATCH 22/80] RefsView: first steps to migrate to RM::Ref --- RefsViews/Branches/BranchesModel.cpp | 8 ++++++-- RefsViews/Branches/BranchesViewData.cpp | 11 ++--------- RefsViews/Branches/BranchesViewData.hpp | 8 +++++++- 3 files changed, 15 insertions(+), 12 deletions(-) diff --git a/RefsViews/Branches/BranchesModel.cpp b/RefsViews/Branches/BranchesModel.cpp index 39e94db..f9b2c25 100644 --- a/RefsViews/Branches/BranchesModel.cpp +++ b/RefsViews/Branches/BranchesModel.cpp @@ -260,9 +260,13 @@ void BranchesModel::rereadBranches() new RefScope( mRoot, tr( "Remote" ) ); new RefScope( mRoot, tr( "Tags" ) ); - Git::Repository repo = mData->repository(); + RM::Repo* repo = mData->repository(); + Q_ASSERT( repo ); - if( repo.isValid() ) + // TODO: replace git repo with RM::Repo + Git::Repository gitRepo = repo ? repo->gitRepo() : Git::Repository(); + + if( gitRepo.isValid() ) { Git::Result r; Git::ReferenceList sl = repo.allReferences( r ); diff --git a/RefsViews/Branches/BranchesViewData.cpp b/RefsViews/Branches/BranchesViewData.cpp index 323803c..1182f47 100644 --- a/RefsViews/Branches/BranchesViewData.cpp +++ b/RefsViews/Branches/BranchesViewData.cpp @@ -56,16 +56,9 @@ void BranchesViewData::detachedFromContext() mModel = NULL; } -Git::Repository BranchesViewData::repository() const +RM::Repo* BranchesViewData::repository() const { IRepositoryContext* ctx = qobject_cast< IRepositoryContext* >( attachedContext() ); - - if( !ctx ) - { - return Git::Repository(); - } - - RM::Repo* repo = ctx->repository(); - return repo ? repo->gitRepo() : Git::Repository(); + return ctx ? ctx->repository() : NULL; } diff --git a/RefsViews/Branches/BranchesViewData.hpp b/RefsViews/Branches/BranchesViewData.hpp index 80f04eb..dbc17a4 100644 --- a/RefsViews/Branches/BranchesViewData.hpp +++ b/RefsViews/Branches/BranchesViewData.hpp @@ -26,6 +26,12 @@ class BranchesModel; class RefsSortProxy; +namespace RM +{ + class Repo; +} + + class BranchesViewData : public BlueSky::ViewContextData { Q_OBJECT @@ -37,7 +43,7 @@ class BranchesViewData : public BlueSky::ViewContextData void detachedFromContext(); public: - Git::Repository repository() const; + RM::Repo* repository() const; public: BranchesModel* mModel; From b97a9574c9a62811ccf98e829eca02b4727ae590 Mon Sep 17 00:00:00 2001 From: Nils Fenner Date: Thu, 29 Jan 2015 04:09:37 +0100 Subject: [PATCH 23/80] updated license info --- RefsViews/Branches/BranchesModel.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/RefsViews/Branches/BranchesModel.cpp b/RefsViews/Branches/BranchesModel.cpp index f9b2c25..be5ab1f 100644 --- a/RefsViews/Branches/BranchesModel.cpp +++ b/RefsViews/Branches/BranchesModel.cpp @@ -1,6 +1,6 @@ /* * MacGitver - * Copyright (C) 2012-2013 The MacGitver-Developers + * Copyright (C) 2015 The MacGitver-Developers * * (C) Sascha Cunz * From 20740c5ab413a400ec17351d6733b0777ff644a4 Mon Sep 17 00:00:00 2001 From: Nils Fenner Date: Thu, 29 Jan 2015 04:12:27 +0100 Subject: [PATCH 24/80] fixup --- RefsViews/Branches/BranchesModel.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/RefsViews/Branches/BranchesModel.cpp b/RefsViews/Branches/BranchesModel.cpp index be5ab1f..eb48d30 100644 --- a/RefsViews/Branches/BranchesModel.cpp +++ b/RefsViews/Branches/BranchesModel.cpp @@ -261,15 +261,14 @@ void BranchesModel::rereadBranches() new RefScope( mRoot, tr( "Tags" ) ); RM::Repo* repo = mData->repository(); - Q_ASSERT( repo ); - // TODO: replace git repo with RM::Repo + // TODO: migrate to RM::Repo Git::Repository gitRepo = repo ? repo->gitRepo() : Git::Repository(); if( gitRepo.isValid() ) { Git::Result r; - Git::ReferenceList sl = repo.allReferences( r ); + Git::ReferenceList sl = gitRepo.allReferences( r ); if( !sl.isEmpty() ) { for( int i = 0; i < sl.count(); ++i ) From bf613c88b8968a6b6d9af9b94f525908cb45d26d Mon Sep 17 00:00:00 2001 From: Nils Fenner Date: Tue, 3 Feb 2015 14:22:51 +0100 Subject: [PATCH 25/80] History-Module: added "less than" comparator for "inline references" Also added the mIsDetached flag, that will be used in upcoming commits. --- History/HistoryEntry.h | 79 +++++++++++++++++++++++++++++++++++++++++- 1 file changed, 78 insertions(+), 1 deletion(-) diff --git a/History/HistoryEntry.h b/History/HistoryEntry.h index f19dc7e..9a64f92 100644 --- a/History/HistoryEntry.h +++ b/History/HistoryEntry.h @@ -61,9 +61,86 @@ struct HistoryInlineRef bool mIsRemote : 1; bool mIsTag : 1; bool mIsStash : 1; + bool mIsDetached : 1; + + bool operator ==(const HistoryInlineRef& other) const + { + if ( this == &other ) { + return true; + } + + return mRefName == other.mRefName && + mRefName == other.mRefName && + mIsBranch == other.mIsBranch && + mIsCurrent == other.mIsCurrent && + mIsRemote == other.mIsRemote && + mIsTag == other.mIsTag && + mIsStash == other.mIsStash && + mIsDetached == other.mIsDetached ; + } + + inline bool operator !=(const HistoryInlineRef& other) const { + return !( *this == other ); + } +}; + +typedef QList< HistoryInlineRef > HistoryInlineRefs; + +struct HistoryInlineRef_LessThan +{ + inline bool detachedHEAD(const HistoryInlineRef& ref) const + { + return ref.mIsDetached && !(ref.mIsTag || ref.mIsBranch || ref.mIsStash); + } + + inline bool nameLessThan(const HistoryInlineRef& a, const HistoryInlineRef& b) const + { + return a.mRefName < b.mRefName; + } + + bool operator ()(const HistoryInlineRef& a, const HistoryInlineRef& b) const + { + // sort order: + // - tag + // - detached HEAD + // - current branch + // - local branch + // - remote branch + // - stash + // - Everything else is sorted by mRefName + + if ( a.mIsTag ) { + // tags have highest priority + return b.mIsTag ? nameLessThan(a, b) : true; + } + + if ( detachedHEAD( a ) ) + { + // a detached HEAD comes right after tag ? -> There can only be one! + return !b.mIsTag; + } + + if ( a.mIsBranch ) + { + if ( b.mIsTag || b.mIsCurrent || detachedHEAD( b ) ) + return false; + + if ( a.mIsCurrent ) { + // a is the current branch + return true; + } + + return ( a.mIsRemote == b.mIsRemote ) ? nameLessThan( a, b ) : !a.mIsRemote; + } + + if ( a.mIsStash ) { + return b.mIsStash ? nameLessThan(a, b) : !(b.mIsTag || b.mIsBranch || detachedHEAD( b )); + } + + return !(b.mIsTag || b.mIsBranch || b.mIsStash || detachedHEAD( b )) ? nameLessThan( a, b ) : false; + } }; -typedef QVector< HistoryInlineRef > HistoryInlineRefs; class HistoryEntry { From a5a92b0bddcd008f6d7f098d40b7fde3f8535de4 Mon Sep 17 00:00:00 2001 From: Nils Fenner Date: Tue, 3 Feb 2015 14:35:54 +0100 Subject: [PATCH 26/80] HistoryModel: outsourced internal update of "inline references" --- History/HistoryModel.cpp | 26 +++++++++++++++----------- History/HistoryModel.h | 7 ++++--- 2 files changed, 19 insertions(+), 14 deletions(-) diff --git a/History/HistoryModel.cpp b/History/HistoryModel.cpp index dcdec8f..447b933 100644 --- a/History/HistoryModel.cpp +++ b/History/HistoryModel.cpp @@ -27,7 +27,6 @@ #include "libGitWrap/Reference.hpp" #include "HistoryModel.h" -#include "HistoryEntry.h" #include "HistoryBuilder.h" HistoryModel::HistoryModel( const Git::Repository& repo, QObject* parent ) @@ -290,7 +289,6 @@ void HistoryModel::scanInlineReferences() { qint64 dur; double avg; - QElapsedTimer timer; Git::ResolvedRefs refs; Git::Result r; Git::Reference refHEAD; @@ -312,7 +310,8 @@ void HistoryModel::scanInlineReferences() return; } - timer.start(); + QElapsedTimer stopwatch; + stopwatch.start(); // Second step: Classify the refs and determine a nice display name for them @@ -382,6 +381,19 @@ void HistoryModel::scanInlineReferences() // Third step: Update the commitlist and mix it with the inline Refs we just found. + updateInlineRefs( refsById ); + + dur = stopwatch.nsecsElapsed(); + avg = double( dur ) / double( refs.count() ); + MacGitver::log(Log::Information, + trUtf8("Found and resolved %1 refs in %2 ns = %3 ns per ref.") + .arg(refs.count()) + .arg(dur) + .arg(avg, 10, 'f', 2)); +} + +void HistoryModel::updateInlineRefs(const QHash& refsById) +{ for( int i = 0; i < mEntries.count(); i++ ) { HistoryEntry* e = mEntries[i]; @@ -417,14 +429,6 @@ void HistoryModel::scanInlineReferences() updateRows( i, i ); } } - - dur = timer.nsecsElapsed(); - avg = double( dur ) / double( refs.count() ); - MacGitver::log(Log::Information, - trUtf8("Found and resolved %1 refs in %2 ns = %3 ns per ref.") - .arg(refs.count()) - .arg(dur) - .arg(avg, 10, 'f', 2)); } void HistoryModel::changeDisplays(InlineRefDisplays displays, bool activate) diff --git a/History/HistoryModel.h b/History/HistoryModel.h index c0427ea..863bdd2 100644 --- a/History/HistoryModel.h +++ b/History/HistoryModel.h @@ -25,15 +25,15 @@ #include "libGitWrap/Repository.hpp" +#include "HistoryEntry.h" + + namespace RM { class Ref; class Repo; } - -class HistoryEntry; - class HistoryModel : public QAbstractTableModel { friend class HistoryBuilder; @@ -102,6 +102,7 @@ class HistoryModel : public QAbstractTableModel void append( HistoryEntry* entry ); void updateRows( int firstRow, int lastRow ); void scanInlineReferences(); + inline void updateInlineRefs(const QHash< Git::ObjectId, HistoryInlineRefs >& refsById); public slots: void ensurePopulated( int row ); From 30a99e0615ec2081855e122245985d4b89d29fb3 Mon Sep 17 00:00:00 2001 From: Nils Fenner Date: Tue, 3 Feb 2015 14:40:47 +0100 Subject: [PATCH 27/80] HistoryModel: fixed comparison of "inline references" while refreshing --- History/HistoryModel.cpp | 24 +++++++----------------- 1 file changed, 7 insertions(+), 17 deletions(-) diff --git a/History/HistoryModel.cpp b/History/HistoryModel.cpp index 447b933..91f9b61 100644 --- a/History/HistoryModel.cpp +++ b/History/HistoryModel.cpp @@ -409,25 +409,15 @@ void HistoryModel::updateInlineRefs(const QHashsetInlineRefs( newRefs ); + updateRows( i, i ); + break; } } - - if( diffs ) - { - e->setInlineRefs( newRefs ); - updateRows( i, i ); - } } } From f2a848bc92c5d761b41868656db6051c869b8186 Mon Sep 17 00:00:00 2001 From: Nils Fenner Date: Tue, 3 Feb 2015 14:51:37 +0100 Subject: [PATCH 28/80] minor cleanup --- History/HistoryModel.cpp | 10 +++++----- History/HistoryModel.h | 1 + 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/History/HistoryModel.cpp b/History/HistoryModel.cpp index 91f9b61..78630f4 100644 --- a/History/HistoryModel.cpp +++ b/History/HistoryModel.cpp @@ -287,11 +287,11 @@ void HistoryModel::buildHistory() void HistoryModel::scanInlineReferences() { - qint64 dur; - double avg; - Git::ResolvedRefs refs; - Git::Result r; - Git::Reference refHEAD; + qint64 dur; + double avg; + Git::ResolvedRefs refs; + Git::Result r; + Git::Reference refHEAD; QHash< Git::ObjectId, HistoryInlineRefs > refsById; if( !mRepo.isValid() ) diff --git a/History/HistoryModel.h b/History/HistoryModel.h index 863bdd2..3fb8e80 100644 --- a/History/HistoryModel.h +++ b/History/HistoryModel.h @@ -101,6 +101,7 @@ class HistoryModel : public QAbstractTableModel private: void append( HistoryEntry* entry ); void updateRows( int firstRow, int lastRow ); + void scanInlineReferences(); inline void updateInlineRefs(const QHash< Git::ObjectId, HistoryInlineRefs >& refsById); From 9404f2c115e73fc4a12be0aae8c455d7375658c9 Mon Sep 17 00:00:00 2001 From: Nils Fenner Date: Tue, 3 Feb 2015 15:05:38 +0100 Subject: [PATCH 29/80] HistoryModel: minor optimizations --- History/HistoryModel.cpp | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/History/HistoryModel.cpp b/History/HistoryModel.cpp index 78630f4..abcb4fb 100644 --- a/History/HistoryModel.cpp +++ b/History/HistoryModel.cpp @@ -294,22 +294,17 @@ void HistoryModel::scanInlineReferences() Git::Reference refHEAD; QHash< Git::ObjectId, HistoryInlineRefs > refsById; - if( !mRepo.isValid() ) - { - return; - } - // First step: Collect all references. refs = mRepo.allResolvedRefs( r ); refHEAD = mRepo.HEAD( r ); - bool detached = mRepo.isHeadDetached(); if( !r ) { MacGitver::log(Log::Error, r.errorText()); return; } + bool detached = mRepo.isHeadDetached(); QElapsedTimer stopwatch; stopwatch.start(); @@ -372,11 +367,12 @@ void HistoryModel::scanInlineReferences() continue; } - if (!refsById.contains(refs[ref])) { - refsById.insert(refs[ref], HistoryInlineRefs()); + const Git::ObjectId &oid = refs[ref]; + if ( !refsById.contains( oid ) ) { + refsById.insert( oid, HistoryInlineRefs() ); } - refsById[refs[ref]].append(inlRef); + refsById[ oid ].append( inlRef ); } // Third step: Update the commitlist and mix it with the inline Refs we just found. From b20401b8b2258bc1666fc59058c4b2c915db2f15 Mon Sep 17 00:00:00 2001 From: Nils Fenner Date: Tue, 3 Feb 2015 15:07:20 +0100 Subject: [PATCH 30/80] HistoryModel: sort "inline references" --- History/HistoryModel.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/History/HistoryModel.cpp b/History/HistoryModel.cpp index abcb4fb..639a80d 100644 --- a/History/HistoryModel.cpp +++ b/History/HistoryModel.cpp @@ -390,6 +390,8 @@ void HistoryModel::scanInlineReferences() void HistoryModel::updateInlineRefs(const QHash& refsById) { + HistoryInlineRef_LessThan lt; + for( int i = 0; i < mEntries.count(); i++ ) { HistoryEntry* e = mEntries[i]; @@ -398,6 +400,9 @@ void HistoryModel::updateInlineRefs(const QHashid() ); HistoryInlineRefs oldRefs = e->refs(); + // sort newRefs: no need to sort oldRefs as it is already sorted) + std::sort( newRefs.begin(), newRefs.end(), lt ); + if( oldRefs.count() != newRefs.count() ) { e->setInlineRefs( newRefs ); From 3cb52b9e7744aaa8889dc92f268a9872a833e349 Mon Sep 17 00:00:00 2001 From: Nils Fenner Date: Tue, 3 Feb 2015 15:08:00 +0100 Subject: [PATCH 31/80] updated license info --- History/HistoryModel.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/History/HistoryModel.cpp b/History/HistoryModel.cpp index 639a80d..2ecc467 100644 --- a/History/HistoryModel.cpp +++ b/History/HistoryModel.cpp @@ -1,6 +1,6 @@ /* * MacGitver - * Copyright (C) 2012-2013 The MacGitver-Developers + * Copyright (C) 2015 The MacGitver-Developers * * (C) Sascha Cunz * (C) Cunz RaD Ltd. From fd594bd45495de1e383554eb71c547a4879b5f00 Mon Sep 17 00:00:00 2001 From: Nils Fenner Date: Tue, 3 Feb 2015 15:16:22 +0100 Subject: [PATCH 32/80] HistoryModel: add an "inline reference" for a detached HEAD --- History/HistoryModel.cpp | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/History/HistoryModel.cpp b/History/HistoryModel.cpp index 2ecc467..5902c32 100644 --- a/History/HistoryModel.cpp +++ b/History/HistoryModel.cpp @@ -305,6 +305,12 @@ void HistoryModel::scanInlineReferences() } bool detached = mRepo.isHeadDetached(); + if ( detached ) { + // append HEAD when detached + refs[QLatin1Literal("< DETACHED >")] = + refHEAD.resolveToObjectId( r ); + } + QElapsedTimer stopwatch; stopwatch.start(); @@ -313,20 +319,10 @@ void HistoryModel::scanInlineReferences() foreach( QString ref, refs.keys() ) { HistoryInlineRef inlRef; + inlRef.mIsDetached = detached; if (mDisplays.testFlag(DisplayLocals) && ref.startsWith(QLatin1String("refs/heads/"))) { - if (ref.endsWith(QLatin1String("HEAD"))) { - if (detached) { - inlRef.mRefName = trUtf8(""); - } - else { - // Skip "HEAD" - continue; - } - } - else { - inlRef.mRefName = ref.mid( strlen( "refs/heads/" ) ); - } + inlRef.mRefName = ref.mid( strlen( "refs/heads/" ) ); inlRef.mIsBranch = true; inlRef.mIsRemote = false; inlRef.mIsTag = false; @@ -362,6 +358,14 @@ void HistoryModel::scanInlineReferences() inlRef.mIsTag = false; inlRef.mIsStash = true; } + else if ( detached && ref == QLatin1Literal("< DETACHED >") ) { + inlRef.mRefName = tr("< DETACHED >"); + inlRef.mIsBranch = false; + inlRef.mIsCurrent = false; + inlRef.mIsRemote = false; + inlRef.mIsTag = false; + inlRef.mIsStash = false; + } else { // qDebug() << "HistoryModel::scanInlineReferences => Unhandled ref:" << ref; continue; From dbcf889d8ff88c5a6538cd8aaa7683f5d882865e Mon Sep 17 00:00:00 2001 From: Nils Fenner Date: Tue, 3 Feb 2015 15:19:05 +0100 Subject: [PATCH 33/80] HistoryModel: Use Qt5 QStringLiterals -> This breaks compatibility to Qt4 We don't need Qt4-Compatibility anyways and I don't want to keep that nasty stuff around. --- History/HistoryModel.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/History/HistoryModel.cpp b/History/HistoryModel.cpp index 5902c32..acf8109 100644 --- a/History/HistoryModel.cpp +++ b/History/HistoryModel.cpp @@ -321,7 +321,7 @@ void HistoryModel::scanInlineReferences() HistoryInlineRef inlRef; inlRef.mIsDetached = detached; - if (mDisplays.testFlag(DisplayLocals) && ref.startsWith(QLatin1String("refs/heads/"))) { + if ( mDisplays.testFlag(DisplayLocals) && ref.startsWith(QLatin1Literal("refs/heads/")) ) { inlRef.mRefName = ref.mid( strlen( "refs/heads/" ) ); inlRef.mIsBranch = true; inlRef.mIsRemote = false; @@ -329,7 +329,7 @@ void HistoryModel::scanInlineReferences() inlRef.mIsStash = false; inlRef.mIsCurrent = inlRef.mRefName == refHEAD.shorthand(); } - else if (mDisplays.testFlag(DisplayTags) && ref.startsWith(QLatin1String("refs/tags/"))) { + else if (mDisplays.testFlag( DisplayTags ) && ref.startsWith( QLatin1Literal("refs/tags/") ) ) { inlRef.mRefName = ref.mid( strlen( "refs/tags/" ) ); inlRef.mIsBranch = false; inlRef.mIsRemote = false; @@ -338,9 +338,9 @@ void HistoryModel::scanInlineReferences() inlRef.mIsStash = false; } else if (mDisplays.testFlag(DisplayRemotes) && - ref.startsWith(QLatin1String("refs/remotes/"))) { + ref.startsWith( QLatin1Literal("refs/remotes/")) ) { - if (ref.endsWith( QLatin1String("HEAD"))) { + if (ref.endsWith( QLatin1Literal("HEAD"))) { continue; // Skip "HEAD" } inlRef.mRefName = ref.mid( strlen( "refs/remotes/" ) ); @@ -350,8 +350,8 @@ void HistoryModel::scanInlineReferences() inlRef.mIsCurrent = false; inlRef.mIsStash = false; } - else if (ref == QLatin1String("refs/stash")) { - inlRef.mRefName = trUtf8( "" ); + else if (ref == QLatin1Literal("refs/stash")) { + inlRef.mRefName = tr( "" ); inlRef.mIsBranch = false; inlRef.mIsCurrent = true; inlRef.mIsRemote = false; From 6ae965be592a8af875dfbdc8a1b4a4a60d977ee5 Mon Sep 17 00:00:00 2001 From: Nils Fenner Date: Tue, 3 Feb 2015 15:19:59 +0100 Subject: [PATCH 34/80] HistoryModel: a stash is never "active" --- History/HistoryModel.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/History/HistoryModel.cpp b/History/HistoryModel.cpp index acf8109..3a414e3 100644 --- a/History/HistoryModel.cpp +++ b/History/HistoryModel.cpp @@ -353,7 +353,7 @@ void HistoryModel::scanInlineReferences() else if (ref == QLatin1Literal("refs/stash")) { inlRef.mRefName = tr( "" ); inlRef.mIsBranch = false; - inlRef.mIsCurrent = true; + inlRef.mIsCurrent = false; inlRef.mIsRemote = false; inlRef.mIsTag = false; inlRef.mIsStash = true; From c2c81078c4658dd9b38428b6b555d713a8c795d4 Mon Sep 17 00:00:00 2001 From: Nils Fenner Date: Tue, 3 Feb 2015 15:20:28 +0100 Subject: [PATCH 35/80] HistoryModel: minor optimization --- History/HistoryModel.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/History/HistoryModel.cpp b/History/HistoryModel.cpp index 3a414e3..3d72982 100644 --- a/History/HistoryModel.cpp +++ b/History/HistoryModel.cpp @@ -327,7 +327,7 @@ void HistoryModel::scanInlineReferences() inlRef.mIsRemote = false; inlRef.mIsTag = false; inlRef.mIsStash = false; - inlRef.mIsCurrent = inlRef.mRefName == refHEAD.shorthand(); + inlRef.mIsCurrent = !detached ? (inlRef.mRefName == refHEAD.shorthand()) : false; } else if (mDisplays.testFlag( DisplayTags ) && ref.startsWith( QLatin1Literal("refs/tags/") ) ) { inlRef.mRefName = ref.mid( strlen( "refs/tags/" ) ); From 0f6d745369ebc8d5b7a20f0857b4aae69b5d14a9 Mon Sep 17 00:00:00 2001 From: Nils Fenner Date: Tue, 3 Feb 2015 15:24:02 +0100 Subject: [PATCH 36/80] HistoryModel: react to symbolic reference changes This is currently not triggered and needs work in RM::RepoMan. --- History/HistoryModel.cpp | 6 ++++++ History/HistoryModel.h | 1 + 2 files changed, 7 insertions(+) diff --git a/History/HistoryModel.cpp b/History/HistoryModel.cpp index 3d72982..bd364aa 100644 --- a/History/HistoryModel.cpp +++ b/History/HistoryModel.cpp @@ -42,6 +42,7 @@ HistoryModel::HistoryModel( const Git::Repository& repo, QObject* parent ) RM::RepoMan &rm = MacGitver::repoMan(); connect( &rm, SIGNAL(refCreated(RM::Repo*,RM::Ref*)), this, SLOT(onRefCreated(RM::Repo*,RM::Ref*)) ); + connect( &rm, SIGNAL(refLinkChanged(RM::Repo*,RM::Ref*)), this, SLOT(onRefLinkChanged(RM::Repo*,RM::Ref*)) ); } HistoryModel::~HistoryModel() @@ -232,6 +233,11 @@ void HistoryModel::onRefCreated(RM::Repo* repo, RM::Ref* ref) scanInlineReferences(); } +void HistoryModel::onRefLinkChanged(RM::Repo* repo, RM::Ref* ref) +{ + scanInlineReferences(); +} + void HistoryModel::ensurePopulated( int row ) { HistoryEntry* e = mEntries[ row ]; diff --git a/History/HistoryModel.h b/History/HistoryModel.h index 3fb8e80..a2bf2d7 100644 --- a/History/HistoryModel.h +++ b/History/HistoryModel.h @@ -120,6 +120,7 @@ private slots: */ ///@{ void onRefCreated(RM::Repo* repo, RM::Ref* ref); + void onRefLinkChanged(RM::Repo* repo, RM::Ref* ref); ///@} private: From 8f195ae9990f4140d9327f2c1813952a2d4f78e9 Mon Sep 17 00:00:00 2001 From: Nils Fenner Date: Tue, 3 Feb 2015 15:24:51 +0100 Subject: [PATCH 37/80] HistoryView: mark a detached HEAD in a red color --- History/HistoryListDelegate.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/History/HistoryListDelegate.cpp b/History/HistoryListDelegate.cpp index 87dd82c..daeca17 100644 --- a/History/HistoryListDelegate.cpp +++ b/History/HistoryListDelegate.cpp @@ -304,7 +304,11 @@ QColor HistoryListDelegate::colorForRefType(const HistoryInlineRef& ref) const return QColor::fromHsl(89, 255, 190); } - return QColor( 0xD9D9D9 ); + if ( ref.mIsStash ) + return QColor( 0xD9D9D9 ); + + // DETACHED REF + return QColor( 0xFF5959 ); } void HistoryListDelegate::paintMessage( QPainter* p, const QStyleOptionViewItem& opt, From 434192494cc0449d3f5a267e0d2287fbcd7b087d Mon Sep 17 00:00:00 2001 From: Nils Fenner Date: Wed, 4 Feb 2015 00:38:05 +0100 Subject: [PATCH 38/80] removed double comparison of mRefName --- History/HistoryEntry.h | 1 - 1 file changed, 1 deletion(-) diff --git a/History/HistoryEntry.h b/History/HistoryEntry.h index 9a64f92..5d05e10 100644 --- a/History/HistoryEntry.h +++ b/History/HistoryEntry.h @@ -70,7 +70,6 @@ struct HistoryInlineRef } return mRefName == other.mRefName && - mRefName == other.mRefName && mIsBranch == other.mIsBranch && mIsCurrent == other.mIsCurrent && mIsRemote == other.mIsRemote && From 2de0af44d95525a99411548bb846153c093a1303 Mon Sep 17 00:00:00 2001 From: Nils Fenner Date: Wed, 4 Feb 2015 01:27:43 +0100 Subject: [PATCH 39/80] moved doxygen comments to cpp --- RefsViews/Branches/BranchesModel.cpp | 6 ++++++ RefsViews/Branches/BranchesModel.hpp | 6 ------ 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/RefsViews/Branches/BranchesModel.cpp b/RefsViews/Branches/BranchesModel.cpp index eb48d30..2daff00 100644 --- a/RefsViews/Branches/BranchesModel.cpp +++ b/RefsViews/Branches/BranchesModel.cpp @@ -282,6 +282,11 @@ void BranchesModel::rereadBranches() endResetModel(); } +/** + * @internal + * @see RM::EventInterface + */ +///@{ void BranchesModel::onRefCreated(RM::Repo* repo, RM::Ref* ref) { Git::Result r; @@ -290,6 +295,7 @@ void BranchesModel::onRefCreated(RM::Repo* repo, RM::Ref* ref) insertRef( true, gref ); } +///@} QModelIndex BranchesModel::index(RefItem* item) const { diff --git a/RefsViews/Branches/BranchesModel.hpp b/RefsViews/Branches/BranchesModel.hpp index 49c2d01..5aaab61 100644 --- a/RefsViews/Branches/BranchesModel.hpp +++ b/RefsViews/Branches/BranchesModel.hpp @@ -58,13 +58,7 @@ class BranchesModel : public QAbstractItemModel void gitError( const Git::Result& error ); private slots: - /** - * @internal - * @see RM::EventInterface - */ - ///@{ void onRefCreated(RM::Repo* repo, RM::Ref* ref); - ///@} private: QModelIndex index(RefItem* item) const; From c2be31596b1abf23d795a126fd57b67c57712b20 Mon Sep 17 00:00:00 2001 From: Nils Fenner Date: Wed, 4 Feb 2015 02:04:33 +0100 Subject: [PATCH 40/80] HistoryModel: fixed temporary copy of object id --- History/HistoryModel.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/History/HistoryModel.cpp b/History/HistoryModel.cpp index bd364aa..3b43513 100644 --- a/History/HistoryModel.cpp +++ b/History/HistoryModel.cpp @@ -377,7 +377,7 @@ void HistoryModel::scanInlineReferences() continue; } - const Git::ObjectId &oid = refs[ref]; + Git::ObjectId oid = refs[ref]; if ( !refsById.contains( oid ) ) { refsById.insert( oid, HistoryInlineRefs() ); } From ae2c3332f1e6280a4618d055412ffe2e1cba0833 Mon Sep 17 00:00:00 2001 From: Nils Fenner Date: Wed, 4 Feb 2015 02:18:45 +0100 Subject: [PATCH 41/80] HistoryModel: changed back stash status to "isCurrent", as it contains the most recent stash --- History/HistoryModel.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/History/HistoryModel.cpp b/History/HistoryModel.cpp index 3b43513..6a3e71d 100644 --- a/History/HistoryModel.cpp +++ b/History/HistoryModel.cpp @@ -359,7 +359,7 @@ void HistoryModel::scanInlineReferences() else if (ref == QLatin1Literal("refs/stash")) { inlRef.mRefName = tr( "" ); inlRef.mIsBranch = false; - inlRef.mIsCurrent = false; + inlRef.mIsCurrent = true; inlRef.mIsRemote = false; inlRef.mIsTag = false; inlRef.mIsStash = true; From 1e570fde5a950a7a8f25b7df57774f3538a1efec Mon Sep 17 00:00:00 2001 From: Nils Fenner Date: Wed, 4 Feb 2015 16:02:47 +0100 Subject: [PATCH 42/80] HistoryModel: react to refMoved signal Most times this signal is send from RM when the HEAD reference changes. --- History/HistoryModel.cpp | 6 ++++++ History/HistoryModel.h | 1 + 2 files changed, 7 insertions(+) diff --git a/History/HistoryModel.cpp b/History/HistoryModel.cpp index 6a3e71d..b00759c 100644 --- a/History/HistoryModel.cpp +++ b/History/HistoryModel.cpp @@ -43,6 +43,7 @@ HistoryModel::HistoryModel( const Git::Repository& repo, QObject* parent ) RM::RepoMan &rm = MacGitver::repoMan(); connect( &rm, SIGNAL(refCreated(RM::Repo*,RM::Ref*)), this, SLOT(onRefCreated(RM::Repo*,RM::Ref*)) ); connect( &rm, SIGNAL(refLinkChanged(RM::Repo*,RM::Ref*)), this, SLOT(onRefLinkChanged(RM::Repo*,RM::Ref*)) ); + connect( &rm, SIGNAL(refMoved(RM::Repo*,RM::Ref*)), this, SLOT(onRefMoved(RM::Repo*,RM::Ref*)) ); } HistoryModel::~HistoryModel() @@ -238,6 +239,11 @@ void HistoryModel::onRefLinkChanged(RM::Repo* repo, RM::Ref* ref) scanInlineReferences(); } +void HistoryModel::onRefMoved(RM::Repo* repo, RM::Ref* ref) +{ + scanInlineReferences(); +} + void HistoryModel::ensurePopulated( int row ) { HistoryEntry* e = mEntries[ row ]; diff --git a/History/HistoryModel.h b/History/HistoryModel.h index a2bf2d7..cfdee42 100644 --- a/History/HistoryModel.h +++ b/History/HistoryModel.h @@ -121,6 +121,7 @@ private slots: ///@{ void onRefCreated(RM::Repo* repo, RM::Ref* ref); void onRefLinkChanged(RM::Repo* repo, RM::Ref* ref); + void onRefMoved(RM::Repo*repo, RM::Ref*ref); ///@} private: From 258b2229a98ab11b3d950f7b7ee9daa3d888e3db Mon Sep 17 00:00:00 2001 From: Nils Fenner Date: Thu, 5 Feb 2015 01:27:12 +0100 Subject: [PATCH 43/80] HistoryModel: replaced less than comparator with operator <() --- History/HistoryEntry.h | 39 ++++++++++++++++++--------------------- History/HistoryModel.cpp | 4 +--- 2 files changed, 19 insertions(+), 24 deletions(-) diff --git a/History/HistoryEntry.h b/History/HistoryEntry.h index 5d05e10..f19a8e0 100644 --- a/History/HistoryEntry.h +++ b/History/HistoryEntry.h @@ -81,23 +81,18 @@ struct HistoryInlineRef inline bool operator !=(const HistoryInlineRef& other) const { return !( *this == other ); } -}; - -typedef QList< HistoryInlineRef > HistoryInlineRefs; -struct HistoryInlineRef_LessThan -{ - inline bool detachedHEAD(const HistoryInlineRef& ref) const + inline bool detachedHEAD() const { - return ref.mIsDetached && !(ref.mIsTag || ref.mIsBranch || ref.mIsStash); + return mIsDetached && !(mIsTag || mIsBranch || mIsStash); } - inline bool nameLessThan(const HistoryInlineRef& a, const HistoryInlineRef& b) const + inline bool nameLessThan(const HistoryInlineRef& other) const { - return a.mRefName < b.mRefName; + return mRefName < other.mRefName; } - bool operator ()(const HistoryInlineRef& a, const HistoryInlineRef& b) const + bool operator <(const HistoryInlineRef& other) const { // sort order: // - tag @@ -108,38 +103,40 @@ struct HistoryInlineRef_LessThan // - stash // - Everything else is sorted by mRefName - if ( a.mIsTag ) { + if ( mIsTag ) { // tags have highest priority - return b.mIsTag ? nameLessThan(a, b) : true; + return other.mIsTag ? nameLessThan(other) : true; } - if ( detachedHEAD( a ) ) + if ( detachedHEAD() ) { // a detached HEAD comes right after tag ? -> There can only be one! - return !b.mIsTag; + return !other.mIsTag; } - if ( a.mIsBranch ) + if ( mIsBranch ) { - if ( b.mIsTag || b.mIsCurrent || detachedHEAD( b ) ) + if ( other.mIsTag || other.mIsCurrent || other.detachedHEAD() ) return false; - if ( a.mIsCurrent ) { + if ( mIsCurrent ) { // a is the current branch return true; } - return ( a.mIsRemote == b.mIsRemote ) ? nameLessThan( a, b ) : !a.mIsRemote; + return ( mIsRemote == other.mIsRemote ) ? nameLessThan( other ) : !mIsRemote; } - if ( a.mIsStash ) { - return b.mIsStash ? nameLessThan(a, b) : !(b.mIsTag || b.mIsBranch || detachedHEAD( b )); + if ( mIsStash ) { + return other.mIsStash ? nameLessThan( other ) + : !(other.mIsTag || other.mIsBranch || other.detachedHEAD()); } - return !(b.mIsTag || b.mIsBranch || b.mIsStash || detachedHEAD( b )) ? nameLessThan( a, b ) : false; + return !(other.mIsTag || other.mIsBranch || other.mIsStash || other.detachedHEAD()) ? nameLessThan( other ) : false; } }; +typedef QList< HistoryInlineRef > HistoryInlineRefs; class HistoryEntry { diff --git a/History/HistoryModel.cpp b/History/HistoryModel.cpp index b00759c..fe27af8 100644 --- a/History/HistoryModel.cpp +++ b/History/HistoryModel.cpp @@ -406,8 +406,6 @@ void HistoryModel::scanInlineReferences() void HistoryModel::updateInlineRefs(const QHash& refsById) { - HistoryInlineRef_LessThan lt; - for( int i = 0; i < mEntries.count(); i++ ) { HistoryEntry* e = mEntries[i]; @@ -417,7 +415,7 @@ void HistoryModel::updateInlineRefs(const QHashrefs(); // sort newRefs: no need to sort oldRefs as it is already sorted) - std::sort( newRefs.begin(), newRefs.end(), lt ); + std::sort( newRefs.begin(), newRefs.end() ); if( oldRefs.count() != newRefs.count() ) { From e768451c591688e36467b09aa7b7a52c15f14420 Mon Sep 17 00:00:00 2001 From: Nils Fenner Date: Fri, 6 Feb 2015 00:38:51 +0100 Subject: [PATCH 44/80] replaced QLatin1Literal with QStringLiteral --- History/HistoryBuilder.cpp | 4 ++-- History/HistoryModel.cpp | 15 +++++++-------- Repository/ProgressDlg.cpp | 16 ++++++++-------- 3 files changed, 17 insertions(+), 18 deletions(-) diff --git a/History/HistoryBuilder.cpp b/History/HistoryBuilder.cpp index 95d2c54..69dbfa8 100644 --- a/History/HistoryBuilder.cpp +++ b/History/HistoryBuilder.cpp @@ -71,14 +71,14 @@ void HistoryBuilder::addBranches(bool includeRemotes) QStringList sl = mRepo.branchNames(r, true, false); foreach (const QString& s, sl) { - mWalker.pushRef(r, QLatin1Literal("refs/heads/") % s); + mWalker.pushRef(r, QStringLiteral("refs/heads/") % s); } if (includeRemotes) { sl = mRepo.branchNames(r, false, true); foreach (const QString& s, sl) { - mWalker.pushRef(r, QLatin1Literal("refs/remotes/") % s); + mWalker.pushRef(r, QStringLiteral("refs/remotes/") % s); } } } diff --git a/History/HistoryModel.cpp b/History/HistoryModel.cpp index fe27af8..6ed1c52 100644 --- a/History/HistoryModel.cpp +++ b/History/HistoryModel.cpp @@ -319,8 +319,7 @@ void HistoryModel::scanInlineReferences() bool detached = mRepo.isHeadDetached(); if ( detached ) { // append HEAD when detached - refs[QLatin1Literal("< DETACHED >")] = - refHEAD.resolveToObjectId( r ); + refs[ QStringLiteral("< DETACHED >") ] = refHEAD.resolveToObjectId( r ); } QElapsedTimer stopwatch; @@ -333,7 +332,7 @@ void HistoryModel::scanInlineReferences() HistoryInlineRef inlRef; inlRef.mIsDetached = detached; - if ( mDisplays.testFlag(DisplayLocals) && ref.startsWith(QLatin1Literal("refs/heads/")) ) { + if ( mDisplays.testFlag(DisplayLocals) && ref.startsWith(QStringLiteral("refs/heads/")) ) { inlRef.mRefName = ref.mid( strlen( "refs/heads/" ) ); inlRef.mIsBranch = true; inlRef.mIsRemote = false; @@ -341,7 +340,7 @@ void HistoryModel::scanInlineReferences() inlRef.mIsStash = false; inlRef.mIsCurrent = !detached ? (inlRef.mRefName == refHEAD.shorthand()) : false; } - else if (mDisplays.testFlag( DisplayTags ) && ref.startsWith( QLatin1Literal("refs/tags/") ) ) { + else if (mDisplays.testFlag( DisplayTags ) && ref.startsWith( QStringLiteral("refs/tags/") ) ) { inlRef.mRefName = ref.mid( strlen( "refs/tags/" ) ); inlRef.mIsBranch = false; inlRef.mIsRemote = false; @@ -350,9 +349,9 @@ void HistoryModel::scanInlineReferences() inlRef.mIsStash = false; } else if (mDisplays.testFlag(DisplayRemotes) && - ref.startsWith( QLatin1Literal("refs/remotes/")) ) { + ref.startsWith( QStringLiteral("refs/remotes/")) ) { - if (ref.endsWith( QLatin1Literal("HEAD"))) { + if (ref.endsWith( QStringLiteral("HEAD"))) { continue; // Skip "HEAD" } inlRef.mRefName = ref.mid( strlen( "refs/remotes/" ) ); @@ -362,7 +361,7 @@ void HistoryModel::scanInlineReferences() inlRef.mIsCurrent = false; inlRef.mIsStash = false; } - else if (ref == QLatin1Literal("refs/stash")) { + else if (ref == QStringLiteral("refs/stash")) { inlRef.mRefName = tr( "" ); inlRef.mIsBranch = false; inlRef.mIsCurrent = true; @@ -370,7 +369,7 @@ void HistoryModel::scanInlineReferences() inlRef.mIsTag = false; inlRef.mIsStash = true; } - else if ( detached && ref == QLatin1Literal("< DETACHED >") ) { + else if ( detached && ref == QStringLiteral("< DETACHED >") ) { inlRef.mRefName = tr("< DETACHED >"); inlRef.mIsBranch = false; inlRef.mIsCurrent = false; diff --git a/Repository/ProgressDlg.cpp b/Repository/ProgressDlg.cpp index cc98352..832e086 100644 --- a/Repository/ProgressDlg.cpp +++ b/Repository/ProgressDlg.cpp @@ -34,17 +34,17 @@ void ProgressDlg::setAction( const QString& action, foreach( QString s, done ) { - act += QLatin1Literal( " (" ) % s % QLatin1Literal( ")" ); + act += QStringLiteral( " (" ) % s % QStringLiteral( ")" ); } foreach( QString s, current ) { - act += QLatin1Literal( " (" ) % s % QLatin1Literal( ")" ); + act += QStringLiteral( " (" ) % s % QStringLiteral( ")" ); } foreach( QString s, open ) { - act += QLatin1Literal( " (" ) % s % QLatin1Literal( ")" ); + act += QStringLiteral( " (" ) % s % QStringLiteral( ")" ); } lblAction->setText( act ); @@ -79,15 +79,15 @@ void ProgressDlg::transportProgress( quint32 totalObjects, QString recv; if( receivedBytes > 1024 * 1024 * 950 ) /* 950 is so we get 0.9 gb */ { - recv = QString::number( receivedBytes / (1024*1024*1024.0), 'f', 2 ) % QLatin1Literal( " Gb" ); + recv = QString::number( receivedBytes / (1024*1024*1024.0), 'f', 2 ) % QStringLiteral( " Gb" ); } else if( receivedBytes > 1024 * 950 ) { - recv = QString::number( receivedBytes / (1024*1024.0), 'f', 2 ) % QLatin1Literal( " Mb" ); + recv = QString::number( receivedBytes / (1024*1024.0), 'f', 2 ) % QStringLiteral( " Mb" ); } else if( receivedBytes > 950 ) { - recv = QString::number( receivedBytes / 1024.0, 'f', 2 ) % QLatin1Literal( " Kb" ); + recv = QString::number( receivedBytes / 1024.0, 'f', 2 ) % QStringLiteral( " Kb" ); } else { @@ -130,7 +130,7 @@ void ProgressDlg::remoteMessage( const QString& msg ) if( outBufLen ) output += QString( outputBuffer, outBufLen ); - QString log = mBaseLog % QLatin1Literal( "
" ) % + QString log = mBaseLog % QStringLiteral( "
" ) % output.replace( QChar( L'\n' ), QLatin1String("
") ).simplified(); txtLog->setHtml( log ); @@ -144,7 +144,7 @@ void ProgressDlg::beginStep( const QString& step ) void ProgressDlg::finalizeStep() { - mBaseLog = txtLog->toHtml() % QLatin1Literal( "
" ); + mBaseLog = txtLog->toHtml() % QStringLiteral( "
" ); mRawRemoteMessage = QString(); txtLog->setHtml( mBaseLog ); From 746f4f65b7872371617f271461e012761ed2c1b9 Mon Sep 17 00:00:00 2001 From: Nils Fenner Date: Sat, 7 Feb 2015 16:08:55 +0100 Subject: [PATCH 45/80] removed obsolete slot "onRefLinkChanged", which is handled by "onRefMoved" --- History/HistoryModel.cpp | 7 +------ History/HistoryModel.h | 1 - 2 files changed, 1 insertion(+), 7 deletions(-) diff --git a/History/HistoryModel.cpp b/History/HistoryModel.cpp index 6ed1c52..53e7c40 100644 --- a/History/HistoryModel.cpp +++ b/History/HistoryModel.cpp @@ -42,7 +42,6 @@ HistoryModel::HistoryModel( const Git::Repository& repo, QObject* parent ) RM::RepoMan &rm = MacGitver::repoMan(); connect( &rm, SIGNAL(refCreated(RM::Repo*,RM::Ref*)), this, SLOT(onRefCreated(RM::Repo*,RM::Ref*)) ); - connect( &rm, SIGNAL(refLinkChanged(RM::Repo*,RM::Ref*)), this, SLOT(onRefLinkChanged(RM::Repo*,RM::Ref*)) ); connect( &rm, SIGNAL(refMoved(RM::Repo*,RM::Ref*)), this, SLOT(onRefMoved(RM::Repo*,RM::Ref*)) ); } @@ -229,12 +228,8 @@ void HistoryModel::afterAppend() endInsertRows(); } -void HistoryModel::onRefCreated(RM::Repo* repo, RM::Ref* ref) -{ - scanInlineReferences(); -} -void HistoryModel::onRefLinkChanged(RM::Repo* repo, RM::Ref* ref) +void HistoryModel::onRefCreated(RM::Repo* repo, RM::Ref* ref) { scanInlineReferences(); } diff --git a/History/HistoryModel.h b/History/HistoryModel.h index cfdee42..f2a7514 100644 --- a/History/HistoryModel.h +++ b/History/HistoryModel.h @@ -120,7 +120,6 @@ private slots: */ ///@{ void onRefCreated(RM::Repo* repo, RM::Ref* ref); - void onRefLinkChanged(RM::Repo* repo, RM::Ref* ref); void onRefMoved(RM::Repo*repo, RM::Ref*ref); ///@} From 46ca393d48f1f0b1850c1a9e84538daa9d66d275 Mon Sep 17 00:00:00 2001 From: Nils Fenner Date: Sun, 8 Feb 2015 01:12:46 +0100 Subject: [PATCH 46/80] Reference-Model: react to refMoved event Currently forces a refresh of all the model data. --- RefsViews/Branches/BranchesModel.cpp | 13 +++++++++++++ RefsViews/Branches/BranchesModel.hpp | 1 + RefsViews/Branches/BranchesView.cpp | 4 ++-- 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/RefsViews/Branches/BranchesModel.cpp b/RefsViews/Branches/BranchesModel.cpp index 2daff00..a2a80c5 100644 --- a/RefsViews/Branches/BranchesModel.cpp +++ b/RefsViews/Branches/BranchesModel.cpp @@ -37,6 +37,7 @@ BranchesModel::BranchesModel( BranchesViewData* parent ) { RM::RepoMan& rm = MacGitver::repoMan(); connect( &rm, SIGNAL(refCreated(RM::Repo*,RM::Ref*)), this, SLOT(onRefCreated(RM::Repo*,RM::Ref*)) ); + connect( &rm, SIGNAL(refMoved(RM::Repo*,RM::Ref*)), this, SLOT(onRefMoved(RM::Repo*,RM::Ref*)) ); } BranchesModel::~BranchesModel() @@ -295,6 +296,18 @@ void BranchesModel::onRefCreated(RM::Repo* repo, RM::Ref* ref) insertRef( true, gref ); } + +void BranchesModel::onRefMoved(RM::Repo* repo, RM::Ref* ref) +{ + Q_UNUSED( repo ) + Q_UNUSED( ref ) + + // TODO: scan for changes in RefItems instead of performing a full update. + QVector updateRoles; + updateRoles << Qt::DisplayRole << Qt::BackgroundRole + << Qt::FontRole << Qt::DecorationRole; + emit dataChanged( index(0, 0), index( rowCount( QModelIndex() ) - 1, 0 ), updateRoles ); +} ///@} QModelIndex BranchesModel::index(RefItem* item) const diff --git a/RefsViews/Branches/BranchesModel.hpp b/RefsViews/Branches/BranchesModel.hpp index 5aaab61..883e797 100644 --- a/RefsViews/Branches/BranchesModel.hpp +++ b/RefsViews/Branches/BranchesModel.hpp @@ -59,6 +59,7 @@ class BranchesModel : public QAbstractItemModel private slots: void onRefCreated(RM::Repo* repo, RM::Ref* ref); + void onRefMoved(RM::Repo* repo, RM::Ref* ref); private: QModelIndex index(RefItem* item) const; diff --git a/RefsViews/Branches/BranchesView.cpp b/RefsViews/Branches/BranchesView.cpp index db24957..16ea640 100644 --- a/RefsViews/Branches/BranchesView.cpp +++ b/RefsViews/Branches/BranchesView.cpp @@ -261,8 +261,8 @@ void BranchesView::attachedToContext(BlueSky::ViewContext* ctx, BlueSky::ViewCon delete mData; mData = myData; - connect( mData->mModel, SIGNAL(gitError(const Git::Result&)) - , this, SLOT(actionFailed(const Git::Result&)) ); + connect( mData->mModel, SIGNAL(gitError(const Git::Result&)), + this, SLOT(actionFailed(const Git::Result&)) ); mTree->setModel( mData->mSortProxy ); mTree->expandAll(); From 86cf9b6ce69ccef8c86758495df2e68113027474 Mon Sep 17 00:00:00 2001 From: Nils Fenner Date: Sun, 8 Feb 2015 01:59:42 +0100 Subject: [PATCH 47/80] Reference-View: removed workaround to update the view manually --- RefsViews/Branches/BranchesView.cpp | 3 --- 1 file changed, 3 deletions(-) diff --git a/RefsViews/Branches/BranchesView.cpp b/RefsViews/Branches/BranchesView.cpp index 16ea640..ccbb145 100644 --- a/RefsViews/Branches/BranchesView.cpp +++ b/RefsViews/Branches/BranchesView.cpp @@ -115,9 +115,6 @@ void BranchesView::onCheckoutRef() .arg(branch->reference().shorthand()) .arg(r.errorText()) ); } - - // TODO: workaround to update the views - update(); } void BranchesView::onRemoveRef() From 07488e9cc79081b5569e36c0d05ed294df815f34 Mon Sep 17 00:00:00 2001 From: Nils Fenner Date: Sun, 8 Feb 2015 22:36:33 +0100 Subject: [PATCH 48/80] RepoManLogger: removed obsolete event "refLinkChanged" --- RepoManLogger/Listener.cpp | 4 ---- RepoManLogger/Listener.hpp | 1 - 2 files changed, 5 deletions(-) diff --git a/RepoManLogger/Listener.cpp b/RepoManLogger/Listener.cpp index 04546f7..832cda8 100644 --- a/RepoManLogger/Listener.cpp +++ b/RepoManLogger/Listener.cpp @@ -102,10 +102,6 @@ void Listener::refMoved(RM::Repo* repo, RM::Ref* ref) { } -void Listener::refLinkChanged(RM::Repo* repo, RM::Ref* ref) -{ -} - void Listener::refHeadDetached(RM::Repo* repo, RM::Ref* ref) { } diff --git a/RepoManLogger/Listener.hpp b/RepoManLogger/Listener.hpp index 34f9919..10b2a6b 100644 --- a/RepoManLogger/Listener.hpp +++ b/RepoManLogger/Listener.hpp @@ -47,7 +47,6 @@ class Listener : public RM::EventsInterface void refCreated(RM::Repo* repo, RM::Ref* ref); void refAboutToBeDeleted(RM::Repo* repo, RM::Ref* ref); void refMoved(RM::Repo* repo, RM::Ref* ref); - void refLinkChanged(RM::Repo* repo, RM::Ref* ref); void refHeadDetached(RM::Repo* repo, RM::Ref* ref); void tagCreated(RM::Repo* repo, RM::Tag* tag); void tagAboutToBeDeleted(RM::Repo* repo, RM::Tag* tag); From e64afa2edb60996afc023d198400ba38d46197eb Mon Sep 17 00:00:00 2001 From: Nils Fenner Date: Sun, 8 Feb 2015 22:38:10 +0100 Subject: [PATCH 49/80] History-Model: moved docs to source --- History/HistoryModel.cpp | 6 ++++++ History/HistoryModel.h | 6 ------ 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/History/HistoryModel.cpp b/History/HistoryModel.cpp index 53e7c40..a908c5b 100644 --- a/History/HistoryModel.cpp +++ b/History/HistoryModel.cpp @@ -228,6 +228,11 @@ void HistoryModel::afterAppend() endInsertRows(); } +/** + * @internal + * @see RM::EventInterface + */ +///@{ void HistoryModel::onRefCreated(RM::Repo* repo, RM::Ref* ref) { @@ -238,6 +243,7 @@ void HistoryModel::onRefMoved(RM::Repo* repo, RM::Ref* ref) { scanInlineReferences(); } +///@} void HistoryModel::ensurePopulated( int row ) { diff --git a/History/HistoryModel.h b/History/HistoryModel.h index f2a7514..3f8f2fe 100644 --- a/History/HistoryModel.h +++ b/History/HistoryModel.h @@ -114,14 +114,8 @@ private slots: void beforeAppend(); void afterAppend(); - /** - * @internal - * @see RM::EventInterface - */ - ///@{ void onRefCreated(RM::Repo* repo, RM::Ref* ref); void onRefMoved(RM::Repo*repo, RM::Ref*ref); - ///@} private: InlineRefDisplays mDisplays; From 351aac9bc8970fa213d4016ec5d5acb450e340e0 Mon Sep 17 00:00:00 2001 From: Nils Fenner Date: Sun, 8 Feb 2015 22:40:00 +0100 Subject: [PATCH 50/80] History-Model: refresh inline references on a removed reference This also is valid for a renamed reference! --- History/HistoryModel.cpp | 6 ++++++ History/HistoryModel.h | 1 + 2 files changed, 7 insertions(+) diff --git a/History/HistoryModel.cpp b/History/HistoryModel.cpp index a908c5b..e6151ff 100644 --- a/History/HistoryModel.cpp +++ b/History/HistoryModel.cpp @@ -42,6 +42,7 @@ HistoryModel::HistoryModel( const Git::Repository& repo, QObject* parent ) RM::RepoMan &rm = MacGitver::repoMan(); connect( &rm, SIGNAL(refCreated(RM::Repo*,RM::Ref*)), this, SLOT(onRefCreated(RM::Repo*,RM::Ref*)) ); + connect( &rm, SIGNAL(refAboutToBeDeleted(RM::Repo*,RM::Ref*)), this, SLOT(onRefDestroyed(RM::Repo*,RM::Ref*)) ); connect( &rm, SIGNAL(refMoved(RM::Repo*,RM::Ref*)), this, SLOT(onRefMoved(RM::Repo*,RM::Ref*)) ); } @@ -239,6 +240,11 @@ void HistoryModel::onRefCreated(RM::Repo* repo, RM::Ref* ref) scanInlineReferences(); } +void HistoryModel::onRefDestroyed(RM::Repo* repo, RM::Ref* ref) +{ + scanInlineReferences(); +} + void HistoryModel::onRefMoved(RM::Repo* repo, RM::Ref* ref) { scanInlineReferences(); diff --git a/History/HistoryModel.h b/History/HistoryModel.h index 3f8f2fe..39e4875 100644 --- a/History/HistoryModel.h +++ b/History/HistoryModel.h @@ -115,6 +115,7 @@ private slots: void afterAppend(); void onRefCreated(RM::Repo* repo, RM::Ref* ref); + void onRefDestroyed(RM::Repo* repo, RM::Ref* ref); void onRefMoved(RM::Repo*repo, RM::Ref*ref); private: From f3c1cccce43d9225a3b6d24860b0d2357ea78014 Mon Sep 17 00:00:00 2001 From: Nils Fenner Date: Sun, 8 Feb 2015 22:43:04 +0100 Subject: [PATCH 51/80] Refs-Model: removed unused code --- RefsViews/Branches/BranchesModel.cpp | 3 --- RefsViews/RefItem.cpp | 5 ----- RefsViews/RefItem.hpp | 2 -- 3 files changed, 10 deletions(-) diff --git a/RefsViews/Branches/BranchesModel.cpp b/RefsViews/Branches/BranchesModel.cpp index a2a80c5..58de219 100644 --- a/RefsViews/Branches/BranchesModel.cpp +++ b/RefsViews/Branches/BranchesModel.cpp @@ -112,9 +112,6 @@ Qt::ItemFlags BranchesModel::flags( const QModelIndex& index ) const if ( (t == RefItem::Reference) || (t == RefItem::Namespace) ) result |= Qt::ItemIsSelectable; - if ( item->isEditable() ) - result |= Qt::ItemIsEditable; - return result; } diff --git a/RefsViews/RefItem.cpp b/RefsViews/RefItem.cpp index 478e86b..bdbaae2 100644 --- a/RefsViews/RefItem.cpp +++ b/RefsViews/RefItem.cpp @@ -67,11 +67,6 @@ QString RefItem::text() const return QString(); } -bool RefItem::isEditable() const -{ - return false; -} - RefScope::RefScope(RefItem *p, const QString &t) : RefItem( p ) diff --git a/RefsViews/RefItem.hpp b/RefsViews/RefItem.hpp index 0ceb344..0d0d973 100644 --- a/RefsViews/RefItem.hpp +++ b/RefsViews/RefItem.hpp @@ -54,8 +54,6 @@ class RefItem virtual QVariant data( int col, int role ) const; virtual bool setData(Git::Result &result, const QVariant &value, int role, int col ); virtual QString text() const; - - virtual bool isEditable() const; }; From eb29b6d8209f3f2fe27bb950e07ef478e751d993 Mon Sep 17 00:00:00 2001 From: Nils Fenner Date: Mon, 9 Feb 2015 00:01:40 +0100 Subject: [PATCH 52/80] RefItem: added temporary helper methods --- RefsViews/RefItem.cpp | 36 ++++++++++++++++++++++++++++++++++++ RefsViews/RefItem.hpp | 13 +++++++++++++ 2 files changed, 49 insertions(+) diff --git a/RefsViews/RefItem.cpp b/RefsViews/RefItem.cpp index bdbaae2..5348a1e 100644 --- a/RefsViews/RefItem.cpp +++ b/RefsViews/RefItem.cpp @@ -22,6 +22,8 @@ #include "libGitWrap/Repository.hpp" #include "libGitWrap/Result.hpp" +#include "libMacGitverCore/RepoMan/Ref.hpp" + #include #include #include @@ -47,6 +49,16 @@ RefItem::~RefItem() qDeleteAll( children ); } +/** + * @brief Checks the validity of internal data. + * + * @return the default implementation returns always true + */ +bool RefItem::isValid() const +{ + return true; +} + QVariant RefItem::data(int col, int role) const { Q_UNUSED( col ) @@ -126,6 +138,30 @@ RefBranch::RefBranch(RefItem *p, const Git::Reference &ref) { } +/** + * @brief Am I pointing to a valid Git::Reference object? + * + * @return true, if the owned reference is valid; false otherwise + */ +bool RefBranch::isValid() const +{ + return (mRef.isValid() && !mRef.wasDestroyed()); +} + +/** + * @brief Workaround to compare the reference name. + * + * This method will be deleted when migrating to RM::RepoMan. + * + * @param ref the RM::Ref to compare with + * + * @return true when both names match; false otherwise + */ +bool RefBranch::sameReference(const RM::Ref* ref) const +{ + return ref && mRef.name() == ref->fullName(); +} + QVariant RefBranch::data(int col, int role) const { if ( role == Qt::DisplayRole ) diff --git a/RefsViews/RefItem.hpp b/RefsViews/RefItem.hpp index 0d0d973..4346c09 100644 --- a/RefsViews/RefItem.hpp +++ b/RefsViews/RefItem.hpp @@ -24,6 +24,11 @@ #include #include +namespace RM +{ + class Ref; +} + class RefItem { @@ -47,6 +52,10 @@ class RefItem RefItem( RefItem* p ); virtual ~RefItem(); +public: + virtual bool isValid() const; + virtual bool sameReference(const RM::Ref* ref) const { return false; } + public: RefItem* parent; QList< RefItem* > children; @@ -85,6 +94,10 @@ class RefBranch : public RefItem public: explicit RefBranch(RefItem* p, const Git::Reference &ref); +public: + bool isValid() const; + bool sameReference(const RM::Ref* ref) const; + QVariant data( int col, int role ) const; bool setData(Git::Result& result, const QVariant &value, int role, int col); From 9666400522eb2b2e39a26b95988fd73dff5f5758 Mon Sep 17 00:00:00 2001 From: Nils Fenner Date: Mon, 9 Feb 2015 00:05:09 +0100 Subject: [PATCH 53/80] RefItem: removed obsolete method "setData" --- RefsViews/Branches/BranchesModel.cpp | 17 ----------------- RefsViews/Branches/BranchesModel.hpp | 1 - RefsViews/RefItem.cpp | 19 ------------------- RefsViews/RefItem.hpp | 2 -- 4 files changed, 39 deletions(-) diff --git a/RefsViews/Branches/BranchesModel.cpp b/RefsViews/Branches/BranchesModel.cpp index 58de219..ed76cb1 100644 --- a/RefsViews/Branches/BranchesModel.cpp +++ b/RefsViews/Branches/BranchesModel.cpp @@ -77,27 +77,10 @@ QVariant BranchesModel::data( const QModelIndex& index, int role ) const return item->data( index.column(), role ); } -bool BranchesModel::setData( const QModelIndex& index, const QVariant& value, int role ) -{ - if ( !index.isValid() || (role != Qt::EditRole) ) - return false; - RefItem *item = static_cast( index.internalPointer() ); - if ( !item ) - return false; - Git::Result result; - if ( !item->setData( result, value, role, index.column() ) ) - { - if( !result ) - emit gitError( result ); - return false; - } - emit dataChanged(index, index); - return true; -} Qt::ItemFlags BranchesModel::flags( const QModelIndex& index ) const { diff --git a/RefsViews/Branches/BranchesModel.hpp b/RefsViews/Branches/BranchesModel.hpp index 883e797..4782e0e 100644 --- a/RefsViews/Branches/BranchesModel.hpp +++ b/RefsViews/Branches/BranchesModel.hpp @@ -45,7 +45,6 @@ class BranchesModel : public QAbstractItemModel int rowCount( const QModelIndex& parent ) const; int columnCount( const QModelIndex& parent ) const; QVariant data( const QModelIndex& index, int role ) const; - bool setData( const QModelIndex& index, const QVariant& value, int role ); Qt::ItemFlags flags( const QModelIndex& index ) const; QModelIndex index( int row, int column = 0, const QModelIndex& parent = QModelIndex() ) const; QModelIndex parent( const QModelIndex& child ) const; diff --git a/RefsViews/RefItem.cpp b/RefsViews/RefItem.cpp index 5348a1e..d95c8e6 100644 --- a/RefsViews/RefItem.cpp +++ b/RefsViews/RefItem.cpp @@ -66,13 +66,6 @@ QVariant RefItem::data(int col, int role) const return QVariant(); } -bool RefItem::setData(Git::Result& result, const QVariant &value, int role, int col) -{ - Q_UNUSED( value ); - Q_UNUSED( role ); - Q_UNUSED( col ); - return false; -} QString RefItem::text() const { @@ -199,17 +192,5 @@ QVariant RefBranch::data(int col, int role) const return QVariant(); } -bool RefBranch::setData(Git::Result& result, const QVariant &value, int role, int col) -{ - if ( col == 0 ) - { - QString newName = value.toString(); - if ( newName.isEmpty() || (newName == mRef.name()) ) - return false; - mRef.rename( result, newName ); - return result; - } - return false; -} diff --git a/RefsViews/RefItem.hpp b/RefsViews/RefItem.hpp index 4346c09..5e614b1 100644 --- a/RefsViews/RefItem.hpp +++ b/RefsViews/RefItem.hpp @@ -61,7 +61,6 @@ class RefItem QList< RefItem* > children; virtual QVariant data( int col, int role ) const; - virtual bool setData(Git::Result &result, const QVariant &value, int role, int col ); virtual QString text() const; }; @@ -99,7 +98,6 @@ class RefBranch : public RefItem bool sameReference(const RM::Ref* ref) const; QVariant data( int col, int role ) const; - bool setData(Git::Result& result, const QVariant &value, int role, int col); Git::Reference reference() const { From 5b79d6b40489fe199a86effa09c1a8c2d8f5a3f7 Mon Sep 17 00:00:00 2001 From: Nils Fenner Date: Mon, 9 Feb 2015 00:07:05 +0100 Subject: [PATCH 54/80] Refs-Model: added temporary helper method to find invalid references --- RefsViews/Branches/BranchesModel.cpp | 22 ++++++++++++++++++++++ RefsViews/Branches/BranchesModel.hpp | 3 +++ 2 files changed, 25 insertions(+) diff --git a/RefsViews/Branches/BranchesModel.cpp b/RefsViews/Branches/BranchesModel.cpp index ed76cb1..f051791 100644 --- a/RefsViews/Branches/BranchesModel.cpp +++ b/RefsViews/Branches/BranchesModel.cpp @@ -263,6 +263,28 @@ void BranchesModel::rereadBranches() endResetModel(); } +/** + * @internal + * + * @brief Workaround: temporary method to recursively destroy invalid tree items + * + * @param item the current item to check + * + * @param ref when given, the ref name will be compared with the RefItem + */ +void BranchesModel::findInvalidRefItems(QVector& invalidItems, RefItem* item, const RM::Ref* ref ) +{ + if ( !item->isValid() || item->sameReference( ref ) ) + { + invalidItems << item; + return; + } + + for ( int i = item->children.count() - 1; i > -1 ; i-- ) { + findInvalidRefItems( invalidItems, item->children[i], ref ); + } +} + /** * @internal * @see RM::EventInterface diff --git a/RefsViews/Branches/BranchesModel.hpp b/RefsViews/Branches/BranchesModel.hpp index 4782e0e..54255ba 100644 --- a/RefsViews/Branches/BranchesModel.hpp +++ b/RefsViews/Branches/BranchesModel.hpp @@ -71,6 +71,9 @@ private slots: private: BranchesViewData* mData; RefItem* mRoot; + +private: + static void findInvalidRefItems(QVector& invalidItems, RefItem* item, const RM::Ref* ref); }; #endif From 2759c897cc2249ee97624a64fbc099ebfeed5a0d Mon Sep 17 00:00:00 2001 From: Nils Fenner Date: Mon, 9 Feb 2015 00:11:04 +0100 Subject: [PATCH 55/80] Refs-Model: react to deleted references This is also valid for a renamed reference! Minor downside: When a scope/namespace has no more children, it will still stay visible. --- RefsViews/Branches/BranchesModel.cpp | 26 ++++++++++++++++++++++++++ RefsViews/Branches/BranchesModel.hpp | 1 + 2 files changed, 27 insertions(+) diff --git a/RefsViews/Branches/BranchesModel.cpp b/RefsViews/Branches/BranchesModel.cpp index f051791..529e91d 100644 --- a/RefsViews/Branches/BranchesModel.cpp +++ b/RefsViews/Branches/BranchesModel.cpp @@ -37,6 +37,7 @@ BranchesModel::BranchesModel( BranchesViewData* parent ) { RM::RepoMan& rm = MacGitver::repoMan(); connect( &rm, SIGNAL(refCreated(RM::Repo*,RM::Ref*)), this, SLOT(onRefCreated(RM::Repo*,RM::Ref*)) ); + connect( &rm, SIGNAL(refAboutToBeDeleted(RM::Repo*,RM::Ref*)), this, SLOT(onRefDestroyed(RM::Repo*,RM::Ref*)) ); connect( &rm, SIGNAL(refMoved(RM::Repo*,RM::Ref*)), this, SLOT(onRefMoved(RM::Repo*,RM::Ref*)) ); } @@ -299,6 +300,31 @@ void BranchesModel::onRefCreated(RM::Repo* repo, RM::Ref* ref) insertRef( true, gref ); } +void BranchesModel::onRefDestroyed(RM::Repo* repo, RM::Ref* ref) +{ + if ( !ref ) { + return; + } + + qDebug( "Reference will be deleted %s", qUtf8Printable(ref->name()) ); + + // TODO: This is an ugly workaround to find a matching RefItem! + // We simply recursively search for invalid objects and delete them. + QVector invalidItems; + findInvalidRefItems( invalidItems, mRoot, ref ); + + if ( !invalidItems.isEmpty() ) { + while ( !invalidItems.isEmpty() ) { + RefItem* ri = invalidItems.takeFirst(); + QModelIndex idx = index( ri ); + beginRemoveRows( idx.parent(), idx.row(), idx.row() ); + // RefItem unlinks itself from its parent + delete ri; + endRemoveRows(); + } + } +} + void BranchesModel::onRefMoved(RM::Repo* repo, RM::Ref* ref) { Q_UNUSED( repo ) diff --git a/RefsViews/Branches/BranchesModel.hpp b/RefsViews/Branches/BranchesModel.hpp index 54255ba..9e164bf 100644 --- a/RefsViews/Branches/BranchesModel.hpp +++ b/RefsViews/Branches/BranchesModel.hpp @@ -58,6 +58,7 @@ class BranchesModel : public QAbstractItemModel private slots: void onRefCreated(RM::Repo* repo, RM::Ref* ref); + void onRefDestroyed(RM::Repo* repo, RM::Ref* ref); void onRefMoved(RM::Repo* repo, RM::Ref* ref); private: From 51912a0012cb915cd60ddf391d87a24a70c67d93 Mon Sep 17 00:00:00 2001 From: Nils Fenner Date: Mon, 9 Feb 2015 00:11:59 +0100 Subject: [PATCH 56/80] Refs-View: We don't need to manually update the RefsView anymore - finally! --- RefsViews/Branches/BranchesView.cpp | 3 --- 1 file changed, 3 deletions(-) diff --git a/RefsViews/Branches/BranchesView.cpp b/RefsViews/Branches/BranchesView.cpp index ccbb145..4f2ea27 100644 --- a/RefsViews/Branches/BranchesView.cpp +++ b/RefsViews/Branches/BranchesView.cpp @@ -145,9 +145,6 @@ void BranchesView::onRemoveRef() .arg(branch->reference().shorthand()) .arg(r.errorText()) ); } - - // TODO: workaround to update the views - mData->mModel->rereadBranches(); } bool BranchesView::checkRemoveRef( const Git::Reference& ref ) From 6ba4df2e2e4a434d1f7e6bd85d39144d3daee927 Mon Sep 17 00:00:00 2001 From: Nils Fenner Date: Mon, 9 Feb 2015 00:30:03 +0100 Subject: [PATCH 57/80] minor: removed debug output --- RefsViews/Branches/BranchesModel.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/RefsViews/Branches/BranchesModel.cpp b/RefsViews/Branches/BranchesModel.cpp index 529e91d..add0de0 100644 --- a/RefsViews/Branches/BranchesModel.cpp +++ b/RefsViews/Branches/BranchesModel.cpp @@ -306,8 +306,6 @@ void BranchesModel::onRefDestroyed(RM::Repo* repo, RM::Ref* ref) return; } - qDebug( "Reference will be deleted %s", qUtf8Printable(ref->name()) ); - // TODO: This is an ugly workaround to find a matching RefItem! // We simply recursively search for invalid objects and delete them. QVector invalidItems; From 38c29c5e2718f6e0193f7670f0074b997ccdd160 Mon Sep 17 00:00:00 2001 From: Nils Fenner Date: Mon, 9 Feb 2015 00:32:27 +0100 Subject: [PATCH 58/80] Refs-Model: no need to check "ref" and "invalidRefs" --- RefsViews/Branches/BranchesModel.cpp | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/RefsViews/Branches/BranchesModel.cpp b/RefsViews/Branches/BranchesModel.cpp index add0de0..0bee9d2 100644 --- a/RefsViews/Branches/BranchesModel.cpp +++ b/RefsViews/Branches/BranchesModel.cpp @@ -302,24 +302,18 @@ void BranchesModel::onRefCreated(RM::Repo* repo, RM::Ref* ref) void BranchesModel::onRefDestroyed(RM::Repo* repo, RM::Ref* ref) { - if ( !ref ) { - return; - } - // TODO: This is an ugly workaround to find a matching RefItem! // We simply recursively search for invalid objects and delete them. QVector invalidItems; findInvalidRefItems( invalidItems, mRoot, ref ); - if ( !invalidItems.isEmpty() ) { - while ( !invalidItems.isEmpty() ) { - RefItem* ri = invalidItems.takeFirst(); - QModelIndex idx = index( ri ); - beginRemoveRows( idx.parent(), idx.row(), idx.row() ); - // RefItem unlinks itself from its parent - delete ri; - endRemoveRows(); - } + while ( !invalidItems.isEmpty() ) { + RefItem* ri = invalidItems.takeFirst(); + QModelIndex idx = index( ri ); + beginRemoveRows( idx.parent(), idx.row(), idx.row() ); + // RefItem unlinks itself from its parent + delete ri; + endRemoveRows(); } } From 2ba056458a4d8709824b0fc67ebf83e9dcd95f96 Mon Sep 17 00:00:00 2001 From: Nils Fenner Date: Mon, 9 Feb 2015 13:00:36 +0100 Subject: [PATCH 59/80] Refs-Model: inlined inline methods --- History/HistoryModel.cpp | 1 - RefsViews/Branches/BranchesModel.cpp | 51 ++-------------------------- RefsViews/Branches/BranchesModel.hpp | 44 ++++++++++++++++++++++-- 3 files changed, 43 insertions(+), 53 deletions(-) diff --git a/History/HistoryModel.cpp b/History/HistoryModel.cpp index e6151ff..19b2dfc 100644 --- a/History/HistoryModel.cpp +++ b/History/HistoryModel.cpp @@ -234,7 +234,6 @@ void HistoryModel::afterAppend() * @see RM::EventInterface */ ///@{ - void HistoryModel::onRefCreated(RM::Repo* repo, RM::Ref* ref) { scanInlineReferences(); diff --git a/RefsViews/Branches/BranchesModel.cpp b/RefsViews/Branches/BranchesModel.cpp index 0bee9d2..5ef3f7c 100644 --- a/RefsViews/Branches/BranchesModel.cpp +++ b/RefsViews/Branches/BranchesModel.cpp @@ -23,12 +23,9 @@ #include "libMacGitverCore/RepoMan/Ref.hpp" #include "libGitWrap/Result.hpp" -#include "libGitWrap/Reference.hpp" #include "BranchesModel.hpp" -#include "RefItem.hpp" - BranchesModel::BranchesModel( BranchesViewData* parent ) : QAbstractItemModel( parent ) @@ -78,11 +75,6 @@ QVariant BranchesModel::data( const QModelIndex& index, int role ) const return item->data( index.column(), role ); } - - - - - Qt::ItemFlags BranchesModel::flags( const QModelIndex& index ) const { if ( !index.isValid() ) @@ -161,7 +153,7 @@ void BranchesModel::insertRef(bool notify, const Git::Reference &ref) QStringList parts = ref.shorthand().split( QChar( L'/' ) ); if ( parts.count() == 1 ) { - insertBranch( notify, scope, parts.last(), ref ); + insertBranch( notify, scope, ref ); return; } @@ -188,48 +180,9 @@ void BranchesModel::insertRef(bool notify, const Git::Reference &ref) Q_ASSERT( ns ); - insertBranch( notify, ns, parts.last(), ref ); + insertBranch( notify, ns, ref ); } -RefItem* BranchesModel::insertNamespace(const bool notify, RefItem* parent, const QString& name) -{ - RefItem* next = NULL; - if ( notify ) { - int fr = parent->children.count(); - beginInsertRows( index( parent ), fr, fr ); - } - - next = new RefNameSpace( parent, name ); - - if ( notify ) { - endInsertRows(); - } - return next; -} - -void BranchesModel::insertBranch(const bool notify, RefItem* parent, const QString& name, const Git::Reference& ref) -{ - if ( notify ) { - int row = parent->children.count(); - beginInsertRows( index( parent ), row, row ); - } - - new RefBranch( parent, ref ); - - if (notify) { - endInsertRows(); - } -} - -RefScope* BranchesModel::scopeForRef(const Git::Reference& ref) const -{ - RefItem* scope = NULL; - if ( ref.isLocal() ) scope = mRoot->children[0]; - else if ( ref.isRemote() ) scope = mRoot->children[1]; - else scope = mRoot->children[2]; - - return static_cast< RefScope* >( scope ); -} void BranchesModel::rereadBranches() { diff --git a/RefsViews/Branches/BranchesModel.hpp b/RefsViews/Branches/BranchesModel.hpp index 9e164bf..5400c0a 100644 --- a/RefsViews/Branches/BranchesModel.hpp +++ b/RefsViews/Branches/BranchesModel.hpp @@ -21,9 +21,11 @@ #include +#include "libGitWrap/Reference.hpp" #include "libGitWrap/Repository.hpp" #include "Branches/BranchesViewData.hpp" +#include "RefItem.hpp" namespace RM { @@ -65,9 +67,45 @@ private slots: QModelIndex index(RefItem* item) const; void insertRef(bool notify, const Git::Reference& ref); - inline RefItem* insertNamespace(const bool notify, RefItem* parent, const QString& name); - inline void insertBranch(const bool notify, RefItem *ns, const QString &name, const Git::Reference& ref); - inline RefScope* scopeForRef( const Git::Reference& ref ) const; + inline RefItem* insertNamespace(const bool notify, RefItem* parent, const QString& name) + { + RefItem* next = NULL; + if ( notify ) { + int fr = parent->children.count(); + beginInsertRows( index( parent ), fr, fr ); + } + + next = new RefNameSpace( parent, name ); + + if ( notify ) { + endInsertRows(); + } + return next; + } + + inline void insertBranch(const bool notify, RefItem *parent, const Git::Reference& ref) + { + if ( notify ) { + int row = parent->children.count(); + beginInsertRows( index( parent ), row, row ); + } + + new RefBranch( parent, ref ); + + if (notify) { + endInsertRows(); + } + } + + inline RefScope* scopeForRef( const Git::Reference& ref ) const + { + RefItem* scope = NULL; + if ( ref.isLocal() ) scope = mRoot->children[0]; + else if ( ref.isRemote() ) scope = mRoot->children[1]; + else scope = mRoot->children[2]; + + return static_cast< RefScope* >( scope ); + } private: BranchesViewData* mData; From 6fe8c8821d9c8c756ad4412e77e1034ec84d9d64 Mon Sep 17 00:00:00 2001 From: Nils Fenner Date: Mon, 9 Feb 2015 20:37:34 +0100 Subject: [PATCH 60/80] RepoMan-Events: check, if the event-repo equals the model's repo --- History/HistoryModel.cpp | 18 ++++++++++++++++++ RefsViews/Branches/BranchesModel.cpp | 12 +++++++++++- 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/History/HistoryModel.cpp b/History/HistoryModel.cpp index 19b2dfc..2dbb6b9 100644 --- a/History/HistoryModel.cpp +++ b/History/HistoryModel.cpp @@ -236,16 +236,34 @@ void HistoryModel::afterAppend() ///@{ void HistoryModel::onRefCreated(RM::Repo* repo, RM::Ref* ref) { + Q_UNUSED( ref ) + + if ( !repo || (repo->gitLoadedRepo() != mRepo) ) { + return; + } + scanInlineReferences(); } void HistoryModel::onRefDestroyed(RM::Repo* repo, RM::Ref* ref) { + Q_UNUSED( ref ) + + if ( !repo || (repo->gitLoadedRepo() != mRepo) ) { + return; + } + scanInlineReferences(); } void HistoryModel::onRefMoved(RM::Repo* repo, RM::Ref* ref) { + Q_UNUSED( ref ); + + if ( !repo || (repo->gitLoadedRepo() != mRepo) ) { + return; + } + scanInlineReferences(); } ///@} diff --git a/RefsViews/Branches/BranchesModel.cpp b/RefsViews/Branches/BranchesModel.cpp index 5ef3f7c..8228038 100644 --- a/RefsViews/Branches/BranchesModel.cpp +++ b/RefsViews/Branches/BranchesModel.cpp @@ -246,6 +246,9 @@ void BranchesModel::findInvalidRefItems(QVector& invalidItems, RefItem ///@{ void BranchesModel::onRefCreated(RM::Repo* repo, RM::Ref* ref) { + if ( repo != mData->repository() ) { + return; + } Git::Result r; Git::Reference gref = repo->gitRepo().reference( r, ref->fullName() ); Q_ASSERT( r ); @@ -255,6 +258,10 @@ void BranchesModel::onRefCreated(RM::Repo* repo, RM::Ref* ref) void BranchesModel::onRefDestroyed(RM::Repo* repo, RM::Ref* ref) { + if ( repo != mData->repository() ) { + return; + } + // TODO: This is an ugly workaround to find a matching RefItem! // We simply recursively search for invalid objects and delete them. QVector invalidItems; @@ -272,9 +279,12 @@ void BranchesModel::onRefDestroyed(RM::Repo* repo, RM::Ref* ref) void BranchesModel::onRefMoved(RM::Repo* repo, RM::Ref* ref) { - Q_UNUSED( repo ) Q_UNUSED( ref ) + if ( repo != mData->repository() ) { + return; + } + // TODO: scan for changes in RefItems instead of performing a full update. QVector updateRoles; updateRoles << Qt::DisplayRole << Qt::BackgroundRole From ada1c01c42ae8965e7405097bf443252c85132a6 Mon Sep 17 00:00:00 2001 From: Nils Fenner Date: Mon, 9 Feb 2015 20:47:02 +0100 Subject: [PATCH 61/80] Refs-Model: made "scopeForRef" future proof --- RefsViews/Branches/BranchesModel.cpp | 9 ++++++--- RefsViews/Branches/BranchesModel.hpp | 10 +++++++--- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/RefsViews/Branches/BranchesModel.cpp b/RefsViews/Branches/BranchesModel.cpp index 8228038..eba4433 100644 --- a/RefsViews/Branches/BranchesModel.cpp +++ b/RefsViews/Branches/BranchesModel.cpp @@ -31,6 +31,9 @@ BranchesModel::BranchesModel( BranchesViewData* parent ) : QAbstractItemModel( parent ) , mData( parent ) , mRoot( new RefItem ) + , mHeaderLocal( NULL ) + , mHeaderRemote( NULL ) + , mHeaderTags( NULL ) { RM::RepoMan& rm = MacGitver::repoMan(); connect( &rm, SIGNAL(refCreated(RM::Repo*,RM::Ref*)), this, SLOT(onRefCreated(RM::Repo*,RM::Ref*)) ); @@ -191,9 +194,9 @@ void BranchesModel::rereadBranches() qDeleteAll( mRoot->children ); mRoot->children.clear(); - new RefScope( mRoot, tr( "Local" ) ); - new RefScope( mRoot, tr( "Remote" ) ); - new RefScope( mRoot, tr( "Tags" ) ); + mHeaderLocal = new RefScope( mRoot, tr( "Local" ) ); + mHeaderRemote = new RefScope( mRoot, tr( "Remote" ) ); + mHeaderTags = new RefScope( mRoot, tr( "Tags" ) ); RM::Repo* repo = mData->repository(); diff --git a/RefsViews/Branches/BranchesModel.hpp b/RefsViews/Branches/BranchesModel.hpp index 5400c0a..61f64b4 100644 --- a/RefsViews/Branches/BranchesModel.hpp +++ b/RefsViews/Branches/BranchesModel.hpp @@ -100,9 +100,9 @@ private slots: inline RefScope* scopeForRef( const Git::Reference& ref ) const { RefItem* scope = NULL; - if ( ref.isLocal() ) scope = mRoot->children[0]; - else if ( ref.isRemote() ) scope = mRoot->children[1]; - else scope = mRoot->children[2]; + if ( ref.isLocal() ) scope = mHeaderLocal; + else if ( ref.isRemote() ) scope = mHeaderRemote; + else scope = mHeaderTags; return static_cast< RefScope* >( scope ); } @@ -111,6 +111,10 @@ private slots: BranchesViewData* mData; RefItem* mRoot; + RefScope* mHeaderLocal; + RefScope* mHeaderRemote; + RefScope* mHeaderTags; + private: static void findInvalidRefItems(QVector& invalidItems, RefItem* item, const RM::Ref* ref); }; From 34ef4250b20b70b505f386458cff1c26a440c968 Mon Sep 17 00:00:00 2001 From: Nils Fenner Date: Mon, 9 Feb 2015 20:51:57 +0100 Subject: [PATCH 62/80] minor: updated copyright info --- RefsViews/Branches/BranchesModel.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/RefsViews/Branches/BranchesModel.hpp b/RefsViews/Branches/BranchesModel.hpp index 61f64b4..33bbc69 100644 --- a/RefsViews/Branches/BranchesModel.hpp +++ b/RefsViews/Branches/BranchesModel.hpp @@ -1,6 +1,6 @@ /* * MacGitver - * Copyright (C) 2012-2013 The MacGitver-Developers + * Copyright (C) 2015 The MacGitver-Developers * * (C) Sascha Cunz * From 01919c0491699e5097d4f495021e918030b5019b Mon Sep 17 00:00:00 2001 From: Sascha Cunz Date: Tue, 10 Feb 2015 21:10:36 +0000 Subject: [PATCH 63/80] Remove RefsSortProxy --- RefsViews/Branches/BranchesView.cpp | 29 +++++++----- RefsViews/Branches/BranchesViewData.cpp | 13 ----- RefsViews/Branches/BranchesViewData.hpp | 3 -- RefsViews/CMakeLists.txt | 2 - RefsViews/RefsSortProxy.cpp | 63 ------------------------- RefsViews/RefsSortProxy.hpp | 41 ---------------- 6 files changed, 17 insertions(+), 134 deletions(-) delete mode 100644 RefsViews/RefsSortProxy.cpp delete mode 100644 RefsViews/RefsSortProxy.hpp diff --git a/RefsViews/Branches/BranchesView.cpp b/RefsViews/Branches/BranchesView.cpp index 4f2ea27..61c058d 100644 --- a/RefsViews/Branches/BranchesView.cpp +++ b/RefsViews/Branches/BranchesView.cpp @@ -24,7 +24,6 @@ #include "libMacGitverCore/RepoMan/RepoMan.hpp" #include "RefItem.hpp" -#include "RefsSortProxy.hpp" #include "RefRenameDialog.hpp" #include "Branches/BranchesModel.hpp" @@ -69,13 +68,13 @@ QSize BranchesView::sizeHint() const return QSize( 120, 100 ); } -void BranchesView::showContextMenu(const QModelIndex &index, const QPoint &globalPos) +void BranchesView::showContextMenu(const QModelIndex& index, const QPoint& globalPos) { - QModelIndex srcIndex = mData->mSortProxy->deeplyMapToSource( index ); - if ( !srcIndex.isValid() ) + if ( !index.isValid() ) { return; + } - const RefItem *item = static_cast(srcIndex.internalPointer()); + const RefItem *item = static_cast(index.internalPointer()); Heaven::Menu* menu = 0; if ( item && (item->data(0, RefItem::TypeRole) == RefItem::Reference) ) @@ -94,12 +93,14 @@ void BranchesView::onCheckoutRef() if ( !action ) return; - QModelIndex srcIndex = mData->mSortProxy->deeplyMapToSource( mTree->currentIndex() ); + QModelIndex srcIndex = mTree->currentIndex(); if ( !srcIndex.isValid() ) return; const RefBranch *branch = static_cast( srcIndex.internalPointer() ); - if ( !branch ) return; + if ( !branch ) { + return; + } Git::CheckoutReferenceOperation* op = new Git::CheckoutReferenceOperation( branch->reference() ); op->setMode( Git::CheckoutSafe ); @@ -122,11 +123,13 @@ void BranchesView::onRemoveRef() Heaven::Action* action = qobject_cast< Heaven::Action* >( sender() ); if ( !action ) return; - QModelIndex srcIndex = mData->mSortProxy->deeplyMapToSource( mTree->currentIndex() ); + QModelIndex srcIndex = mTree->currentIndex(); if ( !srcIndex.isValid() ) return; const RefBranch *branch = static_cast( srcIndex.internalPointer() ); - if ( !branch ) return; + if ( !branch ) { + return; + } if ( !askToGoOn( trUtf8("Delete reference \'%1\'?").arg(branch->reference().shorthand()) ) ) return; @@ -203,8 +206,10 @@ void BranchesView::onRenameRef() Heaven::Action* action = qobject_cast< Heaven::Action* >( sender() ); if ( !action ) return; - QModelIndex srcIndex = mData->mSortProxy->deeplyMapToSource( mTree->currentIndex() ); - if ( !srcIndex.isValid() ) return; + QModelIndex srcIndex = mTree->currentIndex(); + if ( !srcIndex.isValid() ) { + return; + } RefRenameDialog* dlg = new RefRenameDialog; dlg->init( static_cast(srcIndex.internalPointer()) ); @@ -258,7 +263,7 @@ void BranchesView::attachedToContext(BlueSky::ViewContext* ctx, BlueSky::ViewCon connect( mData->mModel, SIGNAL(gitError(const Git::Result&)), this, SLOT(actionFailed(const Git::Result&)) ); - mTree->setModel( mData->mSortProxy ); + mTree->setModel( mData->mModel ); mTree->expandAll(); } diff --git a/RefsViews/Branches/BranchesViewData.cpp b/RefsViews/Branches/BranchesViewData.cpp index 1182f47..04708ad 100644 --- a/RefsViews/Branches/BranchesViewData.cpp +++ b/RefsViews/Branches/BranchesViewData.cpp @@ -24,12 +24,9 @@ #include "Branches/BranchesViewData.hpp" #include "Branches/BranchesModel.hpp" -#include "RefsSortProxy.hpp" - BranchesViewData::BranchesViewData() : BlueSky::ViewContextData() , mModel( NULL ) - , mSortProxy( NULL ) { } @@ -38,20 +35,10 @@ void BranchesViewData::attachedToContext(BlueSky::ViewContext* context) Q_UNUSED( context ); mModel = new BranchesModel( this ); mModel->rereadBranches(); - - // sort references - mSortProxy = new RefsSortProxy( this ); - mSortProxy->setSourceModel( mModel ); - mSortProxy->setSortCaseSensitivity( Qt::CaseInsensitive ); - - mSortProxy->sort( 0 ); } void BranchesViewData::detachedFromContext() { - delete mSortProxy; - mSortProxy = NULL; - delete mModel; mModel = NULL; } diff --git a/RefsViews/Branches/BranchesViewData.hpp b/RefsViews/Branches/BranchesViewData.hpp index dbc17a4..1b85f53 100644 --- a/RefsViews/Branches/BranchesViewData.hpp +++ b/RefsViews/Branches/BranchesViewData.hpp @@ -24,14 +24,12 @@ #include "libGitWrap/Repository.hpp" class BranchesModel; -class RefsSortProxy; namespace RM { class Repo; } - class BranchesViewData : public BlueSky::ViewContextData { Q_OBJECT @@ -47,7 +45,6 @@ class BranchesViewData : public BlueSky::ViewContextData public: BranchesModel* mModel; - RefsSortProxy* mSortProxy; }; #endif diff --git a/RefsViews/CMakeLists.txt b/RefsViews/CMakeLists.txt index 7a1d629..458785b 100644 --- a/RefsViews/CMakeLists.txt +++ b/RefsViews/CMakeLists.txt @@ -14,7 +14,6 @@ SET( SRC_FILES RefItem.cpp RefRenameDialog.cpp - RefsSortProxy.cpp RefsViewDelegate.cpp Branches/BranchesModel.cpp @@ -28,7 +27,6 @@ SET( HDR_FILES RefItem.hpp RefRenameDialog.hpp - RefsSortProxy.hpp RefsViewDelegate.h Branches/BranchesModel.hpp diff --git a/RefsViews/RefsSortProxy.cpp b/RefsViews/RefsSortProxy.cpp deleted file mode 100644 index 3ac87ae..0000000 --- a/RefsViews/RefsSortProxy.cpp +++ /dev/null @@ -1,63 +0,0 @@ -/* - * MacGitver - * Copyright (C) 2012-2013 The MacGitver-Developers - * - * (C) Nils Fenner - * - * This program is free software; you can redistribute it and/or modify it under the terms of the - * GNU General Public License (Version 2) as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without - * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License along with this program; if - * not, see . - * - */ - -#include "RefsSortProxy.hpp" - - -RefsSortProxy::RefsSortProxy(QObject *parent) - : QSortFilterProxyModel(parent) -{ -} - -RefsSortProxy::~RefsSortProxy() -{ -} - -QModelIndex RefsSortProxy::deeplyMapToSource(QModelIndex current) const -{ - while( current.isValid() ) - { - const QAbstractProxyModel* apm = qobject_cast< const QAbstractProxyModel* >( current.model() ); - if( !apm ) - return current; - - current = apm->mapToSource( current ); - } - - return QModelIndex(); -} - -bool RefsSortProxy::filterAcceptsColumn(int sourceColumn, const QModelIndex &sourceParent) const -{ - Q_UNUSED( sourceColumn ) - Q_UNUSED( sourceParent ) - - return true; -} - -bool RefsSortProxy::filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const -{ - QModelIndex i = sourceModel()->index( sourceRow, 0, sourceParent ); - if ( !i.isValid() ) - return false; - - QString itemName = i.data().toString(); - bool display = itemName.right(4) != QString::fromUtf8( "HEAD" ); - - return display; -} diff --git a/RefsViews/RefsSortProxy.hpp b/RefsViews/RefsSortProxy.hpp deleted file mode 100644 index 58c4ce6..0000000 --- a/RefsViews/RefsSortProxy.hpp +++ /dev/null @@ -1,41 +0,0 @@ -/* - * MacGitver - * Copyright (C) 2012-2013 The MacGitver-Developers - * - * (C) Nils Fenner - * - * This program is free software; you can redistribute it and/or modify it under the terms of the - * GNU General Public License (Version 2) as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without - * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License along with this program; if - * not, see . - * - */ - -#ifndef REFS_SORT_PROXY_HPP -#define REFS_SORT_PROXY_HPP - -#include "libGitWrap/GitWrap.hpp" - -#include - -class RefsSortProxy : public QSortFilterProxyModel -{ -public: - RefsSortProxy(QObject *parent = 0); - ~RefsSortProxy(); - -public: - QModelIndex deeplyMapToSource( QModelIndex current ) const; - -private: - bool filterAcceptsColumn(int sourceColumn, const QModelIndex &sourceParent) const; - bool filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const; - -}; - -#endif // REFS_SORT_PROXY_HPP From 50104421febaf166bfb1b643a6dd30e7043f69de Mon Sep 17 00:00:00 2001 From: Sascha Cunz Date: Tue, 10 Feb 2015 21:32:02 +0000 Subject: [PATCH 64/80] Don't expose Model's internals --- RefsViews/Branches/BranchesModel.cpp | 46 ++++++++----------------- RefsViews/Branches/BranchesModel.hpp | 3 ++ RefsViews/Branches/BranchesView.cpp | 51 ++++++++++++++++------------ RefsViews/Branches/BranchesView.hpp | 4 ++- 4 files changed, 49 insertions(+), 55 deletions(-) diff --git a/RefsViews/Branches/BranchesModel.cpp b/RefsViews/Branches/BranchesModel.cpp index eba4433..465e577 100644 --- a/RefsViews/Branches/BranchesModel.cpp +++ b/RefsViews/Branches/BranchesModel.cpp @@ -46,19 +46,19 @@ BranchesModel::~BranchesModel() delete mRoot; } +RefItem* BranchesModel::indexToItem(const QModelIndex& index, RefItem* defaultItem) const +{ + return index.isValid() ? static_cast< RefItem* >( index.internalPointer() ) : defaultItem; +} + int BranchesModel::rowCount( const QModelIndex& parent ) const { - RefItem* parentItem; if( parent.column() > 0 ) { return 0; } - if( !parent.isValid() ) - parentItem = mRoot; - else - parentItem = static_cast< RefItem* >( parent.internalPointer() ); - + RefItem* parentItem = indexToItem(parent, mRoot); return parentItem->children.count(); } @@ -69,13 +69,8 @@ int BranchesModel::columnCount( const QModelIndex& parent ) const QVariant BranchesModel::data( const QModelIndex& index, int role ) const { - if( !index.isValid() ) - { - return QVariant(); - } - - RefItem* item = static_cast< RefItem* >( index.internalPointer() ); - return item->data( index.column(), role ); + RefItem* item = indexToItem(index); + return item ? item->data( index.column(), role ) : QVariant(); } Qt::ItemFlags BranchesModel::flags( const QModelIndex& index ) const @@ -84,7 +79,7 @@ Qt::ItemFlags BranchesModel::flags( const QModelIndex& index ) const return Qt::NoItemFlags; Qt::ItemFlags result = Qt::ItemIsEnabled; - const RefItem *item = static_cast( index.internalPointer() ); + const RefItem *item = indexToItem(index); RefItem::ItemType t = static_cast( item->data( 0, RefItem::TypeRole ).toInt() ); @@ -101,18 +96,10 @@ QModelIndex BranchesModel::index( int row, int column, const QModelIndex& parent return QModelIndex(); } - RefItem* parentItem; - - if( !parent.isValid() ) - parentItem = mRoot; - else - parentItem = static_cast< RefItem* >( parent.internalPointer() ); - + RefItem* parentItem = indexToItem(parent, mRoot); RefItem* childItem = parentItem->children.at( row ); - if( childItem ) - return createIndex( row, column, childItem ); - else - return QModelIndex(); + + return childItem ? createIndex( row, column, childItem ) : QModelIndex(); } QModelIndex BranchesModel::parent( const QModelIndex& child ) const @@ -122,7 +109,7 @@ QModelIndex BranchesModel::parent( const QModelIndex& child ) const return QModelIndex(); } - RefItem* childItem = static_cast< RefItem* >( child.internalPointer() ); + RefItem* childItem = indexToItem(child); RefItem* parentItem = childItem->parent; if( parentItem == mRoot ) @@ -134,17 +121,12 @@ QModelIndex BranchesModel::parent( const QModelIndex& child ) const bool BranchesModel::hasChildren( const QModelIndex& parent ) const { - RefItem* parentItem; if( parent.column() > 0 ) { return 0; } - if( !parent.isValid() ) - parentItem = mRoot; - else - parentItem = static_cast< RefItem* >( parent.internalPointer() ); - + RefItem* parentItem = indexToItem(parent, mRoot); return parentItem->children.count() > 0; } diff --git a/RefsViews/Branches/BranchesModel.hpp b/RefsViews/Branches/BranchesModel.hpp index 33bbc69..7106eff 100644 --- a/RefsViews/Branches/BranchesModel.hpp +++ b/RefsViews/Branches/BranchesModel.hpp @@ -43,6 +43,9 @@ class BranchesModel : public QAbstractItemModel BranchesModel( BranchesViewData* parent ); ~BranchesModel(); +public: + RefItem* indexToItem(const QModelIndex& index, RefItem* defaultItem = NULL) const; + public: int rowCount( const QModelIndex& parent ) const; int columnCount( const QModelIndex& parent ) const; diff --git a/RefsViews/Branches/BranchesView.cpp b/RefsViews/Branches/BranchesView.cpp index 61c058d..3610776 100644 --- a/RefsViews/Branches/BranchesView.cpp +++ b/RefsViews/Branches/BranchesView.cpp @@ -58,6 +58,17 @@ BranchesView::BranchesView() setContextProvider( "RepoTreeView" ); } +RefItem* BranchesView::indexToItem(const QModelIndex& index) const +{ + if (mData) { + if (mData->mModel) { + return mData->mModel->indexToItem(index); + } + } + + return NULL; +} + BlueSky::ViewContextData* BranchesView::createContextData() const { return new BranchesViewData; @@ -70,15 +81,14 @@ QSize BranchesView::sizeHint() const void BranchesView::showContextMenu(const QModelIndex& index, const QPoint& globalPos) { - if ( !index.isValid() ) { + const RefItem* item = indexToItem(index); + + if (!item) { return; } - const RefItem *item = static_cast(index.internalPointer()); - Heaven::Menu* menu = 0; - if ( item && (item->data(0, RefItem::TypeRole) == RefItem::Reference) ) - { + if (item->data(0, RefItem::TypeRole) == RefItem::Reference) { menu = menuCtxMenuRefsView; //menu->setActivationContext( item ); } @@ -90,17 +100,14 @@ void BranchesView::showContextMenu(const QModelIndex& index, const QPoint& globa void BranchesView::onCheckoutRef() { Heaven::Action* action = qobject_cast< Heaven::Action* >( sender() ); - if ( !action ) + if ( !action ) // FIXME: What is this TEST good for? return; - QModelIndex srcIndex = mTree->currentIndex(); - if ( !srcIndex.isValid() ) - return; - - const RefBranch *branch = static_cast( srcIndex.internalPointer() ); - if ( !branch ) { + const RefItem* item = indexToItem(mTree->currentIndex()); + if (!item || item->data(0, RefItem::TypeRole) != RefItem::Reference ) { return; } + const RefBranch* branch = static_cast(item); Git::CheckoutReferenceOperation* op = new Git::CheckoutReferenceOperation( branch->reference() ); op->setMode( Git::CheckoutSafe ); @@ -121,15 +128,13 @@ void BranchesView::onCheckoutRef() void BranchesView::onRemoveRef() { Heaven::Action* action = qobject_cast< Heaven::Action* >( sender() ); - if ( !action ) return; - - QModelIndex srcIndex = mTree->currentIndex(); - if ( !srcIndex.isValid() ) return; + if ( !action ) return; // FIXME: What is this TEST good for? - const RefBranch *branch = static_cast( srcIndex.internalPointer() ); - if ( !branch ) { + const RefItem* item = indexToItem(mTree->currentIndex()); + if (!item || item->data(0, RefItem::TypeRole) != RefItem::Reference ) { return; } + const RefBranch* branch = static_cast(item); if ( !askToGoOn( trUtf8("Delete reference \'%1\'?").arg(branch->reference().shorthand()) ) ) return; @@ -194,6 +199,7 @@ bool BranchesView::checkRemoveRef( const Git::Reference& ref ) bool goOn = askToGoOn( trUtf8( "You are about to remove the last reference '%1'." "\nThis will move all commits in this branch to the \"lost-found\" area." ) + // What is a LOST-FOUND area??? .arg( ref.shorthand() ) ); if ( !goOn ) return false; } @@ -204,15 +210,16 @@ bool BranchesView::checkRemoveRef( const Git::Reference& ref ) void BranchesView::onRenameRef() { Heaven::Action* action = qobject_cast< Heaven::Action* >( sender() ); - if ( !action ) return; + if ( !action ) return; // FIXME: What is this TEST good for? - QModelIndex srcIndex = mTree->currentIndex(); - if ( !srcIndex.isValid() ) { + RefItem* item = indexToItem(mTree->currentIndex()); + if (!item || item->data(0, RefItem::TypeRole) != RefItem::Reference ) { return; } + RefBranch* branch = static_cast(item); RefRenameDialog* dlg = new RefRenameDialog; - dlg->init( static_cast(srcIndex.internalPointer()) ); + dlg->init(branch); if ( dlg->exec() != QDialog::Accepted ) { diff --git a/RefsViews/Branches/BranchesView.hpp b/RefsViews/Branches/BranchesView.hpp index b7a77f4..d0a2236 100644 --- a/RefsViews/Branches/BranchesView.hpp +++ b/RefsViews/Branches/BranchesView.hpp @@ -34,7 +34,7 @@ namespace Git class Result; } - +class RefItem; class BranchesViewData; class BranchesView : public BlueSky::ContextView, private BranchesViewActions @@ -67,6 +67,8 @@ public slots: bool askToGoOn(const QString& message); inline bool checkRemoveRef(const Git::Reference &ref); + RefItem* indexToItem(const QModelIndex& index) const; + private: RefsViewDelegate mRefDelegate; QTreeView* mTree; From a3ff74c41f4f38e93da31862518a4f54d7c53599 Mon Sep 17 00:00:00 2001 From: Sascha Cunz Date: Tue, 10 Feb 2015 21:36:48 +0000 Subject: [PATCH 65/80] Move RefItem file --- RefsViews/{ => Branches}/RefItem.cpp | 0 RefsViews/{ => Branches}/RefItem.hpp | 0 RefsViews/CMakeLists.txt | 4 ++-- RefsViews/RefRenameDialog.cpp | 2 +- RefsViews/RefsViewDelegate.cpp | 2 +- 5 files changed, 4 insertions(+), 4 deletions(-) rename RefsViews/{ => Branches}/RefItem.cpp (100%) rename RefsViews/{ => Branches}/RefItem.hpp (100%) diff --git a/RefsViews/RefItem.cpp b/RefsViews/Branches/RefItem.cpp similarity index 100% rename from RefsViews/RefItem.cpp rename to RefsViews/Branches/RefItem.cpp diff --git a/RefsViews/RefItem.hpp b/RefsViews/Branches/RefItem.hpp similarity index 100% rename from RefsViews/RefItem.hpp rename to RefsViews/Branches/RefItem.hpp diff --git a/RefsViews/CMakeLists.txt b/RefsViews/CMakeLists.txt index 458785b..4c85331 100644 --- a/RefsViews/CMakeLists.txt +++ b/RefsViews/CMakeLists.txt @@ -12,10 +12,10 @@ SET( SRC_FILES RefsViewsModule.cpp - RefItem.cpp RefRenameDialog.cpp RefsViewDelegate.cpp + Branches/RefItem.cpp Branches/BranchesModel.cpp Branches/BranchesView.cpp Branches/BranchesViewData.cpp @@ -25,10 +25,10 @@ SET( HDR_FILES RefsViewsModule.h - RefItem.hpp RefRenameDialog.hpp RefsViewDelegate.h + Branches/RefItem.hpp Branches/BranchesModel.hpp Branches/BranchesView.hpp Branches/BranchesViewData.hpp diff --git a/RefsViews/RefRenameDialog.cpp b/RefsViews/RefRenameDialog.cpp index 27a65c4..2a4d92f 100644 --- a/RefsViews/RefRenameDialog.cpp +++ b/RefsViews/RefRenameDialog.cpp @@ -18,7 +18,7 @@ #include "RefRenameDialog.hpp" -#include "RefItem.hpp" +#include "Branches/RefItem.hpp" #include "libGitWrap/Reference.hpp" diff --git a/RefsViews/RefsViewDelegate.cpp b/RefsViews/RefsViewDelegate.cpp index d8ef327..8b8c56e 100644 --- a/RefsViews/RefsViewDelegate.cpp +++ b/RefsViews/RefsViewDelegate.cpp @@ -1,6 +1,6 @@ #include "RefsViewDelegate.h" -#include "RefItem.hpp" +#include "Branches/RefItem.hpp" #include From 842e0794eee921f6fc7fd9ece25944cee3603731 Mon Sep 17 00:00:00 2001 From: Sascha Cunz Date: Tue, 10 Feb 2015 21:54:33 +0000 Subject: [PATCH 66/80] Create RefRoot, so we can have pure virtual methods in RefItem. --- RefsViews/Branches/BranchesModel.cpp | 2 +- RefsViews/Branches/RefItem.hpp | 11 ++++++++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/RefsViews/Branches/BranchesModel.cpp b/RefsViews/Branches/BranchesModel.cpp index 465e577..c95050b 100644 --- a/RefsViews/Branches/BranchesModel.cpp +++ b/RefsViews/Branches/BranchesModel.cpp @@ -30,7 +30,7 @@ BranchesModel::BranchesModel( BranchesViewData* parent ) : QAbstractItemModel( parent ) , mData( parent ) - , mRoot( new RefItem ) + , mRoot(new RefRoot) , mHeaderLocal( NULL ) , mHeaderRemote( NULL ) , mHeaderTags( NULL ) diff --git a/RefsViews/Branches/RefItem.hpp b/RefsViews/Branches/RefItem.hpp index 5e614b1..153cc87 100644 --- a/RefsViews/Branches/RefItem.hpp +++ b/RefsViews/Branches/RefItem.hpp @@ -42,7 +42,8 @@ class RefItem enum ItemType { - Scope = 1, + Root = 1, + Scope, Namespace, Reference }; @@ -64,6 +65,14 @@ class RefItem virtual QString text() const; }; +class RefRoot : public RefItem +{ +public: + RefRoot() {} + +public: + ItemType type() const; +}; class RefScope : public RefItem { From 7b9222d9ead45a0f2ba66d80fd890f93f6b223ee Mon Sep 17 00:00:00 2001 From: Sascha Cunz Date: Tue, 10 Feb 2015 21:55:11 +0000 Subject: [PATCH 67/80] Don't use data() to transport the type --- RefsViews/Branches/BranchesModel.cpp | 3 +-- RefsViews/Branches/BranchesView.cpp | 8 +++---- RefsViews/Branches/RefItem.cpp | 31 +++++++++++++++++----------- RefsViews/Branches/RefItem.hpp | 13 ++++++------ 4 files changed, 31 insertions(+), 24 deletions(-) diff --git a/RefsViews/Branches/BranchesModel.cpp b/RefsViews/Branches/BranchesModel.cpp index c95050b..515c54f 100644 --- a/RefsViews/Branches/BranchesModel.cpp +++ b/RefsViews/Branches/BranchesModel.cpp @@ -81,8 +81,7 @@ Qt::ItemFlags BranchesModel::flags( const QModelIndex& index ) const Qt::ItemFlags result = Qt::ItemIsEnabled; const RefItem *item = indexToItem(index); - RefItem::ItemType t = static_cast( - item->data( 0, RefItem::TypeRole ).toInt() ); + RefItem::ItemType t = item->type(); if ( (t == RefItem::Reference) || (t == RefItem::Namespace) ) result |= Qt::ItemIsSelectable; diff --git a/RefsViews/Branches/BranchesView.cpp b/RefsViews/Branches/BranchesView.cpp index 3610776..c18db33 100644 --- a/RefsViews/Branches/BranchesView.cpp +++ b/RefsViews/Branches/BranchesView.cpp @@ -88,7 +88,7 @@ void BranchesView::showContextMenu(const QModelIndex& index, const QPoint& globa } Heaven::Menu* menu = 0; - if (item->data(0, RefItem::TypeRole) == RefItem::Reference) { + if (item->type() == RefItem::Branch) { menu = menuCtxMenuRefsView; //menu->setActivationContext( item ); } @@ -104,7 +104,7 @@ void BranchesView::onCheckoutRef() return; const RefItem* item = indexToItem(mTree->currentIndex()); - if (!item || item->data(0, RefItem::TypeRole) != RefItem::Reference ) { + if (!item || item->type() != RefItem::Branch ) { return; } const RefBranch* branch = static_cast(item); @@ -131,7 +131,7 @@ void BranchesView::onRemoveRef() if ( !action ) return; // FIXME: What is this TEST good for? const RefItem* item = indexToItem(mTree->currentIndex()); - if (!item || item->data(0, RefItem::TypeRole) != RefItem::Reference ) { + if (!item || item->type() != RefItem::Branch ) { return; } const RefBranch* branch = static_cast(item); @@ -213,7 +213,7 @@ void BranchesView::onRenameRef() if ( !action ) return; // FIXME: What is this TEST good for? RefItem* item = indexToItem(mTree->currentIndex()); - if (!item || item->data(0, RefItem::TypeRole) != RefItem::Reference ) { + if (!item || item->type() != RefItem::Branch ) { return; } RefBranch* branch = static_cast(item); diff --git a/RefsViews/Branches/RefItem.cpp b/RefsViews/Branches/RefItem.cpp index d95c8e6..f2e6a74 100644 --- a/RefsViews/Branches/RefItem.cpp +++ b/RefsViews/Branches/RefItem.cpp @@ -66,7 +66,6 @@ QVariant RefItem::data(int col, int role) const return QVariant(); } - QString RefItem::text() const { return QString(); @@ -79,6 +78,11 @@ RefScope::RefScope(RefItem *p, const QString &t) { } +RefItem::ItemType RefScope::type() const +{ + return Scope; +} + QVariant RefScope::data(int col, int role) const { switch( role ) @@ -90,9 +94,6 @@ QVariant RefScope::data(int col, int role) const return QColor(216, 233, 255); } - if ( role == RefItem::TypeRole ) - return RefItem::Scope; - return QVariant(); } @@ -107,6 +108,11 @@ RefNameSpace::RefNameSpace(RefItem *p, const QString &t) { } +RefItem::ItemType RefNameSpace::type() const +{ + return Namespace; +} + QVariant RefNameSpace::data(int col, int role) const { switch( role ) @@ -118,9 +124,6 @@ QVariant RefNameSpace::data(int col, int role) const return QFileIconProvider().icon( QFileIconProvider::Folder ); } - if ( role == RefItem::TypeRole ) - return RefItem::Namespace; - return QVariant(); } @@ -155,6 +158,11 @@ bool RefBranch::sameReference(const RM::Ref* ref) const return ref && mRef.name() == ref->fullName(); } +RefItem::ItemType RefBranch::type() const +{ + return Branch; +} + QVariant RefBranch::data(int col, int role) const { if ( role == Qt::DisplayRole ) @@ -183,14 +191,13 @@ QVariant RefBranch::data(int col, int role) const } } - else if ( role == RefItem::TypeRole ) - return RefItem::Reference; - else if ( role == Qt::EditRole) return mRef.name(); return QVariant(); } - - +RefItem::ItemType RefRoot::type() const +{ + return Root; +} diff --git a/RefsViews/Branches/RefItem.hpp b/RefsViews/Branches/RefItem.hpp index 153cc87..8441b52 100644 --- a/RefsViews/Branches/RefItem.hpp +++ b/RefsViews/Branches/RefItem.hpp @@ -16,8 +16,7 @@ * */ -#ifndef REF_ITEM_HPP -#define REF_ITEM_HPP +#pragma once #include "libGitWrap/Reference.hpp" @@ -35,7 +34,6 @@ class RefItem public: enum Role { - TypeRole = Qt::UserRole, RowBgRole = Qt::UserRole + 1, RowBgGradientRole = Qt::UserRole + 2 }; @@ -45,7 +43,8 @@ class RefItem Root = 1, Scope, Namespace, - Reference + Reference, + Branch = Reference }; public: @@ -55,6 +54,7 @@ class RefItem public: virtual bool isValid() const; + virtual ItemType type() const = 0; virtual bool sameReference(const RM::Ref* ref) const { return false; } public: @@ -82,6 +82,7 @@ class RefScope : public RefItem protected: virtual QVariant data( int col, int role ) const; QString text() const; + ItemType type() const; public: QString mText; @@ -94,6 +95,7 @@ class RefNameSpace : public RefScope RefNameSpace( RefItem* p, const QString& t ); QVariant data( int col, int role ) const; + ItemType type() const; }; @@ -107,6 +109,7 @@ class RefBranch : public RefItem bool sameReference(const RM::Ref* ref) const; QVariant data( int col, int role ) const; + ItemType type() const; Git::Reference reference() const { @@ -116,5 +119,3 @@ class RefBranch : public RefItem private: Git::Reference mRef; }; - -#endif // REF_ITEM_HPP From e8942180351d051367d52e8fae7df7f07228c724 Mon Sep 17 00:00:00 2001 From: Sascha Cunz Date: Tue, 10 Feb 2015 22:02:24 +0000 Subject: [PATCH 68/80] Sort methods more logical --- RefsViews/Branches/BranchesModel.cpp | 131 +++++++++++++++++---------- RefsViews/Branches/BranchesModel.hpp | 43 +-------- 2 files changed, 88 insertions(+), 86 deletions(-) diff --git a/RefsViews/Branches/BranchesModel.cpp b/RefsViews/Branches/BranchesModel.cpp index 515c54f..7d72c0c 100644 --- a/RefsViews/Branches/BranchesModel.cpp +++ b/RefsViews/Branches/BranchesModel.cpp @@ -129,45 +129,18 @@ bool BranchesModel::hasChildren( const QModelIndex& parent ) const return parentItem->children.count() > 0; } -void BranchesModel::insertRef(bool notify, const Git::Reference &ref) +QModelIndex BranchesModel::index(RefItem* item) const { - RefScope* scope = scopeForRef( ref ); - Q_ASSERT( scope ); - - QStringList parts = ref.shorthand().split( QChar( L'/' ) ); - if ( parts.count() == 1 ) - { - insertBranch( notify, scope, ref ); - return; - } - - RefItem* ns = scope; - for( int j = 0; j < parts.count() - 1; j++ ) + if ( !item || (item == mRoot) ) { - RefItem* next = NULL; - QString partName = parts[ j ]; - foreach( RefItem* nsChild, ns->children ) - { - if( nsChild->text() == partName ) - { - next = nsChild; - break; - } - } - - if( !next ) - { - next = insertNamespace( notify, ns, partName ); - } - ns = next; + return QModelIndex(); } - Q_ASSERT( ns ); - - insertBranch( notify, ns, ref ); + RefItem* parent = item->parent ? item->parent : mRoot; + int row = parent->children.indexOf( item ); + return createIndex( row, 0, item ); } - void BranchesModel::rereadBranches() { beginResetModel(); @@ -223,11 +196,88 @@ void BranchesModel::findInvalidRefItems(QVector& invalidItems, RefItem } } +void BranchesModel::insertRef(bool notify, const Git::Reference &ref) +{ + RefScope* scope = scopeForRef( ref ); + Q_ASSERT( scope ); + + QStringList parts = ref.shorthand().split( QChar( L'/' ) ); + if ( parts.count() == 1 ) + { + insertBranch( notify, scope, ref ); + return; + } + + RefItem* ns = scope; + for( int j = 0; j < parts.count() - 1; j++ ) + { + RefItem* next = NULL; + QString partName = parts[ j ]; + foreach( RefItem* nsChild, ns->children ) + { + if( nsChild->text() == partName ) + { + next = nsChild; + break; + } + } + + if( !next ) + { + next = insertNamespace( notify, ns, partName ); + } + ns = next; + } + + Q_ASSERT( ns ); + + insertBranch( notify, ns, ref ); +} + +RefItem* BranchesModel::insertNamespace(const bool notify, RefItem* parent, const QString& name) +{ + RefItem* next = NULL; + if ( notify ) { + int fr = parent->children.count(); + beginInsertRows( index( parent ), fr, fr ); + } + + next = new RefNameSpace( parent, name ); + + if ( notify ) { + endInsertRows(); + } + return next; +} + +void BranchesModel::insertBranch(const bool notify, RefItem *parent, const Git::Reference& ref) +{ + if ( notify ) { + int row = parent->children.count(); + beginInsertRows( index( parent ), row, row ); + } + + new RefBranch( parent, ref ); + + if (notify) { + endInsertRows(); + } +} + +RefScope* BranchesModel::scopeForRef( const Git::Reference& ref ) const +{ + RefItem* scope = NULL; + if ( ref.isLocal() ) scope = mHeaderLocal; + else if ( ref.isRemote() ) scope = mHeaderRemote; + else scope = mHeaderTags; + + return static_cast< RefScope* >( scope ); +} + /** * @internal * @see RM::EventInterface */ -///@{ void BranchesModel::onRefCreated(RM::Repo* repo, RM::Ref* ref) { if ( repo != mData->repository() ) { @@ -275,16 +325,3 @@ void BranchesModel::onRefMoved(RM::Repo* repo, RM::Ref* ref) << Qt::FontRole << Qt::DecorationRole; emit dataChanged( index(0, 0), index( rowCount( QModelIndex() ) - 1, 0 ), updateRoles ); } -///@} - -QModelIndex BranchesModel::index(RefItem* item) const -{ - if ( !item || (item == mRoot) ) - { - return QModelIndex(); - } - - RefItem* parent = item->parent ? item->parent : mRoot; - int row = parent->children.indexOf( item ); - return createIndex( row, 0, item ); -} diff --git a/RefsViews/Branches/BranchesModel.hpp b/RefsViews/Branches/BranchesModel.hpp index 7106eff..86a7532 100644 --- a/RefsViews/Branches/BranchesModel.hpp +++ b/RefsViews/Branches/BranchesModel.hpp @@ -70,45 +70,10 @@ private slots: QModelIndex index(RefItem* item) const; void insertRef(bool notify, const Git::Reference& ref); - inline RefItem* insertNamespace(const bool notify, RefItem* parent, const QString& name) - { - RefItem* next = NULL; - if ( notify ) { - int fr = parent->children.count(); - beginInsertRows( index( parent ), fr, fr ); - } - - next = new RefNameSpace( parent, name ); - - if ( notify ) { - endInsertRows(); - } - return next; - } - - inline void insertBranch(const bool notify, RefItem *parent, const Git::Reference& ref) - { - if ( notify ) { - int row = parent->children.count(); - beginInsertRows( index( parent ), row, row ); - } - - new RefBranch( parent, ref ); - - if (notify) { - endInsertRows(); - } - } - - inline RefScope* scopeForRef( const Git::Reference& ref ) const - { - RefItem* scope = NULL; - if ( ref.isLocal() ) scope = mHeaderLocal; - else if ( ref.isRemote() ) scope = mHeaderRemote; - else scope = mHeaderTags; - - return static_cast< RefScope* >( scope ); - } + RefItem* insertNamespace(const bool notify, RefItem* parent, const QString& name); + void insertBranch(const bool notify, RefItem *parent, const Git::Reference& ref); + + RefScope* scopeForRef( const Git::Reference& ref ) const; private: BranchesViewData* mData; From cce685b6e80b5b3e08489b9b4d7feb7979482cc1 Mon Sep 17 00:00:00 2001 From: Sascha Cunz Date: Tue, 10 Feb 2015 22:59:10 +0000 Subject: [PATCH 69/80] Remove totally unused "column" from RefItem::data() --- RefsViews/Branches/BranchesModel.cpp | 5 ++++- RefsViews/Branches/RefItem.cpp | 9 ++++----- RefsViews/Branches/RefItem.hpp | 8 ++++---- 3 files changed, 12 insertions(+), 10 deletions(-) diff --git a/RefsViews/Branches/BranchesModel.cpp b/RefsViews/Branches/BranchesModel.cpp index 7d72c0c..0b403d8 100644 --- a/RefsViews/Branches/BranchesModel.cpp +++ b/RefsViews/Branches/BranchesModel.cpp @@ -70,7 +70,10 @@ int BranchesModel::columnCount( const QModelIndex& parent ) const QVariant BranchesModel::data( const QModelIndex& index, int role ) const { RefItem* item = indexToItem(index); - return item ? item->data( index.column(), role ) : QVariant(); + if (index.column() != 0) { + return QVariant(); + } + return item ? item->data(role) : QVariant(); } Qt::ItemFlags BranchesModel::flags( const QModelIndex& index ) const diff --git a/RefsViews/Branches/RefItem.cpp b/RefsViews/Branches/RefItem.cpp index f2e6a74..27c552c 100644 --- a/RefsViews/Branches/RefItem.cpp +++ b/RefsViews/Branches/RefItem.cpp @@ -59,9 +59,8 @@ bool RefItem::isValid() const return true; } -QVariant RefItem::data(int col, int role) const +QVariant RefItem::data(int role) const { - Q_UNUSED( col ) Q_UNUSED( role ) return QVariant(); } @@ -83,7 +82,7 @@ RefItem::ItemType RefScope::type() const return Scope; } -QVariant RefScope::data(int col, int role) const +QVariant RefScope::data(int role) const { switch( role ) { @@ -113,7 +112,7 @@ RefItem::ItemType RefNameSpace::type() const return Namespace; } -QVariant RefNameSpace::data(int col, int role) const +QVariant RefNameSpace::data(int role) const { switch( role ) { @@ -163,7 +162,7 @@ RefItem::ItemType RefBranch::type() const return Branch; } -QVariant RefBranch::data(int col, int role) const +QVariant RefBranch::data(int role) const { if ( role == Qt::DisplayRole ) return mRef.shorthand().section( QChar(L'/'), -1 ); diff --git a/RefsViews/Branches/RefItem.hpp b/RefsViews/Branches/RefItem.hpp index 8441b52..4ec404b 100644 --- a/RefsViews/Branches/RefItem.hpp +++ b/RefsViews/Branches/RefItem.hpp @@ -61,7 +61,7 @@ class RefItem RefItem* parent; QList< RefItem* > children; - virtual QVariant data( int col, int role ) const; + virtual QVariant data(int role) const; virtual QString text() const; }; @@ -80,7 +80,7 @@ class RefScope : public RefItem RefScope( RefItem* p, const QString& t ); protected: - virtual QVariant data( int col, int role ) const; + virtual QVariant data(int role) const; QString text() const; ItemType type() const; @@ -94,7 +94,7 @@ class RefNameSpace : public RefScope public: RefNameSpace( RefItem* p, const QString& t ); - QVariant data( int col, int role ) const; + QVariant data(int role) const; ItemType type() const; }; @@ -108,7 +108,7 @@ class RefBranch : public RefItem bool isValid() const; bool sameReference(const RM::Ref* ref) const; - QVariant data( int col, int role ) const; + QVariant data(int role) const; ItemType type() const; Git::Reference reference() const From 4e6ddc082d28ee764b2995dc3fde8facd588fa4f Mon Sep 17 00:00:00 2001 From: Sascha Cunz Date: Wed, 11 Feb 2015 21:03:08 +0000 Subject: [PATCH 70/80] Make Headlines a bit taller --- RefsViews/RefsViewDelegate.cpp | 11 +++++++++++ RefsViews/RefsViewDelegate.h | 1 + 2 files changed, 12 insertions(+) diff --git a/RefsViews/RefsViewDelegate.cpp b/RefsViews/RefsViewDelegate.cpp index 8b8c56e..8da53c5 100644 --- a/RefsViews/RefsViewDelegate.cpp +++ b/RefsViews/RefsViewDelegate.cpp @@ -45,3 +45,14 @@ void RefsViewDelegate::paint(QPainter* painter, const QStyleOptionViewItem& opti QStyledItemDelegate::paint( painter, option, index ); } + +QSize RefsViewDelegate::sizeHint(const QStyleOptionViewItem &option, const QModelIndex& index) const +{ + QSize s = QStyledItemDelegate::sizeHint(option, index); + + if (!index.parent().isValid()) { + s.setHeight(25); + } + + return s; +} diff --git a/RefsViews/RefsViewDelegate.h b/RefsViews/RefsViewDelegate.h index 617b4f1..1fee436 100644 --- a/RefsViews/RefsViewDelegate.h +++ b/RefsViews/RefsViewDelegate.h @@ -12,6 +12,7 @@ class RefsViewDelegate : public QStyledItemDelegate public: void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const; + QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex& index) const; }; #endif From b4e6146a2596341856027a9e0d379deafedca9af Mon Sep 17 00:00:00 2001 From: Sascha Cunz Date: Wed, 11 Feb 2015 21:07:10 +0000 Subject: [PATCH 71/80] Rewrite BranchesModel to make use of RepoMan --- RefsViews/Branches/BranchesModel.cpp | 356 +++++++++++++++--------- RefsViews/Branches/BranchesModel.hpp | 39 +-- RefsViews/Branches/BranchesView.cpp | 53 ++-- RefsViews/Branches/BranchesView.hpp | 12 +- RefsViews/Branches/BranchesViewData.cpp | 6 +- RefsViews/Branches/RefItem.cpp | 149 +++++----- RefsViews/Branches/RefItem.hpp | 142 ++++++++-- RefsViews/RefRenameDialog.cpp | 38 +-- RefsViews/RefRenameDialog.hpp | 7 +- 9 files changed, 500 insertions(+), 302 deletions(-) diff --git a/RefsViews/Branches/BranchesModel.cpp b/RefsViews/Branches/BranchesModel.cpp index 0b403d8..df3e7be 100644 --- a/RefsViews/Branches/BranchesModel.cpp +++ b/RefsViews/Branches/BranchesModel.cpp @@ -17,10 +17,15 @@ */ #include +#include #include "libMacGitverCore/App/MacGitver.hpp" #include "libMacGitverCore/RepoMan/RepoMan.hpp" #include "libMacGitverCore/RepoMan/Ref.hpp" +#include "libMacGitverCore/RepoMan/RefTreeNode.hpp" +#include "libMacGitverCore/RepoMan/Branch.hpp" +#include "libMacGitverCore/RepoMan/Remote.hpp" +#include "libMacGitverCore/RepoMan/CollectionNode.hpp" #include "libGitWrap/Result.hpp" @@ -29,16 +34,25 @@ BranchesModel::BranchesModel( BranchesViewData* parent ) : QAbstractItemModel( parent ) - , mData( parent ) + , mRepo(NULL) , mRoot(new RefRoot) , mHeaderLocal( NULL ) , mHeaderRemote( NULL ) , mHeaderTags( NULL ) { RM::RepoMan& rm = MacGitver::repoMan(); - connect( &rm, SIGNAL(refCreated(RM::Repo*,RM::Ref*)), this, SLOT(onRefCreated(RM::Repo*,RM::Ref*)) ); - connect( &rm, SIGNAL(refAboutToBeDeleted(RM::Repo*,RM::Ref*)), this, SLOT(onRefDestroyed(RM::Repo*,RM::Ref*)) ); - connect( &rm, SIGNAL(refMoved(RM::Repo*,RM::Ref*)), this, SLOT(onRefMoved(RM::Repo*,RM::Ref*)) ); + + connect(&rm, SIGNAL(refCreated(RM::Repo*,RM::Ref*)), + this, SLOT(onRefCreated(RM::Repo*,RM::Ref*))); + + connect(&rm, SIGNAL(refAboutToBeDeleted(RM::Repo*,RM::Ref*)), + this, SLOT(onRefDestroyed(RM::Repo*,RM::Ref*))); + + connect(&rm, SIGNAL(refMoved(RM::Repo*,RM::Ref*)), + this, SLOT(onRefMoved(RM::Repo*,RM::Ref*))); + + connect(&rm, SIGNAL(refTreeNodeAboutToBeDeleted(RM::Repo*,RM::RefTreeNode*)), + this, SLOT(onRefTreeNodeAboutToBeDeleted(RM::Repo*,RM::RefTreeNode*))); } BranchesModel::~BranchesModel() @@ -51,6 +65,23 @@ RefItem* BranchesModel::indexToItem(const QModelIndex& index, RefItem* defaultIt return index.isValid() ? static_cast< RefItem* >( index.internalPointer() ) : defaultItem; } +QModelIndex BranchesModel::itemToIndex(RefItem* item) const +{ + if ( !item || (item == mRoot) ) + { + return QModelIndex(); + } + + RefItem* parent = item->parent ? item->parent : mRoot; + int row = parent->children.indexOf( item ); + return createIndex( row, 0, item ); +} + +QModelIndex BranchesModel::objectToIndex(RM::Base* obj) const +{ + return itemToIndex(mObjToItems.value(obj, NULL)); +} + int BranchesModel::rowCount( const QModelIndex& parent ) const { if( parent.column() > 0 ) @@ -78,15 +109,17 @@ QVariant BranchesModel::data( const QModelIndex& index, int role ) const Qt::ItemFlags BranchesModel::flags( const QModelIndex& index ) const { - if ( !index.isValid() ) + if (!index.isValid()) { return Qt::NoItemFlags; + } Qt::ItemFlags result = Qt::ItemIsEnabled; - const RefItem *item = indexToItem(index); + const RefItem* item = indexToItem(index); RefItem::ItemType t = item->type(); - if ( (t == RefItem::Reference) || (t == RefItem::Namespace) ) + if (t != RefItem::Scope) { result |= Qt::ItemIsSelectable; + } return result; } @@ -132,199 +165,258 @@ bool BranchesModel::hasChildren( const QModelIndex& parent ) const return parentItem->children.count() > 0; } -QModelIndex BranchesModel::index(RefItem* item) const +RefItem* BranchesModel::link(bool notify, RefItem* it) { - if ( !item || (item == mRoot) ) - { - return QModelIndex(); + int pos = it->itemPosition(); + + if (notify) { + beginInsertRows(itemToIndex(it->parent), pos, pos); } - RefItem* parent = item->parent ? item->parent : mRoot; - int row = parent->children.indexOf( item ); - return createIndex( row, 0, item ); + it->parent->children.insert(pos, it); + + if (notify) { + endInsertRows(); + } + + return it; } -void BranchesModel::rereadBranches() +RefItem* BranchesModel::createBranchItem(bool notify, RefItem* parent, RM::Branch* obj) { - beginResetModel(); + if (obj->name() == QStringLiteral("HEAD")) { + return NULL; + } - qDeleteAll( mRoot->children ); - mRoot->children.clear(); + if (!parent && obj->parentObject()->objType() != RM::CollectionNodeObject) { + parent = insertObject(notify, obj->parentObject()); + return NULL; + } - mHeaderLocal = new RefScope( mRoot, tr( "Local" ) ); - mHeaderRemote = new RefScope( mRoot, tr( "Remote" ) ); - mHeaderTags = new RefScope( mRoot, tr( "Tags" ) ); + if (!parent) { + parent = mHeaderLocal; + } - RM::Repo* repo = mData->repository(); + return link(notify, new RefBranch(parent, obj)); +} - // TODO: migrate to RM::Repo - Git::Repository gitRepo = repo ? repo->gitRepo() : Git::Repository(); +RefItem* BranchesModel::createTagItem(bool notify, RefItem* parent, RM::Tag* obj) +{ + if (!parent && obj->parentObject()->objType() != RM::CollectionNodeObject) { + parent = insertObject(notify, obj->parentObject()); + return NULL; + } - if( gitRepo.isValid() ) - { - Git::Result r; - Git::ReferenceList sl = gitRepo.allReferences( r ); - if( !sl.isEmpty() ) - { - for( int i = 0; i < sl.count(); ++i ) - { - const Git::Reference ¤tRef = sl[ i ]; - insertRef( false, currentRef ); - } - } + if (!parent) { + parent = mHeaderTags; } - endResetModel(); + return link(notify, new RefTag(parent, obj)); } -/** - * @internal - * - * @brief Workaround: temporary method to recursively destroy invalid tree items - * - * @param item the current item to check - * - * @param ref when given, the ref name will be compared with the RefItem - */ -void BranchesModel::findInvalidRefItems(QVector& invalidItems, RefItem* item, const RM::Ref* ref ) +RefItem* BranchesModel::createScopeItem(bool notify, RefItem* parent, RM::RefTreeNode* obj) { - if ( !item->isValid() || item->sameReference( ref ) ) - { - invalidItems << item; - return; + if (!parent) { + RM::Base* parObj = obj->parentObject(); + + if (parObj->objType() != RM::CollectionNodeObject) { + parent = insertObject(notify, parObj); + return NULL; + } + + RM::CollectionNode* cn = static_cast(parObj); + switch (cn->collectionType()) { + case RM::ctTags: + parent = mHeaderTags; + break; + + case RM::ctBranches: + parent = mHeaderLocal; + break; + + default: + // Should we assert here? + return NULL; + } } - for ( int i = item->children.count() - 1; i > -1 ; i-- ) { - findInvalidRefItems( invalidItems, item->children[i], ref ); + return link(notify, new RefScope(parent, obj)); +} + +RefItem* BranchesModel::createRemoteItem(bool notify, RefItem* parent, RM::Remote* obj) +{ + if (!parent) { + parent = mHeaderRemote; } + + return link(notify, new RefRemote(parent, obj)); } -void BranchesModel::insertRef(bool notify, const Git::Reference &ref) +RefItem* BranchesModel::insertObject(bool notify, RM::Base* obj) { - RefScope* scope = scopeForRef( ref ); - Q_ASSERT( scope ); + if (!obj) { + return NULL; + } - QStringList parts = ref.shorthand().split( QChar( L'/' ) ); - if ( parts.count() == 1 ) - { - insertBranch( notify, scope, ref ); - return; + qDebug() << obj->displayName(); + + bool doChildren = false; + RefItem* parent = mObjToItems.value(obj->parentObject(), NULL); + RefItem* it = mObjToItems.value(obj, NULL); + + if (!it) { + switch (obj->objType()) { + case RM::BranchObject: + it = createBranchItem(notify, parent, static_cast(obj)); + break; + + case RM::TagObject: + it = createTagItem(notify, parent, static_cast(obj)); + break; + + case RM::RefTreeNodeObject: + it = createScopeItem(notify, parent, static_cast(obj)); + doChildren = true; + break; + + case RM::RemoteObject: + it = createRemoteItem(notify, parent, static_cast(obj)); + doChildren = true; + break; + + default: + break; + } } - RefItem* ns = scope; - for( int j = 0; j < parts.count() - 1; j++ ) - { - RefItem* next = NULL; - QString partName = parts[ j ]; - foreach( RefItem* nsChild, ns->children ) - { - if( nsChild->text() == partName ) - { - next = nsChild; - break; + if (it) { + mObjToItems.insert(obj, it); + mItemToObjs.insert(it, obj); + + if (doChildren) { + foreach(RM::Base* child, obj->childObjects()) { + insertObject(notify, child); } } + } - if( !next ) - { - next = insertNamespace( notify, ns, partName ); - } - ns = next; + return it; +} + +void BranchesModel::insertCollection(RM::CollectionNode* coll) +{ + foreach(RM::Base* obj, coll->childObjects()) { + insertObject(false, obj); } +} - Q_ASSERT( ns ); +void BranchesModel::updatedObject(RM::Base* obj) +{ + RefItem* it = mObjToItems.value(obj, NULL); + if (!it) { + return; + } - insertBranch( notify, ns, ref ); + QModelIndex i = itemToIndex(it); + dataChanged(i, i); } -RefItem* BranchesModel::insertNamespace(const bool notify, RefItem* parent, const QString& name) +void BranchesModel::deleteItem(RefItem* it) { - RefItem* next = NULL; - if ( notify ) { - int fr = parent->children.count(); - beginInsertRows( index( parent ), fr, fr ); + if (!it) { + return; } - next = new RefNameSpace( parent, name ); + // Do a depth-first traversal, so we're sure everything's removed correctly - if ( notify ) { - endInsertRows(); + foreach (RefItem* sub, it->children) { + deleteItem(sub); } - return next; + + RefItem* parent = it->parent; + int pos = parent->children.indexOf(it); + + beginRemoveRows(itemToIndex(parent), pos, pos); + + RM::Base* obj = it->object(); + if (obj) { + mObjToItems.remove(obj); + mItemToObjs.remove(it); + } + + delete it; + + endRemoveRows(); } -void BranchesModel::insertBranch(const bool notify, RefItem *parent, const Git::Reference& ref) +void BranchesModel::deletedObject(RM::Base* obj) { - if ( notify ) { - int row = parent->children.count(); - beginInsertRows( index( parent ), row, row ); + deleteItem(mObjToItems.value(obj, NULL)); +} + +void BranchesModel::setRepository(RM::Repo* repo) +{ + if (mRepo == repo) { + return; } - new RefBranch( parent, ref ); + beginResetModel(); - if (notify) { - endInsertRows(); + if (mRepo) { + qDeleteAll(mRoot->children); + mObjToItems.clear(); + mItemToObjs.clear(); + mHeaderLocal = mHeaderRemote = mHeaderTags = NULL; } -} -RefScope* BranchesModel::scopeForRef( const Git::Reference& ref ) const -{ - RefItem* scope = NULL; - if ( ref.isLocal() ) scope = mHeaderLocal; - else if ( ref.isRemote() ) scope = mHeaderRemote; - else scope = mHeaderTags; + mRepo = repo; + + mHeaderLocal = new RefHeadline(mRoot, tr("Local branches")); link(false, mHeaderLocal); + mHeaderRemote = new RefHeadline(mRoot, tr("Remotes")); link(false, mHeaderRemote); + mHeaderTags = new RefHeadline(mRoot, tr("Tags")); link(false, mHeaderTags); + + insertCollection(mRepo->branches()); + insertCollection(mRepo->tags()); - return static_cast< RefScope* >( scope ); + foreach (RM::Remote* rmRemote, repo->childObjects()) { + insertObject(false, rmRemote); + } + + endResetModel(); } -/** - * @internal - * @see RM::EventInterface - */ void BranchesModel::onRefCreated(RM::Repo* repo, RM::Ref* ref) { - if ( repo != mData->repository() ) { + if (repo != mRepo) { return; } - Git::Result r; - Git::Reference gref = repo->gitRepo().reference( r, ref->fullName() ); - Q_ASSERT( r ); - insertRef( true, gref ); + insertObject(true, ref); } void BranchesModel::onRefDestroyed(RM::Repo* repo, RM::Ref* ref) { - if ( repo != mData->repository() ) { + if (repo != mRepo) { return; } - // TODO: This is an ugly workaround to find a matching RefItem! - // We simply recursively search for invalid objects and delete them. - QVector invalidItems; - findInvalidRefItems( invalidItems, mRoot, ref ); + deletedObject(ref); +} - while ( !invalidItems.isEmpty() ) { - RefItem* ri = invalidItems.takeFirst(); - QModelIndex idx = index( ri ); - beginRemoveRows( idx.parent(), idx.row(), idx.row() ); - // RefItem unlinks itself from its parent - delete ri; - endRemoveRows(); +void BranchesModel::onRefTreeNodeAboutToBeDeleted(RM::Repo* repo, RM::RefTreeNode* obj) +{ + if (repo != mRepo) { + return; } + + deletedObject(obj); } void BranchesModel::onRefMoved(RM::Repo* repo, RM::Ref* ref) { - Q_UNUSED( ref ) - - if ( repo != mData->repository() ) { + if (repo != mRepo) { return; } - // TODO: scan for changes in RefItems instead of performing a full update. - QVector updateRoles; - updateRoles << Qt::DisplayRole << Qt::BackgroundRole - << Qt::FontRole << Qt::DecorationRole; - emit dataChanged( index(0, 0), index( rowCount( QModelIndex() ) - 1, 0 ), updateRoles ); + updatedObject(ref); } diff --git a/RefsViews/Branches/BranchesModel.hpp b/RefsViews/Branches/BranchesModel.hpp index 86a7532..87956ba 100644 --- a/RefsViews/Branches/BranchesModel.hpp +++ b/RefsViews/Branches/BranchesModel.hpp @@ -31,6 +31,7 @@ namespace RM { class Ref; class Repo; + class CollectionNode; } class RefItem; @@ -40,10 +41,11 @@ class BranchesModel : public QAbstractItemModel { Q_OBJECT public: - BranchesModel( BranchesViewData* parent ); + BranchesModel(BranchesViewData* parent); ~BranchesModel(); public: + void setRepository(RM::Repo* repo); RefItem* indexToItem(const QModelIndex& index, RefItem* defaultItem = NULL) const; public: @@ -55,9 +57,6 @@ class BranchesModel : public QAbstractItemModel QModelIndex parent( const QModelIndex& child ) const; bool hasChildren( const QModelIndex& parent ) const; -public: - void rereadBranches(); - signals: void gitError( const Git::Result& error ); @@ -65,26 +64,34 @@ private slots: void onRefCreated(RM::Repo* repo, RM::Ref* ref); void onRefDestroyed(RM::Repo* repo, RM::Ref* ref); void onRefMoved(RM::Repo* repo, RM::Ref* ref); + void onRefTreeNodeAboutToBeDeleted(RM::Repo* repo, RM::RefTreeNode* obj); private: - QModelIndex index(RefItem* item) const; + QModelIndex itemToIndex(RefItem* item) const; + QModelIndex objectToIndex(RM::Base* obj) const; - void insertRef(bool notify, const Git::Reference& ref); - RefItem* insertNamespace(const bool notify, RefItem* parent, const QString& name); - void insertBranch(const bool notify, RefItem *parent, const Git::Reference& ref); + RefItem* link(bool notify, RefItem* it); + void insertCollection(RM::CollectionNode* coll); + RefItem* insertObject(bool notify, RM::Base* obj); + RefItem* createBranchItem(bool notify, RefItem* parent, RM::Branch* obj); + RefItem* createTagItem(bool notify, RefItem* parent, RM::Tag* obj); + RefItem* createScopeItem(bool notify, RefItem* parent, RM::RefTreeNode* obj); + RefItem* createRemoteItem(bool notify, RefItem* parent, RM::Remote* obj); - RefScope* scopeForRef( const Git::Reference& ref ) const; + void updatedObject(RM::Base* obj); + void deletedObject(RM::Base* obj); + void deleteItem(RefItem* it); private: - BranchesViewData* mData; - RefItem* mRoot; + RM::Repo* mRepo; + RefRoot* mRoot; - RefScope* mHeaderLocal; - RefScope* mHeaderRemote; - RefScope* mHeaderTags; + RefHeadline* mHeaderLocal; + RefHeadline* mHeaderRemote; + RefHeadline* mHeaderTags; -private: - static void findInvalidRefItems(QVector& invalidItems, RefItem* item, const RM::Ref* ref); + QHash mObjToItems; + QHash mItemToObjs; }; #endif diff --git a/RefsViews/Branches/BranchesView.cpp b/RefsViews/Branches/BranchesView.cpp index c18db33..d449e15 100644 --- a/RefsViews/Branches/BranchesView.cpp +++ b/RefsViews/Branches/BranchesView.cpp @@ -22,6 +22,7 @@ #include "libMacGitverCore/App/MacGitver.hpp" #include "libMacGitverCore/RepoMan/RepoMan.hpp" +#include "libMacGitverCore/RepoMan/Branch.hpp" #include "RefItem.hpp" #include "RefRenameDialog.hpp" @@ -103,24 +104,28 @@ void BranchesView::onCheckoutRef() if ( !action ) // FIXME: What is this TEST good for? return; - const RefItem* item = indexToItem(mTree->currentIndex()); - if (!item || item->type() != RefItem::Branch ) { - return; - } - const RefBranch* branch = static_cast(item); + RefBranch* branch = indexToItemChecked(mTree->currentIndex()); - Git::CheckoutReferenceOperation* op = new Git::CheckoutReferenceOperation( branch->reference() ); - op->setMode( Git::CheckoutSafe ); - op->setStrategy( Git::CheckoutUpdateHEAD | Git::CheckoutAllowConflicts ); - // TODO: setBackgroundMode( true ); - op->execute(); + Git::Result r; + RM::Ref* ref = branch->object(); + Git::Reference gitRef = ref->load(r); + + if (r) { + Git::CheckoutReferenceOperation* op = new Git::CheckoutReferenceOperation(gitRef); + + op->setMode( Git::CheckoutSafe ); + op->setStrategy( Git::CheckoutUpdateHEAD | Git::CheckoutAllowConflicts ); + // TODO: setBackgroundMode( true ); + op->execute(); + + r = op->result(); + } - Git::Result r = op->result(); if ( !r ) { QMessageBox::warning( this, trUtf8("Error while checking out reference."), trUtf8("Failed to checkout reference (%1).\nGit message: %2") - .arg(branch->reference().shorthand()) + .arg(ref->name()) .arg(r.errorText()) ); } } @@ -130,19 +135,18 @@ void BranchesView::onRemoveRef() Heaven::Action* action = qobject_cast< Heaven::Action* >( sender() ); if ( !action ) return; // FIXME: What is this TEST good for? - const RefItem* item = indexToItem(mTree->currentIndex()); - if (!item || item->type() != RefItem::Branch ) { - return; - } - const RefBranch* branch = static_cast(item); + RefBranch* branch = indexToItemChecked(mTree->currentIndex()); + RM::Branch* rmBranch = branch->object(); - if ( !askToGoOn( trUtf8("Delete reference \'%1\'?").arg(branch->reference().shorthand()) ) ) + if ( !askToGoOn( trUtf8("Delete reference \'%1\'?").arg(rmBranch->name()) ) ) return; Git::Result r; - Git::Reference ref = branch->reference(); + Git::Reference ref = rmBranch->load(r); - if ( !checkRemoveRef( ref ) ) return; + if ( !checkRemoveRef( ref ) ) { + return; + } ref.destroy(r); @@ -150,7 +154,7 @@ void BranchesView::onRemoveRef() { QMessageBox::warning( this, trUtf8("Error while removing reference."), trUtf8("Failed to remove reference (%1).\nGit message: %2") - .arg(branch->reference().shorthand()) + .arg(rmBranch->name()) .arg(r.errorText()) ); } } @@ -218,12 +222,11 @@ void BranchesView::onRenameRef() } RefBranch* branch = static_cast(item); - RefRenameDialog* dlg = new RefRenameDialog; - dlg->init(branch); + RefRenameDialog dlg(branch); - if ( dlg->exec() != QDialog::Accepted ) + if ( dlg.exec() != QDialog::Accepted ) { - const Git::Result& dlgResult = dlg->gitResult(); + const Git::Result& dlgResult = dlg.gitResult(); if ( !dlgResult ) { QMessageBox::warning( this, trUtf8("Failed to rename reference"), diff --git a/RefsViews/Branches/BranchesView.hpp b/RefsViews/Branches/BranchesView.hpp index d0a2236..147937c 100644 --- a/RefsViews/Branches/BranchesView.hpp +++ b/RefsViews/Branches/BranchesView.hpp @@ -24,6 +24,7 @@ #include "libBlueSky/Contexts.hpp" #include "RefsViewDelegate.h" +#include "Branches/RefItem.hpp" class QTreeView; class QModelIndex; @@ -34,7 +35,6 @@ namespace Git class Result; } -class RefItem; class BranchesViewData; class BranchesView : public BlueSky::ContextView, private BranchesViewActions @@ -69,6 +69,16 @@ public slots: RefItem* indexToItem(const QModelIndex& index) const; + template + T* indexToItemChecked(const QModelIndex& index) const + { + RefItem* it = indexToItem(index); + if (it && it->type() == T::StaticType) { + return static_cast(it); + } + return NULL; + } + private: RefsViewDelegate mRefDelegate; QTreeView* mTree; diff --git a/RefsViews/Branches/BranchesViewData.cpp b/RefsViews/Branches/BranchesViewData.cpp index 04708ad..7a226e2 100644 --- a/RefsViews/Branches/BranchesViewData.cpp +++ b/RefsViews/Branches/BranchesViewData.cpp @@ -32,9 +32,11 @@ BranchesViewData::BranchesViewData() void BranchesViewData::attachedToContext(BlueSky::ViewContext* context) { - Q_UNUSED( context ); + IRepositoryContext* ctx = qobject_cast< IRepositoryContext* >(context); + mModel = new BranchesModel( this ); - mModel->rereadBranches(); + + mModel->setRepository(ctx ? ctx->repository() : NULL); } void BranchesViewData::detachedFromContext() diff --git a/RefsViews/Branches/RefItem.cpp b/RefsViews/Branches/RefItem.cpp index 27c552c..06b2264 100644 --- a/RefsViews/Branches/RefItem.cpp +++ b/RefsViews/Branches/RefItem.cpp @@ -17,13 +17,12 @@ */ #include "RefItem.hpp" +#include "BranchesModel.hpp" #include "libGitWrap/Reference.hpp" #include "libGitWrap/Repository.hpp" #include "libGitWrap/Result.hpp" -#include "libMacGitverCore/RepoMan/Ref.hpp" - #include #include #include @@ -33,11 +32,10 @@ RefItem::RefItem() { } -RefItem::RefItem(RefItem *p) - : parent( p ) +RefItem::RefItem(RefItem* parent) + : parent(parent) { - Q_ASSERT( p ); - p->children.append( this ); + Q_ASSERT(parent); } RefItem::~RefItem() @@ -49,59 +47,62 @@ RefItem::~RefItem() qDeleteAll( children ); } -/** - * @brief Checks the validity of internal data. - * - * @return the default implementation returns always true - */ -bool RefItem::isValid() const +RM::Base* RefItem::object() { - return true; + return NULL; } -QVariant RefItem::data(int role) const +int RefItem::itemPosition() { - Q_UNUSED( role ) - return QVariant(); -} + int i = 0; + while (i < parent->children.count()) { + RefItem* sibling = parent->children.at(i); + if (sibling->data(Qt::DisplayRole).toString() > data(Qt::DisplayRole).toString()) { + break; + } + i++; + } -QString RefItem::text() const -{ - return QString(); + return i; } - -RefScope::RefScope(RefItem *p, const QString &t) - : RefItem( p ) - , mText ( t ) +QVariant RefItem::data(int role) const { + Q_UNUSED( role ) + return QVariant(); } -RefItem::ItemType RefScope::type() const +int RefHeadline::itemPosition() { - return Scope; + int i = parent->children.indexOf(this); + return (i == -1) ? parent->children.count() : i; } -QVariant RefScope::data(int role) const +QVariant RefHeadline::data(int role) const { - switch( role ) - { + switch (role) { case Qt::DisplayRole: return mText; case RefItem::RowBgRole: return QColor(216, 233, 255); - } - return QVariant(); + default: + return QVariant(); + } } -QString RefScope::text() const +RefItem::ItemType RefHeadline::type() const { - return mText; + return Headline; } +RefItem::ItemType RefScope::type() const +{ + return Scope; +} +#if 0 RefNameSpace::RefNameSpace(RefItem *p, const QString &t) : RefScope( p, t ) { @@ -125,37 +126,7 @@ QVariant RefNameSpace::data(int role) const return QVariant(); } - - -RefBranch::RefBranch(RefItem *p, const Git::Reference &ref) - : RefItem( p ) - , mRef( ref ) -{ -} - -/** - * @brief Am I pointing to a valid Git::Reference object? - * - * @return true, if the owned reference is valid; false otherwise - */ -bool RefBranch::isValid() const -{ - return (mRef.isValid() && !mRef.wasDestroyed()); -} - -/** - * @brief Workaround to compare the reference name. - * - * This method will be deleted when migrating to RM::RepoMan. - * - * @param ref the RM::Ref to compare with - * - * @return true when both names match; false otherwise - */ -bool RefBranch::sameReference(const RM::Ref* ref) const -{ - return ref && mRef.name() == ref->fullName(); -} +#endif RefItem::ItemType RefBranch::type() const { @@ -164,23 +135,23 @@ RefItem::ItemType RefBranch::type() const QVariant RefBranch::data(int role) const { - if ( role == Qt::DisplayRole ) - return mRef.shorthand().section( QChar(L'/'), -1 ); + Git::Result r; + Q_ASSERT(mObject); - else if ( role == Qt::FontRole ) - { + switch (role) { + case Qt::FontRole: + #if 0 if( mRef.isCurrentBranch() ) { QFont f; f.setBold( true ); return f; } - } - - else if ( role == RefItem::RowBgGradientRole ) - { - Git::Result r; + #endif + break; + case RefItem::RowBgGradientRole: + #if 0 if ( mRef.compare( mRef.repository().HEAD(r) ) == 0 ) { QColor back = mRef.isCurrentBranch() @@ -188,15 +159,41 @@ QVariant RefBranch::data(int role) const : QColor::fromHsl(35, 255, 190).lighter(130); return back; } + #endif + break; + + case Qt::EditRole: + return object()->name(); } - else if ( role == Qt::EditRole) - return mRef.name(); + return RefItemObject::data(role); +} - return QVariant(); +RefItem::ItemType RefTag::type() const +{ + return Tag; +} + +QVariant RefTag::data(int role) const +{ + Git::Result r; + Q_ASSERT(mObject); + + switch (role) { + case Qt::EditRole: + return object()->name(); + } + + return RefItemObject::data(role); } RefItem::ItemType RefRoot::type() const { return Root; } + + +RefItem::ItemType RefRemote::type() const +{ + return Remote; +} diff --git a/RefsViews/Branches/RefItem.hpp b/RefsViews/Branches/RefItem.hpp index 4ec404b..8ce3235 100644 --- a/RefsViews/Branches/RefItem.hpp +++ b/RefsViews/Branches/RefItem.hpp @@ -20,14 +20,28 @@ #include "libGitWrap/Reference.hpp" +#include "libHeavenIcons/Icon.hpp" + +#include "libMacGitverCore/RepoMan/RefTreeNode.hpp" +#include "libMacGitverCore/RepoMan/Ref.hpp" +#include "libMacGitverCore/RepoMan/Branch.hpp" +#include "libMacGitverCore/RepoMan/Tag.hpp" +#include "libMacGitverCore/RepoMan/Remote.hpp" + #include #include +#include namespace RM { + class Base; class Ref; + class Branch; + class RefTreeNode; + class Namespace; } +class BranchesModel; class RefItem { @@ -41,32 +55,38 @@ class RefItem enum ItemType { Root = 1, + Headline, Scope, Namespace, + Remote, Reference, - Branch = Reference + Branch = Reference, + Tag }; -public: +protected: RefItem(); - RefItem( RefItem* p ); + RefItem(RefItem* parent); + +public: virtual ~RefItem(); public: - virtual bool isValid() const; + int itemPosition(); virtual ItemType type() const = 0; - virtual bool sameReference(const RM::Ref* ref) const { return false; } + virtual RM::Base* object(); public: RefItem* parent; QList< RefItem* > children; virtual QVariant data(int role) const; - virtual QString text() const; }; class RefRoot : public RefItem { +public: + enum { StaticType = Root }; public: RefRoot() {} @@ -74,48 +94,132 @@ class RefRoot : public RefItem ItemType type() const; }; -class RefScope : public RefItem +class RefHeadline : public RefItem { public: - RefScope( RefItem* p, const QString& t ); + enum { StaticType = Headline }; -protected: +public: + RefHeadline(RefItem* parent, const QString& t) + : RefItem(parent) + , mText(t) + {} + +public: + int itemPosition(); virtual QVariant data(int role) const; - QString text() const; ItemType type() const; public: QString mText; }; +template +class RefItemObject : public RefItem +{ +protected: + RefItemObject(RefItem* parent, T* object) + : RefItem(parent) + , mObject(object) + {} + +public: + const T* object() const { + return mObject; + } + + T* object() { + return mObject; + } + + QVariant data(int role) const { + if (mObject) { + switch (role) { + case Qt::DisplayRole: + return mObject->displayName(); + + case Qt::DecorationRole: + Heaven::IconRef iref = mObject->icon(true); + Heaven::Icon icon = iref.icon(); + return icon.pixmap(); + } + } + return RefItem::data(role); + } + +protected: + T* mObject; +}; + +class RefScope : public RefItemObject +{ +public: + enum { StaticType = Scope }; + +public: + RefScope(RefItem* parent, RM::RefTreeNode* obj) + : RefItemObject(parent, obj) + {} + +protected: + ItemType type() const; +}; + class RefNameSpace : public RefScope { +public: + enum { StaticType = Namespace }; public: RefNameSpace( RefItem* p, const QString& t ); - QVariant data(int role) const; ItemType type() const; }; +class RefRemote : public RefItemObject +{ +public: + enum { StaticType = Remote }; + +public: + RefRemote(RefItem* parent, RM::Remote* remote) + : RefItemObject(parent, remote) + { + } + +public: + ItemType type() const; +}; -class RefBranch : public RefItem +class RefBranch : public RefItemObject { public: - explicit RefBranch(RefItem* p, const Git::Reference &ref); + enum { StaticType = Branch }; public: - bool isValid() const; - bool sameReference(const RM::Ref* ref) const; + RefBranch(RefItem* parent, RM::Branch* branch) + : RefItemObject(parent, branch) + { + } +public: QVariant data(int role) const; ItemType type() const; +}; + - Git::Reference reference() const +class RefTag : public RefItemObject +{ +public: + enum { StaticType = Tag }; + +public: + RefTag(RefItem* parent, RM::Tag* tag) + : RefItemObject(parent, tag) { - return mRef; } -private: - Git::Reference mRef; +public: + QVariant data(int role) const; + ItemType type() const; }; diff --git a/RefsViews/RefRenameDialog.cpp b/RefsViews/RefRenameDialog.cpp index 2a4d92f..fe4cb29 100644 --- a/RefsViews/RefRenameDialog.cpp +++ b/RefsViews/RefRenameDialog.cpp @@ -20,25 +20,22 @@ #include "Branches/RefItem.hpp" -#include "libGitWrap/Reference.hpp" +#include "libGitWrap/BranchRef.hpp" -RefRenameDialog::RefRenameDialog() +#include "libMacGitverCore/RepoMan/Branch.hpp" + +RefRenameDialog::RefRenameDialog(RefBranch* ref) : BlueSky::Dialog() - , mRefInfo( 0 ) + , mRefInfo(ref) { + if (!mRefInfo) { + reject(); + return; + } + setupUi( this ); setFixedSize( size() ); // Why? -} - -RefRenameDialog::~RefRenameDialog() -{ -} - -void RefRenameDialog::init( RefBranch* refInfo ) -{ - mRefInfo = refInfo; - - updateValues(); + textRefName->setText(ref->object()->name()); } const Git::Result &RefRenameDialog::gitResult() const @@ -48,12 +45,12 @@ const Git::Result &RefRenameDialog::gitResult() const void RefRenameDialog::accept() { - if (!mRefInfo) { + Git::Reference ref = mRefInfo->object()->load(mGitResult); + if (!mGitResult) { reject(); return; } - Git::Reference ref = mRefInfo->reference(); const QString oldRefName = ref.name(); const QString prefix = oldRefName.left( oldRefName.length() - ref.shorthand().length() ); @@ -68,12 +65,3 @@ void RefRenameDialog::accept() else reject(); } - -void RefRenameDialog::updateValues() -{ - if ( !mRefInfo ) return; - - const Git::Reference& ref = mRefInfo->reference(); - Q_ASSERT( ref.isValid() ); - textRefName->setText( ref.shorthand() ); -} diff --git a/RefsViews/RefRenameDialog.hpp b/RefsViews/RefRenameDialog.hpp index ed1d674..7292c24 100644 --- a/RefsViews/RefRenameDialog.hpp +++ b/RefsViews/RefRenameDialog.hpp @@ -33,10 +33,8 @@ class RefRenameDialog { Q_OBJECT public: - RefRenameDialog(); - ~RefRenameDialog(); + RefRenameDialog(RefBranch* ref); - void init(RefBranch *refInfo); const Git::Result &gitResult() const; private slots: @@ -45,9 +43,6 @@ private slots: private: RefBranch* mRefInfo; Git::Result mGitResult; - -private: - void updateValues(); }; #endif // REF_RENAME_DIALOG_HPP From 17e5a24c3f91e2bf99fa0398f4f1f6c88793f2b3 Mon Sep 17 00:00:00 2001 From: Sascha Cunz Date: Thu, 12 Feb 2015 15:00:19 +0000 Subject: [PATCH 72/80] Remove EditRole --- RefsViews/Branches/RefItem.cpp | 3 --- 1 file changed, 3 deletions(-) diff --git a/RefsViews/Branches/RefItem.cpp b/RefsViews/Branches/RefItem.cpp index 06b2264..9ae28a8 100644 --- a/RefsViews/Branches/RefItem.cpp +++ b/RefsViews/Branches/RefItem.cpp @@ -161,9 +161,6 @@ QVariant RefBranch::data(int role) const } #endif break; - - case Qt::EditRole: - return object()->name(); } return RefItemObject::data(role); From b000ec63fe547035785efaaa69cd83a00e98bfc2 Mon Sep 17 00:00:00 2001 From: Sascha Cunz Date: Thu, 12 Feb 2015 15:09:48 +0000 Subject: [PATCH 73/80] Fix regresion in RenameDlg --- RefsViews/RefRenameDialog.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/RefsViews/RefRenameDialog.cpp b/RefsViews/RefRenameDialog.cpp index fe4cb29..2af51ef 100644 --- a/RefsViews/RefRenameDialog.cpp +++ b/RefsViews/RefRenameDialog.cpp @@ -21,6 +21,7 @@ #include "Branches/RefItem.hpp" #include "libGitWrap/BranchRef.hpp" +#include "libGitWrap/RefName.hpp" #include "libMacGitverCore/RepoMan/Branch.hpp" @@ -35,7 +36,11 @@ RefRenameDialog::RefRenameDialog(RefBranch* ref) setupUi( this ); setFixedSize( size() ); // Why? - textRefName->setText(ref->object()->name()); + + Git::RefName nameParser(ref->object()->fullName()); + QString name = nameParser.shorthand(); + + textRefName->setText(name); } const Git::Result &RefRenameDialog::gitResult() const From e7140dcff4e17d3bf2787bf0152320234b31c2a3 Mon Sep 17 00:00:00 2001 From: Sascha Cunz Date: Thu, 12 Feb 2015 15:10:21 +0000 Subject: [PATCH 74/80] Make RenameDialog more intuitive --- RefsViews/RefRenameDialog.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/RefsViews/RefRenameDialog.cpp b/RefsViews/RefRenameDialog.cpp index 2af51ef..f96af27 100644 --- a/RefsViews/RefRenameDialog.cpp +++ b/RefsViews/RefRenameDialog.cpp @@ -39,8 +39,10 @@ RefRenameDialog::RefRenameDialog(RefBranch* ref) Git::RefName nameParser(ref->object()->fullName()); QString name = nameParser.shorthand(); + QString localName = nameParser.name(); textRefName->setText(name); + textRefName->setSelection(name.length() - localName.length(), localName.length()); } const Git::Result &RefRenameDialog::gitResult() const From 17592e079bbea1ebd91992a50abdf2ed82ab7287 Mon Sep 17 00:00:00 2001 From: Sascha Cunz Date: Thu, 12 Feb 2015 15:11:13 +0000 Subject: [PATCH 75/80] Refresh Repositories --- RefsViews/RefRenameDialog.cpp | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/RefsViews/RefRenameDialog.cpp b/RefsViews/RefRenameDialog.cpp index f96af27..85b7788 100644 --- a/RefsViews/RefRenameDialog.cpp +++ b/RefsViews/RefRenameDialog.cpp @@ -16,6 +16,8 @@ * */ +#include + #include "RefRenameDialog.hpp" #include "Branches/RefItem.hpp" @@ -24,6 +26,7 @@ #include "libGitWrap/RefName.hpp" #include "libMacGitverCore/RepoMan/Branch.hpp" +#include "libMacGitverCore/RepoMan/Repo.hpp" RefRenameDialog::RefRenameDialog(RefBranch* ref) : BlueSky::Dialog() @@ -59,16 +62,20 @@ void RefRenameDialog::accept() } const QString oldRefName = ref.name(); - const QString prefix = oldRefName.left( oldRefName.length() - ref.shorthand().length() ); + const QString prefix = oldRefName.left(oldRefName.length() - ref.shorthand().length()); + + QString newRefName = prefix % textRefName->text(); + + if (!newRefName.isEmpty() && oldRefName != newRefName) { - QString newRefName = prefix + textRefName->text(); - if ( !newRefName.isEmpty() && (oldRefName != newRefName) ) - { - ref.rename( mGitResult, newRefName ); + ref.rename(mGitResult, newRefName); + + if (mGitResult) { + mRefInfo->object()->repository()->refresh(); + QDialog::accept(); + return; + } } - if ( mGitResult ) - QDialog::accept(); - else - reject(); + reject(); } From 3b8f681a7809c147b449d54b90391aa5c3ea59ae Mon Sep 17 00:00:00 2001 From: Sascha Cunz Date: Thu, 12 Feb 2015 16:03:30 +0000 Subject: [PATCH 76/80] Ref Rename Dialog doesn't need to depend on Model internals --- RefsViews/Branches/BranchesView.cpp | 5 ++++- RefsViews/RefRenameDialog.cpp | 25 +++++++++---------------- RefsViews/RefRenameDialog.hpp | 17 ++++++++--------- 3 files changed, 21 insertions(+), 26 deletions(-) diff --git a/RefsViews/Branches/BranchesView.cpp b/RefsViews/Branches/BranchesView.cpp index d449e15..475c403 100644 --- a/RefsViews/Branches/BranchesView.cpp +++ b/RefsViews/Branches/BranchesView.cpp @@ -222,7 +222,10 @@ void BranchesView::onRenameRef() } RefBranch* branch = static_cast(item); - RefRenameDialog dlg(branch); + Git::Result r; + Git::Reference gitRef(branch->object()->load(r)); + + RefRenameDialog dlg(gitRef, branch->object()->repository()); if ( dlg.exec() != QDialog::Accepted ) { diff --git a/RefsViews/RefRenameDialog.cpp b/RefsViews/RefRenameDialog.cpp index 85b7788..cd111d2 100644 --- a/RefsViews/RefRenameDialog.cpp +++ b/RefsViews/RefRenameDialog.cpp @@ -22,25 +22,24 @@ #include "Branches/RefItem.hpp" -#include "libGitWrap/BranchRef.hpp" #include "libGitWrap/RefName.hpp" #include "libMacGitverCore/RepoMan/Branch.hpp" #include "libMacGitverCore/RepoMan/Repo.hpp" -RefRenameDialog::RefRenameDialog(RefBranch* ref) +RefRenameDialog::RefRenameDialog(const Git::Reference &ref, RM::Repo* repo) : BlueSky::Dialog() - , mRefInfo(ref) + , mRef(ref) + , mRepo(repo) { - if (!mRefInfo) { + if (!mRef.isValid()) { reject(); return; } setupUi( this ); - setFixedSize( size() ); // Why? - Git::RefName nameParser(ref->object()->fullName()); + Git::RefName nameParser = ref.nameAnalyzer(); QString name = nameParser.shorthand(); QString localName = nameParser.name(); @@ -55,23 +54,17 @@ const Git::Result &RefRenameDialog::gitResult() const void RefRenameDialog::accept() { - Git::Reference ref = mRefInfo->object()->load(mGitResult); - if (!mGitResult) { - reject(); - return; - } - - const QString oldRefName = ref.name(); - const QString prefix = oldRefName.left(oldRefName.length() - ref.shorthand().length()); + const QString oldRefName = mRef.name(); + const QString prefix = oldRefName.left(oldRefName.length() - mRef.shorthand().length()); QString newRefName = prefix % textRefName->text(); if (!newRefName.isEmpty() && oldRefName != newRefName) { - ref.rename(mGitResult, newRefName); + mRef.rename(mGitResult, newRefName); if (mGitResult) { - mRefInfo->object()->repository()->refresh(); + mRepo->refresh(); QDialog::accept(); return; } diff --git a/RefsViews/RefRenameDialog.hpp b/RefsViews/RefRenameDialog.hpp index 7292c24..79e554e 100644 --- a/RefsViews/RefRenameDialog.hpp +++ b/RefsViews/RefRenameDialog.hpp @@ -16,16 +16,16 @@ * */ -#ifndef REF_RENAME_DIALOG_HPP -#define REF_RENAME_DIALOG_HPP +#pragma once #include "libBlueSky/Dialog.hpp" #include "libGitWrap/Result.hpp" +#include "libGitWrap/Reference.hpp" -#include "ui_RefRenameDialog.h" +#include "libMacGitverCore/RepoMan/Repo.hpp" -class RefBranch; +#include "ui_RefRenameDialog.h" class RefRenameDialog : public BlueSky::Dialog @@ -33,7 +33,7 @@ class RefRenameDialog { Q_OBJECT public: - RefRenameDialog(RefBranch* ref); + RefRenameDialog(const Git::Reference& ref, RM::Repo* repo); const Git::Result &gitResult() const; @@ -41,8 +41,7 @@ private slots: void accept(); private: - RefBranch* mRefInfo; - Git::Result mGitResult; + Git::Result mGitResult; + Git::Reference mRef; + RM::Repo* mRepo; }; - -#endif // REF_RENAME_DIALOG_HPP From e56b87e25b517dccc565205f186fc034336cc1f7 Mon Sep 17 00:00:00 2001 From: Sascha Cunz Date: Thu, 12 Feb 2015 16:43:04 +0000 Subject: [PATCH 77/80] Now, remove the manual indentation to get the tree aligned exactly --- RefsViews/Branches/BranchesView.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/RefsViews/Branches/BranchesView.cpp b/RefsViews/Branches/BranchesView.cpp index 475c403..4c1d0dd 100644 --- a/RefsViews/Branches/BranchesView.cpp +++ b/RefsViews/Branches/BranchesView.cpp @@ -44,7 +44,6 @@ BranchesView::BranchesView() mTree->setAttribute( Qt::WA_MacShowFocusRect, false ); #endif mTree->setFrameStyle( QFrame::NoFrame ); - mTree->setIndentation( 12 ); mTree->setHeaderHidden( true ); mTree->setRootIsDecorated( false ); mTree->setItemDelegate( &mRefDelegate ); From 4651af0e3acf517d05421f0514922dfc0f9059f1 Mon Sep 17 00:00:00 2001 From: Sascha Cunz Date: Thu, 12 Feb 2015 17:45:47 +0000 Subject: [PATCH 78/80] Add missing spacer to Rename Ref dialog --- RefsViews/RefRenameDialog.ui | 33 +++++++++++++++++++++++---------- 1 file changed, 23 insertions(+), 10 deletions(-) diff --git a/RefsViews/RefRenameDialog.ui b/RefsViews/RefRenameDialog.ui index cda9c33..d71eb26 100644 --- a/RefsViews/RefRenameDialog.ui +++ b/RefsViews/RefRenameDialog.ui @@ -6,25 +6,18 @@ 0 0 - 352 - 85 + 335 + 95 Rename reference - - - - Rename reference: - - - - + Qt::Horizontal @@ -34,6 +27,26 @@ + + + + Rename reference: + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + From d1dac9900a1f5154635f9b7662fe98a5ac7a64c2 Mon Sep 17 00:00:00 2001 From: Sascha Cunz Date: Sat, 14 Feb 2015 07:04:54 +0000 Subject: [PATCH 79/80] Keep Headlines disabled and not selectable As far as _behaviour_ is concerned, we don't want the headlines enabled. So that they cannot actually even be focused. However, this is certainly not what we want to draw. --- RefsViews/Branches/BranchesModel.cpp | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/RefsViews/Branches/BranchesModel.cpp b/RefsViews/Branches/BranchesModel.cpp index df3e7be..b289d8e 100644 --- a/RefsViews/Branches/BranchesModel.cpp +++ b/RefsViews/Branches/BranchesModel.cpp @@ -113,15 +113,14 @@ Qt::ItemFlags BranchesModel::flags( const QModelIndex& index ) const return Qt::NoItemFlags; } - Qt::ItemFlags result = Qt::ItemIsEnabled; - const RefItem* item = indexToItem(index); - + RefItem* item = indexToItem(index); RefItem::ItemType t = item->type(); - if (t != RefItem::Scope) { - result |= Qt::ItemIsSelectable; + + if (t == RefItem::Headline) { + return Qt::NoItemFlags; } - return result; + return Qt::ItemIsSelectable | Qt::ItemIsEnabled; } QModelIndex BranchesModel::index( int row, int column, const QModelIndex& parent ) const From 949835ec3bef30f0b938a6fe2f26b4fa499b51f9 Mon Sep 17 00:00:00 2001 From: Sascha Cunz Date: Mon, 16 Mar 2015 22:19:55 +0000 Subject: [PATCH 80/80] Show current branch in bold --- RefsViews/Branches/BranchesModel.cpp | 17 +++++++---------- RefsViews/Branches/RefItem.cpp | 5 +---- 2 files changed, 8 insertions(+), 14 deletions(-) diff --git a/RefsViews/Branches/BranchesModel.cpp b/RefsViews/Branches/BranchesModel.cpp index b289d8e..ed00375 100644 --- a/RefsViews/Branches/BranchesModel.cpp +++ b/RefsViews/Branches/BranchesModel.cpp @@ -67,8 +67,7 @@ RefItem* BranchesModel::indexToItem(const QModelIndex& index, RefItem* defaultIt QModelIndex BranchesModel::itemToIndex(RefItem* item) const { - if ( !item || (item == mRoot) ) - { + if (!item || (item == mRoot)) { return QModelIndex(); } @@ -125,8 +124,7 @@ Qt::ItemFlags BranchesModel::flags( const QModelIndex& index ) const QModelIndex BranchesModel::index( int row, int column, const QModelIndex& parent ) const { - if( !hasIndex( row, column, parent ) ) - { + if (!hasIndex(row, column, parent)) { return QModelIndex(); } @@ -138,25 +136,24 @@ QModelIndex BranchesModel::index( int row, int column, const QModelIndex& parent QModelIndex BranchesModel::parent( const QModelIndex& child ) const { - if( !child.isValid() ) - { + if (!child.isValid()) { return QModelIndex(); } RefItem* childItem = indexToItem(child); RefItem* parentItem = childItem->parent; - if( parentItem == mRoot ) + if (parentItem == mRoot) { return QModelIndex(); + } int row = parentItem->parent->children.indexOf( parentItem ); return createIndex( row, 0, parentItem ); } -bool BranchesModel::hasChildren( const QModelIndex& parent ) const +bool BranchesModel::hasChildren(const QModelIndex& parent) const { - if( parent.column() > 0 ) - { + if (parent.column() > 0) { return 0; } diff --git a/RefsViews/Branches/RefItem.cpp b/RefsViews/Branches/RefItem.cpp index 9ae28a8..dda9f28 100644 --- a/RefsViews/Branches/RefItem.cpp +++ b/RefsViews/Branches/RefItem.cpp @@ -140,14 +140,11 @@ QVariant RefBranch::data(int role) const switch (role) { case Qt::FontRole: - #if 0 - if( mRef.isCurrentBranch() ) - { + if (object()->isHead()) { QFont f; f.setBold( true ); return f; } - #endif break; case RefItem::RowBgGradientRole: