[kdevplatform] /: Give the patch-review a much needed workover

Milian Wolff mail at milianw.de
Thu Nov 1 18:06:16 UTC 2012


Hey David!

While I really appreciate that you work on this, please *please* use Git 
better and follow our work flow instead of throwing huge diff chunks at us.

Git allows you to commit separate, small chunks independently, try e.g. git 
add -p followed by git commit. Quite probably every bullet point of your 
commit message should have been in a separate commit.

Furthermore, *please* start to add more comments in your code. Just looking at 
e.g. PatchReviewToolView::seekFile makes me shiver once I have to work on it.

Finally, there are quite a few style issues in this patch, most notably 
missing const& for non-POD data types like QList's etc.

Thanks, take care.

On Thursday 01 November 2012 18:31:15 David nolden wrote:
> Git commit 3624e66c5bc1318923d559a3530dcc6e8ab0c4a2 by David nolden.
> Committed on 01/11/2012 at 18:30.
> Pushed by zwabel into branch 'master'.
> 
> Give the patch-review a much needed workover
> 
> * Fix broken patch-review when committing/reviewing a subdirectory with git
> * Don't forget the checked and unchecked files when updating the patch
> * Make the order of automatically opened documents consistent with the
> file-list * Make the 'next hunk' and 'previous hunk' file-local again,
> their changed behavior was very annoying * Correctly jump to the first
> changed hunk on automatically opened documents * Add 'next file' and
> 'previous file' actions, which respect the selection * Don't change the
> cursor position for documents which are already open * Make the file-list
> selectable again, this highlights the currently active document, it's very
> useful! * Make the context-menu in the file-list work
> * Add 'select all' and 'deselect all' actions to the file-list context menu
> 
> M  +12   -10   plugins/patchreview/patchreview.cpp
> M  +1    -0    plugins/patchreview/patchreview.h
> M  +20   -0    plugins/patchreview/patchreview.ui
> M  +162  -23   plugins/patchreview/patchreviewtoolview.cpp
> M  +19   -2    plugins/patchreview/patchreviewtoolview.h
> M  +35   -0    vcs/models/vcsfilechangesmodel.cpp
> M  +28   -0    vcs/models/vcsfilechangesmodel.h
> M  +3    -4    vcs/widgets/vcsdiffpatchsources.cpp
> 
> http://commits.kde.org/kdevplatform/3624e66c5bc1318923d559a3530dcc6e8ab0c4a2
> 
> diff --git a/plugins/patchreview/patchreview.cpp
> b/plugins/patchreview/patchreview.cpp index d4c6955..a8c6f07 100644
> --- a/plugins/patchreview/patchreview.cpp
> +++ b/plugins/patchreview/patchreview.cpp
> @@ -70,6 +70,7 @@ Q_DECLARE_METATYPE( const Diff2::DiffModel* )
> 
>  void PatchReviewPlugin::seekHunk( bool forwards, const KUrl& fileName ) {
>      try {
> +        kDebug() << forwards << fileName << fileName.isEmpty();
>          if ( !m_modelList.get() )
>              throw "no model";
> 
> @@ -82,11 +83,10 @@ void PatchReviewPlugin::seekHunk( bool forwards, const
> KUrl& fileName ) {
> 
>              if ( !fileName.isEmpty() && fileName != file )
>                  continue;
> -
> +
>              IDocument* doc =
> ICore::self()->documentController()->documentForUrl( file ); -
> -            if ( doc && doc ==
> ICore::self()->documentController()->activeDocument() &&
> m_highlighters.contains( doc->url() ) && m_highlighters[doc->url()] ) { -  
>              ICore::self()->documentController()->activateDocument( doc );
> +
> +            if ( doc && m_highlighters.contains( doc->url() ) &&
> m_highlighters[doc->url()] ) { if ( doc->textDocument() ) {
>                      const QList<KTextEditor::MovingRange*> ranges =
> m_highlighters[doc->url()]->ranges();
> 
> @@ -108,7 +108,7 @@ void PatchReviewPlugin::seekHunk( bool forwards, const
> KUrl& fileName ) { if ( bestLine != -1 ) {
>                              v->setCursorPosition( KTextEditor::Cursor(
> bestLine, 0 ) ); return;
> -                        } else {
> +                        } else if(fileName.isEmpty()) {
>                              int next = qBound(0, forwards ? a+1 : a-1,
> m_modelList->modelCount()-1);
> ICore::self()->documentController()->openDocument(urlForFileModel(m_modelLi
> st->modelAt(next))); }
> @@ -223,8 +223,6 @@ void PatchReviewPlugin::updateKompareModel() {
>          m_modelList.reset( 0 );
>          delete m_diffSettings;
> 
> -        emit patchChanged();
> -
>          {
>              IDocument* patchDoc =
> ICore::self()->documentController()->documentForUrl( m_patch->file() ); if(
> patchDoc )
> @@ -369,6 +367,7 @@ void PatchReviewPlugin::finishReview( QList<KUrl>
> selection ) {
> 
>  void PatchReviewPlugin::startReview( IPatchSource* patch,
> IPatchReview::ReviewMode mode ) { Q_UNUSED( mode );
> +    emit startingNewReview();
>      setPatch( patch );
>      QMetaObject::invokeMethod( this, "updateReview", Qt::QueuedConnection
> ); }
> @@ -439,17 +438,20 @@ void PatchReviewPlugin::updateReview() {
>      }
>      futureActiveDoc->textDocument()->setReadWrite( false );
>      futureActiveDoc->setPrettyName( i18n( "Overview" ) );
> +
> +    IDocument* buddyDoc = futureActiveDoc;
> +
>      KTextEditor::ModificationInterface* modif =
> dynamic_cast<KTextEditor::ModificationInterface*>(
> futureActiveDoc->textDocument() ); modif->setModifiedOnDiskWarning( false
> );
> 
>      if( m_modelList->modelCount() < maximumFilesToOpenDirectly ) {
>          //Open all relates files
>          for( int a = 0; a < m_modelList->modelCount(); ++a ) {
> -            KUrl absoluteUrl( m_patch->baseDir(),  m_modelList->modelAt( a
> )->destination() ); +          KUrl absoluteUrl = urlForFileModel(
> m_modelList->modelAt( a ) );
> 
>              if( QFileInfo( absoluteUrl.path() ).exists() &&
> absoluteUrl.path() != "/dev/null" ) {
> -                ICore::self()->documentController()->openDocument(
> absoluteUrl ); +                buddyDoc =
> ICore::self()->documentController()->openDocument( absoluteUrl,
> KTextEditor::Range::invalid(), IDocumentController::DoNotActivate, "",
> buddyDoc ); documents.remove( absoluteUrl );
> 
>                  seekHunk( true, absoluteUrl ); //Jump to the first changed
> position @@ -494,7 +496,7 @@ void PatchReviewPlugin::setPatch(
> IPatchSource* patch ) { m_patch = patch;
> 
>      if( m_patch ) {
> -        kDebug() << "setting new patch" << patch->name() << "with file" <<
> patch->file(); +        kDebug() << "setting new patch" << patch->name() <<
> "with file" << patch->file() << "basedir" << patch->baseDir();
> registerPatch( patch );
> 
>          connect( m_patch, SIGNAL( patchChanged() ), this, SLOT(
> notifyPatchChanged() ) ); diff --git a/plugins/patchreview/patchreview.h
> b/plugins/patchreview/patchreview.h index 4c0b5dc..8c6c046 100644
> --- a/plugins/patchreview/patchreview.h
> +++ b/plugins/patchreview/patchreview.h
> @@ -81,6 +81,7 @@ public :
>      KUrl urlForFileModel( const Diff2::DiffModel* model );
> 
>  Q_SIGNALS:
> +    void startingNewReview();
>      void patchChanged();
> 
>  public Q_SLOTS :
> diff --git a/plugins/patchreview/patchreview.ui
> b/plugins/patchreview/patchreview.ui index b16ef21..457fc38 100644
> --- a/plugins/patchreview/patchreview.ui
> +++ b/plugins/patchreview/patchreview.ui
> @@ -17,6 +17,16 @@
>     <item row="0" column="0" colspan="2">
>      <layout class="QHBoxLayout" name="horizontalLayout_3">
>       <item>
> +      <widget class="QToolButton" name="previousFile">
> +       <property name="toolTip">
> +        <string>Previous file</string>
> +       </property>
> +       <property name="text">
> +        <string>...</string>
> +       </property>
> +      </widget>
> +     </item>
> +     <item>
>        <widget class="QToolButton" name="previousHunk">
>         <property name="toolTip">
>          <string>Previous difference</string>
> @@ -37,6 +47,16 @@
>        </widget>
>       </item>
>       <item>
> +      <widget class="QToolButton" name="nextFile">
> +       <property name="toolTip">
> +        <string>Next file</string>
> +       </property>
> +       <property name="text">
> +        <string>...</string>
> +       </property>
> +      </widget>
> +     </item>
> +     <item>
>        <spacer name="horizontalSpacer">
>         <property name="orientation">
>          <enum>Qt::Horizontal</enum>
> diff --git a/plugins/patchreview/patchreviewtoolview.cpp
> b/plugins/patchreview/patchreviewtoolview.cpp index 14802d4..baac4fe 100644
> --- a/plugins/patchreview/patchreviewtoolview.cpp
> +++ b/plugins/patchreview/patchreviewtoolview.cpp
> @@ -29,7 +29,11 @@
>  #include <interfaces/iprojectcontroller.h>
>  #include <interfaces/iuicontroller.h>
>  #include <util/projecttestjob.h>
> +#include <sublime/area.h>
> +#include <sublime/view.h>
> +#include <sublime/document.h>
>  #include <KLineEdit>
> +#include <KTextEditor/Document>
>  #include <QMenu>
> 
>  using namespace KDevelop;
> @@ -70,14 +74,22 @@ private:
>  };
> 
>  PatchReviewToolView::PatchReviewToolView( QWidget* parent,
> PatchReviewPlugin* plugin ) -    : QWidget( parent ), m_reversed( false ),
> m_plugin( plugin ) { +    : QWidget( parent ),
> +    m_resetCheckedUrls( true ),
> +    m_plugin( plugin ) {
>      connect( plugin, SIGNAL( patchChanged() ), SLOT( patchChanged() ) );
> +    connect( plugin, SIGNAL( startingNewReview() ), SLOT(
> startingNewReview() ) ); connect( ICore::self()->documentController(),
> SIGNAL( documentActivated( KDevelop::IDocument* ) ), this, SLOT(
> documentActivated( KDevelop::IDocument* ) ) );
> 
>      showEditDialog();
>      patchChanged();
>  }
> 
> +void PatchReviewToolView::startingNewReview()
> +{
> +    m_resetCheckedUrls = true;
> +}
> +
>  void PatchReviewToolView::patchChanged() {
>      fillEditFromPatch();
>      kompareModelChanged();
> @@ -201,12 +213,14 @@ void PatchReviewToolView::showEditDialog() {
>      m_editPatch.filesList->setModel( m_fileModel );
>      m_editPatch.filesList->header()->hide();
>      m_editPatch.filesList->setRootIsDecorated( false );
> -   
> m_editPatch.filesList->setSelectionMode(QAbstractItemView::NoSelection);
> m_editPatch.filesList->setContextMenuPolicy(Qt::CustomContextMenu);
> connect(m_editPatch.filesList, SIGNAL(customContextMenuRequested(QPoint)),
> SLOT(customContextMenuRequested(QPoint))); +    connect(m_fileModel,
> SIGNAL(itemChanged(QStandardItem*)),
> SLOT(fileItemChanged(QStandardItem*)));
> 
> +    m_editPatch.previousFile->setIcon( KIcon( "arrow-left" ) );
>      m_editPatch.previousHunk->setIcon( KIcon( "arrow-up" ) );
>      m_editPatch.nextHunk->setIcon( KIcon( "arrow-down" ) );
> +    m_editPatch.nextFile->setIcon( KIcon( "arrow-right" ) );
>      m_editPatch.cancelReview->setIcon( KIcon( "dialog-cancel" ) );
>      m_editPatch.finishReview->setIcon( KIcon( "dialog-ok" ) );
>      m_editPatch.updateButton->setIcon( KIcon( "view-refresh" ) );
> @@ -229,6 +243,8 @@ void PatchReviewToolView::showEditDialog() {
> 
>      connect( m_editPatch.previousHunk, SIGNAL( clicked( bool ) ), this,
> SLOT( prevHunk() ) ); connect( m_editPatch.nextHunk, SIGNAL( clicked( bool
> ) ), this, SLOT( nextHunk() ) ); +    connect( m_editPatch.previousFile,
> SIGNAL( clicked( bool ) ), this, SLOT( prevFile() ) ); +    connect(
> m_editPatch.nextFile, SIGNAL( clicked( bool ) ), this, SLOT( nextFile() )
> ); connect( m_editPatch.filesList, SIGNAL( activated ( QModelIndex ) ),
> this, SLOT( fileDoubleClicked( QModelIndex ) ) );
> 
>      connect( m_editPatch.cancelReview, SIGNAL( clicked( bool ) ), m_plugin,
> SLOT( cancelReview() ) ); @@ -258,6 +274,11 @@ void
> PatchReviewToolView::showEditDialog() {
>      connect( m_editPatch.showButton, SIGNAL( clicked( bool ) ), m_plugin,
> SLOT( updateReview()) );
> 
>      connect( m_editPatch.testsButton, SIGNAL( clicked( bool ) ), this,
> SLOT( runTests() ) ); +
> +    m_selectAllAction = new QAction( KIcon("ok"), i18n("Select All"), this
> ); +    connect( m_selectAllAction, SIGNAL(triggered(bool)),
> SLOT(selectAll()) ); +    m_deselectAllAction = new QAction(
> KIcon("cancel"), i18n("Deselect All"), this ); +    connect(
> m_deselectAllAction, SIGNAL(triggered(bool)), SLOT(deselectAll()) ); }
> 
>  void PatchReviewToolView::customContextMenuRequested(const QPoint& )
> @@ -286,39 +307,147 @@ void
> PatchReviewToolView::customContextMenuRequested(const QPoint& ) vcsActions
> += ext.actions(ContextMenuExtension::VcsGroup); }
> 
> +    menu->addAction(m_selectAllAction);
> +    menu->addAction(m_deselectAllAction);
>      menu->addActions(vcsActions);
>      if ( !menu->isEmpty() ) {
>          menu->exec(QCursor::pos());
>      }
> +
>      delete menu;
>  }
> 
>  void PatchReviewToolView::nextHunk()
>  {
>      IDocument* current =
> ICore::self()->documentController()->activeDocument(); -   
> if(current->url() == m_plugin->patch()->file())
> -        fileDoubleClicked( m_fileModel->index(0,0) );
> -    else if(!current->textDocument())
> -    {
> -        QModelIndex idx =
> m_fileModel->fileItemForUrl(current->url())->index(); -       
> fileDoubleClicked( idx.sibling(idx.row()+1 % m_fileModel->rowCount(), 0) );
> -    }
> -    else
> -        m_plugin->seekHunk( true );
> +    if(current && current->textDocument())
> +        m_plugin->seekHunk( true, current->textDocument()->url() );
>  }
> 
>  void PatchReviewToolView::prevHunk()
>  {
>      IDocument* current =
> ICore::self()->documentController()->activeDocument(); -   
> if(current->url() == m_plugin->patch()->file())
> -        fileDoubleClicked( m_fileModel->index(m_fileModel->rowCount()-1,0)
> ); -    else if(!current->textDocument())
> +    if(current && current->textDocument())
> +        m_plugin->seekHunk( false, current->textDocument()->url() );
> +}
> +
> +void PatchReviewToolView::seekFile(bool forwards)
> +{
> +    if(!m_plugin->patch())
> +        return;
> +    QList<KUrl> checkedUrls = m_fileModel->checkedUrls();
> +    QList<KUrl> allUrls = m_fileModel->urls();
> +    IDocument* current =
> ICore::self()->documentController()->activeDocument(); +    if(!current ||
> checkedUrls.empty())
> +        return;
> +    kDebug() << "seeking direction" << forwards;
> +    int currentIndex = allUrls.indexOf(current->url());
> +    KUrl newUrl;
> +    if((forwards && current->url() == checkedUrls.back()) ||
> +            (!forwards && current->url() == checkedUrls[0]))
>      {
> -        QModelIndex idx =
> m_fileModel->fileItemForUrl(current->url())->index(); -       
> fileDoubleClicked( idx.sibling(idx.row()-1 % m_fileModel->rowCount(), 0) );
> +        newUrl = m_plugin->patch()->file();
> +        kDebug() << "jumping to patch";
> +    }
> +    else if(current->url() == m_plugin->patch()->file() || currentIndex ==
> -1) +    {
> +        if(forwards)
> +            newUrl = checkedUrls[0];
> +        else
> +            newUrl = checkedUrls.back();
> +        kDebug() << "jumping from patch";
>      }
>      else
> -        m_plugin->seekHunk( false );
> +    {
> +        QSet<KUrl> checkedUrlsSet( checkedUrls.toSet() );
> +        for(int offset = 1; offset < allUrls.size(); ++offset)
> +        {
> +            int pos;
> +            if(forwards) {
> +                pos = (currentIndex + offset) % allUrls.size();
> +            }else{
> +                pos = currentIndex - offset;
> +                if(pos < 0)
> +                    pos += allUrls.size();
> +            }
> +            if(checkedUrlsSet.contains(allUrls[pos]))
> +            {
> +                newUrl = allUrls[pos];
> +                break;
> +            }
> +        }
> +    }
> +
> +    if(newUrl.isValid())
> +    {
> +        activate( newUrl, forwards ? current : 0 );
> +    }else{
> +        kDebug() << "found no valid target url";
> +    }
> +}
> +
> +void PatchReviewToolView::activate( KUrl url, IDocument* buddy ) const
> +{
> +    kDebug() << "activating url" << url;
> +    // If the document is already open in this area, just re-activate it
> +    if(KDevelop::IDocument* doc =
> ICore::self()->documentController()->documentForUrl(url)) { +       
> foreach(Sublime::View* view,
> ICore::self()->uiController()->activeArea()->views()) +        {
> +            if(view->document() == dynamic_cast<Sublime::Document*>(doc))
> +            {
> +                ICore::self()->documentController()->activateDocument(doc);
> +                return;
> +            }
> +        }
> +    }
> +
> +    // If the document is not open yet, open it in the correct order
> +    IDocument* newDoc =
> ICore::self()->documentController()->openDocument(url,
> KTextEditor::Range(), IDocumentController::DefaultMode, "", buddy); +   
> if(newDoc && newDoc->textDocument()->activeView() &&
> newDoc->textDocument()->activeView()->cursorPosition().line() == 0) +      
>  m_plugin->seekHunk( true, url );
> +}
> +
> +void PatchReviewToolView::fileItemChanged( QStandardItem* item )
> +{
> +    KUrl url = m_fileModel->statusInfo(item).url();
> +    if(item->checkState() == Qt::Unchecked)
> +    {
> +        // Eventually close the document
> +        if(KDevelop::IDocument* doc =
> ICore::self()->documentController()->documentForUrl(url)) { +           
> if(doc->state() == IDocument::Clean)
> +            {
> +                foreach(Sublime::View* view,
> ICore::self()->uiController()->activeArea()->views()) +                {
> +                    if(view->document() ==
> dynamic_cast<Sublime::Document*>(doc)) +                    {
> +                        kDebug() << "closing view of" << url << "because
> the item was unchecked"; +                       
> ICore::self()->uiController()->activeArea()->closeView(view); +            
>            return;
> +                    }
> +                }
> +            }
> +        }
> +    }
> +}
> +
> +void PatchReviewToolView::nextFile()
> +{
> +    seekFile(true);
> +}
> +
> +void PatchReviewToolView::prevFile()
> +{
> +    seekFile(false);
> +}
> +
> +void PatchReviewToolView::deselectAll()
> +{
> +    m_fileModel->setAllChecked(false);
> +}
> +
> +void PatchReviewToolView::selectAll()
> +{
> +    m_fileModel->setAllChecked(true);
>  }
> 
>  void PatchReviewToolView::finishReview() {
> @@ -331,11 +460,7 @@ void PatchReviewToolView::fileDoubleClicked( const
> QModelIndex& idx ) { QModelIndex i = idx.sibling(idx.row(), 0);
>      KUrl file = m_fileModel->statusInfo( i ).url();
> 
> -    kDebug() << "opening" << file.toLocalFile();
> -
> -    ICore::self()->documentController()->openDocument( file,
> KTextEditor::Cursor() ); -
> -    m_plugin->seekHunk( true, file );
> +    activate( file );
>  }
> 
>  KUrl PatchReviewPlugin::urlForFileModel( const Diff2::DiffModel* model ) {
> @@ -348,8 +473,11 @@ KUrl PatchReviewPlugin::urlForFileModel( const
> Diff2::DiffModel* model ) { }
> 
>  void PatchReviewToolView::kompareModelChanged() {
> +
> +    QList<KUrl> oldCheckedUrls = m_fileModel->checkedUrls();
> +
>      m_fileModel->clear();
> -
> +
>      if ( !m_plugin->modelList() )
>          return;
> 
> @@ -383,11 +511,22 @@ void PatchReviewToolView::kompareModelChanged() {
>          status.setState( it.value() );
>          m_fileModel->updateState( status );
>      }
> +
> +    if(!m_resetCheckedUrls)
> +        m_fileModel->setCheckedUrls(oldCheckedUrls);
> +    else
> +        m_resetCheckedUrls = false;
> 
>      m_editPatch.filesList->resizeColumnToContents( 0 );
> +
> +    // Eventually select the active document
> +    documentActivated(
> ICore::self()->documentController()->activeDocument() ); }
> 
>  void PatchReviewToolView::documentActivated( IDocument* doc ) {
> +    if( !doc )
> +        return;
> +
>      if ( !m_plugin->modelList() )
>          return;
> 
> diff --git a/plugins/patchreview/patchreviewtoolview.h
> b/plugins/patchreview/patchreviewtoolview.h index f236a44..6c3c8d1 100644
> --- a/plugins/patchreview/patchreviewtoolview.h
> +++ b/plugins/patchreview/patchreviewtoolview.h
> @@ -18,7 +18,9 @@
>  #include <QPointer>
>  #include <QTime>
>  #include <ui_patchreview.h>
> +#include <interfaces/ipatchsource.h>
> 
> +class QStandardItem;
>  class KJob;
>  namespace KDevelop {
>  class IDocument;
> @@ -41,10 +43,15 @@ signals:
>      void  stateChanged( PatchReviewToolView* );
>  private slots:
> 
> +    void startingNewReview();
> +
>      void fileDoubleClicked( const QModelIndex& i );
> 
>      void nextHunk();
>      void prevHunk();
> +    void prevFile();
> +    void nextFile();
> +    void seekFile(bool forwards);
> 
>      void patchChanged();
> 
> @@ -56,7 +63,14 @@ private slots:
> 
>      void runTests();
> 
> +    void selectAll();
> +    void deselectAll();
> +
> +    void fileItemChanged( QStandardItem* item );
> +
>  private:
> +    void activate( KUrl url, KDevelop::IDocument* buddy = 0 ) const;
> +
>      void kompareModelChanged();
> 
>      void showEditDialog();
> @@ -72,12 +86,15 @@ private:
> 
>      QPointer< KParts::Part > m_konsolePart;
> 
> -    bool m_reversed;
> +    /// Whether the set of checked URLs should be reset on the next update
> +    bool m_resetCheckedUrls;
> 
>      PatchReviewPlugin* m_plugin;
> 
>      QPointer< QWidget > m_customWidget;
> -
> +    QAction* m_selectAllAction;
> +    QAction* m_deselectAllAction;
> +
>      class PatchFilesModel* m_fileModel;
>  public slots:
>      void documentActivated( KDevelop::IDocument* );
> diff --git a/vcs/models/vcsfilechangesmodel.cpp
> b/vcs/models/vcsfilechangesmodel.cpp index f042693..c4845b3 100644
> --- a/vcs/models/vcsfilechangesmodel.cpp
> +++ b/vcs/models/vcsfilechangesmodel.cpp
> @@ -161,6 +161,17 @@ QList<VcsStatusInfo>
> VcsFileChangesModel::checkedStatuses(QStandardItem *parent) return ret;
>  }
> 
> +void VcsFileChangesModel::setAllChecked(bool checked)
> +{
> +    if(!d->allowSelection)
> +        return;
> +    QStandardItem* parent = invisibleRootItem();
> +    for(int i = 0; i < parent->rowCount(); i++) {
> +        QStandardItem* item = parent->child(i);
> +        item->setCheckState(checked ? Qt::Checked : Qt::Unchecked);
> +    }
> +}
> +
>  QList<KUrl> VcsFileChangesModel::checkedUrls(QStandardItem *parent) const
>  {
>      QList<KUrl> ret;
> @@ -178,6 +189,30 @@ QList<KUrl>
> VcsFileChangesModel::checkedUrls(QStandardItem *parent) const return ret;
>  }
> 
> +QList<KUrl> VcsFileChangesModel::urls(QStandardItem *parent) const
> +{
> +    QList<KUrl> ret;
> +
> +    for(int i = 0; i < parent->rowCount(); i++) {
> +        ret << statusInfo(parent->child(i)).url();
> +    }
> +
> +    return ret;
> +}
> +
> +void VcsFileChangesModel::checkUrls(QStandardItem *parent, QList<KUrl>
> urls) const +{
> +    QSet<KUrl> urlSet(urls.toSet());
> +
> +    if(!d->allowSelection)
> +        return;
> +
> +    for(int i = 0; i < parent->rowCount(); i++) {
> +        QStandardItem* item = parent->child(i);
> +        item->setCheckState(urlSet.contains(statusInfo(item).url()) ?
> Qt::Checked : Qt::Unchecked); +    }
> +}
> +
>  void VcsFileChangesModel::setIsCheckbable(bool checkable)
>  {
>      d->allowSelection = checkable;
> diff --git a/vcs/models/vcsfilechangesmodel.h
> b/vcs/models/vcsfilechangesmodel.h index ad18ad0..96e28b4 100644
> --- a/vcs/models/vcsfilechangesmodel.h
> +++ b/vcs/models/vcsfilechangesmodel.h
> @@ -73,6 +73,24 @@ public:
>          return checkedUrls(invisibleRootItem());
>      }
> 
> +    /**
> +     * Returns urls of all files
> +     * */
> +    QList<KUrl> urls() const {
> +        return urls(invisibleRootItem());
> +    }
> +
> +    /**
> +     * Set the checked urls
> +     * */
> +    void setCheckedUrls(QList<KUrl> urls) const {
> +        return checkUrls(invisibleRootItem(), urls);
> +    }
> +
> +    /**
> +     * Changes the check-state of all files to the given state
> +     * */
> +    void setAllChecked(bool checked);
> 
>      /**
>       * Simple helper to get VcsStatusInfo.
> @@ -119,6 +137,16 @@ protected:
>       * Returns list of currently checked urls.
>       */
>      QList<KUrl> checkedUrls(QStandardItem *parent) const;
> +
> +    /**
> +     * Checks the given urls, unchecks all others.
> +     * */
> +    void checkUrls(QStandardItem *parent, QList<KUrl> urls) const;
> +
> +    /**
> +     * Returns all urls
> +     * */
> +    QList<KUrl> urls(QStandardItem *parent) const;
> 
>  private:
>      class VcsFileChangesModelPrivate *const d;
> diff --git a/vcs/widgets/vcsdiffpatchsources.cpp
> b/vcs/widgets/vcsdiffpatchsources.cpp index 13bc8b2..b522197 100644
> --- a/vcs/widgets/vcsdiffpatchsources.cpp
> +++ b/vcs/widgets/vcsdiffpatchsources.cpp
> @@ -39,15 +39,13 @@
> VCSCommitDiffPatchSource::VCSCommitDiffPatchSource(VCSDiffUpdater* updater)
>      : VCSDiffPatchSource(updater), m_vcs(updater->vcs())
> 
>  {
>      Q_ASSERT(m_vcs);
> -    m_base = updater->url();
> -
>      m_commitMessageWidget = new QWidget;
>      QVBoxLayout* layout = new QVBoxLayout(m_commitMessageWidget.data());
> 
>      m_commitMessageEdit = new KTextEdit;
>      m_commitMessageEdit.data()->setFont( KGlobalSettings::fixedFont() );
>      m_commitMessageEdit.data()->setLineWrapMode(QTextEdit::NoWrap);
> -    m_vcs->setupCommitMessageEditor(m_base, m_commitMessageEdit.data());
> +    m_vcs->setupCommitMessageEditor(updater->url(),
> m_commitMessageEdit.data());
> 
>      QHBoxLayout* titleLayout = new QHBoxLayout;
>      titleLayout->addWidget(new QLabel(i18n("Commit Message:")));
> @@ -172,10 +170,11 @@ void VCSDiffPatchSource::updateFromDiff(VcsDiff
> vcsdiff) t2 << vcsdiff.diff();
>      }
> 
> -    kDebug() << "using file" << m_file << vcsdiff.diff();
> +    kDebug() << "using file" << m_file << vcsdiff.diff() << "base" <<
> vcsdiff.baseDiff();
> 
>      m_name = "VCS Diff";
>      m_base = vcsdiff.baseDiff();
> +    m_base.addPath("/");
> 
>      emit patchChanged();
>  }
-- 
Milian Wolff
mail at milianw.de
http://milianw.de
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 198 bytes
Desc: This is a digitally signed message part.
URL: <http://mail.kde.org/pipermail/kdevelop-devel/attachments/20121101/1cc1188a/attachment.sig>


More information about the KDevelop-devel mailing list