some patches

Jens Weggemann bravey at gmx.de
Fri Apr 4 06:54:02 UTC 2003


Hi,

I  just started playing with the gideon sources a little,
and thought I'd send you the (few) things I've changed so far.
I'm not too familiar with KDE programming (Qt only so far),
so I might not do things the preferred way, feel free to correct
me, just learning..

The first one fixes the following bug: in a qmake project,
after using the new class dialog, the new header and source files
are opened, but they are both empty - they are opened with urls
like '/foo.cpp'.
the cause is the check for the active dir in the cppsupport code -
apparently the trollproject's activeDirectory() method returns an
empty (but non-null) string when there is no active dir, while e.g.
the auto(make)project returns a null string in that case.
the code expected a null string, the activeDirectory() documentation
isn't clear onthat point, so the code should be more careful - obvious patch 
follows:
----------------------------->

Index: cppnewclassdlg.cpp
===================================================================
RCS file: /home/kde/kdevelop/parts/cppsupport/cppnewclassdlg.cpp,v
retrieving revision 1.33
diff -u -r1.33 cppnewclassdlg.cpp
--- cppnewclassdlg.cpp	1 Apr 2003 20:14:22 -0000	1.33
+++ cppnewclassdlg.cpp	4 Apr 2003 04:33:30 -0000
@@ -1521,7 +1521,7 @@

 	QStringList fileList;

-	if ( project->activeDirectory().isNull() )
+	if ( project->activeDirectory().isEmpty() )
 	{
 		fileList.append ( header );
 		fileList.append ( implementation );

<-----------------------------


The next two implement the usual parents-open/close-on-double-click
(and returnpressed) behaviour of the listviews in the class tree and
the file groups tree, respectively.
----------------------------->

Index: classtreebase.cpp
===================================================================
RCS file: /home/kde/kdevelop/parts/classview/classtreebase.cpp,v
retrieving revision 1.45
diff -u -b -r1.45 classtreebase.cpp
--- classtreebase.cpp	24 Mar 2003 14:44:02 -0000	1.45
+++ classtreebase.cpp	3 Apr 2003 23:11:10 -0000
@@ -476,6 +476,10 @@
     if (!item)
         return;

+	// toggle open state for parents
+	if (item->childCount() > 0)
+		setOpen(item, !isOpen(item));
+
     // We assume here that ALL (!) items in the list view
     // are ClassTreeItem's
     ClassTreeItem *ctitem = static_cast<ClassTreeItem*>(item);

Index: filegroupswidget.cpp
===================================================================
RCS file: /home/kde/kdevelop/parts/fileview/filegroupswidget.cpp,v
retrieving revision 1.12
diff -u -b -r1.12 filegroupswidget.cpp
--- filegroupswidget.cpp	5 Feb 2003 13:03:45 -0000	1.12
+++ filegroupswidget.cpp	3 Apr 2003 23:11:32 -0000
@@ -136,6 +136,10 @@
     if (!item)
         return;

+	// toggle open state for parents
+	if (item->childCount() > 0)
+		setOpen(item, !isOpen(item));
+
     // Is it a group item?
     if (!item->parent())
         return;

<-----------------------------

(this is more a matter of taste: ->)
The file groups view takes too much precious horizontal space imho,
so here's a patch that makes it display the file name (without path)
in the first column and only the path without the file name
in the second column. I removed the extraction method rather than
adding a second one for the path extraction, because that would
create two QFileInfo objects for no good reason and it was called
by the class in one place only anyway.
----------------------------->

Index: filegroupswidget.cpp
===================================================================
RCS file: /home/kde/kdevelop/parts/fileview/filegroupswidget.cpp,v
retrieving revision 1.12
diff -u -b -r1.12 filegroupswidget.cpp
--- filegroupswidget.cpp	5 Feb 2003 13:03:45 -0000	1.12
+++ filegroupswidget.cpp	3 Apr 2003 23:31:14 -0000
@@ -84,23 +84,17 @@
     { return fullname; }

 private:
-    static QString extractName(const QString &fileName);
     QString fullname;
 };


 FileGroupsFileItem::FileGroupsFileItem(QListViewItem *parent, const QString 
&fileName)
-    : QListViewItem(parent, extractName(fileName)), fullname(fileName)
+    : QListViewItem(parent), fullname(fileName)
 {
     setPixmap(0, SmallIcon("document"));
-    setText(1, fileName);
-}
-
-
-QString FileGroupsFileItem::extractName(const QString &fileName)
-{
     QFileInfo fi(fileName);
-    return fi.fileName();
+	setText(0, fi.fileName());
+	setText(1, fi.dirPath() + "/");
 }

