• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdesdk API Reference
  • KDE Home
  • Contact Us
 

kompare

  • sources
  • kde-4.14
  • kdesdk
  • kompare
  • komparenavtreepart
komparenavtreepart.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  KompareNavTreePart.cpp
3  ----------------------
4  begin : Sun Mar 4 2001
5  Copyright 2001-2005,2009 Otto Bruggeman <bruggie@gmail.com>
6  Copyright 2001-2003 John Firebaugh <jfirebaugh@kde.org>
7  Copyright 2007-2011 Kevin Kofler <kevin.kofler@chello.at>
8 ****************************************************************************/
9 
10 /***************************************************************************
11 **
12 ** This program is free software; you can redistribute it and/or modify
13 ** it under the terms of the GNU General Public License as published by
14 ** the Free Software Foundation; either version 2 of the License, or
15 ** (at your option) any later version.
16 **
17 ***************************************************************************/
18 
19 #include "komparenavtreepart.h"
20 
21 #include <QtGui/QTreeWidgetItemIterator>
22 
23 #include <kdebug.h>
24 #include <klocale.h>
25 #include <kiconloader.h>
26 #include <kmimetype.h>
27 #include <kaboutdata.h>
28 #include <kcomponentdata.h>
29 #include <kpluginfactory.h>
30 
31 #include "difference.h"
32 #include "diffmodel.h"
33 #include "diffmodellist.h"
34 #include "komparemodellist.h"
35 
36 #define COL_SOURCE 0
37 #define COL_DESTINATION 1
38 #define COL_DIFFERENCE 2
39 
40 using namespace Diff2;
41 
42 KompareNavTreePart::KompareNavTreePart( QWidget* parentWidget, QObject* parent, const QVariantList& )
43  : KParts::ReadOnlyPart( parent ),
44  m_splitter( 0 ),
45  m_modelList( 0 ),
46  m_srcDirTree( 0 ),
47  m_destDirTree( 0 ),
48  m_fileList( 0 ),
49  m_changesList( 0 ),
50  m_srcRootItem( 0 ),
51  m_destRootItem( 0 ),
52  m_selectedModel( 0 ),
53  m_selectedDifference( 0 ),
54  m_source( "" ),
55  m_destination( "" ),
56  m_info( 0 )
57 {
58  m_splitter = new QSplitter( Qt::Horizontal, parentWidget );
59 
60  setWidget( m_splitter );
61 
62  m_srcDirTree = new QTreeWidget( m_splitter );
63  m_srcDirTree->setHeaderLabel( i18n("Source Folder") );
64  m_srcDirTree->setRootIsDecorated( false );
65  m_srcDirTree->setSortingEnabled( true );
66  m_srcDirTree->sortByColumn( 0, Qt::AscendingOrder );
67 
68  m_destDirTree = new QTreeWidget( m_splitter );
69  m_destDirTree->setHeaderLabel( i18n("Destination Folder") );
70  m_destDirTree->setRootIsDecorated( false );
71  m_destDirTree->setSortingEnabled( true );
72  m_destDirTree->sortByColumn( 0, Qt::AscendingOrder );
73 
74  m_fileList = new QTreeWidget( m_splitter );
75  m_fileList->setHeaderLabels( QStringList() << i18n("Source File") << i18n("Destination File") );
76  m_fileList->setAllColumnsShowFocus( true );
77  m_fileList->setRootIsDecorated( false );
78  m_fileList->setSortingEnabled( true );
79  m_fileList->sortByColumn( 0, Qt::AscendingOrder );
80 
81  m_changesList = new QTreeWidget( m_splitter );
82  m_changesList->setHeaderLabels( QStringList() << i18n("Source Line") << i18n("Destination Line") << i18n("Difference") );
83  m_changesList->setAllColumnsShowFocus( true );
84  m_changesList->setRootIsDecorated( false );
85  m_changesList->setSortingEnabled( true );
86  m_changesList->sortByColumn( 0, Qt::AscendingOrder );
87 
88  connect( m_srcDirTree, SIGNAL(currentItemChanged( QTreeWidgetItem*, QTreeWidgetItem* )),
89  this, SLOT(slotSrcDirTreeSelectionChanged( QTreeWidgetItem* )) );
90  connect( m_destDirTree, SIGNAL(currentItemChanged( QTreeWidgetItem*, QTreeWidgetItem* )),
91  this, SLOT(slotDestDirTreeSelectionChanged( QTreeWidgetItem* )) );
92  connect( m_fileList, SIGNAL(currentItemChanged( QTreeWidgetItem*, QTreeWidgetItem* )),
93  this, SLOT(slotFileListSelectionChanged( QTreeWidgetItem* )) );
94  connect( m_changesList, SIGNAL(currentItemChanged( QTreeWidgetItem*, QTreeWidgetItem* )),
95  this, SLOT(slotChangesListSelectionChanged( QTreeWidgetItem* )) );
96 }
97 
98 KompareNavTreePart::~KompareNavTreePart()
99 {
100  m_modelList = 0;
101  m_selectedModel = 0;
102  m_selectedDifference = 0;
103 }
104 
105 void KompareNavTreePart::slotKompareInfo( struct Kompare::Info* info )
106 {
107  m_info = info;
108 }
109 
110 void KompareNavTreePart::slotModelsChanged( const DiffModelList* modelList )
111 {
112  kDebug(8105) << "Models (" << modelList << ") have changed... scanning the models... " << endl;
113 
114  if ( modelList )
115  {
116  m_modelList = modelList;
117  m_srcDirTree->clear();
118  m_destDirTree->clear();
119  m_fileList->clear();
120  m_changesList->clear();
121  buildTreeInMemory();
122  }
123  else
124  {
125  m_modelList = modelList;
126  m_srcDirTree->clear();
127  m_destDirTree->clear();
128  m_fileList->clear();
129  m_changesList->clear();
130  }
131 }
132 
133 void KompareNavTreePart::buildTreeInMemory()
134 {
135  kDebug(8105) << "BuildTreeInMemory called" << endl;
136 
137  if ( m_modelList->count() == 0 )
138  {
139  kDebug(8105) << "No models... weird shit..." << endl;
140  return; // avoids a crash on clear()
141  }
142 
143  if ( m_info == 0 )
144  {
145  kDebug(8105) << "No Info... weird shit..." << endl;
146  return;
147  }
148 
149  QString srcBase;
150  QString destBase;
151 
152  DiffModel* model;
153  model = m_modelList->first();
154  m_selectedModel = 0L;
155 
156  switch ( m_info->mode )
157  {
158  case Kompare::ShowingDiff:
159  // BUG: 107489 No common root because it is a multi directory relative path diff
160  // We need to detect this and create a different rootitem / or so or should we always add this?
161  // Trouble we run into is that the directories do not start with a /
162  // so we have an unknown top root dir
163  // Thinking some more about it i guess it is best to use "" as base and simply show some string
164  // like Unknown filesystem path as root text but only in the case of dirs starting without a /
165  srcBase = model->sourcePath();
166  destBase = model->destinationPath();
167  // FIXME: these tests will not work on windows, we need something else
168  if ( srcBase[0] != '/' )
169  srcBase = "";
170  if ( destBase[0] != '/' )
171  destBase = "";
172  break;
173  case Kompare::ComparingFiles:
174  srcBase = model->sourcePath();
175  destBase = model->destinationPath();
176  break;
177  case Kompare::ComparingDirs:
178  srcBase = m_info->localSource;
179  if ( !srcBase.endsWith( '/' ) )
180  srcBase += '/';
181  destBase = m_info->localDestination;
182  if ( !destBase.endsWith( '/' ) )
183  destBase += '/';
184  break;
185  case Kompare::BlendingFile:
186  case Kompare::BlendingDir:
187  default:
188  kDebug(8105) << "Oops needs to implement this..." << endl;
189  }
190 
191 // kDebug(8105) << "srcBase = " << srcBase << endl;
192 // kDebug(8105) << "destBase = " << destBase << endl;
193 
194  m_srcRootItem = new KDirLVI( m_srcDirTree, srcBase );
195  m_destRootItem = new KDirLVI( m_destDirTree, destBase );
196 
197  QString srcPath;
198  QString destPath;
199 
200  // Create the tree from the models
201  DiffModelListConstIterator modelIt = m_modelList->begin();
202  DiffModelListConstIterator mEnd = m_modelList->end();
203 
204  for ( ; modelIt != mEnd; ++modelIt )
205  {
206  model = *modelIt;
207  srcPath = model->sourcePath();
208  destPath = model->destinationPath();
209 
210  kDebug(8105) << "srcPath = " << srcPath << endl;
211  kDebug(8105) << "destPath = " << destPath << endl;
212  m_srcRootItem->addModel( srcPath, model, &m_modelToSrcDirItemDict );
213  m_destRootItem->addModel( destPath, model, &m_modelToDestDirItemDict );
214  }
215 // m_srcDirTree->setSelected( m_srcDirTree->firstChild(), true );
216 }
217 
218 void KompareNavTreePart::buildDirectoryTree()
219 {
220 // FIXME: afaict this can be deleted
221 // kDebug(8105) << "BuildDirTree called" << endl;
222 }
223 
224 QString KompareNavTreePart::compareFromEndAndReturnSame(
225  const QString& string1,
226  const QString& string2 )
227 {
228  QString result;
229 
230  int srcLen = string1.length();
231  int destLen = string2.length();
232 
233  while ( srcLen != 0 && destLen != 0 )
234  {
235  if ( string1[--srcLen] == string2[--destLen] )
236  result.prepend( string1[srcLen] );
237  else
238  break;
239  }
240 
241  if ( srcLen != 0 && destLen != 0 && result.startsWith( '/' ) )
242  result = result.remove( 0, 1 ); // strip leading /, we need it later
243 
244  return result;
245 }
246 
247 void KompareNavTreePart::slotSetSelection( const DiffModel* model, const Difference* diff )
248 {
249  kDebug(8105) << "KompareNavTreePart::slotSetSelection model = " << model << ", diff = " << diff << endl;
250  if ( model == m_selectedModel )
251  {
252  // model is the same, so no need to update that...
253  if ( diff != m_selectedDifference )
254  {
255  m_selectedDifference = diff;
256  setSelectedDifference( diff );
257  }
258  return;
259  }
260 
261  // model is different so we need to find the right dirs, file and changeitems to select
262  // if m_selectedModel == NULL then everything needs to be done as well
263  if ( !m_selectedModel || model->sourcePath() != m_selectedModel->sourcePath() )
264  { // dirs are different, so we need to update the dirviews as well
265  m_selectedModel = model;
266  m_selectedDifference = diff;
267 
268  setSelectedDir( model );
269  setSelectedFile( model );
270  setSelectedDifference( diff );
271  return;
272  }
273 
274  if ( !m_selectedModel || model->sourceFile() != m_selectedModel->sourceFile() )
275  {
276  m_selectedModel = model;
277  setSelectedFile( model );
278 
279  m_selectedDifference = diff;
280  setSelectedDifference( diff );
281  }
282 }
283 
284 void KompareNavTreePart::setSelectedDir( const DiffModel* model )
285 {
286  KDirLVI* currentDir;
287  currentDir = m_modelToSrcDirItemDict[ model ];
288  kDebug(8105) << "Manually setting selection in srcdirtree with currentDir = " << currentDir << endl;
289  m_srcDirTree->blockSignals( true );
290  m_srcDirTree->setCurrentItem( currentDir );
291  m_srcDirTree->scrollToItem( currentDir );
292  m_srcDirTree->blockSignals( false );
293 
294  currentDir = m_modelToDestDirItemDict[ model ];
295  kDebug(8105) << "Manually setting selection in destdirtree with currentDir = " << currentDir << endl;
296  m_destDirTree->blockSignals( true );
297  m_destDirTree->setCurrentItem( currentDir );
298  m_destDirTree->scrollToItem( currentDir );
299  m_destDirTree->blockSignals( false );
300 
301  m_fileList->blockSignals( true );
302  currentDir->fillFileList( m_fileList, &m_modelToFileItemDict );
303  m_fileList->blockSignals( false );
304 }
305 
306 void KompareNavTreePart::setSelectedFile( const DiffModel* model )
307 {
308  KFileLVI* currentFile;
309  currentFile = m_modelToFileItemDict[ model ];
310  kDebug(8105) << "Manually setting selection in filelist" << endl;
311  m_fileList->blockSignals( true );
312  m_fileList->setCurrentItem( currentFile );
313  m_fileList->scrollToItem( currentFile );
314  m_fileList->blockSignals( false );
315 
316  m_changesList->blockSignals( true );
317  currentFile->fillChangesList( m_changesList, &m_diffToChangeItemDict );
318  m_changesList->blockSignals( false );
319 }
320 
321 void KompareNavTreePart::setSelectedDifference( const Difference* diff )
322 {
323  KChangeLVI* currentDiff;
324  currentDiff = m_diffToChangeItemDict[ diff ];
325  kDebug(8105) << "Manually setting selection in changeslist to " << currentDiff << endl;
326  m_changesList->blockSignals( true );
327  m_changesList->setCurrentItem( currentDiff );
328  m_changesList->scrollToItem( currentDiff );
329  m_changesList->blockSignals( false );
330 }
331 
332 void KompareNavTreePart::slotSetSelection( const Difference* diff )
333 {
334 // kDebug(8105) << "Scotty i need more power !!" << endl;
335  if ( m_selectedDifference != diff )
336  {
337 // kDebug(8105) << "But sir, i am giving you all she's got" << endl;
338  m_selectedDifference = diff;
339  setSelectedDifference( diff );
340  }
341 }
342 
343 void KompareNavTreePart::slotSrcDirTreeSelectionChanged( QTreeWidgetItem* item )
344 {
345  if (!item)
346  return;
347 
348  kDebug(8105) << "Sent by the sourceDirectoryTree with item = " << item << endl;
349  m_srcDirTree->scrollToItem( item );
350  KDirLVI* dir = static_cast<KDirLVI*>(item);
351  // order the dest tree view to set its selected item to the same as here
352  QString path;
353  // We start with an empty path and after the call path contains the full path
354  path = dir->fullPath( path );
355  KDirLVI* selItem = m_destRootItem->setSelected( path );
356  m_destDirTree->blockSignals( true );
357  m_destDirTree->setCurrentItem( selItem );
358  m_destDirTree->scrollToItem( selItem );
359  m_destDirTree->blockSignals( false );
360  // fill the changes list
361  dir->fillFileList( m_fileList, &m_modelToFileItemDict );
362 }
363 
364 void KompareNavTreePart::slotDestDirTreeSelectionChanged( QTreeWidgetItem* item )
365 {
366  if (!item)
367  return;
368 
369  kDebug(8105) << "Sent by the destinationDirectoryTree with item = " << item << endl;
370  m_destDirTree->scrollToItem( item );
371  KDirLVI* dir = static_cast<KDirLVI*>(item);
372  // order the src tree view to set its selected item to the same as here
373  QString path;
374  // We start with an empty path and after the call path contains the full path
375  path = dir->fullPath( path );
376  KDirLVI* selItem = m_srcRootItem->setSelected( path );
377  m_srcDirTree->blockSignals( true );
378  m_srcDirTree->setCurrentItem( selItem );
379  m_srcDirTree->scrollToItem( selItem );
380  m_srcDirTree->blockSignals( false );
381  // fill the changes list
382  dir->fillFileList( m_fileList, &m_modelToFileItemDict );
383 }
384 
385 void KompareNavTreePart::slotFileListSelectionChanged( QTreeWidgetItem* item )
386 {
387  if (!item)
388  return;
389 
390  kDebug(8105) << "Sent by the fileList with item = " << item << endl;
391 
392  KFileLVI* file = static_cast<KFileLVI*>(item);
393  m_selectedModel = file->model();
394  m_changesList->blockSignals( true );
395  file->fillChangesList( m_changesList, &m_diffToChangeItemDict );
396  m_changesList->blockSignals( false );
397 
398  if ( m_changesList->currentItem() )
399  {
400  // FIXME: This is ugly...
401  m_selectedDifference = (static_cast<KChangeLVI*>(m_changesList->currentItem()))->difference();
402  }
403 
404  emit selectionChanged( m_selectedModel, m_selectedDifference );
405 }
406 
407 void KompareNavTreePart::slotChangesListSelectionChanged( QTreeWidgetItem* item )
408 {
409  if (!item)
410  return;
411 
412  kDebug(8105) << "Sent by the changesList" << endl;
413 
414  KChangeLVI* change = static_cast<KChangeLVI*>(item);
415  m_selectedDifference = change->difference();
416 
417  emit selectionChanged( m_selectedDifference );
418 }
419 
420 void KompareNavTreePart::slotApplyDifference( bool /*apply*/ )
421 {
422  KChangeLVI* clvi = m_diffToChangeItemDict[m_selectedDifference];
423  if ( clvi )
424  clvi->setDifferenceText();
425 }
426 
427 void KompareNavTreePart::slotApplyAllDifferences( bool /*apply*/ )
428 {
429  QHash<const Diff2::Difference*, KChangeLVI*>::ConstIterator it = m_diffToChangeItemDict.constBegin();
430  QHash<const Diff2::Difference*, KChangeLVI*>::ConstIterator end = m_diffToChangeItemDict.constEnd();
431 
432  kDebug(8105) << "m_diffToChangeItemDict.count() = " << m_diffToChangeItemDict.count() << endl;
433 
434  for ( ; it != end ; ++it )
435  {
436  it.value()->setDifferenceText();
437  }
438 }
439 
440 void KompareNavTreePart::slotApplyDifference( const Difference* diff, bool /*apply*/ )
441 {
442  // this applies to the currently selected difference
443  KChangeLVI* clvi = m_diffToChangeItemDict[diff];
444  if ( clvi )
445  clvi->setDifferenceText();
446 }
447 
448 void KChangeLVI::setDifferenceText()
449 {
450  QString text;
451  switch( m_difference->type() ) {
452  case Difference::Change:
453  // Shouldn't this simply be diff->sourceLineCount() ?
454  // because you change the _number of lines_ lines in source, not in dest
455  if( m_difference->applied() )
456  text = i18np( "Applied: Changes made to %1 line undone", "Applied: Changes made to %1 lines undone",
457  m_difference->sourceLineCount() );
458  else
459  text = i18np( "Changed %1 line", "Changed %1 lines",
460  m_difference->sourceLineCount() );
461  break;
462  case Difference::Insert:
463  if( m_difference->applied() )
464  text = i18np( "Applied: Insertion of %1 line undone", "Applied: Insertion of %1 lines undone",
465  m_difference->destinationLineCount() );
466  else
467  text = i18np( "Inserted %1 line", "Inserted %1 lines",
468  m_difference->destinationLineCount() );
469  break;
470  case Difference::Delete:
471  if( m_difference->applied() )
472  text = i18np( "Applied: Deletion of %1 line undone", "Applied: Deletion of %1 lines undone",
473  m_difference->sourceLineCount() );
474  else
475  text = i18np( "Deleted %1 line", "Deleted %1 lines",
476  m_difference->sourceLineCount() );
477  break;
478  default:
479  kDebug(8105) << "Unknown or Unchanged enum value when checking for diff->type() in KChangeLVI's constructor" << endl;
480  text = "";
481  }
482 
483  setText( 2, text );
484 }
485 
486 KChangeLVI::KChangeLVI( QTreeWidget* parent, Difference* diff ) : QTreeWidgetItem( parent )
487 {
488  m_difference = diff;
489 
490  setText( 0, QString::number( diff->sourceLineNumber() ) );
491  setText( 1, QString::number( diff->destinationLineNumber() ) );
492 
493  setDifferenceText();
494 }
495 
496 bool KChangeLVI::operator<( const QTreeWidgetItem& item ) const
497 {
498  int column = treeWidget()->sortColumn();
499  QString text1 = text(column);
500  QString text2 = item.text(column);
501 
502  // Compare the numbers.
503  if (column < 2 && text1.length() != text2.length())
504  return text1.length() < text2.length();
505  return text1 < text2;
506 }
507 
508 KChangeLVI::~KChangeLVI()
509 {
510 }
511 
512 KFileLVI::KFileLVI( QTreeWidget* parent, DiffModel* model ) : QTreeWidgetItem( parent )
513 {
514  m_model = model;
515 
516  QString src = model->sourceFile();
517  QString dst = model->destinationFile();
518 
519  setText( 0, src );
520  setText( 1, dst );
521  setIcon( 0, SmallIcon( getIcon( src ) ) );
522  setIcon( 1, SmallIcon( getIcon( dst ) ) );
523 }
524 
525 bool KFileLVI::hasExtension(const QString& extensions, const QString& fileName)
526 {
527  QStringList extList = extensions.split(' ');
528  foreach (const QString &ext, extList) {
529  if ( fileName.endsWith(ext, Qt::CaseInsensitive) ) {
530  return true;
531  }
532  }
533  return false;
534 }
535 
536 const QString KFileLVI::getIcon(const QString& fileName)
537 {
538  // C++, C
539  if ( hasExtension( ".h .hpp", fileName ) ) {
540  return "text-x-c++hdr";
541  }
542  if ( hasExtension( ".cpp", fileName ) ) {
543  return "text-x-c++src";
544  }
545  if ( hasExtension( ".c", fileName ) ) {
546  return "text-x-csrc";
547  }
548  // Python
549  if ( hasExtension( ".py .pyw", fileName ) ) {
550  return "text-x-python";
551  }
552  // C#
553  if ( hasExtension( ".cs", fileName ) ) {
554  return "text-x-csharp";
555  }
556  // Objective-C
557  if ( hasExtension( ".m", fileName ) ) {
558  return "text-x-objcsrc";
559  }
560  // Java
561  if ( hasExtension( ".java", fileName ) ) {
562  return "text-x-java";
563  }
564  // Script
565  if ( hasExtension( ".sh", fileName ) ) {
566  return "text-x-script";
567  }
568  // Makefile
569  if ( hasExtension( ".cmake Makefile", fileName ) ) {
570  return "text-x-makefile";
571  }
572  // Ada
573  if ( hasExtension( ".ada .ads .adb", fileName ) ) {
574  return "text-x-adasrc";
575  }
576  // Pascal
577  if ( hasExtension( ".pas", fileName ) ) {
578  return "text-x-pascal";
579  }
580  // Patch
581  if ( hasExtension( ".diff", fileName ) ) {
582  return "text-x-patch";
583  }
584  // Tcl
585  if ( hasExtension( ".tcl", fileName ) ) {
586  return "text-x-tcl";
587  }
588  // Text
589  if ( hasExtension( ".txt", fileName ) ) {
590  return "text-plain";
591  }
592  // Xml
593  if ( hasExtension( ".xml", fileName ) ) {
594  return "text-xml";
595  }
596  // unknown or no file extension
597  return "text-plain";
598 }
599 
600 void KFileLVI::fillChangesList( QTreeWidget* changesList, QHash<const Diff2::Difference*, KChangeLVI*>* diffToChangeItemDict )
601 {
602  changesList->clear();
603  diffToChangeItemDict->clear();
604 
605  DifferenceListConstIterator diffIt = m_model->differences()->constBegin();
606  DifferenceListConstIterator dEnd = m_model->differences()->constEnd();
607 
608  for ( ; diffIt != dEnd; ++diffIt )
609  {
610  KChangeLVI* change = new KChangeLVI( changesList, *diffIt );
611  diffToChangeItemDict->insert( *diffIt, change );
612  }
613 
614  changesList->setCurrentItem( changesList->topLevelItem( 0 ) );
615 }
616 
617 KFileLVI::~KFileLVI()
618 {
619 }
620 
621 KDirLVI::KDirLVI( QTreeWidget* parent, QString& dir ) : QTreeWidgetItem( parent )
622 {
623 // kDebug(8105) << "KDirLVI (QTreeWidget) constructor called with dir = " << dir << endl;
624  m_rootItem = true;
625  m_dirName = dir;
626  setIcon( 0, SmallIcon( "folder" ) );
627  setExpanded( true );
628  if ( m_dirName.isEmpty() )
629  setText( 0, i18n( "Unknown" ) );
630  else
631  setText( 0, m_dirName );
632 }
633 
634 KDirLVI::KDirLVI( KDirLVI* parent, QString& dir ) : QTreeWidgetItem( parent )
635 {
636 // kDebug(8105) << "KDirLVI (KDirLVI) constructor called with dir = " << dir << endl;
637  m_rootItem = false;
638  m_dirName = dir;
639  setIcon( 0, SmallIcon( "folder" ) );
640  setExpanded( true );
641  setText( 0, m_dirName );
642 }
643 
644 // addModel always removes it own path from the beginning
645 void KDirLVI::addModel( QString& path, DiffModel* model, QHash<const Diff2::DiffModel*, KDirLVI*>* modelToDirItemDict )
646 {
647 // kDebug(8105) << "KDirLVI::addModel called with path = " << path << " from KDirLVI with m_dirName = " << m_dirName << endl;
648 
649  if ( !m_dirName.isEmpty() )
650  {
651  if ( path.indexOf( m_dirName ) > -1 )
652  path = path.remove( path.indexOf( m_dirName ), m_dirName.length() );
653  }
654 
655 // kDebug(8105) << "Path after removal of own dir (\"" << m_dirName << "\") = " << path << endl;
656 
657  if ( path.isEmpty() ) {
658  m_modelList.append( model );
659  modelToDirItemDict->insert( model, this );
660  return;
661  }
662 
663  KDirLVI* child;
664 
665  QString dir = path.mid( 0, path.indexOf( "/", 0 ) + 1 );
666  child = findChild( dir );
667  if ( !child )
668  {
669  // does not exist yet so make it
670 // kDebug(8105) << "KDirLVI::addModel creating new KDirLVI because not found" << endl;
671  child = new KDirLVI( this, dir );
672  }
673 
674  child->addModel( path, model, modelToDirItemDict );
675 }
676 
677 KDirLVI* KDirLVI::findChild( QString dir )
678 {
679 // kDebug(8105) << "KDirLVI::findChild called with dir = " << dir << endl;
680  KDirLVI* child;
681  if ( ( child = static_cast<KDirLVI*>(this->child(0)) ) != 0L )
682  { // has children, check if dir already exists, if so addModel
683  QTreeWidgetItemIterator it(child);
684  while (*it) {
685  child = static_cast<KDirLVI*>(*it);
686 
687  if ( dir == child->dirName() )
688  return child;
689  ++it;
690  }
691  }
692 
693  return 0L;
694 }
695 
696 void KDirLVI::fillFileList( QTreeWidget* fileList, QHash<const Diff2::DiffModel*, KFileLVI*>* modelToFileItemDict )
697 {
698  fileList->clear();
699 
700  DiffModelListIterator modelIt = m_modelList.begin();
701  DiffModelListIterator mEnd = m_modelList.end();
702  for ( ;modelIt != mEnd; ++modelIt )
703  {
704  KFileLVI* file = new KFileLVI( fileList, *modelIt );
705  modelToFileItemDict->insert( *modelIt, file );
706  }
707 
708  fileList->setCurrentItem( fileList->topLevelItem( 0 ) );
709 }
710 
711 QString KDirLVI::fullPath( QString& path )
712 {
713 // if ( !path.isEmpty() )
714 // kDebug(8105) << "KDirLVI::fullPath called with path = " << path << endl;
715 // else
716 // kDebug(8105) << "KDirLVI::fullPath called with empty path..." << endl;
717 
718  if ( m_rootItem ) // don't bother adding rootItem's dir...
719  return path;
720 
721  path = path.prepend( m_dirName );
722 
723  KDirLVI* lviParent = dynamic_cast<KDirLVI*>( parent() );
724  if ( lviParent )
725  {
726  path = lviParent->fullPath( path );
727  }
728 
729  return path;
730 }
731 
732 KDirLVI* KDirLVI::setSelected( QString dir )
733 {
734 // kDebug(8105) << "KDirLVI::setSelected called with dir = " << dir << endl;
735 
736  // root item's dirName is never taken into account... remember that
737  if ( !m_rootItem )
738  {
739  dir = dir.remove( 0, m_dirName.length() );
740  }
741 
742  if ( dir.isEmpty() )
743  {
744  return this;
745  }
746  KDirLVI* child = static_cast<KDirLVI*>(this->child(0));
747  if ( !child )
748  return 0L;
749 
750  QTreeWidgetItemIterator it(child);
751  while (*it) {
752  child = static_cast<KDirLVI*>(*it);
753 
754  if ( dir.startsWith( child->dirName() ) )
755  return child->setSelected( dir );
756  ++it;
757  }
758 
759  return 0L;
760 }
761 
762 KDirLVI::~KDirLVI()
763 {
764  m_modelList.clear();
765 }
766 
767 static KAboutData aboutData()
768 {
769  KAboutData about("komparenavtreepart", 0, ki18n("KompareNavTreePart"), "1.2");
770  about.addAuthor(ki18n("John Firebaugh"), ki18n("Author"), "jfirebaugh@kde.org");
771  about.addAuthor(ki18n("Otto Bruggeman"), ki18n("Author"), "bruggie@gmail.com" );
772  return about;
773 }
774 
775 K_PLUGIN_FACTORY(KompareNavTreePartFactory,
776  registerPlugin<KompareNavTreePart>();
777  )
778 K_EXPORT_PLUGIN( KompareNavTreePartFactory(aboutData()) )
779 
780 #include "komparenavtreepart.moc"
KDirLVI::fillFileList
void fillFileList(QTreeWidget *fileList, QHash< const Diff2::DiffModel *, KFileLVI * > *modelToFileItemDict)
Definition: komparenavtreepart.cpp:696
KChangeLVI::operator<
virtual bool operator<(const QTreeWidgetItem &item) const
Definition: komparenavtreepart.cpp:496
QString::indexOf
int indexOf(QChar ch, int from, Qt::CaseSensitivity cs) const
KDirLVI::fullPath
QString fullPath(QString &path)
Definition: komparenavtreepart.cpp:711
QWidget
QHash::insert
iterator insert(const Key &key, const T &value)
KChangeLVI::~KChangeLVI
~KChangeLVI()
Definition: komparenavtreepart.cpp:508
QTreeWidget::sortColumn
int sortColumn() const
KDirLVI
Definition: komparenavtreepart.h:144
QTreeWidgetItem::child
QTreeWidgetItem * child(int index) const
QTreeWidget::scrollToItem
void scrollToItem(const QTreeWidgetItem *item, QAbstractItemView::ScrollHint hint)
KompareNavTreePart::KompareNavTreePart
KompareNavTreePart(QWidget *parentWidget, QObject *parent, const QVariantList &args)
Definition: komparenavtreepart.cpp:42
QString::split
QStringList split(const QString &sep, SplitBehavior behavior, Qt::CaseSensitivity cs) const
QString::prepend
QString & prepend(QChar ch)
KFileLVI
Definition: komparenavtreepart.h:129
QTreeWidgetItemIterator
QTreeWidgetItem::setIcon
void setIcon(int column, const QIcon &icon)
KDirLVI::~KDirLVI
~KDirLVI()
Definition: komparenavtreepart.cpp:762
QTreeView::sortByColumn
void sortByColumn(int column, Qt::SortOrder order)
QString::remove
QString & remove(int position, int n)
QHash::count
int count(const Key &key) const
KChangeLVI::setDifferenceText
void setDifferenceText()
Definition: komparenavtreepart.cpp:448
QTreeWidget::clear
void clear()
QTreeWidget
KompareNavTreePart::selectionChanged
void selectionChanged(const Diff2::DiffModel *model, const Diff2::Difference *diff)
QString::number
QString number(int n, int base)
KFileLVI::KFileLVI
KFileLVI(QTreeWidget *parent, Diff2::DiffModel *model)
Definition: komparenavtreepart.cpp:512
QHash::constEnd
const_iterator constEnd() const
QHash
QObject
QString::isEmpty
bool isEmpty() const
KFileLVI::model
Diff2::DiffModel * model()
Definition: komparenavtreepart.h:135
QString::startsWith
bool startsWith(const QString &s, Qt::CaseSensitivity cs) const
KFileLVI::~KFileLVI
~KFileLVI()
Definition: komparenavtreepart.cpp:617
QString::endsWith
bool endsWith(const QString &s, Qt::CaseSensitivity cs) const
KDirLVI::addModel
void addModel(QString &dir, Diff2::DiffModel *model, QHash< const Diff2::DiffModel *, KDirLVI * > *modelToDirItemDict)
Definition: komparenavtreepart.cpp:645
QTreeView::setAllColumnsShowFocus
void setAllColumnsShowFocus(bool enable)
QTreeWidget::currentItem
QTreeWidgetItem * currentItem() const
QString
QTreeWidgetItem::treeWidget
QTreeWidget * treeWidget() const
QStringList
KompareNavTreePart::slotKompareInfo
void slotKompareInfo(Kompare::Info *info)
Definition: komparenavtreepart.cpp:105
QHash::clear
void clear()
QHash::value
const T value(const Key &key) const
KompareNavTreePart::slotModelsChanged
void slotModelsChanged(const Diff2::DiffModelList *modelList)
Definition: komparenavtreepart.cpp:110
QObject::blockSignals
bool blockSignals(bool block)
KDirLVI::dirName
QString & dirName()
Definition: komparenavtreepart.h:152
QTreeWidgetItem::parent
QTreeWidgetItem * parent() const
QTreeWidget::setCurrentItem
void setCurrentItem(QTreeWidgetItem *item)
QTreeWidget::setHeaderLabels
void setHeaderLabels(const QStringList &labels)
KFileLVI::fillChangesList
void fillChangesList(QTreeWidget *changesList, QHash< const Diff2::Difference *, KChangeLVI * > *diffToChangeItemDict)
Definition: komparenavtreepart.cpp:600
QTreeWidget::setHeaderLabel
void setHeaderLabel(const QString &label)
QHash::constBegin
const_iterator constBegin() const
QSplitter
QTreeView::setSortingEnabled
void setSortingEnabled(bool enable)
QTreeWidgetItem::setExpanded
void setExpanded(bool expand)
QString::mid
QString mid(int position, int n) const
KDirLVI::KDirLVI
KDirLVI(KDirLVI *parent, QString &dir)
Definition: komparenavtreepart.cpp:634
QTreeWidgetItem
KompareNavTreePart::slotSetSelection
void slotSetSelection(const Diff2::DiffModel *model, const Diff2::Difference *diff)
aboutData
static KAboutData aboutData()
Definition: komparenavtreepart.cpp:767
KompareNavTreePart::~KompareNavTreePart
virtual ~KompareNavTreePart()
Definition: komparenavtreepart.cpp:98
komparenavtreepart.h
QTreeWidgetItem::setText
void setText(int column, const QString &text)
QString::length
int length() const
QTreeWidget::topLevelItem
QTreeWidgetItem * topLevelItem(int index) const
QTreeView::setRootIsDecorated
void setRootIsDecorated(bool show)
KChangeLVI::KChangeLVI
KChangeLVI(QTreeWidget *parent, Diff2::Difference *diff)
Definition: komparenavtreepart.cpp:486
KChangeLVI::difference
Diff2::Difference * difference()
Definition: komparenavtreepart.h:121
QTreeWidgetItem::text
QString text(int column) const
KDirLVI::setSelected
KDirLVI * setSelected(QString dir)
Definition: komparenavtreepart.cpp:732
KChangeLVI
Definition: komparenavtreepart.h:115
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:40:01 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

kompare

Skip menu "kompare"
  • Main Page
  • Namespace List
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members

kdesdk API Reference

Skip menu "kdesdk API Reference"
  • kapptemplate
  • kcachegrind
  • kompare
  • lokalize
  • umbrello
  •   umbrello

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal