KDE/kdesdk/kompare

Kevin Kofler kevin.kofler at chello.at
Mon Feb 15 22:05:29 CET 2010


SVN commit 1090720 by kkofler:

Patch to reduce Qt3Support usage by Jakub Wieczorek <faw217 at gmail.com>:
* use QHash instead of Q3PtrDict
* use QList instead of Q3ValueList
* remove copied BubbleSort implementation of DiffModelList::sort(), instead use qSort with a custom comparison function which ensures the correct ordering (by value, not by pointer address)
* remove some unused Qt3Support #includes
* fix a leftover reference to K3Process in a comment

CCMAIL: faw217 at gmail.com
CCMAIL: kompare-devel at kde.org

 M  +13 -12    komparenavtreepart/komparenavtreepart.cpp  
 M  +8 -9      komparenavtreepart/komparenavtreepart.h  
 M  +0 -1      komparepart/kompareconnectwidget.h  
 M  +8 -8      komparepart/komparelistview.cpp  
 M  +2 -2      komparepart/komparelistview.h  
 M  +6 -40     libdiff2/diffmodellist.cpp  
 M  +5 -5      libdiff2/diffmodellist.h  
 M  +1 -1      libdiff2/komparemodellist.h  
 M  +1 -1      libdiff2/kompareprocess.cpp  


