KDevelop API Documentation

autolistviewitems.cpp

Go to the documentation of this file.
00001 /***************************************************************************
00002 *   Copyright (C) 2001-2002 by Bernd Gehrmann                             *
00003 *   bernd@kdevelop.org                                                    *
00004 *                                                                         *
00005 *   Copyright (C) 2002 by Victor Rder                                    *
00006 *   victor_roeder@gmx.de                                                  *
00007 *                                                                         *
00008 *   This program is free software; you can redistribute it and/or modify  *
00009 *   it under the terms of the GNU General Public License as published by  *
00010 *   the Free Software Foundation; either version 2 of the License, or     *
00011 *   (at your option) any later version.                                   *
00012 *                                                                         *
00013 ***************************************************************************/
00014 
00015 #include <qpainter.h>
00016 #include <qinputdialog.h>
00017 #include <qregexp.h>
00018 
00019 #include <kiconloader.h>
00020 #include "misc.h"
00021 #include "autolistviewitems.h"
00022 #include "autoprojectpart.h"
00023 #include "autoprojectwidget.h"
00024 #include "autodetailsview.h"
00025 
00030 ProjectItem::ProjectItem( Type type, QListView *parent, const QString &text )
00031         : QListViewItem( parent, text ), typ( type )
00032 {
00033     bld = false;
00034 }
00035 
00036 
00037 ProjectItem::ProjectItem( Type type, ProjectItem *parent, const QString &text )
00038         : QListViewItem( parent, text ), typ( type )
00039 {
00040     bld = false;
00041 }
00042 
00043 
00044 void ProjectItem::paintCell( QPainter *p, const QColorGroup &cg,
00045                              int column, int width, int alignment )
00046 {
00047     if ( isBold() )
00048     {
00049         QFont font( p->font() );
00050         font.setBold( true );
00051         p->setFont( font );
00052     }
00053     QListViewItem::paintCell( p, cg, column, width, alignment );
00054 }
00055 
00056 
00061 SubprojectItem::SubprojectItem( QListView *parent, const QString &text )
00062         : ProjectItem( Subproject, parent, text )
00063 {
00064     init();
00065 }
00066 
00067 
00068 SubprojectItem::SubprojectItem( SubprojectItem *parent, const QString &text )
00069         : ProjectItem( Subproject, parent, text )
00070 {
00071     init();
00072 }
00073 
00074 
00075 void SubprojectItem::init()
00076 {
00077     targets.setAutoDelete( true );
00078     setPixmap( 0, SmallIcon( "folder" ) );
00079 }
00080 
00081 
00082 QString SubprojectItem::relativePath()
00083 {
00084     QString relpath = subdir;
00085 
00086     SubprojectItem *it = this;
00087     while ( (it= dynamic_cast<SubprojectItem*>(it->parent())) )
00088     {
00089         relpath.prepend(it->subdir + "/");
00090     }
00091     relpath.remove(0, 2);
00092 
00093     return relpath;
00094 }
00095 
00096 
00101 TargetItem::TargetItem( QListView *lv, bool group, const QString &text )
00102         : ProjectItem( Target, lv, text )
00103 {
00104     sources.setAutoDelete( true );
00105     setPixmap( 0, group ? SmallIcon( "tar" ) : SmallIcon( "binary" ) );
00106 }
00107 
00108 
00113 FileItem::FileItem( QListView *lv, const QString &text, bool set_is_subst )
00114         : ProjectItem( File, lv, text ) , is_subst(set_is_subst)
00115 {
00116     if(!is_subst)
00117     {
00118         setPixmap( 0, SmallIcon( "document" ) );
00119     }
00120     else
00121     {
00122         setPixmap( 0, SmallIcon( "variablenew" ) );
00123     }
00124 }
00125 
00126 
00127 void FileItem::changeSubstitution()
00128 {
00129 if(!is_subst)
00130 return;
00131 
00132     bool ok;
00133     QString text = QInputDialog::getText(
00134                        i18n("Edit Substitution"), i18n("Substitution:"), QLineEdit::Normal,
00135                        name, &ok );
00136     if ( ok && !text.isEmpty() )
00137     {
00138         // user entered something and pressed OK
00139         QString new_name = text;
00140         if(new_name == name)
00141             return;
00142         setText(0,new_name);
00143         changeMakefileEntry(new_name);
00144         name = new_name;
00145     }
00146     else
00147     {
00148         // user entered nothing or pressed Cancel
00149 
00150     }
00151 }
00152 
00153 void FileItem::changeMakefileEntry(const QString& new_name)
00154 {
00155     TargetItem* target = dynamic_cast<TargetItem*>(parent());
00156 
00157     QMap<QString,QString> replaceMap;
00158 
00159     QString canontargetname = AutoProjectTool::canonicalize(target->name);
00160     QString varname;
00161     if( target->primary == "PROGRAMS" || target->primary == "LIBRARIES" || target->primary == "LTLIBRARIES" )
00162         varname = canontargetname + "_SOURCES";
00163     else
00164         varname = target->prefix + "_" + target->primary;
00165     SubprojectItem* subProject = dynamic_cast<AutoDetailsView*>(listView())->m_part->m_widget->selectedSubproject();
00166     QStringList sources = QStringList::split(QRegExp("[ \t\n]"), subProject->variables[varname]);
00167     QStringList::iterator it = sources.find(name);
00168     (*it) = new_name;
00169     subProject->variables[varname] = sources.join(" ");
00170     replaceMap.insert(varname, subProject->variables[varname]);
00171 
00172     AutoProjectTool::modifyMakefileam(subProject->path + "/Makefile.am", replaceMap);
00173 
00174     if(new_name == "")
00175         target->sources.remove(this);
00176 
00177 }
KDE Logo
This file is part of the documentation for KDevelop Version 3.1.2.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Tue Feb 22 09:22:21 2005 by doxygen 1.3.9.1 written by Dimitri van Heesch, © 1997-2003