kmail

snippetitem.cpp

00001 /*
00002  *  File : snippetitem.cpp
00003  *
00004  *  Author: Robert Gruber <rgruber@users.sourceforge.net>
00005  *
00006  *  Copyright: See COPYING file that comes with this distribution
00007  */
00008 
00009 #include <qstring.h>
00010 
00011 
00012 #include "snippetitem.h"
00013 
00014 SnippetItem::SnippetItem(QListView * parent, QString name, QString text )
00015             : QListViewItem( parent, name )
00016 {
00017   strName = name;
00018   strText = text;
00019   iParent = -1;
00020 }
00021 
00022 SnippetItem::SnippetItem(QListViewItem * parent, QString name, QString text)
00023             : QListViewItem( parent, name )
00024 {
00025   strName = name;
00026   strText = text;
00027   iParent = ((SnippetGroup *)parent)->getId();
00028 }
00029 
00030 SnippetItem::~SnippetItem()
00031 {
00032 }
00033 
00034 
00038 QString SnippetItem::getName()
00039 {
00040   return strName;
00041 }
00042 
00043 
00047 QString SnippetItem::getText()
00048 {
00049   return strText;
00050 }
00051 
00052 
00056 void SnippetItem::setText(QString text)
00057 {
00058   strText = text;
00059 }
00060 
00061 
00065 void SnippetItem::setName(QString name)
00066 {
00067   strName = name;
00068 }
00069 
00070 void SnippetItem::resetParent()
00071 {
00072   SnippetGroup * group = dynamic_cast<SnippetGroup*>(parent());
00073   if (group)
00074     iParent = group->getId();
00075 }
00076 
00077 SnippetItem * SnippetItem::findItemByName(QString name, QPtrList<SnippetItem> &list)
00078 {
00079   for ( SnippetItem * item = list.first(); item; item = list.next() ) {  //write the snippet-list
00080     if (item->getName() == name)
00081         return item;
00082   }
00083   return NULL;
00084 }
00085 
00086 SnippetGroup * SnippetItem::findGroupById(int id, QPtrList<SnippetItem> &list)
00087 {
00088   for ( SnippetItem * item = list.first(); item; item = list.next() ) {  //write the snippet-list
00089     SnippetGroup * group = dynamic_cast<SnippetGroup*>(item);
00090     if (group && group->getId() == id)
00091         return group;
00092   }
00093   return NULL;
00094 }
00095 
00096 
00097 /* * * * * * * * * * * * * * * * * * * *
00098 Deklaration for class SnippetGroup
00099 * * * * * * * * * * * * * * * * * * * */
00100 
00101 int SnippetGroup::iMaxId = 1;
00102 
00103 SnippetGroup::SnippetGroup(QListView * parent, QString name, int id)
00104  : SnippetItem(parent, name, "GROUP")
00105 {
00106     if (id > 0) {
00107       iId = id;
00108       if (id >= iMaxId)
00109         iMaxId = id+1;
00110     } else {
00111       iId = iMaxId;
00112       iMaxId++;
00113     }
00114 }
00115 
00116 SnippetGroup::~SnippetGroup()
00117 {
00118 }
00119 
00120 void SnippetGroup::setId(int id)
00121 {
00122     iId = id; 
00123     if (iId >= iMaxId)
00124         iMaxId = iId+1;
00125 }
KDE Home | KDE Accessibility Home | Description of Access Keys