--- trunk/KDE/kdesdk/kompare/komparenavtreepart/komparenavtreepart.cpp #1090719:1090720
@@ -282,14 +282,14 @@
 void KompareNavTreePart::setSelectedDir( const DiffModel* model )
 {
 	KDirLVI* currentDir;
-	currentDir = m_modelToSrcDirItemDict[ (void*)model ];
+	currentDir = m_modelToSrcDirItemDict[ model ];
 	kDebug(8105) << "Manually setting selection in srcdirtree with currentDir = " << currentDir << endl;
 	m_srcDirTree->blockSignals( true );
 	m_srcDirTree->setSelected( currentDir, true );
 	m_srcDirTree->ensureItemVisible( currentDir );
 	m_srcDirTree->blockSignals( false );
 
-	currentDir = m_modelToDestDirItemDict[ (void*)model ];
+	currentDir = m_modelToDestDirItemDict[ model ];
 	kDebug(8105) << "Manually setting selection in destdirtree with currentDir = " << currentDir << endl;
 	m_destDirTree->blockSignals( true );
 	m_destDirTree->setSelected( currentDir, true );
@@ -304,7 +304,7 @@
 void KompareNavTreePart::setSelectedFile( const DiffModel* model )
 {
 	KFileLVI* currentFile;
-	currentFile = m_modelToFileItemDict[ (void*)model ];
+	currentFile = m_modelToFileItemDict[ model ];
 	kDebug(8105) << "Manually setting selection in filelist" << endl;
 	m_fileList->blockSignals( true );
 	m_fileList->setSelected( currentFile, true );
@@ -319,7 +319,7 @@
 void KompareNavTreePart::setSelectedDifference( const Difference* diff )
 {
 	KChangeLVI* currentDiff;
-	currentDiff = m_diffToChangeItemDict[ (void*)diff ];
+	currentDiff = m_diffToChangeItemDict[ diff ];
 	kDebug(8105) << "Manually setting selection in changeslist to " << currentDiff << endl;
 	m_changesList->blockSignals( true );
 	m_changesList->setSelected( currentDiff, true );
@@ -405,27 +405,28 @@
 
 void KompareNavTreePart::slotApplyDifference( bool /*apply*/ )
 {
-	KChangeLVI* clvi = m_diffToChangeItemDict[(void*)m_selectedDifference];
+	KChangeLVI* clvi = m_diffToChangeItemDict[m_selectedDifference];
 	if ( clvi )
 		clvi->setDifferenceText();
 }
 
 void KompareNavTreePart::slotApplyAllDifferences( bool /*apply*/ )
 {
-	Q3PtrDictIterator<KChangeLVI> it( m_diffToChangeItemDict );
+	QHash<const Diff2::Difference*, KChangeLVI*>::ConstIterator it = m_diffToChangeItemDict.constBegin();
+	QHash<const Diff2::Difference*, KChangeLVI*>::ConstIterator end = m_diffToChangeItemDict.constEnd();
 
 	kDebug(8105) << "m_diffToChangeItemDict.count() = " << m_diffToChangeItemDict.count() << endl;
 
-	for ( ; it.current(); ++it )
+	for ( ; it != end ; ++it )
 	{
-		it.current()->setDifferenceText();
+		it.value()->setDifferenceText();
 	}
 }
 
 void KompareNavTreePart::slotApplyDifference( const Difference* diff, bool /*apply*/ )
 {
 	// this applies to the currently selected difference
-	KChangeLVI* clvi = m_diffToChangeItemDict[(void*)diff];
+	KChangeLVI* clvi = m_diffToChangeItemDict[diff];
 	if ( clvi )
 		clvi->setDifferenceText();
 }
@@ -591,7 +592,7 @@
 	return "text-plain";
 }
 
-void KFileLVI::fillChangesList( K3ListView* changesList, Q3PtrDict<KChangeLVI>* diffToChangeItemDict )
+void KFileLVI::fillChangesList( K3ListView* changesList, QHash<const Diff2::Difference*, KChangeLVI*>* diffToChangeItemDict )
 {
 	changesList->clear();
 	diffToChangeItemDict->clear();
@@ -638,7 +639,7 @@
 }
 
 // addModel always removes it own path from the beginning
-void KDirLVI::addModel( QString& path, DiffModel* model, Q3PtrDict<KDirLVI>* modelToDirItemDict )
+void KDirLVI::addModel( QString& path, DiffModel* model, QHash<const Diff2::DiffModel*, KDirLVI*>* modelToDirItemDict )
 {
 //	kDebug(8105) << "KDirLVI::addModel called with path = " << path << " from KDirLVI with m_dirName = " << m_dirName << endl;
 
@@ -685,7 +686,7 @@
 	return 0L;
 }
 
-void KDirLVI::fillFileList( K3ListView* fileList, Q3PtrDict<KFileLVI>* modelToFileItemDict )
+void KDirLVI::fillFileList( K3ListView* fileList, QHash<const Diff2::DiffModel*, KFileLVI*>* modelToFileItemDict )
 {
 	fileList->clear();
 
--- trunk/KDE/kdesdk/kompare/komparenavtreepart/komparenavtreepart.h #1090719:1090720
@@ -19,9 +19,8 @@
 #ifndef KOMPARENAVTREEPART_H
 #define KOMPARENAVTREEPART_H
 
-#include <q3ptrdict.h>
-#include <q3ptrlist.h>
 #include <QtGui/QSplitter>
+#include <QtCore/QHash>
 #include <q3listview.h>
 
 #include <k3listview.h>
@@ -96,10 +95,10 @@
 	QSplitter*                         m_splitter;
 	const Diff2::DiffModelList*        m_modelList;
 
-	Q3PtrDict<KChangeLVI>               m_diffToChangeItemDict;
-	Q3PtrDict<KFileLVI>                 m_modelToFileItemDict;
-	Q3PtrDict<KDirLVI>                  m_modelToSrcDirItemDict;
-	Q3PtrDict<KDirLVI>                  m_modelToDestDirItemDict;
+	QHash<const Diff2::Difference*, KChangeLVI*>	m_diffToChangeItemDict;
+	QHash<const Diff2::DiffModel*, KFileLVI*>       m_modelToFileItemDict;
+	QHash<const Diff2::DiffModel*, KDirLVI*>        m_modelToSrcDirItemDict;
+	QHash<const Diff2::DiffModel*, KDirLVI*>        m_modelToDestDirItemDict;
 
 	K3ListView*                         m_srcDirTree;
 	K3ListView*                         m_destDirTree;
@@ -142,7 +141,7 @@
 	~KFileLVI();
 public:
 	Diff2::DiffModel* model() { return m_model; };
-	void fillChangesList( K3ListView* changesList, Q3PtrDict<KChangeLVI>* diffToChangeItemDict );
+	void fillChangesList( K3ListView* changesList, QHash<const Diff2::Difference*, KChangeLVI*>* diffToChangeItemDict );
 private:
 	bool hasExtension(const QString& extensions, const QString& fileName);
 	const QString getIcon(const QString& fileName);
@@ -157,11 +156,11 @@
 	KDirLVI( K3ListView* parent, QString& dir );
 	~KDirLVI();
 public:
-	void addModel( QString& dir, Diff2::DiffModel* model, Q3PtrDict<KDirLVI>* modelToDirItemDict );
+	void addModel( QString& dir, Diff2::DiffModel* model, QHash<const Diff2::DiffModel*, KDirLVI*>* modelToDirItemDict );
 	QString& dirName() { return m_dirName; };
 	QString fullPath( QString& path );
 	KDirLVI* setSelected( QString dir );
-	void fillFileList( K3ListView* fileList, Q3PtrDict<KFileLVI>* modelToFileItemDict );
+	void fillFileList( K3ListView* fileList, QHash<const Diff2::DiffModel*, KFileLVI*>* modelToFileItemDict );
 	bool isRootItem() { return m_rootItem; };
 private:
 	KDirLVI* findChild( QString dir );
--- trunk/KDE/kdesdk/kompare/komparepart/kompareconnectwidget.h #1090719:1090720
@@ -22,7 +22,6 @@
 
 #include <QtGui/QWidget>
 #include <QtGui/QSplitter>
-#include <Q3PointArray>
 #include <QtGui/QPaintEvent>
 #include <QtGui/QMouseEvent>
 #include <QVBoxLayout>
--- trunk/KDE/kdesdk/kompare/komparepart/komparelistview.cpp #1090719:1090720
@@ -284,7 +284,7 @@
 
 	m_selectedDifference = diff;
 
-	KompareListViewItem* item = m_itemDict[ (void*)diff ];
+	KompareListViewItem* item = m_itemDict[ diff ];
 	if( !item ) {
 		kDebug(8104) << "KompareListView::slotSetSelection(): couldn't find our selection!" << endl;
 		return;
@@ -317,8 +317,6 @@
 	m_itemDict.clear();
 	m_selectedModel = model;
 
-	m_itemDict.resize(model->differenceCount());
-
 	DiffHunkListConstIterator hunkIt = model->hunks()->begin();
 	DiffHunkListConstIterator hEnd   = model->hunks()->end();
 
@@ -397,7 +395,7 @@
 
 void KompareListView::slotApplyDifference( bool apply )
 {
-	m_itemDict[ (void*)m_selectedDifference ]->applyDifference( apply );
+	m_itemDict[ m_selectedDifference ]->applyDifference( apply );
 	// now renumber the line column if this is the destination
 	if ( !m_isSource )
 		renumberLines();
@@ -405,9 +403,11 @@
 
 void KompareListView::slotApplyAllDifferences( bool apply )
 {
-	Q3PtrDictIterator<KompareListViewDiffItem> it ( m_itemDict );
-	for( ; it.current(); ++it )
-		it.current()->applyDifference( apply );
+	QHash<const Diff2::Difference*, KompareListViewDiffItem*>::ConstIterator it = m_itemDict.constBegin();
+	QHash<const Diff2::Difference*, KompareListViewDiffItem*>::ConstIterator end = m_itemDict.constEnd();
+	for ( ; it != end; ++it )
+		it.value()->applyDifference( apply );
+
 	// now renumber the line column if this is the destination
 	if ( !m_isSource )
 		renumberLines();
@@ -416,7 +416,7 @@
 
 void KompareListView::slotApplyDifference( const Difference* diff, bool apply )
 {
-	m_itemDict[ (void*)diff ]->applyDifference( apply );
+	m_itemDict[ diff ]->applyDifference( apply );
 	// now renumber the line column if this is the destination
 	if ( !m_isSource )
 		renumberLines();
--- trunk/KDE/kdesdk/kompare/komparepart/komparelistview.h #1090719:1090720
@@ -19,7 +19,7 @@
 #ifndef KOMPARELISTVIEW_H
 #define KOMPARELISTVIEW_H
 
-#include <Q3PtrDict>
+#include <QHash>
 #include <QLabel>
 #include <QResizeEvent>
 #include <QWheelEvent>
@@ -89,7 +89,7 @@
 
 private:
 	QList<KompareListViewDiffItem*> m_items;
-	Q3PtrDict<KompareListViewDiffItem> m_itemDict;
+	QHash<const Diff2::Difference*, KompareListViewDiffItem*> m_itemDict;
 	bool                              m_isSource;
 	ViewSettings*                     m_settings;
 	int                               m_scrollId;
--- trunk/KDE/kdesdk/kompare/libdiff2/diffmodellist.cpp #1090719:1090720
@@ -17,50 +17,16 @@
 
 #include "diffmodellist.h"
 
-#include <q3tl.h>
 #include <kdebug.h>
 
 using namespace Diff2;
 
-void DiffModelList::sort()
+bool diffModelCompare(DiffModel* model1, DiffModel* model2)
 {
-	// This is not going to be performance critical so implementing a very simple bubblesort based on qbubblesortrcode
-	// Goto last element;
-	DiffModelListIterator last = end();
-	DiffModelListIterator e = end();
-	DiffModelListIterator b = begin();
-
-	// empty list
-	if ( b == e )
-		return;
-
-	--last;
-	// only one element ?
-	if ( last == b )
-		return;
-
-	// So we have at least two elements in here
-	while (b != last) {
-		bool swapped = false;
-		DiffModelListIterator swapPos = b;
-		DiffModelListIterator x = e;
-		DiffModelListIterator y = x;
-		y--;
-		do {
-			--x;
-			--y;
-			if ( (*(*x) < *(*y)) ) {
-				swapped = true;
-				DiffModel* temp = *x;
-				*x = *y;
-				*y = temp;
-				swapPos = y;
-			}
-		} while (y != b);
-		if (!swapped)
-			return;
-		b = swapPos;
-		++b;
-	}
+	return *model1 < *model2;
 }
 
+void DiffModelList::sort()
+{
+	qSort(begin(), end(), diffModelCompare);
+}
--- trunk/KDE/kdesdk/kompare/libdiff2/diffmodellist.h #1090719:1090720
@@ -18,7 +18,7 @@
 #ifndef DIFFMODELLIST_H
 #define DIFFMODELLIST_H
 
-#include <q3valuelist.h> // include for the base class
+#include <qlist.h> // include for the base class
 
 #include "diffmodel.h"
 #include "diff2export.h"
@@ -26,14 +26,14 @@
 namespace Diff2
 {
 
-typedef Q3ValueListIterator<DiffModel*> DiffModelListIterator;
-typedef Q3ValueListConstIterator<DiffModel*> DiffModelListConstIterator;
+typedef QList<DiffModel*>::Iterator DiffModelListIterator;
+typedef QList<DiffModel*>::ConstIterator DiffModelListConstIterator;
 
-class DIFF2_EXPORT DiffModelList : public Q3ValueList<DiffModel*>
+class DIFF2_EXPORT DiffModelList : public QList<DiffModel*>
 {
 public:
 	DiffModelList() {}
-	DiffModelList( const DiffModelList &list ) : Q3ValueList<DiffModel*>( list ) {}
+	DiffModelList( const DiffModelList &list ) : QList<DiffModel*>( list ) {}
 	virtual ~DiffModelList()
 	{
 		// Memleak as indicated by valgrind
--- trunk/KDE/kdesdk/kompare/libdiff2/komparemodellist.h #1090719:1090720
@@ -85,7 +85,7 @@
 	int differenceCount() const;
 	int appliedCount() const;
 
-	const DiffModel* modelAt( int i ) const { return *( m_models->at( i ) ); };
+	const DiffModel* modelAt( int i ) const { return m_models->at( i ); };
 	int              findModel( DiffModel* model ) const { return m_models->findIndex( model ); };
 
 	bool hasUnsavedChanges() const;
--- trunk/KDE/kdesdk/kompare/libdiff2/kompareprocess.cpp #1090719:1090720
@@ -96,7 +96,7 @@
 
 void KompareProcess::writeCommandLine()
 {
-	// load the executable into the K3Process
+	// load the executable into the KProcess
 	if ( m_diffSettings->m_diffProgram.isEmpty() )
 	{
 		kDebug(8101) << "Using the first diff in the path..." << endl;


More information about the Kompare-devel mailing list