<-----------------------------

Next one is a little cleaning up and fixing in the qmake project manager.
I don't see a reason why QFileInfo wasn't used to split filename,
path, and extension. old version is commented out.
the way the file group was determined from the extension didn't
work properly ("cpp c".find(ext)>=0  <- a "*.p" file would be
considered a source file) - however, it should probably be settable
somewhere (either take the filegroupview's settings or both
should inherit a project setting), so i abstracted that into
a static method for now with an unelegant, but working check
----------------------------->

Index: trollprojectwidget.h
===================================================================
RCS file: /home/kde/kdevelop/parts/trollproject/trollprojectwidget.h,v
retrieving revision 1.36
diff -u -r1.36 trollprojectwidget.h
--- trollprojectwidget.h	1 Apr 2003 19:00:38 -0000	1.36
+++ trollprojectwidget.h	4 Apr 2003 01:19:52 -0000
@@ -125,6 +125,7 @@
 {
 public:
     enum GroupType {NoType, Sources, Headers, Forms };
+	static GroupType groupTypeForExtension(const QString &ext);

     GroupItem(QListView *lv, GroupType type, const QString &text,const 
QString &scopeString);

Index: trollprojectwidget.cpp
===================================================================
RCS file: /home/kde/kdevelop/parts/trollproject/trollprojectwidget.cpp,v
retrieving revision 1.91
diff -u -r1.91 trollprojectwidget.cpp
--- trollprojectwidget.cpp	1 Apr 2003 19:00:38 -0000	1.91
+++ trollprojectwidget.cpp	4 Apr 2003 01:19:58 -0000
@@ -120,6 +120,17 @@
     setPixmap(0, SmallIcon("tar"));
 }

+GroupItem::GroupType GroupItem::groupTypeForExtension(const QString &ext)
+{
+	if (ext == "cpp" || ext == "cc" || ext == "c")
+		return Sources;
+	else if (ext == "hpp" || ext == "h")
+		return Headers;
+	else if (ext == "ui")
+		return Forms;
+	else
+		return NoType;
+}

 /**
  * Class FileItem
@@ -1000,6 +1011,8 @@
 {
   if (!m_shownSubproject)
     return;
+
+/*
   QStringList splitFile = QStringList::split('.',fileName);
   QString ext = splitFile[splitFile.count()-1];
   splitFile = QStringList::split('/',fileName);
@@ -1013,6 +1026,14 @@
     addFileToCurrentSubProject(GroupItem::Forms,fileWithNoSlash);
   else
     addFileToCurrentSubProject(GroupItem::NoType,fileWithNoSlash);
+*/
+
+  QFileInfo info(fileName);
+  QString ext = info.extension(false).simplifyWhiteSpace();
+  QString noPathFileName = info.fileName();
+
+  addFileToCurrentSubProject(GroupItem::groupTypeForExtension(ext), 
noPathFileName);
+
   updateProjectFile(m_shownSubproject);
   slotOverviewSelectionChanged(m_shownSubproject);
   emitAddedFile ( fileName );
@@ -1052,7 +1073,7 @@
 void TrollProjectWidget::slotNewFile()
 {
     KDevCreateFile * createFileSupport = m_part->createFileSupport();
-    if (createFileSupport)
+    if (createFileSupport)
     {
         KDevCreateFile::CreatedFile crFile =
             createFileSupport->createNewFile(QString::null, 
projectDirectory()+m_shownSubproject->path.mid(projectDirectory().length()));

<-----------------------------

hope this helps,
Jens





More information about the KDevelop-devel mailing list