KDE/kdevplatform

Andreas Pakulat apaku at gmx.de
Sat Feb 16 21:20:31 UTC 2008


SVN commit 775955 by apaku:

change the interface to get a project item for a url. This implementation is a
lot slower than the old one, however the old one was incorrect in two ways:

- it assumed there's only 1 project item for a given url, thats wrong as a file
  might be part of multiple targets
- it assumed that the project item for a given url is inside the subtree that
  has the same path, which might not be the case

In the cause of this, the function now returns a list of items, that is all
these items have the same url, but different parents. The language support
parts probably want to do something more sensible than just taking the first
one.

CCMAIL:kdevelop-devel at kdevelop.org


 M  +1 -1      interfaces/iproject.h  
 M  +39 -73    shell/project.cpp  
 M  +1 -1      shell/project.h  


--- trunk/KDE/kdevplatform/interfaces/iproject.h #775954:775955
@@ -97,7 +97,7 @@
 
     virtual QList<ProjectFileItem*> files() const = 0;
 
-    virtual ProjectFileItem *fileForUrl( const KUrl& ) const = 0;
+    virtual QList<ProjectFileItem*> filesForUrl( const KUrl& ) const = 0;
 
 //     virtual KUrl projectConfigFile() const = 0;
 //     virtual KUrl projectDefaultsConfigFile() const = 0;
--- trunk/KDE/kdevplatform/shell/project.cpp #775954:775955
@@ -104,6 +104,40 @@
         return files;
     }
 
+    QList<ProjectFileItem*> filesForUrlInternal( const KUrl& url, ProjectFolderItem* folder ) const
+    {
+        QList<ProjectFileItem*> files;
+        if( !folder )
+            return files;
+        // Check top level files
+        foreach( ProjectFileItem* file, folder->fileList() )
+        {
+            if( file->url() == url )
+            {
+                files << file;
+            }
+        }
+    
+        // Check top level targets
+        foreach( ProjectTargetItem* target, folder->targetList() )
+        {
+            foreach( ProjectFileItem* file, target->fileList() )
+            {
+                if( file->url() == url )
+                {
+                    files << file;
+                }
+            }
+        }
+        
+        foreach( ProjectFolderItem* top, folder->folderList() )
+        {
+            files += filesForUrlInternal( url, top );
+        }
+        return files;
+    }
+
+
     void importDone( KJob* )
     {
         Core::self()->projectControllerInternal()->projectImportingFinished( project );
@@ -231,7 +265,7 @@
         d->tmp->close();
     }
 
-    kdDebug(9501) << "Creating KConfig object for project files" << d->developerTempFile << d->projectTempFile;
+    kDebug(9501) << "Creating KConfig object for project files" << d->developerTempFile << d->projectTempFile;
     d->m_cfg = KSharedConfig::openConfig( d->developerTempFile );
     d->m_cfg->addConfigSources( QStringList() << d->projectTempFile );
 
@@ -314,7 +348,7 @@
 
 bool Project::inProject( const KUrl& url ) const
 {
-    return ( fileForUrl( url ) != 0 || url.equals( d->topItem->url(), KUrl::CompareWithoutTrailingSlash ) );
+    return ( !filesForUrl( url ).isEmpty() || url.equals( d->topItem->url(), KUrl::CompareWithoutTrailingSlash ) );
 }
 
 ProjectFileItem* Project::fileAt( int num ) const
@@ -336,84 +370,16 @@
     return files;
 }
 
-ProjectFileItem *Project::fileForUrl(const KUrl& url) const
+QList<ProjectFileItem*> Project::filesForUrl(const KUrl& url) const
 {
     // TODO: This is moderately efficient, but could be much faster with a
     // QHash<QString, ProjectFolderItem> member. Would it be worth it?
 
     KUrl u = d->topItem->url();
     if ( u.protocol() != url.protocol() || u.host() != url.host() )
-        return 0;
+        return QList<ProjectFileItem*>();
 
-    foreach( ProjectFileItem* file, d->topItem->fileList() )
-    {
-        if( file->url() == url )
-        {
-            return file;
-        }
-    }
-
-    foreach( ProjectTargetItem* target, d->topItem->targetList() )
-    {
-        foreach( ProjectFileItem* file, target->fileList() )
-        {
-            if( file->url() == url )
-            {
-                return file;
-            }
-        }
-    }
-    
-    foreach( ProjectFolderItem* top, d->topItem->folderList() )
-    {
-        while ( top )
-        {
-            u = top->url();
-            if ( u.isParentOf( url ) )
-            {
-                ProjectFolderItem *parent = 0;
-                QList<ProjectFolderItem*> folder_list = top->folderList();
-                foreach( ProjectFolderItem *folder, folder_list )
-                {
-                    if ( folder->url().isParentOf( url ) )
-                    {
-                        parent = folder;
-                        break;
-                    }
-                }
-                if ( !parent ) //the subfolders are not parent of url
-                {
-                    QList<ProjectFileItem*> file_list = top->fileList();
-                    foreach( ProjectFileItem *file, file_list )
-                    {
-                        if ( file->url() == url )
-                        {
-                            return file; //we found it
-                            break;
-                        }
-                    }
-                    QList<ProjectTargetItem*> target_list = top->targetList();
-                    foreach( ProjectTargetItem *target, target_list )
-                    {
-                        QList<ProjectFileItem*> targetfile_list = target->fileList();
-                        foreach( ProjectFileItem *file, targetfile_list )
-                        {
-                            if ( file->url() == url )
-                            {
-                                return file; //we found it
-                                break;
-                            }
-                        }
-                    }
-                    return 0; //not in the project
-                }
-                top = parent;
-            }
-            else
-                top = 0;
-        }
-    }
-    return 0;
+    return d->filesForUrlInternal( url, d->topItem );
 }
 
 int Project::fileCount() const
--- trunk/KDE/kdevplatform/shell/project.h #775954:775955
@@ -70,7 +70,7 @@
 
     virtual QList<ProjectFileItem*> files() const;
 
-    virtual ProjectFileItem *fileForUrl( const KUrl& ) const;
+    virtual QList<ProjectFileItem*> filesForUrl( const KUrl& ) const;
 
     QString projectTempFile() const;
     QString developerTempFile() const;




More information about the KDevelop-devel mailing list